02-patroni-初始化数据库

举报
snowofsummer 发表于 2021/12/20 16:45:41 2021/12/20
【摘要】  mkdir /datachown postgres:postgres /data第一个节点:自动初始化数据库su - postgrespatroni /etc/patroni/patroni_postgresql.yml[root@db02 ~#] su - postgresLast login: Thu Nov  4 00:53:07 EDT 2021 on pts/1[postgres...

 

mkdir /data
chown postgres:postgres /data
第一个节点:自动初始化数据库

su - postgres
patroni /etc/patroni/patroni_postgresql.yml

[root@db02 ~#] su - postgres
Last login: Thu Nov  4 00:53:07 EDT 2021 on pts/1
[postgres@db02 ~$]
[postgres@db02 ~$]patroni /etc/patroni/patroni_postgresql.yml
2021-11-10 23:55:46,073 INFO: Selected new etcd server http://127.0.0.1:2379
2021-11-10 23:55:46,076 INFO: No PostgreSQL configuration items changed, nothing to reload.
2021-11-10 23:55:46,094 INFO: Lock owner: None; I am node1
2021-11-10 23:55:46,098 INFO: trying to bootstrap a new cluster
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

creating directory /data/db02 ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... America/New_York
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok


initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    /usr/local/postgresql/bin/pg_ctl -D /data/db02 -l logfile start

2021-11-10 23:55:47,851 INFO: postmaster pid=7163
2021-11-10 23:55:47.861 EST [7163] LOG:  starting PostgreSQL 13.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39), 64-bit
2021-11-10 23:55:47.861 EST [7163] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2021-11-10 23:55:47.862 EST [7163] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2021-11-10 23:55:47.863 EST [7165] LOG:  database system was shut down at 2021-11-10 23:55:47 EST
2021-11-10 23:55:47.864 EST [7163] LOG:  database system is ready to accept connections
localhost:5432 - accepting connections
localhost:5432 - accepting connections
2021-11-10 23:55:47,885 INFO: establishing a new patroni connection to the postgres cluster
2021-11-10 23:55:47,893 INFO: running post_bootstrap
2021-11-10 23:55:47,898 WARNING: Could not activate Linux watchdog device: "Can't open watchdog device: [Errno 2] No such file or directory: '/dev/watchdog'"
2021-11-10 23:55:47,911 INFO: initialized a new cluster
2021-11-10 23:55:57,910 INFO: no action. I am (node1) the leader with the lock
2021-11-10 23:55:57,920 INFO: no action. I am (node1) the leader with the lock

#集群状态检查:
[root@db04 ~]# patronictl -c /etc/patroni/patroni_postgresql.yml list
+--------+---------------+--------+---------+----+-----------+
| Member | Host          | Role   | State   | TL | Lag in MB |
+ Cluster: pgha (7029171592628739058) ------+----+-----------+
| node1  | 192.168.5.201 | Leader | running |  1 |           |
+--------+---------------+--------+---------+----+-----------+


配置第一个节点的pg_hba.conf:
host replication  replicator 192.168.5.0/24  md5
pg_ctl -D /data/db02/ reload





第二个节点:

[postgres@db04 ~]$ patroni /etc/patroni/patroni_postgresql.yml
2021-11-11 00:10:58,408 INFO: Selected new etcd server http://127.0.0.1:2379
2021-11-11 00:10:58,412 INFO: No PostgreSQL configuration items changed, nothing to reload.
2021-11-11 00:10:58,499 INFO: Lock owner: node1; I am node3
2021-11-11 00:10:58,501 INFO: trying to bootstrap from leader 'node1'
2021-11-11 00:10:58,737 INFO: replica has been created using basebackup
2021-11-11 00:10:58,738 INFO: bootstrapped from leader 'node1'
2021-11-11 00:10:59.266 EST [2136] LOG:  starting PostgreSQL 13.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39), 64-bit
2021-11-11 00:10:59.267 EST [2136] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2021-11-11 00:10:59.267 EST [2136] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2021-11-11 00:10:59.269 EST [2137] LOG:  database system was interrupted; last known up at 2021-11-11 00:10:58 EST
2021-11-11 00:10:59,270 INFO: postmaster pid=2136
2021-11-11 00:10:59.274 EST [2139] FATAL:  the database system is starting up
localhost:5432 - rejecting connections
2021-11-11 00:10:59.277 EST [2141] FATAL:  the database system is starting up
localhost:5432 - rejecting connections
2021-11-11 00:10:59.278 EST [2137] LOG:  entering standby mode
2021-11-11 00:10:59.279 EST [2137] LOG:  redo starts at 0/2000028
2021-11-11 00:10:59.279 EST [2137] LOG:  consistent recovery state reached at 0/2000100
2021-11-11 00:10:59.279 EST [2136] LOG:  database system is ready to accept read only connections
2021-11-11 00:10:59.299 EST [2145] LOG:  started streaming WAL from primary at 0/3000000 on timeline 1
localhost:5432 - accepting connections
this is patroni callback on_start replica pgha
2021-11-11 00:11:00,294 INFO: Lock owner: node1; I am node3
2021-11-11 00:11:00,295 INFO: establishing a new patroni connection to the postgres cluster

