patroni-增加节点

举报
snowofsummer 发表于 2021/12/31 08:59:28 2021/12/31
【摘要】  #删除节点:当进程停止,节点信息,自动清除,不需要手动操作。[root@db03 ~]# patronictl -c /etc/patroni/patroni_postgresql.yml list+--------+---------------+---------+---------+----+-----------+| Member | Host          | Role   ...

 #删除节点:

当进程停止,节点信息,自动清除,不需要手动操作。


[root@db03 ~]# patronictl -c /etc/patroni/patroni_postgresql.yml list
+--------+---------------+---------+---------+----+-----------+
| Member | Host          | Role    | State   | TL | Lag in MB |
+ Cluster: pgha (7025507499523621070) -------+----+-----------+
| node1  | 192.168.5.201 | Replica | running |  6 |         0 |
| node2  | 192.168.5.202 | Replica | running |  6 |         0 |
| node3  | 192.168.5.203 | Leader  | running |  6 |           |
| node4  | 192.168.5.200 | Replica | stopped |    |   unknown |
+--------+---------------+---------+---------+----+-----------+

##自动清除node3:




1,克隆主数据库,并启动
pg_basebackup -D /data/db02 -F p -X stream -v -P -h 192.168.5.201 -p 5432 -U  replicator -R


2,修改patroni_postgresql.yml配置文件

name: node4  #节点名称
listen: 192.168.5.200:8008
connect_address: 192.168.5.200:8008
connect_address: 192.168.5.200:5432 # local ip



scope: pgha    #集群名
namespace: /pgsql/  #etcd path
name: node4  # node 名称,每个节点不同
restapi:
  listen: 192.168.5.200:8008
  connect_address: 192.168.5.200:8008
etcd:
  hosts: 192.168.5.201:2379,192.168.5.202:2379,192.168.5.203:2379
  #host: ip:port  #single etd server
bootstrap:
  # this section will be written into Etcd:/<namespace>/<scope>/config after initializing new cluster
  # and all other cluster members will use it as a `global configuration`
  dcs:
    ttl: 30
    loop_wait: 10
    retry_timeout: 10
    maximum_lag_on_failover: 20485760
    master_start_timeout: 300
#    synchronous_mode: false
    postgresql:
      use_pg_rewind: true
      use_slots: false
      parameters:
        listen_addresses: "*"
        port: 5432
        wal_level: replica
        hot_standby: "on"
        max_wal_senders: 10
        #synchronous_standby_names: '*'
        max_connections: 150
        max_replication_slots: 10
        wal_log_hints: "on"


postgresql:
  listen: 0.0.0.0:5432
  connect_address: 192.168.5.200:5432 # local ip
  data_dir: /data/db02
  bin_dir: /usr/local/postgresql/bin
#  config_dir:
  authentication:
    replication:
      username: replicator
      password: replicator
    superuser:
      username: postgres
      password: postgres
  callbacks:
    on_start: /etc/patroni/patroni_callback.sh
    on_stop: /etc/patroni/patroni_callback.sh
    on_role_change: /etc/patroni/patroni_callback.sh




#watchdog:
#  mode: automatic # Allowed values: off, automatic, required
#  device: /dev/watchdog
#  safety_margin: 5


tags:
    nofailover: false
    noloadbalance: false
    clonefrom: false
    nosync: false




3,启动并检查状态


[root@db03 ~]# patronictl -c /etc/patroni/patroni_postgresql.yml list
+--------+---------------+---------+---------+----+-----------+
| Member | Host          | Role    | State   | TL | Lag in MB |
+ Cluster: pgha (7025507499523621070) -------+----+-----------+
| node1  | 192.168.5.201 | Replica | running |  6 |         0 |
| node2  | 192.168.5.202 | Replica | running |  6 |         0 |
| node3  | 192.168.5.203 | Leader  | running |  6 |           |
+--------+---------------+---------+---------+----+-----------+
#添加节点之后中状态:
[root@db03 ~]# patronictl -c /etc/patroni/patroni_postgresql.yml list
+--------+---------------+---------+---------+----+-----------+
| Member | Host          | Role    | State   | TL | Lag in MB |
+ Cluster: pgha (7025507499523621070) -------+----+-----------+
| node1  | 192.168.5.201 | Replica | running |  6 |         0 |
| node2  | 192.168.5.202 | Replica | running |  6 |         0 |
| node3  | 192.168.5.203 | Leader  | running |  6 |           |
| node4  | 192.168.5.200 | Replica | running |  6 |         0 |
+--------+---------------+---------+---------+----+-----------+

#添加日志":
Nov  2 03:06:59 db01 systemd: Started Patroni server.
Nov  2 03:06:59 db01 patroni: 2021-11-02 03:06:59,516 INFO: Selected new etcd server http://127.0.0.1:2379
Nov  2 03:06:59 db01 patroni: 2021-11-02 03:06:59,518 ERROR: Request to server http://127.0.0.1:2379 failed: MaxRetryError("HTTPConnectionPool(host='127.0.0.1', port=2379): Max retries exceeded with url: /v2/keys/pgsql/%E3%80%80%E3%80%80%EF%BC%83etcd%20path/pgha/?recursive=true (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f6b0b0f1a20>: Failed to establish a new connection: [Errno 111] Connection refused',))",)
Nov  2 03:06:59 db01 patroni: 2021-11-02 03:06:59,519 INFO: Reconnection allowed, looking for another server.
Nov  2 03:06:59 db01 patroni: 2021-11-02 03:06:59,519 INFO: Retrying on http://192.168.5.201:2379
Nov  2 03:06:59 db01 patroni: 2021-11-02 03:06:59,521 INFO: Selected new etcd server http://192.168.5.201:2379
Nov  2 03:06:59 db01 patroni: 2021-11-02 03:06:59,523 INFO: No PostgreSQL configuration items changed, nothing to reload.
Nov  2 03:06:59 db01 patroni: 2021-11-02 03:06:59,527 INFO: establishing a new patroni connection to the postgres cluster
2021-11-02 03:06:59.547 EDT [5143] LOG:  received SIGHUP, reloading configuration files
2021-11-02 03:06:59.548 EDT [5143] LOG:  parameter "primary_conninfo" changed to "user=replicator passfile=/home/postgres/pgpass host=192.168.5.203 port=5432 sslmode=prefer application_name=node4 gssencmode=prefer channel_binding=prefer"
2021-11-02 03:06:59.549 EDT [5144] LOG:  WAL receiver process shutdown requested
2021-11-02 03:06:59.550 EDT [5206] FATAL:  terminating walreceiver process due to administrator command
Nov  2 03:06:59 db01 patroni: server signaled
2021-11-02 03:06:59.561 EDT [5262] LOG:  started streaming WAL from primary at 0/D000000 on timeline 6
Nov  2 03:06:59 db01 patroni: this is patroni callback on_start replica pgha
Nov  2 03:06:59 db01 patroni: 2021-11-02 03:06:59,567 INFO: no action. I am a secondary (node4) and following a leader (node3)
Nov  2 03:07:06 db01 patroni: 2021-11-02 03:07:06,939 INFO: Lock owner: node3; I am node4
Nov  2 03:07:06 db01 patroni: 2021-11-02 03:07:06,940 INFO: Local timeline=6 lsn=0/D01D700
Nov  2 03:07:06 db01 patroni: 2021-11-02 03:07:06,943 INFO: master_timeline=6
Nov  2 03:07:06 db01 patroni: 2021-11-02 03:07:06,948 INFO: no action. I am a secondary (node4) and following a leader (node3)


 

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。