-

Linux下部署LVS(NAT)+keepalived

Linux

LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统。keepalives主要用作RealServer的健康状态检查以及LoadBalance主机和BackUP主机之间failover的实现。我们完全可以用这两个免费软件配合实现网站高性能高可用负载均衡。

director(高可用引导服务器主从)
1、安装ipvsadm和keepalive
[cc lang=”bash”][root@CentOS-LVS ~]# yum -y install popt popt-devel libnl libnl-devel popt-static openssl-devel ipvsadm
[root@CentOS-LVS ~]# yum install keepalived
######### 将keepalived做成启动服务,方便管理##########
[root@CentOS-LVS ~]# wget http://www.keepalived.org/software/keepalived-1.2.4.tar.gz
[root@CentOS-LVS ~]# tar zxvf keepalived-1.2.4.tar.gz
[root@CentOS-LVS ~]# cd keepalived-1.2.4
[root@CentOS-LVS keepalived-1.2.4]# ./configure && make && make install
[root@CentOS-LVS ~]# cp /usr/local/etc/rc.d/init.d/keepalived /etc/init.d/
[root@CentOS-LVS ~]# cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
[root@CentOS-LVS ~]# mkdir /etc/keepalived/
[root@CentOS-LVS ~]# cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
[root@CentOS-LVS_MASTER ~]# cp /usr/local/sbin/keepalived /usr/sbin/
[root@CentOS-LVS_MASTER ~]# service keepalived start | stop[/cc]

2、开启路由转发
[cc lang=”bash”][root@CentOS-LVS ~]# vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
[root@CentOS-LVS ~]# sysctl -p[/cc]

3、配置Keepalived
[cc lang=”bash”][root@CentOS-LVS ~]# less /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
router_id LVS_MASTER #BACKUP上修改为LVS_BACKUP
}

vrrp_instance VI_1 {
state MASTER #BACKUP上修改为BACKUP
interface eth0
virtual_router_id 51
priority 100 #BACKUP上修改为80
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.0.227
}
}

vrrp_instance LAN_GATEWAY {
state MASTER #BACKUP上修改为LVS_BACKUP
interface eth1
virtual_router_id 52
priority 100 #BACKUP上修改为80
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.10.10
}
}

virtual_server 10.0.0.227 80 {
delay_loop 6
lb_algo rr
lb_kind NAT
# persistence_timeout 5
protocol TCP

real_server 192.168.10.4 80 {
weight 3
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}

real_server 192.168.10.5 80 {
weight 3
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}[/cc]
BACKUP服务器同上配置,先安装lvs再安装keepalived,然后配置/etc/keepalived/keepalived.conf,只需将批注部分改一下即可。

4、分别在2台Real Server上面设置网关
[cc lang=”bash”][root@CentOS-LVS ~]# /sbin/ifconfig lo:0 10.0.0.227 broadcast 10.0.0.227 netmask 255.255.255.255 up
[root@CentOS-LVS  ~]# echo “1” > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@CentOS-LVS ~]# echo “2” > /proc/sys/net/ipv4/conf/all/arp_announce[/cc]

5、在2台RealServer中分别配置HTTP
[cc lang=”bash” escaped=”true”][root@CentOS-LVS ~]# yum -y install httpd
[root@CentOS-LVS ~]# cd /var/www/html/
[root@CentOS-LVS html]# cat index.html
<h1>WEB1/192.168.10.4</h1>
[root@raykaeso html]# /etc/init.d/httpd start[/cc]
另一台机器配置一样,过程略。

6、分别在CentOS-LVS_MASTER、CentOS-LVS_BACKUP上执行service keepalived start启动keepalived就可实现负载均衡及高可用集群了;
[cc lang=”bash”][root@CentOS-LVS keepalived]# service keepalived start[/cc]

来源:Linux下部署LVS(NAT)+keepalived

Linux下部署LVS(NAT)+keepalived” 评论

    61o 评论:
    2019年5月10日 下午8:44

    哇塞,居然是沙发?留个名

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注