配置环境:
server1:调度器1(172.25.254.1)
server2:real server1(172.25.254.2)
server3:real server2(172.25.254.3)
一、haproxy负载均衡
1、haproxy安装
haproxy可以使用源码安装,rpm直接安装和rpmbuild安装三种方式,本次采用rpmbuild安装
1、在官网下载haproxy安装包,并解压
[root@server1 ~]# ls
haproxy-1.6.11 haproxy-1.6.11.tar.gz
1
2
2、安装rpm-build
[root@server1 ~]# yum install rpm-build -y
3、执行命令生成rpmbuild目录
[root@server1 ~]# rpmbuild -bb haproxy-1.6.11
4、进入到解压的haproxy目录下
[root@server1 haproxy-1.6.11]# cd examples/
[root@server1 examples]# ls
acl-content-sw.cfg debug2html init.haproxy
auth.cfg debugfind option-http_proxy.cfg
check errorfiles seamless_reload.txt
check.conf haproxy.init ssl.cfg
content-sw-sample.cfg haproxy.spec stats_haproxy.sh
debug2ansi haproxy.vim transparent_proxy.cfg
[root@server1 examples]# rpmbuild -bb haproxy.spec ##rpmbuild来生成rpm包
error: Failed build dependencies:
pcre-devel is needed by haproxy-1.6.11-1.x86_64 ##报错缺少pcre-devel包
[root@server1 examples]# yum install pcre-devel ##安装
[root@server1 examples]# rpmbuild -bb haproxy.spec 继续执行
1
2
3
4
5
6
7
8
9
10
11
12
13
遇到此报错意思是缺少gcc,安装即可
这里写图片描述
[root@server1 examples]# rpmbuild -bb haproxy.spec继续
[root@server1 examples]# cd /root/rpmbuild/RPMS/x86_64/ ##成功后会生成x86_64目录下 会有haproxy的rpm包,rpm-ivh安装即可
[root@server1 x86_64]# ls
haproxy-1.6.11-1.x86_64.rpm
[root@server1 x86_64]# rpm -ivh haproxy-1.6.11-1.x86_64.rpm
Preparing… ########################################### [100%]
1:haproxy ########################################### [100%]
1
2
3
4
5
6
2、负载均衡配置
1、修改配置文件
/root/haproxy-1.6.11/examples
[root@server1 examples]# ls
acl-content-sw.cfg debug2html init.haproxy
auth.cfg debugfind option-http_proxy.cfg
check errorfiles seamless_reload.txt
check.conf haproxy.init ssl.cfg
content-sw-sample.cfg haproxy.spec stats_haproxy.sh
debug2ansi haproxy.vim transparent_proxy.cfg
[root@server1 examples]# cp content-sw-sample.cfg /etc/haproxy/haproxy.cfg
[root@server1 examples]# cd /etc/ha
-bash: cd: