首页 > 代码库 > cenOS系统,chkconfig设置程序开机自启--mysql、tomcat、redis、fastdfs--nginx/fdfs_trackerd/fdfs_storaged

cenOS系统,chkconfig设置程序开机自启--mysql、tomcat、redis、fastdfs--nginx/fdfs_trackerd/fdfs_storaged

设置程序开机启动就是将程序的启动脚本添加到/etc/init.d目录下,或者将启动路径写入/etc/rc.d/rc.local文件里面.

设置mysql开机启动

cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysql   chkconfig --add mysql  chkconfig  mysql  on

设置fdfs_tracker开机启动

cp /usr/local/src/FastDFS/init.d/fdfs_trackerd /etc/init.d/chkconfig --add fdfs_trackerdchkconfig fdfs_trackerd on

设置fdfs_storafed开机启动

cp /usr/local/src/FastDFS/init.d/fdfs_storaged /etc/init.d/chkconfig --add fdfs_storagedchkconfig fdfs_storaged on

 设置redis开机启动

cp  /usr/local/src/redis-stable/utils./install_server.sh 

具体配置可以详见http://www.open-open.com/lib/view/open1355055890117.html

设置tomcat开机启动

在startup.sh文件中添加如下内容

vim  /usr/local/tomcat/bin/startup.shi            //代表进入文档输入模式#!/bin/sh                 //#不能少# chkconfig: 2345 97 00  # description:tomcat auto start# processname: tomcat

 在catalina.sh文件中增加如下内容

vim  /usr/local/tomcat/bin/catalina.shi                                                //进入输入模式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                                              //按esc键:wq                                          //保存并退出

创建软连接

ln -s /usr/local/tomcat/bin/startup.sh /etc/init.d

 设置启动

chkconfig --add tomcatchkconfig tomcat on

设置nginx开机启动

在/etc/init.d目录下新建nginx文档

vim /etc/init.c/ngin 

写入一下命令并保存

#!/bin/bash# nginx Startup script for the Nginx HTTP Server# it is v.0.0.2 version.# chkconfig: - 85 15# description: Nginx is a high-performance web and proxy server.#              It has a lot of features, but its not for everyone.# processname: nginx# pidfile: /usr/local/nginx/logs/nginx.pid    //根据实际情况修改# config: /usr/local/nginx/conf/nginx.conf     //根据实际情况修改nginxd=/usr/local/nginx/sbin/nginx    //根据实际情况修改nginx_config=/usr/local/nginx/conf/nginx.conf    //根据实际情况修改nginx_pid=/usr/local/nginx/logs/nginx.pid    //根据实际情况修改RETVAL=0prog="nginx"# Source function library.. /etc/rc.d/init.d/functions# Source networking configuration.. /etc/sysconfig/network# Check that networking is up.[ ${NETWORKING} = "no" ] && exit 0[ -x $nginxd ] || exit 0# Start nginx daemons functions.start() {if [ -e $nginx_pid ];then   echo "nginx already running...."   exit 1fi   echo -n $"Starting $prog: "   daemon $nginxd -c ${nginx_config}   RETVAL=$?   echo   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx   return $RETVAL}# Stop nginx daemons functions.stop() {        echo -n $"Stopping $prog: "        killproc $nginxd        RETVAL=$?        echo        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx  /usr/local/nginx/logs/nginx.pid    //根据实际情况修改}# reload nginx service functions.reload() {    echo -n $"Reloading $prog: "    #kill -HUP `cat ${nginx_pid}`    killproc $nginxd -HUP    RETVAL=$?    echo}# See how we were called.case "$1" instart)        start        ;;stop)        stop        ;;reload)        reload        ;;restart)        stop        start        ;;status)        status $prog        RETVAL=$?        ;;*)        echo $"Usage: $prog {start|stop|restart|reload|status|help}"       exit 1esacexit $RETVAL

 设置开启启动

chkconfig --add  nginxchkconfig nginx on