1、前置
1、配置nacos对应的数据库
2、挂载nacos对应的application.properties
3、运行nacos
4、备注
2、配置Nacos对应的MySQL
找到对应的MySQL文件地址:
https://github.com/alibaba/nacos/blob/master/distribution/conf/nacos-mysql.sql
在集群部署说明里面可以找到初始化SQL文件地址:
https://nacos.io/zh-cn/docs/cluster-mode-quick-start.html
大家可以自行去这个地方复制SQL语句
3、配置Nacos对应的application.properties
找到对应的MySQL文件地址:
https://github.com/nacos-group/nacos-docker/blob/master/build/conf/application.properties
修改内容:
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://172.19.0.2(数据库IP):3306(数据库端口)/nacos_config(数据库库名)?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root (数据库用户名)
db.password=123456 (数据库密码)
删除db.url.1
# spring
server.servlet.contextPath=${SERVER_SERVLET_CONTEXTPATH:/nacos}
server.contextPath=/nacos
server.port=${NACOS_APPLICATION_PORT:8848}
spring.datasource.platform=mysql
nacos.cmdb.dumpTaskInterval=3600
nacos.cmdb.eventTaskInterval=10
nacos.cmdb.labelTaskInterval=300
nacos.cmdb.loadDataAtStart=false
db.num=1
db.url.0=jdbc:mysql://172.19.0.2:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=123456
### 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}
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=/,/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
4、启动Nacos
docker-nacos.yaml
# Compose 版本 Version 2支持更多的指令。Version 1将来会被弃用。
version: "3"
# 定义服务
services:
# 为project定义服务
nacos:
# 服务的镜像名称或镜像ID。如果镜像在本地不存在,Compose将会尝试拉取镜像
image: nacos/nacos-server:1.2.1
# 配置端口 - "宿主机端口:容器暴露端口"
ports:
- 8848:8848
# 配置容器连接的网络,引用顶级 networks 下的条目(就是最下面配置的networks(一级目录))
networks:
- mysql_mysql
# 挂载
volumes:
- "E://Docker/nacos/conf/application.properties:/home/nacos/conf/application.properties"
# 容器总是重新启动
restart: always
# 添加环境变量
environment:
MODE: standalone
# 指定一个自定义容器名称,而不是生成的默认名称。
container_name: nacos
# 使用该参数,container内的root拥有真正的root权限。
privileged: true
# 声明外部网络
networks:
mysql_mysql:
external: true
运行容器:
docker-compose -f docker-nacos.yaml up -d
日志:
4、备注说明
-
Nacos 1.1.4移除数据库主从镜像配置: 原因:https://github.com/nacos-group/nacos-docker/wiki/移除数据库主从镜像配置(所以我删除了db.url.1)
-
我这里是通过docker-compose方式进行的启动, 大家可以修改成对应的docker run模式
-
docker-compose明天会进行介绍
-
当然大家也可以通过源码, 或者安装包的模式进行运行nacos
-
关于application.properties里面的参数说明, 以及custom.properties配置:https://github.com/nacos-group/nacos-docker/blob/master/README_ZH.md