PostgreSQL+Pgpool实现HA主备切换的操作

PostgreSQL流复制实现HA主备切换

环境说明和主机规划

操作系统 主机名 主机 角色 端口
CentOS 7 master 10.0.0.11 PG-Master 54321
CentOS 7 slave 10.0.0.12 PG-Slave 54321
CentOS 7 pool 10.0.0.13 pgpool 54321

基础环境配置(所有主机操作)

配置HOSTS

echo -e "10.0.0.11 master\n10.0.0.12 slave\n10.0.0.13 pool" >> /etc/hosts # 执行一次即可

配置统一的时间(若已配置,请忽略)

yum install -y ntpdate && ntpdate ntp1.aliyun.com
echo -e "# sync time from ntp1.aliyun.com\n5 * * * * /usr/sbin/ntpdate ntp1.aliyun.com > /dev/null 2>&1
" >> /var/spool/cron/root # 写入定时任务,执行一次即可

创建postgres用户

useradd postgres && echo "your_password" | passwd --stdin postgres

配置免密钥登陆

su - postgres
ssh-keygen -t rsa -f /home/postgres/.ssh/id_rsa -P ""
cd ~/.ssh/
ssh-copy-id postgres@master # 三台主机执行
scp authorized_keys postgres@slave:~/.ssh # 只在master主机执行
scp authorized_keys postgres@pool:~/.ssh # 只在master主机执行

安装Postgresql数据库(PG9.6)

yum install -y https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm

yum install -y postgresql96-server postgresql96-contrib postgresql96 postgresql96-libs

创建统一的目录结构

mkdir /data1/pg_{data,bin,logs} -p

chown -R postgres.postgres /data1/

修改系统变量

vi /etc/profile #增加以下内容
export PGHOME=/usr/pgsql-9.6/
export PGDATA=/data1/pg_data
export PGPORT=54321
export PATH=$PATH:$PGHOME/bin
# 生效
source /etc/profile

PostgreSQL流复制结构(master和slave主机操作)

master主机操作

初始化系统

/usr/pgsql-9.6/bin/postgresql96-setup initdb

vi /usr/lib/systemd/system/postgresql-9.6.service

修改postgresql-9.6.service

内容如下:

# Include the default config:
.include /usr/lib/systemd/system/postgresql-9.6.service

[Service]
Environment=PGDATA=/data1/pg_data

重启PG服务

systemctl daemon-reload
su - postgres -c '/usr/pgsql-9.6/bin/initdb -D /data1/pg_data'
systemctl restart postgresql-9.6
systemctl enable postgresql-9.6.service

修改系统配置(以下用postgres用户操作)

cp /data1/pg_data/pg_hba.conf{,.bak}
cat >/data1/pg_data/pg_hba.conf<<EOF
local all    all            trust
host all    all      10.0.0.11/32   trust
host all    all      10.0.0.12/32   trust
host all    all      0.0.0.0/0    md5
host all    all      ::1/128     trust
host replication  stream_replication  0.0.0.0/0    md5
EOF
#host replication  stream_replication  0.0.0.0/0    md5 为流复制用户

64G

cp /data1/pg_data/postgresql.conf{,.bak}
cat >/data1/pg_data/postgresql.conf<<EOF
listen_addresses = '*'
port = 54321
max_connections = 256
shared_buffers = 16GB
effective_cache_size = 48GB
work_mem = 64MB
maintenance_work_mem = 2GB
min_wal_size = 2GB
max_wal_size = 4GB
checkpoint_completion_target = 0.9
wal_buffers = 16MB
default_statistics_target = 100
wal_level = hot_standby
wal_log_hints = on
max_wal_senders = 1
hot_standby = on
logging_collector = on
log_directory = 'pg_log'
EOF
#操作完记得重启 pg_ctl restart

128G

listen_addresses = '*'
port = 54321
max_connections = 256
shared_buffers = 32GB
effective_cache_size = 96GB
work_mem = 128MB
maintenance_work_mem = 2GB
min_wal_size = 2GB
max_wal_size = 4GB
checkpoint_completion_target = 0.9
wal_buffers = 16MB
default_statistics_target = 100
wal_level = hot_standby
wal_log_hints = on
max_wal_senders = 1
hot_standby = on
logging_collector = on
log_directory = 'pg_log'

