HAProxy+Keepalived高可用负载均衡配置

一、系统环境:
系统版本:CentOS5.5 x86_64
master_ip:172.20.27.40
backup_ip:172.20.27.50 
vip:172.20.27.200
web_1: 172.20.27.90
web_2:172.20.27.100
二、haproxy安装:
1.首先172.20.27.40安装上安装:
1.1安装
 tar zxvf haproxy-1.3.20.tar.gz
 cd haproxy-1.3.20
 make TARGET=linux26 PREFIX=/usr/local/haproxy                             
 make install PREFIX=/usr/local/haproxy
1.2.配置
 cd /usr/local/haproxy 
 mkdir etc
 cd etc
 vi haproxy.cfg

global
  log 127.0.0.1   local0
   maxconn 65535
   chroot /usr/local/haproxy
    uid 99
    gid 99
    daemon
    nbproc 12
   pidfile /usr/local/haproxy/haproxy.pid
defaults
   log     127.0.0.1       local3
   mode   http
   option httplog
   option httpclose
   option dontlognull
   option forwardfor
   option redispatch
   retries 2
   maxconn 65535
   balance   source
   stats   uri     /web-status
   stats   auth admin:[email protected]
   stats   refresh 60s
   contimeout      5000
   clitimeout      50000
   srvtimeout      50000
listen  172.20.27.200
  bind *:80
  mode http 
  option httplog 
  log global
  option httpchk HEAD /t.htm HTTP/1.0
  server web1  172.20.27.90:80 weight 5  check inter 2000 rise 2 fall 3
  server web2  172.20.27.100:80 weight 5  check inter 2000 rise 2 fall 3
然后启动haproxy,如下执行启动命令:
 /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/etc/haproxy.cfg 
2.首先172.20.27.50安装上安装:
2.1.安装
 tar zxvf haproxy-1.3.20.tar.gz
 cd haproxy-1.3.20
 make TARGET=linux26 PREFIX=/usr/local/haproxy                             
 make install PREFIX=/usr/local/haproxy
2.2.配置
 cd /usr/local/haproxy 
 mkdir etc
 cd etc
 vi haproxy.cfg

global
  log 127.0.0.1   local0
   maxconn 65535
   chroot /usr/local/haproxy
    uid 99
    gid 99
    daemon
    nbproc 12
   pidfile /usr/local/haproxy/haproxy.pid
defaults
   log     127.0.0.1       local3
   mode   http
   option httplog
   option httpclose
   option dontlognull
   option forwardfor
   option redispatch
   retries 2
   maxconn 65535
   balance   source
   stats   uri     /web-status
   stats   auth admin:[email protected]
   stats   refresh 60s
   contimeout      5000
   clitimeout      50000
   srvtimeout      50000
listen  172.20.27.200
  bind *:80
  mode http 
  option httplog 
  log global
  option httpchk HEAD /t.htm HTTP/1.0
  server web1  172.20.27.90:80 weight 5  check inter 2000 rise 2 fall 3
  server web2  172.20.27.100:80 weight 5  check inter 2000 rise 2 fall 3
然后启动haproxy,如下执行启动命令:
 /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/etc/haproxy.cfg 
三、keepalived安装:
1.首先172.20.27.40安装上安装:
1.1安装
tar zxvf keepalived-1.1.17.tar.gz
cd keepalived-1.1.17
./configure 
make
make install
cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d
cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig
mkdir /etc/keepalived
cp /usr/local/sbin/keepalived /usr/sbin/
cd /etc/keepalived
1.2.配置
 vi keepalived.conf
