1. 区分版本
nacos 1.4 以下 使用 mysql 5.7
nacos 1.4 以上 使用 mysq 8.0 以上
相应的sql 脚本 nacos 1.0 与 2.0 也不相同 一定要对应版本使用
否则 添加配置文件 会报 参数错误
mysql 密码要复杂些 否则要重新设置 无法连接1521
2. docker-compose 文件
version: "3.5"
networks:
nacos:
driver: bridge
services:
mysql:
image: mysql:8.0.20
restart: always
command: [
'--character-set-server=utf8mb4',
'--collation-server=utf8mb4_general_ci',
'--port=3306',
]
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: "admin123456"
MYSQL_USER: 'root'
networks:
- nacos
nacos:
image: nacos/nacos-server:latest
restart: always
deploy:
replicas: 1
resources:
limits:
cpus: "1"
memory: 512M
#volumes:
# - ./logs/:/home/nacos/logs
# - ./init.d/custom.properties:/home/nacos/init.d/custom.properties
ports:
- "8848:8848"
- "9848:9848"
- "9555:9555"
networks:
- nacos
depends_on:
- mysql
environment:
- JVM_XMS=512m
- JVM_XMX=1024m
- JVM_XMN=512m
- PREFER_HOST_MODE=hostname
- MODE=standalone
- SPRING_DATASOURCE_PLATFORM=mysql
- MYSQL_SERVICE_HOST=mysql
- MYSQL_SERVICE_DB_NAME=nacos
- MYSQL_SERVICE_PORT=3306
- MYSQL_SERVICE_USER=root
- MYSQL_SERVICE_PASSWORD=admin123456
- MYSQL_SERVICE_DB_PARAM=characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
2. volumes 如果要配置 要新建文件 custom.properties
# spring
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://ip:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=nacos
db.password=nacos
#
#server.contextPath=/nacos
#server.servlet.contextPath=/nacos
server.port=8848
# nacos.cmdb.dumpTaskInterval=3600
# nacos.cmdb.eventTaskInterval=10
# nacos.cmdb.labelTaskInterval=300
# nacos.cmdb.loadDataAtStart=false
# metrics for prometheus
#management.endpoints.web.exposure.include=*
# metrics for elastic search
management.metrics.export.elastic.enabled=false
#management.metrics.export.elastic.host=http://localhost:9200
# metrics for influx
management.metrics.export.influx.enabled=false
#management.metrics.export.influx.db=springboot
#management.metrics.export.influx.uri=http://localhost:8086
#management.metrics.export.influx.auto-create-db=true
#management.metrics.export.influx.consistency=one
#management.metrics.export.influx.compressed=true
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i
# default current work dir
server.tomcat.basedir=
## spring security config
### turn off security
#spring.security.enabled=false
#management.security=false
#security.basic.enabled=false
#nacos.security.ignore.urls=/**
nacos.security.ignore.urls=/,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/login,/v1/console/health/**,/v1/cs/**,/v1/ns/**,/v1/cmdb/**,/actuator/**,/v1/console/server/**
# nacos.naming.distro.taskDispatchPeriod=200
# nacos.naming.distro.batchSyncKeyCount=1000
# nacos.naming.distro.syncRetryDelay=5000
# nacos.naming.data.warmup=true
# nacos.naming.expireInstance=true
3. MYSQL_SERVICE 相应的变量可以去掉了