1.需求环境
- JDK1.8+
- Maven3.3+
- Nginx作为负载均衡
- MySQL5.7+
2.下载Nacos
3.Linux下解压
4.修改配置文件
以8849实例为例,其余的实例修改相同(端口不同)
(1)修改数据源配置,使用外置数据源
#*************** Spring Boot Related Configurations ***************#
### Default web context path:
server.servlet.contextPath=/nacos
### Default web server port:
server.port=8849
#*************** Network Related Configurations ***************#
### If prefer hostname over ip for Nacos server addresses in cluster.conf:
# nacos.inetutils.prefer-hostname-over-ip=false
### Specify local server's IP:
# nacos.inetutils.ip-address=
#*************** Config Module Related Configurations ***************#
### If use MySQL as datasource:
spring.datasource.platform=mysql
### Count of DB:
db.num=1
### Connect URL of DB:
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=root
db.password.0=123456
### Connection pool configuration: hikariCP
db.pool.config.connectionTimeout=30000
db.pool.config.validationTimeout=10000
db.pool.config.maximumPoolSize=20
db.pool.config.minimumIdle=2
#*************** Naming Module Related Configurations ***************#
### Data dispatch task execution period in milliseconds:
# nacos.naming.distro.taskDispatchPeriod=200
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
#*************** CMDB Module Related Configurations ***************#
### The interval to dump external CMDB in seconds:
# nacos.cmdb.dumpTaskInterval=3600
### The interval of polling data change event in seconds:
# nacos.cmdb.eventTaskInterval=10
### The interval of loading labels in seconds:
# nacos.cmdb.labelTaskInterval=300
### If turn on data loading task:
# nacos.cmdb.loadDataAtStart=false
#*************** Metrics Related Configurations ***************#
### 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
#*************** Access Log Related Configurations ***************#
### If turn on the access log:
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
### The directory of access log:
server.tomcat.basedir=
#*************** Access Control Related Configurations ***************#
### If enable spring security, this option is deprecated in 1.2.0:
#spring.security.enabled=false
### The ignore urls of auth, is deprecated in 1.2.0:
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' 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
### 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=true
### Since 1.4.1, Turn on/off white auth for user-agent: nacos-server, only for upgrade from old version.
nacos.core.auth.enable.userAgentAuthWhite=true
### Since 1.4.1, worked when nacos.core.auth.enabled=true and nacos.core.auth.enable.userAgentAuthWhite=false.
### The two properties is the white list for auth and used by identity the request from other server.
nacos.core.auth.server.identity.key=
nacos.core.auth.server.identity.value=
#*************** Istio Related Configurations ***************#
### If turn on the MCP server:
nacos.istio.mcp.server.enabled=false
(2)导入nacos数据库数据
- 创建nacos(你自己的连接配置中的库名)数据库,确保使用的MySQL版本是5.7+,字符集使用utf8mb4
- 执行/usr/local/nacos/nacos8849/conf/文件夹下的nacos-mysql.sql导入数据
(3)修改集群服务地址配置
(4)修改nacos服务JVM内存分配参数
- 转到/usr/local/nacos/nacos8849/bin/路径下
- 记事本编辑startup.sh文件
- 找到JVM配置如下图位置
- 本人的虚拟机内存较小,容易引发内存不足,需要修改JVM内存参数,修改结果如下图
- 尝试启动8849端口的nacos服务
./startup.sh
- 查看启动日志,启动成功则会打印Nacos started successfully in cluster mode
tail -f ../logs/start.out
- 登录nacos主页(【虚拟机ip地址】:8849/nacos),登录成功说明开启成功,否则查看防火墙和安全组是否开发
- 拷贝配置文件到8850和8851(询问是否覆盖均为y)
cd /usr/local/nacos/
cp ./nacos8849/conf/application.properties ./nacos8850/conf/application.properties
y
cp ./nacos8849/conf/application.properties ./nacos8851/conf/application.properties
y
cp ./nacos8849/conf/cluster.conf ./nacos8850/conf/cluster.conf
cp ./nacos8849/conf/cluster.conf ./nacos8851/conf/cluster.conf
cp ./nacos8849/bin/startup.sh ./nacos8850/bin/startup.sh
y
cp ./nacos8849/bin/startup.sh ./nacos8851/bin/startup.sh
y
- 修改8850和8851的application.properties中的端口分别为8850和8851
- 启动启动8850和8851端口的nacos服务
(5)使用Nginx负载均衡配置
5.浏览器登录nacos主页
- 登录http://192.168.100.201:8847/nacos/,账号/密码:nacos/nacos