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

Posted pcdd

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker安装Nacos2.x.x(单机版)相关的知识,希望对你有一定的参考价值。

1. 拉取镜像

docker pull nacos/nacos-server

2. 进入容器

docker exec -it c_nacos bash

3. 创建挂载文件和目录

mkdir -p /root/docker/nacos/conf /root/docker/nacos/logs

4. 修改配置文件

vi /root/docker/nacos/conf/application.properties

注意一下,低版本挂载的是/home/nacos/init.d/custom.properties,也可进入容器自行查看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

5. 启动容器

docker run -id \\
--name=c_nacos \\
-p 8848:8848 \\
# 为jvm启动时分配的内存,默认2G,太大需修改
-e JVM_XMS=256m \\
# 为jvm运行过程中分配的最大内存,默认2G,太大需修改
-e JVM_XMX=256m \\
# 以单机模式启动
-e MODE=standalone \\
# 是否支持hostname
-e PREFER_HOST_MODE=hostname \\
-v /root/docker/nacos/logs:/home/nacos/logs \\
-v /root/docker/nacos/conf/application.properties:/home/nacos/conf/application.properties \\
--restart=always \\
nacos/nacos-server

6. 官方配置参数

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.x.x(单机版)的主要内容,如果未能解决你的问题,请参考以下文章

Docker安装RocketMQ单机版

solr安装-docker-单机版

docker安装fastdfs单机版

Docker安装Nacos2.0.3(单机版)

Docker安装Nacos2.0.3(单机版)

Docker(单机Kafka安装)