在主库中创建流复制用户(stream_replication)和PGPool用户(srcheck)

CREATE USER stream_replication replication LOGIN CONNECTION LIMIT 5 ENCRYPTED PASSWORD 'your_password';

CREATE USER srcheck replication LOGIN CONNECTION LIMIT 5 ENCRYPTED PASSWORD 'your_password';

修改主库pg_hba.conf文件(已操作见cat >/data1/pg_data/pg_hba.conf<<EOF)

host replication stream_replication 0.0.0.0/0 md5

slave主机操作

初始化系统

/usr/pgsql-9.6/bin/postgresql96-setup initdb

vi /usr/lib/systemd/system/postgresql-9.6.service

修改postgresql-9.6.service

内容如下:

# Include the default config:
.include /usr/lib/systemd/system/postgresql-9.6.service

[Service]
Environment=PGDATA=/data1/pg_data

重启PG服务

systemctl daemon-reload

基础备份复制到备库服务器

rm -rf /data1/pg_data # 如果没有重要数据可操作,主要为同步主库路径

su - postgres -c 'pg_basebackup -D $PGDATA --format=p -h master -p 54321 -U stream_replication -W'

修改备库配置信息

cp $PGHOME/share/recovery.conf.sample $PGDATA/recovery.conf

vi $PGDATA/recovery.conf

增加以下内容

standby_mode='on'
primary_conninfo = 'host=master port=54321 user=stream_replication password=your_password'
restore_command = ''
recovery_target_timeline = 'latest'
# 重启PG服务
systemctl restart postgresql-9.6
systemctl enable postgresql-9.6.service

验证

主节点执行

create table test (id int4, create_time timestamp(0) without time zone);
insert into test values (1, now());
select * from test;

备节点执行

select * from test;

其他查询

进入测试数据库test,主库上执行如下命令返回f,备库上返回t。 select pg_is_in_recovery();

执行如下命令查看快照,它返回主库记录点、备库记录点;主库每增加一条写入,记录点的值就会加1。

select txid_current_snapshot();

执行如下命令可以查看主备同步状态。

select * from pg_stat_replication;

字段state显示的同步状态有:startup(连接中)、catchup(同步中)、streaming(同步);字段sync_state显示的模式有:async(异步)、sync(同步)、potential(虽然现在是异步模式,但是有可能升级到同步模式)。

主备切换

假设主库崩溃了,备库如何从只读状态切换为读写状态呢?只要把备库的postgresql.conf中hot_standby修改为off,并且删除recovery.conf,然后重启库就可以提供服务了。

PGPool2(pool主机操作)

安装PGPool2

yum install -y http://www.pgpool.net/yum/rpms/3.6/redhat/rhel-7-x86_64/pgpool-II-release-3.6-1.noarch.rpm
yum -y install pgpool-II-pg96 pgpool-II-pg96-debuginfo pgpool-II-pg96-devel pgpool-II-pg96-extensions
systemctl enable pgpool.service #开启自动启动

添加Pgpool-II运行用户

useradd postgres # 环境准备时已操作
chown -R postgres.postgres /etc/pgpool-II
chown -R postgres.postgres /var/run/pgpool/

配置pool_hba.conf

cp /etc/pgpool-II/pool_hba.conf{,.bak}

vi /etc/pgpool-II/pool_hba.conf

增加内容

host all all 0.0.0.0/0 md5

配置pcp.conf

主节点登陆后执行:

postgres=# select rolname,rolpassword from pg_authid;
  rolname  |    rolpassword
--------------------+-------------------------------------
 pg_signal_backend |
 srcheck   | md5662c10f61b27a9ab38ce69157186b25f
 postgres   | md5d3612d57ee8d4c147cf27b11e3a0974d
 stream_replication | md59279ef6b904bc483e4f85e6d44cfc0ed
(4 rows)

vi /etc/pgpool-II/pool_passwd

增加SQL执行结果的内容,形式为$rolname:$rolpassword例如:

srcheck:md5662c10f61b27a9ab38ce69157186b25f

或者:

pg_md5 -u postgres your_password

vi /etc/pgpool-II/pcp.conf ## 加入 postgres:上一命令的输出

配置pgpool.conf

cp /etc/pgpool-II/pgpool.conf{,.bak}

vi /etc/pgpool-II/pgpool.conf

内容如下:

