Linux の sh ファイルは、単一マシンの Nacos クラスターの起動とシャットダウンを管理します

注:
システムにjdkがインストールされ、環境変数が設定されていることが前提
環境:CentOS8.5 スタンドアロン擬似クラスタ
nacosバージョン:2.2.0

  1. nacos_cluster.sh を作成します。以下はすべてのテキストですので、コピーして貼り付けるだけです。
#!/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. ターミナルで次のコマンドを使用して、sh ファイルに実行権限を付与します。

 chmod +x  nacos_cluster.sh

3. これで、実行できます

./nacos_cluster.sh start 启动集群
./nacos_cluster.sh stop 停止集群
./nacos_cluster.sh restart  重启集群

おすすめ

転載: blog.csdn.net/qq_37120477/article/details/131652368