没有合适的资源?快使用搜索试试~ 我知道了~
首页HAProxy+Keepalived+LVS实现负载平衡高可用集群最佳实践
HAProxy+Keepalived+LVS实现负载平衡高可用集群最佳实践
4星 · 超过85%的资源 需积分: 50 166 下载量 167 浏览量
更新于2023-05-31
评论 8
收藏 760KB PDF 举报
HAProxy+Keepalived+LVS实现负载平衡高可用集群最佳实践
资源详情
资源评论
资源推荐
美河学习在线 www.eimhe.com
1 配置 HAProxy 负载平衡集群
1.1 问题
准备三台 Linux 服务器,两台做 Web 服务器,一台安装 HAProxy,实现如下功能:
客户端访问 HAProxy,HAProxy 分发请求到后端 Real Server
要求 HAProxy 可以根据 Cookie 为客户端分配固定后端服务器
开启 HAProxy 监控页面,及时查看调度器状态
设置 HAProxy 为开机启动
1.2 方案
使用 3 台虚拟机,1 台作为 HAProxy 调度器、2 台作为 Real Server、物理机作为客
户端,拓扑结构如图-1 所示。
图-1
1.3 步骤
实现此案例需要按照如下步骤进行。
步骤一:配置后端 Web 服务器
1)配置两台 Web 服务器网络参数
1. [root@web1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
美河学习在线 www.eimhe.com
2. DEVICE=eth0
3. ONBOOT=yes
4. BOOTPROTO=static
5. IPADDR=192.168.0.1
6. NETMASK=255.255.255.0
7. GATEWAY=192.168.0.254
8. DNS1=202.106.0.10
9. [root@web1 ~]# service network restart
10. [root@web1 ~]# iptables -F
11. [root@web1 ~]# service iptables save
12. [root@web2 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
13. DEVICE=eth0
14. ONBOOT=yes
15. BOOTPROTO=static
16. IPADDR=192.168.0.2
17. NETMASK=255.255.255.0
18. GATEWAY=192.168.0.254
19. DNS1=202.106.0.10
20. [root@web2 ~]# service network restart
21. [root@web2 ~]# iptables -F
22. [root@web2 ~]# service iptables save
2)设置后端 Web 服务
1. [root@web1 ~]# yum -y install httpd
2. [root@web1 ~]# service httpd start
3. [root@web1 ~]# echo “192.168.0.1” > /var/www/html/index.html
4. [root@web2 ~]# yum -y install httpd
5. [root@web2 ~]# service httpd start
6. [root@web2 ~]# echo “192.168.0.2” > /var/www/html/index.html
步骤二:部署 HAProxy 服务器
美河学习在线 www.eimhe.com
1)配置网络,安装软件
1. [root@haproxy ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
2. DEVICE=eth0
3. ONBOOT=yes
4. BOOTPROTO=static
5. IPADDR=202.114.106.20
6. [root@haproxy ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1
7. DEVICE=eth0
8. ONBOOT=yes
9. BOOTPROTO=static
10. IPADDR=192.168.0.254
11. NETMASK=255.255.255.0
12. DNS1=202.106.0.20
13. [root@haproxy ~]# service network restart
14. [root@haproxy ~]# sed -i '/ip_forward/s/0/1/' sysctl.conf //开启路由转发
15. [root@haproxy ~]# sysctl -p
16. [root@haproxy ~]# yum -y install pcre pcre-devel
17. [root@haproxy ~]# tar xvzf haproxy-1.4.24.tar.gz
18. [root@haproxy ~]# cd haproxy-1.4.24
19. [root@haproxy haproxy-1.4.24]# uname -r
20. [root@haproxy haproxy-1.4.24]# make TARGET=linux2628 \
21. > USE_PCRE=1 PREFIX=/usr/local/haproxy install
22. [root@haproxy haproxy-1.4.24]# ln -s /usr/local/haproxy/sbin/haproxy \
23. > /usr/local/sbin/
24. [root@haproxy haproxy-1.4.24]# cp examples/haproxy.cfg /etc/haproxy/haproxy.cfg
25. [root@haproxy haproxy-1.4.24]# cp examples/haproxy.init /etc/init.d/haproxy
26. [root@haproxy haproxy-1.4.24]# chmod +x /etc/init.d/haproxy
2)修改配置文件
1. [root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
美河学习在线 www.eimhe.com
2. global //全局设置
3. log 127.0.0.1 local0 //日志输出配置
4. maxconn 4096 //最大连接数
5. chroot /usr/local/haproxy
6. uid 99 //所属运行的用户 uid
7. gid 99 //所属运行的用户组
8. daemon //以后台形式运行
9. nbproc 2 //启动 2 个 haproxy 实例
10. pidfile /var/run/haproxy.pid
11. defaults //默认设置
12. log global
13. mode http //默认采用 http 模式
14. option httplog //日志类别
15. retries 3 //3 次连接失败认为服务器不可用
16. option redispatch //当 serverid 对应的服务器挂掉后,
17. //强制定向到其他健康服务器
18. stats uri /haproxy-admin //设置监控
19. contimeout 5000 //连接超时时间
20. clitimeout 50000 //客户端连接超时时间
21. srvtimeout 50000 //服务器端连接超时时间
22. listen websrv-rewrite 0.0.0.0:80
23. cookie SERVERID rewrite
24. balance roundrobin
25. server app1_1 192.168.0.1:80 cookie app1inst1 check inter 2000 rise 2 fall 5
26. server app1_2 192.168.0.2:80 cookie app1inst2 check inter 2000 rise 2 fall 5
3)启动服务器并设置开机启动
1. [root@haproxy ~]# haproxy -f /etc/haproxy/haproxy.cfg
2. [root@haproxy ~]# chkconfig --add haproxy
3. [root@haproxy ~]# chkconfig haproxy on
剩余17页未读,继续阅读
machen_smiling
- 粉丝: 506
- 资源: 1958
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- RTL8188FU-Linux-v5.7.4.2-36687.20200602.tar(20765).gz
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
- SPC统计方法基础知识.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1