forked from Percona-QA/percona-qa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_pxc80.sh
executable file
·287 lines (251 loc) · 8.75 KB
/
start_pxc80.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
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
#!/bin/bash
if [ $# -eq 0 ]; then
echo "No arguments passed. Exiting"
exit 1
fi
BASEDIR=$(realpath $1)
PXC_START_TIMEOUT=60
echo "Killing any previous running mysqld server"
pkill -9 mysqld
echo "BaseDir has been set to: $BASEDIR";
if [ -d $BASEDIR/pxc-node ]; then
echo "Found existing PXC nodes."
rm -irf $BASEDIR/pxc-node
fi
echo "Creating work directory"
WORKDIR=$BASEDIR/pxc-node
mkdir $WORKDIR
mkdir $WORKDIR/cert
echo "Workdir has been set to: $WORKDIR"
SOCKET1=$BASEDIR/pxc-node/dn1/mysqld.sock
SOCKET2=$BASEDIR/pxc-node/dn2/mysqld.sock
SOCKET3=$BASEDIR/pxc-node/dn3/mysqld.sock
ERR_FILE1=$BASEDIR/pxc-node/node1.err
ERR_FILE2=$BASEDIR/pxc-node/node2.err
ERR_FILE3=$BASEDIR/pxc-node/node3.err
echo "Creating n1.cnf"
echo "
[mysqld]
port = 4000
server-id=1
log-error-verbosity=3
core-file
# file paths
basedir=$BASEDIR/
datadir=$BASEDIR/pxc-node/dn1
plugin_dir=$BASEDIR/lib/plugin/
log-error=$BASEDIR/pxc-node/node1.err
general_log=1
general_log_file=$BASEDIR/pxc-node/dn1/general.log
slow_query_log=1
slow_query_log_file=$BASEDIR/pxc-node/dn1/slow.log
socket=$SOCKET1
character-sets-dir=$BASEDIR/share/charsets
lc-messages-dir=$BASEDIR/share/
# pxc variables
log_bin=binlog
binlog_format=ROW
gtid_mode=ON
enforce_gtid_consistency=ON
master_verify_checksum=on
binlog_checksum=CRC32
binlog_encryption=ON
pxc_encrypt_cluster_traffic=ON
# wsrep variables
wsrep_cluster_address='gcomm://127.0.0.1:5030,127.0.0.1:6030'
wsrep_provider=$BASEDIR/../../percona-xtradb-cluster-galera/libgalera_smm.so
wsrep_sst_receive_address=127.0.0.1:4020
wsrep_node_incoming_address=127.0.0.1
wsrep_slave_threads=2
wsrep_cluster_name=my_pxc
wsrep_provider_options = \"gmcast.listen_addr=tcp://127.0.0.1:4030\"
wsrep_sst_method=xtrabackup-v2
wsrep_node_name=node4000
innodb_autoinc_lock_mode=2
early-plugin-load=keyring_file.so
keyring_file_data=keyring
ssl-ca = $WORKDIR/cert/ca.pem
ssl-cert = $WORKDIR/cert/server-cert.pem
ssl-key = $WORKDIR/cert/server-key.pem
[client]
ssl-ca = $WORKDIR/cert/ca.pem
ssl-cert = $WORKDIR/cert/client-cert.pem
ssl-key = $WORKDIR/cert/client-key.pem
[sst]
encrypt = 4
ssl-ca = $WORKDIR/cert/ca.pem
ssl-cert = $WORKDIR/cert/server-cert.pem
ssl-key = $WORKDIR/cert/server-key.pem
" > $WORKDIR/n1.cnf
echo "Creating n2.cnf"
echo "
[mysqld]
port = 5000
server-id=2
log-error-verbosity=3
core-file
# file paths
basedir=$BASEDIR/
datadir=$BASEDIR/pxc-node/dn2
plugin_dir=$BASEDIR/lib/plugin
log-error=$BASEDIR/pxc-node/node2.err
general_log=1
general_log_file=$BASEDIR/pxc-node/dn2/general.log
slow_query_log=1
slow_query_log_file=$BASEDIR/pxc-node/dn2/slow.log
socket=$SOCKET2
character-sets-dir=$BASEDIR/share/charsets
lc-messages-dir=$BASEDIR/share/
# pxc variables
binlog_format=ROW
gtid_mode=ON
enforce_gtid_consistency=ON
master_verify_checksum=on
binlog_checksum=CRC32
binlog_encryption=ON
pxc_encrypt_cluster_traffic=ON
# wsrep variables
wsrep_cluster_address='gcomm://127.0.0.1:4030,127.0.0.1:6030'
wsrep_provider=$BASEDIR/../../percona-xtradb-cluster-galera/libgalera_smm.so
wsrep_sst_receive_address=127.0.0.1:5020
wsrep_node_incoming_address=127.0.0.1
wsrep_slave_threads=2
wsrep_cluster_name=my_pxc
wsrep_provider_options = \"gmcast.listen_addr=tcp://127.0.0.1:5030;\"
wsrep_sst_method=xtrabackup-v2
wsrep_node_name=node5000
innodb_autoinc_lock_mode=2
early-plugin-load=keyring_file.so
keyring_file_data=keyring
ssl-ca = $WORKDIR/cert/ca.pem
ssl-cert = $WORKDIR/cert/server-cert.pem
ssl-key = $WORKDIR/cert/server-key.pem
[client]
ssl-ca = $WORKDIR/cert/ca.pem
ssl-cert = $WORKDIR/cert/client-cert.pem
ssl-key = $WORKDIR/cert/client-key.pem
[sst]
encrypt = 4
ssl-ca = $WORKDIR/cert/ca.pem
ssl-cert = $WORKDIR/cert/server-cert.pem
ssl-key = $WORKDIR/cert/server-key.pem
" > $WORKDIR/n2.cnf
echo "Creating n3.cnf"
echo "
[mysqld]
port = 6000
server-id=3
log-error-verbosity=3
core-file
# file paths
basedir=$BASEDIR/
datadir=$BASEDIR/pxc-node/dn3
plugin_dir=$BASEDIR/lib/plugin
log-error=$BASEDIR/pxc-node/node3.err
general_log=1
general_log_file=$BASEDIR/pxc-node/dn3/general.log
slow_query_log=1
slow_query_log_file=$BASEDIR/pxc-node/dn3/slow.log
socket=$SOCKET3
character-sets-dir=$BASEDIR/share/charsets
lc-messages-dir=$BASEDIR/share/
# pxc variables
binlog_format=ROW
gtid_mode=ON
enforce_gtid_consistency=ON
master_verify_checksum=on
binlog_checksum=CRC32
binlog_encryption=ON
pxc_encrypt_cluster_traffic=ON
# wsrep variables
wsrep_cluster_address='gcomm://127.0.0.1:4030,127.0.0.1:5030'
wsrep_provider=$BASEDIR/../../percona-xtradb-cluster-galera/libgalera_smm.so
wsrep_sst_receive_address=127.0.0.1:6020
wsrep_node_incoming_address=127.0.0.1
wsrep_slave_threads=2
wsrep_debug=1
wsrep_cluster_name=my_pxc
wsrep_provider_options = \"gmcast.listen_addr=tcp://127.0.0.1:6030\"
wsrep_sst_method=xtrabackup-v2
wsrep_node_name=node6000
innodb_autoinc_lock_mode=2
early-plugin-load=keyring_file.so
keyring_file_data=keyring
ssl-ca = $WORKDIR/cert/ca.pem
ssl-cert = $WORKDIR/cert/server-cert.pem
ssl-key = $WORKDIR/cert/server-key.pem
[client]
ssl-ca = $WORKDIR/cert/ca.pem
ssl-cert = $WORKDIR/cert/client-cert.pem
ssl-key = $WORKDIR/cert/client-key.pem
[sst]
encrypt = 4
ssl-ca = $WORKDIR/cert/ca.pem
ssl-cert = $WORKDIR/cert/server-cert.pem
ssl-key = $WORKDIR/cert/server-key.pem
" > $WORKDIR/n3.cnf
fetch_err_socket() {
NR=$1
if [ $NR -eq 1 ]; then
SOCKET=$SOCKET1
ERR_FILE=$ERR_FILE1
elif [ $NR -eq 2 ]; then
SOCKET=$SOCKET2
ERR_FILE=$ERR_FILE2
elif [ $NR -eq 3 ]; then
SOCKET=$SOCKET3
ERR_FILE=$ERR_FILE3
fi
}
pxc_startup_status(){
for X in $(seq 0 ${PXC_START_TIMEOUT}); do
sleep 1
if ${BASEDIR}/bin/mysqladmin -uroot -S${SOCKET} ping > /dev/null 2>&1; then
echo "Node started successfully"
break
fi
if [ $X -eq ${PXC_START_TIMEOUT} ]; then
echo "Could not start the server. Exiting"
exit 1
fi
done
}
echo "Creating data directories"
$BASEDIR/bin/mysqld --no-defaults --datadir=$BASEDIR/pxc-node/dn1 --basedir=$BASEDIR --initialize-insecure --log-error=$BASEDIR/pxc-node/node1.err
$BASEDIR/bin/mysqld --no-defaults --datadir=$BASEDIR/pxc-node/dn2 --basedir=$BASEDIR --initialize-insecure --log-error=$BASEDIR/pxc-node/node2.err
$BASEDIR/bin/mysqld --no-defaults --datadir=$BASEDIR/pxc-node/dn3 --basedir=$BASEDIR --initialize-insecure --log-error=$BASEDIR/pxc-node/node3.err
echo "Data directory created"
cp ${WORKDIR}/dn1/*.pem ${WORKDIR}/cert/
cp ${WORKDIR}/dn2/*.pem ${WORKDIR}/cert/
cp ${WORKDIR}/dn3/*.pem ${WORKDIR}/cert/
echo "Starting PXC nodes..."
fetch_err_socket 1
$BASEDIR/bin/mysqld --defaults-file=$BASEDIR/pxc-node/n1.cnf --wsrep_new_cluster > ${ERR_FILE} 2>&1 &
pxc_startup_status 1
fetch_err_socket 2
$BASEDIR/bin/mysqld --defaults-file=$BASEDIR/pxc-node/n2.cnf > ${ERR_FILE} 2>&1 &
pxc_startup_status 2
fetch_err_socket 3
$BASEDIR/bin/mysqld --defaults-file=$BASEDIR/pxc-node/n3.cnf > ${ERR_FILE} 2>&1 &
pxc_startup_status 3
echo "Checking 3 node PXC Cluster startup..."
for X in $(seq 0 3); do
sleep 10
CLUSTER_UP=0;
if ${BASEDIR}/bin/mysqladmin -uroot -S${SOCKET1} ping > /dev/null 2>&1; then
if [ `${BASEDIR}/bin/mysql -uroot -S${SOCKET1} -e"show global status like 'wsrep_cluster_size'" | sed 's/[| \t]\+/\t/g' | grep "wsrep_cluster" | awk '{print $2}'` -eq 3 ]; then CLUSTER_UP=$[ ${CLUSTER_UP} + 1]; fi
if [ `${BASEDIR}/bin/mysql -uroot -S${SOCKET2} -e"show global status like 'wsrep_cluster_size'" | sed 's/[| \t]\+/\t/g' | grep "wsrep_cluster" | awk '{print $2}'` -eq 3 ]; then CLUSTER_UP=$[ ${CLUSTER_UP} + 1]; fi
if [ `${BASEDIR}/bin/mysql -uroot -S${SOCKET3} -e"show global status like 'wsrep_cluster_size'" | sed 's/[| \t]\+/\t/g' | grep "wsrep_cluster" | awk '{print $2}'` -eq 3 ]; then CLUSTER_UP=$[ ${CLUSTER_UP} + 1]; fi
if [ "`${BASEDIR}/bin/mysql -uroot -S${SOCKET1} -e"show global status like 'wsrep_local_state_comment'" | sed 's/[| \t]\+/\t/g' | grep "wsrep_local" | awk '{print $2}'`" == "Synced" ]; then CLUSTER_UP=$[ ${CLUSTER_UP} + 1]; fi
if [ "`${BASEDIR}/bin/mysql -uroot -S${SOCKET2} -e"show global status like 'wsrep_local_state_comment'" | sed 's/[| \t]\+/\t/g' | grep "wsrep_local" | awk '{print $2}'`" == "Synced" ]; then CLUSTER_UP=$[ ${CLUSTER_UP} + 1]; fi
if [ "`${BASEDIR}/bin/mysql -uroot -S${SOCKET3} -e"show global status like 'wsrep_local_state_comment'" | sed 's/[| \t]\+/\t/g' | grep "wsrep_local" | awk '{print $2}'`" == "Synced" ]; then CLUSTER_UP=$[ ${CLUSTER_UP} + 1]; fi
fi
# If count reached 6 (there are 6 checks), then the Cluster is up & running and consistent in it's Cluster topology views (as seen by each node)
if [ ${CLUSTER_UP} -eq 6 ]; then
echo "3 Node PXC Cluster started ok. Clients:"
echo "Node #1: `echo ${BASEDIR}/bin/mysql | sed 's|/mysqld|/mysql|'` -uroot -S${SOCKET1}"
echo "Node #2: `echo ${BASEDIR}/bin/mysql | sed 's|/mysqld|/mysql|'` -uroot -S${SOCKET2}"
echo "Node #3: `echo ${BASEDIR}/bin/mysql | sed 's|/mysqld|/mysql|'` -uroot -S${SOCKET3}"
break
fi
done