`
lcyaiym
  • 浏览: 26928 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

CentOS 开机启动

 
阅读更多

欢迎访问我的个人博客网站:http://www.yanmin99.com/

一、开机启动介绍

  • 在CentOS或者RedHat其他系统下,如果是后面安装的服务,如httpd、mysqld、postfix等,安装后系统默认不会自动启动的。就算手动执行 /etc/init.d/mysqld start 启动了服务,只要服务器重启后,系统仍然不会自动启动服务。

二、CentOS设置自动启动方式

1、CentOS7之前

  • A、利用 chkconfig 来配置启动级别

    • chkconfig介绍

      chkconfig –-add xxx //把服务添加到chkconfig列表
      chkconfig --del xxx //把服务从chkconfig列表中删除
      chkconfig xxx on //开启开机自动启动
      chkconfig xxx off //关闭开机自动启动
      chkconfig --list //查看所有chklist中服务
      chkconfig --list xxx 查看指定服务
    • chkconfig实例

      //把nginx添加到chkconfig中
      chkconfig --add nginx
      //查看nginx是否在chkconfig中(添加进去默认设置自动启动)
      chkconfig --list nginx
      //2~5都是on,就表明会自动启动了
      nginx 0:off 1:off   2:on    3:on    4:on    5:on    6:off
      //开启开机启动
      chkconfig nginx on
      //关闭开机启动
      chkconfig nginx off
      chkconfig --del nginx
  • B、修改 /etc/rc.d/rc.local

    /etc/rc.d/init.d/nginx start

CentOS7

  • 方案一

    • 赋予脚本可执行权限(/opt/script/autostart.sh是你的脚本路径)

      chmod +x /opt/script/autostart.sh
    • 打开/etc/rc.d/rc/local文件,在末尾增加如下内容

      /opt/script/autostart.sh
    • 在centos7中,/etc/rc.d/rc.local的权限被降低了,所以需要执行如下命令赋予其可执行权限

      chmod +x /etc/rc.d/rc.local
  • 方案二

    • 将脚本移动到/etc/rc.d/init.d目录下

      mv /opt/script/autostart.sh /etc/rc.d/init.d
    • 增加脚本的可执行权限

      chmod +x /etc/rc.d/init.d/autostart.sh
    • 添加脚本到开机自动启动项目中

      cd /etc/rc.d/init.d
      chkconfig --add autostart.sh
      chkconfig autostart.sh on
<script type="text/javascript"> $(function () { $('pre.prettyprint code').each(function () { var lines = $(this).text().split('\n').length; var $numbering = $('<ul/>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('<li/>').text(i)); }; $numbering.fadeIn(1700); }); }); </script>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics