枫叶飞翔 发表于 2019-1-1 14:56:35

【中级篇】使用Haproxy搭建WEB群集

使用Haproxy搭建WEB群集
1.          实验需求:
1)   2台服务器部署NgINX服务
2)1台做Haproxy调度器
3)搭建负载均衡,测试其效果。
2.          实验环境:
主机
操作系统
IP地址
主要软件
Haproxy
RedHat6.532位
192.168.10.10
haproxy-1.4.24.tar.gz
Nginx服务器1
CentOS--6.5 32位
192.168.10.15
nginx-1.5.10.tar.gz
Nginx服务器2
CentOS--6.5 32位
192.168.10.18
nginx-1.5.10.tar.gz
客户端
win7
192.168.10.5
IE浏览器
3.      实验步骤:
基本安装操作:
1.在2台服务器上搭建WEB服务
Server-01:
http://s3.运维网.com/wyfs02/M02/7A/48/wKioL1am5sby1LVZAABANc5drQU723.png
http://s5.运维网.com/wyfs02/M00/7A/48/wKiom1am5pHgi9yQAAA78JTEhnQ975.png
http://s5.运维网.com/wyfs02/M00/7A/48/wKioL1am5xqyAI4dAAECi9X3qVU208.png
http://s1.运维网.com/wyfs02/M01/7A/48/wKioL1am5yrTM6RPAACbDkxtI6o381.png
  解压:
http://s4.运维网.com/wyfs02/M01/7A/48/wKiom1am5vLTK0gTAAAmiKTTaFg424.png
http://s3.运维网.com/wyfs02/M02/7A/48/wKioL1am50GgX1lOAAAnzgWV6w4025.png
  创建一个系统用户
http://s4.运维网.com/wyfs02/M02/7A/48/wKiom1am5w6yzrVUAAA3bEFkI5k746.png
  
  配置:
http://s4.运维网.com/wyfs02/M00/7A/48/wKioL1am52TDrTUrAAArhkmWqlo112.png
  编译并安装
http://s1.运维网.com/wyfs02/M01/7A/48/wKioL1am54XDzh4cAAAxmidQvV4380.png
  创建一个软连接
http://s1.运维网.com/wyfs02/M01/7A/48/wKiom1am51HD0ec6AABN1afL5no972.png
  写入一个测试页: 并启动nginx
http://s3.运维网.com/wyfs02/M02/7A/48/wKiom1am52WhsBUeAABtdl0cDV0586.png
  关闭防火墙和selinux;
http://s3.运维网.com/wyfs02/M00/7A/48/wKiom1am53XAsmmfAABFecVFUH4625.png
  测试是否正常:
http://s5.运维网.com/wyfs02/M01/7A/48/wKiom1am54Cw8Kk0AABJ44lCVdY574.png
  
Server-02:
  
http://s5.运维网.com/wyfs02/M01/7A/48/wKioL1am59OC6LQhAABX1hyifHE415.png
http://s3.运维网.com/wyfs02/M01/7A/48/wKiom1am563gMGPMAAAwI9TMpeU101.png
  
