Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Using haproxy to build web Cluster

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Use haproxy to build web cluster case overview: haproxy is a popular cluster scheduling tool. In comparison, LVS has the best performance, but the construction is complex. The upstream module of Nginx supports the cluster function, but the health check function of the cluster node is not strong, and the performance is not as good as haproxy. Experimental environment: host operating system IP address main software haproxy service machine CentOS 7.3 x86_64192.168.217.128haproxy-1.5.19.tar.gzNginx server 1CentOS 7.3 x86_64192.168.217.129nginx-1.12.0.tar.gzNginx server 2CentOS 7.3 x86_64192.168.217.130nginx-1.12.0.tar.gz client Windows 7192.168.217.131IE browser configuration Nginx server: install Environment for service: yum install-y pcre-devel zlib-devel gcc gcc-c++ # pcre supports regular expression zlib web page compression install Nginx service: useradd-M-s / sbin/nologin nginx # create a program to manage Nginx user tar zxvf nginx-1.12.0.tar.gz-C / opt/ # decompress cd / opt/nginx-1.12.0/./configure\ -- prefix=/usr/local/nginx\ # specify the Nginx installation path-- user=nginx\ # Administrative user-- group=nginx # Management Group make & & make install # compile and install add test home page Close the firewall: cd / usr/local/nginx/html echo "this is accp web" > test.html # newly created web page, or directly modify indexln-s / usr/local/nginx/sbin/nginx / usr/local/sbin/ # to establish a soft connection Convenient for the system to manage nginx # the environment needed to start systemctl stop firewalld.service to configure the Haproxy server installation service: yum install-y pcre-devel gcc gcc-c++ install Haproxy service: tar zxvf haproxy-1.5.19.tar.gz-C / opt/cd / opt/haproxy-1.5.19/make TARGET=linux26 # use uname-r to view the kernel For example, 2.6.18-371.el5 At this point, this parameter edits the haproxy configuration file for linux26make install: mkdir / etc/haproxy cp examples/haproxy.cfg / etc/haproxy/ # copy the configuration file to etc cd / etc/haproxy/vim haproxy.cfgchroot / usr/share/haproxy # Delete and change the root directory redispatch # delete mandatory will request Send to the down-dropped server listen webcluster 0.0.0.0 option httpchk GET 80 # listens for all addresses on port 80 option httpchk GET / test.html # check the server's test.html file balance roundrobin # load balancer uses polling algorithm server inst1 192.168.217.129 option httpchk GET 80 check inter 2000 fall 3 # points to server server inst2 192.168.217.130 80 check inter 2000 fall 3 start the haproxy service: cp / opt/haproxy-1.5.19/examples/haproxy.init / etc/init.d/haproxy # replication startup script chmod + x haproxychkconfig-- add / etc/init.d/haproxy # add service, You can also set self-boot ln-s / usr/local/sbin/haproxy / usr/sbin/haproxy # to establish a soft connection Convenient for system management service haproxy start # enable service Haproxy log management: (log is output to syslog by default, it is not very convenient to view) vim / etc/haproxy/haproxy.cfg # modify log / dev/log local0 info log / dev/log local0 notice / / put these two lines of configuration into the global configuration project of haproxy Mainly, the info and notice logs of haproxy are recorded in different log files. Service haproxy restart # restart service touch / etc/rsyslog.d/haproxy.conf # define haproxy-related configuration independently to haproxy.conf vim / etc/rsyslog.d/haproxy.confif ($programname = = 'haproxy' and $syslogseverity-text = =' info') then-/ var/log/haproxy/haproxy-info.log&~ # access date Log location if ($programname = = 'haproxy' and $syslogseverity-text = =' notice') then-/ var/log/haproxy/haproxy-notice.log&~ # advertise log location systemctl restart rsyslog.service test open client access 192.168.217.128/test.html Refresh the page to see if the two pages appear in turn.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report