一、环境介绍
二、安装后端服务器
三、安装前端Apache服务
四、配置Apache使用mod_jk模块实现代理及负载均衡
五、配置Apache基于mod_proxy模块实现代理及负载均衡
六、论坛安装
七、安装并配置Keepalived实现前端高可用
一、环境介绍
系统版本:CentOS 6.4_x86_64
Mysql版本:mysql-5.1.66-2.el6_3.x86_64
Apache版本:httpd-2.2.25 点此下载
Keepalived版本:keepalived-1.2.7 点此下载
Tomcat版本:apache-tomcat-7.0.33 点此下载
Jdk版本: jdk-7u40-linux-x64 点此下载
Tomcat-commectors版本:tomcat-connectors-1.2.37 点此下载
论坛版本:JspRun!_6.0.0_GBK 点此下载
环境介绍:
当用户通过 "www.allen.com" 域名访问时,首先是由前端两台Apache代理服务器响应并转发到后端Tomcat服务器上,而在Apache上做的是反向代理负载均衡到后端Tomcat服务器上,前端服务器使用Keepalived做的高可用集群,【Apache1默认为Master,Apache2为Backup】虚拟IP地址为"172.16.14.10"模拟为公网IP;当然这里数据库只有一台主机会成为点故障,这里不要介绍Mysql的高可用,如果有兴趣可以看前面写的博客
提示:这里使用Keepalived做高可用时,前面所有的服务都已完成后,最后实现的对前端服务器做高可用
二、安装后端Tomcat与Mysql服务器
1、在Tomcat1与Tomcat2服务器上安装Tomcat,安装方法相同,这里只介绍一次
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
安装JDK
# rpm -ivh jdk-7u40-linux-x64.rpm
# vim /etc/profile.d/java.sh
export JAVA_HOME= /usr/java/latest
export PATH=$JAVA_HOME /bin :$PATH
# . /etc/profile.d/java.sh
# java -version
java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)
------------------------------------------------------------------------
安装Tomcat
# tar xf apache-tomcat-7.0.33.tar.gz -C /usr/local/
# cd /usr/local/
# ln -s apache-tomcat-7.0.33 tomcat
# vim /etc/profile.d/tomcat.sh
export CATALINA_HOME= /usr/local/tomcat
export PATH=$CATALINA_HOME /bin :$PATH
# . /etc/profile.d/tomcat.sh
# catalina.sh version
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/latest
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap .jar: /usr/local/tomcat/bin/tomcat-juli .jar
Server version: Apache Tomcat /7 .0.33
Server built: Nov 18 2012 04:15:21
Server number: 7.0.33.0
OS Name: Linux
OS Version: 2.6.32-358.el6.x86_64
Architecture: amd64
JVM Version: 1.7.0_40-b43
JVM Vendor: Oracle Corporation
|
2、启动Tomcat服务并访问测试,默认访问端口为"8080";如下
1
2
3
4
5
6
7
8
9
10
11
|
# catalina.sh start
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/latest
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap .jar: /usr/local/tomcat/bin/tomcat-juli .jar
# jps
2283 Jps
2272 Bootstrap
# ss -tanlp | grep 8080
LISTEN 0 100 :::8080 :::* users :(( "java" ,2272,40))
|
3、开启Tomcat管理及状态页面
1
2
3
4
5
6
|
# vim /usr/local/tomcat/conf/tomcat-users.xml
"allen" password= "admin" roles= "manager-gui,admin-gui" />
# catalina.sh stop
# catalina.sh start
|
4、访问Tomcat后台管理
5、安装Mysql服务器
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
######安装Mysql并创建数据库,授权用户访问新创建的数据库有所有权,方便后面使用
[root@Mysql ~] # yum -y install mysql-server
[root@Mysql ~] # service mysqld start
[root@Mysql ~] # mysql
mysql> create database bbs;
mysql> grant all on bbs.* to
'bbsuser' @ '172.16.%.%' identified by 'bbspass' ;
mysql> flush privileges;
----------------------------------------------------------------------
远程连接数据库测试授权用户是否能连接成功
# mysql -ubbsuser -pbbspass -h 172.16.14.5 -e 'show databases';
+--------------------+
| Database |
+--------------------+
| information_schema |
| bbs |
|
test |
+--------------------+
|
三、安装前端Apache服务
1、在Apache1与Apache2服务器上安装Httpd软件,安装方法相同,这里只介绍一次
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# tar xf httpd-2.2.25.tar.bz2
# cd httpd-2.2.25
# yum -y install gcc gcc-c++ openssl-devel pcre-devel
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-modules=most --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --enable-mpms-shared=all --with-mpm=prefork --enable-proxy --enable-proxy-http --enable-proxy-ajp --enable-proxy-balancer --enable-cache --enable-cache-disk --enable-mem-cache --enable-file-cache --enable-proxy-connect
# make && make install
# cp build/rpm/httpd.init /etc/init.d/httpd
------修改如下内容
# vim /etc/init.d/httpd
httpd=${HTTPD- /usr/local/apache/bin/httpd }
pidfile=${PIDFILE- /usr/local/apache/logs/ ${prog}.pid}
lockfile=${LOCKFILE- /var/lock/subsys/ ${prog}}
RETVAL=0
# check for 1.3 configuration
check13 () {
CONFFILE= /etc/httpd/httpd .conf
----------------------------------------------------------------------
修改环境变量并把Httpd加入到系统服务
# echo "PATH=/usr/local/apache/bin:$PATH" >> /etc/profile.d/http.sh
# . /etc/profile.d/http.sh
# ln -s /usr/local/apache/include/ /usr/include/httpd
# chkconfig --add httpd
----------------------------------------------------------------------
创建测试页
# echo "
|
2、在Apache1与Apache2服务器上安装"tomcat-connectors"
1
2
3
4
5
6
7
8
9
10
11
12
13
|
# tar xf tomcat-connectors-1.2.37-src.tar.gz
# cd tomcat-connectors-1.2.37-src/native/
# ./configure --with-apxs=/usr/local/apache/bin/apxs
# make && make install
------------------------------------------------------------------------
安装完成后会生成如下文件
# ls /usr/local/apache/modules/
mod_jk.so
------------------------------------------------------------------------
启动Httpd服务
#service httpd start
# ss -tanl |grep 80
LISTEN 0 128 :::80 :::*
|
3、访问测试Apache是否正常工作
四、配置Apache使用mod_jk模块实现代理及负载均衡
1、修改Apache主配置文件,包含一个文件并创建该文件;实现代理功能
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
将下面指令添加到文件末尾即可
# vim /etc/httpd/httpd.conf
Include /etc/httpd/extra/mod_jk .conf
------------------------------------------------------------------------
创建文件添加如下内容
# vim /etc/httpd/extra/mod_jk.conf
LoadModule jk_module modules /mod_jk .so
JkWorkersFile /etc/httpd/extra/workers .properties
JkLogFile logs /mod_jk .log
JkLogLevel debug
JkMount /* TomcatA
JkMount /status/
stat1
------------------------------------------------------------------------
# vim /etc/httpd/extra/workers.properties
worker.list=TomcatA,stat1
worker.TomcatA.port=8009
worker.TomcatA.host=172.16.14.3
worker.TomcatA. type =ajp13
worker.TomcatA.lbfactor=1
worker.stat1.
type = status
----------------------------------------------------------------------
# service httpd restart
|
2、修改后端Tomcat1服务器,添加一个虚拟主机并提供测试页面
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
[root@Tomcat1 ~] # cd /usr/local/tomcat/conf/
[root@Tomcat1 conf] # cp server.xml server.xml.bak
[root@Tomcat1 conf] # vim server.xml
######修改如下内容
"Catalina" defaultHost= "www.allen.com" jvmRoute= "TomcatA" >
######在"Engine"中添加如下内容
"www.allen.com" appBase= "/web/allen"
unpackWARs=
"true" autoDeploy= "true" >
"org.apache.catalina.valves.AccessLogValve" directory= "logs"
prefix=
"allen_access_log." suffix= ".txt"
pattern=
"%h %l %u %t "%r" %s %b" />
"" docBase= "/web/allen" />
< /Host >
----------------------------------------------------------------------
######创建网站存放目录并创建测试页
[root@Tomcat1 ~] # mkdir -p /web/allen
[root@Tomcat1 ~] # vim /web/allen/index.jsp
<%@ page language=
"java" %>
< head > /title >< /head >
3、访问Apache1主机,验证是否代理成功 4、修改Apache配置文件(mod_jk.conf、workers.properties);实现负载均衡
5、修改后端Tomcat2服务器,添加一个虚拟主机并提供测试页面
|