參考來源
http://www.liferay.com/zh/community/wiki/-/wiki/Main/JBoss-Tomcat-Liferay+portal+Clustering+-+what+and+how
- 下載所需檔案
先下載 apr-1.5.1.tar.gz apr-util-1.5.4.tar.gz pcre-8.34.tar.gz httpd-2.4.10
這三個檔案解壓縮,
安裝順序為
apr-1.5.1
apr-util-1.5.4
pcre-8.34
httpd-2.4.10
apr-1.5.1安裝 , cd到解壓後的dir
[root@localhost apr-1.5.1]# ./configure
下載安裝gcc組件。centos中安裝如下:
1、在centos 用yum install gcc 也很方便
2、不過先要用yum install yum-fastestmirror更新下源,不然太慢了
apr-util-1.5.4 cd安裝, cd到解壓後的dir 安裝時需要依賴 apr-1.5.1
[root@localhost apr-util-1.5.4]# ./configure –prefix=/root/Downloads/apr-util-1.5.1 –with-apr=/root/Downloads/apr-1.5.1
pcre-8.34 安裝, cd到解壓後的dir
[root@localhost pcre-8.34]# ./configure
httpd安裝, cd到解壓後的dir 安裝時需要依賴另外兩個檔案
[root@localhost apr-util-1.5.4]# ./configure --prefix=/root/Downloads/httpd-2.4.10 --enable-so --with-apr=/root/Downloads/apr-1.5.1 --with-apr-util=/root/Downloads/apr-util-1.5.4 --with-pcre=/root/Downloads/pcre-8.34/pcre-config
以上安裝好後,輸入
[root@localhost apr-util-1.5.4]# make
[root@localhost apr-util-1.5.4]# make install,即可完成安裝,打開localhost能否看到it works?
1、下載tomcat-connectors-1.2.37-src.tar.gz
2、解壓縮tomcat-connectors-1.2.37-src.tar.gz,cd到native文件夾,提示:
[root@localhost native]# chmod 755 buildconf.sh
[root@localhost native]#./buildconf.sh
buildconf: checking installation...
buildconf: autoconf not found.
You need autoconf version 2.59 or newer installed
to build mod_jk from SVN.
[root@sony619 native]# yum install autoconf
執行[root@sony619 native]#./buildconf.sh 再次提示
buildconf: libtool not found.
You need libtool version 1.4 or
newer installed
to build mod_jk from SVN.
解决:
[root@sony619 native]#./yum install libtool。
结束後,到apache-2.0下面找mod_jk.so文件,同時到apache的modules下面找應該會有,如果没有直接複製過去。
- 方法2
1. 檢查 apxs 有没有安裝。"/usr/sbin/apxs"
2. 如果没有的話,先安裝apxs
[root@localhost ~]# cd /etc/
[root@localhost ~]# vi yum.conf
如果有關於 apache or httpd 的 "exclude"這樣一行,把它註解掉;如果没有,就直接退出就行
儲存並退出
[root@localhost ~]# yum install apr-util-devel
[root@localhost ~]# yum install httpd-devel
做完這幾步以後,就應該有 "/usr/sbin/apxs" 這個文件了。
3. 編譯 mod_jk.so
下載最新mod_jk源文件:http://tomcat.apache.org/download-connectors.cgi
[root@localhost ~]# tar –xvf tomcat-connectors-1.2.37-src.tar.gz
[root@localhost ~]# cd tomcat-connectors-1.2.37-src/native/
[root@localhost ~]# ./buildconfig.sh
[root@localhost ~]# ./configure --with-apxs=/usr/sbin/apxs
[root@localhost ~]# make
4. 編譯完畢以後就有mod_jk.so文件了,路徑是 tomcat-connectors-1.2.37-src/native/apache-2.0/mod_jk.so
5. cd tomcat-connectors-1.2.37-src/native/apache-2.0/
2. 如果没有的話,先安裝apxs
[root@localhost ~]# cd /etc/
[root@localhost ~]# vi yum.conf
如果有關於 apache or httpd 的 "exclude"這樣一行,把它註解掉;如果没有,就直接退出就行
儲存並退出
[root@localhost ~]# yum install apr-util-devel
[root@localhost ~]# yum install httpd-devel
做完這幾步以後,就應該有 "/usr/sbin/apxs" 這個文件了。
3. 編譯 mod_jk.so
下載最新mod_jk源文件:http://tomcat.apache.org/download-connectors.cgi
[root@localhost ~]# tar –xvf tomcat-connectors-1.2.37-src.tar.gz
[root@localhost ~]# cd tomcat-connectors-1.2.37-src/native/
[root@localhost ~]# ./buildconfig.sh
[root@localhost ~]# ./configure --with-apxs=/usr/sbin/apxs
[root@localhost ~]# make
4. 編譯完畢以後就有mod_jk.so文件了,路徑是 tomcat-connectors-1.2.37-src/native/apache-2.0/mod_jk.so
5. cd tomcat-connectors-1.2.37-src/native/apache-2.0/
6. cp mod_jk.so /usr/local/apache/modules 【如果modules没有mod_jk.so的話,直接複製過去】
mod_jk安裝完成後,apache-mod_jk-tomcat三個連接起来。
下面把mod_jk配置進去。
在/etc/httpd文件中添加workers.properties文件,内容如下:
worker.list=balancer,stat
worker.node1.type=ajp13
worker.node1.port=8109 (Tomcat的AJP13的port)
worker.node1.host=localhost (到時候這可以改成domainName 或 IP)
worker.node1.lbfactor=1 (數值越高取得請求比例越高)
worker.node2.type=ajp13
worker.node2.port=8209
worker.node2.host=localhost
worker.node2.lbfactor=1
worker.balancer.type=lb ( lb = Load Balancing)
worker.balancer.balance_workers=node1,node2 (指派分擔請求的Tomcat)
worker.balancer.sticky_session=1 (允許session 複製)
worker.stat.type=status
- httpd.conf
在/etc/httpd/httpd.conf文件中加入:
LoadModule jk_module modules/mod_jk.so
JkWorkersFile /etc/httpd/workers.properties ( works.properties檔案的路徑)
JkLogFile logs/mod_jk.log (產生LOG的檔案路徑)
JkLogLevel emerg
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"
JkMount
/status stat
JkMount /* balancer
<Proxy balancer://myCluster>
BalancerMember ajp://localhost:8109 loadfactor=10 route=node1
BalancerMember ajp://localhost:8209 loadfactor=10 route=node2
ProxySet lbmethod=byrequests
</Proxy>
<Location / >
ProxyPass balancer://myCluster/ stickysession=JSESSIONID nofailover=Off
</Location>
<Location /balancer-manager>
SetHandler balancer-manager
Order Deny,Allow
Allow from localhost
Deny from all
</Location>
- 配置Tomcat
可參考來源
- server.xml
在$TOMCAT_AS_DIR/conf/server.xml的檔案替換掉上面附圖標示那段,換成以下字段。
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelSendOptions="6">
<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.4"
port="45564"
frequency="500"
dropTime="3000"/>
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="auto"
port="5000"
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"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>
</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.ClusterSessionListener"/>
</Cluster>
加入 jvmRoute=”node1”的參數; 識別Tomcat的代號
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelSendOptions="6">
<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.4"
port="45564"
frequency="500"
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="auto"
port="5000"
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"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>
</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.ClusterSessionListener"/>
</Cluster>
加入 jvmRoute=”node1”的參數; 識別Tomcat的代號
<Engine
defaultHost=”localhost” name=”Catalina” jvmRoute=”node1”>
- context.xml
接著在portal-ext.properties
加入以下兩行參數
cluster.link.enabled=true (啟用Liferay的複製數據庫緩存和搜索索引)
cluster.link.autodetect.address=228.0.0.4:45564 (告訴Liferay的用於多播通信什麼網絡接口)
lucene.replicate.write=true (讓Lucene來跨節點複製索引)
dl.store.file.system.root.dir=/data/liferay/cluster_document_library (使用文件系統存儲文檔和圖片)