keepalive:

keepalive:

调度器的高可用

vip地址在主备之间的切换,主在工作时,vip地址只在主上,主停止工作,vip漂移到备服务器。

在主备的优先级不变的情况下,主恢复工作,vip会飘回到主服务器。

1、配优先级

2、配置vip和真实服务器

3、主备的id要一致

4、主备的id要区分。

keepalive是专门为lvs打造的,但是不是为lvs专门服务的。

keepalive也可以使用nginx,haproxy。

keepalive+nginx实现高可用

vrrp script check_nginx {
script "/opt/check_nginx.sh"
#调用脚本内容,检测nginx的状态
interval 5
#检测的间隔时间是5秒
}
操作:

1、关闭两台nginx的防火墙

[root@test3 ~]# systemctl stop firewalld
[root@test3 ~]# setenforce 0

2、下载keepalive配置文件

[root@test3 ~]# yum -y install keepalived

3、在主写一个监控nginx的脚本

[root@test3 opt]# vim check_nginx.sh 
​
#!/bin/bash
/usr/bin/curl -I http://localhost &> /dev/null
if [ $? -ne 0 ]
then
 systemctl stop keepalived
fi

4、将脚本赋权

[root@test3 opt]# chmod 777 check_nginx.sh 

5、在主中更改keepalive配置文件

[root@test3 opt]# vim /etc/keepalived/keepalived.conf
​
! Configuration File for keepalived
​
global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_01
   vrrp_skip_check_adv_addr
   vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
   vrrp_iptables
}
   vrrp_script check_nginx {
        script "/opt/check_nginx.sh"
        interval 5
}
​
vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 120
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.60.100
    }
     track_script {
        check_nginx
    }
}

6、将主的keepalive配置文件复制到备中

[root@test4 ~]# scp root@192.168.60.30:/etc/keepalived/keepalived.conf /etc/keepalived/

7、更改备的配置文件

[root@test4 ~]# vim /etc/keepalived/keepalived.conf 
​
! Configuration File for keepalived
​
global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_02
   vrrp_skip_check_adv_addr
   vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
   vrrp_iptables
}
   vrrp_script check_nginx {
        script "/opt/check_nginx.sh"
        interval 5
}
​
vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.60.100
    }
     track_script {
        check_nginx
    }
}

面试题:

脑裂是什么

HA 高可用架构中的一个特殊现象,只要使用vip地址代理的冗余模式的高可用。都有可能出现脑裂的问题。

主和备同时都有vip地址

主和备无法确定各自的身份,同时出现了vip地址,两边起来了,但是两边都无法使用。

原因:

1、keepalive的配置文件问题

2、心跳线(网线)断了,老化

3、网卡出了问题(硬件),IP地址配置冲突。

4、防火墙的策略,iptables的策略,屏蔽了组播地址的广播。屏蔽了vrrp协议的报文

5、两台服务器的时间不同步也可能导致。

6、其他的服务配置对心跳线的检测造成了干扰。

怎么解决

1、 将keepalive的配置文件中错误配置更改

2、 更换新的网线

3、 Ip地址冲突,就更改其他的vip地址,如果是硬件问题,就更换新的网卡

4、 将防火墙策略中阻止通信的策略删除或在keepalive的配置文件中加一行vrrp_iptables

5、 将两台服务器的时间同步

6、 将其他服务配置更改

nginx lvs lvs+keepalive keepalive单独配置

web集群

Haproxy负载均衡:

nginx 四层转发,七层代理

lvs 四层转发 内核态 用户态

Haproxy 四层转发 七层代理

Haproxy的作用和使用场景:

1、场景 用于高并发的web场景,可以支持一万个以上的并发请求,高性能的tcp和http的负载均衡器。

工作原理:

提高一个代理地址,访问集群

2、作用:

1)进行四层和七层转发

2)支持https

3)haproxy本身不自带缓存功能。请求当中添加cookie,使用缓存

4)支持主备切换(keepalive)

3、特点:

可靠性高,稳定性好

可以同时维护40000~50000个并发,单位时间内可以处理的最大请求数20000个(3秒)

支持负载均衡算法,虽然不带缓存,但是可以支持会话保持。

rr

wrr

lestconn

make TARGET=linux2628 ARCH=x86 64

target使用的版本要大于linux2.60以上的办呢

3.10

2628

2.62.8 linux内核版本

操作:

1、安装依赖环境

[root@test8 opt]# yum install -y pcre-devel bzip2-devel gcc gcc-c++ make

