In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Experimental requirements:
1. One Haproxy scheduling server, two Nginx servers, and one windows7 as the client
two。 Three 64-bit systems with CentOS 7.3servers
3. All host network cards are set to host-only mode and bind static addresses
4. The client can access two node servers by accessing the scheduling server, without the need to access the real server address
Host role IP address centos7-1Haproxy server 192.168.1.10centos7-2Nginx server 1192.168.1.20centos7-3Nginx server 2192.168.1.30win 7windows7 client 192.168.1.40 Experimental steps: 1. Build two Nginx servers
Install the environment package and nginx
[root@nginx1 mnt] # yum-y install\ gcc\ gcc-c++\ zlib-devel\ pcre pcre-devel\ expat-devel [root@nginx1 mnt] # useradd-M-s / sbin/nologin nginx # establish administrative user [root@nginx1 mnt] # tar zxvf nginx-1.12.0.tar.gz-C / opt/ [root@nginx1 nginx-1.12.0] #. / configure\-prefix=/usr/local/nginx\-user=nginx\-- group=nginx [ Root@nginx1 nginx-1.12.0] # make & & make install # compile and install [root@nginx1 nginx-1.12.0] # ln-s / usr/local/nginx/sbin/nginx / usr/local/sbin/ [root@nginx1 nginx-1.12.0] # vim / usr/local/nginx/html/test.html # write the home page ACCP web!
Write a startup script
[root@nginx1 nginx-1.12.0] # vim / etc/init.d/nginx # convenient for service to call #! / bin/bashwenjian= "/ usr/local/nginx/sbin/nginx" pid= "/ usr/local/nginx/logs/nginx.pid" case $1 instart) $wenjian;; stop) kill-s QUIT $(cat $pid);; restart) $0 stop $0 start;;reload) kill-s HUP $(cat $pid) *) echo "Please,try again" exit 1 Esacexit 0 [root@nginx1 nginx-1.12.0] # chmod + x / etc/init.d/nginx # activate the service [root@nginx1 nginx-1.12.0] # service nginx start [root@nginx1 nginx-1.12.0] # systemctl stop firewalld.service [root@nginx1 nginx-1.12.0] # setenforce change to static [root@nginx1 nginx-1.12.0] # vim / etc/sysconfig/network-scripts/ifcfg-ens33 [root@nginx1 nginx-1.12.0] # systemctl restart nework2, Set up Haproxy scheduling server
Install the environment package and haproxy
# change static [root@nginx1 nginx-1.12.0] # vim / etc/sysconfig/network-scripts/ifcfg-ens33 [root@nginx1 nginx-1.12.0] # systemctl restart nework## installation environment package [root@haproxy mnt] # yum-y install gcc gcc-c++ bzip2-devel pcre pcre-devel# install haproxy[ root @ nginx1 ~] # mount.cifs / / 192.168.10.71/rpm / mnt/ [root@localhost mnt] # tar zxvf haproxy-1.5.19. Tar.gz-C / opt/ [root@localhost mnt] # cd / opt/haproxy-1.5.19/# source code compilation, Install [root@localhost haproxy-1.5.19] # make TARGET=linux26 # # compiled version as Linux kernel version (view using uname-a) [root@localhost haproxy-1.5.19] # make install
Modify the configuration file
Root@localhost haproxy-1.5.19] # mkdir / etc/haproxy # create profile site [root@localhost haproxy-1.5.19] # cp examples/haproxy.cfg / etc/haproxy/ # copy template [root@localhost haproxy-1.5.19] # vim / etc/haproxy/haproxy.cfg # modify configuration file chroot / usr/share/haproxy # (default home directory) delete the line The file does not actually exist redispatch # send the request to the failed node (it is useless to turn it off)-delete all listen segments-# # add listen Webcluster 0.0.0.0 test.html 80 option httpchk GET / test.html # enable health check for backend servers (here, submit test test page) # POST uses encryption to submit parameters GET directly submits parameters in clear text. The parameters are shown on url. Balance roundrobin # load balancer adopts polling algorithm server inst1 192.168.1.20 check inter 80 check inter 2000 fall 3 # to define online node 1 server inst2 192.168.1.30 balance roundrobin 80 check inter 2000 fall 3 # define online node 2
Define startup script
# define startup script [root@localhost haproxy-1.5.19] # cp / opt/haproxy-1.5.19/examples/haproxy.init / etc/init.d/haproxy [root@localhost haproxy-1.5.19] # chmod + x / etc/init.d/haproxy [root@localhost haproxy-1.5.19] # chkconfig-add / etc/init.d/haproxy # # add to startup list [root@localhost haproxy-1.5.19] # ln- S / usr/local/sbin/haproxy / usr/sbin/# start service [root@localhost haproxy-1.5.19] # service haproxy start [root@localhost haproxy-1.5.19] # systemctl stop firewalld.service [root@localhost haproxy-1.5.19] # setenforce 0
Experimental results
Use the client to access the Haproxy server, and the scheduling server will schedule access to the back-end web server
At this point, the Haproxy server writes the access log to the system log, which is very unfriendly to the maintenance staff. Therefore, we need to split the log of haproxy separately.
Configure haproxy Profil
Location: / etc/rsyslog.d/haproxy.conf
# restart haproxy service [root@haproxy etc] # service haproxy restart Restarting haproxy (via systemctl): [OK] # create [root@haproxy haproxy-1.5.19] # touch / etc/rsyslog.d/haproxy.conf [root@haproxy haproxy-1.5.19] # vim / etc/rsyslog.d/haproxy.conf# define haproxy information log if ($programname = = 'haproxy' and $syslogseverity-text = =' info') then-/ var / log/haproxy/haproxy-info.log&~# defines haproxy notification log if ($programname = = 'haproxy' and $syslogseverity-text = =' notice') then-/ var/log/haproxy/haproxy-notice.log&~# restart log service [root@haproxy etc] # systemctl restart rsyslog.service# switch to log directory to view haproxy log file [root@haproxy etc] # cd / var/log/haproxy/ [root@haproxy haproxy] # lshaproxy-info.log# to view log text Piece [root@haproxy haproxy] # cat haproxy-info.logNov 30 16:53: 30 Haproxy haproxy [119165]: 192.168.100.50: 49191 [30/Nov/2019:16:53: 30.100webcluster. Webcluster/inst2 168 Nov 0 Nov 0 Haproxy haproxy [119165]: 192.168.100.50: 49191 [30/Nov/2019:16:53:42.290: webcluster. Webcluster/inst1 159ax 0 GET 0 GET / test.html HTTP/1.1---1, 1, 000, 200, 253
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.