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.www58058.com/75741