http://s5.运维网.com/wyfs02/M02/7A/48/wKiom1am58HifkLxAAA-rqP5YiM918.png
http://s5.运维网.com/wyfs02/M02/7A/48/wKioL1am6BGgnY0MAAEHH8qTv08974.png
http://s1.运维网.com/wyfs02/M02/7A/48/wKiom1am596hygzaAACsLZkjt20856.png
http://s3.运维网.com/wyfs02/M00/7A/48/wKioL1am6Cyw-jYpAAA0vH9tQ6E854.png
http://s3.运维网.com/wyfs02/M00/7A/48/wKiom1am5_XCf6R1AABVXxu7fxk845.png
http://s5.运维网.com/wyfs02/M01/7A/48/wKiom1am61WThPC2AAAvqGd63K8719.png
http://s4.运维网.com/wyfs02/M00/7A/48/wKioL1am7Hby5WVOAAAqP_qieDQ315.png
http://s2.运维网.com/wyfs02/M01/7A/48/wKioL1am7JXTftTiAABBWSRH92M197.png
http://s4.运维网.com/wyfs02/M02/7A/49/wKiom1am7G3wGuAAAAA_BguP9Kw167.png
http://s4.运维网.com/wyfs02/M00/7A/48/wKioL1am7MPjSoVfAABpj3M6_JM507.png
http://s4.运维网.com/wyfs02/M02/7A/49/wKiom1am7WXgFLhDAAAMjoOb4Gc566.png
http://s5.运维网.com/wyfs02/M00/7A/49/wKiom1am7XSiDTWuAABGVvso4tk399.png
http://s5.运维网.com/wyfs02/M00/7A/48/wKioL1am7cbCyhUrAABF2hCoaDY211.png
2.在1台服务器上搭建Haproxy服务
① 挂载光盘
http://s2.运维网.com/wyfs02/M00/7A/49/wKiom1am7ZCgIVJbAAA2hxsnOR8657.png
② 把本地磁盘的文件共享到linux中。
http://s4.运维网.com/wyfs02/M01/7A/48/wKioL1am7eOTK6qdAABXSppgrjM802.png
http://s1.运维网.com/wyfs02/M01/7A/48/wKioL1am7fTjOEIYAADMrX1mo1Y584.png
③ 编译安装Haproxy:
http://s1.运维网.com/wyfs02/M01/7A/49/wKiom1am7b-whH4cAAA5kM2ypqc128.png
http://s2.运维网.com/wyfs02/M02/7A/48/wKioL1am7g-zGYo2AABFtFL_HnM276.png
④ Haproxy 服务器配置:
http://s1.运维网.com/wyfs02/M00/7A/49/wKiom1am7dnxTOcjAABW6X1DKBY019.png
http://s3.运维网.com/wyfs02/M00/7A/48/wKioL1am7i3SUOBGAABKXhAZANs155.png
http://s3.运维网.com/wyfs02/M00/7A/48/wKioL1am712h_5ubAAAx5h0-YNg109.png
  创建配置文件目录:
http://s5.运维网.com/wyfs02/M01/7A/48/wKioL1am722yibKsAABB_0ESqCY238.png
  将haproxy.cfg文件复制到配置文件目录:
http://s2.运维网.com/wyfs02/M02/7A/49/wKiom1am7ziCkN4zAAAx8NIChs4922.png
⑤ 配置Haproxy文件:
http://s3.运维网.com/wyfs02/M01/7A/48/wKioL1am76mD62LKAAA624UxrYU568.png
  
  下面两行加上注释(#)
http://s1.运维网.com/wyfs02/M00/7A/49/wKiom1am76DiwKAdAABaWDdQMtM470.png
http://s1.运维网.com/wyfs02/M01/7A/49/wKiom1am77bCOk1_AABkq7sicwk861.png
⑥ 创建自启动脚本
http://s2.运维网.com/wyfs02/M02/7A/49/wKiom1am783CN2enAAAyeEb3P6Y220.png
http://s3.运维网.com/wyfs02/M01/7A/49/wKiom1am793Qi_VAAABsobz68JE872.png
http://s4.运维网.com/wyfs02/M01/7A/48/wKioL1am8DPQcqG8AAA4m5Pce4o569.png
http://s1.运维网.com/wyfs02/M00/7A/49/wKiom1am8ADjh52bAAA17Ccxruk829.png
http://s3.运维网.com/wyfs02/M01/7A/48/wKioL1am8FfjT0GPAAByuQp81KU468.png
⑦ 测试WEB集群:
http://s3.运维网.com/wyfs02/M00/7A/49/wKiom1am8CHxeibrAABG9uk24Wg065.png
  刷新一下:
http://s5.运维网.com/wyfs02/M00/7A/48/wKioL1am8Hrg4TaAAABKXCC17_I807.png
  如果Haproxy服务器出现故障,是否影响集群使用?如何保证Haproxy高可用。
  这时我们就要使用keepalived双机热备。要在Haproxy服务器上搭建Keepalived,这样类似实现切换。让用户不感知服务器出现故障。



页: [1]
查看完整版本: 【中级篇】使用Haproxy搭建WEB群集