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

官方配置参数

Nacos Docker官方文档

namedescriptionoption
MODEcluster模式/standalone模式cluster/standalone default cluster
NACOS_SERVERSnacos cluster地址eg. ip1,ip2,ip3
PREFER_HOST_MODE是否支持hostnamehostname/ip default ip
NACOS_SERVER_PORTnacos服务器端口default 8848
NACOS_SERVER_IP多网卡下的自定义nacos服务器IP
SPRING_DATASOURCE_PLATFORMstandalone 支持 mysqlmysql / empty default empty
MYSQL_MASTER_SERVICE_HOSTmysql 主节点host
MYSQL_MASTER_SERVICE_PORTmysql 主节点端口default : 3306
MYSQL_MASTER_SERVICE_DB_NAMEmysql 主节点数据库
MYSQL_MASTER_SERVICE_USER数据库用户名
MYSQL_MASTER_SERVICE_PASSWORD数据库密码
MYSQL_SLAVE_SERVICE_HOSTmysql从节点host
MYSQL_SLAVE_SERVICE_PORTmysql从节点端口default :3306
MYSQL_DATABASE_NUM数据库数量default :2
JVM_XMS-Xmsdefault :2g
JVM_XMX-Xmxdefault :2g
JVM_XMN-Xmndefault :1g
JVM_MS-XX:MetaspaceSizedefault :128m
JVM_MMS-XX:MaxMetaspaceSizedefault :320m
NACOS_DEBUG开启远程调试y/n default :n
TOMCAT_ACCESSLOG_ENABLEDserver.tomcat.accesslog.enableddefault :false

以上是关于Docker安装Nacos2.0.3(单机版)的主要内容,如果未能解决你的问题,请参考以下文章

Docker 下载运行 Nacos

Docker安装RocketMQ单机版

solr安装-docker-单机版

docker安装fastdfs单机版

Docker安装Nacos2.x.x(单机版)

Docker安装Nacos2.x.x(单机版)