haproxy+keepalived安装.docx
- 文档编号:1363070
- 上传时间:2022-10-21
- 格式:DOCX
- 页数:15
- 大小:271.39KB
haproxy+keepalived安装.docx
《haproxy+keepalived安装.docx》由会员分享,可在线阅读,更多相关《haproxy+keepalived安装.docx(15页珍藏版)》请在冰豆网上搜索。
haproxy+keepalived安装
HAproxy指南之haproxy双机热备(案例篇)
转载2017年03月06日14:
28:
56
∙标签:
∙487
∙编辑
∙删除
haproxy的出现正是弥补nginx一些应用上不足,比如session会话保持,健康监控检测机制,负载算法等等,在很多应用环境中,nginx的代理性能会haproxy稍逊一些,不过在一些实际案例中,keepalive+nginx与keepalive+nginx往往会根据业务去选择,比如nginx有着haproxy没有的代理缓存的功能等等,如果需要用到缓存就可以使用nginx,总之:
根据业务来选择这两者!
Keepalive+haproxy双机热备
如图所示为整体的拓扑图:
一.部署前说明:
(1)系统版本:
centos6.6(64位)
(2)角色及ip相关信息:
角色名称
网络ip信息
客户端(CIP)
10.58.137.203/24
Master_DR
eth0:
172.51.96.105/24&& eth1:
192.168.0.105/24
Backup_DR
eth0:
172.51.96.119/24&& eth1:
192.168.0.119/24
VIP
172.51.96.175/24
(3)相关中间件信息
keepalive版本信息:
keepalived-1.2.15
nginx版本信息:
haproxy-1.5.15 (提供proxy代理)
二.部署操作:
haproxy部署
分别在Master_DR和backup_DR上安装haproxy,操作如下:
1.1到haproxy官网下载haproxy源码包如下
cd~
wgethttp:
//www.haproxy.org/download/1.5/src/haproxy-1.5.15.tar.gz
1.2创建haproxy运行用户
groupadd-rhaproxy
useradd-r-ghaproxy-M-s/sbin/nologinhaproxy
1.3编译安装haproxy:
cd~
tarzxvfhaproxy-1.5.15.tar.gz-C/usr/local/src
cd/usr/local/src/haproxy-1.5.15
makeTARGET=linux26PREFIX=/usr/local/haproxy
makeinstallPREFIX=/usr/local/haproxy
注意:
TARGET=Linux26是通过uname-a来查看Linux内核版本的
1.4创建haproxy主配置文件:
mkdir/etc/haproxy/
vim/etc/haproxyhaproxy.cfg
配置代码内容如下:
(注意主备server上haproxy.cfg配置要一致)
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
log 127.0.0.1 local3
maxconn 204800
chroot /usr/local/haproxy
user haproxy
group haproxy
daemon
nbproc 1
pidfile /var/run/haproxy.pid
stats socket /usr/local/haproxy/stats
description haproxy server
#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
log global
mode http
maxconn 10000
option httplog
option httpclose
option dontlognull
option forwardfor except 127.0.0.0/8
retries 3
option redispatch
option abortonclose
balance roundrobin
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
#---------------------------------------------------------------------
# use listen setting the haproxy status for site
#---------------------------------------------------------------------
listen admin_status
bind *:
3030
mode http
log 127.0.0.1 local3 err
stats refresh 5s
stats uri /status
stats realm
stats auth admin:
admin
stats hide-version
stats admin if TRUE
#---------------------------------------------------------------------
# main listen which proxys to the backends
#---------------------------------------------------------------------
listen www
bind *:
80
maxconn 5000
mode http
log global
option httplog
option httpclose
option forwardfor
log global
default_backend default
#<----------------------default site for listen and frontend------------------------------------>
backend default
mode http
option httpchk GET /index.html
server default 127.0.0.1:
81 cookie id1 check inter 2000 rise 2 fall 3 maxconn 5000
1.5创建haproxy系统服务启动脚本:
关于haproxy服务脚本代码请访问:
1.6启动haproxy服务:
serverhaproxyrestart
Keepalive部署
(1)分别在Master_DR和backup_DR上安装keepalive,操作如下:
1.安装Keepalive所需要的相关依赖包:
yuminstallopenssl-develpopt-devellibnl-develkernel-devel -y
2.编译安装keepalive
1.1keepalived的源码获取
keepalived源码包我们可以到keepalived的官网:
http:
//www.keepalived.org/去下载,相关说明文档亦可在其官网查看,比如keepalived的使用,相关配置说明,这里演示的版本为:
1.2.15
cd~
wgethttp:
//www.keepalived.org/software/keepalived-1.2.15.tar.gz
1.2编译安装keepalived
<--编译安装keepalived-->
ln-s/usr/src/kernels/2.6.32-573.18.1.el6.x86_64//usr/src/linux
tar zxvf keepalived-1.2.15.tar.gz -C /usr/local/src
cd /usr/local/src/keepalived-1.2.15/
./configure \
--prefix=/usr/local/keepalived \
--with-kernel-dir=/usr/src/kernels/2.6.32-573.18.1.el6.x86_64
#2.6.32-573.18.1.el6.x86_64这个需要根据kernel来匹配,一般安装了kernel-devel即可查看
make make install
<--对keepalived进行相关路径优化调整-->
<---拷贝keepalived相关启动命令--->
cp/usr/local/keepalived/sbin/keepalived/usr/sbin/
cp/usr/local/keepalived/etc/sysconfig/keepalived/etc/sysconfig/
<---将keepalived启动脚本添加到系统服务--->
cp/usr/local/keepalived/etc/rc.d/init.d/keepalived/etc/init.d/
chkconfig--addkeepalived
chkconfig--level2345keepalive
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- haproxy keepalived 安装
![提示](https://static.bdocx.com/images/bang_tan.gif)