Keepalived It is a high availability scheme for Web services based on the VRRP protocol, which can be used to avoid single points of failure. A Web service will have at least 2 servers running keepalived, one master server (master), one backup server (standby), but external as a virtual IP, and the primary server sends a specific message to the backup server. When the backup server does not receive the message, that is, when the primary server goes down, the backup server takes over the virtual IP and continues to serve, guaranteeing high availability.
Nginx installation in my previous blog has been written, here will not repeat.
And then it's installing keepalived?
Command: wget? Http://www.keepalived.org/software/keepalived-1.1.20.tar.gz
Choose the keepalived download that suits your version as needed.
Decompression: tar-zxvf/root/keepalived-1.2.19.tar.gz (fill in the download path according to your own)
cd/root/keepalived-1.2.19 into the extracted file. Have an executable file for configure?
Create a new keepalived folder under the/usr/local file
Mkdir/usr/local/keepalived?
? then run./configure--prefix=/usr/local/keepalived
Here with Nginx to load balance without LVS to load so do not take care of this line.
Make&&make install? After the installation is complete, four folders are generated under/usr/local/keepalived to indicate that the installation was successful.
This is the directory structure of the/usr/local/keepalived folder
Execute the following commands after installation to facilitate later management
Mkdir/etc/?keepalived
- ? ln-s/usr/local/sbin/keepalived/usr/sbin/or
- ? cp/usr/local/keepalived/sbin/keepalived/usr/sbin
Cp/usr/local/keepalived/etc/sysconfig/keepalived/etc/sysconfig
cp/usr/local/keepalived/etc/rc.d/init.d/keepalived/etc/rc.d/init.d/
cp/usr/local/keepalived/etc/keepalived/keepalived.conf/etc/keepalived/
Start Keepalived:service keepalived Start
Keepalived Dual master Configuration
? Master: Real ip192.168.110.134 vip192.168.110.80
Ip192.168.110.135: True vip192.168.110.90
Main:
Vrrp_instance Vi_1 {
State MASTER//defined as Primary server
interface Eth0//VIP-bound NIC
VIRTUAL_ROUTER_ID 51//Virtual route ID, master and slave must be consistent
Priority 100//precedence, random value but the master server must be larger than the server
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
virtual_ipaddress {
192.168.110.80//Bound virtual IP
}
}
Vrrp_instance Vi_2 {
State BACKUP//defined as Slave server
interface Eth0//VIP-bound NIC
VIRTUAL_ROUTER_ID 52//Virtual route ID, master and slave must be consistent
Priority 90//precedence, random value but the master server must be larger than the server
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
virtual_ipaddress{
192.168.110.90//Bind VIP
}
}
? Configure play restart Keepalived:service keepalived restart
? IP Addr View
Preparation:?
? vrrp_instance vi_1 {
State BACKUP
Interface eth0
VIRTUAL_ROUTER_ID 51
Priority 90
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
virtual_ipaddress {
192.168.110.80
}
}
Vrrp_instance Vi_2 {
State MASTER
Interface eth0
VIRTUAL_ROUTER_ID 52
Priority 100
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
virtual_ipaddress{
192.168.110.90
}
}
Test: When the primary server is working, it is easy to verify the difference
The primary server shuts down or the service process dies and immediately switches the standby server, the switch time does not feel.
Load Balancing:
The upstream default is a poll-based load balancing method, in which each request is assigned to a different backend server in chronological order, and can be automatically rejected if the backend server is down. Another way is Ip_hash: Each request is allocated according to the hash result of the access IP, so that each visitor fixed access to a back-end server can solve the session problem.
? Each primary server is configured as follows
Vi/etc/nginx/nginx.conf
? upstream Test {
Server 127.0.0.1 down; Local server does not participate in load
Server 192.168.110.136:80 weight=5; Background server
Server 192.168.110.137:80 weight=5;//Background server
#ip_hash;
}
? location/{
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Proxy_pass http://test;
root/usr/share/nginx/html;
Index index.html index.htm;
}
Success!
This is my own installation after the tutorial because of the new contact architecture, many of which are smattering explained enough detail!??
Keepalived+nginx+upstream-based dual master hot swap + load Balancing implementation scheme