Linux配置tomcat,redis自启动

Linux配置tomcat,redis自启动

tomcat自启动

1.配置java环境

[$ root]vim /etc/profile
插入下方代码:(根据jdk安装目录配置java环境)
export JAVA_HOME=/usr/local/apps/jdk1.8

export JAVA_BIN=/usr/local/apps/jdk1.8/bin

export PATH=$PATH:$JAVA_HOME/bin

export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

export JAVA_HOME JAVA_BIN PATH CLASSPATH 

Linux配置tomcat,redis自启动_第1张图片

2.启动tomcat

进入tomcat中的bin目录,并输入./startup.sh 屏幕输出如下说明tomcat已启动。
在这里插入图片描述

3.配置tomcat开机自启动

1. cd  /etc/rc.d/init.d
2. vim rtlsmgr 
3. 粘贴下面代码保存
4. 设置权限  chmod 777 /etc/rc.d/init.d/tomcat
5. 设置开机自启动  sudo  chkconfig tomcat on
6. 验证:重启服务器访问
#!/bin/sh
# chkconfig: 345 99 10
# description: Auto-starts tomcat
# /etc/init.d/tomcat
# Tomcat auto-start
# Source function library.
#. /etc/init.d/functions
# source networking configuration.
#. /etc/sysconfig/network
 
export JAVA_HOME=/usr/local/apps/jdk1.8
export JRE_HOME=$JAVA_HOME/jre
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.
export CATALINA_HOME=/usr/local/apps/tomcat
 
case "$1" in
start)
        sleep 30   
        ${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/rc.d/init.d/tomcat{start|stop|restart|force-reload|debug}"
        exit 1
        ;;
esac
exit 0

redis开机自启动

redis的安装需要gcc环境,安装步骤省略

配置开机自启动
键入:         vi /etc/rc.d/init.d/redis  (粘贴下方代码:修改redis安装目录)
修改文件权限:  chmod 777 /etc/rc.d/init.d/redis
添加到服务:    chkconfig  redis  on
              chkconfig  --add  redis
              chkconfig  list
开启服务:      service  redis   start 
#!/bin/bash
#chkconfig:   2345 90 10
# description:  Redis is a persistent key-value database
PATH=/usr/local/bin:/sbin:/usr/bin:/bin   
REDISPORT=6379  
EXEC=/usr/local/apps/redis/src/redis-server   
REDIS_CLI=/usr/local/apps/redis/src/redis-cli
PIDFILE=/var/run/redis.pid   
CONF="/usr/local/apps/redis/redis.conf"  
AUTH="1234"  
case "$1" in   
        start)   
                if [ -f $PIDFILE ]   
                then   
                        echo "$PIDFILE exists, process is already running or crashed."  
                else  
                        echo "Starting Redis server..."  
                        $EXEC $CONF   &
                fi   
                if [ "$?"="0" ]   
                then   
                        echo "Redis is running..."  
                fi   
                ;;   
        stop)   
                if [ ! -f $PIDFILE ]   
                then   
                        echo "$PIDFILE exists, process is not running."  
                else  
                        PID=$(cat $PIDFILE)   
                        echo "Stopping..."  
                       $REDIS_CLI -p $REDISPORT  SHUTDOWN    
                        sleep 2  
                       while [ -x $PIDFILE ]   
                       do  
                                echo "Waiting for Redis to shutdown..."  
                               sleep 1  
                        done   
                        echo "Redis stopped"  
                fi   
                ;;   
        restart|force-reload)   
                ${0} stop   
                ${0} start   
                ;;   
        *)   
               echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2  
                exit 1  
esac

你可能感兴趣的:(linux)