前期准备:
linux环境
tomcat多个
apache服务器: httpd-2.4.33.tar.gz http://httpd.apache.org/download.cgi
APR
apr-1.6.3.tar.gz
apr-util-1.6.1.tar.gz
pcre-8.42.tar.gz
tomcat-connectors-1.2.40-src.tar.gz
**在配置mod_jk.conf时mod_jk.so的配置要通过安装tomcat-connectors-1.2.40-src.tar.gz
在native目录下的apache-2内会生成一个mod_jk.so,把它复制到你apache的modules下。**
启动apache总是加载不出mod_jk.so
解决方法:
下载:tomcat-connectors-1.2.40-src.tar.gz
root@localhost ~]# tar zxf tar zxf tomcat-connectors-1.2.40-src.tar.gz
[root@localhost ~]# cd tomcat-connectors-1.2.40-src/native
[root@localhost native]# ./configure --with-apxs=/usr/local/apache2/bin/apxs
[root@localhost native]# make
如果make成功的话,在当前目录的apache-2下应该会生成一个mod_jk.so,把它复制到你apache的modules下。
[root@localhost apache-2.0]# cp mod_jk.so /usr/local/apache2/modules/
pcre安装
1.解压进入目录
# tar -zxvf pcre-8.42.tar.gz
# cd /home/jiqun/pcre-8.42
2.进入目录执行./configure –prefix=安装路径,进行初始化配置
出现错误:
checking for a BSD-compatible install… /bin/install -c
checking whether build environment is sane… yes
checking for a thread-safe mkdir -p… /bin/mkdir -p
checking for gawk… gawk
checking whether make sets $(MAKE)… yes
checking whether make supports nested variables… yes
checking whether make supports nested variables… (cached) yes
checking for style of include used by make… GNU
checking for gcc… no
checking for cc… no
checking for cl.exe… no
configure: error: in /home/jiqun/pcre-8.42':
config.log’ for more details
configure: error: no acceptable C compiler found in $PATH
See
查看得知未安装合适的编译器。
sudo yum install gcc-c++
(使用sudo yum install gcc-c++时会自动安装/升级gcc及其他依赖的包。)
3.再次执行./configure
4.一次执行make、make install
success!
安装apr;
1.解压进入目录
2.执行./configure –prefix=安装路径 ,(安装pcre时安装了sudo yum install gcc-c++,这会儿不会报错,如过报configure: error: no acceptable C compiler found in $PATH,执行一遍即可);
3.一次执行make、makeinstall;
success!
安装apr-util
1.执行./configure –prefix=安装路径
出错:
[root@centos7jiqun apr-util-1.6.1]# ./configure
checking build system type… x86_64-pc-linux-gnu
checking host system type… x86_64-pc-linux-gnu
checking target system type… x86_64-pc-linux-gnu
checking for a BSD-compatible install… /bin/install -c
checking for working mkdir -p… yes
APR-util Version: 1.6.1
checking for chosen layout… apr-util
checking for gcc… gcc
checking whether the C compiler works… yes
checking for C compiler default output file name… a.out
checking for suffix of executables…
checking whether we are cross compiling… no
checking for suffix of object files… o
checking whether we are using the GNU C compiler… yes
checking whether gcc accepts -g… yes
checking for gcc option to accept ISO C89… none needed
Applying apr-util hints file rules for x86_64-pc-linux-gnu
checking for APR… no
configure: error: APR could not be located. Please use the –with-apr option.
解决方法:
apr-util安装:
1)./configure –prefix=apr-util路径 –with-apr=apr路径
2)make
make出错:
ad -DHAVE_CONFIG_H -DLINUX -D_REENTRANT -D_GNU_SOURCE -I/home/jiqun/apr-util-1.6.1/include -I/home/jiqun/apr-util-1.6.1/include/private -I/home/jiqun/apr-1.6.3/include -o xml/apr_xml.lo -c xml/apr_xml.c && touch xml/apr_xml.lo
xml/apr_xml.c:35:19: 致命错误:expat.h:没有那个文件或目录
#include
yum install expat-devel -y
3)make install;
success!
apache安装
1.解压http-**.tar.gz;
把解压好的apr和apr-util 复制到 /httpd-2.4.33/srclib/ 中去
cp -r apr-1.6.1 /usr/local/src/httpd-2.4.33/srclib/apr
cp -r apr-util-1.6.2 /usr/local/src/httpd-2.4.33/srclib/apr-util
2.
./configure --prefix=apache安装路径(自定) --with-apr=原apr安装路径 --with-apr-util=原来apr-util安装路径 --with-pcre原来pcre安装路径 --enable-mods-shared=most --enable-so --with-included-apr
2.make
报错:collect2: error: ld returned 1 exit status
make[2]: * [htpasswd] 错误 1
make[2]: 离开目录“/home/jiqun/httpd-2.4.33/support”
make[1]: * [all-recursive] 错误 1
make[1]: 离开目录“/home/jiqun/httpd-2.4.33/support”
make: * [all-recursive] 错误 1
解决方法:https://blog.csdn.net/River_Crab/article/details/79732131
3.make install
启动apache:
在/apache/bin目录下执行./apachectl start
./apachectl stop 停止服务
./apachectl restart 重启服务
配置mod_jk
在配置mod_jk.conf时mod_jk.so的配置要通过安装tomcat-connectors-1.2.40-src.tar.gz
在native目录下的apache-2内会生成一个mod_jk.so,把它复制到你apache的modules下。
安装tomcat-connectors-1.2.40-src.tar.gz
root@localhost ~]# tar zxf tar zxf tomcat-connectors-1.2.40-src.tar.gz
[root@localhost ~]# cd tomcat-connectors-1.2.40-src/native
#yum install httpd-devel(依据情况而定)
#find / -name apxs //查找apxs文件夹的位置
[root@localhost native]# ./configure --with-apxs=apxs文件夹的位置
[root@localhost native]# make
如果make成功的话,在当前目录的apache-2下应该会生成一个mod_jk.so,把它复制到你apache的modules下。
[root@localhost apache-2.0]# cp mod_jk.so /usr/local/apache2/modules/
修改Apache配置
1、修改httpd.conf
conf目录下的httpd.conf,在文件的最后一行添加
Include conf/mod_jk.conf
在相应位置新建mod_jk.conf
在mod_jk.conf中添加如下内容:
加载mod_jk Module
LoadModule jk_module modules/mod_jk-1.2.31-httpd-2.2.3.so
指定workers.properties文件路径
JkWorkersFile conf/workers.properties
指定那些请求交给tomcat处理,”controller”为在workers.propertise里指定的负载分配控制器名
JkMount /* controller
然后在*\conf创建一个workers.properties的文件,添加如下内容
server
worker.list = controller
========tomcat1======== #ajp13端口号,在tomcat下server.xml配置,默认8009
worker.tomcat1.port=8009
tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat1.host=localhost
协议类型
worker.tomcat1.type=ajp13
server的加权比重,值越高,分得的请求越多。lbfactor是负载平衡因数(Load Balance Factor)
worker.tomcat1.lbfactor=1
========tomcat2
worker.tomcat2.port=9009
worker.tomcat2.host= localhost
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=1
========controller,负载均衡控制器======== #负载均衡控制器类型,lbfactor是负载平衡因数(Load Balance Factor)
worker.controller.type=lb
指定分担请求的tomcat列表
worker.controller.balanced_workers=tomcat1,tomcat2
粘性session(默认是打开的) 当该属性值=true(或1)时,代表session是粘性的,即同一session在集群中的同一个节点上处理,session不跨越节点。在集群环境中,一般将该值设置为false
worker.controller.sticky_session=false
设置用于负载均衡的server的session可否共享
worker.controller.sticky_session_force=1