Keepalived + haproxy-deploy high-availability server Load balancer and keepalivedhaproxy-
Environment:
Prepare two machines,Install haproxyAnd keepaliveThey are all the same, but the configuration is different.
Here we only describe how to install haproxy on one server.And keepalive.
==============================================
1. keepalivedInstall configurations
Mkidr/application/tool-p
Cd/application/tool
Wget http://www.keepalived.org/software/keepalived-1.1.19.tar.gz
Yum-y install popt-devel
Uname-a; filter and view the connotation version
Ln-s/usr/src/kernels/2/6.32... /Usr/src/linux
Tar xf keepalived-1.1.19.tar.gz
Cd keepalived-1.1.19
./Configure -- sysconf =/etc
Cp/usr/local/sbin/keepalived/usr/bin/
# Vim/etc/keepalived. conf
===== The configuration is as follows ===
! Configuration File for keepalived
Global_defs {
Smtp_connect_timeout 30
Router_id LVS_1; The route_id of each machine is different;Backup Machine idDifferent
}
Vrrp_instance VI_1 {;Instance of the same face;Always on the backup machine
State MASTER;Type-based;BACKUP status: BACKUP
Interface eth0;IP address to listenInterface;Based on the actual interface of the Backup Machine
Virtual_router_id 55;Same instance;Backup Server persistence 1To
Priority 150;The higher the priority, it becomes the master state. Preferential service provision.;The priority of the slave node cannot be higher than that of the master node.
Advert_int 1;Send a message every second
Authentication {;Authentication Method for the same instance;Consistent backup
Auth_type PASS
Auth_pass 1111
}
Virtual_ipaddress {;VIPThe address of the same instance.;The standby server remains the same
192.168.0.253/24
}
}
===== End of configuration ======
#/Etc/init. d/keepalived start
# Ip add | grep 192.168.0.253;If the address is displayed, the configuration of the first master is correct.
On the backup machine, you only need to perform the same steps and perform different configurations.
Note:Add | grep 192.168.0.253 on the slave machineNo address is displayed. This is a normal phenomenon. This VIP address is available only when the master node is down.Address.
========================================================== ====
Ii. haproxyConfiguration
Mkdir/application/tool
Cd/application/tool
Wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.24.tar.gz
Tar xf haproxy-1.4.24.tar.gz
Cd haproxy-1.4.24
Make TARGET = linux26 ARCH = x86_64
Make PREFIX =/application/haproxy install
Sed-I "s # net. ipv4.ip _ forward = 0 # net. ipv4.ip _ forward = 1 # g"
Sysctl-p
Cd/application/haproxy
Mkdir-p bin conf logs var/run var/chroot
# Vim conf/haproxy. conf
==================== Configure the following ========================
Global
Chroot/application/haproxy/var/chroot; defines a security directory
Daemon; started in daemon mode
Group haproxy; users and groups
User haproxy
Log 127.0.0.1: 514 local0 warning; log Type
Pidfile/application/haproxy/var/run/haproxy. pid; pid path
Maxconn 20000; Maximum number of connections
Spread-checks 3
Nbproc 4; number of processes, specified based on the number of CPU Cores
Ults
Log global
Retries 3
Option redispatch
Contimeout 5000
Clitimeout 50000
Srvtimeout 50000
Stats enable; enable Status view project
Stats uri/admin? Status; defines the usr address
Stats auth admin: admin; user name and password
Listen pet_ebk_push; defines a listen instance.
Bind 192.168.0.253: 8080; listening address. Note that it is consistent with the keepalived VIP address.
Mode tcp; layer-4 tcp mode, port detection.
Balance roundrobin; round robin algorithm
# Option forwardfor
Timeout server 15 s
Timeout connect 15 s
Server web01 192.168.0.176: 8080 check port 8080 inter 1000 fall 1
Server web02 192.168.0.176: 8081 check port 8081 inter 1000 fall 1; when accessing the local port 192.168.0.253: 8080, this haproxy host actually helps our proxy to find the next 0.176 sub-request data for this machine, return the request result to the user. Then you can add the backend listener directly.
============ Configuration end ======================================== =
Note: the installation and configuration of the other haproxy are identical, with no difference.
The configuration of keepalived + haproxy has ended. If you want to know more, please read the relevant information. (Very powerful)