这里都选择了最新的版本,即haproxy-2.0.1.tar.gz和Keepalived for Linux - Version 2.0.17
1、HAProxy安装与配置(基于Centos7)IP为 192.168.10.9
1)解压
tar xvf haproxy-2.0.1.tar.gz
2)编译安装haproxy
cd haproxy-2.0.1
make TARGET=linux-glibc PREFIX=/usr/local/haproxy
make install PREFIX=/usr/local/haproxy
3)配置环境变量
vi /etc/profile
export HAPROXY_HOME=/usr/local/haproxy
export PATH=$HAPROXY_HOME/sbin:$PATH
退出,执行source /etc/profie
4)配置haproxy配置文件
mkdir -p /usr/local/haproxyconf
cp /usr/local/haproxy-2.0.1/examples/option-http_proxy.cfg /usr/local/haproxyl/conf/haproxy.cfg
cd /usr/local/haproxy/conf
vi haproxy.cfg
输入以下信息(加粗为关键字,#后为注释)
# 默认配置
defaults
# 应用全局的日志配置
log global
# 默认的模式mode=tcp|http|health
# tcp是4层负载均衡,http是7层,health只返回ok
mode tcp
# 日志类别
option tcplog
# 不记录健康检查日志信息
option dontlognull
# 3次失败认为服务不可用
retries 3
# 每个进程可用的最大连接数
maxconn 2000
# 连接超时时间
timeout connect 5s
# 客户端超时时间
timeout client 120s
# 服务端超时
timeout server 120s
# 邦定配置
listen rabbitmq_cluster
# 转发端口
bind *:5671
# 配置tcp模式
mode tcp
# 负载均衡策略-采用简单的轮询策略
balance roundrobin
# RabbitMQ集群节点配置
server mqnode1 192.168.10.13:5672 check inter 5000 rise 2 fall 3 weight 1
server mqnode2 192.168.10.14:5672 check inter 5000 rise 2 fall 3 weight 1
server mqnode3 192.168.10.15:5672 check inter 5000 rise 2 fall 3 weight 1
# haproxy监控页面地址
listen monitor
# haproxy页面监听端口
bind *:9181
mode http
option httplog
stats enable
# haproxy页面地址
stats uri /haproxy_stats
# 要登录
stats realm welcome login \ Haproxy
# 登录的用户名及密码
stats auth admin:admin
# 隐藏haproxy版本号
stats hide-version
# haproxy监听页面刷新时间
stats refresh 5s
退出,执行haproxy -f haproxy.cfg,运行haproxy
浏览器输入:http://192.168.10.9:9181/haproxy_stats
2、KeepAlived安装与配置,IP:192.168.10.9
1)解压
tar -zxvf keepalived-2.0.17.tar.gz
2)编译前配置
cd keepalived-2.0.17
由于1.4版本开始需要对IPV6进行支持,所以在编译安装Keepalived之前要先安装如下环境:
yum install -y libnl-devel libnl3-devel libnfnetlink-devel
如果安装出现Cannot retrieve metalink for repository: epel. Please verify its path and try again,这样的问题,
可以修改以下内容:打开/etc/yum.repos.d/epel.repo,将
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
修改为:[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
然后执行:yum clean allyum install -y libnl-devel libnl3-devel libnfnetlink-devel
如果编译时出现!!! OpenSSL is not properly installed on your system. !!! Can not include OpenSSL headers files.!!! 这样的报错需要先安装openssl-devel这个软件包
yum install openssl-devel -y
最后执行:
./configure --prefix=/usr/local/keepalived
3)编译安装
make && make install
4)配置环境变量
vi /etc/profile
export KEEPALIVED_HOME=/usr/local/keepalived
export PATH=$KEEPALIVED_HOME/sbin:$PATH
生效环境变量
source /etc/profile
验证安装
keepalived -v
5)配置keepAlived配置文件
可参考以下链接: