以下使用的Linux版本为: RedHat Enterprise Linux 7.0 x86_64,Tomcat版本为tomcat-7.0.54.
1.下载JDK与Tomcat.
jdk下载地址:
Oracle.com/technetwork/Java/javase/downloads/jdk7-downloads-1880260.html
tomcat下载地址:
2.jdk安装与配置.
(1)jdk安装
rpm包:
# rpm -ivh jdk-7u55-linux-x64.rpm
tar.gz包:解压缩
# mkdir /usr/java
# cd /usr/java
# tar -zxvf /software/jdk-7u55-linux-x64.tar.gz
生成链接以便版本升级
# ln -s jdk1.7.0_55 latest
# ln -s latest default
(2)配置环境变量
# vi /etc/profile
export JAVA_HOME=/usr/java/default
export JAVA_BIN=$JAVA_HOME/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
使配置生效
# source /etc/profile
测试jdk.
# java -version
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)
3.Tomcat的安装
解压缩
# mkdir /usr/local/tomcat
# cd /usr/local/tomcat
# tar -zxvf /software/apache-tomcat-7.0.54.tar.gz
生成链接以便版本升级
# ln -s apache-tomcat-7.0.54 server
启动Tomcat
# cd /usr/local/tomcat/server/bin
# ./startup.sh
Using CATALINA_BASE: /usr/local/tomcat/server
Using CATALINA_HOME: /usr/local/tomcat/server
Using CATALINA_TEMDIR: /usr/local/tomcat/server/temp
Using JRE_HOME: /usr/java/default
Using CLASS_PATH: /usr/local/tomcat/server/bin/bootstrap.jar:/usr/local/tomcat/server/bin/tomcat-juli.jar
Tomcat started.
测试Tomcat:
打开防火墙,使外部能访问
# /sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
# service iptables save
# service iptables restart
或直接修改文件/etc/sysconfig/iptables.
# vi /etc/sysconfig/iptables
-A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
# service iptables restart
在浏览器输入: :8080
如在本机可以输入: :8080
出现tomcat的页面表示安装成功.
停止Tomcat
# ./shutdown.sh
4.配置web管理帐号
修改文件conf/tomcat-users.xml,在<tomcat-users>元素中添加帐号密码,需要指定角色.
# vi /usr/local/tomcat/server/conf/tomcat-users.xml
<tomcat-users>
<user password="admin" roles="admin-gui,manager-gui" />
</tomcat-users>
5.配置web访问端口
可以修改conf目录下的文件server.xml,修改Connector元素(Tomcat的默认端口是8080),需要重新启动Tomcat服务生效.
# vi /usr/local/tomcat/server/conf/server.xml
<Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
6.配置https安全连接(ssl加密连接)
https连接需要用到数字证书与数字签名(MD5算法)
网站https连接首先需要申请数字证书,配置加密连接器,浏览器安装证书.
·使用java的工具keytool产生数字证书
# keytool -genkey -alias tomcat -keyalg RSA
生成文件.keystore
注意:CN为主机名称,本机可用localhost
·将文件.keystore放到Tomcat服务器的conf目录下
# cp .keystore /usr/local/tomcat/server/conf/
·修改conf/server.xml文件,修改加密连接器,添加keystoreFile与keystorePass
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="conf/.keystore" keystorePass="123456"/>
·重新启动tomcat.浏览器输入https://localhost:8443访问,并安装证书.