, exchanging, adding, modifying, or deleting specified content in a request or response, this operation is based on specific rules.
I use haproxy mainly because it has the following advantages:
I,Free open-source, stability is also very good, this can be seen through some of my small projects, a single haproxy also runs well, stability can be comparable to LVS;
II,According to the official documentation,
# connection timeoutTimeout client 30000 ms # client timeoutTimeout server 30000 ms # server timeout# Timeout check 2000 # Heartbeat detection timeout# Timeout http-keep-alive10s # default persistent connection timeout# Timeout http-request 10 s # default http request timeout# Timeoutqueue 1 m # default queue timeoutBalance roundrobin # Set the default Load Balancing mode and polling Mode# Balance source # Set the default Load Balancing mode, similar to the nginx ip_hash# Balnace leastconn # Se
Check Port 9200 Inter 12000 RI SE 3 Fall 3 server MYSQL-PXC02 192.168.163.7:3306 Check Port 9200 Inter 12000 rise 3 Fall 3 backend stats-back mode HTTP b
Alance roundrobin stats uri/haproxy/stats stats auth Pxcstats:secret backend pxc-onenode-back mode TCP balance Leastconn Option Httpchk Server mysql-pxc01 192.168.163.6:3306 Check Port 9200 Inter 12000 Rise 3 Fall 3 server MYSQL-PXC02 192.168. 163.7:3306 Check Port 92Inter 12000 rise 3 Fall 3
7 be
rise 3 fall 5
Enable service haproxy start
4. Open the prepared web server on the backend server
Systemctl start nginx
Systemctl start php-fpm
Systemctl start mariadb
5. Test
(1) Access http: // 172.17.100.100: 1080/haproxyadmin on the webpage to go to the status monitoring page. You can control your own backend services.
(2) Two machines, not a group, can be broken down.
One backend server goes down an
used as MySQL, mail or other non-web load balancing, we often use it as a MySQL (read) load balancing;Four, with a strong monitoring server status of the page, the actual environment we combine Nagios Mail or SMS alarm, this is also I like it one of the reasons;Five, Haproxy support virtual host.
When doing a load balancing of a reverse proxy server, we usually use a nginx balanced configuration. In fact,
after each request is completedOption dontlognull # do not record Health Check log informationOption forwardfor # If the backend server needs to obtain the parameters that need to be configured for the real IP address of the client, the Client IP address can be obtained from the HTTP header.Option redispatch # After the server corresponding to the serverid fails, it is forcibly redirected to another healthy server.Retries 2 # If the connection fails twice, the service is considered unavailable.
–9 PIDView the Monitoring pageHttp://192.168.1.227/haproxy-statsSuch as: Note that the Status column shows 200, if not the Web server does not start, or the Health Check link is not accessibleTestThen open a different browser to simulate user accesshttp://192.168.1.227/login/'ll seeProof that the request was distributed to a different Web serverView CookiesThe cookie was added to the Srv=aProcess of Session
/wKiom1YEqR_DsLnqAAEKeZEJDqs390.jpg "title=" Qq20150925095517.png "alt=" Wkiom1yeqr_dslnqaaekezejdqs390.jpg "/>6. Test the client, start the website service on Web1 and WEB2, and modify the default page, Web1 page for 1.1.1.10,WEB2 is 1.1.1.20.650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/73/B1/wKioL1YEqsnxDtT-AADJjt8ZoU8255.jpg "title=" Qq20150925100219.png "alt=" Wkiol1yeqsnxdtt-aadjjt8zou8255.jpg "/>650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/73/B4/wKiom1YEqs-R2lHl
Main Standby modeProgramme IThat is also where the VIP is, Haproxy is where to start the main standby mode.[Email protected] ~]# Cat/etc/ha.d/haresources#gao services#10.0.0.103 Www.lvnian.orgMASTER ipaddr::10.0.0.103/24/ Eth0 Haproxyd [[email protected] ~]#Note the point:# #haproxy If you manage heartbeat, then the Haproxy script above must be/etc/init.d/directo
nbproc, so that the task_queue of each process will be much shorter, and the performance will naturally improve a lot# Pidfile/var/run/haproxy-private.pid
defaults log global mode http optionhttplog optiondontlognull log 127.0.0.1 local3 retries 3 option redispatch maxconn 2000 contimeout 5000 clitimeout 50000 srvtimeout 50000
Listen webfarm 0.0.0.0: 80Mode HTTPStats uri/haproxy-Stats # moni
Haproxy achieves load balancing and dynamic/static Separation
After haprxy Server Load balancer and dynamic/static separation, haproxy is more professional in these two aspects than nginx, including session persistence, cookie guidance, and url monitoring backend, mysql Server Load balancer is not available in nginx, but it cannot be said that haprox can replace
// set up monitoring and control directory just name it.Contimeout//Connection time- outClitimeout 50000// Client connection time-outSrvtimeout 50000// server-side connection time-outListen Websrv-rewrite 0.0.0.0:80//Listening address, can write Haproxy address, can also be written as 0.0.0.0, listen to all local addressesCookie ServerID RewriteBalance Roundrobin Load Balancing MethodServer App1_1 192.168.2
1.HAProxy Introduction
Haproxy is an open-source, high-performance, load-balancing software based on TCP (four-tier), HTTP (seven-tier) applications. That haproxy as a professional load balancer software, it has the following advantages:
Very good reliability and stability, comparable to hardware-level F5 load balancing devices
. Up to 40000-50000 concurrent conn
Haproxy is a powerful, flexible and easy to use reverse proxy software, provides a high-availability, load-balanced, back-end server Agent functions, it is in the 7-tier load balancing function is very powerful (support cookie track, header rewrite, etc.), support dual-machine hot standby, support virtual host , has a very good server health check function, when its agent's back-end server failure, Haproxy
load balancer device uses TCP buffering to establish extremely long requests and has a large response time.Haproxy Advantages1, Haproxy can be used as MySQL, mail or other non-web load balancer, we often use it as MySQL (read) load balancing;2, with a powerful monitoring server status of the page;3, Haproxy support virtual host;4,
advantage is not the other load balancerD, Haproxy support full transparent proxy (already have the typical characteristics of hardware firewall)E, Haproxy now more than the online MySQL cluster environment, we often use it as MySQL (read) load balancerF, with powerful monitoring server status of the page, in real-world we combine nagios for mail or SMS alarmExp
; index.html -------------> the is web2
Background monitoring management:
When the web1 server is disconnected:
When the web1 server is restored:
################################# Some tests have been completed ### ###################
Vi. Log Configuration:
######### Add the following statement #########
Vi/etc/syslog. confLocal3. */var/log/haproxy. logLocal0. */var/log/
maxconn20 #默认的最大连接数 statsenable #启用状态监控 statsrefresh30s #监控页面自动刷新时间 statsuri/haproxy_ status #监控页面url statsauth admin:123456 #设置监控页面的用户名和密码, you can set multiple usernames statshide-version# Hide Haproxy version information on the monitoring page listenwebsites bind192.168.100.121:80# Bind to port 80 on 192.168.100.121 timeoutserver 15stimeoutconnect30sserver Mylinux3192.168.100.181:80checkport80inter2
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.