1
2
|
# wget
http:
//download
.oracle.com
/otn-pub/java/jdk/8u60-b27/jdk-8u60-linux-x64
.rpm?AuthParam=1443611456_fa9cf3c3ff6845d1bcd351d6983780a8
|
1
|
# wget http://mirrors.cnnic.cn/apache/tomcat/tomcat-8/v8.0.26/bin/apache-tomcat-8.0.26.tar.gz
|
1
|
# wget http://apache.fayea.com/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.41-src.tar.gz
|
1
|
# yum install -y httpd httpd-devel apr apr-util-devel autoconf libtool
|
1
|
# rpm -ivh jdk-8u60-linux-x64.rpm
|
1
2
3
4
5
6
7
8
|
# vi /etc/profile.d/java.sh
export
JAVA_HOME=
/usr/java/jdk1
.8.0_60
export
PATH=$PATH:$JAVA_HOME
/bin
# . /etc/profile.d/java.sh
# java -version
java version
"1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
|
1
2
3
4
5
|
# tar -zxvf apache-tomcat-8.0.26.tar.gz
# mkdir /usr/local/tomcat
# mv apache-tomcat-8.0.26/* /usr/local/tomcat/
# catalina.sh start ##开启tomcat
# catalina.sh stop ##关闭tomcat
|
1
2
3
4
5
6
7
|
# ss -tlnp ##查看tomcat是否启动
# getenforce 0
# systemctl stop firewalld
# vi /etc/profile.d/tomcat.sh
export
CATALINA_HOME=
/usr/local/tomcat
export
PATH=$PATH:$CATALINA_HOME
/bin
# . /etc/profile.d/tomcat.sh
|
1
2
|
# cd /usr/local/tomcat/webapps/ROOT/
# echo "hello,tomcat" > index.html
|
1
2
3
|
# cd /usr/local/tomcat/webapps/ROOT/
# vi tomcat.jsp ##新建测试页
1
Now time is: <%=
new
java.util.Date() %>
|
1
2
3
4
5
6
7
8
|
# cd /usr/local/tomcat/conf/
# vi server.xml ##更改默认host
103
<Engine name=
"Catalina"
defaultHost=
"www.zhi.com"
jvmRoute=
"TomcatZHI"
>
<Host name=
"www.zhi.com"
appBase=
"webapps"
unpackWARs=
"true"
autoDeploy=
"true"
>
<Contest path=
""
docBase=
"webapps"
reLoadable=
"true"
/>
</Host>
# catalina.sh configtest ##测试语法
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# cd /usr/local/tomcat/webapps/ROOT
# mv index.jsp index.jsp.bak
# vi index.jsp ##新建测试页
2
<%@ page language=
"java"
%>
<html>
<head><title>TomcatZHI</title></head>
<body>
<h1><font color=
"red"
>TomcatZHI </font></h1>
<table align=
"centre"
border=
"1"
>
<tr>
<td>Session ID</td>
<% session.setAttribute(
"abc"
,
"abc"
); %>
<td><%= session.getId() %></td>
</tr>
<tr>
<td>Created on</td>
<td><%= session.getCreationTime() %></td>
</tr>
</table>
</body>
</html>
# catalina.sh start ##开启tomcat
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
# tar -zxvf tomcat-connectors-1.2.41-src.tar.gz
# cd tomcat-connectors-1.2.41-src
# cd tomcat-connectors-1.2.41-src/native
# ./buildconf.sh
buildconf: checking installation...
buildconf: autoconf version 2.69 (ok)
buildconf: libtool version 2.4.2 (ok)
buildconf: libtoolize --automake --copy
buildconf: aclocal
buildconf: autoheader
buildconf: automake -a --foreign --copy
buildconf: autoconf
# ./configure --with-apxs=/usr/bin/apxs
# make
# make install
|
1
2
3
4
5
|
# ./buildconf.sh
buildconf: checking installation...
buildconf: autoconf not found.
You need autoconf version 2.59 or newer installed
to build mod_jk from SVN.
|
1
|
# yum install autoconf
|
1
2
3
4
5
6
|
# ./buildconf.sh
buildconf: checking installation...
buildconf: autoconf version 2.69 (ok)
buildconf: libtool not found.
You need libtool version 1.4 or newer installed
to build mod_jk from SVN.
|
1
|
# yum install libtool
|
1
2
3
4
5
6
7
8
9
|
# vi /etc/httpd/conf/mod_jk.conf
JkWorkersFile
/etc/httpd/conf/workers
.properties
##加载tomcat works配置文件
JkLogFile logs
/mod_jk
.log
##日志文件
JkLogLevel warn
##日志级别
JkLogStampFormat
"[%a %b %d %H:%M:%S %Y]"
##日志数据格式
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
##其他配置项
JkRequestLogFormat
"%w %V %T"
##请求日志的格式
JkMount
/servlet/
* worker1
JkMount /*.jsp worker1
##JkMount用于控制URL与Tomcat workers的对应关系,JkMount表示用tomcat来解析,JkUnMount则相反
|
1
2
3
4
5
6
7
8
9
|
# vi /etc/httpd/conf/workers.properties
#
# workers.properties ##可配置多实例
#
worker.list=worker1
worker.worker1.
type
=ajp13
##worker的类型为ajp13
worker.worker1.host=127.0.0.1
##worker的主机(IP)
worker.worker1.port=8009
##worker的端口
worker.worker1.lbfactor=5
##worker负载均衡
|
1
2
3
4
5
6
7
8
9
10
|
# vi /etc/httpd/conf/httpd.conf
#
# Dynamic Shared Object (DSO) Support
#
LoadModule jk_module modules
/mod_jk
.so
Include
/etc/httpd/conf/mod_jk
.conf
ServerName www.zhi.com:80
# service httpd configtest ##测试语法
|
1
2
3
4
5
6
7
8
9
10
11
|
# httpd -D DUMP_MODULES | grep proxy
proxy_module (shared)
proxy_ajp_module (shared)
proxy_balancer_module (shared)
proxy_connect_module (shared)
proxy_express_module (shared)
proxy_fcgi_module (shared)
proxy_fdpass_module (shared)
proxy_ftp_module (shared)
proxy_http_module (shared)
proxy_scgi_module (shared)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
# vi /etc/httpd/conf/httpd.conf ##只需配置如下即可
ProxyVia Off
ProxyRequests Off
ProxyPreserveHost Off
<Proxy />
Require all granted
<
/Proxy
>
ProxyPass / http:
//192
.168.10.132:8080/
ProxyPassReverse / http:
//192
.168.10.132:8080/
<Location / >
Require all granted
<
/Location
>
# httpd -t ##检查语法
|
Service Unavailable
1
|
# setenforce 0 ##或设置selinux为enabled(需重启生效)
|
1
2
3
|
<IfModule dir_module>
DirectoryIndex index.jsp index.htm index.html
<
/IfModule
>
|