目录
Nacos节点服务器
Nacos 集群配置安装
JAVA环境安装:
创建数据库并导入表:
配置集群配置文件:
应用、属性配置:
启动文件配置:
同步nacos配置
启动服务
Supervisor管理Nacos服务
安装supervisor
生成配置文件:
修改supervisor配置
配置管理Nacos
更改nacos startup.sh
启动supervisor
查看状态:
加入开机自启
配置Nginx代理:
官方给出的架构图:
更改了一下架构:
集群中包含 3 个 Nacos Server 节点,两个 Proxy 主备节点,Mysql 数据库主备
这里仅记录Nacos的安装
节点 |
IP |
端口 |
---|---|---|
Nacos1 |
172.17.10.21 |
8858 (默认 8848) |
Nacos1 |
172.17.10.22 |
8858 (默认 8848) |
Nacos1 |
172.17.10.23 |
8858 (默认 8848) |
#安装JDK8
yum install java-1.8.0-openjdk*
#配置环境
vim /etc/profile
export JAVA_HOME=/usr/lib/jvm/java
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/jre/lib/rt.jar
export PATH=$PATH:$JAVA_HOME/bin
#环境生效
source /etc/profile
#创建数据库
CREATE DATABASE nacos DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
use nacos;
#导入数据表
source /opt/nacos/conf/nacos-mysql.sql
#授权用户
CREATE USER 'nacos'@'172.17.%' IDENTIFIED BY 'nacospassword';
GRANT ALL ON nacos.* TO 'nacos'@'172.17.%';
cp /opt/nacos/conf/cluster.conf.example /opt/nacos/conf/cluster.conf
vim /opt/nacos/conf/cluster.conf
172.17.10.21:8858
172.17.10.22:8858
172.17.10.23:8858
#忽略一些默认配置,如需配置其他参数可参开githup上的配置
vim /opt/nacos/conf/application.properties
server.port=8858
nacos.inetutils.ip-address=本地监听地址(更改为自己的IP),我的机器是2个网卡都有IP所以指定了监听IP
#*************** 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://172.17.10.45:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=nacos
db.password.0=nacospassword
vim /opt/nacos/bin/startup.sh
# JVM Configuratio
if [[ "${MODE}" == "standalone" ]]; then
JAVA_OPT="${JAVA_OPT} -Xms512m -Xmx512m -Xmn256m"
JAVA_OPT="${JAVA_OPT} -Dnacos.standalone=true"
else
if [[ "${EMBEDDED_STORAGE}" == "embedded" ]]; then
JAVA_OPT="${JAVA_OPT} -DembeddedStorage=true"
fi
JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
JAVA_OPT="${JAVA_OPT} -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${BASE_DIR}/logs/java_heapdump.hprof"
JAVA_OPT="${JAVA_OPT} -XX:-UseLargePages"
fi
scp -r nacos 172.17.10.22:/opt/
scp -r nacos 172.17.10.23:/opt/
[root@nacos1 bin]# ./startup.sh
[root@nacos2 bin]# ./startup.sh
[root@nacos3 bin]# ./startup.sh
默认的用户密码: nacos/nacos 访问地址:http://ip:8858
yum -y install python3-pip
pip3 install supervisor
#验证安装结果
echo_supervisord_conf #输出配置信息则安装成功
#创建工作/配置目录
mkdir -p /etc/supervisor/conf.d
生成配置文件:
echo_supervisord_conf > /etc/supervisor/supervisord.conf
[unix_http_server]
file=/var/run/supervisor.sock
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock
#解开注释行并配置files,其他参数 如 log pid 等配置可选修改自行修改为自己定义的目录
[include]
files = /etc/supervisor/conf.d/*
[program:nacos-cluster] ;项目名称
command=sh bin/startup.sh ;项目启动命令
directory=/opt/nacos ;项目目录,启动前切换目录
numprocs=1
autostart=true
autorestart=true
startsecs=30
startretries=3
exitcodes=0,2
stopsignal=QUIT
stopwaitsecs=10
user=root ;这个用户需要更改为普通用户,nacos相关的目录的属主属组也需要指定普通用户
redirect_stderr=true
killasgroup=true
stopasgroup=true
stderr_logfile=/opt/nacos/logs/supervisor.err.log
stdout_logfile=/opt/nacos/logs/supervisor.out.log
stdout_logfile_maxbytes=100MB
stdout_logfile_backups=5
stdout_capture_maxbytes=1MB
environment=JAVA_HOME=/usr/lib/jvm/java
if [[ "$JAVA_OPT_EXT_FIX" == "" ]]; then
#nohup "$JAVA" ${JAVA_OPT} nacos.nacos >> ${BASE_DIR}/logs/start.out 2>&1 &
"$JAVA" ${JAVA_OPT} nacos.nacos
else
#nohup "$JAVA" "$JAVA_OPT_EXT_FIX" ${JAVA_OPT} nacos.nacos >> ${BASE_DIR}/logs/start.out 2>&1 &
"$JAVA" "$JAVA_OPT_EXT_FIX" ${JAVA_OPT} nacos.nacos
fi
#先关闭个个节点的nacos
cd /opt/nacos/bin/ && sh shutdown.sh
#启动supervisor
supervisord -c /etc/supervisor/supervisord.conf
supervisorctl status
nacos-cluster RUNNING pid 16691, uptime 0:05:25
vim /lib/systemd/system/supervisord.service
#配置信息
[Unit]
Description=Process Monitoring and Control Daemon
After=rc-local.service nss-user-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=/usr/local/bin/supervisorctl shutdown
ExecReload=/usr/local/bin/supervisorctl reload
killMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
[root@nacos1 bin]# systemctl enable supervisord
Created symlink from /etc/systemd/system/multi-user.target.wants/supervisord.service to /usr/lib/systemd/system/supervisord.service.
[root@nacos1 bin]# systemctl start supervisord
[root@nacos1 bin]# systemctl status supervisord
● supervisord.service - Process Monitoring and Control Daemon
Loaded: loaded (/usr/lib/systemd/system/supervisord.service; enabled; vendor preset: disabled)
Active: active (running) since 一 2022-08-08 17:29:22 CST; 4s ago
# nacos proxy
upstream nacoscluster {
server 172.17.10.21:8858;
server 172.17.10.22:8858;
server 172.17.10.23:8858;
}
server {
# 监听端口
listen 8847;
server_name localhost;
# 路由匹配规则
location /nacos/ {
proxy_pass http://nacoscluster/nacos/;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect http:// $scheme://;
}
}