标签:次数 oop ns3 art 指定 vrrp 成功 conf init.d
Centos7 LVS+keepalived+httpd高可用集群> 环境:
主keepalived服务器:192.168.80.100
从keepalived服务器: 192.168.80.101Web服务器:192.168.80.102
192.168.80.103windows操作系统 :192.168.80.20
加载LVS内核模块,并安装
modprobe ip_vs ---加载ip_vs模块
yum install ipvsadm -y ---安装 ipvsadm
源码安装keepalived:
安装插件和编译软件。yum -y install gcc gcc-c++ make popt-devel kernel-devel openssl-devel
安装上传软件,把软件包从windows系统上传到Centos上去。yum install lrz* -y
把软件包解压到 /opt,编译并安装
tar xf keepalived-1.4.2.tar.gz -C /opt ---解压软件包到/opt
cd /opt/keepalived-1.4.2/ ---切换到解压目录里
./configure --prefix=/
make && make install ----编译并且安装
cp keepalived/etc/init.d/keepalived /etc/init.d/ ---加入系统管理服务
在主服务器上修改配置文件vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_01 //本服务器的名称
}
vrrp_instance VI_1 { //定义VRRP热备实例
state MASTER //热备状态,MASTER表示主服务器,BACKUP表示从服务器
interface ens32 //承载VIP地址的物理接口
virtual_router_id 51 //虚拟路由器的ID号,每个热备组保持一致
priority 110 //优先级,数值越大优先级越高
advert_int 1 //通告间隔秒数(心跳频率)
authentication { //热备认证信息,每个热备组保持一致
auth_type PASS //认证类型
auth_pass 6666 //密码字符串
}
virtual_ipaddress { //指定漂移地址(VIP),可以有多个
192.168.80.188
}
}
virtual_server 192.168.80.188 80 { //虚拟服务器地址(VIP)、端口
delay_loop 6 //健康检查的间隔时间(秒)
lb_algo rr //轮询(rr)调度算法
lb_kind DR //直接路由(DR)群集工作模式
persistence_timeout 60 //连接保持时间(秒)
protocol TCP //应用服务器采用的是TCP协议
real_server 192.168.80.102 80 { //第一个Web服务器节点的地址、端口
weight 1 //节点的权重
TCP_CHECK { //健康检查方式
connect_port 80 //检查的目标端口
connect_timeout 3 //连接超时(秒)
nb_get_retry 3 //重试次数
delay_before_retry 3 //重试间隔
}
}
real_server 192.168.80.103 80 { //第二个Web服务器节点的地址、端口
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
service keepalived start ---启动 keepalived
ip addr show dev ens32 ---查看ens32地址
ipvsadm –Ln //查看LVS虚拟服务器
配置从keepalived服务器:
加载LVS内核模块,并安装
modprobe ip_vs ---加载ip_vs模块
yum install ipvsadm -y ---安装 ipvsadm
源码安装keepalived:
安装插件和编译软件。yum -y install gcc gcc-c++ make popt-devel kernel-devel openssl-devel
安装上传软件,把软件包从windows系统上传到Centos上去。yum install lrz* -y
把软件包解压到 /opt,编译并安装
tar xf keepalived-1.4.2.tar.gz -C /opt ---解压软件包到/opt
cd /opt/keepalived-1.4.2/ ---切换到解压目录里
./configure --prefix=/
make && make install ----编译并且安装
cp keepalived/etc/init.d/keepalived /etc/init.d/ ---加入系统管理服务
vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_02
}
vrrp_instance VI_1 {
state BACKUP
interface ens32
virtual_router_id 51
priority 105
advert_int 1
authentication {
auth_type PASS
auth_pass 6666
}
virtual_ipaddress {
192.168.80.188
}
}
virtual_server 192.168.80.188 80 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.168.80.102 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.80.103 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
service keepalived start ---启动 keepalived
ipvsadm –Ln ---//查看LVS虚拟服务器
配置web节点服务器
第一台web节点:yum install -y httpd ---安装httpd
vi /etc/httpd/conf/httpd.conf ---修改主配置文件
ServerName www.example.com:80 --- 查到此内容,并把前面的注释符合删除
cd /var/www/html/ ---切换到网页根目录
echo "<h1>SERVER AA</h1>" > index.html ---把SERVER AA写入到index.html,同于创建一个index.html
```
service httpd start ---启动http服务
` vi web.sh ---创建一个shell脚本,添加以下内容`
#!/bin/bash
#haha
ifconfig lo:0 192.168.80.188 broadcast 192.168.80.188 netmask 255.255.255.255 up
route add -host 192.168.80.188 dev lo:0
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
sysctl -p &>/dev/null
`sh web.sh ---执行脚本`
`ifconfig ---查看网卡信息`
![](https://s1.51cto.com/images/blog/201901/09/52f207e6a074b5751671cf4878fef7ff.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
第二台web服务器:
` yum install -y httpd ---安装httpd`
` vi /etc/httpd/conf/httpd.conf ---修改主配置文件`
`ServerName www.example.com:80 --- 查到此内容,并把前面的注释符合删除`
` cd /var/www/html/ ---切换到网页根目录`
` echo "<h1>SERVER AA</h1>" > index.html ---把SERVER AA写入到index.html,同于创建一个index.html`
service httpd start ---启动http服务
` vi web.sh ---创建一个shell脚本,添加以下内容`
#!/bin/bash
#haha
ifconfig lo:0 192.168.80.188 broadcast 192.168.80.188 netmask 255.255.255.255 up
route add -host 192.168.80.188 dev lo:0
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
sysctl -p &>/dev/null
`sh web.sh ---执行脚本`
`ifconfig ---查看网卡信息`
![](https://s1.51cto.com/images/blog/201901/09/de6d635ee0b85f4933efa814e6fb4f09.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
-----
测试LVS+Keepalived高可用群集
在客户端的浏览器中,能够通过LVS+Keepalived群集的漂移地址(192.168.80.100)正常访问web页面内容,则验证群集构建成功。
1. 验证两台Web服务器轮询工作
windows 192.168.80.188
![](https://s1.51cto.com/images/blog/201901/09/21db49a801d055829a0f6d0279b960c0.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
2. 模拟主调度器故障,验证结果
systemctl stop keepalived
//主调度器keepalived停止工作
![](https://s1.51cto.com/images/blog/201901/09/6138185b732211e39e731b377deaae5e.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
![](https://s1.51cto.com/images/blog/201901/09/796145b5c01ed1fa07f4baee198fc83f.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
3、模拟Web服务器aa故障
`service httpd stop ---关闭web服务`
![](https://s1.51cto.com/images/blog/201901/09/5412a13c8a654d1b15f822f4fc237dc2.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
-----
LVS+Keepalived+httpd已成功搭建并测试完成
标签:次数 oop ns3 art 指定 vrrp 成功 conf init.d
原文地址:http://blog.51cto.com/13701082/2340851