Skip to content

Commit fa33b72

Browse files
authored
Add Maxscale Cluster Support (#16)
Signed-off-by: SK Ali Arman <[email protected]>
1 parent b53b813 commit fa33b72

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

scripts/maxscale.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ cat >>/etc/maxscale/maxscale.cnf <<EOL
99
threads=1
1010
log_debug=1
1111
EOL
12+
#TODO: configuration sync: among maxscale nodes, when something done in a specific maxscale
13+
#https://mariadb.com/kb/en/mariadb-maxscale-2402-maxscale-2402-mariadb-maxscale-configuration-guide/#runtime-configuration-changes
14+
#if [ "${MAXSCALE_CLUSTER:-}" == "true" ];then
15+
# cat >>/etc/maxscale/maxscale.cnf <<EOL
16+
#config_sync_cluster = ReplicationMonitor
17+
#config_sync_user = maxscale_confsync
18+
#config_sync_password = '$MYSQL_ROOT_PASSWORD'
19+
#EOL
20+
#fi
1221

1322
cat >>/etc/maxscale/maxscale.cnf.d/maxscale.cnf <<EOL
1423
# Auto-generated server list from environment
@@ -57,7 +66,11 @@ replication_user=repl
5766
replication_password='$MYSQL_ROOT_PASSWORD'
5867
EOL
5968

60-
69+
if [ "${MAXSCALE_CLUSTER:-}" == "true" ];then
70+
cat >>/etc/maxscale/maxscale.cnf.d/maxscale.cnf <<EOL
71+
cooperative_monitoring_locks=majority_of_running
72+
EOL
73+
fi
6174
cat >>/etc/maxscale/maxscale.cnf.d/maxscale.cnf <<EOL
6275
6376
[RW-Split-Router]
@@ -71,6 +84,7 @@ master_failure_mode=fail_on_write
7184
transaction_replay=true
7285
slave_selection_criteria=ADAPTIVE_ROUTING
7386
master_accept_reads=true
87+
enable_root_user=true
7488
EOL
7589

7690
cat >>/etc/maxscale/maxscale.cnf.d/maxscale.cnf <<EOL

scripts/std-replication-setup.sh

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,24 @@ function create_maxscale_user() {
103103
fi
104104
}
105105

106+
//TODO:
107+
#function create_maxscale_confsync_user() {
108+
# log "INFO" "Checking whether maxscale user exist or not......"
109+
# local mysql="$mysql_header --host=$localhost"
110+
# # At first, ensure that the command executes without any error. Then, run the command again and extract the output.
111+
# retry 120 ${mysql} -N -e "select count(host) from mysql.user where mysql.user.user='maxscale_confsync';" | awk '{print$1}'
112+
# out=$(${mysql} -N -e "select count(host) from mysql.user where mysql.user.user='maxscale_confsync';" | awk '{print$1}')
113+
# # if the user doesn't exist, crete new one.
114+
# if [[ "$out" -eq "0" ]]; then
115+
# log "INFO" "maxscale_confsync user not found. Creating new maxscale_confsync user........"
116+
# retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;CREATE USER 'maxscale_confsync'@'%' IDENTIFIED BY '$MYSQL_ROOT_PASSWORD';"
117+
# retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT SELECT, INSERT, UPDATE, CREATE ON mysql.maxscale_config TO maxscale_confsync@'%';"
118+
# retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;FLUSH PRIVILEGES;"
119+
# else
120+
# log "INFO" "maxscale_confsync user exists. Skipping creating new one......."
121+
# fi
122+
#}
123+
106124
function create_monitor_user() {
107125
log "INFO" "Checking whether monitor user exist or not......"
108126
local mysql="$mysql_header --host=$localhost"
@@ -114,8 +132,16 @@ function create_monitor_user() {
114132
if [[ "$out" -eq "0" ]]; then
115133
log "INFO" "Monitor user not found. Creating new monitor user........"
116134
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;CREATE USER 'monitor_user'@'%' IDENTIFIED BY '$MYSQL_ROOT_PASSWORD';"
117-
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT REPLICATION CLIENT on *.* to 'monitor_user'@'%';"
118-
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT SUPER, RELOAD on *.* to 'monitor_user'@'%';"
135+
#mariadb 10.6+ change SUPER-> READ_ONLY ADMIN, REPLICATION CLIENT> SLAVE MONITOR
136+
if [[ "$(echo -e "1:10.7\n$MARIADB_VERSION" | sort -V | tail -n1)" == "$MARIADB_VERSION" ]]; then
137+
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT READ_ONLY ADMIN, RELOAD on *.* to 'monitor_user'@'%';"
138+
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT SLAVE MONITOR ON *.* TO 'monitor_user'@'%';"
139+
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT BINLOG ADMIN, REPLICATION MASTER ADMIN, REPLICATION SLAVE ADMIN ON *.* TO 'monitor_user'@'%';"
140+
else
141+
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT SUPER, RELOAD on *.* to 'monitor_user'@'%';"
142+
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT REPLICATION CLIENT on *.* to 'monitor_user'@'%';"
143+
fi
144+
119145
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;FLUSH PRIVILEGES;"
120146
else
121147
log "INFO" "Monitor user exists. Skipping creating new one......."
@@ -210,6 +236,10 @@ create_maxscale_user
210236
# ensure monitor user
211237
create_monitor_user
212238

239+
#TODO:
240+
# ensure maxscale_confsync user
241+
#create_maxscale_confsync_user
242+
213243
while true; do
214244
kill -0 $pid
215245
exit="$?"

0 commit comments

Comments
 (0)