Chinaunix首页 | 论坛 | 博客
  • 博客访问: 439225
  • 博文数量: 52
  • 博客积分: 1076
  • 博客等级: 准尉
  • 技术积分: 821
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-18 20:05
个人简介

Hello World !

文章分类

全部博文(52)

文章存档

2016年(1)

2014年(1)

2013年(8)

2012年(38)

2011年(4)

分类: LINUX

2013-03-20 23:21:06

[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后,环境变量无效
[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]#

点击(此处)折叠或打开

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

  7. # source function library.
  8. . /etc/rc.d/init.d/functions
  9. # check that networking is up.
  10. [ "${NETWORKING}" = "no" ] && exit 0
  11. # check for tomcat script
  12. if [ ! -f $CATALINA_HOME/bin/catalina.sh ]; then
  13.          echo "Tomcat not valilable..."
  14.         exit
  15. fi
  16. start(){
  17.         echo -n "Starting Tomcat: "
  18.         daemon $TOMCAT_START
  19.         echo
  20.         touch /var/lock/subsys/tomcat
  21. }
  22. stop(){
  23.         ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}' \
  24.  | wc | awk '{print $2}' > /tmp/tomcat_process_count.txt
  25.         read line < /tmp/tomcat_process_count.txt
  26.         if [ $line -gt 0 ]; then
  27.                 echo -n "tomcat ( pid "
  28.                 ps ax --width=1000 | grep "org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
  29.                 echo -n ") is running..."
  30.                 echo
  31.                 
  32.                 echo -n $"Shutting down Tomcat: "
  33.                 daemon $TOMCAT_STOP
  34.                 rm -f /var/lock/subsys/tomcat.pid echo
  35.         else
  36.                 echo "Tomcat is stopped"
  37.         fi
  38.         
  39.         
  40. }
  41. restart(){
  42.         stop
  43.         start
  44. }
  45. status(){
  46.         ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}' \
  47.  | wc | awk '{print $2}' > /tmp/tomcat_process_count.txt
  48.         read line < /tmp/tomcat_process_count.txt
  49.         if [ $line -gt 0 ]; then
  50.                 echo -n "tomcat ( pid "
  51.                 ps ax --width=1000 | grep "org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
  52.                 echo -n ") is running..."
  53.                 echo
  54.         else
  55.                 echo "Tomcat is stopped"
  56.         fi
  57. }
  58. case "$1" in
  59.         start)
  60.                 start ;;
  61.         stop)
  62.                 stop ;;
  63.         restart)
  64.                 stop
  65.                 sleep 3
  66.                 start ;;
  67.         status)
  68.                 status ;;
  69.         *)
  70.                 echo "Usage: tomcatd {start|stop|restart|status}"
  71.                 exit 1
  72. esac
  73. exit 0
  74. #=======tomcat7 Service Script=====================================================================

阅读(13766) | 评论(4) | 转发(3) |
给主人留下些什么吧!~~

geeksun2015-08-27 11:12:46

我按照配置文件设置后,启动: service tomcat, 提示下面错误:
Starting Tomcat: Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
                                          &nb

likeilinux2013-03-26 16:23:41

在脚本前面需要加入下面三行才能将tomcat7加入开机启动
#!/bin/bash
# chkconfig: 2345 10 90 
# description:Tomcat service

likeilinux2013-03-21 22:44:56

怎么了,请指出???

天仙宝宝122013-03-21 14:11:32

文明上网,理性发言...