1. 编写需要执行的shell脚本
    • 脚本规范:

      • 第一行(#!/bin/sh),指定解释器
      • 第二行(#chkconfig: 2345 80 90),表示在2/3/4/5运行级别启动,启动序号(S80),关闭序号(K90)
      1. redis

        1. #!/bin/sh
        2. #chkconfig: 2345 80 90
        3. /home/cluster/redis-5.0.5/src/redis-server /home/cluster/redis-5.0.5/redis-cluster/6379/redis.conf
        4. /home/cluster/redis-5.0.5/src/redis-server /home/cluster/redis-5.0.5/redis-cluster/6380/redis.conf
      2. nacos

        1. #!/bin/sh
        2. #chkconfig: 2345 80 90
        3. # 环境变量
        4. export PATH=$PATH:/home/jdk1.8.0_172/bin
        5. /home/nacos/bin/startup.sh
      3. keepalived

    1. 复制脚本至系统目录下

      1. cp ***.sh /etc/init.d
    2. 脚本授权可执行

      1. chmod +x ***.sh
    3. 将脚本加入开机启动项中

      1. chkconfig --add ***.sh
    4. 查看日志 ```bash journalctl -u *

    systemctl status *

    1. 6. 常用命令
    2. ```shell
    3. # 启动服务
    4. systemctl start postfix.service
    5. # 关闭服务
    6. systemctl stop postfix.service
    7. # 重启服务
    8. systemctl restart postfix.service
    9. # 显示服务的状态
    10. systemctl status postfix.service
    11. 管理服务自启动
    12. # 在开机时启用服务
    13. systemctl enable postfix.service
    14. # 在开机时禁用服务
    15. systemctl disable postfix.service
    16. # 查看服务是否开机启动
    17. systemctl is-enabled postfix.service
    18. # 查看开机自启动的服务列表
    19. systemctl list-unit-files | grep enabled
    20. # 查看启动失败的服务列表
    21. systemctl --failed