Note: In the lvs + keepalived high-availability solution, the master and slave nodes do not need to bind scripts, but only need a single file of keepalived to complete the cluster.
This experiment uses the rpm package installation method for ease of understanding and can bypass the tar package. The focus of this discussion is lvs + keepalived.
1.1 IPAddress Configuration:
Lvs1master 192.168.80.145 master keepalived
Lvs2 slave 192.168.80.144 backup keepalived
Realserver 192.168.80.146 web1
Realserver 192.168.80.147 web2
It is too bad to add machines in the realserver 192.168.80.149 web3 experiment)
GW 192.168.80.254 Gateway
1.2Architecture diagram:
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/0059463936-0.jpg "title =" lvs?keepalived=httpd,jpg.jpg "/>
Installation support package:
yum install openssl-devel kernel-devel
Install ipvsadm:
yum install ipvsadm
Install keepalived:
yum install keepalived
Configure the boot item:
chkconfig ipvsadm onchkconfig keepalived on
Configure keepalived:
vim /etc/keepalived/keepalived.confg
The content is as follows:
! Configuration File for detail {icationication_email {# acassen@firewall.loc # failover@firewall.loc # sysadmin@firewall.loc57674891 # 57674891@qq.com @ qq.com # contact} icationication_email_from smtp_server smtp.qq.com route 30 router_id LVS_DEVEL} vrrp_instance VI_1 {state MASTER # from direct BACKUP. Interface eth0 virtual_router_id 51 priority 100 # The master database is 100, which must be smaller than the master database, 90 advert_int 1 authentication {auth_type PASS # password verification type auth_pass 1111 # authentication password between master and slave databases, master and slave 2 must be consistent} after the virtual_ipaddress {#192.168.200.16 #192.168.200.17 #192.168.200.18 #10.0.0.100 192.168.80.148 # virtual ip vip) address, the following can continue to stack. }}# ------------------------------------ Virtual_server 192.168.80.148 80 {# virtual IP delay_loop 6 # (realserver status query every 10 seconds) lb_algo rr # (lvs algorithm) change the algorithm here to change lb_kind DR # (Direct Route) persistence_timeout 5 # (connections from the same IP address are allocated to the same realserver within 60 seconds) protocol TCP # (use the TCP protocol to check the realserver status) real_server 192.168.80.146 80 {# web end address weight 1 # (weight) TCP_CHECK {connect_timeout 10 # (no response timeout in 10 seconds) nb_get_retry 3 delay_before_retry 3 connect_port 80 # port} real_server 192.168.80.147 80 {weight 1 TCP_CHECK {connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 }}}
# There are many examples to load other services.
------------------------ Master ha configuration is completed -------------------------------------
BackupConfiguration:
Install ipvsadmAnd keepalivedIs the same
scp root@192.168.80.144:/etc/keepalived/keepalived.conf
Modify the keepalived configuration file to make it a slave ha. You only need to modify it in two places)
vim /etc/keepalived/keepalived.conf
Vrrp_instance VI_1 {state BACKUP # simply change it to BACKUP. Interface eth0 virtual_router_id 51 priority 90 # The value 100 on the master must be smaller than the master, 90 advert_int 1
Restart keepalived after setting. start ipvsadm start.
service keepalived start
---------------------- Backup ha configuration is complete -------------------------------------
WebTerminal:
vim /root/realserver.sh
#! /Bin/bash # description: Config realserver # Written by: http://kerry.blog.51cto.com # This script