蒦嗳伱 发表于 2018-12-28 14:06:35

03: HAProxy服务器 、 Keepalived热备 、 Keepalived+LVS

  LVS/DR
不对realserver 主机上的服务做健康性检查
是基于四层负载均衡集群软件(端口)
  一、使用Haproxy软件部署网站LB集群
1.1普通LB集群
  客户端               192.168.4.250
  haproxy服务器   192.168.4.100
  网站服务器          192.168.4.101/102
  配置 haproxy服务器:192.168.4.100
装包
yumlist| grep-i haproxy
rpm-q   haproxy   ||yum-yinstall haproxy
  修改配置文件
cp/etc/haproxy/haproxy.cfg   /etc/haproxy/haproxy.cfg.bak
vim/etc/haproxy/haproxy.cfg

....
  
......   
stats   uri   /admin
listenlbweb0.0.0.0:80
cookieSERVERID rewrite
balance roundrobin
serverwebA 192.168.4.101:80 cookie app101a check inter 2000   rise 2 fall 5
serverwebB 192.168.4.102:80 cookie app102b check inter 2000 rise 2 fall 5
  :wq
  启动服务#servicehaproxystart   ; chkconfig   haproxyon
查看端口   #netstat-utnalp| grep :80
客户端250 测试#elinks   --dump   http://192.168.4.100/test.html
查看web页面显示健康性检查信息 http://192.168.4.100/admin
++++++++++++++++++++++++++++++++++++++++++++++
test.html   a.php
]# servicehaproxy stop
]# mv haproxy.cfg haproxy.cfg-1
]# cp haproxy.cfg.bak   haproxy.cfg
  1.2区分业务的LB集群(七层)
]# vim   haproxy.cfg
statsuri/admin
frontendweblb    192.168.4.100:80
aclpathhtml         path_end   -i   .html
aclpathphp          path_end   -i   .php

use_backend   htmlgrpif pathhtml
use_backend   phpgrpif pathphp
default_backend   htmlgrp
  backend htmlgrp
balance   roundrobin
serverapp101 192.168.4.101:80check
serverapp102 192.168.4.102:80check
backendphpgrp
balance   roundrobin
serverapp103192.168.4.103:80check
serverapp104192.168.4.104:80   check
]# servicehaproxystart
++++++++++++++++++++++++++++++++++++++++
250elinks--dumphttp://192.168.4.100/test.html
web101
web102
250elinks--dumphttp://192.168.4.100/a.php
helloweb103
helloweb104
  250   elinks--dumphttp://192.168.4.100
++++++++++++++++++++++++++++++++++++++
二、使用keepalived软件部署网站HA集群


[*]能够实现任意单故障节点的高可用集群。
  配置网站高可用集群   103和 104
1 在主机上都安装keepalived软件
#yumlist   |grep-i keepalived
#rpm-qkeepalived|| yum-yinstall keepalived
  2 修改服务的主配置文件/etc/keepalived/keepalived.conf
2.1修改主服务器192.168.4.103
vim   /etc/keepalived/keepalived.conf
...
state   MASTER
priority 150
33   lb_kind DR
35   #persistence_timeout 50 #50秒内访问同一台
  ....
:wq
2.2修改备用服务器192.168.4.104
vim   /etc/keepalived/keepalived.conf
....
stateBACKUP
priority 100
33   lb_kind DR
35   #persistence_timeout 50 #50秒内访问同一台
  ....
:wq
++++++++++++++++++++++++++++++
3 启动服务
主服务器
/etc/init.d/keepalivedstart
chkconfig   keepalivedon
  备用服务器
/etc/init.d/keepalivedstart
chkconfig   keepalivedon
  4 查看是否获取到vip 地址
#ip   addr   show   |grep   192.168.4.
  4测试
250: elinks   --dumphttp://vip/teset.php
192.168.4.253
  ++++++++++++++++++++++++++++++++++++++++++++++++
部署101和102为 HA 高可用集群。
客户端访问集群的vip地址是192.168.4.252
  101    n-> p ->1 ->2次回车->w
165fdisk-l /dev/vdd
169blkid /dev/vdd1
170mkfs.ext4/dev/vdd1
171blkid /dev/vdd1
172mkdir/webdir
173mount /dev/vdd1 /webdir
174df -h /webdir/
  umount/webdir
  设置开机挂载/etc/fstab
# tail -1 /etc/fstab
UUID=3f505f56-b559-4f95-9d99-8f99d9318e3c       /webdirext4    defaults      0 0
# mount-a
# mount   | grep/webdir
  1.2共享存储存储空间:装包、修改配置文件、启动服务
184rpm -qnfs-utils
185rpm -qnfs-utils || yum -yinstallnfs-utils
186rpm -qnfs-utils
]# rpm -q rpcbind || yum -yinstall rpcbind
]# vim/etc/exports
/webdir   *(rw)
:wq
]# chmod o+w /webdir/
  193/etc/init.d/rpcbind status
194/etc/init.d/rpcbind start
195/etc/init.d/nfs status
196/etc/init.d/nfs start
#chkconfig   rpcbindon
#chkconfig   nfson
  1.3在本机查看共享信息
# whichshowmount
/usr/sbin/showmount
# rpm -qf /usr/sbin/showmount
nfs-utils-1.2.3-64.el6.x86_64
#
# showmount-e localhost
Export list for localhost:
/webdir
#
二、配置应用服务器192.168.4.101/102
2.1挂载nfs共享目录
]# yum -y install nfs-utils
]#showmount-e   192.168.4.105
]# rm -rf/var/www/html/
]# mount-tnfs   192.168.4.105:/webdir   /var/www/html/
2.2在105主机上编写网页文件
vim /webdir/test.html
aaaa
cccc
:wq
2.3客户端 250 访问 lb集群能够看到网页内容
elinks--dump   http://192.168.4.253/test.html



cn539 发表于 2018-12-28 17:47:15

学习学习了。。。。。
页: [1]
查看完整版本: 03: HAProxy服务器 、 Keepalived热备 、 Keepalived+LVS