-
Notifications
You must be signed in to change notification settings - Fork 1
/
gcaa-patroni.txt
432 lines (364 loc) · 11.3 KB
/
gcaa-patroni.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
sed -i 's/enforcing/disabled/g' /etc/selinux/config /etc/selinux/config
sed -i "\$ a $1 192.168.8.73\t\t$NEW_HOST auhsmaxdbp01\t$NEW_HOST" /etc/hosts
sed -i "\$ a $1 192.168.8.74\t\t$NEW_HOST auhsmaxdbp02\t$NEW_HOST" /etc/hosts
sed -i "\$ a $1 192.168.8.76\t\t$NEW_HOST auhsmaxdbp03\t$NEW_HOST" /etc/hosts
systemctl disable firewalld
vgcreate vg00 /dev/sdb
lvcreate -l 100%FREE -n lv00 vg00
mkfs.xfs /dev/vg00/lv00
dnf -y install epel-release
dnf -y update
dnf -y install yum-utils
dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
dnf -qy module disable postgresql
dnf -y install postgresql12-server postgresql12 postgresql12-devel
ln -s /usr/pgsql-12/bin/* /usr/sbin/
curl -O https://ftp.postgresql.org/pub/repos/yum/common/pgdg-rhel8-extras/redhat/rhel-8.5-x86_64/etcd-3.5.5-1.rhel8.x86_64.rpm
dnf -y install etcd-3.5.5-1.rhel8.x86_64.rpm
vi /etc/watchdog.conf
watchdog-device = /dev/watchdog
mknod /dev/watchdog c 10 130
modprobe softdog
chown postgres /dev/watchdog
mv /etc/etcd/etcd.conf /etc/etcd/etcd.conf.ori
cat - <<HEREDOC >/etc/etcd/etcd.conf
ETCD_NAME=auhsmaxdbp01
ETCD_DATA_DIR="/var/lib/etcd/auhsmaxdbp01"
ETCD_LISTEN_PEER_URLS="http://192.168.8.73:2380"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.8.73:2380"
ETCD_INITIAL_CLUSTER="auhsmaxdbp01=http://192.168.8.73:2380,auhsmaxdbp02=http://192.168.8.74:2380,auhsmaxdbp03=http://192.168.8.76:2380"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_ADVERTISE_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_ENABLE_V2="true"
HEREDOC
cat - <<HEREDOC >/etc/etcd/etcd.conf
ETCD_NAME=auhsmaxdbp02
ETCD_DATA_DIR="/var/lib/etcd/auhsmaxdbp02"
ETCD_LISTEN_PEER_URLS="http://192.168.8.74:2380"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.8.74:2380"
ETCD_INITIAL_CLUSTER="auhsmaxdbp01=http://192.168.8.73:2380,auhsmaxdbp02=http://192.168.8.74:2380,auhsmaxdbp03=http://192.168.8.76:2380"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_ADVERTISE_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_ENABLE_V2="true"
HEREDOC
cat - <<HEREDOC >/etc/etcd/etcd.conf
ETCD_NAME=auhsmaxdbp03
ETCD_DATA_DIR="/var/lib/etcd/auhsmaxdbp03"
ETCD_LISTEN_PEER_URLS="http://192.168.8.76:2380"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.8.76:2380"
ETCD_INITIAL_CLUSTER="auhsmaxdbp01=http://192.168.8.73:2380,auhsmaxdbp02=http://192.168.8.74:2380,auhsmaxdbp03=http://192.168.8.76:2380"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_ADVERTISE_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_ENABLE_V2="true"
HEREDOC
vi .bash_profile
export PGDATA="/var/lib/pgsql/12/data"
export ETCDCTL_API="3"
export PATRONI_ETCD_URL="http://127.0.0.1:2379"
export PATRONI_SCOPE="pg_cluster"
patroni1=192.168.8.73
patroni2=192.168.8.74
patroni3=192.168.8.76
ENDPOINTS=$auhsmaxdbp01:2379,$auhsmaxdbp02:2379,$auhsmaxdbp03:2379
systemctl start etcd && systemctl enable etcd && systemctl status etcd
etcdctl endpoint status --write-out=table --endpoints=$ENDPOINTS
dnf -y install python3 python3-devel python3-pip gcc libpq-devel
pip3 install psycopg2
pip3 install --upgrade testresources
pip3 install --upgrade setuptools
pip3 install psycopg2
dnf -y install python3-etcd
dnf -y install patroni patroni-etcd watchdog
mkdir -p /etc/patroni
cat - <<HEREDOC >/etc/patroni/patroni.yml
scope: pg_cluster
namespace: /service/
name: auhsmaxdbp01
restapi:
listen: 192.168.8.73:8008
connect_address: 192.168.8.73:8008
etcd:
hosts: 192.168.8.73:2379, 192.168.8.74:2379, 192.168.8.76:2379
bootstrap:
dcs:
ttl: 30
loop_wait: 10
retry_timeout: 10
maximum_lag_on_failover: 1048576
postgresql:
use_pg_rewind: true
use_slots: true
parameters:
initdb:
- encoding: UTF8
- data-checksums
pg_hba:
- host replication replicator 127.0.0.1/32 md5
- host replication replicator 192.168.8.73/0 md5
- host replication replicator 192.168.8.74/0 md5
- host replication replicator 192.168.8.76/0 md5
- host all all 0.0.0.0/0 md5
users:
admin:
password: admin
options:
- createrole
- createdb
postgresql:
listen: 192.168.8.73:5432
connect_address: 192.168.8.73:5432
data_dir: /var/lib/pgsql/12/data
bin_dir: /usr/pgsql-12/bin
pgpass: /tmp/pgpass
authentication:
replication:
username: replicator
password: replicator
superuser:
username: postgres
password: postgres
watchdog:
mode: required
device: /dev/watchdog
safety_margin: 5
tags:
nofailover: false
noloadbalance: false
clonefrom: false
nosync: false
HEREDOC
mkdir -p /etc/patroni
cat - <<HEREDOC >/etc/patroni/patroni.yml
scope: pg_cluster
namespace: /service/
name: auhsmaxdbp02
restapi:
listen: 192.168.8.74:8008
connect_address: 192.168.8.74:8008
etcd:
hosts: 192.168.8.73:2379, 192.168.8.74:2379, 192.168.8.76:2379
bootstrap:
dcs:
ttl: 30
loop_wait: 10
retry_timeout: 10
maximum_lag_on_failover: 1048576
postgresql:
use_pg_rewind: true
use_slots: true
parameters:
initdb:
- encoding: UTF8
- data-checksums
pg_hba:
- host replication replicator 127.0.0.1/32 md5
- host replication replicator 192.168.8.73/0 md5
- host replication replicator 192.168.8.74/0 md5
- host replication replicator 192.168.8.76/0 md5
- host all all 0.0.0.0/0 md5
users:
admin:
password: admin
options:
- createrole
- createdb
postgresql:
listen: 192.168.8.74:5432
connect_address: 192.168.8.74:5432
data_dir: /var/lib/pgsql/12/data
bin_dir: /usr/pgsql-12/bin
pgpass: /tmp/pgpass
authentication:
replication:
username: replicator
password: replicator
superuser:
username: postgres
password: postgres
watchdog:
mode: required
device: /dev/watchdog
safety_margin: 5
tags:
nofailover: false
noloadbalance: false
clonefrom: false
nosync: false
HEREDOC
mkdir -p /etc/patroni
cat - <<HEREDOC >/etc/patroni/patroni.yml
scope: pg_cluster
namespace: /service/
name: auhsmaxdbp03
restapi:
listen: 192.168.8.76:8008
connect_address: 192.168.8.76:8008
etcd:
hosts: 192.168.8.73:2379, 192.168.8.74:2379, 192.168.8.76:2379
bootstrap:
dcs:
ttl: 30
loop_wait: 10
retry_timeout: 10
maximum_lag_on_failover: 1048576
postgresql:
use_pg_rewind: true
use_slots: true
parameters:
initdb:
- encoding: UTF8
- data-checksums
pg_hba:
- host replication replicator 127.0.0.1/32 md5
- host replication replicator 192.168.8.73/0 md5
- host replication replicator 192.168.8.74/0 md5
- host replication replicator 192.168.8.76/0 md5
- host all all 0.0.0.0/0 md5
users:
admin:
password: admin
options:
- createrole
- createdb
postgresql:
listen: 192.168.8.76:5432
connect_address: 192.168.8.76:5432
data_dir: /var/lib/pgsql/12/data
bin_dir: /usr/pgsql-12/bin
pgpass: /tmp/pgpass
authentication:
replication:
username: replicator
password: replicator
superuser:
username: postgres
password: postgres
watchdog:
mode: required
device: /dev/watchdog
safety_margin: 5
tags:
nofailover: false
noloadbalance: false
clonefrom: false
nosync: false
HEREDOC
systemctl start patroni && systemctl enable patroni && systemctl status patroni
dnf -y install haproxy
mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.orig
cat - <<HEREDOC >/etc/haproxy/haproxy.cfg
global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 1000
user haproxy
group haproxy
daemon
stats socket /var/lib/haproxy/stats
defaults
mode tcp
log global
option tcplog
retries 3
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout check 10s
maxconn 900
listen stats
mode http
bind *:7000
stats enable
stats uri /
listen primary
bind 192.168.10.76:5000
option httpchk OPTIONS /master
http-check expect status 200
default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions
server patroni1 192.168.8.73:5432 maxconn 100 check port 8008
server patroni2 192.168.8.74:5432 maxconn 100 check port 8008
server patroni3 192.168.8.76:5432 maxconn 100 check port 8008
listen standby
bind 192.168.8,76:5001
balance roundrobin
option httpchk OPTIONS /replica
http-check expect status 200
default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions
server patroni1 192.168.8.73:5432 maxconn 100 check port 8008
server patroni2 192.168.8.74:5432 maxconn 100 check port 8008
server patroni3 192.168.8.76:5432 maxconn 100 check port 8008
HEREDOC
systemctl start haproxy && systemctl enable haproxy
All 3 node following steps
dnf -y install keepalived
vi /etc/sysctl.conf
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.ip_forward = 1
sysctl --system
sysctl -p
mv /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.ori
ip addr show enp0s3
cat - <<HEREDOC >/etc/keepalived/keepalived.conf
vrrp_script chk_haproxy {
script "pkill -0 haproxy"
interval 5
weight -4
fall 2
rise 1
}
vrrp_script chk_lb {
script "pkill -0 keepalived"
interval 1
weight 6
fall 2
rise 1
}
vrrp_script chk_servers {
script "echo 'GET /are-you-ok' | nc 127.0.0.1 7000 | grep -q '200 OK'"
interval 2
weight 2
fall 2
rise 2
}
vrrp_instance vrrp_1 {
interface enp0s3
state BACKUP
virtual_router_id 51
priority 99
virtual_ipaddress_excluded {
192.168.8.75
}
track_interface {
enp0s3 weight -2
}
track_script {
chk_haproxy
chk_lb
}
}
HEREDOC
Kindly ask end cus for IP Address for virtual and check the ethernet card name as well.
Before starting keepalived find out who is leader in pgsql cluster.
#patronictl -c /etc/patroni/patroni.yml list
On leader node run below command
systemctl start keepalived
systemctl status keepalived
systemctl enable keepalived
Other 2 node run above command
----------------
dnf update -y
curl -o /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release https://www.redhat.com/security/data/fd431d51.txt
curl --create-dirs -o /etc/rhsm/ca/redhat-uep.pem https://ftp.redhat.com/redhat/convert2rhel/redhat-uep.pem
curl -o /etc/yum.repos.d/convert2rhel.repo https://ftp.redhat.com/redhat/convert2rhel/8/convert2rhel.repo
dnf clean all
dnf -y install convert2rhel
convert2rhel --username rajatjpatel@gmail.com --password
convert2rhel --username=rajatjpatel@gmail.com --auto-attach