Tomcat实现反向代理、负载均衡、内存复制----apache做前端代理,基于mod_proxy模块与Tomcat连接
4.1 编译安装apache
唯一的区别是在编译时额外加上
1.--enable-proxy --enable-proxy-http --enable-proxy-ajp
2.
3.--enable-proxy ##启用代理
4.--enable-proxy-http ##启用http代理模块
5.--enable-proxy-ajp ##启用ajp代理模块
4.2 编缉/etc/httpd/httpd.conf
1.vi /etc/httpd/httpd.conf
2.
3.LoadModule slotmem_shm_module modules/mod_slotmem_shm.so ##启用该模块
4.#DocumentRoot "/usr/local/apache/htdocs" ##注释掉,我们启用虚拟主机
5.Include /etc/httpd/extra/httpd-vhosts.conf ##我们用虚拟主机
4.3 编缉/etc/httpd/extra/httpd-vhosts.conf
1.<VirtualHost *:80>
2. ServerName jsprun.linuxidc.com
3. ProxyVia Off ##不让代理在http首部中显示
4.ProxyRequests Off ##关闭正向代理
5.ProxyPass / http://jsprun.linuxidc.com:8080/ ##访问/则代理到jsprun中
6.ProxyPassReverse / http://jsprun.linuxidc.com:8080/ ##不让tomcat直接响应客端
7.<Proxy *>
8. Require all granted
9.</Proxy>
10.<Location/>
11. Require all granted
12.</Location>
13. ErrorLog "logs/linuxidc-error_log"
14. CustomLog "logs/linuxidc-access_log" common
15.</VirtualHost>
4.4 修改linux的/etc/hosts为jsprun.linuxidc.com解析
1.vi /etc/hosts
2.
3.172.16.1.22 jsprun.linuxidc.com jsprun
4.5 访问http://jsprun.linuxidc.com测试
4.6 基于ajp协议与tomcat连接,与http的基本相同,只修改协议与端口即可,其它的一样
1.ProxyPass / ajp://jsprun.linuxidc.com:8009/
2.ProxyPassReverse / ajp://jsprun.linuxidc.com:8009/