首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 操作系统 >

CentOS上Apache + Tomcat集群

2014-07-17 
CentOS下Apache + Tomcat集群1.以下几个包是需要下载的Tomcat http://apache.etoak.com/tomcat/tomcat-7/v

CentOS下Apache + Tomcat集群
1.以下几个包是需要下载的
Tomcat http://apache.etoak.com/tomcat/tomcat-7/v7.0.27/bin/apache-tomcat-7.0.27.tar.gz
Apr  http://labs.renren.com/apache-mirror//apr/apr-1.4.6.tar.gz
Apr Util http://apache.etoak.com//apr/apr-util-1.4.1.tar.gz
Apache Http Server http://labs.renren.com/apache-mirror//httpd/httpd-2.2.22.tar.gz
Connector    http://www.apache.org/dist/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.35-src.tar.gz

2.安装APR
[root@localhost app]#tar -zxvf apr-1.4.6.tar.gz
[root@localhost app]#cd apr-1.4.6

[root@localhost apr-1.4.6]#./buildconfbuildconf: checking installation...buildconf: python version 2.6.5 (ok)buildconf: autoconf not found.           You need autoconf version 2.59 or newer installed           to build APR from SVN.[root@localhost apr-1.4.6]#yum install autoconf[root@localhost apr-1.4.6]#./buildconfbuildconf: libtool not found.           You need libtool version 1.4 or newer installed           to build APR from SVN.[root@localhost apr-1.4.6]#yum install libtool[root@localhost apr-1.4.6]#./configure[root@localhost apr-1.4.6]# make-bash: make: command not found[root@localhost apr-1.4.6]#yum install make[root@localhost apr-1.4.6]# make[root@localhost apr-1.4.6]# make install


3.安装APR Utils
[root@localhost app]# tar -zxvf apr-util-1.4.1.tar.gz[root@localhost app]# cd apr-util-1.4.1[root@localhost apr-util-1.4.1]#./buildconf --with-apr=/app/apr-1.4.6[root@localhost apr-util-1.4.1]# ./configure --with-apr=/app/apr-1.4.6[root@localhost apr-util-1.4.1]#make[root@localhost apr-util-1.4.1]#make install


4.安装Apache Http Server
[root@localhost app]# tar -zxvf httpd-2.2.22.tar.gz[root@localhost app]# cd httpd-2.2.22[root@localhost httpd-2.2.22]# ./buildconf[root@localhost httpd-2.2.22]# ./configure[root@localhost httpd-2.2.22]# make[root@localhost httpd-2.2.22]# make install


5.安装Apache 和 Tomcat 的连接器Connector
[root@localhost app]tar -zxvf tomcat-connectors-1.2.35-src.tar.gz[root@localhost app]cd tomcat-connectors-1.2.35-src/native[root@localhost native]# ./configure --with-apxs=/usr/local/apache2/bin/apxs[root@localhost native]#make[root@localhost native]#make install

注意:该tar.gz文件里面其实有很多关于配置的详细文档,如果出现问题可以再其中进行查阅,另外,我的编译应该说是成功了,但是生成的文件却不能用,后来是去网上下载了个已经编译好了的才解决的


6.配置Apache Http Server
原文是说Apache 的httpd.conf是在/usr/local/apache2/conf/目录下面,但是实际上我发现控制Apache的文件却是在/etc/httpd/conf/目录下面,这点还请高手赐教

在文件最后加上下面一句话就可以了
Include conf/mod_jk.conf


7.在httpd.conf文件同一目录下建立mod_jk.conf文件,内容如下:
#加载mod_jk ModuleLoadModule jk_module modules/mod_jk.so#指定 workers.properties文件路径JkWorkersFile conf/workers.properties#指定那些请求交给tomcat处理,"controller"为在workers.propertise里指定的负载分配控制器JkMount /*.jsp controller


8.在httpd.conf同目录下新建 workers.properties文件,内容如下:

worker.list = controller,tomcat1,tomcat2  #server 列表#========tomcat1========worker.tomcat1.port=8009         #ajp13 端口号,在tomcat下server.xml配置,默认8009worker.tomcat1.host=localhost  #tomcat的主机地址,如不为本机,请填写ip地址worker.tomcat1.type=ajp13worker.tomcat1.lbfactor = 1   #server的加权比重,值越高,分得的请求越多#========tomcat2========worker.tomcat2.port=9009       #ajp13 端口号,在tomcat下server.xml配置,默认8009worker.tomcat2.host=localhost  #tomcat的主机地址,如不为本机,请填写ip地址worker.tomcat2.type=ajp13worker.tomcat2.lbfactor = 1   #server的加权比重,值越高,分得的请求越多#========controller,负载均衡控制器========worker.controller.type=lbworker.controller.balanced_workers=tomcat1,tomcat2   #指定分担请求的tomcatworker.controller.sticky_session=1


9.解压apache-tomcat-7.0.27.tar.gz,并copy一份,home目录分别命名为tomcat1,tomcat2
[root@localhost app]# tar -zxvf apache-tomcat-7.0.27.tar.gz[root@localhost app]# mv apache-tomcat-7.0.27 tomcat1[root@localhost app]# cp -R tomcat1/ tomcat2



10.更改tomcat2的server.xml文件,由于我的两个tomcat是在同一个服务器上,所以要修改下面红颜色的端口,以防端口冲突.

<Server port="9005" shutdown="SHUTDOWN">


<Connector port="9080" protocol="HTTP/1.1"               connectionTimeout="20000"               redirectPort="8443" />

这个是APJ端口:
  <Connector port="9009" protocol="AJP/1.3" redirectPort="8443" />


11.下面是关于负载均衡的配置,在2个tomcat的server.xml中:
<!-- You should set jvmRoute to support load-balancing via AJP ie :<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">--><Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2"><!--tomcat2将与tomcat1黏贴session 在这里指定黏贴对象-->


下面这段代码也是必须的,注意端口不能重复:

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"       channelSendOptions="6">                  <Manager className="org.apache.catalina.ha.session.DeltaManager"          expireSessionsOnShutdown="false"          notifyListenersOnReplication="true"/>      <!--      <Manager className="org.apache.catalina.ha.session.BackupManager"          expireSessionsOnShutdown="false"          notifyListenersOnReplication="true"          mapSendOptions="6"/>      -->      <Channel className="org.apache.catalina.tribes.group.GroupChannel">          <Membership className="org.apache.catalina.tribes.membership.McastService"              address="228.0.0.5"              port="45564"              frequency="500"              dropTime="3000"/>         <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"              address="auto"              port="4000"  <!--tomcat1将与tomcat2的端口不同-->             selectorTimeout="100"              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=".*/.gif;.*/.js;.*/.jpg;.*/.png;.*/.htm;.*/.html;.*/.css;.*/.txt;"/>       <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>      <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>   </Cluster>


这是最后我遇到的问题和解决方法:
如果mod_jk.so权限组出现问题请使用一下命令:

chcon -t httpd_modules_t /usr/local/apache2/modules/mod_jk.so


错误: undefined symbol: ap_get_server_description
解决办法:下载编译好的文件http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/linux/jk-1.2.30/i586/

如果启动Httpd失败但是没有错误信息,要检查/etc/httpd/logs下的error_log文件

如果是因为SELinux的问题,可以关闭之


转自:http://blog.csdn.net/daihui05/article/details/7524745

热点排行