1. 程式人生 > 其它 >linux下自啟動mysql和tomcat

linux下自啟動mysql和tomcat

技術標籤:學習筆記linux

一、自啟動mysql

  1. 將/usr/local/mysql/mysql/support-files/ 資料夾下的mysql.server檔案複製到/etc/rc.d/init.d/ 目錄下mysqld,執行linux命令:
    cp /usr/local/mysql/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld

  2. 賦予可執行許可權:
    chmod +x /etc/init.d/mysqld

  3. 新增服務自啟動列表:
    chkconfig --add mysqld

    檢視自啟動服務列表:

    chkconfig --list

二.自啟動tomcat

1.把tomcat先做成一個服務,使其可以通過service 來啟動和停止tomcat服務

進入/etc/init.d目錄

cd /etc/init.d

建立tomcat檔案

vim tomcat

tomcat內容如下:


#!/bin/sh -e
#chkconfig: 2345 80 90    
#description:tomcat auto start    
#processname: tomcat
 
export JAVA_HOME=/usr/work/jdk1.8.0
export JRE_HOME=$JAVA_HOME/jre
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.
export CATALINA_HOME=/usr/work/tomcat
 
case "$1" in
start)
        ${CATALINA_HOME}/bin/startup.sh
        exit 0
        ;;
stop)
        ${CATALINA_HOME}/bin/shutdown.sh
        exit 0
        ;;
debug)
        ${CATALINA_HOME}/bin/shutdown.sh
        ${CATALINA_HOME}/bin/catalina.sh run
        exit 0
        ;;
force-reload|restart)
        ${CATALINA_HOME}/bin/startup.sh
        ${CATALINA_HOME}/bin/shutdown.sh
        exit 0
        ;;
 
*)
        echo "Usage: /etc/init.d/tomcat {start|stop|restart|force-reload|debug}"
        exit 1
        ;;
esac
 
exit 0

為tomcat新增可執行許可權

chmod +x /etc/init.d/tomcat

把tomcat新增自啟動列表

chkconfig --add tomcat

重啟伺服器

reboot

伺服器啟動好了,可以通過如下命令停止tomcat服務

service tomcat stop

可以通過如下命令啟動tomcat服務

service tomcat start