标签:web
查看系统信息:
[root@node120 ~]# uname -a Linux node120 3.10.0-327.10.1.el7.x86_64 #1 SMP Tue Feb 16 17:03:50 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux [root@node120 ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core)
安装jdk:
[root@node120 ~]# rpm -ivh jdk-8u73-linux-x64.rpm [root@node120 ~]# vim /etc/profile export JAVA_HOME=/usr/java/jdk1.8.0_73 export JAVA_BIN=/usr/java/jdk1.8.0_73/bin export PATH=${JAVA_HOME}/bin:$PATH export CLASSPATH=.:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar
[root@node120 ~]# source /etc/profile [root@node120 ~]# java -version java version "1.8.0_73" Java(TM) SE Runtime Environment (build 1.8.0_73-b02) Java HotSpot(TM) 64-Bit Server VM (build 25.73-b02, mixed mode)
[root@node120 ~]# wget http://mirrors.cnnic.cn/apache/tomcat/tomcat-8/v8.0.32/bin/apache-tomcat-8.0.32.tar.gz
解压重命名
[root@node120 ~]# tar -xf apache-tomcat-8.0.32.tar.gz -C /usr/local/ [root@node120 ~]# mv /usr/local/apache-tomcat-8.0.32/ /usr/local/tomcat
添加运行tomcat的用户
[root@node120 ~]# useradd -u 8002 -M tomcat #注意tomcat用户要可以切换
添加服务启动脚本
#!/bin/bash # # chkconfig: - 95 15 # description: Tomcat start/stop/status script #Location of JAVA_HOME (bin files) JAVA_HOME=/usr/java/jdk1.8.0_73 export JAVA_HOME #Add Java binary files to PATH PATH=$JAVA_HOME/bin:$PATH export PATH #CATALINA_HOME is the location of the configuration files of this instance of Tomcat CATALINA_HOME=/usr/local/tomcat #TOMCAT_USER is the default user of tomcat TOMCAT_USER=tomcat #TOMCAT_USAGE is the message if this script is called without any options TOMCAT_USAGE="Usage: $0 {\e[00;32mstart\e[00m|\e[00;31mstop\e[00m|\e[00;32mstatus\e[00m|\e[00;31mrestart\e[00m}" #SHUTDOWN_WAIT is wait time in seconds for java proccess to stop SHUTDOWN_WAIT=20 tomcat_pid() { echo `ps -ef | grep $CATALINA_HOME | grep -v grep | tr -s " "|cut -d" " -f2` } start() { pid=$(tomcat_pid) if [ -n "$pid" ];then echo -e "\e[00;31mTomcat is already running (pid: $pid)\e[00m" else echo -e "\e[00;32mStarting tomcat\e[00m" if [ `user_exists $TOMCAT_USER` = "1" ];then su $TOMCAT_USER -c $CATALINA_HOME/bin/startup.sh else $CATALINA_HOME/bin/startup.sh fi status fi return 0 } status(){ pid=$(tomcat_pid) if [ -n "$pid" ];then echo -e "\e[00;32mTomcat is running with pid: $pid\e[00m" else echo -e "\e[00;31mTomcat is not running\e[00m" fi } stop() { pid=$(tomcat_pid) if [ -n "$pid" ];then echo -e "\e[00;31mStoping Tomcat\e[00m" $CATALINA_HOME/bin/shutdown.sh let kwait=$SHUTDOWN_WAIT count=0; until [ `ps -p $pid | grep -c $pid` = ‘0‘ ] || [ $count -gt $kwait ] do echo -n -e "\e[00;31mwaiting for processes to exit\e[00m\n"; sleep 1 let count=$count+1; done if [ $count -gt $kwait ];then echo -n -e "\n\e[00;31mkilling processes which didn‘t stop after $SHUTDOWN_WAIT seconds\e[00m" kill -9 $pid fi else echo -e "\e[00;31mTomcat is not running\e[00m" fi return 0 } user_exists(){ if id -u $1 >/dev/null 2>&1; then echo "1" else echo "0" fi } case $1 in start) start ;; stop) stop ;; restart) stop start ;; status) status ;; *) echo -e $TOMCAT_USAGE ;; esac exit 0
[root@node120 ~]# chmod +x /etc/init.d/tomcat
[root@node120 ~]# chkconfig tomcat on
配置tomcat web管理页面:
安全起见,将自带的默认页面全部移除
[root@node120 ~]# mkdir /opt/tomcat-web [root@node120 ~]# mv /usr/local/tomcat/webapps/* /opt/tomcat-web/
简单配置JVM参数:
[root@node120 ~]# vim /usr/local/tomcat/bin/catalina.sh JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms512m -Xmx512m -XX:NewSize=128m -XX:MaxNewSize=128m -XX:PermSize=128m -XX:MaxPermSize=128m -XX:+DisableExplicitGC"
启动tomcat:
[root@node120 ~]# chown -R tomcat:tomcat /usr/local/tomcat/ [root@node120 ~]# service tomcat start Starting tomcat Using CATALINA_BASE: /usr/local/tomcat Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/temp Using JRE_HOME: /usr/java/jdk1.8.0_73 Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar Tomcat started. Tomcat is running with pid: 12127
[root@node120 ~]# lsof -i :8080 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME java 12127 tomcat 46u IPv6 33591 0t0 TCP *:webcache (LISTEN)
本文出自 “一步小心踏破了红尘” 博客,请务必保留此出处http://lorne.blog.51cto.com/9062483/1776035
标签:web
原文地址:http://lorne.blog.51cto.com/9062483/1776035