HAProxy+Keepalived高可用性Webクラスタの構築
環境準備
1)パッケージのインストール
プライマリサーバ9このマシンはip a sコマンドによりeth 0ポートに仮想IPがあり、サーバからこの仮想IPがないことを見ることができる.プライマリ・サーバのkeepalivedサービスがアナログ・サーバのダウンタイムを停止した後、別のサーバからこの仮想IPが検出された場合、以下で負荷分散を検証できます.
web1:192.168.1.11 web2:192.168.1.12
HAProxy1:192.168.1.9 HAProxy2:192.168.1.10
最初のエージェントサーバを構築するhaproxyとkeepalived1)パッケージのインストール
yum -y install haproxy keepalived
2)haproxyプロファイルの変更(2台の同理操作)vim /etc/haproxy/haproxy.cfg
,
listen wordpress *:80
balance roundrobin
server web1 192.168.1.11:80 check inter 2000 rise 2 fall 3
server web2 192.168.1.12:80 check inter 2000 rise 2 fall 3
3)サービスを起動し、起動時の自己起動を設定するsystemctl start haproxy
systemctl enable haproxy
4)プライマリサーバkeepalivedのプロファイルの変更vim /etc/keepalived/keepalived.conf
global_defs {
notification_email {
[email protected] # , profix, ,
[email protected]
[email protected]
}
notification_email_from [email protected] #
vrrp_iptables
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_iptables // ,
}
vrrp_instance VI_1 {
state MASTER # , master
interface eth0
virtual_router_id 51
priority 100 #
advert_int 1
authentication {
auth_type PASS
auth_pass 1111 # ( )
}
virtual_ipaddress {
192.168.1.100 # ip, vip( )
}
}
5)サーバからのkeepalivedプロファイルの変更vim /etc/keepalived/keepalived.conf
global_defs {
notification_email {
[email protected] # , profix, ,
[email protected]
[email protected]
}
notification_email_from [email protected] #
vrrp_iptables
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_iptables // ,
}
vrrp_instance VI_1 {
state BACKUP # , BACKUP
interface eth0
virtual_router_id 51
priority 50 #
advert_int 1
authentication {
auth_type PASS
auth_pass 1111 #
}
virtual_ipaddress {
192.168.1.100 # ip, vip( )
}
}
6)Keepalivedサービスの起動systemctl start keepalved
systemctl enable keepalived
検証#ケンショウ#プライマリサーバ9このマシンはip a sコマンドによりeth 0ポートに仮想IPがあり、サーバからこの仮想IPがないことを見ることができる.プライマリ・サーバのkeepalivedサービスがアナログ・サーバのダウンタイムを停止した後、別のサーバからこの仮想IPが検出された場合、以下で負荷分散を検証できます.
curl http://192.168.1.100
何度もアクセスすると自分で設定したウェブページポーリング方式が見えて負荷均衡を実現したウェブサーバの構築は書かない