[postgres@db02 /data/db02$]patronictl -c /etc/patroni/patroni_postgresql.yml list
+--------+---------------+---------+---------+----+-----------+
| Member | Host          | Role    | State   | TL | Lag in MB |
+ Cluster: pgha (7029171592628739058) -------+----+-----------+
| node1  | 192.168.5.201 | Leader  | running |  1 |           |
| node3  | 192.168.5.203 | Replica | running |  1 |         0 |
+--------+---------------+---------+---------+----+-----------+



第三个节点:

-bash-4.2$ patroni /etc/patroni/patroni_postgresql.yml
2021-11-11 00:21:07,617 INFO: Selected new etcd server http://192.168.5.202:2379
2021-11-11 00:21:07,621 INFO: No PostgreSQL configuration items changed, nothing to reload.
2021-11-11 00:21:07,625 INFO: Lock owner: node1; I am node2
2021-11-11 00:21:07,627 INFO: trying to bootstrap from leader 'node1'
2021-11-11 00:21:09,210 INFO: replica has been created using basebackup
2021-11-11 00:21:09,212 INFO: bootstrapped from leader 'node1'
2021-11-11 00:21:10,230 INFO: postmaster pid=8713
localhost:5432 - no response
2021-11-11 00:21:10.263 EST [8713] LOG:  starting PostgreSQL 13.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39), 64-bit
2021-11-11 00:21:10.263 EST [8713] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2021-11-11 00:21:10.264 EST [8713] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2021-11-11 00:21:10.265 EST [8715] LOG:  database system was interrupted; last known up at 2021-11-11 00:21:08 EST
2021-11-11 00:21:10.274 EST [8715] LOG:  entering standby mode
2021-11-11 00:21:10.275 EST [8715] LOG:  redo starts at 0/4000028
2021-11-11 00:21:10.275 EST [8715] LOG:  consistent recovery state reached at 0/4000100
2021-11-11 00:21:10.275 EST [8713] LOG:  database system is ready to accept read only connections
2021-11-11 00:21:10.281 EST [8719] LOG:  started streaming WAL from primary at 0/5000000 on timeline 1
localhost:5432 - accepting connections
localhost:5432 - accepting connections
2021-11-11 00:21:11,261 INFO: Lock owner: node1; I am node2
2021-11-11 00:21:11,262 INFO: establishing a new patroni connection to the postgres cluster
2021-11-11 00:21:11,290 INFO: no action. I am a secondary (node2) and following a leader (node1)
2021-11-11 00:21:17,593 INFO: no action. I am a secondary (node2) and following a leader (node1)

#集群状态
[postgres@db02 /data/db02$]patronictl -c /etc/patroni/patroni_postgresql.yml list
+--------+---------------+---------+---------+----+-----------+
| Member | Host          | Role    | State   | TL | Lag in MB |
+ Cluster: pgha (7029171592628739058) -------+----+-----------+
| node1  | 192.168.5.201 | Leader  | running |  1 |           |
| node2  | 192.168.5.202 | Replica | running |  1 |         0 |
| node3  | 192.168.5.203 | Replica | running |  1 |         0 |
+--------+---------------+---------+---------+----+-----------+



 

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

评论(0

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

全部回复

上滑加载中

设置昵称

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

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

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