PostgreSQL stolon
【摘要】 环境基础信息:组件名称ip端口角色etcd192.168.5.2202379postgres0192.168.0.2005432masterpostgres1192.168.0.2205432standbypostgres2192.168.0.2205433standbyproxy192.168.5.220 25432对外提供链接地址软件信息:etcd Version: 3.3.11sto...
环境基础信息:
组件名称 |
ip
|
端口 | 角色 |
etcd
|
192.168.5.220
|
2379
|
|
postgres0
|
192.168.0.200
|
5432
|
master
|
postgres1
|
192.168.0.220
|
5432
|
standby
|
postgres2
|
192.168.0.220
|
5433
|
standby
|
proxy
|
192.168.5.220
|
25432
|
对外提供链接地址
|
软件信息:
etcd Version: 3.3.11
stolon-v0.17.0-linux-amd64.tar.gz
postgresql-12.3.tar.bz2
01,启动etcd(本次测试使用单台etcd)
etcd --listen-client-urls 'http://0.0.0.0:2379' --advertise-client-urls 'http://0.0.0.0:2379'
02,集群初始化
stolonctl --cluster-name stolon-cluster --store-backend=etcdv3 --store-endpoints=http://192.168.5.220:2379 init
[root@db01 ~]# stolonctl --cluster-name stolon-cluster --store-backend=etcdv3 --store-endpoints=http://192.168.5.220:2379 init
WARNING: The databases managed by the keepers will be overwritten depending on the provided cluster spec.
Are you sure you want to continue? [yes/no] yes
03,启动sentinel(支持多台,只有一台为LEADER,当一台故障自动切换)
stolon-sentinel --cluster-name stolon-cluster --store-backend=etcdv3 --store-endpoints=http://192.168.5.220:2379
04,启动数据库
#启动postgres0(第一启动的为主数据库)
stolon-keeper --cluster-name stolon-cluster --store-backend=etcdv3 --store-endpoints=http://192.168.5.220:2379 --uid postgres0 --data-dir data/postgres0 --pg-su-password=supassword --pg-repl-username=repluser --pg-repl-password=replpassword --pg-listen-address=192.168.5.200
#启动postgres1(备)
stolon-keeper --cluster-name stolon-cluster --store-backend=etcdv3 --store-endpoints=http://192.168.5.220:2379 --uid postgres1 --data-dir data/postgres1 --pg-su-password=supassword --pg-repl-username=repluser --pg-repl-password=replpassword --pg-listen-address=192.168.5.220
#启动postgres2(备)
stolon-keeper --cluster-name stolon-cluster --store-backend=etcdv3 --store-endpoints=http://192.168.5.220:2379 --uid postgres2 --data-dir data/postgres2 --pg-su-password=supassword --pg-repl-username=repluser --pg-repl-password=replpassword --pg-listen-address=192.168.5.220 --pg-port 5433
05,启动proxy(支持多台部署)
stolon-proxy --cluster-name stolon-cluster --store-backend=etcdv3 --listen-address 192.168.5.220 --port 25432
#登录连接测试
#psql --host 192.168.5.220 --port 25432 postgres -U postgres
#密码:supassword
#主从状态查询
--主数据库
select pid,usename,application_name,client_addr,state,sync_state from pg_stat_replication;
--or 备库
select pid,status,last_msg_send_time,last_msg_receipt_time,conninfo from pg_stat_wal_receiver;
select pg_is_in_recovery();
06,状态检查:
stolonctl --cluster-name=stolon-cluster --store-backend=etcdv3 --store-endpoints=http://192.168.5.220:2379 status
stolonctl --cluster-name=stolon-cluster --store-backend=etcdv3 --store-endpoints=http://192.168.5.220:2379 clusterdata read
=== Active sentinels ===
ID LEADER
527b42f1 true
f2c54a73 false
=== Active proxies ===
ID
d808c772
=== Keepers ===
UID HEALTHY PG LISTENADDRESS PG HEALTHY PG WANTEDGENERATION PG CURRENTGENERATION
postgres0 true 192.168.5.200:5432 true 2 2
postgres1 true 192.168.5.220:5432 true 3 3
postgres2 true 192.168.5.220:5433 true 5 5
=== Cluster Info ===
Master Keeper: postgres2
===== Keepers/DB tree =====
postgres2 (master)
├─postgres1
└─postgres0
07,切换,不支持手动切换.
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)