目录
部署Haproxy+keepalived
一,配置主服务器(haproxy)
根据上篇博客 操作,再添加一台haproxy服务器做(备用)边缘服务器,部署keepalived。
1,关闭防火墙
2,安装依赖环境
[root@haproxy ~]#yum -y install pcre-devel zlib-devel gcc gcc-c++ make
3,编译安装haproxy
tar zxvf haproxy-1.6.9.tar.gz #解压安装包
cd haproxy-1.6.9/ #进入解压目录
make TARGET=linux2628 ARCH=x86_64 #进行编译
(TARGET=linux2628 表示内核版本,使用uname -r查看内核,如:2.6.18-371.el5,此时该参数用TARGET=linux26;kernel大于2.6.28的用TARGET=linux2628)
(ARCH=x86_64 系统位数,现在基本都是64位)
make install # 安
4,haproxy服务配置文件修改
[root@kya haproxy-1.5.19]#mkdir /etc/haproxy
[root@kya haproxy-1.5.19]#cp /opt/haproxy-1.5.19/examples/haproxy.cfg /etc/haproxy/
[root@kya haproxy-1.5.19]#cd /etc/haproxy/
[root@kya haproxy]#ls
haproxy.cfg
删除将原来的listen配置项,添加新配置:
listen webcluster 0.0.0.0:80
option httpchk GET /index.html
balance roundrobin
server nginx1 192.168.135.90:80 check inter 2000 fall 3
server nginx2 192.168.135.91:80 check inter 2000 fall 3
5,添加haproxy系统服务
cp /opt/haproxy-1.5.19/examples/haproxy.init /etc/init.d/haproxy
chmod +x /etc/init.d/haproxy
chkconfig --add /etc/init.d/haproxyln -s /usr/local/sbin/haproxy /usr/sbin/haproxy
service haproxy start 或 /etc/init.d/haproxy start //如果ningx服务器未部署会提示找不到web服务器,可以等web部署完后再开启haproxy
systemctl stop firewalld
setenforce 0
yum -y install gcc gcc-c++ make pcre-devel bzip2-devel
tar zxvf haproxy-1.6.9.tar.gz
cd haproxy-1.6.9/
make TARGET=linux2628 ARCH=x86_64 #进行编译
make install
mkdir /etc/haproxy #创建haproxy目录