005.HAProxy+Keepalived高可用负载均衡
一 基础准备
1.1 部署环境及说明
主机名
|
主机IP地址
|
集群角色
|
虚机IP/域名
|
master
|
172.24.8.10
|
主HAProxy服务器
|
172.24.8.100
|
backup
|
172.24.8.11
|
备HAProxy服务器
|
|
webapp1
|
172.24.8.30
|
后端web服务器
|
www.lz.com
|
webapp2
|
172.24.8.31
|
static.lz.com
|
|
webapp3
|
172.24.8.32
|
video.lz.com
|
1.2 架构规划
二 后端httpd集群部署
2.1 部署httpd集群
[root@webapp1 ~]# yum -y install httpd
[root@webapp1 ~]# vi /var/www/html/index.html
This is my www.lz.com!
[root@webapp1 ~]# vi /var/www/html/index.html
This is my static.lz.com!
[root@webapp1 ~]# vi /var/www/html/index.html
This is my video.lz.com!
[root@webapp1 ~]# systemctl start httpd.service
[root@webapp1 ~]# systemctl enable httpd.service
[root@webapp1 ~]# systemctl stop firewalld.service
[root@webapp1 ~]# systemctl disable firewalld.service
[root@webapp1 ~]# vi /etc/selinux/config
SELINUX=disabled
[root@webapp1 ~]# setenforce 0 #关闭SELinux及防火墙
三 基础NTP部署
3.1 NTP部署
[root@webapp1 ~]# yum -y install ntp
[root@webapp1 ~]# systemctl start ntpd.service
四 Keepalived部署
4.1 编译环境
# yum -y install gcc gcc-c++ make kernel-devel kernel-tools kernel-tools-libs kernel libnl libnl-devel libnfnetlink-devel openssl-devel wget openssh-clients
4.2 安装Keepalived
[root@haproxy_master ~]# wget http://www.keepalived.org/software/keepalived-1.3.6.tar.gz
[root@haproxy_master ~]# tar -zxvf keepalived-1.3.6.tar.gz
[root@haproxy_master ~]# cd keepalived-1.3.6/
[root@lvsmaster keepalived-1.3.6]# ./configure --prefix=/usr/local/keepalived
[root@haproxy_master keepalived-1.3.6]# make && make install
4.3 添加Keepalived启动相关服务
[root@haproxy_master ~]# mkdir /etc/keepalived
[root@haproxy_master ~]# cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
[root@haproxy_master ~]# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
[root@haproxy_master ~]# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
[root@haproxy_master ~]# vi /etc/init.d/keepalived #创建Keepalived启动脚本,见附件
[root@haproxy_master ~]# chmod u+x /etc/rc.d/init.d/keepalived
4.4 配置Keepalived
[root@haproxy_master ~]# vi /etc/keepalived/keepalived.conf
global_defs {
notification_email {
#……
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
} vrrp_script check_haproxy {
script "/usr/bin/killall -0 haproxy"
interval 2
weight 21
} vrrp_instance HAProxy_HA {
state BACKUP #在HAProxy主备均设置为BACKUP
interface eth0
virtual_router_id 80
priority 100
advert_int 2
nopreempt #不抢占模式
authentication {
auth_type PASS
auth_pass 1111
} notify_master "/etc/keepalived/master.sh"
notify_backup "/etc/keepalived/backup.sh"
notify_fault "/etc/keepalived/fault.sh" track_script {
check_haproxy
} virtual_ipaddress {
172.24.8.100 dev eth0
}
}
4.5 编写Keepalived脚本
[root@haproxy_master ~]# vi /etc/keepalived/master.sh
#!/bin/bash
LOGFILE=/var/log/keepalived-mysql-state/log
date >>$LOGFILE
echo "[Master]" >>$LOGFILE
[root@haproxy_master ~]# vi /etc/keepalived/backup.sh
#!/bin/bash
LOGFILE=/var/log/keepalived-mysql-state/log
date >>$LOGFILE
echo "[BACKUP]" >>$LOGFILE
[root@haproxy_master ~]# vi /etc/keepalived/fault.sh
#!/bin/bash
LOGFILE=/var/log/keepalived-mysql-state/log
date >>$LOGFILE
echo "[FAULT]" >>$LOGFILE
[root@haproxy_master ~]# chmod u+x /etc/keepalived/backup.sh
[root@haproxy_master ~]# chmod u+x /etc/keepalived/master.sh
[root@haproxy_master ~]# chmod u+x /etc/keepalived/fault.sh
4.5 Bakcup节点配置
[root@haproxy_master ~]# scp /etc/keepalived/keepalived.conf 172.24.8.11:/etc/keepalived/keepalived.conf #将配置好的Master节点的配置文件复制到Backup节点
[root@haproxy_slave ~]# vi /etc/keepalived/keepalived.conf
state BACKUP
priority 80
[root@haproxy_master ~]# scp /etc/keepalived/*.sh 172.24.8.11:/etc/keepalived/
#将对应的脚本也复制至backup节点。
五 HAProxy部署
5.1 HAProxy安装
[root@haproxy_master ~]# yum -y install haproxy
5.2 HAProxy配置
[root@haproxy_master ~]# vi /etc/haproxy/haproxy.cfg
global
log 127.0.0.1 local0 info
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4096
user haproxy
group haproxy
daemon
nbproc 1
defaults
mode http
log global
retries 3
timeout connect 5s
timeout client 30s
timeout server 30s
timeout check 2s
frontend www
bind 172.24.8.100:80
mode http
option httplog
option forwardfor
log global acl host_www hdr_dom(host) -i www.lz.com #配置不同域名分发不同后端策略
acl host_static hdr_dom(host) -i static.lz.com
acl host_video hdr_dom(host) -i video.lz.com use_backend server_www if host_www #配置不同域名分发不同后端策略
use_backend server_static if host_static
use_backend server_video if host_video
backend server_www #后端真是服务器
mode http
option redispatch
option abortonclose
balance roundrobin
option httpchk GET /index.html
server webapp1 172.24.8.30:80 weight 6 check inter 2000 rise 2 fall 3
backend server_static #后端真是服务器
mode http
option redispatch
option abortonclose
balance roundrobin
option httpchk GET /index.html
server webapp2 172.24.8.31:80 weight 6 check inter 2000 rise 2 fall 3
backend server_video #后端真是服务器
mode http
option redispatch
option abortonclose
balance roundrobin
option httpchk GET /index.html
server webapp3 172.24.8.32:80 weight 6 check inter 2000 rise 2 fall 3
[root@haproxy_master ~]# scp /etc/haproxy/haproxy.cfg root@172.24.8.11:/etc/haproxy/haproxy.cfg #将配置文件复制至HAProxy备节点
5.3 打开转发
[root@haproxy_master ~]# vi /etc/sysctl.conf
net.ipv4.ip_nonlocal_bind = 1
[root@haproxy_master ~]# sysctl -p
六 启动服务
[root@webapp1 ~]# systemctl start httpd
[root@haproxy_master ~]# service haproxy start
[root@haproxy_master ~]# service keepalived start
七 验证测试
7.1 高可用验证
[root@haproxy_master ~]# ip add
[root@haproxy_master ~]# service haproxy stop #停止HAProxy主节点的HAProxy进程
[root@haproxy_master ~]# tail -f /var/log/messages #观察HAProxy主节点日志
[root@haproxy_slave ~]# ip addr #查看备HAProxy节点的IP
[root@haproxy_master ~]# service haproxy start
7.2 负载均衡测试
172.24.8.100 www.lz.com
172.24.8.100 static.lz.com
172.24.8.100 video.lz.com
005.HAProxy+Keepalived高可用负载均衡的更多相关文章
- 案例一(haproxy+keepalived高可用负载均衡系统)【转】
1.搭建环境描述: 操作系统: [root@HA-1 ~]# cat /etc/redhat-release CentOS release 6.7 (Final) 地址规划: 主机名 IP地址 集群角 ...
- HAProxy+Keepalived 高可用负载均衡
转自 https://www.jianshu.com/p/95cc6e875456 Keepalived+haproxy实现高可用负载均衡 Master backup vip(虚拟IP) 192.16 ...
- 基于HAProxy+Keepalived高可用负载均衡web服务的搭建
一 原理简介 1.HAProxyHAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种解决方案.HAProxy特别适用于那些负载特大的web ...
- HAProxy+Keepalived高可用负载均衡
一 基础准备 1.1 部署环境及说明 系统OS:CentOS 6.8 64位 HAProxy软件:HA-Proxy version 1.5.18 Keepalived软件:keepalived-1.3 ...
- Haproxy+Keepalived高可用负载均衡详细配置
本文所使用的环境: 10.6.2.128 centos6.5 10.6.2.129 centos6.5 VIP 为10.6.2.150 要实现的目标: 实现10.6.2.128和10.6 ...
- 测试LVS+Keepalived高可用负载均衡集群
测试LVS+Keepalived高可用负载均衡集群 1. 启动LVS高可用集群服务 此时查看Keepalived服务的系统日志信息如下: [root@localhost ~]# tail -f /va ...
- LVS+Keepalived高可用负载均衡集群架构实验-01
一.为什么要使用负载均衡技术? 1.系统高可用性 2. 系统可扩展性 3. 负载均衡能力 LVS+keepalived能很好的实现以上的要求,LVS提供负载均衡,keepalived提供健康检查, ...
- 使用Ansible实现nginx+keepalived高可用负载均衡自动化部署
本篇文章记录通过Ansible自动化部署nginx的负载均衡高可用,前端代理使用nginx+keepalived,端web server使用3台nginx用于负载效果的体现,结构图如下: 部署前准备工 ...
- Keepalived+HAProxy 搭建高可用负载均衡
转载自:https://mp.weixin.qq.com/s/VebiWftaRa26x1aA21Jqww 1. 概述 软件负载均衡技术是指可以为多个后端服务器节点提供前端IP流量分发调度服务的软件技 ...
随机推荐
- Flask最强攻略 - 跟DragonFire学Flask - 第八篇 实例化Flask的参数 及 对app的配置
Flask 是一个非常灵活且短小精干的web框架 , 那么灵活性从什么地方体现呢? 有一个神奇的东西叫 Flask配置 , 这个东西怎么用呢? 它能给我们带来怎么样的方便呢? 首先展示一下: from ...
- Microservice Patterns
https://www.manning.com/books/microservice-patterns http://www.jianshu.com/p/2f32ac949138
- POI读取Excel(xls、xlsx均可以)——(四)
maven构建的项目-->pom.xml文件 eclipse提供Dependencies直接添加依赖jar包的工具:直接搜索poi以及poi-ooxml即可,maven会自动依赖需要的jar包: ...
- Jetson tk1 安装OpenNI 1 +Xtion Pro +NiTE
参考: http://blog.csdn.net/xiabodan/article/details/44496871 序: 由于第三方库 NiTE2.0 不支持 arm 架构的处理器,因此需要安装Op ...
- c++动态库封装及调用(3、windows下动态库调用)
1.DLL的隐式调用 隐式链接采用静态加载的方式,比较简单,需要.h..lib..dll三件套.新建“控制台应用程序”或“空项目”.配置如下: 项目->属性->配置属性->VC++ ...
- Linux驱动技术(三) _DMA编程【转】
转自:https://www.cnblogs.com/xiaojiang1025/archive/2017/02/11/6389194.html DMA即Direct Memory Access,是一 ...
- dubbo 一个接口多个实现
<dubbo:service ref="dubboGroupService1" interface="com.yncp.dubbo.service.IDubboGr ...
- linux windows 共享文件夹
1.首先在windows上共享一个目录,如:共享了目录share,用户和密码都是:massky 2.在linux机器上,在/mnt目录下建立一个ml45目录,使用root用户,执行下面命令: moun ...
- cas中总是得不到返回的属性
cas可以登录,但是得不到返回的属性,后来看日志才知道数据库链接报错,原来URL中少了jdbc:.真是愚蠢的错误,记录之,警之!
- 最全Kafka 设计与原理详解【2017.9全新】
一.Kafka简介 1.1 背景历史 当今社会各种应用系统诸如商业.社交.搜索.浏览等像信息工厂一样不断的生产出各种信息,在大数据时代,我们面临如下几个挑战: 如何收集这些巨大的信息 如何分析它 如何 ...