keepalived相关配置示例(二)

虚拟服务器配置实验:

两台centos6主机为web service系统为CentOS6.8  n1:172.16.253.87    n2:172.16.252.5都安装httpd    yum install -y httpd[root@n1 ~]#vim /var/www/html/index.html<h1>Real Server 1</h1>[root@n1 ~]#service httpd start[root@n2 ~]#vim /var/www/html/index.html<h1>RealServer 2</h1>[root@n1 ~]#service httpd start#!/bin/bash##vip='172.16.0.99'netmask='255.255.255.255'iface='lo:0' case $1 instart)        echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore        echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore        echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce        echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce         ifconfig $iface $vip netmask $netmask broadcast $vip up        route add -host $vip dev $iface        ;;stop)        ifconfig $iface down         echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore        echo 0 > /proc/sys/net/ipv4/conf/lo/arp_ignore        echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce        echo 0 > /proc/sys/net/ipv4/conf/lo/arp_announce        ;;*)        exit 1esac[root@n1 ~]#bash -x setrs.sh start[root@n1 ~]#route -n172.16.0.99     0.0.0.0         255.255.255.255 UH    0      0        0 lo[root@n1 ~]#scp setrs.sh 172.16.252.5:/root[root@n2 ~]#bash -x setrs.sh start[root@n2 ~]#route -n172.16.0.99     0.0.0.0         255.255.255.255 UH    0      0        0 lo [root@node1 ~]#yum -y install nginx[root@node1 ~]#systemctl start nginx.service[root@node2 ~]#yum -y install nginx[root@node2 ~]#systemctl start nginx.service[root@node1 ~]#yum install -y ipvsadm[root@node1 /etc/keepalived]#vim keepalived.confvirtual_server 172.16.0.99 80 {        delay_ loop 1   服务轮询的时间间隔        lb_algo wrr 定义调度方法        lb_kind DR  集群的类型        protocol TCP 服务协议,仅支持TCP        sorry_server 127.0.0.1 80   备用服务器地址        real_server 172.16.252.5 80 {                weight 1                HTTP_GET {                    url {   定义当前主机的健康状态检测方法                        path /index.html 定义要监控的URL                        status_code 200 判断上述检测机制为健康状态的响应码                    }                       nb_get_retry 3  重试次数                    delay_before_retry 2    重试之前的延迟时长                    connect_timeout 3   连接请求的超时时长                }        }        real_server 172.16.252.5 80 {                weight 1                HTTP_GET {                    url {                        path /index.html                        status_code 200                    }                       nb_get_retry 3                    delay_before_retry 2                    connect_timeout 3                }           }       }       [root@node2 /etc/keepalived]#vim keepalived.conf    做同上操作测试:[root@node1 /etc/keepalived]#systemctl stop keepalived.service[root@node2 /etc/keepalived]#curl http://172.16.0.99<h1>Real Server 1</h1>[root@node2 /etc/keepalived]#curl http://172.16.0.99<h1>RealServer 2</h1>[root@node2 /etc/keepalived]#curl http://172.16.0.99<h1>Real Server 1</h1>[root@node2 /etc/keepalived]#curl http://172.16.0.99<h1>RealServer 2</h1>[root@node1 /etc/keepalived]#systemctl start keepalived.service[root@node1 /etc/keepalived]#ipvsadm -ln  -> 172.16.252.5:80              Route   1      0          2           -> 172.16.253.87:80             Route   1      0          2         [root@node2 /etc/keepalived]#ipvsadm -ln  -> 172.16.252.5:80              Route   1      0          0           -> 172.16.253.87:80             Route   1      0          0       [root@n1 ~]#service httpd stop[root@node1 /etc/keepalived]#ipvsadm -ln  -> 172.16.252.5:80              Route   1      0          0    [root@n1 ~]#service httpd start   [root@n2 ~]#service httpd stop[root@node2 /etc/keepalived]#ipvsadm -ln  -> 172.16.253.87:80             Route   1      0          0   

TCP_CHECK使用示例:

[root@node1 /etc/keepalived]#vim keepalived.confvirtual_server 172.16.0.99 80 {        delay_ loop 1        lb_algo wrr        lb_kind DR        protocol TCP        sorry_server 127.0.0.1 80         real_server 172.16.253.87 80 {                weight 1                HTTP_GET {                    url {                        path /index.html                        status_code 200                    }                    nb_get_retry 3                    delay_before_retry 2                    connect_timeout 3                }        }        real_server 172.16.252.5 80 {                weight 1                TCP_CHECK {                    nb_get_retry 3                    delay_before_retry 2                    connect_timeout 3                }        }}

原创文章,作者:Linux.rookie,如若转载,请注明出处:http://www.178linux.com/78798

(0)
Linux.rookieLinux.rookie
上一篇 2017-06-28
下一篇 2017-06-29

相关推荐

  • iptables

    练习:基于状态放行telnet, ftp, ssh, http, samba, icmp等服务 (1) 对本机的ping请求每分钟不得超出20个 (2) 每客户端对本机的ssh的并发连接数不得超过3个 (3) 本机的telnet服务仅允许工作时间内访问 [root@node1 ~]# vim iptables.sh iptabl…

    Linux干货 2016-10-22
  • 文本字符处理工具

    文件查看命令 cat,tac,rev cat [options] [file]     -E:显示行结束符     -n:显示行号                    nl file 也能实现相同的功能   …

    Linux干货 2017-02-25
  • iptables实现地址转换

    NAT:(工作在网络和传输层) 过载技术 Basic NAT:静态NAT     一个内部主机,分配一个外网地址 NAPT:动态NAT,网络地址端口转换;net会话表     源地址转换:SNAT 用于内网主机访问互联网    &…

    Linux干货 2016-10-31
  • Linux运维学习历程-第四天-Linux的使用帮助和快捷键

    本章内容     命令存放位置     命令帮助      help     man帮助     其它帮助        命令历史     快捷键 一、命令存放位置   &nbsp…

    Linux干货 2016-08-03
  • 单台主机lnmp+wordpress配置示例

    单台主机lnmp+wordpress fpm配置 ]# yum install php php-fpm php-mysql –y ]# vim /etc/php-fpm.d/www.conf 配置服务监听地址和程序运行者身份 listen = 127.0.0.1:9000 user = nginx group = nginx ]# chown -R ngin…

    Linux干货 2016-11-07
  • 上篇博客简单提了一下Nginx配置文件的大体组成部分,这次来好好解释一下这些个配置文件。 一、main配置段 分类:    正常运行必备的配置    优化性能相关的配置    用于调试及定位问题相关的配置   …

    Linux干货 2016-10-26