(一)設計思路php
高可用:keepalived 解決方案node
負載均衡:(lvs)DR作輪詢,須要一個調度器,後端節點兩個(部署nginx動態博客),經過一個vip去訪問動態博客nginx
後端節點須要部署動態博客做爲資源供客戶訪問。docker
調度器作keepalived(dr),給調度器作一個備節點,讓他倆互爲主備,避免資源浪費。後端
這樣的話就須要四臺物理機,兩臺主備調度器,兩臺realserver。瀏覽器
(二)部署過程架構
(1)調度器上的部署負載均衡
1. 兩臺調度器下載keepalived:oop
yum install -y keepalived
2.編輯配置文件,讓兩臺調度器互爲主備測試
[root@node1 keepalived]# cat /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { notification_email { # acassen@firewall.loc # failover@firewall.loc # sysadmin@firewall.loc } # notification_email_from Alexandre.Cassen@firewall.loc # smtp_server 192.168.200.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 MASTER interface ens33 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.42.200 } } vrrp_instance VI_2 { state BACKUP interface ens33 virtual_router_id 52 priority 99 advert_int 1 authentication { auth_type PASS auth_pass 2222 } virtual_ipaddress { 192.168.42.100 } } virtual_server 192.168.42.200 80 { delay_loop 6 lb_algo rr lb_kind DR protocol TCP real_server 192.168.42.172 80 { weight 1 HTTP_GET { url { path /
state_code 200 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } } virtual_server 192.168.42.200 80 { delay_loop 6 lb_algo rr lb_kind DR protocol TCP real_server 192.168.42.173 80 { weight 1 HTTP_GET { url { path / state_code 200 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } }
[root@node2 ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
# acassen@firewall.loc
# failover@firewall.loc
# sysadmin@firewall.loc
}
# notification_email_from Alexandre.Cassen@firewall.loc
# smtp_server 192.168.200.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 ens33
virtual_router_id 51
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.42.200
}
}
vrrp_instance VI_2 {
state MASTER
interface ens33
virtual_router_id 52
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 2222
}
virtual_ipaddress {
192.168.42.100
}
}
virtual_server 192.168.42.200 80 {
delay_loop 6
lb_algo rr
lb_kind DR
protocol TCP
real_server 192.168.42.172 80 {
weight 1
HTTP_GET {
url {
path /
state_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
virtual_server 192.168.42.200 80 {
delay_loop 6
lb_algo rr
lb_kind DR
protocol TCP
real_server 192.168.42.173 80 {
weight 1
HTTP_GET {
url {
path /
state_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
3.調度器重啓keepalived(能夠作個測試,查看vip的遷移)
systemctl restart keepalived
(2)realserver部署
1. realserver部署DR
[root@node3 ~]# cd /proc/sys/net/ipv4/conf/ [root@node3 conf]# ls all calib2dc35d78a1 docker0 lo cali748bf682dd1 calib6602a4140d ens33 tunl0 cali8e151c6d769 default flannel.1 [root@node3 conf]# cd all [root@node3 all]# ls accept_local disable_policy proxy_arp_pvlan accept_redirects disable_xfrm route_localnet accept_source_route force_igmp_version rp_filter arp_accept forwarding secure_redirects arp_announce log_martians send_redirects arp_filter mc_forwarding shared_media arp_ignore medium_id src_valid_mark arp_notify promote_secondaries tag bootp_relay proxy_arp [root@node3 all]# echo 1 > arp_ignore [root@node3 all]# echo 2 > arp_announce [root@node3 all]# cd .. [root@node3 conf]# ls all calib2dc35d78a1 docker0 lo cali748bf682dd1 calib6602a4140d ens33 tunl0 cali8e151c6d769 default flannel.1 [root@node3 conf]# cd lo [root@node3 lo]# ls accept_local disable_policy proxy_arp_pvlan accept_redirects disable_xfrm route_localnet accept_source_route force_igmp_version rp_filter arp_accept forwarding secure_redirects arp_announce log_martians send_redirects arp_filter mc_forwarding shared_media arp_ignore medium_id src_valid_mark arp_notify promote_secondaries tag bootp_relay proxy_arp [root@node3 lo]# echo 2 > arp_announce [root@node3 lo]# echo 1 > arp_ignore [root@node3 lo]# ifconfig ens33:0 192.168.42.200/32 broadcast 192.168.42.200 up [root@node3 lo]# route add -host 192.168.42.200 dev ens33:0[root@node3 lo]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.42.200 0.0.0.0 255.255.255.255 UH 0 0 0 ens33
2. 部署LNMP架構上線動態博客(上一篇博客有就再也不贅述了)
(3)瀏覽器訪問vip:
http://192.168.42.200/wp-admin/install.php