1、双主模型的ipvs高可用
一、双主模型的ipvs高可用
1)网络结构图
2)、ipvs的类型是dr模型,调度算法是rr
RS1和RS2都是centos6.8
对RS1和RS2的配置:
(1)实现对内核参数的更改
#echo 1 >
/proc/sys/net/ipv4/conf/all/arp_ignore
#echo 2 >
/proc/sys/net/ipv4/conf/all/arp_announce
#ifconfig lo:0
172.18.52.10/32 broadcast 172.18.52.10 up
#ifconfig lo:1
172.18.52.20/32 broadcast 172.18.52.20 up
(2)安装httpd的web服务
#yum install httpd –y
在RS1主机上
#echo “This test web1 server” >
/var/www/html/index.html
在RS2主机上
#echo “This test web2 server” >
/var/www/html/index.html
(3)启动httpd服务
#service httpd start
(4)配置dir1和dir2主机
安装keepalived
#yum install keepalived –y
对keepalived的配置文件修改
#vim /etc/keepalived/keepalived.conf
——————–以下是配置文件的内容——————–
! Configuration File for keepalived
global_defs {
notification_email { #向谁发送通知
root@localhost
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id www.zorro.org #可以随意修改
vrrp_mcast_group4
224.18.52.2 #发送多播的地址,建议修改免得和别人冲突
}
#建立两个实例分别对应两个集群服务,但是都是指向后端的80web服务
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 199
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 3344520
}
virtual_ipaddress {
172.18.52.10
}
vrrp_instance VI_2 {
state BACKUP
interface eth0
virtual_router_id 200
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 3344521
}
virtual_ipaddress {
172.18.52.20
}
}
}
———-使用ipvs的相关配置—————————
———–VIP1的ipvs设置———————————-
virtual_server 172.18.52.10 80 {
delay_loop 6
lb_algo
rr
lb_kind DR
nat_mask 255.255.255.255
persistence_timeout 0
protocol TCP
real_server 172.18.52.3 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server
172.18.52.4 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
—————–VIP2的ipvs设置————————————–
virtual_server 172.18.52.20 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.255
persistence_timeout 0
protocol TCP
real_server 172.18.52.3 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server
172.18.52.4 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
二、双主模型的nginx
proxy高可用集群
1)网络拓扑
2)后端的RS1和RS2都是httpd服务,去lo:0的别名设置
取消内核参数的设置,都设置为0
3)在前端的dir1和dir2停止keeplaived服务
#service stop keeplaived
4)安装nginx
#yum install nginx –y
5)设置nginx的配置文件/etc/nginx/nginx.conf
在http字段中添加两个
Upstream webserver1 {
Server 172.18.52.3;
Server 172.18.52.4;
}
Upstream webserver2 {
Server 172.18.52.3;
Server 172.18.52.4;
}
在server字段”location /”中添加
Server {
Listen 80;
Location / {
Proxy_pass http://webserver1;
}
}
Server {
Listen 80;
Location / {
Proxy_pass http://webserver2;
}
}
关于第二个部分对于nginx的双主模型的设计比较粗糙,如果有更好的方法,请不吝赐教。
原创文章,作者:luoxz,如若转载,请注明出处:http://www.178linux.com/75741