-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-galera-3nodes.sh
245 lines (194 loc) · 5.5 KB
/
deploy-galera-3nodes.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
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
#!/bin/bash
if [ "$EUID" -ne 0 ]; then
echo "Gimme some root access"
exit 1
fi
# HINT: You nodes should be all installed the same and be able to communicate with each other
# In my case, I have 3 nodes, installed on Debian 12 Bookworm
# setting ur variables for 3 nodes and the script goes whoo
NODE1="10.200.0.4"
NODE2="10.200.0.2"
NODE3="10.200.0.3"
CLUSTERNAME="XXXX-APP-Cluster"
#Gateway
NETGW="10.200.0.1"
NETMASK="255.255.255.0"
#primary DNS, secondary DNS
NETDNS="10.200.0.11,8.8.8.8"
NODE1_HOSTNAME="srv-vm-node1-db01"
NODE2_HOSTNAME="srv-vm-node2-db01"
NODE3_HOSTNAME="srv-vm-node3-db01"
# change Variables to your own passwords
USERPW="URUSERPW"
ROOTPW="URROOTPW"
echo "Changing passwords from default"
chpasswd <<<"administrator:$USERPW"
chpasswd <<<"root:$ROOTPW"
echo "disable ipv6"
echo "net.ipv6.conf.all.disable_ipv6 = 1" >> /etc/sysctl.conf
sysctl -p
if [ "$HOSTNAME" = "$NODE1_HOSTNAME" ]; then
printf '%s\n' "on the right host ($HOSTNAME)"
rm /etc/network/interfaces
cat <<EOF > /etc/network/interfaces
source /etc/network/interfaces.d/*
#loopback interface
auto lo
iface lo inet loopback
allow-hotplug ens192
iface ens192 inet static
address $NODE1
netmask $NETMASK
gateway $NETGW
dns-nameservers $NETDNS
EOF
elif [ "$HOSTNAME" = "$NODE2_HOSTNAME" ]; then
printf '%s\n' "on the right host ($HOSTNAME)"
rm /etc/network/interfaces
cat <<EOF > /etc/network/interfaces
source /etc/network/interfaces.d/*
#loopback interface
auto lo
iface lo inet loopback
allow-hotplug ens192
iface ens192 inet static
address $NODE2
netmask $NETMASK
gateway $NETGW
dns-nameservers $NETDNS
EOF
elif [ "$HOSTNAME" = "$NODE3_HOSTNAME" ]; then
printf '%s\n' "on the right host ($HOSTNAME)"
rm /etc/network/interfaces
cat <<EOF > /etc/network/interfaces
source /etc/network/interfaces.d/*
#loopback interface
auto lo
iface lo inet loopback
allow-hotplug ens192
iface ens192 inet static
address $NODE3
netmask $NETMASK
gateway $NETGW
dns-nameservers $NETDNS
EOF
else
printf '%s\n' "uh-oh, wrong host ($HOSTNAME)"
fi
apt update && apt upgrade -y
echo "Installing some essential packages"
apt install net-tools curl -y
curl -LsS -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
sudo bash mariadb_repo_setup --mariadb-server-version=10.11.6
apt install mariadb-server mariadb-client
Y
printf "\r\n"
echo "setting mysql_secure_installation up"
echo "Y" | mysql_secure_installation <<EOF
printf "\r\n"
Y
printf "\r\n"
N
Y
Y
Y
Y
EOF
if [ "$HOSTNAME" = "$NODE1_HOSTNAME" ]; then
printf '%s\n' "on the right host ($HOSTNAME)"
rm /etc/mysql/mariadb.conf.d/50-server.cnf
cat <<EOF > /etc/mysql/mariadb.conf.d/50-server.cnf
[server]
[mysqld]
pid-file = /run/mysqld/mysqld.pid
basedir = /usr
#bind-address = 127.0.0.1
expire_logs_days = 10
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
[embedded]
[mariadb]
[mariadb-10.11]
[galera]
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
wsrep_cluster_address=gcomm://
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
wsrep_cluster_name="ITCares-APP-Cluster"
wsrep_node_address="$NODE1"
EOF
elif [ "$HOSTNAME" = "$NODE2_HOSTNAME" ]; then
printf '%s\n' "on the right host ($HOSTNAME)"
rm /etc/mysql/mariadb.conf.d/50-server.cnf
cat <<EOF > /etc/mysql/mariadb.conf.d/50-server.cnf
[server]
[mysqld]
pid-file = /run/mysqld/mysqld.pid
basedir = /usr
#bind-address = 127.0.0.1
expire_logs_days = 10
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
[embedded]
[mariadb]
[mariadb-10.11]
[galera]
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
# Specify cluster nodes
wsrep_cluster_address="gcomm://$NODE1,$NODE2,$NODE3"
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
wsrep_cluster_name="$CLUSTERNAME"
wsrep_node_address="$NODE2"
EOF
elif [ "$HOSTNAME" = "$NODE3_HOSTNAME" ]; then
printf '%s\n' "on the right host ($HOSTNAME)"
rm /etc/mysql/mariadb.conf.d/50-server.cnf
cat <<EOF > /etc/mysql/mariadb.conf.d/50-server.cnf
[server]
[mysqld]
pid-file = /run/mysqld/mysqld.pid
basedir = /usr
#bind-address = 127.0.0.1
expire_logs_days = 10
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
[embedded]
[mariadb]
[mariadb-10.11]
[galera]
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
# Specify cluster nodes
wsrep_cluster_address="gcomm://$NODE1,$NODE2,$NODE3"
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
wsrep_cluster_name="$CLUSTERNAME"
wsrep_node_address="$NODE3"
EOF
else
printf '%s\n' "uh-oh, wrong host ($HOSTNAME)"
fi
systemctl restart networking
if [ "$HOSTNAME" = "$NODE1_HOSTNAME" ]; then
galera_new_cluster
elif [ "$HOSTNAME" = "$NODE2_HOSTNAME" ]; then
systemctl start mariadb
elif [ "$HOSTNAME" = "$NODE3_HOSTNAME" ]; then
systemctl start mariadb
else
printf '%s\n' "uh-oh, wrong host ($HOSTNAME)"
fi
echo "MariaDB Galera 10.11.6 installed successfully"
echo "Show SQL integrity & status"
mysql -e "SHOW GLOBAL STATUS LIKE 'wsrep_cluster_size'"
mysql -e "SHOW GLOBAL STATUS LIKE 'wsrep_%';"
echo "Well done Script Created by git/aftereffexts"