实验环境
主机 | 服务 |
---|---|
server1:172.25.23.1 | haproxy |
server2:172.25.23.2 | apache |
server3:172.25.23.3 | apache |
物理机:172.25.23.250 | 测试 |
一、Haproxy实现负载均衡
1.下载并解压haproxy安装包
[root@server1 ~]# ls
haproxy-1.7.3.tar.gz
[root@server1 ~]# tar zxf haproxy-1.7.3.tar.gz
[root@server1 ~]# ls
haproxy-1.7.3 haproxy-1.7.3.tar.gz
2.用find . -name *.spec命令查看,有spec才可以搭成rpm包
[root@server1 ~]# cd haproxy-1.7.3
[root@server1 haproxy-1.7.3]# find . -name *.spec
./examples/haproxy.spec
3.安装源码编译软件
[root@server1 ~]#yum install rpm-build -y
[root@server1 ~]# yum install gcc -y
[root@server1 ~]# yum install pcre-devel -y
4.源码编译haproxy软件
[root@server1 ~]# rpmbuild -tb haproxy-1.7.3.tar.gz
5.编译完成后,会生成rpmbuild目录,切换到rpmbuild/RPMS/ x86_64/目录下,安装haproxy-1.7.3-1.x86_64软件
[root@server1 ~]# ls
haproxy-1.7.3 haproxy-1.7.3.tar.gz rpmbuild
[root@server1 ~]# cd rpmbuild/
[root@server1 rpmbuild]# ls
BUILD BUILDROOT RPMS SOURCES SPECS SRPMS
[root@server1 rpmbuild]# cd RPMS/
[root@server1 RPMS]# ls
x86_64
[root@server1 RPMS]# cd x86_64/
[root@server1 x86_64]# ls
haproxy-1.7.3-1.x86_64.rpm
[root@server1 x86_64]# rpm -ivh haproxy-1.7.3-1.x86_64.rpm
6.切换到examples目录下,找到haproxy的配置文件,复制配置文件到/etc/haproxy/目录下
[root@server1 ~]# cd haproxy-1.7.3
[root@server1 haproxy-1.7.3]# cd examples/
[root@server1 examples]# ls
[root@server1 examples]# cp content-sw-sample.cfg /etc/haproxy/haproxy.cfg
[root@server1 examples]# cd
7.进入/etc/haproxy/目录下,编辑haproxy配置文件
[root@server1 ~]# cd /etc/haproxy/
[root@server1 haproxy]# ls
haproxy.cfg
[root@server1 haproxy]# vim haproxy.cfg
global ##全局定义
maxconn 10000 ##