Nacos集群部署
1、下载安装包
https://github.com/alibaba/nacos/releases/download/2.3.1/nacos-server-2.3.1.tar.gz
2、解压安装包
tar -xf nacos-server-2.3.1.tar.gz
3、java环境配置
3.1、下载jdk17
https://download.oracle.com/java/17/archive/jdk-17.0.10_linux-x64_bin.tar.gz
3.2、解压jdk
tar -xf jdk-17.0.10_linux-x64_bin.tar.gz
3.3、解压后配置环境变量
vim /etc/profile. # 将一下内容添加到最后即可
JAVA_HOME=/usr/local/jdk17/jdk-17.0.10
CLASSPATH=.:$JAVA_HOME/lib.tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH
3.4、使变量生效
source /etc/profile
4、配置集群文件
cat /data/nacos-server/nacos/conf/cluster.conf
#2024-03-15T08:09:37.750969674
172.31.41.82:8848
172.31.46.15:8848
172.31.46.236:8848
5、导入数据库
mysql> CREATE DATABASE `nacos_config`;
mysql> USE `nacos_config`;
mysql> source /root/nacos-mysql.sql;
6、修改配置文件
cat /data/nacos-server/nacos/conf/application.properties
server.servlet.contextPath=/nacos
server.error.include-message=ALWAYS
server.port=8848
spring.datasource.platform=mysql
spring.sql.init.platform=mysql
db.num=1
db.url.0=jdbc:mysql://x.x.x.x:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=nacos
db.password.0=njbY&lnmm9
db.pool.config.connectionTimeout=30000
db.pool.config.validationTimeout=10000
db.pool.config.maximumPoolSize=20
db.pool.config.minimumIdle=2
nacos.config.push.maxRetryTime=50
server.tomcat.mbeanregistry.enabled=true
management.metrics.export.elastic.enabled=false
management.metrics.export.influx.enabled=false
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.rotate=true
server.tomcat.accesslog.file-date-format=.yyyy-MM-dd-HH
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i %{Request-Source}i
server.tomcat.basedir=file:.
nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-ui/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**
nacos.core.auth.system.type=nacos
nacos.core.auth.enabled=true
nacos.core.auth.caching.enabled=true
nacos.core.auth.enable.userAgentAuthWhite=false
nacos.core.auth.server.identity.key=nacos
nacos.core.auth.server.identity.value=nacos
nacos.core.auth.plugin.nacos.token.cache.enable=false
nacos.core.auth.plugin.nacos.token.expire.seconds=18000
nacos.core.auth.plugin.nacos.token.secret.key=YzBhYVF5RVRHJTIxUCUyMXc0TE1rdyU1RTlsS2FMayUyNjhxUUc0Ng==
nacos.istio.mcp.server.enabled=false
7、启动服务
/data/nacos-server/nacos/bin/startup.sh
8、查看服务监听状态
[root@client1 nacos]# netstat -nutlp|grep 8848
tcp6 0 0 :::8848 :::* LISTEN 2148/java
9、配置成服务
vim /usr/lib/systemd/system/nacos.service
[Unit]
Description=nacos-server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/data/nacos-server/nacos/bin/startup.sh
ExecStop=/data/nacos-server/nacos/bin/shutdown.sh
Restart=always PrivateTmp=true
[Install]
WantedBy=multi-user.target
# 重新启动服务
systemctl restart nacos.service
# 查看服务状态
systemctl status nacos.service
# 开启自启动
systemctl enable nacos.service
10、配置完成