li26598296 发表于 2017-1-10 08:41:05

Configure JBoss EAP 6 to Communicate with Apache Mod_jk

  1. 安装Apache
  我使用的版本是httpd-2.2.15。下载解压后进入httpd的根目录,依次执行如下命令:
  $ sudo ./configure --prefix=PREFIX --enable-so --enable-mods-shared=most --enable-ssl
     $ sudo make
     $ sudo make install
  启动apache
     $ PREFIX/bin/apachectl start
  配置为service
  将apachectl拷贝到init.d
  sudo cp apachectl /etc/init.d/httpd
  sudo chkconfig --add httpd
     sudo chkconfig httpd on
  sudo service httpd start
  注意:
  1)PREFIX要替换为Apache的安装目录,如/usr/local/apache2.2
  2)如果您使用的是httpd2.4,安装包中不包含APR 、APR-Util 和 Perl-Compatible Regular Expressions Library (PCRE),如系统中未曾安装,需下载安装。
  安装apr:
  sudo ./configure --prefix=/usr/local/apr
    sudo make
    sudo make install
  安装apr-util:
  sudo ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
    sudo make
    sudo make install
  安装pcre:
  sudo ./configure --prefix=/usr/local/pcre
    sudo make
    sudo make install
  重新执行命令:
  sudo ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-so  --enable-mods-shared=most --enable-ssl
  若启动后报错Failed to lookup provider 'shm' for 'slotmem': is mod_slotmem_shm loaded?
  修改httpd.conf配置文件,放开该模块即可。
  2. 安装mod_jk
  下载mod_jk, 解压后进入native目录,依次执行如下命令:
  ./configure --with-apxs=/usr/local/apache2.2/bin/apxs
     make
  编译成功后,进入native/apache-2.0目录,将mod_jk.so拷贝到Apache的modules目录下。
  3. 配置mod_jk
  在Apache的conf目录中创建三个文件:mod-jk.conf、workers.properties、uriworkermap.properties,内容如下:
  mod-jk.conf
  # Load mod_jk module
# Update this path to match your modules location
LoadModule jk_module modules/mod_jk.so
 
# Declare the module for <IfModule directive>
#AddModule mod_jk.c
 
# Where to find workers.properties
# Update this path to match your conf directory location (put workers.properties next to httpd.conf)
JkWorkersFile conf/workers.properties
 
# Where to put jk logs
# Update this path to match your logs directory location (put mod_jk.log next to access_log)
JkLogFile logs/mod_jk.log
 
# Set the jk log level
JkLogLevel info
 
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
 
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
 
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
 
# 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
 
# 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

# Add jkstatus for managing runtime data
<Location /jkstatus/>
    JkMount status
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
</Location>
  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.reference=worker.template
worker.node1.host=192.168.50.1
worker.node1.port=8009
worker.node1.lbfactor=1
  # Define Node2
# modify the host as your host IP or DNS name.
worker.node2.reference=worker.template
worker.node2.host=192.168.50.2
worker.node2.port=8009
worker.node2.lbfactor=2

worker.template.type=ajp13
worker.template.socket_connect_timeout=5000
worker.template.socket_keepalive=true
worker.template.connection_pool_minsize=0
worker.template.connection_pool_timeout=600
worker.template.ping_mode=A
 
# Load-balancing behaviour 
worker.loadbalancer.type=lb 
worker.loadbalancer.balance_workers=node1,node2
worker.loadbalancer.sticky_session=true

# Status worker for managing load balancer
worker.status.type=status
  uriworkermap.properties
  /signac-web|/*=loadbalancer

#
# Mount jkstatus to /jkmanager
# For production servers you will need to
# secure the access to the /jkmanager url
#
/jkstatus=status
  最后在httpd.conf文件中添加:
  Include conf/mod-jk.conf
  4、配置EAP
  mod_jk使用AJP协议进行通讯,需在web subsystem中配置 ajp connector;
  另外需配置jvmRoute,如未配置sticky_session是不起作用的。在EAP6中需添加属性instance-id="node1"(名称要与workers.properties中一致),如下:
  <subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" native="false" instance-id="node1">
            <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
            <connector name="ajp" protocol="AJP/1.3" scheme="http" socket-binding="ajp"/>
            ....
        </subsystem>
  绑定ajp端口
  <socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
        ...
        <socket-binding name="ajp" port="8009"/>
  <socket-binding name="http" port="8080"/>
  ....
  </socket-binding-group>
  5、启动jboss和apache
  启动apache:
  ./apachectl start
  测试页面:
  jkstatus: http://127.0.0.1/jkstatus
  signac-web: http://127.0.0.1/signac-web
  附:
  如使用YUM安装apache,需执行
  yum install httpd
  yum install httpd-devel
  httpd-devel中包含apxs。
  升级openssl时注意使用--shared,否则可能会提示版本冲突
  ./config --prefix=/usr --shared
  SSL Server Test
页: [1]
查看完整版本: Configure JBoss EAP 6 to Communicate with Apache Mod_jk