您的位置:首页 > 理论基础 > 计算机网络

keepalived+httpd+tomcat实现高可用负载均衡

2015-07-25 14:36 639 查看
一、环境

centos 6.5

keepalived keepalived-1.2.19.tar.gz

httpd httpd-2.4.12.tar.gz

tomcat apache-tomcat-7.0.63.tar.gz

二、部署

安装 httpd

tar -zxvf httpd-2.4.12.tar.gz
cd httpd-2.4.12
./configure --prefix=/usr/local/apache2 --enable-mods-share=all
这里会报错提示:
configure: error: APR not found.  Please read the documentation.
解决办法如下:
到Apache官网下载缺少的软件包,下载地址http://apr.apache.org/download.cgi
下载
apr-1.5.2.tar.gz
apr-util-1.5.4.tar.gz
安装缺少的依赖的软件包
tar -zxvf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure --prefix=/usr/local/apr
这里会提示没有gcc
提示内容如下
checking for chosen layout... apr
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/opt/httpd/apr-1.5.2':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
需要添加gcc支持
yum -y install gcc
yum -y install gcc-c++
完成之后我们接着安装apr
./configure --prefix=/usr/local/apr
make && make install
tar -zxvf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
make && make install

然后接着配置httpd
./configure --prefix=/usr/local/apache2 --enable-mods-share=all
在这个后面添加
-with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
合起来之后是
./configure --prefix=/usr/local/apache2 --enable-mods-share=all -with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
好无语到了这里竟敢有提示缺少依赖包!!!
提示内容如下:
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org 没办法我们接着添加依赖,wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz tar -zxvf pcre-8.37.tar.gz
cd pcre-8.37
./configure --prefix=/usr/local/pcre
make && make install
然后,我们接着装httpd
./configure --prefix=/usr/local/apache2 --enable-mods-share=all -with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre/bin/pcre-config
终于完成配置了!
make && make install


配置httpd

vim /usr/local/apache2/conf/httpd.conf
在其中添加
# Load mod_jk module
LoadModule jk_module modules/mod_jk.so
# Specify jk log file.
JkLogFile /log/httpd/mod_jk.log
JkShmFile /var/log/httpd/mod_jk.shm
# Specify jk log level [debug/error/info]
JkLogLevel info
# Specify workers.properties, this file tell jk:
# how many nodes and where they are.
JkWorkersFile /opt/tomcat/conf/workers.properties
# Specify which requests should handled by which node.
JkMount /* controller

并且放开
# Server-pool management (MPM specific)
Include conf/extra/httpd-mpm.conf
这里是配置httpd并发数,他有三种工作模式
Apache Prefork、Worker和Event!详细可参阅其他的文章
或者是参考官方文档(http://httpd.apache.org/docs/2.4/mod/mpm_common.html)
这里特别提醒如果想支持并发数超过400的需要添加
ServerLimit 256这个属性,这个支持最大并发数6400
如果还需要更大则需要从新编译httpd!

在启动httpd的时候发现没有成功可以到httpd的日志中查看原因!!!


安装Apache Tomcat Connector(mod_jk)

tar -zxvf tomcat-connectors-1.2.40-src.tar.gz

cd tomcat-connectors-1.2.40-src/native/

./buildconf.sh

这里会提示缺少autoconf

autoconf not found.

You need autoconf version 2.59 or newer installed to build mod_jk from SVN.

yum -y install autoconf

然后,我们继续./buildconf.sh

靠,还让不让人活啊,又缺少libtool

libtool not found.

You need libtool version 1.4 or newer installed to build mod_jk from SVN.

yum -y install libtool

接着./buildconf.sh

./configure –with-apxs=/usr/local/apache2/bin/apxs

make && make install

如果成功结束,你可以在/usr/local/apache2/modules/下找到mod_jk.so文件。

安装tomcat

需要修改配置文件server.xml,



在后添加如下内容

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelSendOptions="8">

<Manager className="org.apache.catalina.ha.session.DeltaManager"
expireSessionsOnShutdown="false" notifyListenersOnReplication="true" />

<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Membership className="org.apache.catalina.tribes.membership.McastService"
address="228.0.0.4" port="45564" frequency="500" dropTime="3000" />
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="auto" port="4000" autoBind="100" selectorTimeout="5000"
maxThreads="6" />

<Sender
className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<Transport
className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />
</Sender>
<Interceptor
className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector" />
<Interceptor
className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor" />
</Channel>

<Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
filter="" />
<Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve" />

<Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
tempDir="/tmp/war-temp/" deployDir="/tmp/war-deploy/" watchDir="/tmp/war-listen/"
watchEnabled="false" />

<ClusterListener
className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener" />
<ClusterListener
className="org.apache.catalina.ha.session.ClusterSessionListener" />
</Cluster>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  tomcat httpd