# CONNECTIONS

listen_addresses = '*'
port = 54321
socket_dir = '/var/run/pgpool'
pcp_listen_addresses = '*'
pcp_port = 9898
pcp_socket_dir = '/var/run/pgpool'

# - Backend Connection Settings -

backend_hostname0 = 'master'
backend_port0 = 54321
backend_weight0 = 1
backend_data_directory0 = '/data1/pg_data'
backend_flag0 = 'ALLOW_TO_FAILOVER'

backend_hostname1 = 'slave'
backend_port1 = 54321
backend_weight1 = 1
backend_data_directory1 = '/data1/pg_data'
backend_flag1 = 'ALLOW_TO_FAILOVER'

# - Authentication -

enable_pool_hba = on
pool_passwd = 'pool_passwd'

# FILE LOCATIONS

pid_file_name = '/var/run/pgpool/pgpool.pid'
logdir = '/data1/pg_logs'

replication_mode = off
load_balance_mode = on
master_slave_mode = on
master_slave_sub_mode = 'stream'

sr_check_period = 5
sr_check_user = 'srcheck'
sr_check_password = '123456'
sr_check_database = 'postgres'

# HEALTH CHECK 健康检查

health_check_period = 10
health_check_timeout = 20
health_check_user = 'srcheck'
health_check_password = '123456'
health_check_database = 'postgres'

# FAILOVER AND FAILBACK

failover_command = '/data1/pg_bin/failover_stream.sh %H'

failover_stream.sh脚本

vim /data1/pg_bin/failover_stream.sh
chmod 777 /data1/pg_bin/failover_stream.sh
chmod u+s /sbin/ifconfig
chmod u+s /usr/sbin
pgpool -n -d -D > /data1/pg_logs/pgpool.log 2>&1 & ## 启动
pgpool -m fast stop ## 关闭

failover_stream.sh内容:

#! /bin/sh
# Failover command for streaming replication.
# Arguments: $1: new master hostname. 

new_master=$1
trigger_command="$PGHOME/bin/pg_ctl promote -D $PGDATA" 

# Prompte standby database.
/usr/bin/ssh -T $new_master $trigger_command 

exit 0;

登陆设置

当执行pgpool -n -d -D > /data1/pg_logs/pgpool.log 2>&1 &后可查看集群状态:

[postgres@pool pgpool-II]$ psql -p 54321 -h 10.0.0.13 -U srcheck -d postgres

postgres=# show pool_nodes;
 node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay
---------+----------+-------+--------+-----------+---------+------------+-------------------+-------------------
 0  | master | 54321 | up  | 0.500000 | primary | 0   | false    | 0
 1  | slave | 54321 | up  | 0.500000 | standby | 0   | true    | 0
(2 rows)

如果未发现集群状态,请在master和slave主机分别执行以下操作:

[postgres@pool ~]$ pcp_attach_node -d -U postgres -h pool -p 9898 -n 0
[postgres@pool ~]$ pcp_attach_node -d -U postgres -h pool -p 9898 -n 1
#详情查询命令pcp_attach_node

HA切换

模拟master主机宕机

Master端:

[postgres@master ~]$ pg_ctl stop
waiting for server to shut down.... done
server stopped

当前集群状态

[postgres@pool ~]$ psql -p 54321 -h 10.0.0.13 -U srcheck -d postgres
psql (9.6.1)
Type "help" for help.

postgres=# show pool_nodes;
 node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay
---------+----------+------+--------+-----------+---------+------------+-------------------+-------------------
 0  | master | 5432 | down| 0.500000 | standby | 0    | false | 0
 1  | slave  | 5432 | up  | 0.500000 | primary | 0    | true | 0
(2 rows)

发现master已经是standby了,且down机了

修改master,启动

当master主机宕机后,此时slave主机PG数据库成为主库,修改master成为slave的从库即可

[postgres@master ~]$ vim recovery.conf
standby_mode='on'
primary_conninfo = 'host=slave port=54321 user=stream_replication password=your_password'
restore_command = ''
recovery_target_timeline = 'latest'

同步时间线

