zoukankan      html  css  js  c++  java
  • centos 添加开启开机自启脚本

    通过chkconfig命令

    centos 设置服务开机自动启动的方式有好多种,这里介绍一下通过chkconfig命令添加脚本为开机自动启动的方法。

    编写脚本autostart.sh(这里以开机启动redis服务为例),脚本内容如下:

    #!/bin/sh
    #chkconfig: 2345 80 90
    #description:开机自启动脚本 power by https://www.shangmayuan.com
    
    # redis
    cd /data1/redis
    redis-server /data1/redis/redis.conf

    脚本第一行 “#!/bin/sh” 告诉系统使用的shell;
    脚本第二行 “#chkconfig: 2345 80 90” 表示在2/3/4/5运行级别启动,启动序号(S80),关闭序号(K90);
    脚本第三行 表示的是服务的描述信息
    注意: 第二行和第三行必写,负责会出现如“服务 autostart.sh 不支持 chkconfig”这样的错误。

    将写好的autostart.sh脚本移动到/etc/rc.d/init.d/目录下,并给脚本赋可执行权限

    chmod +x autostart.sh

    添加脚本到开机自动启动项目中

    chkconfig --add autostart.sh
    chkconfig autostart.sh on

    学习笔记

  • 相关阅读:
    Ubuntu 各版本代号简介
    Ubuntu如何同步网络时间
    Ubuntu下修改DNS重启也能用的方法
    provider networks和self-service networks
    openstack 架构
    系统故障排除
    系统日志管理
    系统引导
    网络管理
    Linux下开启FTP服务
  • 原文地址:https://www.cnblogs.com/TF511/p/14718357.html
Copyright © 2011-2022 走看看