8. Establish soft links for easy management of Nginxln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
9. Check Nginx Configurationnginx -t
10. Start the servicenginx
Shutting down firewalls and SELinuxsystemctl stop firewalld.service setenforce 0
TestThird, Haproxy server 1. Install Environment packyum install -y pcre-devel bzip2-devel gcc gcc-c++ make
2. Unzip the Haproxytar zxvf /linux-tools/haproxy-1.5.19.tar.gz -C /opt/
3. Switch to the Haproxy directorycd /opt/haproxy-1.5.19/
4. Compiling and installingmake TARGET=linux26make install
5. Create the Haproxy profile directorymkdir /etc/haproxy
6. Copy the template configuration file to the Haproxy directorycp examples/haproxy.cfg /etc/haproxy/
7. Edit Haproxy. CFG configuration filevim /etc/haproxy/haproxy.cfg
#1. Delete the following 2 lines of statements
Chroot/usr/share/haproxy
Redispatch
#2. Delete all Listen items
#3. New Add the following data
Listen Webcluster 0.0.0.0:80
Option Httpchk get/index.html
Balance Roundrobin
Server Inst1 192.168.100.26:80 check Inter fall 3
Server Inst2 192.168.100.27:80 check Inter fall 3
8. Create a startup script Haproxycp /opt/haproxy-1.5.19/examples/haproxy.init /etc/init.d/haproxy
9. Assign executable permissions for Haproxychmod +x /etc/init.d/haproxy
10. Join the system servicechkconfig --add /etc/init.d/haproxyln -s /usr/local/sbin/haproxy /usr/sbin/haproxy
11. Start Haproxyservice haproxy start
12. Turn off the firewall and SELinuxsystemctl stop firewalld.service setenforce 0
13. Test:Win7 Client: http://192.168.100.25/
Iv. Add Log functionNote: Haproxy default is not to output the file log directly, so we want to use Linux rsyslog to let haproxy output log
1. Edit Haproxy.cfgvim /etc/haproxy/haproxy.cfg
#将信息提示与告警进行分离
Log/dev/log local0 Info
Log/dev/log local0 Notice
2. Restart Haproxyservice haproxy restart
3. New configuration formatvim /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.log
&~
4. Restart the System Log servicesystemctl restart rsyslog.service
5. After the client accesses, the record is viewed in the log directory of the dispatch servercat /var/log/haproxy/haproxy-info.log
At this point, the Haproxy build Web cluster is complete.
Haproxy Building a Web cluster