yum安装tomcat
[root@node5 ~]# yum -y install java-1.8.0-openjdk-devel tomcat tomcat-webapps tomcat-admin-weapps tomcat-docs-webapp
[root@node5 ~]# ls /var/lib/tomcat/webapps/
docs examples host-manager manager ROOT sample
[root@node5 ~]# mkdir test
[root@node5 ~]# mkdir test/{WEB-INF,META-INF,lib,classes}
[root@node5 ~]# tree test
test
├── classes
├── lib
├── META-INF
└── WEB-INF
4 directories, 0 files
在tomcat上创建默认测试页
[root@node5 ~]# vi test/index.jsp
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<html>
<head>
<title>Test Page</title>
</head>
<body>
<% out.println("hello world");
%>
</body>
</html>
复制测试页到tomcat路径下
[root@node5 ~]# cp -a test/ /var/lib/tomcat/webapps/
[root@node5 ~]# ls /var/lib/tomcat/webapps/
docs examples host-manager manager ROOT sample test
[root@node5 ~]# systemctl start tomcat
浏览器输入:http://192.168.170.30:8080/test/index.jsp
[root@node5 ~]# cd /var/cache/tomcat/work/
[root@node5 work]# ls
Catalina
[root@node5 work]# tree Catalina/
Catalina/
└── localhost
├── _
│ └── org
│ └── apache
│ └── jsp
│ ├── index_jsp.class
│ └── index_jsp.java
├── docs
├── examples
├── host-manager
│ └── org
│ └── apache
│ └── jsp
│ └── WEB_002dINF
│ └── jsp
│ ├── _401_jsp.class
│ └── _401_jsp.java
├── manager
│ └── org
│ └── apache
│ └── jsp
│ └── WEB_002dINF
│ └── jsp
│ ├── _401_jsp.class
│ └── _401_jsp.java
└── sample
20 directories, 6 files
[root@node5 work]#
编辑tomcat-users.xml,添加用户名和密码为管理图形化界面
[root@node5 tomcat]# vi tomcat-users.xml
<role rolename="manager-gui"/>
<user username="tomcat" password="tomcat" roles="manager-gui"/>
启动tomcat服务
[root@node5 tomcat]# systemctl restart tomcat
浏览器测试:192.168.170.30:8080,显示tomcat默认测试页面
[root@node5 tomcat]# vi tomcat-users.xml
<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<user username="tomcat" password="tomcat" roles="manager-gui,admin-gui"/>
[root@node5 tomcat]# systemctl restart tomcat
浏览器登陆测试:
创建配置文件路径,制作其它测试页
[root@node5 tomcat]# mkdir -pv /appdata/ilinux/ROOT/
mkdir: created directory ‘/appdata’
mkdir: created directory ‘/appdata/ilinux’
mkdir: created directory ‘/appdata/ilinux/ROOT/’
[root@node5 tomcat]#
[root@node5 tomcat]# cp /root/test/* /appdata/ilinux/ROOT/ -a
[root@node5 tomcat]# vi /appdata/ilinux/ROOT/index.jsp
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<html>
<head>
<title>Test Page</title>
</head>
<body>
<% out.println("hello ilinux.io");
%>
</body>
</html>
重启tomcat服务
[root@node5 tomcat]# systemctl restart tomcat
查看正常服务是否启动
[root@node5 tomcat]# ss -tunlp
tcp LISTEN 0 1 ::ffff:127.0.0.1:8005 :::* users:(("java",pid=18238,fd=59))
tcp LISTEN 0 100 :::8009 :::* users:(("java",pid=18238,fd=55))
tcp LISTEN 0 100 :::8080 :::* users:(("java",pid=18238,fd=54))
[root@node5 ~]# curl http://www.mylinux.com:8080
<html>
<head>
<title>Test Page</title>
</head>
<body>
hello ilinux.io
</body>
</html>
[root@node5 ~]# curl http://127.0.0.1:8080/test/index.jsp
<html>
<head>
<title>Test Page</title>
</head>
<body>
hello world
</body>
</html>
[root@node5 ~]#
浏览器测试:http://www.mylinux.com:8080 正常
上传shopxx网站程序包在解压并在tomcat上运行
[root@node5 ~]# unzip shopxx-a5-Beta.zip
[root@node5 ~]# ls
cobbler.ks ks-post-nochroot.log shopxx-a5-Beta.zip shopxx-v3.0-Beta
[root@node5 ~]# cp -a /root/shopxx-v3.0-Beta/shopxx-3.0Beta/ /appdata/ilinux/
[root@node5 ilinux]# ln -sv shopxx-3.0Beta shopxx
‘shopxx’ -> ‘shopxx-3.0Beta’
[root@node5 ~]# vi /etc/tomcat/server.xml
</Host>
<Host name="www.mylinux.com" appBase="/appdata/ilinux" unpackWARs="true" autoDeploy="true"/>
<Context path="/eshop" docBase="/e-shop/shopxx" reloadable="true"/>
[root@node5 ~]#
浏览器测试:http://www.mylinux.com:8080/shopxx 跳转到安装页面
示例4:
[root@node5 e-shop]# rm -rf shopxx*
[root@node5 ilinux]# ll
total 0
drwxr-xr-x 6 root root 80 Jan 12 06:27 ROOT
[root@node5 ilinux]# cp -a /root/shopxx-v3.0-Beta/shopxx-3.0Beta/ /e-shop/
[root@node5 ilinux]# cd -
/e-shop
[root@node5 e-shop]# ln -sv shopxx-3.0Beta shopxx
‘shopxx’ -> ‘shopxx-3.0Beta’
[root@node5 e-shop]# ls
shopxx shopxx-3.0Beta
[root@node5 ~]# vi /etc/tomcat/server.xml
</Host>
<Host name="www.ilinux.io" appBase="/appdata/ilinux" unpackWARs="true" autoDeploy="true"/>
<Context path="/eshop" docBase="/e-shop/shopxx" reloadable="true"/>
</Host>
[root@node5 ~]# systemctl restart tomcat
[root@node5 ~]# ss -tunlp
浏览器测试:http://www.mylinux.com:8080/eshop 跳转到安装页面
示例5:
LNMT示例
Tomcat backend server
node2 192.168.10.11
gateway:192.168.10.254
[root@node2 ~]# yum -y install java-1.8.0-openjdk-devel tomcat tomcat-webapps tomcat-admin-weapps tomcat-docs-webapp
[root@node2 ~]# systemctl start tomcat.service
[root@node2 ~]# ss -tunlp
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp LISTEN 0 1 ::ffff:127.0.0.1:8005 :::* users:(("java",pid=14309,fd=54))
tcp LISTEN 0 100 :::8009 :::* users:(("java",pid=14309,fd=50))
tcp LISTEN 0 128 :::8080 :::* users:(("java",pid=14309,fd=49))
tcp LISTEN 0 128 :::22 :::* users:(("sshd",pid=846,fd=4))
tcp LISTEN 0 100 ::1:25 :::* users:(("master",pid=1160,fd=14))
[root@node2 ~]# mkdir -pv /var/lib/tomcat/webapps/test/{WEB-INF,META-INF,lib,classes}
mkdir: created directory ‘/var/lib/tomcat/webapps/test’
mkdir: created directory ‘/var/lib/tomcat/webapps/test/WEB-INF’
mkdir: created directory ‘/var/lib/tomcat/webapps/test/META-INF’
mkdir: created directory ‘/var/lib/tomcat/webapps/test/lib’
mkdir: created directory ‘/var/lib/tomcat/webapps/test/classes’
[root@node2 ~]# vi /var/lib/tomcat/webapps/test/index.jsp
<%@ page language="java" %>
<html>
<head><title>TomcatB</title></head>
<body>
<h1><font color="blue">TomcatB.magedu.com</font></h1>
<table align="centre" border="1">
<tr>
<td>Session ID</td>
<% session.setAttribute("magedu.com","magedu.com"); %>
<td><%= session.getId() %></td>
</tr>
<tr>
<td>Created on</td>
<td><%= session.getCreationTime() %></td>
</tr>
</table>
</body>
</html>
[root@node2 ~]#
浏览器;192.168.10.11:8080 正常
www.ilinux.io/test/ 正常
nginx做反向代理
node3 ens192 192.168.170.9
ens224 192.168.10.254
[root@node3 ~]# vi /etc/hosts
192.168.10.11 www.mylinux.com
[root@node3 ~]# yum -y install nginx
[root@node3 ~]# vi /etc/nginx/conf.d/ilinux.conf
server {
listen 80;
server_name www.mylinux.com;
location / {
proxy_pass http://192.168.10.12:8080;
}
}
[root@node3 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@node3 ~]# systemctl restart nginx
[root@node3 ~]# ss -tunlp
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp LISTEN 0 1 ::ffff:127.0.0.1:8005 :::* users:(("java",pid=14309,fd=54))
tcp LISTEN 0 100 :::8009 :::* users:(("java",pid=14309,fd=50))
tcp LISTEN 0 128 :::8080 :::* users:(("java",pid=14309,fd=49))
tcp LISTEN 0 128 :::22 :::* users:(("sshd",pid=846,fd=4))
tcp LISTEN 0 100 ::1:25 :::* users:(("master",pid=1160,fd=14))
[root@node3 ~]# tail /var/log/nginx/access.log 确实通过代理访问
172.17.1.35 - - [12/Jan/2019:21:11:26 +0800] "GET /favicon.ico HTTP/1.1" 404 0 "http://www.mylinux.com/test/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36" "-"
node3对后端主机做动静分离
[root@node3 ~]# vi /etc/nginx/conf.d/ilinux.conf
server {
listen 80;
server_name www.ilinux.io;
location / {
proxy_pass http://192.168.10.12:8080;
}
location ~* \.(jsp|do)$ {
proxy_pass http://192.168.10.12:80;
}
}
[root@node3 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@node3 ~]# nginx -s reload
[root@node3 ~]# ss -tunlp
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp LISTEN 0 1 ::ffff:127.0.0.1:8005 :::* users:(("java",pid=14309,fd=54))
tcp LISTEN 0 100 :::8009 :::* users:(("java",pid=14309,fd=50))
tcp LISTEN 0 128 :::8080 :::* users:(("java",pid=14309,fd=49))
tcp LISTEN 0 128 :::22 :::* users:(("sshd",pid=846,fd=4))
tcp LISTEN 0 100 ::1:25 :::* users:(("master",pid=1160,fd=14))
node2 192.168.10.12 动态和静态资源都放在上面
[root@node2 ~]# cd /var/lib/tomcat/webapps/test/
[root@node2 test]# cp /var/www/html/sky.jpg ./
[root@node2 test]# ls
classes sky.jpg index.jsp lib META-INF WEB-INF
客户端浏览器测试:www.mylinux.com/test/和www.mylinux.com/test/sky.jpg都是通过nginx调度到后端服务器取得的资源
LAMT部署
使用httpd的reverse_proxy_module模块反代至tomcat
1、proxy_module, proxy_http_module
httpd的安装
[root@node3 ~]# yum -y install httpd
修改httpd配置文档
注释掉主配置文档中的DocumentRoot
[root@node3 ~]# vim /etc/httpd/conf/httpd.conf
#DocumentRoot "/var/www/html"
创建http_tomcat.conf的子配置文档
[root@node3 ~]# vim /etc/httpd/conf.d/http_tomcat.conf
<VirtualHost *:80>
ServerName www.mylinux.com
ProxyRequests Off
#DocumentRoot "/data/ilinux/htdocs"
ProxyVia On
ProxyPreserveHost On
<Proxy *>
Require all granted
</Proxy>
ProxyPass / http://192.168.10.11:8080/ 反向代理到后端主机
ProxyPassReverse / http://192.168.10.11:8080/
<Location>
Require all granted
</Location>
</VirtualHost>
- 验证配置并启动httpd
[root@node3 ~]# httpd -t
Syntax OK
[root@node3 ~]# systemctl start httpd.service
客户端测试:
www.ilinux.io/test
客户端浏览器测试:www.mylinux.com/test 依然正常访问
示例7
2、proxy_module, proxy_ajp_module
httpd反代至tomcat的ajp 8009端口
[root@node3 ~]# cd /etc/httpd/conf.d/
[root@node3 conf.d]# ls
autoindex.conf http_tomcat.conf README userdir.conf welcome.conf
[root@node3 conf.d]# cp http_tomcat.conf ajp_tomcat.conf
[root@node3 conf.d]# mv http_tomcat.conf http_tomcat.conf.bak
[root@node3 conf.d]# vim ajp_tomcat.conf
<VirtualHost *:80>
ServerName www.myunix.com
ProxyRequests Off
#DocumentRoot "/data/ilinux/htdocs"
ProxyVia On
ProxyPreserveHost On
<Proxy *>
Require all granted
</Proxy>
ProxyPass / ajp://192.168.10.11:8009/ 反向代理到后端主机
ProxyPassReverse / ajp://192.168.10.11:8009/
<Location>
Require all granted
</Location>
</VirtualHost>
- 验证配置并启动httpd
[root@node3 ~]# httpd -M 确保模块已装载
[root@node3 ~]# httpd -t
Syntax OK
[root@node3 ~]# systemctl restart httpd.service
客户端浏览器测试:www.myunix.com/test 正常访问
node1 tomcat server1
ens192 192.168.10.11 gateway 192.168.10.254
ens224 192.168.170.8
[root@node1 ~]# yum -y install java-1.8.0-openjdk-devel tomcat tomcat-webapps tomcat-admin-weapps tomcat-docs-webapp
[root@node3 ~]# scp /etc/tomcat/tomcat-users.xml 192.168.10.11:/etc/tomcat/
[root@node1 ~]# mkdir -pv /var/lib/tomcat/webapps/test/{WEB-INF,META-INF,lib,classes}
mkdir: created directory ‘/var/lib/tomcat/webapps/test’
mkdir: created directory ‘/var/lib/tomcat/webapps/test/WEB-INF’
mkdir: created directory ‘/var/lib/tomcat/webapps/test/META-INF’
mkdir: created directory ‘/var/lib/tomcat/webapps/test/lib’
mkdir: created directory ‘/var/lib/tomcat/webapps/test/classes’
[root@node1 ~]# vi /var/lib/tomcat/webapps/test/index.jsp
<%@ page language="java" %>
<html>
<head><title>TomcatA</title></head>
<body>
<h1><font color="green">TomcatA.magedu.com</font></h1>
<table align="centre" border="1">
<tr>
<td>Session ID</td>
<% session.setAttribute("magedu.com","magedu.com"); %>
<td><%= session.getId() %></td>
</tr>
<tr>
<td>Created on</td>
<td><%= session.getCreationTime() %></td>
</tr>
</table>
</body>
</html>
[root@node1 ~]# systemctl restart tomcat.service
[root@node1 ~]# ss -tunlp
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp LISTEN 0 128 *:22 *:* users:(("sshd",pid=886,fd=3))
tcp LISTEN 0 100 127.0.0.1:25 *:* users:(("master",pid=1616,fd=13))
tcp LISTEN 0 1 ::ffff:127.0.0.1:8005 :::* users:(("java",pid=28234,fd=54))
tcp LISTEN 0 100 :::8009 :::* users:(("java",pid=28234,fd=50))
tcp LISTEN 0 100 :::8080 :::* users:(("java",pid=28234,fd=49))
tcp LISTEN 0 32 :::21 :::* users:(("vsftpd",pid=17230,fd=3))
tcp LISTEN 0 128 :::22 :::* users:(("sshd",pid=886,fd=4))
tcp LISTEN 0 100 ::1:25 :::* users:(("master",pid=1616,fd=14))
[root@node1 ~]#
客户端浏览器测试:http://192.168.170.8:8080 和 http://192.168.170.8:8080/test/ 正常
注:由于服务器是双网卡,因此,我是通过外网网卡测试的。
node3 nginx_proxy
[root@node3 ~]# systemctl stop httpd
[root@node3 ~]#
[root@node3 ~]# vi /etc/nginx/nginx.conf
http {
upstream tcsrvs {
server 192.168.10.11:8080;
server 192.168.10.12:8080;
}
}
[root@node3 ~]# vi /etc/nginx/conf.d/ilinux.conf
server {
listen 80;
server_name www.ilinux.io;
location / {
proxy_pass http://tcsrvs;
}
}
检查语法并启动服务
[root@node3 ~]# nginx -t
[root@node3 ~]# systemctl start nginx
查看服务是否正常启动
[root@node3 ~]# ss -tunlp
客户端测试:确实是轮询调度
[root@node4 ~]# curl -s http://www.mylinux.com/test/ | grep -i 'tomcat'
<head><title>TomcatA</title></head>
<h1><font color="green">TomcatA.magedu.com</font></h1>
[root@node4 ~]# curl -s http://www.mylinux.com/test/ | grep -i 'tomcat'
<head><title>TomcatB</title></head>
<h1><font color="blue">TomcatB.magedu.com</font></h1>
[root@node4 ~]# curl -s http://www.mylinux.com/test/ | grep -i 'tomcat'
<head><title>TomcatA</title></head>
<h1><font color="green">TomcatA.magedu.com</font></h1>
[root@node4 ~]# curl -s http://www.mylinux.com/test/ | grep -i 'tomcat'
<head><title>TomcatB</title></head>
<h1><font color="blue">TomcatB.magedu.com</font></h1>
会话绑定示例:
[root@node3 ~]# vi /etc/nginx/nginx.conf
httpd {
upstream tcsrvs {
hash $request_uri consitent;
server 192.168.10.11:8080;
server 192.168.10.12:8080;
}
}
[root@node3 ~]# nginx -t
[root@node3 ~]# nginx -s reload
客户端测试:会话都绑定到tomcatA主机上
[root@node4 ~]# curl -s http://www.mylinux.com/test/ | grep -i 'tomcat'
<head><title>TomcatA</title></head>
<h1><font color="green">TomcatA.magedu.com</font></h1>
[root@node4 ~]# curl -s http://www.mylinux.com/test/ | grep -i 'tomcat'
<head><title>TomcatA</title></head>
<h1><font color="green">TomcatA.magedu.com</font></h1>
[root@node4 ~]# curl -s http://www.mylinux.com/test/ | grep -i 'tomcat'
<head><title>TomcatA</title></head>
<h1><font color="green">TomcatA.magedu.com</font></h1>
[root@node4 ~]# curl -s http://www.mylinux.com/test/ | grep -i 'tomcat'
<head><title>TomcatA</title></head>
<h1><font color="green">TomcatA.magedu.com</font></h1>
cookie stick示例:
[root@node3 ~]# vi /etc/nginx/nginx.conf
http {
upstream tcsrvs {
hash $cookie_name consitent;
server 192.168.10.11:8080;
server 192.168.10.12:8080;
}
}
[root@node3 ~]# nginx -t
[root@node3 ~]# nginx -s reload
客户端测试:会话绑定同上
[root@node4 ~]# curl -s http://www.mylinux.com/test/ | grep -i 'tomcat'
<head><title>TomcatA</title></head>
<h1><font color="green">TomcatA.magedu.com</font></h1>
[root@node4 ~]# curl -s http://www.mylinux.com/test/ | grep -i 'tomcat'
<head><title>TomcatA</title></head>
<h1><font color="green">TomcatA.magedu.com</font></h1>
[root@node4 ~]# curl -s http://www.mylinux.com/test/ | grep -i 'tomcat'
<head><title>TomcatA</title></head>
<h1><font color="green">TomcatA.magedu.com</font></h1>
httpd proxy使用balancer module示例:
node1
[root@node3 ~]# httpd -M | grep balancer
proxy_balancer_module (shared)
[root@node3 ~]# cd /etc/httpd/conf.d
[root@node3 conf.d]# vim ilinux_tomcat.conf
<Proxy balancer://tcsrvs>
BalancerMember http://192.168.10.11:8080
BalancerMember http://192.168.10.12:8080
ProxySet lbmethod=byrequests
</Proxy>
<VirtualHost *:80>
ServerName www.ilinux.io
ProxyRequests Off
DocumentRoot "/data/ilinux/htdocs"
ProxyVia On
ProxyPreserveHost On
<Proxy *>
Require all granted
</Proxy>
ProxyPass / balancer://tcsrvs/
ProxyPassReverse / balancer://tcsrvs/
<Location />
Require all granted
</Location>
</VirtualHost>
[root@node3 ~]# httpd -t
Syntax OK
[root@node3 ~]# systemctl start httpd
[root@node3 ~]# ss -utnlp
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp LISTEN 0 128 :::8080 :::* users:(("httpd",pid=12463,fd=6),("httpd",pid=12462,fd=6),("httpd",pid=12460,fd=6),("httpd",pid=11212,fd=6),("httpd",pid=2729,fd=6),("httpd",pid=2709,fd=6),("httpd",pid=2708,fd=6),("httpd",pid=2707,fd=6),("httpd",pid=2706,fd=6),("httpd",pid=2705,fd=6),("httpd",pid=2693,fd=6))
tcp LISTEN 0 128 :::80 :::* users:(("httpd",pid=12463,fd=4),("httpd",pid=12462,fd=4),("httpd",pid=12460,fd=4),("httpd",pid=11212,fd=4),("httpd",pid=2729,fd=4),("httpd",pid=2709,fd=4),("httpd",pid=2708,fd=4),("httpd",pid=2707,fd=4),("httpd",pid=2706,fd=4),("httpd",pid=2705,fd=4),("httpd",pid=2693,fd=4))
浏览器测试: 轮询调度
[root@node4 ~]# curl -s http://www.mylinux.com/test/ | grep -i 'tomcat'
<head><title>TomcatA</title></head>
<h1><font color="green">TomcatA.magedu.com</font></h1>
[root@node4 ~]# curl -s http://www.mylinux.com/test/ | grep -i 'tomcat'
<head><title>TomcatB</title></head>
<h1><font color="blue">TomcatB.magedu.com</font></h1>
[root@node4 ~]# curl -s http://www.mylinux.com/test/ | grep -i 'tomcat'
<head><title>TomcatA</title></head>
<h1><font color="green">TomcatA.magedu.com</font></h1>
[root@node4 ~]# curl -s http://www.mylinux.com/test/ | grep -i 'tomcat'
<head><title>TomcatB</title></head>
<h1><font color="blue">TomcatB.magedu.com</font></h1>
[root@node4 ~]#
node3
[root@node3 conf.d]# vim iunix_tomcat.conf
<Proxy balancer://tomcatsrvs>
BalancerMember http://192.168.10.11:8009
BalancerMember http://192.168.10.12:8009
ProxySet lbmethod=byrequests
</Proxy>
<VirtualHost *:80>
ServerName www.iunix.io
ProxyRequests Off
#DocumentRoot "/data/ilinux/htdocs"
ProxyVia On
ProxyPreserveHost On
<Proxy *>
Require all granted
</Proxy>
ProxyPass / balancer://tomcatsrvs/
ProxyPassReverse / balancer://tomcatsrvs/
<Location />
Require all granted
</Location>
</VirtualHost>
[root@node3 ~]# httpd -t
Syntax OK
[root@node3 ~]# systemctl restart httpd
[root@node3 ~]# ss -utnlp
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp LISTEN 0 128 :::8080 :::* users:(("httpd",pid=12463,fd=6),("httpd",pid=12462,fd=6),("httpd",pid=12460,fd=6),("httpd",pid=11212,fd=6),("httpd",pid=2729,fd=6),("httpd",pid=2709,fd=6),("httpd",pid=2708,fd=6),("httpd",pid=2707,fd=6),("httpd",pid=2706,fd=6),("httpd",pid=2705,fd=6),("httpd",pid=2693,fd=6))
tcp LISTEN 0 128 :::80 :::* users:(("httpd",pid=12463,fd=4),("httpd",pid=12462,fd=4),("httpd",pid=12460,fd=4),("httpd",pid=11212,fd=4),("httpd",pid=2729,fd=4),("httpd",pid=2709,fd=4),("httpd",pid=2708,fd=4),("httpd",pid=2707,fd=4),("httpd",pid=2706,fd=4),("httpd",pid=2705,fd=4),("httpd",pid=2693,fd=4))
客户端测试: 轮询调度
[root@node4 ~]# curl -s http://www.myunix.com/test/ | grep -i 'tomcat'
<head><title>TomcatB</title></head>
<h1><font color="blue">TomcatB.magedu.com</font></h1>
[root@node4 ~]# curl -s http://www.myunix.com/test/ | grep -i 'tomcat'
<head><title>TomcatA</title></head>
<h1><font color="green">TomcatA.magedu.com</font></h1>
[root@node4 ~]# curl -s http://www.myunix.com/test/ | grep -i 'tomcat'
<head><title>TomcatB</title></head>
<h1><font color="blue">TomcatB.magedu.com</font></h1>
[root@node4 ~]#
node3
[root@node3 conf.d]# vim ilinux_tomcat.conf
Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
<proxy balancer://tcsrvs>
BalancerMember http://192.168.10.11:8080
BalancerMember http://192.168.10.12:8080
ProxySet lbmethod=byrequests
ProxySet sticksession=ROUTEID
</Proxy>
[root@node3 ~]# httpd -t
Syntax OK
[root@node3 ~]# systemctl restart httpd
[root@node3 ~]# ss -utnlp
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp LISTEN 0 128 :::8080 :::* users:(("httpd",pid=12463,fd=6),("httpd",pid=12462,fd=6),("httpd",pid=12460,fd=6),("httpd",pid=11212,fd=6),("httpd",pid=2729,fd=6),("httpd",pid=2709,fd=6),("httpd",pid=2708,fd=6),("httpd",pid=2707,fd=6),("httpd",pid=2706,fd=6),("httpd",pid=2705,fd=6),("httpd",pid=2693,fd=6))
tcp LISTEN 0 128 :::80 :::* users:(("httpd",pid=12463,fd=4),("httpd",pid=12462,fd=4),("httpd",pid=12460,fd=4),("httpd",pid=11212,fd=4),("httpd",pid=2729,fd=4),("httpd",pid=2709,fd=4),("httpd",pid=2708,fd=4),("httpd",pid=2707,fd=4),("httpd",pid=2706,fd=4),("httpd",pid=2705,fd=4),("httpd",pid=2693,fd=4))
客户端浏览器测试:http://www.mylinux.com/test/ 带有会话粘性
node3 配置tomcat服务状态页
[root@node3 conf.d]# vim ilinux_tomcat.conf
Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
<proxy balancer://tcsrvs>
BalancerMember http://192.168.10.11:8080
BalancerMember http://192.168.10.12:8080
ProxySet lbmethod=byrequests
ProxySet sticksession=ROUTEID
</Proxy>
<VirtualHost *:80>
ServerName www.ilinux.io
ProxyRequests Off
DocumentRoot "/data/ilinux/htdocs"
ProxyVia On
ProxyPreserveHost On
<Proxy *>
Require all granted
</Proxy>
ProxyPass / balancer://tcsrvs/
ProxyPassReverse / balancer://tcsrvs/
<Location>
Require all granted
</Location>
<Location /bstatus>
SetHandler balancer-manager
ProxyPass !
Require all granted
</Location>
</VirtualHost>
[root@node3 ~]# httpd -t
Syntax OK
[root@node3 ~]# systemctl restart httpd
[root@node3 ~]# ss -utnlp
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp LISTEN 0 128 :::8080 :::* users:(("httpd",pid=12463,fd=6),("httpd",pid=12462,fd=6),("httpd",pid=12460,fd=6),("httpd",pid=11212,fd=6),("httpd",pid=2729,fd=6),("httpd",pid=2709,fd=6),("httpd",pid=2708,fd=6),("httpd",pid=2707,fd=6),("httpd",pid=2706,fd=6),("httpd",pid=2705,fd=6),("httpd",pid=2693,fd=6))
tcp LISTEN 0 128 :::80 :::* users:(("httpd",pid=12463,fd=4),("httpd",pid=12462,fd=4),("httpd",pid=12460,fd=4),("httpd",pid=11212,fd=4),("httpd",pid=2729,fd=4),("httpd",pid=2709,fd=4),("httpd",pid=2708,fd=4),("httpd",pid=2707,fd=4),("httpd",pid=2706,fd=4),("httpd",pid=2705,fd=4),("httpd",pid=2693,fd=4))
客户端浏览器测试:www.mylinux.com/bstatus/ 状态页