当前位置:网站首页>Hapoxy cluster service setup
Hapoxy cluster service setup
2022-06-23 17:26:00 【User 7353950】
Hapoxy colony
1. Hapoxy brief introduction
HAProxy It's a use C Free and open source software written in language [1], It provides high availability 、 Load balancing , And based on TCP and HTTP Application proxy for .
HAProxy Especially suitable for those with heavy load web Site , These sites usually need session persistence or seven layers of processing .HAProxy Running on the current hardware , It can support tens of thousands of concurrent connections . And its running mode makes it easy and safe to integrate into your current architecture , And protect your web The server is not exposed to the network .
HAProxy Implemented an event driven , Single process model , This model supports a very large number of concurrent connections . The multiprocess or multithreaded model is limited by memory 、 System scheduler restrictions and ubiquitous lock restrictions , Rarely handle thousands of concurrent connections . Event driven model because of better resource and time management of user space (User-Space) Achieve all of these tasks , So there are no such problems . The disadvantage of this model is , On a multicore system , These programs usually have poor scalability . That's why they have to optimize to Make each CPU Time slice (Cycle) Do more work .
Include GitHub、Bitbucket[3]、Stack Overflow[4]、Reddit、Tumblr、Twitter5 and Tuenti[7] Famous websites inside , And Amazon Web services HAProxy.
haproxy_ Baidu Encyclopedia (baidu.com)
2. Haproxy The construction of clusters
2.1 Environment configuration
Service configuration | ip |
|---|---|
Haproxy | 192.168.80.20 |
web The server 1 | 192.168.80.30 |
web The server 2 | 192.168.80.35 |
2.2 The configuration process
1. Turn off firewall , And transmit compressed packets
systemctl stop firewalld
setenforce 0
haproxy-1.5.19.tar.gz2. Compilation and installation Haproxy
yum install -y pcre-devel bzip2-devel gcc gcc-c++ make
tar zxvf haproxy-1.5.19.tar.gzcd haproxy-1.5.19/
make TARGET=linux2628 ARCH=x86_64
make install3.Haproxy Server configuration
mkdir /etc/haproxy
cp examples/haproxy.cfg /etc/haproxy/
cd /etc/haproxy/
vim haproxy.cfg
_______________________________
global
--4~5 That's ok -- modify , Configure logging ,local0 For log devices , It is stored in the system log by default
log /dev/log local0 info
log /dev/log local0 notice
#log loghost local0 info
maxconn 4096 # maximum connection , Need to consider ulimit -n Limit
--8 That's ok -- notes ,chroot Running path , Self set root directory for the service , Generally, this line needs to be commented out
#chroot /usr/share/haproxy
uid 99 # user UID
gid 99 # user GID
daemon # Daemons mode
defaults
log global # Define the log as global Log definition in configuration
mode http # The model is http
option httplog # use http Log format log
option dontlognull # Do not record health check log information
retries 3 # Check node server failures , Three consecutive failures , The node is considered unavailable
redispatch # When the server load is high , Automatically end connections that have been queued for a long time
maxconn 2000 # maximum connection
contimeout 5000 # Connection timeout
clitimeout 50000 # Client timeout
srvtimeout 50000 # Server timeout
-- Delete all below listen term --, add to
listen webcluster 0.0.0.0:80 # Define a name webcluster Application
option httpchk GET /index.html # Check the... Of the server test.html file
balance roundrobin # The load balancing scheduling algorithm uses the polling algorithm roundrobin
server inst1 192.168.80.30:80 check inter 2000 fall 3 # Define online nodes
server inst2 192.168.80.35:80 check inter 2000 fall 34. Add system services
cp /opt/haproxy-1.5.19/examples/haproxy.init /etc/init.d/haproxycd /etc/init.dchmod +x haproxy
chkconfig --add /etc/init.d/haproxyln -s /usr/local/sbin/haproxy /usr/sbin/haproxy
service haproxy start or /etc/init.d/haproxy start2.3 Configuration screenshot
2.3.1haproxy Server configuration
2.3.2 Web Server node configuration
————————————————————————————192.168.80.30 To configure echo "this is WEB SERVER11111" > /var/www/html/index.html
systemctl start httpd
————————————————————————————192.168.80.35 To configure echo "this is WEB SERVER22222" > /var/www/html/index.html
systemctl start httpd2.3.3 Client access test
3. Haproxy Cluster log redefinition
haproxy The log of is output to the system by default syslog in , In the previous step, the logs have been defined in /dev/log in , Pictured
Need modification rsyslog To configure , For ease of management . take haproxy The relevant configuration is defined independently to haproxy.conf, And on the /etc/rsyslog.d/ Next ,rsyslog All configuration files in this directory will be loaded automatically at startup .
## This part of the configuration will haproxy Of info The log goes to /var/log/haproxy/haproxy-info.log Next , take notice The log goes to /var/log/haproxy/haproxy-notice.log Next .“&~” Indicates that after the log is written to the log file ,rsyslog Stop processing this message .vim /etc/rsyslog.d/haproxy.conf
___________________________________________
if ($programname == 'haproxy' and $syslogseverity-text == 'info')
then -/var/log/haproxy/haproxy-info.log
&~
if ($programname == 'haproxy' and $syslogseverity-text == 'notice')
then -/var/log/haproxy/haproxy-notice.logmkdir /var/log/haproxy/
systemctl restart rsyslog.service
tail -f /var/log/haproxy/haproxy-info.log # see haproxy Access request log information for 3.1 The operation screenshot
be based on 2 The operation of
1. modify rsyslog To configure
2. establish /var/log/haproxy/ Directory and restart the service
3. Use client access web service .
4. Review the log generation again
4. Comparison of several load balancing implementations (Nginx-LVS-Haproxy)
4.1 Nginx
Nginx The advantages of :
- Working on the Internet 7 Layer above , Can target http Apply some diversion strategies , For example for domain names 、 Directory structure .Nginx Regular rules are better than HAProxy More powerful and flexible .
- Nginx The dependence on network stability is very small , Theoretically, it can ping The load function can be carried out through ,LVS It depends on the stability of the network , Stability is relatively high .
- Nginx install and configure 、 The test is simple 、 convenient , There are clear logs for investigation and management ,LVS Configuration of 、 The test will take a long time .
- Can bear high load pressure and stable , It can support tens of thousands of concurrent times , Load ratio LVS Relatively small .
- Nginx The internal fault of the server can be detected through the port , For example, according to the server processing the status code returned by the web page 、 Timeout and so on .
- Nginx It's not just a good load balancer / Reverse agent software , It's also powerful Web application server .
- Nginx As Web Reverse acceleration caching is becoming more and more mature , Faster than the traditional Squid The server is faster , It is used as a reverse proxy accelerator in many scenarios .
- Nginx As a static web page and image server , The performance in this area is excellent , At the same time, there are many third-party modules .
Nginx The shortcomings of :
- Nginx Only supported http、https and Email agreement , In this way, the scope of application is smaller .
- Health check for back-end servers , Only through the port to detect , No support for passing url To detect .
- I won't support it Session Keep it straight , Need to pass through ip_hash and cookie Guide to solve .
4.2 LVS
LVS The advantages of :
- Strong resistance to load 、 It is work in the network 4 Above the layer for distribution only , There is no flow . So the best performance in load balancing software , The memory and cpu Resource consumption is relatively low .
- LVS Stable work , Because of its strong anti load ability , It has a complete hot standby scheme .
- No flow ,LVS Distribute requests only , And traffic doesn't go out of itself , This guarantees the equalizer IO The performance of will not be affected by large traffic .
- It has a wide range of applications , because LVS Working in 4 layer , So it can do load balancing for almost all applications , Include http、 Database etc. .
LVS The shortcomings of :
- The software itself does not support regular expression processing , We can't separate the static from the dynamic . relatively speaking ,Nginx/HAProxy+Keepalived It has obvious advantages .
- If the website application is relatively large ,LVS/DR+Keepalived It's more complicated to implement . relatively speaking ,Nginx/HAProxy+Keepalived It's much simpler .
4.3 HAProxy
HAProxy The advantages of :
- HAProxy It also supports virtual hosts .
- HAProxy Support 8 Load balancing strategies .
- HAProxy The advantages of can complement Nginx Some shortcomings of , Such as support Session To keep ,Cookie The boot , At the same time, it supports obtaining the specified url To detect the state of the back-end server .
- HAProxy Follow LVS similar , It's just a load balancing software , In terms of pure efficiency HAProxy than Nginx Better load balancing speed , It is also superior in concurrent processing Nginx Of .
- HAProxy Support TCP Load balanced forwarding of protocol .
边栏推荐
猜你喜欢

Another breakthrough! Alibaba cloud enters the Gartner cloud AI developer service Challenger quadrant

Practice sharing of chaos engineering in stability management of cloud native Middleware

使用Jmeter进行性能测试及性能监控平台搭建

Opengauss database source code analysis series articles -- detailed explanation of dense equivalent query technology (Part 2)

Importance and purpose of test

Mathematical analysis_ Certification_ Chapter 1: the union of countable sets is countable

EasyPlayer移动端播放webrtc协议时长按播放页面无法关闭“关于我们”页面

【网络通信 -- WebRTC】WebRTC 源码分析 -- 接收端带宽估计

Robot Orientation and some misunderstandings in major selection in college entrance examination

时间戳90K是什么意思?
随机推荐
The official Chinese course of zero foundation introduction jetpack compose is coming
Freemark uses FTL files to generate word
浅谈5类过零检测电路
Three minutes to learn how to retrieve the MySQL password
Get first and last days by year
Importance and purpose of test
官方零基础入门 Jetpack Compose 的中文课程来啦
测试的重要性及目的
How to use SQL window functions
AMQP协议
A number of individual stocks in Hong Kong stocks performed actively, triggering investors' speculation and concern about the recovery of the Hong Kong stock market
什么是抽象类?怎样定义抽象类?
QT layout manager [qvboxlayout, qhboxlayout, qgridlayout]
你的PCB地线走的对吗?为什么要有主地?
谈谈redis缓存击穿透和缓存击穿的区别,以及它们所引起的雪崩效应
记录——kubeadm集群node节点加入
The evolution of social structure and capital system brought about by the yuan universe
相机电源受干扰案例分析,严重影响画质
mysql-选择使用Repeatable read的原因
Digital twin excavator of Tupu software realizes remote control