Apache的負載平衡之mod_jk模組實現

來源:互聯網
上載者:User

標籤:apache mod_jk   負載平衡

     

          Apache的負載平衡之mod_jk模組實現

 

    先配置mod_jk的代理功能,

[[email protected] ~]# yum install -y httpd-devel

[[email protected] ~]# rpm -ql httpd-devel

/usr/sbin/apxs

apxs是httpd安裝外部模組必備的

 

[[email protected] ~]# yum groupinstall"Development Tools" "Server Platform Development" -y //所需要的包組。

    編譯安裝需要的環境。

[[email protected] ~]# tar xftomcat-connectors-1.2.40-src.tar.gz

[[email protected] ~]# ls

a                            install.log              oracle

apache-tomcat-7.0.56.tar.gz  install.log.syslog       root20141030092112523.zip

apache-tomcat-8.0.20.tar.gz  jdk-8u31-linux-i586.rpm  tomcat-connectors-1.2.40-src

b                            lamp                    tomcat-connectors-1.2.40-src.tar.gz

[[email protected] ~]# cd tomcat-connectors-1.2.40-src

[[email protected] tomcat-connectors-1.2.40-src]# ls

conf docs  HOWTO-RELEASE.txt  jkstatus LICENSE  native  NOTICE README.txt  support  tools xdocs

[[email protected] tomcat-connectors-1.2.40-src]# cdnative/

[[email protected] native]# ls

aclocal.m4 apache-2.0    BUILDING.txt  configure    docs  Makefile.am  netscape   scripts     TODO.txt

apache-1.3 buildconf.sh  common        configure.ac  iis  Makefile.in  README.txt  STATUS.txt

[[email protected] native]# ./configure--with-apxs=/usr/sbin/apxs

[[email protected] native]# make && makeinstall

              。

              。

              。

----------------------------------------------------------------------

chmod 755/usr/lib64/httpd/modules/mod_jk.so

 

Please be sure to arrange/etc/httpd/conf/httpd.conf...

 

make[1]: Leaving directory`/root/tomcat-connectors-1.2.40-src/native/apache-2.0‘

make[1]: Entering directory`/root/tomcat-connectors-1.2.40-src/native‘

make[2]: Entering directory`/root/tomcat-connectors-1.2.40-src/native‘

make[2]: Nothing to be done for`install-exec-am‘.

make[2]: Nothing to be done for`install-data-am‘.

make[2]: Leaving directory`/root/tomcat-connectors-1.2.40-src/native‘

make[1]: Leaving directory`/root/tomcat-connectors-1.2.40-src/native‘


[[email protected] ~]# cd /etc/httpd

[[email protected] httpd]# ls

conf conf.d  logs  modules run

[[email protected] httpd]# cd conf.d/

[[email protected] conf.d]# ls

php.conf README  welcome.conf

[[email protected] conf.d]# vim mod_jk.conf

# Load the mod_jk

LoadModule jk_module  modules/mod_jk.so

JkWorkersFile  /etc/httpd/conf.d/workers.properties

JkLogFile logs/mod_jk.log

JkLogLevel debug

JkMount /*  TomcatA

JkMount /status/  statA

~                                    

[[email protected] conf.d]# vim/etc/httpd/conf.d/workers.properties

worker.list = TomcatA,statA

worker.TomcatA.port=8009

worker.TomcatA.host=192.168.1.116

worker.TomcatA.type=ajp13

worker.TomcatA.lbfactor=1

worker.statA.type = status

 

[[email protected] conf.d]# httpd -t

Syntax OK

[[email protected] conf.d]# service httpd restart

Stopping httpd:                                           [  OK  ]

Starting httpd:                                            [ OK  ]

[[email protected] conf.d]#

    至此,一個基於mod_jk模組與後端名為TomcatA的worker通訊的配置已經完成,重啟httpd服務即可生效。

650) this.width=650;" src="http://home.51cto.com/thumb.php?w=600&h=600&t=f&url=http://s3.51cto.com/wyfs02/M01/59/FF/wKioL1TzK2aQLNnsAALrg_E-QqU235.jpg" id="big_pic" alt="wKioL1TzK2aQLNnsAALrg_E-QqU235.jpg" />

 

    還有狀態資訊  

650) this.width=650;" src="http://home.51cto.com/thumb.php?w=600&h=600&t=f&url=http://s3.51cto.com/wyfs02/M00/5A/02/wKiom1TzKlGxumFAAAPIzvlqjzQ107.jpg" alt="wKiom1TzKlGxumFAAAPIzvlqjzQ107.jpg" />

 

要實現負載平衡,至少需要兩個tomcat還在本機上操作,配置另一個版本的tomcat,配置完成之後訪問http://192.168.1.116:9080

650) this.width=650;" src="http://home.51cto.com/thumb.php?w=600&h=600&t=f&url=http://s3.51cto.com/wyfs02/M02/5A/02/wKiom1TzKmaT5124AAPGzvdrBTQ853.jpg" alt="wKiom1TzKmaT5124AAPGzvdrBTQ853.jpg" />

   mod_jk可直接支援負載平衡,需要啟用一個特殊型的worker:lb。

[[email protected] conf.d]# vim mod_jk.conf

 #Load the mod_jk

LoadModule jk_module  modules/mod_jk.so

JkWorkersFile  /etc/httpd/conf.d/workers.properties

JkLogFile logs/mod_jk.log

JkLogLevel debug

JkMount /*  lbcluster1

JkMount /status/  statA

~                      

[[email protected] conf.d]# vim workers.properties

worker.list = lbcluster1,statA

worker.TomcatA.port=8009

worker.TomcatA.host=192.168.1.116

worker.TomcatA.type=ajp13

worker.TomcatA.lbfactor=1

worker.TomcatB.port=9009

worker.TomcatB.host=192.168.1.116

worker.TomcatB.type=ajp13

worker.TomcatB.lbfactor=1

worker.lbcluster1.type = lb

sorker.lbcluster1.sticky_session = 0

worker.lbcluster1.balance_workers =TomcatA, TomcatB

worker.statA.type = status

~                                                                                                          

[[email protected] conf.d]# httpd -t

Syntax OK

[[email protected] bin]# service httpd restart

Stopping httpd:                                           [  OK  ]

Starting httpd:                                           [  OK  ]

[[email protected] bin]#

    到此mod_jk實現負載平衡就配置好了,測試如下。

    訪問http://192.168.1.116

650) this.width=650;" src="http://home.51cto.com/thumb.php?w=600&h=600&t=f&url=http://s3.51cto.com/wyfs02/M01/59/FF/wKioL1TzK2aQLNnsAALrg_E-QqU235.jpg" alt="wKioL1TzK2aQLNnsAALrg_E-QqU235.jpg" />

    再次重新整理

650) this.width=650;" src="http://home.51cto.com/thumb.php?w=600&h=600&t=f&url=http://s3.51cto.com/wyfs02/M00/5A/02/wKiom1TzLQ3gJumBAAMHlrwgNjM147.jpg" alt="wKiom1TzLQ3gJumBAAMHlrwgNjM147.jpg" />


Apache的負載平衡之mod_jk模組實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.