2、将压缩包拖到opt目录下

[root@test8 ~]# cd /opt/
[root@test8 opt]# rz -E
rz waiting to receive.

3、解压haproxy压缩包并执行

[root@test8 opt]# tar -xf haproxy-1.5.19.tar.gz 
[root@test8 opt]# cd haproxy-1.5.19/
[root@test8 haproxy-1.5.19]# uname -r
3.10.0-957.el7.x86_64
[root@test8 haproxy-1.5.19]# make TARGET=linux2628 ARCH=x86_64

4、执行一下

[root@test8 haproxy-1.5.19]# make install

5、创建一个目录将主配置文件复制到创建的目录下

[root@test8 haproxy-1.5.19]# mkdir /etc/haproxy
[root@test8 haproxy-1.5.19]# cd examples/
[root@test8 examples]# cp haproxy.
haproxy.cfg   haproxy.init  haproxy.spec  haproxy.vim
[root@test8 examples]# cp haproxy.cfg /etc/haproxy/

6、更改主配置文件

[root@test8 examples]# cp haproxy.cfg /etc/haproxy/
[root@test8 examples]# cd /etc/haproxy/
[root@test8 haproxy]# vim haproxy.cfg 
​
# this config needs haproxy-1.1.28 or haproxy-1.2.1
​
global
        log /dev/log    local0 info
        log /dev/log    local1 notice
        #log loghost    local0 info
        maxconn 4096
        #最大连接数,推荐使用10240
        #chroot /usr/share/haproxy
        uid 99
        gid 99
        daemon
        nbproc 4
        #4相当于haproxy的并发线程数,设置的数量最好是cpu的2倍或者和cpu保持一致
        #debug
        #quiet
​
defaults
#这里是默认参数配置,连接配置,监听配置以及代理配置
        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3
        #检查节点服务器3次,连续3次失败,就认为节点服务器不可用
        redispatch
        #服务器负载很高时,自动结束当前队列中处理比较久的连接
        maxconn 2000
        #最大连接数,这个数值可以和global中的一致,也可以比他小,但是不能超过他,一般设置成一致。
        #contimeout     5000
        #clitimeout     50000
        #srvtimeout     50000
        timeout http-request 10s
        #http请求的默认超时时间
        timeout queue 1m
        #在队列当中请求的超时时间
        timeout connect 10s
        #连接超时时间
        timeout client 1m
        #客户端的超时时间
        timeout server 1m
        #服务端的超时时间
        timeout http-keep-alive 10s
        #默认长连接的超时时间
        timeout check 10s
        #检查后端服务器的超时时间. 
​
#转发请求的设置,既可以是四层也可以是七层
#7层的配置:
listen xy102 0.0.0.0:80
        option httpchk GET /index.html
        balance        static-rr
        server rs01 192.168.60.30:80 check inter 2000 fall 3 weight 2
        server rs02 192.168.60.40:80 check inter 2000 fall 3 weight 3
#server 指定真实服务器  rs01 自定后台服务器名称 check inter 2000 启动对后端服务器进行检查,检查的间隔时间2000毫秒。  fall 3  连续三次见不到任务失败。

7、将haproxy.init配置文件复制并赋权和做软连接

[root@test8 haproxy-1.5.19]# cd /opt/haproxy-1.5.19/examples/
[root@test8 examples]# cp haproxy.init /etc/init.d/haproxy
[root@test8 examples]# chmod 777 /etc/init.d/haproxy 
[root@test8 examples]# chkconfig --add /etc/init.d/haproxy 
[root@test8 examples]# ln -s /usr/local/sbin/haproxy /usr/bin/
​

8、重启haproxy服务

[root@test8 init.d]# systemctl restart haproxy

9、四层代理

#四层转发:
frontend test
bind *:80
mode tcp
default_backend test
​
backend test
mode tcp
balance roundrobin
server server1 192.168.60.30:80 check inter 2000 fall 3 weight 2
server server2 192.168.60.40:80 check inter 2000 fall 3 weight 2

10、结果

[root@test8 haproxy]# curl 192.168.60.80
this is test3
[root@test8 haproxy]# curl 192.168.60.80
this is test4
[root@test8 haproxy]# curl 192.168.60.80
this is test4
[root@test8 haproxy]# curl 192.168.60.80
this is test3
[root@test8 haproxy]# curl 192.168.60.80
this is test4

keepalive+haproxy:

vip 192.168.60.100

rs1

rs2

nginx+keepalive:

  • 18
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值