haproxy群集服务搭建

image

---------------------安装服务软件包----------------

yum install pcre-devel bzip2-devel gcc gcc-c++ -y

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 /opt/haproxy-1.5.19/examples/haproxy.cfg /etc/haproxy/

vim /etc/haproxy/haproxy.cfg

# chroot /usr/share/haproxy               //禁锢share目录

# redispatch //反复重新发送

----------删除所有listen,增加下段---------

listen webcluster 0.0.0.0:80           //允许任意网络访问网站

option httpchk GET /index.html          //定义默认首页类型

balance roundrobin                    //负载均衡算法,轮询

server inst1 192.168.218.130:80 check inter 2000 fall 3                  //定义在线节点 

server inst2 192.168.218.131:80 check inter 2000 fall 3

--------------------创建启动连接,开启服务----------------------

cp /opt/haproxy-1.5.19/examples/haproxy.init /etc/init.d/haproxy

chmod 755 /etc/init.d/haproxy 

chkconfig --add haproxy                   //开机自启

ln -s /usr/local/sbin/haproxy /usr/sbin/haproxy

systemctl start haproxy.service

systemctl stop firewalld.service

setenforce 0

猜你喜欢

转载自blog.51cto.com/13710287/2165332