-
Notifications
You must be signed in to change notification settings - Fork 0
/
repl-fix-2b.sh
executable file
·83 lines (68 loc) · 2.12 KB
/
repl-fix-2b.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
#!/bin/bash
# Scenario
# An update it run on the classicmodels DB, but employees DB is the default.
# DB employees is being replicated, so the query is run on the slave, but since
# there is no classicmodels DB at slave, it errors.
# Confirm CBS is attached as /dev/xvde
if [ ! -b /dev/xvde ]; then
echo "ERROR: No CBS volume detected at /dev/xvde"
echo "Attach a CBS volume and retry"
exit 1
fi
# Setup LVM
yum -y install parted lvm2
parted -s -- /dev/xvde mklabel gpt
parted -s -a optimal -- /dev/xvde mkpart primary 0% 100%
parted -s -- /dev/xvde align-check optimal 1
parted -s -- /dev/xvde set 1 lvm on
pvcreate /dev/xvde1
vgcreate vg00 /dev/xvde1
lvcreate -L15G -n lv00 vg00
mkfs -t ext4 /dev/mapper/vg00-lv00
mkdir /data
mount /dev/mapper/vg00-lv00 /data
grep /dev/mapper/vg00-lv00 /etc/mtab >> /etc/fstab
# Setup MySQL
yum -y install mysql-server
mkdir /data/mysqllogs
mkdir /data/mysqltmp
tar -C /data -xzf /home/lab/master-data.tgz
# Master position = binlog.000004, 6260
chown mysql:mysql /data/mysqltmp
chown mysql:mysql /data/mysqllogs
chown -R mysql:mysql /data/mysql
echo > /var/log/mysqld.log
cat >/etc/my.cnf <<EOF
[mysqld]
datadir=/data/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
tmpdir = /data/mysqltmp
server-id = 2
read-only
replicate-do-db=employees
log-bin = /data/mysqllogs/binlog
relay-log = /data/mysqllogs/relaylog
binlog-format = MIXED
log-slave-updates
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
EOF
# Start the service
service mysqld start
# Delete all the databases we're not replicating:
mysql -e "DROP DATABASE classicmodels;"
mysql -e "DROP DATABASE proletariat;"
mysql -e "DROP DATABASE ecom;"
mysql -e "DROP DATABASE disasters;"
# Start slave
read -p "Private IP of db1/master? " MASTERIP
mysql -e "CHANGE MASTER TO MASTER_HOST='$MASTERIP',
MASTER_USER='repl',
MASTER_PASSWORD='dkMcn5Vtgv',
MASTER_LOG_FILE='binlog.000004',
MASTER_LOG_POS=6260;"
mysql -e "START SLAVE;"