Docker安装Nacos2.0.3(单机版)
Posted pcdd
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker安装Nacos2.0.3(单机版)相关的知识,希望对你有一定的参考价值。
准备工作:挂载配置文件application.properties
# 配置文件存放目录
mkdir /root/docker/nacos/conf
application.properties内容如下,该文件是通过docker cp命令原封不动的从nacos容器中拷贝出来的
# spring
server.servlet.contextPath=$SERVER_SERVLET_CONTEXTPATH:/nacos
server.contextPath=/nacos
server.port=$NACOS_APPLICATION_PORT:8848
spring.datasource.platform=$SPRING_DATASOURCE_PLATFORM:""
nacos.cmdb.dumpTaskInterval=3600
nacos.cmdb.loadDataAtStart=false
db.num=$mysql_DATABASE_NUM:1
db.user=$MYSQL_SERVICE_USER
db.password=$MYSQL_SERVICE_PASSWORD
### The auth system to use, currently only 'nacos' is supported:
nacos.core.auth.system.type=$NACOS_AUTH_SYSTEM_TYPE:nacos
### The token expiration in seconds:
nacos.core.auth.default.token.expire.seconds=$NACOS_AUTH_TOKEN_EXPIRE_SECONDS:18000
### The default token:
nacos.core.auth.default.token.secret.key=$NACOS_AUTH_TOKEN:SecretKey012345678901234567890123456789012345678901234567890123456789
### Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay.
nacos.core.auth.caching.enabled=$NACOS_AUTH_CACHE_ENABLE:false
nacos.core.auth.enable.userAgentAuthWhite=$NACOS_AUTH_USER_AGENT_AUTH_WHITE_ENABLE:false
nacos.core.auth.server.identity.key=$NACOS_AUTH_IDENTITY_KEY:serverIdentity
nacos.core.auth.server.identity.value=$NACOS_AUTH_IDENTITY_VALUE:security
server.tomcat.accesslog.enabled=$TOMCAT_ACCESSLOG_ENABLED:false
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
# default current work dir
server.tomcat.basedir=
## spring security config
### turn off security
nacos.security.ignore.urls=$NACOS_SECURITY_IGNORE_URLS:/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**
# metrics for elastic search
management.metrics.export.elastic.enabled=false
management.metrics.export.influx.enabled=false
nacos.naming.distro.taskDispatchThreadCount=10
nacos.naming.distro.taskDispatchPeriod=200
nacos.naming.distro.batchSyncKeyCount=1000
nacos.naming.distro.initDataRatio=0.9
nacos.naming.distro.syncRetryDelay=5000
nacos.naming.data.warmup=true
注意一下
低版本(1.4.x)挂载的文是/home/nacos/init.d/custom.properties
而2.0.3版本挂载的文件是/home/nacos/conf/application.properties
也可进入容器自行查看nacos目录结构
使用docker-compose构建
version: '3'
services:
nacos:
image: nacos/nacos-server:v2.0.3
container_name: nacos
restart: always
volumes:
- "/root/docker/nacos/data:/home/nacos/data"
- "/root/docker/nacos/logs:/home/nacos/logs"
- "/root/docker/nacos/conf/application.properties:/home/nacos/conf/application.properties"
environment:
- MODE=standalone
- PREFER_HOST_MODE=ip
- NACOS_SERVER_IP=部署nacos机器的公网ip
- NACOS_SERVER_PORT=8848
- JVM_XMS=128m
- JVM_XMX=128m
- JVM_XMN=64m
ports:
- 8848:8848
- 9848:9848
- 9849:9849
这里需要说明几点
1 如果不加jvm参数的话,nacos会很占服务器内存。测试了下不加任何jvm参数启动后实际占用内存900多M,加了上述jvm参数后降低到440多M
2 Nacos2.x.x版本相比1.x新增了gRPC的通信方式,因此需要添加两个映射端口9848、9849,否则会报错:com.alibaba.nacos.api.exception.NacosException:Client not connected,current status:STARTING
官方配置参数
name | description | option |
---|---|---|
MODE | cluster模式/standalone模式 | cluster/standalone default cluster |
NACOS_SERVERS | nacos cluster地址 | eg. ip1,ip2,ip3 |
PREFER_HOST_MODE | 是否支持hostname | hostname/ip default ip |
NACOS_SERVER_PORT | nacos服务器端口 | default 8848 |
NACOS_SERVER_IP | 多网卡下的自定义nacos服务器IP | |
SPRING_DATASOURCE_PLATFORM | standalone 支持 mysql | mysql / empty default empty |
MYSQL_MASTER_SERVICE_HOST | mysql 主节点host | |
MYSQL_MASTER_SERVICE_PORT | mysql 主节点端口 | default : 3306 |
MYSQL_MASTER_SERVICE_DB_NAME | mysql 主节点数据库 | |
MYSQL_MASTER_SERVICE_USER | 数据库用户名 | |
MYSQL_MASTER_SERVICE_PASSWORD | 数据库密码 | |
MYSQL_SLAVE_SERVICE_HOST | mysql从节点host | |
MYSQL_SLAVE_SERVICE_PORT | mysql从节点端口 | default :3306 |
MYSQL_DATABASE_NUM | 数据库数量 | default :2 |
JVM_XMS | -Xms | default :2g |
JVM_XMX | -Xmx | default :2g |
JVM_XMN | -Xmn | default :1g |
JVM_MS | -XX:MetaspaceSize | default :128m |
JVM_MMS | -XX:MaxMetaspaceSize | default :320m |
NACOS_DEBUG | 开启远程调试 | y/n default :n |
TOMCAT_ACCESSLOG_ENABLED | server.tomcat.accesslog.enabled | default :false |
以上是关于Docker安装Nacos2.0.3(单机版)的主要内容,如果未能解决你的问题,请参考以下文章