cenOS设置程序开机自启动的方法
cenOS设置程序开机自启动的方法主要有两种
1.把启动程序的命令添加到/etc/rc.d/rc.local 文件夹中.
eg1.设置开机启动mysql
vim /etc/rc.d/rc.local #!/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/mysql/bin/mysql start
eg2.设置开机启动tomcat
vim /etc/rc.d/rc.local # 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. export CATALINA_BASE=/usr/local/tomcat/ export CATALINA_HOME=/usr/local/tomcat/ export CATALINA_TMPDIR=/usr/local/tomcat/temp export JRE_HOME=/usr/java/jdk1.7.0_55/
#tomcat自启动
/usr/local/tomcat/bin/startup.sh start
touch /var/lock/subsys/local --此句如果文档里面有,无需再写
2、把写好的启动脚本添加到目录/etc/rc.d/init.d/,然后使用命令chkconfig设置开机启动。(推荐)
chkconfig 功能说明:检查,设置系统的各种服务。
语法:chkconfig [--add][--del][--list][系统服务] 或 chkconfig [--level <等级代号>][系统服务][on/off/reset]
--add 添加服务
--del 删除服务
--list 查看各服务启动状态
eg1.设置redis自启动
redis在首次安装的时候就可以设置为自启动
url:
http://www.open-open.com/lib/view/open1355055890117.html
#测试redis的启动
redis-cli redis 127.0.0.1:6379> set foo 123 OK redis 127.0.0.1:6379> get foo "123" redis 127.0.0.1:6379> exit
eg2.fastdfs开机自启动
[root@localhost ~]# cp /usr/local/src/FastDFS/init.d/fdfs_storaged /etc/init.d/ [root@localhost ~]# chkconfig --add fdfs_storaged [root@localhost ~]# chkconfig fdfs_storaged on [root@localhost ~]# service fdfs_storaged start
###############################如果是使用chkconfig命令来将tomcat设置为自启动############################
1、修改start.sh文件
vim /home/wwwroot/tomcat_wiki/bin/startup.sh
在文件头增加以下内容:
#!/bin/sh
# chkconfig: 2345 97 00 # description:tomcat auto start #processname: tomcat
2、修改catalina.sh文件
vim /home/wwwroot/tomcat_wiki/bin/catalina.sh
增加以下内容:
export CATALINA_BASE=/home/wwwroot/tomcat_wiki export CATALINA_HOME=/home/wwwroot/tomcat_wiki export CATALINA_TMPDIR=/home/wwwroot/tomcat_wiki/temp export JRE_HOME=/usr/local/jdk1.6.0_37
3、创建链接文件
ln –s /home/wwwroot/tomcat_wiki/bin/startup.sh /etc/init.d/tomcat
4、修改权限
chmod +x tomcat
5、添加启动
chkconfig –add tomcat(add前是两个减号)
chkconfig tomcat on
6、检查
service tomcat start
或者reboot