首页 技术 正文
技术 2022年11月23日
0 收藏 715 点赞 5,132 浏览 2090 个字

HAProxy根据不同的URI 转发到后端的服务器组

1 ) 实验内容说明:

 1.1 ) 根据不同的URI 转发到后端的服务器组.  /a   /b   和其他   默认使用其他。
1.2 ) 使用IP介绍:
haproxy | 10.10.50.119 | ha | 入口LB
server-1 | 10.10.29.207 | http | /a 路径转发到此
server-2 | 10.10.4.209 | http | /b 路径转发到此
server-3 | 10.10.116.206 | http | 其他所有的转发到此

2 ) HAProxy-1.8.20 根据路径转发到不同后端组:

2.1 ) haproxy 配置
[root@ser haproxy]# grep -vE '^$|^#|^ #' haproxy.cfg
global
maxconn 100000
chroot /data/soft/haproxy
stats socket /var/lib/haproxy/haproxy.sock mode 600 level admin
uid 1000
gid 1000
daemon
nbproc 2
cpu-map 1 0
cpu-map 2 1
pidfile /usr/local/haproxy/run/haproxy.pid
log 127.0.0.1 local3 info
defaults
option http-keep-alive
option forwardfor # ip地址透传 针对http 协议有效
maxconn 100000
mode http
timeout connect 300000ms
timeout client 300000ms
timeout server 300000ms
frontend web_prot_80
bind 0.0.0.0:80
mode http
#########################重点部分开始
acl web_port path_beg -i /a # 定义一个ACL,名web_port,模糊匹配路径/a
acl mob_port path_beg -i /b # 定义一个ACL,名web_port,模糊匹配路径/b
use_backend web_port_http_nodes if web_port
# 客户端访问HA路径http://10.10.50.119/a,匹配成功web_port就转发到web_port_http_nodes.如果没有成功继续往下匹配.都匹配不成功就转发到 defalt_backend.
use_backend mob_port_http_nodes if mob_port
# 客户端访问HA路径http://10.10.50.119/b,匹配成功mob_port就转发到mob_port_http_nodes.如果没有成功继续往下匹配.都匹配不成功就转发到 defalt_backend.
default_backend backup_nodes # 一定要有默认转发的这一条,否则会报错。
backend web_port_http_nodes
server server1 10.10.29.207:80 weight 1 check port 80 inter 3s fall 2 rise 5
backend mob_port_http_nodes
server server2 10.10.4.209:80 weight 1 check port 80 inter 3s fall 2 rise 5
backend backup_nodes
server server3 10.10.116.206:80 weight 1 check port 80 inter 3s fall 2 rise 5
###########################重点部分结束
listen stats
mode http
bind 0.0.0.0:9999
stats enable
log global
bind-process 2
stats uri /s
stats auth admin:34343434

3 ) 后端机器做如下操作:

## 后端统一安装httpd
yum install httpd -y
systemctl restart httpd## server-1
mkdir -p /var/www/html/a
echo "this is server-1 29.207" >/var/www/html/a/index.html## server-2
server-2
mkdir -p /var/www/html/b
echo "this is server -2 4.209" >/var/www/html/a/index.html## server-3
server-3
echo "backup redis-2 index.html" /var/www/html/index.html

4 ) 验证最终过程

[root@client1 haproxy]# curl -L http://10.10.50.119/a
this is server-1 29.207
[root@client1 haproxy]# curl -L http://10.10.50.119/b
this is server -2 4.209
[root@client1 haproxy]# curl -L http://10.10.50.119
backup redis-2 index.html
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,996
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,510
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,353
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,137
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848