测试配置keepalived_lvs_realserver

1. 在lvs-director-master: svr200-21上配置keepalived
安装
[[email protected] ~]# yum -y install ipvsadm keepalived

配置1个vip对应4个real server
vip: 10.0.205.100
dip: 10.0.200.21
rip: 10.0.205.2-5

2. 配置几个realserver的vip
控制脚本:
[[email protected] salt]# cat lvs/bin/lvs-realsvr.sh 
#!/bin/bash
# 
# 2015/2/28
# lvs real server
#
# chkconfig:   - 85 15
# description:  control vip on lvs realserver 

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

lockfile="/var/lock/subsys/lvs-real"
  
s_vip=‘10.0.205.100‘

start() {
  ifconfig lo:1 ${s_vip} netmask 255.255.255.255 broadcast ${s_vip}
  route add -host ${s_vip} dev lo:1
  echo 1 >/proc/sys/net/ipv4/conf/lo/arp_ignore
  echo 2 >/proc/sys/net/ipv4/conf/lo/arp_announce
  echo 1 >/proc/sys/net/ipv4/conf/all/arp_ignore
  echo 2 >/proc/sys/net/ipv4/conf/all/arp_announce

  retval=$?
  echo
  [ $retval -eq 0 ] && touch $lockfile
  return $retval
}

stop() {
  echo 0 >/proc/sys/net/ipv4/conf/lo/arp_ignore
  echo 0 >/proc/sys/net/ipv4/conf/lo/arp_announce
  echo 0 >/proc/sys/net/ipv4/conf/all/arp_ignore
  echo 0 >/proc/sys/net/ipv4/conf/all/arp_announce
  ifconfig lo:1 down
  route del -host ${s_vip}

  retval=$?
  echo
  [ $retval -eq 0 ] && rm -f $lockfile
  return $retval
}

status() {
  ip a |grep inet |grep -v inet6  
}

case $1 in  
  start)
    start
    status
    ;;
  stop)
    stop
    status
    ;;
  status)
    status
    ;;
  *)  
    echo $"Usage: $0 {start|stop|status}"
    exit 2 
esac  

在几个rip主机上start脚本,即可启用vip。

3. 调整director的配置文件
[[email protected] keepalived]# pwd
/etc/keepalived
[[email protected] keepalived]# cp -a keepalived.conf  keepalived.conf.old

[[email protected] keepalived]# cat keepalived.conf
! Configuration File for keepalived

