-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
init-environment.sh
executable file
·127 lines (111 loc) · 3.5 KB
/
init-environment.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
#!/usr/bin/env bash
source scripts/my-functions.sh
MYSQL_VERSION="5.7.44"
PROXYSQL_VERSION="2.6.3"
echo
echo "Starting environment"
echo "===================="
echo
echo "Creating network"
echo "----------------"
docker network create springboot-proxysql-mysql
echo
echo "Starting mysql-master container"
echo "-------------------------------"
docker run -d \
--name mysql-master \
--network=springboot-proxysql-mysql \
--restart=unless-stopped \
--env "MYSQL_ROOT_PASSWORD=secret" \
--env "MYSQL_DATABASE=customerdb" \
--env "MYSQL_USER=admin" \
--env "MYSQL_PASSWORD=admin" \
--publish 3306:3306 \
--health-cmd='mysqladmin ping -u root -p$${MYSQL_ROOT_PASSWORD}' \
mysql:${MYSQL_VERSION} \
--server-id=1 \
--log-bin='mysql-bin-1.log' \
--relay_log_info_repository=TABLE \
--master-info-repository=TABLE \
--gtid-mode=ON \
--log-slave-updates=ON \
--enforce-gtid-consistency
echo
echo "Starting mysql-slave-1 container"
echo "--------------------------------"
docker run -d \
--name mysql-slave-1 \
--network=springboot-proxysql-mysql \
--restart=unless-stopped \
--env "MYSQL_ROOT_PASSWORD=secret" \
--publish 3307:3306 \
--health-cmd='mysqladmin ping -u root -p$${MYSQL_ROOT_PASSWORD}' \
mysql:${MYSQL_VERSION} \
--server-id=2 \
--enforce-gtid-consistency=ON \
--log-slave-updates=ON \
--read_only=TRUE \
--skip-log-bin \
--skip-log-slave-updates \
--gtid-mode=ON
echo
echo "Starting mysql-slave-2 container"
echo "--------------------------------"
docker run -d \
--name mysql-slave-2 \
--network=springboot-proxysql-mysql \
--restart=unless-stopped \
--env "MYSQL_ROOT_PASSWORD=secret" \
--publish 3308:3306 \
--health-cmd='mysqladmin ping -u root -p$${MYSQL_ROOT_PASSWORD}' \
mysql:${MYSQL_VERSION} \
--server-id=3 \
--enforce-gtid-consistency=ON \
--log-slave-updates=ON \
--read_only=TRUE \
--skip-log-bin \
--skip-log-slave-updates \
--gtid-mode=ON
echo
wait_for_container_log "mysql-master" "port: 3306"
wait_for_container_log "mysql-slave-1" "port: 3306"
wait_for_container_log "mysql-slave-2" "port: 3306"
echo
echo "Setting MySQL Replication"
echo "-------------------------"
docker exec -i -e MYSQL_PWD=secret mysql-master mysql -uroot < mysql/master-replication.sql
docker exec -i -e MYSQL_PWD=secret mysql-slave-1 mysql -uroot < mysql/slave-replication.sql
docker exec -i -e MYSQL_PWD=secret mysql-slave-2 mysql -uroot < mysql/slave-replication.sql
echo
echo "Checking MySQL Replication"
echo "--------------------------"
./check-replication-status.sh
echo
echo "Creating ProxySQL monitor user"
echo "------------------------------"
docker exec -i -e MYSQL_PWD=secret mysql-master mysql -uroot --ssl-mode=DISABLED < mysql/master-proxysql-monitor-user.sql
echo
echo "Waiting 5 seconds before starting proxysql container ..."
sleep 5
echo
echo "Starting proxysql container"
echo "---------------------------"
docker run -d \
--name proxysql \
--network=springboot-proxysql-mysql \
--restart=unless-stopped \
--publish 6032:6032 \
--publish 6033:6033 \
--volume $PWD/proxysql/proxysql.cnf:/etc/proxysql.cnf \
proxysql/proxysql:${PROXYSQL_VERSION}
echo
echo "Waiting 5 seconds before checking mysql servers"
sleep 5
echo
echo "Checking mysql servers"
echo "----------------------"
docker exec -i -e MYSQL_PWD=radmin mysql-master bash -c 'mysql -hproxysql -P6032 -uradmin --prompt "ProxySQL Admin> " <<< "select * from mysql_servers;"'
echo
echo "Environment Up and Running"
echo "=========================="
echo