安装JDK, 注意操作系统的位数, 64 or 32:
# mkdir /usr/java # cd /usr/java #rpm -Uvh /bak/jdk-7u55-linux-x64.rpm # vi /etc/profile JAVA_HOME=/usr/java/jdk1.7.0_55 export JAVA_HOME CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export CLASSPATH PATH=$JAVA_HOME/bin:$PATH export PATH # source /etc/profile # echo $JAVA_HOME /usr/java/jdk1.7.0_55
2. 建组建用户,查看,设置密码
# groupadd webserver # useradd -m -g webserver -G webserver webapp # id webapp # passwd webapp # vi /etc/sudoers
找到此行,
root ALL=(ALL) ALL
添加:
webapp ALL=(ALL) ALL
3. 建目录,变更权限,安装tomcat7
# mkdir /usr/local/tomcat # chown -R webapp:webserver /usr/local/tomcat # su webapp
4. 使用webapp权限将apache-tomcat-7.0.53.tar.gz放到/usr/local/tomcat
$ cd /usr/local/tomcat $ tar -zxvf apache-tomcat-6.0.36.tar.gz $ vi ~/.bash_profile CATALINA_BASE=/usr/local/tomcat/apache-tomcat-7.0.53 CATALINA_HOME=/usr/local/tomcat/apache-tomcat-7.0.53 PATH=$PATH:$HOME/bin:$CATALINA_HOME/bin export PATH $source ~/.bash_profile CATALINA_BASE=/usr/local/tomcat/apache-tomcat-6.0.36 CATALINA_HOME=/usr/local/tomcat/apache-tomcat-6.0.36 PATH=$PATH:$HOME/bin:$CATALINA_HOME/bin export PATH $source ~/.bash_profile
5. 修改tomcat配置文件tomcat-users.xml,补充如下内容:
<role rolename="manager-gui"/> <role rolename="admin-gui"/> <user username="webapp" password="password" roles="manager-gui,admin-gui"/>
6. 设置tomcat启动服务:
# cd /etc/init.d # vi tomcat
脚本内容如下:
#!/bin/bash # chkconfig: 2345 10 90 # description: Starts and Stops the Tomcat daemon. CATALINA_HOME=/usr/local/tomcat/apache-tomcat-7.0.53 JAVA_HOME=/usr/java/jdk1.7.0_55 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
保存退出后,修改文件属性
#chmod a+x tomcat
设置服务运行
#chkconfig --add tomcat
启动:
#service tomcat start
原文:http://my.oschina.net/u/221951/blog/344061