centos 配置服务的自动启动(mysql,tomcat)

来源:互联网 发布:蒂灵沙在淘宝怎么买 编辑:程序博客网 时间:2024/05/18 02:34

场景:在安装好服务如mysql,tomcat等的服务器,如果有的时候需要重启,这个时候如果可以自动启动服务,可以提升服务效率

处理方案:
1、安装好特定服务,可以启动和关闭成功;
2、配置启动,关闭和重启的特定服务脚本到 /etc/init.d/ 下;
3、授予 执行的权限 chmod +x mysql/tomcat;
4、把服务加入到:chkconfig -add mysql;
5、启动服务:chkconfig mysql on;
6、重启测试:service mysql start/stop/restart;

mysql配置
1、cp support-files/mysql.server /etc/init.d/mysql
2、chmod +x /etc/init.d/mysql
3、chkconfig -add mysql;
4、chkconfig mysql on;
5、service mysql start/stop;

tomcat 配置:
1、配置脚本:

#!/bin/sh# chkconfig: 2345 10  80# description: Auto-starts tomcat# /etc/init.d/tomcat61# Tomcat auto-start# Source function library.#. /etc/init.d/functions# source networking configuration.#. /etc/sysconfig/networkRETVAL=0#export JDK_HOME=/data0/jdk1.8.0_72export CATALINA_HOME=/data0/apache-tomcat-8.0.32-syscoreexport CATALINA_BASE=/data0/apache-tomcat-8.0.32-syscorestart(){        if [ -f $CATALINA_HOME/bin/startup.sh ];          then            echo $"Starting Tomcat"                $CATALINA_HOME/bin/startup.sh            RETVAL=$?            echo " OK"            return $RETVAL        fi}stop(){        if [ -f $CATALINA_HOME/bin/shutdown.sh ];          then            echo $"Stopping Tomcat"                $CATALINA_HOME/bin/shutdown.sh            RETVAL=$?            sleep 1            ps -ef tomcat | grep $CATALINA_HOME |grep -v grep | grep -v PID | awk '{print $2}'|xargs kill -9            echo " OK"            # [ $RETVAL -eq 0 ] && rm -f /var/lock/...            return $RETVAL        fi}case "$1" in start)        start        ;; stop)        stop        ;; restart)         echo $"Restaring Tomcat"         $0 stop         sleep 1         $0 start         ;; *)        echo $"Usage: $0 {start|stop|restart}"        exit 1        ;;esacexit $RETVAL

2、授权 chmod +x tomcat
3、chkconfig -add tomcat;
4、chkconfig tomcat on;
5、service tomcatstart/stop;

0 0
原创粉丝点击