怎么合理的利用新采购服务器的资源呢(原来就一台前端服务器),第一就想到用nginx来做,大家都知道nginx好是好,但是session没办法同步,是否没有办法了?办法是有的,可以利用HAProxy 来祢补nginx的不足的地方.
一:安装 HAProxy[root@xutest src] /usr/local/ [root@xutest src]wget -1.3.15.7.tar.gz [root@xutest src]tar -zxvf haproxy-1.3.15.7.tar.gz [root@xutest src]cd haproxy-1.3.15.7 [root@xutest src]make TARGET=linux26 USE_STATIC_PCRE=1 [root@xutest src]make install PREFIX=/home二:配置1)新建haproxy 用户组和用户:
[root@xutest src]groupa haproxy [root@xutest src] haproxy -g haproxy2)查看用户ID:
[root@xutest src]vi /etc/ haproxy:x:500:500::/home/haproxy:/bin/bash3)新建HAProxy目录:
[root@xutest opt]# /opt/haproxy [root@xutest opt]# /opt/haproxy/haproxy.cfg4)配置haproxy.cfg
[root@xutest opt]#vi /opt/haproxy/haproxy.cfg global log 127.0.0.1 local0 maxconn 4096 chroot /opt/haproxy uid 500 gid 500 daemon nbproc 1 #pi ile /home/haproxy/logs/haproxy.pid #debug #quiet defaults log 127.0.0.1 local3 mode http option httplog option httpclose option dontlognull option forwardfor option redis re ies 2 maxconn 2000 bala e roundrobin s uri /haproxy-stats con out 5000 clitimeout 50000 srvtimeout 50000 listen web_proxy 0.0.0.0:8888 option httpchk server web1 192.168.1.250:8080 weight 3 check server web2 192.168.1.238:8080 weight 3 check三:启动HAProxy主进程:
[root@xutest haproxy]# /usr/local/sbin/haproxy -f /opt/haproxy/haproxy.cfg停止HAProxy:
[root@xutest haproxy]# ps aux| haproxy [root@xutest haproxy]# -9 + 进程ID到此HAProxy配置完,我们可以通过浏览器查看: