tomcat7官方下载地址:http://tomcat.apache.org/download-70.cgi 最新版本:7.0.73
安装tomcat之前需安装jdk
下载地址:http://www.oracle.com/technetwork/cn/java/javase/downloads/jdk8-downloads-2133151-zhs.html #下载rpm包安装
安装jdk步骤:
[root@app-server ~]# rpm -ivh jdk-8u102-linux-x64.rpm
[root@app-server ~]# vi /etc/profile #添加环境变量
export JAVA_HOME=/usr/java/jdk1.8.0_102 #JDK默认的安装目录
export JAVA_BIN=/usr/java/jdk1.8.0_102/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
[root@app-server ~]# source /etc/profile
[root@app-server ~]# java -version
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode) java -version
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
安装tomcat步骤:
1、压到本地目录 如:/usr/local
2、添加环境变量
[root@app-server ~]# vi /etc/profile
export CATALINA_HOME=/usr/local/apache-tomcat-7.0.73
root@app-server ~]# source /etc/profile
3、启动tocmat
[root@app-server ~]# /usr/local/apache-tomcat-7.0.73/bin/satrtup.sh
Using CATALINA_BASE: /usr/local/apache-tomcat-7.0.73
Using CATALINA_HOME: /usr/local/apache-tomcat-7.0.73
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.73/temp
Using JRE_HOME: /usr/java/jdk1.8.0_102
Using CLASSPATH: /usr/local/apache-tomcat-7.0.73/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.70/bin/tomcat-juli.jar
4、配置管理员
[root@app-server ~]# vi /usr/local/apache-tomcat-7.0.70/conf/tomcat-users.xml
修改默认管理员
<tomcat-users>
<role rolename="admin-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="admin-script"/>
<role rolename="manager-status"/>
<role rolename="manager-gui"/>
<user username="admin" password="1234" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-script,admin-gui"/>
</tomcat-users>
rhel7 开机自动启动(systemctl方式配置)
[root@app-server ~]# cd $CATALINA_HOME
[root@app-server apache-tomcat-7.0.73]# touch tomcat.pid
[root@app-server bin]# vi setenv.sh
#set java runtime environment variable
export JAVA_HOME=/usr/java/jdk1.8.0_102
export JRE_HOME=/usr/java/jdk1.8.0_102/jre
# set APR
export LD_LIBRARY_PATH=/usr/local/apr/lib //需要安装APR
#add tomcat pid
CATALINA_PID="$CATALINA_HOME/tomcat.pid"
#add java opts
JAVA_OPTS="-server -Xms1024m -Xmx4096m -XX:PermSize=256M -XX:MaxNewSize=1024m -XX:MaxPermSize=512m -Djava.awt.headless=true"
[root@app-server bin]# vi /usr/lib/systemd/system/tomcat.service
[Unit]
Description=Tomcat
After=syslog.targetnetwork.target remote-fs.targetnss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/apache-tomcat-7.0.73/tomcat.pid
ExecStart=/usr/local/apache-tomcat-7.0.73/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID Private
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@app-server bin]# systemctl enable tomcat
[root@app-server bin]# systemctl start tomcat
[root@app-server systemd]# systemctl status tomcat
● tomcat.service - Tomcat
Loaded: loaded (/usr/lib/systemd/system/tomcat.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2016-12-08 15:43:44 CST; 1min ago
Process: 1251 ExecStart=/usr/local/apache-tomcat-7.0.73/bin/startup.sh (code=exited, status=0/SUCCESS)
Main PID: 2154 (java)
CGroup: /system.slice/tomcat.service
└─2154 /usr/java/jdk1.8.0_102/jre/bin/java -Djava.util.logging.config.file=/usr/local/apache-tomcat-7.0.73/conf/loggin...
Dec 08 15:43:42 app-server systemd[1]: Starting Tomcat...
Dec 08 15:43:44 app-server startup.sh[1251]: Using CATALINA_BASE: /usr/local/apache-tomcat-7.0.73
Dec 08 15:43:44 app-server startup.sh[1251]: Using CATALINA_HOME: /usr/local/apache-tomcat-7.0.73
Dec 08 15:43:44 app-server startup.sh[1251]: Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.73/temp
Dec 08 15:43:44 app-server startup.sh[1251]: Using JRE_HOME: /usr/java/jdk1.8.0_102/jre
Dec 08 15:43:44 app-server startup.sh[1251]: Using CLASSPATH: /usr/local/apache-tomcat-7.0.73/bin/bootstrap.jar:/usr/...li.jar
Dec 08 15:43:44 app-server startup.sh[1251]: Using CATALINA_PID: /usr/local/apache-tomcat-7.0.73/tomcat.pid
Dec 08 15:43:44 app-server startup.sh[1251]: Tomcat started.
Dec 08 15:43:44 app-server systemd[1]: Started Tomcat.
Hint: Some lines were ellipsized, use -l to show in full.
原文地址:http://31405.blog.51cto.com/21405/1889634