Build haproxy+keepalived high-availability clusters.
I. Overview of the case
1.haproxy is currently a popular cluster scheduling tool, is a free Cost-open source software, and has a certain security; Haproxy is more suitable for web nodes that are heavily loaded and supports tens of thousands of concurrency . There are many similar scheduling tools, such as LVS and Nginx. In comparison, LVS performance is the best, but the construction of relatively complex, Nginx upstream module support cluster function, but the cluster node health Check function is not strong, performance is not haproxy good. Haproxy primarily implements load balancing for Web clusters Haproxy official website: http://haproxy.1wt.eu/.
2. Load Balancing scheduling algorithm:
①.RR (Round Robin): Polling, assigning access requests in turn based on node weights.
②.LC (Least Connect): The minimum number of connections algorithm that allocates access requests based on the number of connections to a node, assigning connection requests to clients with the least number of connections each time. is one of the more algorithms used at present.
③.sh (source Hashing): A source-based access scheduling algorithm. Can be based on IP, cookies, such as cluster scheduling, such as IP1 first access was assigned to a site, IP2 access is assigned to the B site, then each ip1 will be assigned to a site, IP2 is assigned to the B site. If a certain amount of IP access is large, it will cause a lot of pressure on the node.
3. Case Environment:
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/8A/03/wKiom1gj58vTt7c0AAAGngECh8g526.png-wh_500x0-wm_3 -wmp_4-s_1539231999.png "title=" qq picture 20161110112113.png "alt=" Wkiom1gj58vtt7c0aaagngech8g526.png-wh_50 "/>
Second, compile and install Haproxy (here take the main Haproxy server example)
1. Install the Haproxy-enabled development kit with Yum first
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/8A/04/wKiom1gj6pSR1YoyAAAVqSm3VUY539.png-wh_500x0-wm_3 -wmp_4-s_2716620236.png "title=" qq picture 20161110113317.png "alt=" Wkiom1gj6psr1yoyaaavqsm3vuy539.png-wh_50 "/>
2: Compile and install Haproxy.
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/8A/04/wKiom1gj7JLwH3n8AAAMIKdl_PI473.png-wh_500x0-wm_3 -wmp_4-s_3869072811.png "title=" qq picture 20161110114147.png "alt=" Wkiom1gj7jlwh3n8aaamikdl_pi473.png-wh_50 "/> The Linux26 here refers to the 64-bit operating system.
3. Configuring the Haproxy Server
To manually establish the Haproxy profile directory, copy the Haproxy.cfg file to the configuration file directory you just created manually.
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/8A/04/wKiom1gj7buD7MyXAAAJJn4Ncd0390.png-wh_500x0-wm_3 -wmp_4-s_3838522332.png "title=" qq picture 20161110114637.png "Width=" "height=" "border=" 0 "hspace=" 0 "vspace=" 0 " Style= "width:600px;height:61px;" alt= "Wkiom1gj7bud7myxaaajjn4ncd0390.png-wh_50"/>
4. Modify the Haproxy configuration file
Haproxy is usually divided into three parts (global: Globally configured, defaults: Default configuration, Listen: Application module Configuration)
First modify the global configuration: 650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/8A/04/wKiom1gj84bQviEjAACpa6F-sO4169.jpg-wh_ 500x0-wm_3-wmp_4-s_142082311.jpg "title=" qq picture 20161110121130.jpg "alt=" wkiom1gj84bqviejaacpa6f-so4169.jpg-wh_50 "/ >
Next is the default configuration:
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/8A/01/wKioL1gj86vgCk-cAAAXkjdPQ_E025.png-wh_500x0-wm_3 -wmp_4-s_3195656640.png "title=" qq picture 20161110121206.png "alt=" Wkiol1gj86vgck-caaaxkjdpq_e025.png-wh_50 "/>
Finally, for the application module configuration:
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/8A/05/wKiom1gj8_jyeQbUAAAX7JiTrf4981.png-wh_500x0-wm_3 -wmp_4-s_3968121007.png "title=" qq picture 20161110121320.png "alt=" Wkiom1gj8_jyeqbuaaax7jitrf4981.png-wh_50 "/>
Save to exit.
5. Create a self-launching script
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/8A/01/wKioL1gj9OuQMMdZAAAdl3LWKFc002.png-wh_500x0-wm_3 -wmp_4-s_1654002894.png "title=" qq picture 20161110121723.png "alt=" Wkiol1gj9ouqmmdzaaadl3lwkfc002.png-wh_50 "/>
Three. Testing the Web cluster
1. Build test page 650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/8A/05/wKiom1gj923RXrGIAAAKr5s_kuA981.png-wh_ 500x0-wm_3-wmp_4-s_771027046.png "title=" qq picture 20161110122801.png "alt=" wkiom1gj923rxrgiaaakr5s_kua981.png-wh_50 "/ >
Launch Apache Service
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/8A/01/wKioL1gj93fCetpjAAAWv51xbp0870.png-wh_500x0-wm_3 -wmp_4-s_788597791.png "title=" qq picture 20161110122804.png "alt=" Wkiol1gj93fcetpjaaawv51xbp0870.png-wh_50 "/>
2. Test the page that was displayed for the first time Web1
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/8A/01/wKioL1gj-ejjfULBAAAbFxaqsCU191.png-wh_500x0-wm_3 -wmp_4-s_1546644091.png "title=" qq picture 20161110123755.png "alt=" Wkiol1gj-ejjfulbaaabfxaqscu191.png-wh_50 "/>
WEB2 page for the second time display
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/8A/05/wKiom1gj-gKhDxFYAAAabihW00M893.png-wh_500x0-wm_3 -wmp_4-s_1206844562.png "title=" qq picture 20161110123750.png "alt=" Wkiom1gj-gkhdxfyaaaabihw00m893.png-wh_50 "/>
Iv. High Availability of Haproxy
Installing support software
yum-y Install kernel-devel openssl-devel popt-devel ipvsadm
2. Compile and install keepalived and add keepalived as a system service
cd/usr/src/keepalived-1.2.13/
./configure--prefix=/--with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64/&& make && make Install
Ls-l/etc/init.d/keepalived
Chkconfig--add keepalived
3. Using keepalived to realize dual-machine hot standby
First configure the primary scheduler, the primary haproxy (/etc/keepalived/keepalived.conf)
To modify the keepalived configuration file:
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/8A/06/wKiom1gkD3fT01wRAAA4Bzr6_kU527.png-wh_500x0-wm_3 -wmp_4-s_4167930427.png "title=" qq picture 20161110141026.png "alt=" Wkiom1gkd3ft01wraaa4bzr6_ku527.png-wh_50 "/>
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/8A/06/wKiom1gkD5HQ7BEeAAAnuNPvj3k501.png-wh_500x0-wm_3 -wmp_4-s_3063660265.png "title=" qq picture 20161110141037.png "alt=" Wkiom1gkd5hq7beeaaanunpvj3k501.png-wh_50 "/>
2. Configure the Slave Scheduler
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/8A/02/wKioL1gkD8mzKEMkAAAta2GeBG8385.png-wh_500x0-wm_3 -wmp_4-s_218635770.png "title=" qq picture 20161110141204.png "alt=" Wkiol1gkd8mzkemkaaata2gebg8385.png-wh_50 "/>
3. Restart keepalived after configuration
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/8A/02/wKioL1gkETaSXQYBAAAoWNBY8Oo181.png-wh_500x0-wm_3 -wmp_4-s_182606626.png "title=" qq picture 20161110141810.png "alt=" Wkiol1gketasxqybaaaownby8oo181.png-wh_50 "/>
4. Use the client to browse the Web through the cluster. The effect is as follows:
(Change the cluster IP to 192.168.1.20 due to address conflicts)
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/8A/06/wKiom1gkGy2z2ILKAAAihhh3E5o171.png-wh_500x0-wm_3 -wmp_4-s_3749405152.png "style=" Float:none; "title=" QQ picture 20161110150000.png "alt=" Wkiom1gkgy2z2ilkaaaihhh3e5o171.png-wh_50 "/>
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/8A/06/wKiom1gkGy6zuCb4AAAzHXJuSIs197.jpg-wh_500x0-wm_3 -wmp_4-s_327793648.jpg "style=" Float:none; "title=" QQ picture 20161110150003.jpg "alt=" Wkiom1gkgy6zucb4aaazhxjusis197.jpg-wh_50 "/>
The client will still be able to access the main haproxy when the network card is disconnected.
Note: The author's knowledge is limited, I hope you will put forward valuable comments!
This article is from the "Breeze with You" blog, please be sure to keep this source http://super12138.blog.51cto.com/12190541/1871474
Build a Web cluster with Haproxy and implement dual-machine hot standby by keepalived