一、下载相关软件
JDK:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Tomcat:http://mirrors.shuosc.org/apache/tomcat/tomcat-9/v9.0.2/bin/apache-tomcat-9.0.2.tar.gz
二、安装与配置JDK
[root@JDK-Tomcat ~]# rpm -ivh jdk-8u151-linux-x64.rpm
在/etc/profile中加入以下三行:
[root@JDK-Tomcat ~]# vi /etc/profile
export JAVA_HOME=/usr/java/jdk1.8.0_151
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$CLASSPATH
查看一下安装详情。
[root@JDK-Tomcat ~]# java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
三、安装与配置Tomcat
1、下载安装Tomcat。
[root@JDK-Tomcat ~]# wget -c http://mirrors.shuosc.org/apache/tomcat/tomcat-9/v9.0.2/bin/apache-tomcat-9.0.2.tar.gz
[root@JDK-Tomcat ~]# tar -xzvf apache-tomcat-9.0.2.tar.gz
[root@JDK-Tomcat ~]# mkdir /usr/local/tomcat
[root@JDK-Tomcat ~]# mv apache-tomcat-9.0.2 /usr/local/tomcat/
[root@JDK-Tomcat ~]# cd /usr/local/tomcat/apache-tomcat-9.0.2/
2、修改配置系统设置,启动Tomcat。
[root@JDK-Tomcat apache-tomcat-9.0.2]# vi /etc/profil
export TOMCAT_HOME=/usr/local/tomcat/apache-tomcat-9.0.2/
[root@JDK-Tomcat bin]# source /etc/profile
[root@JDK-Tomcat bin]# ./catalina.sh start
Using CATALINA_BASE: /usr/local/tomcat/apache-tomcat-9.0.2
Using CATALINA_HOME: /usr/local/tomcat/apache-tomcat-9.0.2
Using CATALINA_TMPDIR: /usr/local/tomcat/apache-tomcat-9.0.2/temp
Using JRE_HOME: /usr/java/jdk1.8.0_151
Using CLASSPATH: /usr/local/tomcat/apache-tomcat-9.0.2/bin/bootstrap.jar:/usr/local/tomcat/apache-tomcat-9.0.2/bin/tomcat-juli.jar
Tomcat started.
在浏览器输入服务器IP地址,默认端口8080,看是否出现以下页面:
如出现上图所示,则说明安装成功!
4、停止Tomcat,进一步修改配置。
[root@JDK-Tomcat bin]# ./shutdown.sh
Using CATALINA_BASE: /usr/local/tomcat/apache-tomcat-9.0.2
Using CATALINA_HOME: /usr/local/tomcat/apache-tomcat-9.0.2
Using CATALINA_TMPDIR: /usr/local/tomcat/apache-tomcat-9.0.2/temp
Using JRE_HOME: /usr/java/jdk1.8.0_151
Using CLASSPATH: /usr/local/tomcat/apache-tomcat-9.0.2/bin/bootstrap.jar:/usr/local/tomcat/apache-tomcat-9.0.2/bin/tomcat-juli.jar
1、修改默认监听端口,例如:将8080端口修改为80,把配置文件中的8080替换为80即可。启动Tomcat去掉端口号查看。
[root@JDK-Tomcat bin]# vim /usr/local/tomcat/apache-tomcat-9.0.2/conf/server.xml
:1,$s/8080/80/
2、修改字符编码。在如图所示部分加入高亮部分代码,保存退出,重启Tomcat。
3、设置Tomcat开机自启动。
在/usr/local/tomcat/apache-tomcat-9.0.2/bin/startup.sh的尾部新增如下四行,保存退出!
export JAVA_HOME=/usr/java/jdk1.8.0_151
export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
export PATH=$JAVA_HOME/bin
export CATALINA_HOME=/usr/local/tomcat/apache-tomcat-9.0.2/bin/catalina.sh start
编辑/etc/rc.d/rc.local配置文件。加入如下一行,保存退出!
/usr/local/tomcat/apache-tomcat-9.0.2/bin/startup.sh
给/etc/rc.d/rc.local加上执行权限,这个很重要,别忘了!否则不会执行!
[root@JDK-Tomcat ~]# chmod u+x /etc/rc.d/rc.local
4、优化。在/usr/local/tomcat/apache-tomcat-9.0.2/bin/catalina.sh新增如下一行:
JAVA_OPTS="-XX:MaxPermSize=192M -Xms1000M -Xmx2000M"
关闭服务器,重启观察是否正常开机自启动?