前面JBoss 系列二:使用Apache httpd(mod_cluster)和JBoss構架高可用集羣環境中咱們介紹了企業應用的目的的目的,負載均衡,容錯等,並經過Apache httpd(mod_cluster)和JBoss構架高可用集羣環境,咱們這裏在原有的環境中將mod_cluster換成mod_jk,其架構以下圖所示:html
本方案是在開源Linux操做系統Fedora 15上進行,咱們列出本方案使用的硬件和軟件,三臺物理機器,內存4GB或以上,安裝Fedora 15後IP地址分別爲10.66.192.48,10.66.192.231,10.66.192.232,咱們分別對這三臺物理機器作相應的安裝以下:
java
從http://tomcat.apache.org/download-connectors.cgi下載mod_jk.so包到本地(注意選擇適合本身操做系統對應httpd的包)。node
請參照系列一 Apache httpd 安裝(http://blog.csdn.net/kylinsoong/article/details/12291173)
web
編輯httpd/conf/httpd.conf,讓httpd監聽在10.66.192.48:80上:
apache
Listen 10.66.192.48:80拷貝mod_jk.so文件到httpd/modules目錄:
cp mod_jk.so /etc/httpd/modules在 httpd/conf.d下建立mod_jk.conf文件,編輯內容以下:
# Load mod_jk module # Specify the filename of the mod_jk lib LoadModule jk_module modules/mod_jk.so # Where to find workers.properties JkWorkersFile conf/workers.properties # You can use external file for mount points. # # It will be checked for updates each 60 seconds. # # The format of the file is: /url=worker # # /examples/*=loadbalancer JkMountFile conf/uriworkermap.properties # Where to put jk logs JkLogFile logs/mod_jk.log # Set the jk log level [debug/error/info] JkLogLevel info # Select the log format JkLogStampFormat "[%a %b %d %H:%M:%S %Y]" # JkOptions indicates to send SSK KEY SIZE JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories # JkRequestLogFormat JkRequestLogFormat "%w %V %T" # Mount your applications JkMount /application/* loadbalancer # Add shared memory. # This directive is present with 1.2.10 and # later versions of mod_jk, and is needed for # for load balancing to work properly JkShmFile logs/jk.shm # Add jkstatus for managing runtime data <Location /jkstatus/> JkMount status Order deny,allow Deny from all Allow from 127.0.0.1 </Location>在 httpd/conf下建立workers.properties,並添加以下內容:
# Define list of workers that will be used # for mapping requests worker.list=loadbalancer,status # Define Node1 # modify the host as your host IP or DNS name. worker.node1.port=8009 worker.node1.host=10.66.192.231 worker.node1.type=ajp13 worker.node1.ping_mode=A worker.node1.lbfactor=1 # Define Node2 # modify the host as your host IP or DNS name. worker.node2.port=8009 worker.node2.host=10.66.192.232 worker.node2.type=ajp13 worker.node2.ping_mode=A worker.node2.lbfactor=1 # Load-balancing behavior worker.loadbalancer.type=lb worker.loadbalancer.balance_workers=node1,node2 worker.loadbalancer.sticky_session=1 # Status worker for managing load balancer worker.status.type=status在 httpd/conf下建立uriworkermap.properties,並添加以下內容:
# Simple worker configuration file # Mount the Servlet context to the ajp13 worker /jmx-console=loadbalancer /jmx-console/*=loadbalancer /web-console=loadbalancer /web-console/*=loadbalancer #/printSession=loadbalancer #/printSession/*=loadbalancer配置完成後重啓 Apache httpd ,若是啓動顯示成功代表配置正確。
分別啓動10.66.192.231,10.66.192.232 JBoss,到管理界面,Profile -> General Configuration -> System Properties,單擊添加按鈕,添加兩組變量jvmRoute=node1,UseJK=true到10.66.192.231,以及jvmRoute=node2,UseJK=true到10.66.192.232.添加完成後,依次重啓兩個節點:tomcat
./standalone.sh -c standalone-ha.xml -b 10.66.192.231 -bmanagement=10.66.192.231 -u 239.255.100.100 -Djboss.node.name=node1
./standalone.sh -c standalone-ha.xml -b 10.66.192.232 -bmanagement=10.66.192.232 -u 239.255.100.100 -Djboss.node.name=node2
至此,配置結束,咱們能夠部署測試應用測試高可用,負責均衡等,相似於JBoss 系列二:使用Apache httpd(mod_cluster)和JBoss構架高可用集羣環境session