centos7 haproxy 加keepalived 实现后端应用udp 73端口负载均衡高可用的配置
时间: 2023-11-27 20:53:15 浏览: 83
以下是在CentOS 7系统上使用HAProxy和Keepalived实现UDP 73端口负载均衡高可用的配置步骤:
1. 安装HAProxy和Keepalived
```bash
yum install haproxy keepalived -y
```
2. 配置HAProxy
编辑HAProxy配置文件`/etc/haproxy/haproxy.cfg`,添加如下内容:
```bash
frontend udp_front
bind *:73 # 监听UDP 73端口
default_backend udp_back
backend udp_back
balance roundrobin # 负载均衡策略为轮询
server server1 192.168.1.101:73 check # 后端服务器1
server server2 192.168.1.102:73 check # 后端服务器2
```
3. 配置Keepalived
编辑Keepalived配置文件`/etc/keepalived/keepalived.conf`,添加如下内容:
```bash
global_defs {
router_id haproxy
}
vrrp_instance VI_1 {
state MASTER # 主节点为MASTER
interface eth0 # 监听网卡
virtual_router_id 51 # 虚拟路由ID,同一物理网络内唯一
priority 101 # 主节点优先级较高
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.100/24 # 虚拟IP地址
}
}
virtual_server 192.168.1.100 73 {
delay_loop 6
lb_algo rr # 负载均衡算法
lb_kind NAT
persistence_timeout 60
protocol UDP
real_server 192.168.1.101 73 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.1.102 73 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
```
4. 启动服务
启动HAProxy和Keepalived服务:
```bash
systemctl start haproxy
systemctl start keepalived
```
5. 验证是否成功
在另外一台主机上使用`nc`命令测试UDP 73端口是否正常:
```bash
nc -u 192.168.1.100 73
```
如果配置正确,应该能够顺利连接到其中一台后端服务器,实现UDP 73端口的负载均衡和高可用。
阅读全文