19.6.3. 安装 mod_jk 模块到 Apache HTTP 服务器(ZIP 方式)
预备条件
- 要执行这个任务,您必须使用安装在受支持环境里的 Apache HTTP 服务器或安装在 JBoss Enterprise Web Server 里的 Apache HTTP 服务器。请注意,JBoss Enterprise Web Server 里安装的 Apache HTTP 服务器是 JBoss EAP 6 的一部分。
- 如果您需要安装 Apache HTTP 服务器,请使用《Red Hat 企业版 Linux 部署指南》里的说明。
- 如果你需要安装 JBoss Enterprise Web Server,请使用《JBoss Enterprise Web Server 安装指南》里的说明。
- 如果您在使用 Apache HTTP 服务器,请从 Red Hat 客户入口 https://access.redhat.com 下载 JBoss EAP 6 Native 组件软件包 。这个软件包包含为 Red Hat 企业版 Linux 编译的
mod_jk和mod_cluster。如果您使用的是 JBoss Enterprise Web 服务器,它已经包含了mod_jk。 - 如果您在使用 Red Hat 企业版 Linux 5(RHEL)和原生 Apache HTTP 服务器(httpd 2.2.3),请在加载 mod_jk 模块前加载 mod_perl。
- 您必须用管理员权限(root)登录。
过程 19.11. 安装 mod_jk 模块
配置 mod_jk 模块
- 创建一个名为
HTTPD_HOME/conf.d/mod-jk.conf的文件并添加下列内容:注意
JkMount指令指定 Apache 应该转发哪些 URL 到 mod_jk 模块。根据指令的配置,mod_jk 将接收到的 URL 转发到正确的 Servlet 容器。要直接服务静态内容且只使用本地负载平衡器,URL 路径应该为/application/*。要将 mod_jk 用作负载平衡器,请使用/*将所有 URL 转发给 mod_jk。# 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 # 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 -ForwardDirectories # JkRequestLogFormat JkRequestLogFormat "%w %V %T" # Mount your applications # The default setting only sends Java application data to mod_jk. # Use the commented-out line to send all URLs through mod_jk. # JkMount /* loadbalancer 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>
查看这些值,确保它们是合理的,然后保存文件。 指定 JKMountFile 指令
除了mod-jk.conf里的 JKMount 指令以外,您可以指定一个包含多个转发到 mod_jk 的 URL 模式的文件。- 添加下列内容到
HTTPD_HOME/conf/mod-jk.conf文件:# 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
- 创建一个名为
HTTPD_HOME/conf/uriworkermap.properties的新文件,其中每一行对应一个 URL 模式。下面的例子展示了这个文件的语法。# Simple worker configuration file /*=loadbalancer
复制 mod_jk.so 文件到 HTTPD 的 modules 目录
注意
只有您的 HTTP 服务器在其modules/目录下没有mod_jk.so时它才是必需的。如果您在使用 JBoss EAP 6 里包含的 Apache HTTP 服务器,您可以跳过这个步骤。解压 Native Web Server Connectors ZIP 软件包。在EAP_HOME/modules/system/layers/base/native/lib/httpd/modules/或EAP_HOME/modules/system/layers/base/native/lib64/httpd/modules/目录里找到mod_jk.so文件(根据操作系统是 32 还是 64 位的)。复制文件到HTTPD_HOME/modules/目录。
配置 mod_jk 工作节点。
- 创建一个名为
HTTPD_HOME/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=node1.mydomain.com 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=node2.mydomain.com 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
关于workers.properties文件的详细描述和高级配置选项,请参考 第 19.6.5 节 “Apache Mod_jk 工作节点的配置”。
重启 Web Server。
重启 Web 服务器的方法取决于您是否使用 Red Hat 企业版 Linux 的 Apache HTTP 或包含在 JBoss Enterprise Web Server 里的 Apache HTTP 服务器。请从下面两个方法里选择一个。Red Hat 企业版 Linux 的 Apache HTTP 服务器
运行下列命令:[root@host]#
service httpd restartJBoss Enterprise Web Server 的 Apache HTTP 服务器
JBoss Enterprise Web Server 既可以运行在 Red Hat Enterprise Linux 也可以运行在 Microsoft Windows Server 上。两者重启 Web 服务器的方法是不同的。Red Hat 企业版 Linux(通过 RPM 安装)
在 Red Hat 企业版 Linux 里,JBoss Enterprise Web Server 将 Web 服务器安装为服务。要重启 Web 服务器,执行下面两个命令:[root@host ~]# service httpd stop [root@host ~]# service httpd start
Red Hat 企业版 Linux(通过 ZIP 安装)
如果您已经通过 ZIP 归档安装了 JBoss Enterprise Web Server 的 Apache HTTP 服务器,请使用apachectl命令来重启 Web 服务器。请用您解压 JBoss Enterprise Web Server 的 Apache HTTP 服务器的目录来替换 EWS_HOME。[root@host ~]# EWS_HOME/httpd/sbin/apachectl restart
Microsoft Windows Server
用管理员权限执行下列命令:C:\> net stop Apache2.2 C:\> net start Apache2.2
Solaris
请在命令行提示下用有管理权限的用户执行下列命令。请用您解压 JBoss Enterprise Web 服务器的 Apache HTTP 服务器的目录来替换 EWS_HOME。[root@host ~] EWS_HOME/httpd/sbin/apachectl restart
已配置 Apache HTTP 服务器使用 mod_jk 负载平衡器。要使 JBoss EAP 6 可以意识到 mod_jk,请参照 第 19.3.6 节 “配置 JBoss EAP 6 接受外部 Web 服务器的请求”。

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.