博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
lvs+keepalived+DR搭建高可用集群
阅读量:6036 次
发布时间:2019-06-20

本文共 6037 字,大约阅读时间需要 20 分钟。

lvs+keepalived+DR搭建高可用集群

环境准备:

  lvsserver1  192.168.1.10

  lvsserver2  192.168.1.11

  vip                   192.168.1.15

  rs1                   192.168.1.12

  rs2                   192.168.1.13

lvsserver1和lvsserver2操作:

开启路由转发

临时生效  echo "1" > /proc/sys/net/ipv4/ip_forward

永久生效  vim /etc/sysctl.conf

      net.ipv4.ip_forward = 1

1 安装ipvsadm以及keepadlived  2 [root@lvs1 ~]# yum install gcc* c++ * autoconf automake zlib*  libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* popt-devel libnl-devel kernel-devel ipvsadm  3 [root@lvs1 ~]# wget http://www.keepalived.org/software/keepalived-1.1.19.tar.gz    //不推荐使用最新版本  4 [root@lvs1 ~]# tar -xf keepalived-1.1.19.tar.gz      5 [root@lvs1 ~]# ./configure  6 Keepalived configuration  7   8 ------------------------  9  10 Keepalived version : 1.1.17 11 Compiler : gcc 12 Compiler flags : -g -O2 13 Extra Lib : -lpopt -lssl -lcrypto 14 Use IPVS Framework : No            **使用IPVS框架,也就是负载均衡模块 15 IPVS sync daemon support : No    **启用IPVS同步功能 16 Use VRRP Framework : Yes        **实现高可用的必须模块 17 Use LinkWatch : No 18 Use Debug flags : No 19  20 当出现这两个为No的时候,则需以下操作 21  22 [root@lvs1 ~]# ./configure --with-kernel-dir=/usr/src/kernels/2.6.32-754.11.1.el6.x86_64/ 23 [root@lvs1 ~]# make 24 [root@lvs1 ~]# make install 25 [root@lvs1 ~]# cp -a /usr/local/etc/rc.d/init.d/keepalived /etc/init.d/ 26 [root@lvs1 ~]# cp -a /usr/local/etc/sysconfig/keepalived /etc/sysconfig/  27 [root@lvs1 ~]# mkdir -p /etc/keepalived  28 [root@lvs1 ~]# cp -a /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/  29 [root@lvs1 ~]# cp -a /usr/local/sbin/keepalived /usr/bin/ 30 [root@lvs1 ~]# cd /etc/keepalived && cp -a keepalived.conf keepalived.conf.bak 31 [root@lvs1 ~]# cat keepalived.conf 32 [root@lvs1 ~]# cat /etc/keepalived/keepalived.conf 33 ! Configuration File for keepalived 34  35 global_defs { 36    router_id LVS_MASTER             **标识本节点的字条串,通常通知邮件会用到。一般设置hostname 37 } 38  39 vrrp_instance VI_1 {     40     state MASTER                    **标识机器的状态,从则为BACKUP 41     interface eth0                  **绑定ip地址接口 42     lvs_sync_daemon_inteface eth0  **负载均衡之间的监控接口,类似于HA HeartBeat的心跳线 43     virtual_router_id 51            **虚拟路由id,两台机器必须一样 44     priority 150                    **优先级,master必须比backup大,从为100 45     advert_int 1                    **发VRRP的间隔时间,即多久一次master选举 46     authentication {          **认证区域 47         auth_type PASS 48         auth_pass 123456  49     } 50     virtual_ipaddress { 51     172.30.21.230                    **定义一个vip 52     } 53 } 54  55 virtual_server 192.168.1.15 443 {   **定义虚拟服务器 56     delay_loop 6             **定义健康检查间隔 57     lb_algo rr              **负载均衡调度算法 58     lb_kind DR              **负载均衡机制 59     #nat_mask 255.255.255.0      **子网掩码 60     persistence_timeout 50       **会话保持时间,提供动态保持session,同一ip在该时间内分配到同一服务器 61     protocol TCP             **转发协议类型,支持TCP/UDP 62  63     real_server 192.168.1.12 443 {  **定义节点服务器 64     weight 3               **权重 65         TCP_CHECK {            **健康监测方式,支持HTTP_GET,SSL_GET,TCP_CHECK,SNMP_CHECK,MISC_CHECK 66             connect_timeout 3      **无响应时间,单位秒 67             nb_get_retry 3        **重试次数 68             delay_before_retry 3    **重试间隔,单位秒 69             connect_port 443      **监测端口,不指定时默认为real_server端口 70         } 71     } 72  73     real_server 192.168.1.13 443 { 74     weight 3 75         TCP_CHECK { 76             connect_timeout 3 77             nb_get_retry 3 78             delay_before_retry 3 79             connect_port 443 80         } 81         } 82 } 83  84 virtual_server 192.168.1.15 2222 { 85     delay_loop 6 86     lb_algo rr 87     lb_kind DR 88     #nat_mask 255.255.255.0 89     persistence_timeout 50 90     protocol TCP 91  92     real_server 192.168.1.12 2222 { 93     weight 3 94         TCP_CHECK { 95             connect_timeout 3 96             nb_get_retry 3 97             delay_before_retry 3 98             connect_port 2222 99             }100         }101 102     real_server 192.168.1.13 2222 {103     weight 3104         TCP_CHECK {105             connect_timeout 3106             nb_get_retry 3107             delay_before_retry 3108             connect_port 2222109                }110         }111 }112 113 两台机器都启动keepalived以及ipvsadm114 [root@lvs1 ~]# ip addr    **查看vip在哪

 