#如果报时间线冲突落后,先停掉pg服务,然后执行同步时间线,否知直接看状态
[postgres@master ~]$ pg_rewind --target-pgdata=/data1/pg_data --source-server='host=slave port=54321 user=postgres dbname=postgres'
servers diverged at WAL position 0/5000098 on timeline 1
rewinding from last common checkpoint at 0/5000028 on timeline 1
Done!
# 重新启动数据库
[postgres@master ~]$ pg_ctl start

再次查看当前状态

[postgres@pool ~]$ psql -p 54321 -h 10.0.0.13 -U srcheck -d postgres
postgres=# show pool_nodes;
 node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay
---------+----------+------+--------+-----------+---------+------------+-------------------+-------------------
 0  | master | 5432 | down| 0.500000 | standby | 0    | false | 0
 1  | slave  | 5432 | up  | 0.500000 | primary | 0    | true | 0
(2 rows)

#注意虽然master已经启动了,但是还是down,需要手动将master节点添加进pgpool,master的node_id是0,所以-n 0
[postgres@pool ~]$ pcp_attach_node -d -U postgres -h pool -p 54321 -n 0
#提示输入密码,输入pcp管理密码
#查看当前状态
[postgres@pool ~]$ psql -p 54321 -h 10.0.0.13 -U srcheck -d postgres
postgres=# show pool_nodes;
 node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay
---------+----------+------+--------+-----------+---------+------------+-------------------+-------------------
 0  | master | 5432 | up | 0.500000 | standby | 0    | false | 0
 1  | slave  | 5432 | up  | 0.500000 | primary | 0    | true | 0
(2 rows)

现在两个节点都是up了。

主从两节点pgpool健康检查脚本(pgpool_check.sh)

说明:此脚本是基于PGpool只安装到master和slave两个主机上的情况下使用,在master主机有了pgpool进程后,可在slave主机执行sh pgpool_check.sh & 即可

#! /bin/bash
# Check Master host pgpool-process

while true
do
 pgcount=$(nmap 10.0.0.11|egrep '9898|9999'|wc -l)

 if [ $pgcount -eq 2 ] ; then
  echo 'Master host pgpool is GOOD!!!' > /dev/null 2>&1
 else
  echo -e "Master host pgpool is \033[31m BAD!!! \033[0m"
  echo -e "Master host pgpool is \033[31m BAD!!! \033[0m"
  echo -e "Master host pgpool is \033[31m BAD!!! \033[0m"
  echo -e "SYSTEM WILL DO THE SHELL : \033[34m su - postgres -c 'pgpool -n -d -D > /data1/pg_logs/pgpool.log 2>&1 &' \033[0m"
  su - postgres -c 'pgpool -n -d -D > /data1/pg_logs/pgpool.log 2>&1 &'
  pgport=$(netstat -lntup|egrep '9898|9999'|wc -l)
  [ $pgport -gt 0 ] && echo -e "Slave host pgpool is \033[32m RUNNING!!! \033[0m"
  exit 0
 fi
done

以上为个人经验,希望能给大家一个参考,也希望大家多多支持我们。如有错误或未考虑完全的地方,望不吝赐教。

(0)

