CentOS 7 安装 jakarta-tomcat-connectors-jk2-src-current.tar.gz 详细步骤(解压、编译、配置)

0 阅读1分钟

 一、准备环境

先确认你已经装了 Apache 和 Tomcat,还有编译工具(gcc、make 这些)。

# 安装编译工具和 Apache 开发包(httpd-devel 里有 apxs)
sudo yum install -y gcc make httpd-devel

二、解压源码包

安装包下载:pan.quark.cn/s/62d04e88b…,把下载好的 jakarta-tomcat-connectors-jk2-src-current.tar.gz放到一个目录,比如 /usr/local/src/,然后解压:

cd /usr/local/src/
tar zxvf jakarta-tomcat-connectors-jk2-src-current.tar.gz

解压后会生成一个文件夹,比如 jakarta-tomcat-connectors-jk2-src,名字可能带版本号,用 ls看看实际叫啥。

三、进入编译目录

进入解压后的 jk/native2目录(这是 JK2 的源码目录):

cd jakarta-tomcat-connectors-jk2-src/jk/native2

四、配置编译参数

运行配置脚本,指定 Apache 的 apxs路径(apxs 是 Apache 的扩展工具,一般在 /usr/sbin/apxs或 /usr/local/apache2/bin/apxs):

# 先找一下 apxs 在哪
which apxs
# 假设找到是 /usr/sbin/apxs,就执行:
./configure --with-apxs2=/usr/sbin/apxs

如果提示缺 libapr,就装 apr-devel

sudo yum install -y apr-devel apr-util-devel

五、编译并安装

配置完直接编译和安装:

make
make install

编译完成后,会在 Apache 的 modules 目录(比如 /etc/httpd/modules/或 /usr/local/apache2/modules/)生成 mod_jk2.so文件。

验证一下有没有生成:

ls /etc/httpd/modules/mod_jk2.so

六、配置 Apache 加载 JK2 模块

编辑 Apache 的配置文件 httpd.conf(一般在 /etc/httpd/conf/httpd.conf):

sudo vi /etc/httpd/conf/httpd.conf

在文件末尾加一行,加载 JK2 模块:

LoadModule jk2_module modules/mod_jk2.so

七、重启 Apache 生效

保存配置后重启 Apache:

sudo systemctl restart httpd

八、验证是否加载成功

查看 Apache 已加载的模块,确认 jk2_module在不在:

httpd -M | grep jk2

如果输出 jk2_module (shared),说明安装成功。