在CentOS系统下,主要有两种方法设置自己安装的程序开机启动。
1、把启动程序的命令添加到/etc/rc.d/rc.local文件中,比如下面的是设置开机启动httpd。
#!/bin/sh # # This script will be executed *after* all the other init scripts. # You can put your own initialization stuff in here if you don't # want to do the full Sys V style init stuff. touch /var/lock/subsys/local /usr/local/apache/bin/apachectl start
2、把写好的启动脚本添加到目录/etc/rc.d/init.d/,然后使用命令chkconfig设置开机启动。
chkconfig 功能说明:检查,设置系统的各种服务。
语法:chkconfig [--add][--del][--list][系统服务] 或 chkconfig [--level <等级代号>][系统服务][on/off/reset]
--add 添加服务
--del 删除服务
--list 查看各服务启动状态
比如我们设置自启动mysql:
#将mysql启动脚本放入所有脚本运行目录/etc/rc.d/init.d中 cp /lamp/mysql-5.0.41/support-files/mysql.server /etc/rc.d/init.d/mysqld #改变权限 chown root.root /etc/rc.d/init.d/mysqld #所有用户都可以执行,单只有root可以修改 chmod 755 /etc/rc.d/init.d/mysqld #将mysqld 放入linux启动管理体系中 chkconfig --add mysqld #查看全部服务在各运行级状态 chkconfig --list mysqld #只要运行级别3启动,其他都关闭 chkconfig --levels 245 mysqld off
例如:我们把httpd的脚本写好后放进/etc/rc.d/init.d/目录,使用
chkconfig --add httpd chkconfig httpd on
命令即设置好了开机启动。
3、把启动程序的命令添加到/etc/rc.d/rc.sysinit 文件中
脚本/etc/rc.d/rc.sysinit,完成系统服务程序启动,如系统环境变量设置、设置系统时钟、加载字体、检查加载文件系统、生成系统启动信息日志文件等
比如我们设置自启动apache:
echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.sysinit
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持华域联盟。
您可能感兴趣的文章:
- 详解Centos7中Nginx开机自启动的解决办法
- centos7系统下nginx安装并配置开机自启动操作
- CentOS 7安装Mysql并设置开机自启动的方法
- Centos下配置Redis开机启动脚本
- centos 6.5 oracle开机自启动的环境配置详解
- 详解Centos7下配置Redis并开机自启动
- CentOS 开机启动自定义脚本详解及实现
- nginx centos 服务开机启动设置实例详解
- Centos 6和Centos 7下服务启动方法及添加到开机启动项的方法
- CentOS6 配置Nginx,MySql,php-fpm开机启动的方法
- Centos7开机启动自己的脚本的方法
本文由 华域联盟 原创撰写:华域联盟 » 详解CentOS设置程序开机自启动的方法
转载请保留出处和原文链接:https://www.cnhackhy.com/56055.htm