! Configuration File for keepalived
global_defs {
 notification_email {
    [email protected]
}
  notification_email_from [email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
  router_id LVS_DEVEL
}
vrrp_script chk_haproxy {
   script "/usr/local/haproxy/shell/check_haproxy.sh"
   interval 2
   weight 2
}
  # VIP1
  vrrp_instance VI_1 {
   state BACKUP
    interface eth0
   lvs_sync_daemon_inteface eth0
    virtual_router_id 151
    priority 100
    advert_int 5
    nopreempt
    authentication {
       auth_typePASS
       auth_pass 2222
   }
    virtual_ipaddress {
        172.20.27.200
    }
    track_script {
   chk_haproxy
   }
}
mkdir -p /usr/local/haproxy/shell
cd /usr/local/haproxy/shell
#建立监控haproxy脚本
vi check_haproxy.sh
#!/bin/bash
#auto check haprox process
#2014-6-30
killall -0 haproxy
 if  [[ $? -ne 0 ]];then
 /etc/init.d/keepalived stop
 fi
chmod u+x check_haproxy.sh
service keepalived restart
2.首先172.20.27.50安装上安装:
2.1安装
tar zxvf keepalived-1.1.17.tar.gz
cd keepalived-1.1.17
./configure
make
make install
cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d
cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig
mkdir /etc/keepalived
cp /usr/local/sbin/keepalived /usr/sbin/
cd /etc/keepalived
2.2配置
 vi keepalived.conf
! Configuration File for keepalived
global_defs {
 notification_email {
     [email protected]
}
   notification_email_from  [email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
vrrp_script chk_haproxy {
   script "/usr/local/haproxy/shell/check_haproxy.sh"
   interval 2
   weight 2
}
  # VIP1
  vrrp_instance VI_1 {
   state BACKUP
    interface eth0
   lvs_sync_daemon_inteface eth0
   virtual_router_id 151
    priority 90
    advert_int 5
    nopreempt
    authentication {
       auth_typePASS
       auth_pass 2222
   }
    virtual_ipaddress {
        172.20.27.200
    }
    track_script {
   chk_haproxy
   }
}
mkdir -p /usr/local/haproxy/shell
cd /usr/local/haproxy/shell
#建立监控haproxy脚本
vi check_haproxy.sh
#!/bin/bash
#auto check haprox process
#2014-6-30
killall -0 haproxy
 if  [[ $? -ne 0 ]];then
 /etc/init.d/keepalived stop
 fi
chmod u+x check_haproxy.sh
service keepalived restart

四、测试
 把vip  172.20.27.200绑定到你的域名上面进行测试
 1.一直ping 172.20.27.200这个IP,然后把master_ip这台服务器模拟宕机状态。这时候ping会延迟3秒后,自动切换到backup_ip。(说明测试成功)

时间: 2024-10-18 02:49:49

HAProxy+Keepalived高可用负载均衡配置的相关文章

案例一(haproxy+keepalived高可用负载均衡系统)【转】

1.搭建环境描述: 操作系统: [[email protected] ~]# cat /etc/redhat-release CentOS release 6.7 (Final) 地址规划: 主机名 IP地址 集群角色 虚拟IP haproxy-server 10.0.0.35 主HAProxyServer 10.0.0.40 haproxy-backup 10.0.0.36 备用HAProxyServer webapp1 10.0.0.150 Backend Server 无 webapp2

HAProxy+Keepalived 高可用负载均衡

转自 https://www.jianshu.com/p/95cc6e875456 Keepalived+haproxy实现高可用负载均衡 Master 192.168.0.69 haproxy.keepalived Centos7.4 backup 192.168.0.70 haproxy.keepalived Centos7.4 vip(虚拟IP) 192.168.0.180 192.168.0.181 1.两台都安装haproxy,参照安装haproxy文档 2. 两台都安装Keepali

基于HAProxy+Keepalived高可用负载均衡web服务的搭建

一 原理简介 1.HAProxyHAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种解决方案.HAProxy特别适用于那些负载特大的web站点,这些站点通常又需要会话保持或七层处理.HAProxy运行在时下的硬件上,完全可以支持数以万计的并发连接.并且它的运行模式使得它可以很简单安全的整合进当前的架构中, 同时可以保护web服务器不被暴露到网络上.2.KeepalivedKeepalived 是一个基于VRRP协议来实现的LVS服务高

HAProxy+Keepalived高可用负载均衡

一 基础准备 1.1 部署环境及说明 系统OS:CentOS 6.8 64位 HAProxy软件:HA-Proxy version 1.5.18 Keepalived软件:keepalived-1.3.6.tar.gz 官方链接:http://www.haproxy.org/ (国内可能无法打开) 下载连接:http://pkgs.fedoraproject.org/repo/pkgs/haproxy/ 部署说明:当用户访问对应的域名时,HAProxy能将请求发送到对应的后端主机上,同时当主HA

Haproxy + keepalived 高可用负载均衡解决方案

IP 信息列表: 名称     IP -----------------------------------VIP      192.168.200.254 Haproxy-1    192.168.200.202Haproxy-2    192.168.200.204Nginx1     192.168.200.202 Nginx2     192.168.200.203 1.在Nginx1/2上编译安装nginx服务1.1首先安装Nginx1[[email protected] ~]# yu

(2)LVS+Keepalived高可用负载均衡架构原理及配置

1.keepalived 介绍2.keepalived 优缺点3.keepalived 应用场景4.keepalived 安装配置5.keepalived+lvs 高可用6.keepalived+nginx 高可用7.keepalived 切换原理8.性能优化9.常见故障 一.keepalived 介绍 1.keepalived 定义keepalived是一个基于VRRP(virtual route redundent protocol)协议来实现的LVS服务高可用方案,可以利用其来避免单点故障

配置nginx+keepalived高可用负载均衡的时候。主从服务器都出现了VIP 阿里云问题

配置nginx+keepalived高可用负载均衡的时候.主从服务器都出现了VIP 出现这问题的场景是在阿里VPS云服务器网络环境中,因为路由交换层禁用了ARP的广播限制,造成KEEPALIVE主备协议无法通过广播的方式进行通信,造成主备两台服务器都强占HAVIP地址,出现同时两台服务器都有VIP地址的情况出现,必须通过配置来指定IP的两台服务器间进行通讯(阿里说明文档中解释只能支持两台使用同一个HAVIP地址),基于以下方法可以的情况下,多备方式用同样的方式也应该可行 ,有需要的兄弟可以测试下

虚拟机 搭建LVS + DR + keepalived 高可用负载均衡

一:环境说明:   LVS-DR-Master:    10.3.0.82   LVS-DR-Backup:    10.3.0.70   VIP:                10.3.0.60   RealServer1:    10.3.0.69   RealServer1:    10.3.0.83   Centos:5.7    二:安装LVS和Keepalvied软件包   1. 下载相关软件包    mkdir /usr/local/src/lvs    cd /usr/loca

nginx高可用负载均衡配置

Nginx+keepalived 实现高可用负载均衡集群 一.Nginx简介 Nginx ("engine x") 是一个高性能HTTP和反向代理 服务器,也是一个 IMAP/POP3/SMTP 服务器. Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,第一个公开版本0.1.0发布于2004年10月4日.其将源代码以类BSD许可证的形式发布,因它的稳定性.丰富的功能集.示例配置文件和低系统资源的消耗而闻名.2011年6月1日,nginx