相关推荐

  • 查看postgresql数据库用户系统权限、对象权限的方法

    PostgreSQL简介 PostgreSQL是一种特性非常齐全的自由软件的对象-关系型数据库管理系统(ORDBMS),是以加州大学计算机系开发的POSTGRES,4.2版本为基础的对象关系型数据库管理系统.POSTGRES的许多领先概念只是在比较迟的时候才出现在商业网站数据库中.PostgreSQL支持大部分的SQL标准并且提供了很多其他现代特性,如复杂查询.外键.触发器.视图.事务完整性.多版本并发控制等.同样,PostgreSQL也可以用许多方法扩展,例如通过增加新的数据类型.函数.操作符

  • PostgreSQL时间线(timeline)和History File的用法

    说明: 在pg中,当我们进行了基于时间点的还原(PITR)后,数据库会启用新的时间线并继续进行操作. 但是,当我们进行基于时间点的还原后如果发现又出现错误,想要继续还原数据库该如何操作呢?如何还原到原先旧的时间线呢? 我们可以使用recovery_target_timeline参数来指定数据库还原到某一个时间线上.如果你还不清楚这个参数该如何使用,或者说压根不知道时间线是啥,那么请继续往下看. PostgreSQL 时间线: 每当我们在数据库中完成一个事务时,所做的操作都会记录到$PGDATA/

  • 基于postgresql行级锁for update测试

    创建表: CREATE TABLE db_user ( id character varying(50) NOT NULL, age integer, name character varying(100), roleid character varying, CONSTRAINT db_user_pkey PRIMARY KEY (id) ) 随便插入几条数据即可. 一.不加锁演示 1.打开一个postgreSQL的SQL Shell或pgAdmin的SQL编辑器窗口,执行: begin; s

  • 基于postgresql数据库锁表问题的解决

    查询是否锁表了 select oid from pg_class where relname='可能锁表了的表' select pid from pg_locks where relation='上面查出的oid' 如果查询到了结果,表示该表被锁 则需要释放锁定 select pg_cancel_backend(上面查到的pid) 补充:PostgreSQL 解决锁表.死锁问题 1.-- 查询ACTIVITY的状态等信息 SELECT T .PID, T.STATE, T.QUERY, T.WA

  • Postgresql锁机制详解(表锁和行锁)

    表锁 LOCK [ TABLE ] [ ONLY ] name [ * ] [, ...] [ IN lockmode MODE ] [ NOWAIT ] lockmode包括以下几种: ACCESS SHARE | ROW SHARE | ROW EXCLUSIVE | SHARE UPDATE EXCLUSIVE| SHARE | SHARE ROW EXCLUSIVE | EXCLUSIVE | ACCESS EXCLUSIVE LOCK TABLE命令用于获取一个表锁,获取过程将阻塞一直

  • postgresql synchronous_commit参数的用法介绍

    synchronous_commit 指定在命令返回"success"指示给客户端之前,一个事务是否需要等待 WAL 记录被写入磁盘. 合法的值是{local,remote_write,remote_apply,on,off} 默认的并且安全的设置是on. 不同于fsync,将这个参数设置为off不会产生数据库不一致性的风险:一个操作系统或数据库崩溃可能会造成一些最近据说已提交的事务丢失,但数据库状态是一致的,就像这些事务已经被干净地中止.因此,当性能比完全确保事务的持久性更重要时,关

  • Postgresql - 查看锁表信息的实现

    查看表锁信息,是DBA常用的脚本之一. 实验环境: CentOS 7 PG 10.4 先通过A窗口执行 mytest=# begin; BEGIN mytest=# update t1 set col1 = 'a' where id =1 ; UPDATE 1 mytest=# 打开B窗口执行 mytest=# begin; BEGIN mytest=# update t1 set col1 = 'b' where id =2; UPDATE 1 mytest=# update t1 set c

  • Postgresql创建新增、删除与修改触发器的方法

    新增触发器 第一步:创建函数 为待模糊查询的表创建函数 CREATE OR REPLACE FUNCTION fuzzy_query_func() RETURNS TRIGGER AS $$ BEGIN INSERT INTO fuzzy_query(id,name,address,table_name) VALUES (new.id, NEW.name,NEW.address,TG_TABLE_NAME); RETURN NEW; END; $$ LANGUAGE plpgsql; 第二步:创

  • PostgreSQL+Pgpool实现HA主备切换的操作

    PostgreSQL流复制实现HA主备切换 环境说明和主机规划 操作系统 主机名 主机 角色 端口 CentOS 7 master 10.0.0.11 PG-Master 54321 CentOS 7 slave 10.0.0.12 PG-Slave 54321 CentOS 7 pool 10.0.0.13 pgpool 54321 基础环境配置(所有主机操作) 配置HOSTS echo -e "10.0.0.11 master\n10.0.0.12 slave\n10.0.0.13 pool

  • redis 主从备份及其主备切换的操作

    首先原文是用了3 个服务器,我是用了一个服务器: 然后再原文的基础上,稍加了自己的整理. 前提: redis中,主从切换场景中,没有绝对的主和从,只有初始化的主和从,然后当主down后,从就变成主了,而主即使连接上,也是从,不会变为主 1.redis-server的主备关系: master : redis-1 slave1 : redis-2 slave3 : redis-3 2. 首先进行主从备份: 修改从服务 redis-1 redis-2 的redis.conf 在从服务上 修改redis

  • postgres主备切换之文件触发方式详解

    本文测试参考PostgresSQL实战一书. 本文档测试环境: 主库IP:192.168.40.130 主机名:postgres 端口:5442 备库IP: 192.168.40.131 主机名:postgreshot 端口:5442 PostgreSQL9.0版本流复制主备切换只能通过创建触发文件方式进行,这一小节将介绍这种主备切换方式,测试环境为一主一备异步流复制环境,postgres上的数据库为主库,postgreshot上的数据库为备库,文件触发方式的手工主备切换主要步骤如下: 1)配置

  • 关于mysql主备切换canal出现的问题解决

    通过配置VIP,在进行主备切换时,出现的报错信息: 1.当主备节点当前binlog文件名称相同时,原主节点的position小于主备切换后的position,出现如下报错: 2020-07-02 15:08:09,332 INFO [destination = 1-236 , address = /192.168.3.100:3306 , EventParser] MysqlConnection:293 | Register slave RegisterSlaveCommandPacket[re

  • 解决redis sentinel 频繁主备切换的问题

    问题描述 操作redis发现原有Master变成slave,其他slave成master,切换较频繁 问题分析 查看redis服务器sentinel日志,发现主机频繁在凌晨左右sentinel哨兵检查到master挂了,主备切换,排查为每天凌晨左右对hash:sms:qxt:mobile:content:day队列进行删除触发的切机,队列量级过大,删除时导致redis服务器卡住,切机. 问题处理 队列改用分批删除,避免对大数据量队列进行删除而引起切机 补充:redis一主一从一哨兵,第一次主从切

  • MySQL是如何实现主备同步

    主备同步,也叫主从复制,是MySQL提供的一种高可用的解决方案,保证主备数据一致性的解决方案. 在生产环境中,会有很多不可控因素,例如数据库服务挂了.为了保证应用的高可用,数据库也必须要是高可用的. 因此在生产环境中,都会采用主备同步.在应用的规模不大的情况下,一般会采用一主一备. 除了上面提到的数据库服务挂了,能够快速切换到备库,避免应用的不可用外,采用主备同步还有以下好处: 提升数据库的读并发性,大多数应用都是读比写要多,采用主备同步方案,当使用规模越来越大的时候,可以扩展备库来提升读能力.

  • MySQL是怎么保证主备一致的

    目录 MySQL 主备的基本原理 binlog 的三种格式对比 为什么会有 mixed 格式的 binlog? 循环复制问题 总结: 抛出问题:大家知道 binlog 可以用来归档,也可以用来做主备同步,但它的内容是什么样的呢?为什么备库执行了 binlog 就可以跟主库保持一致了呢? MySQL 主备的基本原理 图 1 MySQL 主备切换流程 在状态 1 中,客户端的读写都直接访问节点 A,而节点 B 是 A 的备库,只是将 A 的更新都同步过来,到本地执行.这样可以保持节点 B 和 A 的

  • postgresql 12版本搭建及主备部署操作

    postgresql 12版本主备部署 环境搭建 centos 7+ postgresql 12.0 # 网络检查 ping -c2 baidu.com #关闭防火墙,selinux systemctl stop firewalld && sudo systemctl disable firewalld sed -ri s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config setenforce 0 ### 配置阿里云yum源

  • Spring Boot中自定义注解结合AOP实现主备库切换问题

    摘要:本篇文章的场景是做调度中心和监控中心时的需求,后端使用TDDL实现分表分库,需求:实现关键业务的查询监控,当用Mybatis查询数据时需要从主库切换到备库或者直接连到备库上查询,从而减小主库的压力,在本篇文章中主要记录在Spring Boot中通过自定义注解结合AOP实现直接连接备库查询. 一.通过AOP 自定义注解实现主库到备库的切换 1.1 自定义注解 自定义注解如下代码所示 import java.lang.annotation.ElementType; import java.la

  • 高可用架构etcd选主故障主备秒级切换实现

    目录 什么是Etcd? 主备服务场景描述 jetcd具体实现 首先引入jetcd依赖 初始化客户端 关键api介绍 完整的测试用例 什么是Etcd? etcd是一个强大的一致性的分布式键值存储,它提供了一种可靠的方式来存储需要由分布式系统或机器群访问的数据.它优雅地处理网络分区期间的领导者选举,并且可以容忍机器故障,即使在领导者节点中也是如此.从简单的Web应用程序到Kubernetes,任何复杂的应用程序都可以读取数据并将数据写入etcd.这是官方对Etcd的描述,基于这些特性,Etcd常用于

随机推荐