北极星光 发表于 2019-1-1 06:51:07

lvs + keepalived + httpd DR模式web层高可用方案架构

  注意:lvs+keepalived 高可用方案中主备可以不需要绑定脚本,只需要keepalived的单个文件就可以整个集群.
  本实验为了方便理解采用了rpm 包安装的方式,对tar包情有独钟的可以绕过.本次讨论的重点是lvs+keepalived
  1.1IP地址的配置:
  lvs1master          192.168.80.145      主keepalived
  lvs2 slave          192.168.80.144      备keepalived
  realserver          192.168.80.146      web1
  realserver          192.168.80.147      web2
  realserver          192.168.80.149      web3      实验里面未添加(机器太烂)
  GW                  192.168.80.254      网关
  1.2架构图:
http://img1.运维网.com/attachment/201307/111725672.jpg
  安装支持包:
1yum install openssl-devel kernel-devel  安装ipvsadm :
1yum install ipvsadm  安装keepalived :
1yum install keepalived  配置开机启动项:
12chkconfig ipvsadm onchkconfig keepalived on  配置keepalived :
1vim /etc/keepalived/keepalived.confg  内容如下:
  
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657! Configuration File forkeepalivedglobal_defs {notification_email {#    acassen@firewall.loc#    failover@firewall.loc#    sysadmin@firewall.loc57674891@qq.com                  # 联系人}notification_email_from 57674891@qq.comsmtp_server   smtp.qq.comsmtp_connect_timeout    30router_id LVS_DEVEL}vrrp_instance VI_1 {state MASTER             #从上直接改为BACKUP 即可。interfaceeth0virtual_router_id 51priority 100# 主上是100从一定要设置比主小,90advert_int 1authentication {auth_type PASS      #密码验证类型auth_pass 1111#主从之间的验证密码,主从2端一定要一致}virtual_ipaddress {# 192.168.200.16# 192.168.200.17# 192.168.200.18#10.0.0.100192.168.80.148# 虚拟ip (vip)地址后面,下面可以继续叠加。}}#--------------------------------------virtual_server 192.168.80.14880{    # 虚拟IPdelay_loop 6#(每隔10秒查询realserver状态)lb_algo rr                     #(lvs 算法) 更改算法在此处更改lb_kind DR                  #(Direct Route)persistence_timeout 5#(同一IP的连接60秒内被分配到同一台realserver)protocol TCP                  #(用TCP协议检查realserver状态)real_server 192.168.80.14680{   #web端地址weight 1#(权重)TCP_CHECK {connect_timeout 10#(10秒无响应超时)nb_get_retry 3delay_before_retry 3connect_port 80#端口}}real_server 192.168.80.14780{weight 1TCP_CHECK {connect_timeout 10nb_get_retry 3delay_before_retry 3connect_port 80}}}  #后面还有很多示例可以负载其他服务,再此不做演示
  ------------------------主ha配置完成-------------------------------------
  backup 配置:
  安装ipvsadm 和keepalived 是一样的
1scp root@192.168.80.144:/etc/keepalived/keepalived.conf  修改keepalived 配置文件使之成为备ha,(仅需要修改2个地方)
1vim /etc/keepalived/keepalived.conf123456vrrp_instance VI_1 {state BACKUP            #直接改为BACKUP 即可。interfaceeth0virtual_router_id 51priority 90#主上是100从一定要设置比主小,90advert_int 1  设置完成重启keepalived 即可,启动ipvsadm start
1service keepalived start  ------------------------备ha配置完成-------------------------------------
  web 端:
1vim /root/realserver.sh12345678910111213141516171819202122232425262728293031#!/bin/bash# description: Config realserver            #Written by : http://kerry.blog.运维网.com#此脚本转自以上作者,尊重他人劳动成果。特此保留版权信息SNS_VIP=192.168.80.148# VIP 地址/etc/rc.d/init.d/functions   #如果提示权限不够 执行:chmod 777/etc/rc.d/init.d/functionscase"$1"instart)/sbin/ifconfig lo:0$SNS_VIP netmask 255.255.255.255broadcast $SNS_VIP/sbin/route add -host $SNS_VIP dev lo:0echo "1">/proc/sys/net/ipv4/conf/lo/arp_ignoreecho "2">/proc/sys/net/ipv4/conf/lo/arp_announceecho "1">/proc/sys/net/ipv4/conf/all/arp_ignoreecho "2">/proc/sys/net/ipv4/conf/all/arp_announcesysctl -p >/dev/null2>&1echo "RealServer Start OK";;stop)/sbin/ifconfig lo:0down/sbin/route del $SNS_VIP >/dev/null2>&1echo "0">/proc/sys/net/ipv4/conf/lo/arp_ignoreecho "0">/proc/sys/net/ipv4/conf/lo/arp_announceecho "0">/proc/sys/net/ipv4/conf/all/arp_ignoreecho "0">/proc/sys/net/ipv4/conf/all/arp_announceecho "RealServer Stoped";;*)echo "Usage: $0 {start|stop}"exit 1esacexit 0  赋予可执行权限:
1chmod a+x realserver.sh  加入开启自启动:
1echo /root/realserver.sh &>>/etc/rc.local  启动脚本:
1/root/realserver.sh &  查看本机的ip信息:
  #
1ifconfig  http://img1.运维网.com/attachment/201307/112301100.jpg
  把realserver.sh复制到其他的web端上同样操作,验证即可。
  
  ------------------------至此realserver配置完成-----------------------
  测试部分:
  任意客户端访问http://192.168.80.148应该都在146,147,149 三台主机之间切换
  主lvs + keepalived 访问效果图:
  ipvsadm –ln
http://img1.运维网.com/attachment/201307/112435444.jpg
  ipvsadm –ln–-stats
http://img1.运维网.com/attachment/201307/112545828.jpg
  backup 上的内容
  ipvsadm –ln
http://img1.运维网.com/attachment/201307/112621886.jpg
  ipvsadm –ln –stats:
http://img1.运维网.com/attachment/201307/112701464.jpg
  主从切换日志内容:
  停掉主上的keepalived
  tail –F/var/log/message
http://img1.运维网.com/attachment/201307/112730751.jpg
  backup日志
http://img1.运维网.com/attachment/201307/112826580.jpg
  从接替主之后访问VIP 产生的效果:
http://img1.运维网.com/attachment/201307/112919754.png
  主从切换正常,试验完成。
  本文出自 “振兴的空间” 博客,请务必保留此出处http://renzhenxing.blog.运维网.com/728846/1251228

页: [1]
查看完整版本: lvs + keepalived + httpd DR模式web层高可用方案架构