搭建高可用的web集群


日志

  1. 构成 #man 5 rsyslog.conf

Facility.priority相当于是 服务.优先级

Facility可以是这些关键字:auth,authpriv, cron, daemon, kern, lpr, mail, mark, news, securitysyslog, user, uucp 以及local0local7

Local0local7是预留出来的接口,供第三方应用调用。

Priority可以使用的关键字:debug,info,notice, warning, warn err, errorcrit,alert,emerg, panic

Debug是最不严重的级别,panic是最严重的级别。如果日志记录优先级是info,表示比info严重的日志都需要记录。


配置haproxy日志

1、配置本机接受通过网络发来的日志

[root@node4~]# vim /etc/rsyslog.conf

#Provides UDP syslog reception

$ModLoadimudp

$UDPServerRun514

#Provides TCP syslog reception

$ModLoadimtcp

$InputTCPServerRun514

[root@node4~]# systemctl restart rsyslog

  1. 查看日志

[root@node4~]# tail -f /var/log/messages

访问haproxy调度器,可以看到日志信息。



VRRP:虚拟冗余路由协议,IETF公共标准

HSRP:热备份路由协议,,思科私有



搭建高可用的web集群

  1. node2node3提供web服务。由于没有过多的用户访问,只有一台服务器工作即可,另一台只是起到备份作用。

  2. 安装服务

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

  1. 修改配置文件

[root@node2~]# vim /etc/keepalived/keepalived.conf

#vrrp_strict

vrrp_instanceVI_1 {

stateMASTER #辅助写BACKUP

interfaceeth0

virtual_router_id51 #虚拟路由器ID

priority150 #优先级

advert_int1 # 心跳消息发送间隔

authentication{ # 集群成员共享密码

auth_typePASS

auth_pass1111

}

virtual_ipaddress{

192.168.4.200 # vip

}

}

Heartbeat:心跳

[root@node2~]# systemctl start keepalived

  1. 查看、验证

[root@node2~]# ip address show eth0



双主配置:两台主机,两个服务,每个主机是一个服务的主




搭建高可用、负载均衡的web集群

1、新建node5虚拟机,作为额外的lvs服务器。虽然有两台调度器,也是DR模式。

2、在web服务器的lo上配置VIP

3、调整web服务器的内核参数

4、调度器上不要再手工的为eth0配置VIP了。因为VIP出现在活跃的调度器上,活跃设备由keepalived决定。应该把已经存在的调度器VIP移除。

[root@node4~]# ifdown eth0:0

[root@node4~]# mv /etc/sysconfig/network-scripts/ifcfg-eth0:0 ~

  1. node4上的haproxy停掉

[root@node4~]# systemctl stop haproxy

6、将node4上的lvs规则清掉。因为lvs规则将由keepalived配置文件指定。

[root@node4~]# ipvsadm -D -t 192.168.4.100:80

  1. node5上安装ipvsadm

[root@node5~]# yum install -y ipvsadm

8、在node4/5安装keeaplived

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

  1. node4上配置keepalived

[root@node4~]# vim /etc/keepalived/keepalived.conf

global_defs{

notification_email{

root@localhost # 收件人

}

notification_email_fromadmin@tedu.cn # 发件人

smtp_server127.0.0.1 # 邮件服务器地址

smtp_connect_timeout30

router_idLVS_DEVEL

vrrp_skip_check_adv_addr

#vrrp_strict

vrrp_garp_interval0

vrrp_gna_interval0

}

vrrp_instanceVI_1 {

stateMASTER

interfaceeth0

virtual_router_id51

priority150

advert_int1

authentication{

auth_typePASS

auth_pass1111

}

virtual_ipaddress{

192.168.4.100

}

}

virtual_server192.168.4.10080 {

delay_loop6

lb_algorr

lb_kindDR

persistence_timeout50

protocolTCP


real_server192.168.4.2 80 {

weight1

TCP_CHECK{

connect_timeout3

nb_get_retry3

delay_before_retry3

}

}

real_server192.168.4.3 80 {

weight1

TCP_CHECK{    //TCP_CHECK与{ 之间要有空格

connect_timeout3

nb_get_retry3

delay_before_retry3

}

}

}


[root@vh05 ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived


global_defs {
   notification_email {
     root@localhost 
  }
   notification_email_from admin@tedu.cn
   smtp_server 127.0.0.1 
   smtp_connect_timeout 30
   router_id LVS_DEVEL
   vrrp_skip_check_adv_addr
   #vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}


vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.4.100
        
        
    }
}


virtual_server 192.168.4.100 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    #persistence_timeout 50    //超时时间
    protocol TCP


    real_server 192.168.4.2 80 {
        weight 1
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }


    real_server 192.168.4.3 80 {
        weight 1
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }


    }

   17  systemctl start keepalived
   18  ipvsadm -Ln
   19  ip a s eth0
   20  mail

  1. 启动服务验证

[root@node4~]# systemctl restart keepalived.service

http://192.168.4.100/

 ip a s eth0

[root@vh04 ~]# ip a s eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:b3:cc:45 brd ff:ff:ff:ff:ff:ff
    inet 192.168.4.4/24 brd 192.168.4.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 192.168.4.100/32 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::1ee:eef7:8d98:d473/64 scope link 
       valid_lft forever preferred_lft forever
[root@vh04 ~]# systemctl stop keepalived

[root@vh04 ~]# 


[root@vh05 ~]# ip a s eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:83:17:b5 brd ff:ff:ff:ff:ff:ff
    inet 192.168.4.5/24 brd 192.168.4.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::14cb:13bf:406f:c219/64 scope link 
       valid_lft forever preferred_lft forever
[root@vh05 ~]# ip a s eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:83:17:b5 brd ff:ff:ff:ff:ff:ff
    inet 192.168.4.5/24 brd 192.168.4.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 192.168.4.100/32 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::14cb:13bf:406f:c219/64 scope link 
       valid_lft forever preferred_lft forever
[root@vh05 ~]# 

[root@rootroom9pc01 cluster]# curl http://192.168.4.100/
test
[root@rootroom9pc01 cluster]# curl http://192.168.4.100/
<marquee><font size="12" color="red">LVS 2</font></marquee>
[root@rootroom9pc01 cluster]# curl http://192.168.4.100/
test

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

乐于技术分享

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值