资讯专栏INFORMATION COLUMN

安装配置patroni

IT那活儿 / 1701人阅读
安装配置patroni

点击上方“IT那活儿”,关注后了解更多内容,不管IT什么活儿,干就完了!!!



机器分配

10.37.129.3 node1

10.37.129.4 node2

10.37.129.5 node3

10.37.129.6 node-vip



源码包安装

python3 setup.py build

python3 setup.py install



软件包安装  

--all nodes

--标准配置:

firewalld

selinux

chrony

gcc

libpq5-devel

--PostgreSQL数据库安装:

postgresql12

postgresql12-server

postgresql12-libs

postgresql12-contrib

--patroni软件需要:

etcd

python3

python3-devel




配置sudo权限


visudo

#
# Allow root to run any commands anywhere

postgres ALL=(root) NOPASSWD: ALL




ETCD集群安装配置  

--all nodes

--查看etcd状态:

export ETCDCTL_API=3

export ENDPOINTS=http://10.37.129.4 :2379,http://10.37.129.5 :2379,http://10.37.129.3 :2379

etcdctl endpoint status --endpoints=$ENDPOINTS -w=table

+-------------------------+------------------+---------+---------+-----------+-----------+------------+

| ENDPOINT |         ID | VERSION | DB SIZE | IS LEADER | RAFT TERM | RAFT INDEX |

+-------------------------+------------------+---------+---------+-----------+-----------+------------+

| http://10.37.129.4 :2379 | 49bab10dd5347fa2 | 3.3.11 |   20 kB | false |        105 | 9 |

| http://10.37.129.5 :2379 | 97cdb5480a6be19f | 3.3.11 |   20 kB | false |        105 | 9 |

| http://10.37.129.3 :2379 | a2916ae27f29d955 | 3.3.11 |   20 kB | true |        105 | 9 |

+-------------------------+------------------+---------+---------+-----------+-----------+------------+




软件WATCHDOG安装配置


--all nodes


# 安装软件,linux内置功能
yum install -y watchdog

# 初始化watchdog字符设备
modprobe softdog

# 修改/dev/watchdog设备权限
chmod 666 /dev/watchdog

# 启动watchdog服务
systemctl start watchdog
systemctl enable watchdog




partroni软件安装  

--all nodes

pip3 install psycopg2==2.8.6

pip3 install patroni[etcd]




创建patroni.service服务


 --all nodes


vi /usr/lib/systemd/system/patroni.service

[Unit]

Description=Runners to orchestrate a high-availability PostgreSQL

After=syslog.target network.target etcd.service

[Service]

Type=simple

User=postgres

Group=postgres

EnvironmentFile=-/etc/patroni/patroni_env.conf

ExecStartPre=-/usr/bin/sudo /sbin/modprobe softdog

ExecStartPre=-/usr/bin/sudo /bin/chown postgres /dev/watchdog

ExecStart=/usr/bin/env patroni /etc/patroni/patroni.yml

ExecReload=/bin/kill -s HUP $MAINPID

KillMode=process

TimeoutSec=30

Restart=on-failure

[Install]

WantedBy=multi-user.target

systemctl daemon-reload




修改配置文件  


--all nodes

--yaml文件不能使用制表位。

vi /etc/patroni/patroni.yml

scope: pgsql

namespace: /service/

name: pg1

restapi:

listen: 0.0.0.0 :8008

connect_address: 10.37.129.3:8008

etcd:

hosts: 10.37.129.3:2379,10.37.129.4:2379,10.37.129.5:2379

bootstrap:

dcs:

ttl: 30

loop_wait: 10

retry_timeout: 10

maximum_lag_on_failover: 1048576

master_start_timeout: 300

synchronous_mode: false

synchronous_node_count: 2 #同步备用服务器数量为2

synchronous_mode_strict: false #没有可用备用同步服务器情况下,阻塞主服务器会话

postgresql:

use_pg_rewind: true

use_slots: true

parameters:

listen_addresses: "0.0.0.0"

port: 5432

wal_level: replica

hot_standby: "on"

wal_keep_segments: 100

max_wal_senders: 10

max_replication_slots: 10

wal_log_hints: "on"

archive_mode: "on"

archive_timeout: 1800s

archive_command: mkdir -p . ./wal_archive && test ! -f . ./wal_archive/%f && cp %p . ./wal_archive/%f

recovery_conf:

restore_command: cp ../wal_archive/%f %p

initdb:

- encoding: UTF8

- locale: C

- lc-ctype: zh_CN.UTF-8

- data-checksums

pg_hba:

- host replication postgres 10.37.129.0/24 md5

- host all all 0.0.0.0/0 md5

postgresql:

listen: 0.0.0.0 :5432

connect_address: 10.37.129.3 :5432

data_dir: /var/lib/pgsql/12/data

bin_dir: /usr/pgsql-12/bin

authentication:

replication:

username:

postgres

"123456"

postgres

"123456"

postgres

"123456"

password:

superuser:

username:

password:

rewind:

username:

password:

basebackup:

max-rate: 100M

checkpoint: fast

watchdog:

mode: automatic # Allowed values: off, automatic, required

device: /dev/watchdog

safety_margin: 5

tags:

nofailover: false

noloadbalance: false

clonefrom: false

nosync: false




启动patroni服务  

--all nodes

systemctl enable patroni

systemctl start patroni




查看patroni集群状态


patronictl -c /etc/patroni/patroni.yml list

+ Cluster: pgsql (6942330619575798728) ----+----+-----------+

| Member | Host | Role | State | TL | Lag in MB |

+--------+-------------+---------+---------+----+-----------+

|
 pg1

| pg2

|
 pg3

|

0 |


0 |

|
 10.37.129.3 | Leader | running | 1 |

| 10.37.129.4 | Replica | running |  1 |

|
 10.37.129.5 | Replica | running | 1 |




通过web查看集群信息

http://10.37.129.3:8008/patroni


文章参考链接:http://blog.itpub.net/30496307/viewspace-2764349/


本文作者:陈辉耀

本文来源:IT那活儿(上海新炬王翦团队)

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/129572.html

相关文章

发表评论

0条评论

IT那活儿

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<