rs1和rs2操作:

1 [root@lvs-nginx1 ~]# cat /etc/init.d/lvs  2 #!/bin/bash 3  4 VIP=192.168.1.15 5  6 /etc/rc.d/init.d/functions 7  8 case "$1" in 9 10 start)11            echo "start LVS of RealServer DR"12            /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up13            echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore14            echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce15            echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore16            echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce 17        ;;18 stop)19            /sbin/ifconfig lo:0 down20            echo "close LVS of RealServer DR"21            echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore22            echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce23            echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore24            echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce25            ;;26 *)27           echo "Usage: $0 {start|stop}"28           exit 129 esac30 31 exit 032 33 [root@lvs-nginx1 ~]# /etc/init.d/lvs start34 [root@lvs-nginx1 ~]# echo "/etc/init.d/lvs start" >> /etc/rc.d/rc.local

 

最后使用ipvsadm -L查看结果以及切换演练

 

nginx.conf 开启 stream {        include /etc/nginx/tcp/*.conf;}#stream {        upstream aaa_ssh {        server xxxx:2222;        server xxxx:2222;        hash $remote_addr consistent;        }        upstream aaa_ssl {        server xxxx:443;        hash $remote_addr consistent;        }        server {        listen  2222 so_keepalive=on;	因为是22端口,所以开启长连接        proxy_pass      aaa_ssh;        proxy_connect_timeout 60;        proxy_timeout 1h;        #include        proxy.conf;        }        server {        listen  443;        proxy_pass      aaa_ssl;        proxy_connect_timeout 60;        #include        proxy.conf;        }#}

  

转载于:https://www.cnblogs.com/jcici/p/10607463.html

你可能感兴趣的文章
【转】keyCode对照表及JS监听组合按键
查看>>
[Java开发之路](14)反射机制
查看>>
mac gentoo-prefix安装git svn
查看>>
浅尝异步IO
查看>>
C - Train Problem II——(HDU 1023 Catalan 数)
查看>>
Speak loudly
查看>>
iOS-在项目中引入RSA算法
查看>>
[译] 听说你想学 React.js ?
查看>>
gulp压缩合并js与css
查看>>
块级、内联、内联块级
查看>>
Predicate
查看>>
[面试题记录01]实现一个function sum达到一下目的
查看>>
这个季节的忧伤,点到为止
查看>>
mysql通过配置文件进行优化
查看>>
省级网站群建设关注点
查看>>
工作第四天之采集资源
查看>>
innobackupex 在增量的基础上增量备份
查看>>
Windows Server 2012 R2 DirectAccess功能测试(2)App1服务器安装及配置
查看>>
基于清单的启动器的实现
查看>>
外网用户通过citrix打印慢的解决方法
查看>>