主機 | 操做系統 | IP地址 | 主要軟件 |
---|---|---|---|
HAProxy服務器 | CentOS7-3 | 192.168.1.60 | haproxy-1.5.19.tar.gz |
Nginx服務器1 | CentOS7-3 | 192.168.1.61 | nginx-1.12.0.tar.gz |
Nginx服務器2 | CentOS7-3 | 192.168.1.61 | nginx-1.12.0.tar.gz |
客戶端 | Windows7 | 192.168.1.66 | IE瀏覽器 |
#yum install pcre-devel zlib-devel gcc gcc-c++ make –y
#useradd –M –s /sbin/nologin nginx
#tar zxvf nginx-1.12.0.tar.gz –C /opt/ //保證在由此軟件包的目錄下
#cd nginx-1.12.0/ #./configure \ --prefix=/usr/local/nginx \ //安裝目錄 --user=nginx \ //用戶 --group=nginx //用戶組
#make && make install
#cd /usr/local/nginx/html #echo 「this is benet web」>test.html
#ln –s /usr/local/nginx/sbin/nginx /usr/local/sbin
#nginx
#systemctl stop firewalld.service #setenforce 0
#yum install –y pcre-devel bzip2-devel gcc gcc-c++ make
#tar zxvf haproxy-1.5.19.tar.gz –C /opt/
#cd /opt/haproxy-1.5.19 #make TARGET=linux26 #make install
#mkdir /etc/haproxy
#cp examples/haproxy.cfg /etc/haproxy/
#cd /etc/haproxy/ #vim haproxy.cfg 刪除全部listen項目並刪除如下語句 chroot /usr/share/haproxy redispatch 添加 listen webcluster 0.0.0.0:80 option httpchk GET /test.html //檢查系統的test.html文件 balance roundrobin //負載均衡調度算法使用輪詢算法 server inst1 192.168.1.61:80 check inter 2000 fall 3 //定義在線節點 server inst2 192.168.1.62:80 check inter 2000 fall 3
#cp /opt/haproxy-1.5.19/examples/haproxy.init /etc/init.d/haproxy #chmod +x /etc/init.d/haproxy //賦予可執行權限 #chkconfig –add /etc/init.d/haproxy //加入系統服務 #ln –s /usr/local/sbin/haproxy /usr/sbin/haproxy
#service haproxy start
#systemctl stop firewalld.service #setenforce 0
#vim /etc/haproxy/haproxy.cfg log /dev/log /local0 info log /dev/log /local0 notice //將配置文件裏global下面的兩行進行替換
#service haproxy restart
#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.log &~
#systemctl restart rsyslog.service
#tail –f /var/log/haproxy/haproxy-info.log