haproxy + keepalived 实现网站高可靠

haproxy 1的配置文件,包括 keepalived 和 haproxy 的配置,分别如下:

【haproxy 1的keepalived 配置文件】  /etc/keepalived/keepalived.conf

global_defs {
router_id NodeB
}
vrrp_instance VI_1 {
state BACKUP #设置为主服务器
interface ens33 #监测网络接口
virtual_router_id 51 #主、备必须一样
priority 90 #(主、备机取不同的优先级,主机值较大,备份机值较小,值越大优先级越高)
advert_int 1 #VRRP Multicast广播周期秒数
authentication {
auth_type PASS #VRRP认证方式,主备必须一致
auth_pass 1111 #(密码)
}
virtual_ipaddress {
192.168.248.200
}

【haproxy 1的haproxy.conf 配置文件】  /etc/haproxy/haproxy.cfg

#---------------------------------------------------------------------
# Example configuration for a possible web application. See the
# full configuration options online.
#
# http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------

#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events. This is done
# by adding the ‘-r‘ option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
log 127.0.0.1 local2

chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon

# turn on stats unix socket
stats socket /var/lib/haproxy/stats

#---------------------------------------------------------------------
# common defaults that all the ‘listen‘ and ‘backend‘ sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------

frontend web *:80
frontend web1 192.168.248.200:80
# bind 192.168.248.200:80
mode http
use_backend app

#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static
balance roundrobin
server static 127.0.0.1:4331 check

#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend app
balance roundrobin
server app1 192.168.248.144:80 check
server app2 192.168.248.146:80 check

【haproxy 2的keepalived 配置文件】

global_defs {
router_id NodeB
}
vrrp_instance VI_1 {
state BACKUP #设置为主服务器
interface ens33 #监测网络接口
virtual_router_id 51 #主、备必须一样
priority 90 #(主、备机取不同的优先级,主机值较大,备份机值较小,值越大优先级越高)
advert_int 1 #VRRP Multicast广播周期秒数
authentication {
auth_type PASS #VRRP认证方式,主备必须一致
auth_pass 1111 #(密码)
}
virtual_ipaddress {
192.168.248.200
}

【haproxy 2的haproxy.cfg】 /etc/haproxy/haproxy.cfg

#---------------------------------------------------------------------
# Example configuration for a possible web application. See the
# full configuration options online.
#
# http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------

#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events. This is done
# by adding the ‘-r‘ option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
log 127.0.0.1 local2

chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon

# turn on stats unix socket
stats socket /var/lib/haproxy/stats

#---------------------------------------------------------------------
# common defaults that all the ‘listen‘ and ‘backend‘ sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------

frontend web *:80
frontend web1 192.168.248.200:80
# bind 192.168.248.200:80
mode http
use_backend app

#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static
balance roundrobin
server static 127.0.0.1:4331 check

#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend app
balance roundrobin
server app1 192.168.248.144:80 check
server app2 192.168.248.146:80 check

【web 服务器1 的http index文件内容】

[[email protected] zhou]# yum install -y httpd

[[email protected] zhou]# echo "Hello I am nginx-backend 1. " > /var/www/html/index.html
[[email protected] zhou]# service httpd start
Redirecting to /bin/systemctl start httpd.service
[[email protected] zhou]# firewall-cmd --permanent --add-port=80/tcp
success
[[email protected] zhou]# firewall-cmd --reload
success
[[email protected] zhou]#

【web 服务器2 的http index文件内容】

[[email protected] zhou]# yum install -y httpd

[[email protected] zhou]# echo "Hello I am nginx-backend 2. " > /var/www/html/index.html
[[email protected] zhou]# service httpd start
Redirecting to /bin/systemctl start httpd.service
[[email protected] zhou]# firewall-cmd --permanent --add-port=80/tcp
success
[[email protected] zhou]# firewall-cmd --reload
success
[[email protected] zhou]#

【haproxy 1的服务启动】 haproxy 2与之相同。

keepalived -f /etc/keepalived/keepalived.conf

haproxy   -f   /etc/haproxy/haproxy.cfg

firewall-cmd --permenant --add-port=80/tcp

firewall-cmd --reload

【验证结果】

如果关闭掉一个haproxy ,则不影响系统的正常工作,web网站还是可以正常访问,并且是轮询的结果。

时间: 2024-11-19 06:26:08

haproxy + keepalived 实现网站高可靠的相关文章

HAproxy+Keepalived负载均衡-高可用web站

haproxy+keepalived负载均衡高可用web站   OS IP 子网掩码 路由网关 Centos6.6 HAproxy Keepalived Eth0:192.168.26.210 255.255.252.0 192.168.25.3 VIP:192.168.27.210 Centos6.6 HAporxy Keepalived Eth0:192.168.26.211 255.255.252.0 192.168.25.3 VIP:192.168.27.210 Centos6.6(WE

Haproxy+Keepalived搭建Weblogic高可用负载均衡集群

配置环境说明:   KVM虚拟机配置 用途 数量 IP地址 机器名 虚拟IP地址 硬件 内存3G  系统盘20G cpu 4核 Haproxykeepalived 2台 192.168.1.10192.168.1.20 Haserver01Haserver02 192.168.30192.168.40 内存6G  系统盘20G cpu 4核 Weblogic 4台 192.168.1.100192.168.1.150 192.168.1.200 192.168.1.250 Clusters01C

HAproxy+keepalived/pacemaker实现高可用,负载均衡技术

HAproxy+keepalived/pacemaker Haproxy+keepalived的结合,实现负载均衡与高可用的完美结合,既解决了提供服务的负载均衡,又解决了作负载均衡器的单点故障问题.这样架构就很健壮了. 材料准备: keepalived-1.2.20.tar.gz 步骤: #tar -zxf  keepalived-1.2.20.tar.gz    :解压源码包,进行编译安装 #cd   keepalived-1.2.20 #yum  install  -y  gcc  open

实现基于Haproxy+Keepalived负载均衡高可用架构

一:环境准备 centos系统服务器4台,两台用于做haproxy主从架构, 两台作为后端server,服务器配置好yum源,防火墙关闭, 关闭selinux,各节点时钟服务同步,各节点之间可以通过主机名互相通信. 二:安装步骤 1.iptables –F &&setenforing 清空防火墙策略,关闭selinux. 2.拿两台服务器都使用yum方式安haproxy,keepalived 服务 3.后端服务器配置好基于LNMP架构的web服务 当准备工作做好之后,就可以修改配置文件啦,

Haproxy+Keepalived实现网站双主高可用-理论篇

一.Haproxy简介 HAProxy是一款提供高可用性.负载均衡以及基于TCP(第四层)和HTTP(第七层)应用的代理软件,HAProxy是完全免费的.借助HAProxy可以快速并且可靠的提供基于TCP和HTTP应用的代理解决方案. (1)免费开源,稳定性也是非常好,稳定性可以与硬件级的F5相媲美: (2)根据官方文档,HAProxy可以跑满10Gbps-Newbenchmark of HAProxy at 10 Gbps using Myricom's 10GbE NICs (Myri-10

haproxy+keepalived实现负载均衡及高可用

HAProxy是一个使用C语言编写的自由及开放源代码软件,其提供高性能性.负载均衡,以及基于TCP和HTTP的应用程序代理.相较与 Nginx,HAProxy 更专注与反向代理,因此它可以支持更多的选项,更精细的控制,更多的健康状态检测机制和负载均衡算法. HAProxy特别适用于那些负载特大的web站点,这些站点通常又需要会话保持或七层处理.HAProxy运行在当前的硬件上,完全可以支持数以万计的并发连接.并且它的运行模式使得它可以很简单安全的整合进您当前的架构中, 同时可以保护你的web服务

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

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

Haproxy+Keepalived高可用环境部署梳理(主主和主从模式)

Nginx.LVS.HAProxy 是目前使用最广泛的三种负载均衡软件,本人都在多个项目中实施过,通常会结合Keepalive做健康检查,实现故障转移的高可用功能. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

haproxy+keepalived实现高可用负载均衡web集群

haproxy+keepalived实现高可用负载均衡web集群 负载均衡集群的概念 负载均衡是设计分布式系统架构必须要考虑的因素之一,它指的是通过调度分发的方式尽可能将"请求"."访问"的压力负载平均分摊到集群中的各个节点,避免有些节点负载太高导致访问延迟,而有些节点负载很小导致资源浪费.这样,每个节点都可以承担一定的访问请求负载压力,并且可以实现访问请求在各节点之间的动态分配,以实现负载均衡,从而为企业提供更高性能,更加稳定的系统架构解决方案. 高可用集群的概念