postgres高可用学习篇三:haproxy+keepalived实现postgres负载均衡
环境: CentOS Linux release 7.6.1810 (Core) 内核版本:3.10.0-957.10.1.el7.x86_64
node1:192.168.216.130
node2:192.168.216.132
node3:192.168.216.134
VIP:192.168.216.138
基础环境准备
优化内核参数cat /etc/sysctl.conf
net.netfilter.nf_conntrack_tcp_be_liberal=1
vm.swappiness=1
vm.min_free_kbytes=102400
vm.dirty_expire_centisecs=1000
vm.dirty_background_bytes=67108864
vm.dirty_bytes=536870912
vm.zone_reclaim_mode=0
kernel.numa_balancing=0
kernel.sched_migration_cost_ns=5000000
kernel.sched_autogroup_enabled=0
net.ipv4.ip_nonlocal_bind=1
net.ipv4.ip_forward=1
net.ipv4.ip_local_port_range=1024 65535
net.netfilter.nf_conntrack_max=1048576
一、安装haproxy
yum install centos-release-scl -y
yum install rh-haproxy18-haproxy rh-haproxy18-haproxy-syspaths -y
开机启动:
systemctl enable rhhaproxy18-haproxy
启动:
systemctl start rh-haproxy18-haproxy
在node1、node2、node3分别修改配置文件haproxy.cfg,并启动haproxy服务
5000读写/5001只读、5002同步模式/5003异步模式(默认异步模式)
cat /etc/haproxy/haproxy.cfg
global
maxconn 100000
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
stats timeout 30s
user haproxy
group haproxy
daemon defaults
mode tcp
log global
retries 2
timeout queue 5s
timeout connect 5s
timeout client 60m
timeout server 60m
timeout check 15s listen stats
mode http
bind 192.168.216.130:7000
stats enable
stats uri / listen master
bind 192.168.216.138:5000
maxconn 10000
option tcplog
option httpchk OPTIONS /master
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 4 on-marked-down shutdown-sessions
server pgnode01 192.168.216.130:6432 check port 8008
server pgnode02 192.168.216.132:6432 check port 8008
server pgnode03 192.168.216.134:6432 check port 8008 listen replicas
bind 192.168.216.138:5001
maxconn 10000
option tcplog
option httpchk OPTIONS /replica
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
server pgnode01 192.168.216.130:6432 check port 8008
server pgnode02 192.168.216.132:6432 check port 8008
server pgnode03 192.168.216.134:6432 check port 8008 listen replicas_sync
bind 192.168.216.138:5002
maxconn 10000
option tcplog
option httpchk OPTIONS /sync
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
server pgnode01 192.168.216.130:6432 check port 8008
server pgnode02 192.168.216.132:6432 check port 8008
server pgnode03 192.168.216.134:6432 check port 8008 listen replicas_async
bind 192.168.216.138:5003
maxconn 10000
option tcplog
option httpchk OPTIONS /async
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
server pgnode01 192.168.216.130:6432 check port 8008
server pgnode02 192.168.216.132:6432 check port 8008
server pgnode03 192.168.216.134:6432 check port 8008
haproxy默认不开启日志记录,haproxy启用日志记录方法
参考:https://blog.csdn.net/eddie_cm/article/details/79794432
二、1、分别在node1、node2、node3节点安装keepalived
yum install -y epel-release
yum install -y keepalived
2、更改node1节点上的keepalived.conf
配置文件
cat /etc/keepalived/keepalived.conf
global_defs {
router_id ocp_vrrp
} vrrp_script haproxy_check {
script "/bin/kill -0 `cat /var/run/haproxy/haproxy.pid`"
interval 2
weight 2
} vrrp_instance VI_1 {
interface ens32
virtual_router_id 133
priority 100
advert_int 2
state BACKUP
virtual_ipaddress {
192.168.216.138
}
track_script {
haproxy_check
}
authentication {
auth_type PASS
auth_pass 1ce24b6e
}
}
这里需要注意的是:"virtual_ipaddress"也就是所谓的vip我们设置为192.168.216.138
3、更改node2节点上的keepalived.conf
配置文件
[root@pgnode02 ~]# cat /etc/keepalived/keepalived.conf
global_defs {
router_id ocp_vrrp
} vrrp_script haproxy_check {
script "/bin/kill -0 `cat /var/run/haproxy/haproxy.pid`"
interval 2
weight 2
} vrrp_instance VI_1 {
interface ens32
virtual_router_id 133
priority 100
advert_int 2
state BACKUP
virtual_ipaddress {
192.168.216.138
}
track_script {
haproxy_check
}
authentication {
auth_type PASS
auth_pass 1ce24b6e
}
}
这里需要注意的是:"virtual_ipaddress"也就是所谓的vip我们设置为192.168.216.138
4、更改node3节点上的keepalived.conf
配置文件
[root@localhost keepalived]# cat /etc/keepalived/keepalived.conf
global_defs {
router_id ocp_vrrp
} vrrp_script haproxy_check {
script "/bin/kill -0 `cat /var/run/haproxy/haproxy.pid`"
interval 2
weight 2
} vrrp_instance VI_1 {
interface ens32
virtual_router_id 133
priority 100
advert_int 2
state BACKUP
virtual_ipaddress {
192.168.216.138
}
track_script {
haproxy_check
}
authentication {
auth_type PASS
auth_pass 1ce24b6e
}
}
这里需要注意的是:"virtual_ipaddress"也就是所谓的vip我们设置为192.168.216.138
5、依次在node1、node2、node3上启动keepalived
systemctl start keepalived
验证node1、node2、node3上keepalived启动状态,VIP跟随master进行漂移
node2 :
node3:
postgres高可用学习篇三:haproxy+keepalived实现postgres负载均衡的更多相关文章
- postgres高可用学习篇二:通过pgbouncer连接池工具来管理postgres连接
安装pgbouncer yum install libevent -y yum install libevent-devel -y wget http://www.pgbouncer.org/down ...
- postgres高可用学习篇一:如何通过patroni如何管理3个postgres节点
环境: CentOS Linux release 7.6.1810 (Core) 内核版本:3.10.0-957.10.1.el7.x86_64 node1:192.168.216.130 node2 ...
- Linux服务之nginx服务篇三(反向代理、负载均衡)
一.Nginx实现反向代理 概念 反向代理:在收到客户端请求之后,会修目标IP地址和端口 正向代理:在收到客户端请求之后,会修源IP地址和端口 上游服务器:代理服务器后端的哪些真正给客户端提供服务的节 ...
- 【DB宝42】MySQL高可用架构MHA+ProxySQL实现读写分离和负载均衡
目录 一.MHA+ProxySQL架构 二.快速搭建MHA环境 2.1 下载MHA镜像 2.2 编辑yml文件,创建MHA相关容器 2.3 安装docker-compose软件(若已安装,可忽略) 2 ...
- DR模式下的高可用的LVS(LVS+keepalived)
一.keepalived 在DR模式下,使用Keepalived实现LVS的高可用.Keepalived的作用是检测服务器的状态,如果有一台web服务器 宕机,或工作出现故障,Keepalived将检 ...
- 企业级Nginx负载均衡与keepalived高可用实战(二)keepalived篇
1.Keepalived高可用软件 1.1.Keepalived介绍 Keepalived软件起初是专门为LVS负载均衡软件设计的,用来管理并监控LVS集群系统中各个服务节点的状态,后来又加入了可以实 ...
- Keepalived+LVS+Nginx负载均衡之高可用
Keepalived+LVS+Nginx负载均衡之高可用 上一篇写了nginx负载均衡,此篇实现高可用(HA).系统整体设计是采用Nginx做负载均衡,若出现Nginx单机故障,则导致整个系统无法正常 ...
- 高可用架构篇--MyCat在MySQL主从复制基础上实现读写分离
实战操作可参考:http://www.roncoo.com/course/view/3117ffd4c74b4a51a998f9276740dcfb 一.环境 操作系统:CentOS-6.6-x86_ ...
- lvs+keepalived+bind实现负载均衡高可用智能dns【转】
转:https://www.cnblogs.com/mikeluwen/p/7068356.html 整体架构: 1.IP地址规划: Dns1:172.28.0.54 Dns2:172.28.0.55 ...
随机推荐
- 17 SpringMVC response响应
1.Model.ModelMap和ModelAndView的使用详解 Spring-MVC在请求处理方法可出现和返回的参数类型中,最重要就是Model和ModelAndView了,对于MVC框架,控制 ...
- window 关机
schtasks /create /tn "关机" /tr "shutdown /s" /sc once /st 20:30
- dp --- 二维dp + 最大上升子序列
<传送门> 滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 74477 Accepted: 27574 ...
- Java操作JSON数据(3)--fastjson操作JSON数据
fastjson是阿里巴巴的开源JSON解析库,它可以解析JSON格式的字符串,支持将Java Bean序列化为JSON字符串,也可以从JSON字符串反序列化到JavaBean.本文介绍下fastjs ...
- C++ Clock函数调用及用途
用途1 Clock函数可以有效地针对一些只能用随机化做的题目 为了提高该类代码的正确性,我们期望它运行的次数在要求时限内运行足够多 因此将Clock函数充当计时器 用途2 计时判断负环 原理: 给定一 ...
- day53——标签操作
day53 今日内容 标签操作 值操作 取值: 文本输入框:$('#username').val(); input,type=radio单选框: $('[type="radio"] ...
- SPOJ Qtree系列
Qtree1 将边权变为这条边连接的两个点中深度更深的点的点权,这样就可以变为带修改链上最大点权.直接树链剖分即可. 下面是一份C语言代码 #include<stdio.h> #inclu ...
- angular复习笔记1-开篇
前言 学习和使用angular已经有一段时间了.这段时间利用angular做了一个系统,算是对angular有了一个全面的认识,趁着现在有一些时间,把angular的一些知识记录一下. 安装angul ...
- linux 安装Python3.6
1.安装依赖 yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel ...
- 【开发工具】- 设置Sublime支持韩文展示
菜单栏 --> 首选项 --> 设置 -->User 添加以下代码 { "font_size": 12, "show_encoding":tr ...