在Linux Tomcat7怎样安装配置注册服务

由于Tomcat需要JDK的支持,所以在安装Tomcat之前需要先安装JDK。假如安装了JDK则跳过该步,直接看安装Tomcat7。

[root@demo tomcat7]# pwd

/opt/tomcat7
[root@demo tomcat7]# ls
bin   lib      logs    RELEASE-NOTES  temp     work
conf  LICENSE  NOTICE  RUNNING.txt    webapps
[root@demo jdk1.7.0_17]# ls
bin        lib          src.zip
COPYRIGHT  LICENSE      THIRDPARTYLICENSEREADME-JAVAFX.txt
db         man          THIRDPARTYLICENSEREADME.txt
include    README.html
jre        release
[root@demo jdk1.7.0_17]# pwd
/opt/jdk1.7.0_17

全局环境变量:
vi /etc/profile在最后添加
[root@demo etc]# tail -n 4 /etc/profile
export JAVA_HOME=/opt/jdk1.7.0_17
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin:/opt/tomcat7/bin
export JRE_HOME=$JAVA_HOME/jre

只更改root环境变量
[root@demo ~]# vi .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export JAVA_HOME=/opt/jdk1.7.0_17
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin:/opt/tomcat7/bin
export JRE_HOME=$JAVA_HOME/jre

添加临时环境变量,关闭当前bash后,环境变量无效 VPS
[root@demo bin]# export JAVA_HOME=/opt/jdk1.7.0_17
[root@demo bin]# export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
[root@demo bin]# export PATH=$PATH:$JAVA_HOME/bin:/opt/tomcat7/bin
[root@demo bin]# export JRE_HOME=$JAVA_HOME/jre

[root@Test init.d]# vi /etc/init.d/tomcat7    
内容文末附有
[root@Test init.d]# chkconfig --add tomcat7
[root@Test init.d]# chkconfig --list |grep tomcat7
tomcat7         0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@Test init.d]# service tomcat7 restart
tomcat ( pid 9106 9144 ) is running...
Shutting down Tomcat: Using CATALINA_BASE:   /opt/tomcat7
Using CATALINA_HOME:   /opt/tomcat7
Using CATALINA_TMPDIR: /opt/tomcat7/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /opt/tomcat7/bin/bootstrap.jar:/opt/tomcat7/bin/tomcat-juli.jar
Starting Tomcat: Using CATALINA_BASE:   /opt/tomcat7       [  OK  ]
Using CATALINA_HOME:   /opt/tomcat7
Using CATALINA_TMPDIR: /opt/tomcat7/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /opt/tomcat7/bin/bootstrap.jar:/opt/tomcat7/bin/tomcat-juli.jar
                                                           [  OK  ]
[root@Test init.d]# service tomcat7 stop
tomcat ( pid 9192 9224 ) is running...
Shutting down Tomcat: Using CATALINA_BASE:   /opt/tomcat7
Using CATALINA_HOME:   /opt/tomcat7
Using CATALINA_TMPDIR: /opt/tomcat7/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /opt/tomcat7/bin/bootstrap.jar:/opt/tomcat7/bin/tomcat-juli.jar
[root@Test init.d]# service tomcat7 restart                [  OK  ]
Tomcat is stopped
Starting Tomcat: Using CATALINA_BASE:   /opt/tomcat7
Using CATALINA_HOME:   /opt/tomcat7
Using CATALINA_TMPDIR: /opt/tomcat7/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /opt/tomcat7/bin/bootstrap.jar:/opt/tomcat7/bin/tomcat-juli.jar
                                                           [  OK  ]
[root@Test init.d]# service tomcat7 start
Starting Tomcat: Using CATALINA_BASE:   /opt/tomcat7
Using CATALINA_HOME:   /opt/tomcat7
Using CATALINA_TMPDIR: /opt/tomcat7/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /opt/tomcat7/bin/bootstrap.jar:/opt/tomcat7/bin/tomcat-juli.jar
                                                           [  OK  ]
[root@Test init.d]#

点击(此处)折叠或打开

    #=======tomcat7 Service Script=====================================================================
    [root@Test init.d]# vi /etc/init.d/tomcat7
    CATALINA_HOME=/opt/tomcat7
    JAVA_HOME=/opt/jdk1.7.0_17
    TOMCAT_START=$CATALINA_HOME/bin/startup.sh
    TOMCAT_STOP=$CATALINA_HOME/bin/shutdown.sh

    # source function library.
    . /etc/rc.d/init.d/functions
    # check that networking is up.
    [ "${NETWORKING}" = "no" ] && exit 0
    # check for tomcat script
    if [ ! -f $CATALINA_HOME/bin/catalina.sh ]; then
             echo "Tomcat not valilable..."
            exit
    fi
    start(){
            echo -n "Starting Tomcat: "
            daemon $TOMCAT_START
            echo
            touch /var/lock/subsys/tomcat
    }
    stop(){
            ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}' \
     | wc | awk '{print $2}' > /tmp/tomcat_process_count.txt
            read line < /tmp/tomcat_process_count.txt
            if [ $line -gt 0 ]; then
                    echo -n "tomcat ( pid "
                    ps ax --width=1000 | grep "org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
                    echo -n ") is running..."
                    echo
                    
                    echo -n $"Shutting down Tomcat: "
                    daemon $TOMCAT_STOP
                    rm -f /var/lock/subsys/tomcat.pid echo
            else
                    echo "Tomcat is stopped"
            fi
            
            
    }
    restart(){
            stop
            start
    }
    status(){
            ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}' \
     | wc | awk '{print $2}' > /tmp/tomcat_process_count.txt
            read line < /tmp/tomcat_process_count.txt
            if [ $line -gt 0 ]; then
                    echo -n "tomcat ( pid "
                    ps ax --width=1000 | grep "org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
                    echo -n ") is running..."
                    echo
            else
                    echo "Tomcat is stopped"
            fi
    }
    case "$1" in
            start)
                    start ;;
            stop)
                    stop ;;
            restart)
                    stop
                    sleep 3
                    start ;;
            status)
                    status ;;
            *)
                    echo "Usage: tomcatd {start|stop|restart|status}"
                    exit 1
    esac
    exit 0
    #=======tomcat7 Service Script
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值