In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
For more information on haproxy configuration files, please see: haproxy
The environment is as follows:
First, prepare:
1. Download haproxy software package, haproxy extraction code: 9it6
2. Web website can use Apache, Nginx or build. Here, for convenience, I directly use the httpd service of the system disk.
The construction of web website can be referred to: install web service and basic configuration based on Linux; build Nginx based on Centos 7
3. Configure firewall to release traffic
4. I use all centos 7 systems here. Note that this environment is not a production environment. If you are in a production environment, there must be back-end storage to store web pages. The web server reads the web pages on the storage server and returns them to the client. Only in this way can we ensure the consistency of the web page content.
2. Start building:
1. Configure the master server:
[root@haproxy1 /] # yum-y install pcre-devel bzip2-devel keepalived # installation related dependent packages and packages [root@haproxy1 media] # tar zxf haproxy-1.5.19.tar.gz-C / usr/src/ [root@haproxy1 media] # cd / usr/src/haproxy-1.5.19/ [root@haproxy1 haproxy-1.5.19] # make TARHET=linux26 & & make install # compilation and installation TARGET means 64-bit operating system [root@haproxy1 haproxy-1.5.19] # mkdir / etc/haproxy # create a directory for storing master files [root@haproxy1 haproxy-1.5.19] # cp examples/haproxy.cfg / etc/haproxy/ # copy the master files in the compiled package to the configuration file directory. Note: this configuration file is in the compiled package. Notice the path [root@haproxy1 /] # vim / etc/haproxy/haproxy.cfg # this config needs haproxy-1.1.28 or haproxy-1.2.1global log / dev/log local0 info log / dev/log local0 notice # log loghost local0 info maxconn 4096 # chroot / usr/share/haproxy # comment out uid 99 gid 99 daemon # debug # quietdefaults log global mode http option httplog option dontlognull retries 3 redispatch maxconn 2000 contimeout 5000 clitimeout 50000 srvtimeout 50000listen webcluster 0.0.0.0 redispatch maxconn 80 # modify the port number to 80 Webcluster is the cluster name Modifiable option httpchk GET / index.html balance roundrobin # means using polling algorithm server web1 192.168.1.20 fall 80 check inter 2000 fall 3 # two web nodes server web2 192.168.1.30 fall 80 check inter 2000 fall 3 [root@haproxy1 /] # cp / usr/src/haproxy-1.5.19 / examples/haproxy.init / etc/init.d/haproxy # replication service control script [root@haproxy1 /] # ln-s / usr/local/sbin/haproxy / usr/sbin/haproxy # create links to make commands easier to use [root@haproxy1 /] # chmod + x / etc/init.d/haproxy # add execution permissions [root@haproxy1 /] # Chkconfig-- add / etc/init.d/haproxy # added as a system service [root@haproxy1 /] # / etc/init.d/haproxy start # launch Starting haproxy (via systemctl): [OK] [root@haproxy1 /] # vim / etc/rsyslog.d/haproxy.conf # configuration log file Write the following content: 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.log& ~ [root@haproxy1 /] # systemctl restart rsyslog.service # restart the log service
Configure keepalived:
[root@haproxy1 /] # vim / etc/keepalived/keepalived.conf! Configuration File for keepalivedglobal_defs {notification_email {acassen@firewall.loc failover@firewall.loc sysadmin@firewall.loc} notification_email_from Alexandre.Cassen@firewall.loc smtp_server 192.168.200.1 smtp_connect_timeout 30 router_id LVS1 # distinguish between master and slave scheduler name} vrrp_instance VI_1 {state MASTER interface ens33 # modify the name of the network card Virtual_router_id 51 priority 100 advert_int 1 authentication {auth_type PASS auth_pass 1111} virtual_ipaddress {192.168.1.100 # fill in the drift address}} [root@haproxy1 /] # systemctl restart keepalived # restart the service to make the configuration effective
2. Configure slave server:
[root@haproxy2 /] # yum-y install pcre-devel bzip2-devel keepalived [root@haproxy2 media] # tar zxf haproxy-1.5.19.tar.gz-C / usr/src/ [root@haproxy2 media] # cd / usr/src/haproxy-1.5.19/ [root@haproxy2 haproxy-1.5.19] # make TARGET=linux26 & & make install [root@haproxy2 haproxy-1.5.19] # mkdir / etc/haproxy [root@haproxy2 haproxy-1.5.19] # scp root@ 192.168.1.10:/etc/haproxy/haproxy.cfg / etc/haproxy/ # figure is convenient to copy root@192.168.1.10's password: haproxy.cfg 100570 0.6KB/s 00:00 [root@haproxy2 /] # cp / usr/src/haproxy-1.5.19/examples/haproxy.init / etc/init. D/haproxy # replication service control script [root@haproxy2 /] # ln-s / usr/local/sbin/haproxy / usr/sbin/haproxy [root@haproxy2 /] # chmod + x / etc/init.d/haproxy [root@haproxy2 /] # chkconfig-- add / etc/init.d/haproxy [root@haproxy2 /] # / etc/init.d/haproxy start Starting haproxy (via systemctl): [OK] [root@haproxy2 /] # scp root@192.168.1.10:/etc/rsyslog.d/haproxy.conf / etc/rsyslog.d/root@192.168.1.10's password: haproxy.conf 100% 226 0.2KB/s 00:00 [root@haproxy2 /] # systemctl restart rsyslog.service # restart the service to make the configuration effective [root @ haproxy2 haproxy-1.5.19] # scp root@192.168.1.10:/etc/keepalived/keepalived.conf / etc/keepalived/root@192.168.1.10's password: keepalived.conf 3511 3.4KB/s 00:00 [root@haproxy2 /] # vim / etc/keepalived/keepalived.conf # modify the main configuration file Modify the following parts. Omit part of router_id LVS2 # Master-Slave Scheduler distinguish ID} vrrp_instance VI_1 {state BACKUP # status modified to BACKUP interface ens33 virtual_router_id 51 priority 90 # priority lower advert_int 1 authentication {auth_type PASS auth _ pass 1111} virtual_ipaddress {192.168.1.100 # Drift address}} [root@haproxy2 /] # systemctl restart keepalived
Two web node configurations (both configurations are the same):
[root@web2 /] # yum-y install httpd
[root@web2 /] # echo server2.com > / var/www/html/index.html # create a test web page
[root@web2 /] # systemctl start httpd
[root@web2 /] # systemctl enable httpd
Of course, in the actual production environment, the web page is the same, here I do two different test files in order to verify the effect.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.