forked from mmhy2003/Odoo-Deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02-slave-install.sh
executable file
·158 lines (136 loc) · 4.74 KB
/
02-slave-install.sh
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
#!/bin/bash
ODOO_DB_USER="odoo1"
ODOO_DB_PASS="odoo1"
MASTER_IP="192.168.122.61"
SLAVE_IP="192.168.122.62"
SLAVE_USER="vagrant"
SLAVE_PASS="vagrant"
NETWORK="192.168.122.0/24"
VIP_IP="192.168.122.60"
VIP_HOST="192.168.122.60/32"
VIP_NETW="192.168.122.60/24"
VIP_INT="eth1"
COROCONF="/etc/corosync/corosync.conf"
HA_PWD="hacluster"
HA_USER="hacluster"
MASTER_NODE="srv1"
SLAVE_NODE="srv2"
MASTER_ALT="srv1-alt"
SLAVE_ALT="srv2-alt"
CLUSTER_NAME="cluster_pgsql"
KVM_USER="esgi"
KVM_PASS="esgi"
KVM_IP="192.168.122.1"
#--------------------------------------------------
# Repository Setup
#--------------------------------------------------
echo -e "\n---- Repository Setup ----"
sudo cat <<EOF >> /etc/apt/sources.list.d/pgdg.list
deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main
EOF
echo -e "\n---- Update local APT cache ----"
sudo apt-get install ca-certificates -y
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add
sudo apt-get update
sudo apt-get install pgdg-keyring -y
#--------------------------------------------------
# Update Server
#--------------------------------------------------
echo -e "\n---- Update Server ----"
sudo apt-get update
sudo apt-get upgrade -y
#--------------------------------------------------
# Network Setup
#--------------------------------------------------
echo -e "\n---- Network Setup ----"
sudo sed -i '/^127.0.1.1/s/^/#/g' /etc/hosts
sudo cat <<EOF >> /etc/hosts
192.168.122.10 front-nginx odoo.mydomain.local
192.168.122.65 app-odoo2
192.168.122.64 app-odoo1
192.168.122.63 backend-pgbouncer
192.168.122.60 pgsql-vip
192.168.122.61 srv1
192.168.122.62 srv2
192.168.123.61 srv1-alt
192.168.123.62 srv2-alt
EOF
#--------------------------------------------------
# PostgreSQL & Cluster Stack Installation
#--------------------------------------------------
echo -e "\n---- PostgreSQL & Cluster Stack Installation ----"
sudo apt-get install --no-install-recommends pacemaker pacemaker-cli-utils fence-agents pcs sshpass -y
sudo apt-get install postgresql-9.6 postgresql-contrib-9.6 postgresql-client-9.6 -y
sudo apt-get install resource-agents-paf -y
echo -e "\n---- Extend systemd-tmpfiles for postgresql ----"
sudo cat <<EOF > /etc/tmpfiles.d/postgresql-part.conf
# Directory for PostgreSQL temp stat files
d /var/run/postgresql/9.6-main.pg_stat_tmp 0700 postgres postgres - -
EOF
echo -e "\n---- Apply changes immediately ----"
sudo systemd-tmpfiles --create /etc/tmpfiles.d/postgresql-part.conf
#--------------------------------------------------
# PostgreSQL Setup
#--------------------------------------------------
echo -e "\n---- PostgreSQL Setup ----"
sudo -i -u postgres bash << EOF
cd /etc/postgresql/9.6/main/
cat <<EOP >> postgresql.conf
listen_addresses = '*'
wal_level = replica
max_wal_senders = 10
hot_standby = on
hot_standby_feedback = on
logging_collector = on
EOP
cat <<EOP >> pg_hba.conf
# forbid self-replication
host replication postgres $VIP_HOST reject
host replication postgres $(hostname -s) reject
# allow any standby connection
host replication postgres 0.0.0.0/0 trust
EOP
cat <<EOP > recovery.conf.pcmk
standby_mode = on
primary_conninfo = 'host=$VIP_IP application_name=$(hostname -s)'
recovery_target_timeline = 'latest'
EOP
EOF
echo -e "\n---- Cleanup instance created by the package & clone primary ----"
sudo systemctl stop [email protected]
sudo -i -u postgres bash << EOF
rm -rf 9.6/main/
pg_basebackup -h pgsql-vip -D ~postgres/9.6/main/ -X stream -P
cp /etc/postgresql/9.6/main/recovery.conf.pcmk ~postgres/9.6/main/recovery.conf
EOF
sudo systemctl start [email protected]
echo -e "\n---- Stop and Disable PostgreSQL Services ----"
sudo systemctl stop [email protected]
sudo systemctl disable [email protected]
sudo echo disabled > /etc/postgresql/9.6/main/start.conf
#--------------------------------------------------
# Cluster Pre-requisites
#--------------------------------------------------
echo -e "\n---- Disable corosync & pacemaker ----"
sudo systemctl disable corosync # important!
sudo systemctl disable pacemaker
sudo systemctl stop pacemaker.service corosync.service
if [ -f "$COROCONF" ]
then
echo -e "\n---- Remove corosync.conf ----"
sudo rm -f $COROCONF
fi
echo -e "\n---- Set 'hacluster' System User ----"
echo -e "$HA_PWD\n$HA_PWD" | passwd $HA_USER
sleep 3s
echo -e "\n---- Authenticate Each Node ----"
sudo pcs cluster auth $MASTER_NODE $SLAVE_NODE -u $HA_USER -p $HA_PWD
#--------------------------------------------------
# Node Fencing
#--------------------------------------------------
echo -e "\n---- Configure password-less SSH ----"
sudo ssh-keygen -f ~/.ssh/id_rsa -t rsa -N ''
echo -e "\n---- Copy RSA keys to KVM Host ----"
sudo sshpass -p $KVM_PASS ssh-copy-id $KVM_USER@$KVM_IP
sleep 10s
echo -e "\n---- Completed Slave Configuration Successfully ----"