Note:
The premise is that jdk is installed in the system and the environment variables have been configured.
Environment: CentOS8.5 stand-alone pseudo-cluster
nacos version: 2.2.0
- Create a nacos_cluster.sh. The following is all the text. Just copy and paste it.
#!/bin/bash
# 不要忘了改成自己的集群地址
NACOS_DIR_1="/usr/local/nacoscluster/nacos8848/bin"
NACOS_DIR_2="/usr/local/nacoscluster/nacos8850/bin"
NACOS_DIR_3="/usr/local/nacoscluster/nacos8852/bin"
start_instances() {
start_instance $NACOS_DIR_1
start_instance $NACOS_DIR_2
start_instance $NACOS_DIR_3
}
start_instance() {
local nacos_dir=$1
cd $nacos_dir
./startup.sh > /dev/null 2>&1 &
echo "Nacos instance at $nacos_dir started."
}
stop_instances() {
stop_instance $NACOS_DIR_1
stop_instance $NACOS_DIR_2
stop_instance $NACOS_DIR_3
}
stop_instance() {
local nacos_dir=$1
cd $nacos_dir
./shutdown.sh
echo "Nacos instance at $nacos_dir stop success."
}
case "$1" in
start)
start_instances
;;
stop)
stop_instances
;;
restart)
stop_instances
sleep 3
start_instances
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
2. In the terminal, use the following command to grant execution permissions to the sh file:
chmod +x nacos_cluster.sh
3. Now, you can run
./nacos_cluster.sh start 启动集群
./nacos_cluster.sh stop 停止集群
./nacos_cluster.sh restart 重启集群