Nacos
nacos文档
1. docker安装nacos
- 安装nacos
docker pull nacos/nacos-server
mkdir -p /mydata/nacos/logs/ #新建logs目录
mkdir -p /mydata/nacos/conf/
mkdir -p /mydata/nacos/data/
vim /mydata/nacos/conf/application.properties #修改配置文件
3.创建nacos数据库,执行sql
- 修改application.properties
server.servlet.contextPath=/nacos
server.port=8848
spring.datasource.platform=mysql
### Count of DB:
db.num=1
### Connect URL of DB:
db.url.0=jdbc:mysql://{docker容器中的mysql地址}:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=root
db.password.0=root
### Connection pool configuration: hikariCP
db.pool.config.connectionTimeout=30000
db.pool.config.validationTimeout=10000
db.pool.config.maximumPoolSize=20
db.pool.config.minimumIdle=2
nacos.naming.empty-service.auto-clean=true
nacos.naming.empty-service.clean.initial-delay-ms=50000
nacos.naming.empty-service.clean.period-time-ms=30000
server.tomcat.accesslog.enabled=true
### The access log pattern:
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i %{Request-Source}i
nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-ui/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**
### The auth system to use, currently only 'nacos' and 'ldap' is supported:
nacos.core.auth.system.type=nacos
### If turn on auth system:
nacos.core.auth.enabled=false
### The token expiration in seconds:
nacos.core.auth.default.token.expire.seconds=18000
### The default token:
nacos.core.auth.default.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789
nacos.core.auth.caching.enabled=true
nacos.core.auth.enable.userAgentAuthWhite=false
nacos.core.auth.server.identity.key=serverIdentity
nacos.core.auth.server.identity.value=security
nacos.istio.mcp.server.enabled=false
- 启动容器
docker run -it --name nacos \
-p 8848:8848 \
-e MODE=standalone \
-v /mydata/nacos/conf/application.properties:/home/nacos/conf/application.properties \
-v /mydata/nacos/data:/home/nacos/conf/data \
-v /mydata/nacos/logs:/home/nacos/conf/logs \
-d nacos/nacos-server
2. nacos配置
配置在bootstrap.properties或者bootstrap.yml文件中
spring:
cloud:
nacos:
config:
#配置文件后缀
file-extension: yaml
#配置中心地址
server-addr: 192.168.56.2:8848
discovery:
#服务注册中心地址
server-addr: 192.168.56.2:8848
inetutils:
#指定网卡
preferred-networks: 192.168.56.1
启动类注解
@EnableDiscoveryClient
#命名空间,一般一个服务一个命名空间
spring.cloud.nacos.config.namespace=c2f62303-e83a-4ac4-90a3-5eb7540deba5
#分组,一般分(dev,pro,test)
spring.cloud.nacos.config.group=dev
#拓展的配置文件
spring.cloud.nacos.config.ext-config[1].data-id=datasource.yml
spring.cloud.nacos.config.ext-config[1].group=dev
#配置文件发生改动是否自动刷新
spring.cloud.nacos.config.ext-config[1].refresh=true
@RefreshScope //支持Nacos的动态刷新