tar.gz方式安装nacos设置使用systemct进行service方式的管理并设置开机自启动

nacos解压缩目录是:/opt/nacos

编写shell脚本

# vim /opt/nacos/bin/nacos.sh

#!/bin/bash

source /etc/profile
workDir=/opt/nacos/bin/

start(){
    cd ${workDir} && bash ./startup.sh > ../logs/startup_nacos.log 2>&1 &
}

stop(){
    cd ${workDir} && bash ./shutdown.sh > ../logs/shutdown_nacos.log 2>&1 &
}

case $1 in
    "start")
        start
        ;;
    "stop")
        stop
        ;;
    "restart")
        stop
        start
        ;;
esac

# chmod 777 /opt/nacos/bin/nacos.sh

编写service文件

# vim /usr/lib/systemd/system/nacos.service

[Unit]
Description=uams server
Wants=network-online.target
After=network.target

[Service]
Type=forking
WorkingDirectory=/opt/nacos/bin/
ExecStart=/bin/bash nacos.sh start
ExecStop=/bin/bash nacos.sh stop
ExecReload=/bin/bash nacos.sh restart
Restart=on-failure

[Install]
WantedBy=multi-user.target

# 重载
systemctl daemon-reload

systemctl restart nacos  #启动
systemctl enable nacos   #配置自启
systemctl stop  nacos   #停止服务
systemctl status  nacos  #检测状态
上一篇:第02章_MySQL环境搭建


下一篇:Docker 基本管理