global_defs {
   notification_email {
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_Director1
}

vrrp_instance VIP1 {
    state MASTER          # MASTER or BACKUP,大写
    interface eth0        # 对外服务的端口
    virtual_router_id 21  # 虚拟路由器id
    priority 150          # 数值大则优先级高
    advert_int 1          # 同步时间间隔
    authentication {
      auth_type PASS
      auth_pass 654321
    }
    virtual_ipaddress {
      10.0.205.100
    }
}

virtual_server 10.0.205.100 80 {
    delay_loop 6              # 健康检查时间间隔
    lb_algo wrr                # 调度算法:rr | wrr | lc | wlc | lblc | sh | dh
    lb_kind DR                # 转发规则:NAT | DR | TUN
    #persistence_timeout 50   # 会话保持时间
    protocol TCP

    # genhash -s rip -p port -u url
    # genhash -s 10.0.205.2 -p 80 -u /index.html

    real_server 10.0.205.2 80 {
      weight 1

      HTTP_GET {                  # HTTP_GET | SSL_GET | TCP_CHECK | SMTP_CHECK | MISC_CHECK
        url {
          path /index.html
          digest e93e7f6cfbc7c343707f21e2f681dd31
        }
        connect_timeout 3         # 连接超时时间,秒
        nb_get_retry 3            # 失败重试次数,超过后移除
        delay_before_retry 3      # 失败重试间隔,秒
      }
    }

    real_server 10.0.205.3 80 {
      weight 1

      HTTP_GET {                  # HTTP_GET | SSL_GET | TCP_CHECK | SMTP_CHECK | MISC_CHECK
        url {
          path /index.html
          digest b8682521d6c7a01d370ebad57ad6981f 
        }
        connect_timeout 3         # 连接超时时间,秒
        nb_get_retry 3            # 失败重试次数,超过后移除
        delay_before_retry 3      # 失败重试间隔,秒
      }
    }

    real_server 10.0.205.4 80 {
      weight 1

      HTTP_GET {                  # HTTP_GET | SSL_GET | TCP_CHECK | SMTP_CHECK | MISC_CHECK
        url {
          path /index.html
          digest 93c5e661950fabd0bfda085a513cdb7a
        }
        connect_timeout 3         # 连接超时时间,秒
        nb_get_retry 3            # 失败重试次数,超过后移除
        delay_before_retry 3      # 失败重试间隔,秒
      }
    }

    real_server 10.0.205.5 80 {
      weight 1

      HTTP_GET {                  # HTTP_GET | SSL_GET | TCP_CHECK | SMTP_CHECK | MISC_CHECK
        url {
          path /index.html
          digest e63f0e81e7a2fddb2d32d83aacbe8472
        }
        connect_timeout 3         # 连接超时时间,秒
        nb_get_retry 3            # 失败重试次数,超过后移除
        delay_before_retry 3      # 失败重试间隔,秒
      }
    }

}

2. 启动服务
[[email protected] keepalived]# service keepalived start
Starting keepalived:                                       [  OK  ]

[[email protected] keepalived]# tail -f /var/log/messages
Feb 28 16:37:02 server200-21 Keepalived_healthcheckers[23679]: Activating healthchecker for service [10.0.205.2]:80
Feb 28 16:37:02 server200-21 Keepalived_healthcheckers[23679]: Activating healthchecker for service [10.0.205.3]:80
Feb 28 16:37:02 server200-21 Keepalived_healthcheckers[23679]: Activating healthchecker for service [10.0.205.4]:80
Feb 28 16:37:02 server200-21 Keepalived_healthcheckers[23679]: Activating healthchecker for service [10.0.205.5]:80
Feb 28 16:37:03 server200-21 Keepalived_vrrp[23680]: VRRP_Instance(VIP1) Transition to MASTER STATE
Feb 28 16:37:04 server200-21 Keepalived_vrrp[23680]: VRRP_Instance(VIP1) Entering MASTER STATE
Feb 28 16:37:04 server200-21 Keepalived_vrrp[23680]: VRRP_Instance(VIP1) setting protocol VIPs.
Feb 28 16:37:04 server200-21 Keepalived_vrrp[23680]: VRRP_Instance(VIP1) Sending gratuitous ARPs on eth0 for 10.0.205.100
Feb 28 16:37:04 server200-21 Keepalived_healthcheckers[23679]: Netlink reflector reports IP 10.0.205.100 added
Feb 28 16:37:09 server200-21 Keepalived_vrrp[23680]: VRRP_Instance(VIP1) Sending gratuitous ARPs on eth0 for 10.0.205.100
   
查看lvs:
[[email protected] keepalived]# ipvsadm -Ln               
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  10.0.205.100:80 wrr
  -> 10.0.205.2:80                Route   1      3          0         
  -> 10.0.205.3:80                Route   1      1          0         
  -> 10.0.205.4:80                Route   1      2          0         
  -> 10.0.205.5:80                Route   1      2          0    

访问网站:
http://10.0.205.100
得到:
--------------------------
HOST: svr205-5 

lo: 127.0.0.1 
eth0: 10.0.205.5 
--------------------------

   
停止了svr205-5 上的的nginx服务后:
[[email protected] keepalived]# tail -f /var/log/messages
Feb 28 16:41:26 server200-21 Keepalived_healthcheckers[23679]: Error connecting server [10.0.205.5]:80.
Feb 28 16:41:26 server200-21 Keepalived_healthcheckers[23679]: Removing service [10.0.205.5]:80 from VS [10.0.205.100]:80
Feb 28 16:41:26 server200-21 Keepalived_healthcheckers[23679]: Remote SMTP server [127.0.0.1]:25 connected.
Feb 28 16:41:26 server200-21 Keepalived_healthcheckers[23679]: SMTP alert successfully sent.

访问网站:
http://10.0.205.100
得到:
--------------------------
HOST: svr205-4 

lo: 127.0.0.1 
eth0: 10.0.205.4 
--------------------------

查看lvs:
[[email protected] keepalived]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  10.0.205.100:80 wrr
  -> 10.0.205.2:80                Route   1      0          0         
  -> 10.0.205.3:80                Route   1      2          0         
  -> 10.0.205.4:80                Route   1      3          0  
  
  
  
再次启动svr205-5 上的的nginx服务
[[email protected] keepalived]# tail -f /var/log/messages
Feb 28 16:42:50 server200-21 Keepalived_healthcheckers[23679]: MD5 digest success to [10.0.205.5]:80 url(1).
Feb 28 16:42:56 server200-21 Keepalived_healthcheckers[23679]: Remote Web server [10.0.205.5]:80 succeed on service.
Feb 28 16:42:56 server200-21 Keepalived_healthcheckers[23679]: Adding service [10.0.205.5]:80 to VS [10.0.205.100]:80
Feb 28 16:42:56 server200-21 Keepalived_healthcheckers[23679]: Remote SMTP server [127.0.0.1]:25 connected.
Feb 28 16:42:56 server200-21 Keepalived_healthcheckers[23679]: SMTP alert successfully sent.

查看lvs:  
[[email protected] keepalived]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  10.0.205.100:80 wrr
  -> 10.0.205.2:80                Route   1      0          0         
  -> 10.0.205.3:80                Route   1      2          0         
  -> 10.0.205.4:80                Route   1      3          0         
  -> 10.0.205.5:80                Route   1      3          0
时间: 2024-11-07 18:08:18

测试配置keepalived_lvs_realserver的相关文章

【阿里云产品公测】简单粗暴30S完成PTS测试配置附tornado服务器测试结果

作者:阿里云用户morenocjm [阿里云产品公测]简单粗暴 30S完成PTS测试配置(附tornado服务器测试结果) -------------------------------------------------------------------------------------------- 如果你想了解自己服务器,性能测试当然是不能少的. 使用PTS测试并不需要自己编写脚本, 简单的操作界面以及合理的菜单确实便于操作, 真的只要几十秒的操作就能让你了解你的服务器负载能力了.  

spring自带测试配置

spring自带的测试注解 @ContextConfiguration(locations="classpath:applicationContext.xml")@RunWith(SpringJUnit4ClassRunner.class) public class TestUserDaoImpl extends AbstractJUnit4SpringContextTests{ @Autowired UserDao userDao; //TODO } classpath:applic

再次测试配置keepalived,lvs和realserver

熟能生巧嘛. 对keepalived和VRRP的理解: keepalived: 高可用,更便捷的配置管理lvs vrrp: 理解成局域网中增加了一个虚拟路由器组,其中有一个主机上的vrrp实例是master角色,上面启用了vip,组内其他都是backup角色,利用这个协议,可以让vip在局域网中同组的vrrp实例上漂移 一.需求 要使用keepalived配置vip来转发到后端的realserver上 vip:10.0.200.100 dip:  10.0.200.104(master) 10.

测试配置yum仓库的http镜像

一.基础环境 1.在tvm-base的基础上,复制一个镜像为tvm-yum来测试. 2.网络: eth0:host-only(用于虚拟内网,手动固定IP,这样从宿主机可以直接连接到这个vm) eth1:NAT(用于上外网,动态IP) [[email protected] ~]# cd /etc/sysconfig/network-scripts/ [[email protected] network-scripts]# cat ifcfg-eth0 DEVICE=eth0 TYPE=Ethern

30_MHA集群概述 、 部署MHA集群 测试配置

版本:5.7.28 1.准备MHA集群环境准备6台虚拟机,并按照本节规划配置好IP参数在这些虚拟机之间实现SSH免密登录在相应节点上安装好MHA相关的软件包 使用6台RHEL 7虚拟机,如图-1所示.准备集群环境,安装依赖包,授权用户,配置ssh密钥对认证登陆,所有节点之间互相以root秘钥对认证登录,管理主机以root密钥对认证登录所有数据节点主机,配置mha集群. 1.1 修改主机名,配置IPmsyql{50..57}192.168.4.{50..57} 1.2 安装包(51-55)]# t

Jmeter 分布式测试配置方法

利用JMeter进行负载测试的时候,使用单台机器模拟测试超过1000个行程的并发就有些力不从心,在执行的过程中,JMeter自身会自动关闭,要解决这个问题,可以使用分布式测试,运行多台机器运行所谓的 Agent 来分担 JMeter自身的压力,并借此来获取更大的并发用户数,但是需要进行相关的一些修改,具体如下: 1.在所有期望运行 JMeter 作为 Load Generator 的机器上安装 JMeter,并确定其中一台机器作为 Controller,其他的机器作为 Agent.然后运行所有

mycat 1.6 配置【仅学习测试配置使用】

jdk 自行配置 mycat 1.6 点击下载 配置文件 schema.xml <?xml version="1.0"?> <!DOCTYPE mycat:schema SYSTEM "schema.dtd"> <mycat:schema xmlns:mycat="http://io.mycat/"> <schema name="TESTDB" checkSQLschema="

Tengine/2.1.2 (nginx/1.6.2) 测试配置

前端tenginx 配置 cat /usr/local/tengine/conf/nginx.conf user nginx nginx;                                                                                                                                                                                     

自动测试配置(python)

一.python的安装和配置 安装 官网:http//www.python.org/ 配置 系统设置中Path路径后面;C:\Users\AppData\Local\Programs\Python\Python37 (python的安装路径) 系统设置中Path路径后面;C:\Users\AppData\Local\Programs\Python\Python37\Scripts  (python安装路径下的scripts路径) 验证: 进入:cmd 输入:python  运行正常即可(也可以输