Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZCS-10242 : Mariadb master-master setup #95

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions src/libexec/zmmysqlenable-mmr
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#
# ***** BEGIN LICENSE BLOCK *****
# Zimbra Collaboration Suite Server
# Copyright (C) 2010, 2011, 2013, 2014, 2015, 2016 Synacor, Inc.
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software Foundation,
# version 2 of the License.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with this program.
# If not, see <https://www.gnu.org/licenses/>.
# ***** END LICENSE BLOCK *****
#

if [ x`whoami` != "xzimbra" ]; then
echo "Error: must be run as user zimbra"
exit 1
fi

source /opt/zimbra/bin/zmshutil || exit 1
zmsetvars -f

#
# Sanity checks
#
zmassert -x /opt/zimbra/common/bin/mysqladmin
zmassert -x /opt/zimbra/common/bin/mysql
zmassert -x /opt/zimbra/bin/zmlocalconfig
zmassert -x /opt/zimbra/bin/zmcontrol
zmassert -r ${zimbra_db_directory}/db.sql
if [ ! -x /opt/zimbra/common/bin/mysql ]; then
echo "Mysql not found on this host"
exit 1
fi

configure_mysql_mycnf(){
mysql_mycnf="`zmlocalconfig -s -m nokey mysql_mycnf`"
backup_date=`date +%Y-%m-%d`
/opt/zimbra/libexec/zminiutil --backup=.pre-${backup_date}-bind-address --section=mysqld --key=bind-address --unset $mysql_mycnf
/opt/zimbra/libexec/zminiutil --backup=.pre-${backup_date}-server-id --section=mysqld --key=server-id --set --value=$2 $mysql_mycnf
/opt/zimbra/libexec/zminiutil --backup=.pre-${backup_date}-log_bin --section=mysqld --key=log_bin --set --value=/opt/zimbra/log/mysql-bin.log $mysql_mycnf
/opt/zimbra/libexec/zminiutil --backup=.pre-${backup_date}-binlog_format --section=mysqld --key=binlog_format --set --value=row $mysql_mycnf
server_id="`/opt/zimbra/libexec/zminiutil --section=mysqld --key=binlog_format --get --key=server-id $mysql_mycnf`"
if [ -z "$server_id" ]
then
echo "Error: Failed to configure Server ID $server_id for $1"
exit 1
else
echo "Info: Server ID $server_id is configured for $1"
fi
}

check_server_id(){
mysql_mycnf="`zmlocalconfig -s -m nokey mysql_mycnf`"
server_id="`/opt/zimbra/libexec/zminiutil --section=mysqld --key=binlog_format --get --key=server-id $mysql_mycnf`"
maridb_primary=$1
if [ ! -z "$server_id" ]
then
echo "Error: Server ID $server_id is already configured for $maridb_primary"
exit 1
fi
}

create_replication_user(){
mysql_replicator_password="`zmlocalconfig -s -m nokey mysql_replicator_password 2>/dev/null`"
if [ -z "$mysql_replicator_password" ]
then
zmlocalconfig -r -f -e mysql_replicator_password
fi
mysql_replicator_password="`zmlocalconfig -s -m nokey mysql_replicator_password`"
mysql -e "create user if not exists 'zmreplicator'@'%' identified by '$mysql_replicator_password';"
mysql -e "grant replication slave on *.* to 'zmreplicator'@'%';"
mysql -e "flush privileges;"
}

restart_mysql(){
mysql.server restart
}

check_data_before_start(){
return_value=""
maridb_primary="`zmlocalconfig -s -m nokey $1 2>/dev/null`"
if [ -z "$maridb_primary" ]; then
return_value="false"
echo "$return_value"
else
return_value="true"
echo "$return_value"
fi
}

maridb_primary_1=$(check_data_before_start maridb_primary1)
maridb_primary_2=$(check_data_before_start maridb_primary2)
if [ "${maridb_primary_1}" = "false" ] || [ "${maridb_primary_2}" = "false" ]; then
echo "Error: maridb_primary1 and maridb_primary2 are not found in zmlocalconfig"
echo "Error: please first set maridb_primary1 and maridb_primary2 using zmlocalconfig"
exit 1
fi
maridb_primary1="`zmlocalconfig -s -m nokey maridb_primary1| cut -f1 -d :`"
maridb_primary2="`zmlocalconfig -s -m nokey maridb_primary2| cut -f1 -d :`"
ip_address=$(hostname -I)
ip_address=(${ip_address//" "/ })
for ip in "${ip_address[@]}";
do
# Assign server-id=1 for maridb_primary1
if [ "$ip" == "$maridb_primary1" ]; then
check_server_id $maridb_primary1
server_id=1
configure_mysql_mycnf $maridb_primary1 $server_id
create_replication_user
restart_mysql
fi

# Assign server-id=2 for maridb_primary2
if [ "$ip" == "$maridb_primary2" ]; then
check_server_id $maridb_primary2
server_id=2
configure_mysql_mycnf $maridb_primary2 $server_id
create_replication_user
restart_mysql
fi
done
108 changes: 108 additions & 0 deletions src/libexec/zmmysqlmmr-status
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#
# ***** BEGIN LICENSE BLOCK *****
# Zimbra Collaboration Suite Server
# Copyright (C) 2010, 2011, 2013, 2014, 2015, 2016 Synacor, Inc.
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software Foundation,
# version 2 of the License.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with this program.
# If not, see <https://www.gnu.org/licenses/>.
# ***** END LICENSE BLOCK *****
#

if [ x`whoami` != "xzimbra" ]; then
echo "Error: must be run as user zimbra"
exit 1
fi

source /opt/zimbra/bin/zmshutil || exit 1
zmsetvars -f

#
# Sanity checks
#
zmassert -x /opt/zimbra/common/bin/mysqladmin
zmassert -x /opt/zimbra/common/bin/mysql
zmassert -x /opt/zimbra/bin/zmlocalconfig
zmassert -x /opt/zimbra/bin/zmcontrol
zmassert -r ${zimbra_db_directory}/db.sql
if [ ! -x /opt/zimbra/common/bin/mysql ]; then
echo "Mysql not found on this host"
exit 1
fi

check_server_id(){
mysql_mycnf="`zmlocalconfig -s -m nokey mysql_mycnf`"
server_id="`/opt/zimbra/libexec/zminiutil --section=mysqld --key=binlog_format --get --key=server-id $mysql_mycnf`"
maridb_master=$1
echo "Server information:"
if [ -z "$server_id" ]; then
echo "Mariadb Primary1 is $maridb_primary1_host"
echo "Mariadb Primary2 is $maridb_primary2_host"
echo "Server ID is not yet configured for $maridb_master"
exit 1
else
echo "ServerID is $server_id"
echo "Server is $maridb_master"
fi
}

replication_info(){
echo "------------------------"
echo "Replication information:"
Slave_IO_Running="`mysql 2>/dev/null -e "SHOW SLAVE STATUS\G;" | grep Slave_IO_Running| tail -n 1 | awk {'print $2'}`"
echo "Slave_IO_Running : $Slave_IO_Running"
Slave_SQL_Running="`mysql 2>/dev/null -e "SHOW SLAVE STATUS\G;" | grep Slave_SQL_Running| tail -n 1 | awk {'print $2'}`"
echo "Slave_SQL_Running : $Slave_SQL_Running"
Read_Master_Log_Pos="`mysql 2>/dev/null -e "SHOW SLAVE STATUS\G;" | grep Read_Master_Log_Pos| tail -n 1 | awk {'print $2'}`"
echo "Read_Master_Log_Pos : $Read_Master_Log_Pos"
Exec_Master_Log_Pos="`mysql 2>/dev/null -e "SHOW SLAVE STATUS\G;" | grep Exec_Master_Log_Pos| tail -n 1 | awk {'print $2'}`"
echo "Exec_Master_Log_Pos : $Exec_Master_Log_Pos"
if [ "$Read_Master_Log_Pos" == "$Exec_Master_Log_Pos" ]; then
echo "Read_Master_Log_Pos and Exec_Master_Log_Pos are in sync and databases also are in sync"
else
echo "Read_Master_Log_Pos and Exec_Master_Log_Pos are not in sync, so databases are not in sync. Something wrong with replication"
fi
}
check_data_before_start(){
return_value=""
maridb_primary="`zmlocalconfig -s -m nokey $1 2>/dev/null`"
if [ -z "$maridb_primary" ]; then
return_value="false"
echo "$return_value"
else
return_value="true"
echo "$return_value"
fi
}

maridb_primary_1=$(check_data_before_start maridb_primary1)
maridb_primary_2=$(check_data_before_start maridb_primary2)
if [ "${maridb_primary_1}" = "false" ] || [ "${maridb_primary_2}" = "false" ]; then
echo "Error: maridb_primary1 and maridb_primary2 are not found in zmlocalconfig"
echo "Error: please first set maridb_primary1 and maridb_primary2 using zmlocalconfig"
exit 1
fi
maridb_primary1_host="`zmlocalconfig -s -m nokey maridb_primary1| cut -f1 -d :`"
maridb_primary1_port="`zmlocalconfig -s -m nokey maridb_primary1| cut -f2 -d :`"
maridb_primary2_host="`zmlocalconfig -s -m nokey maridb_primary2| cut -f1 -d :`"
maridb_primary2_port="`zmlocalconfig -s -m nokey maridb_primary2| cut -f2 -d :`"
ip_address=$(hostname -I)
ip_address=(${ip_address//" "/ })
for ip in "${ip_address[@]}";
do
if [ "$ip" == "$maridb_primary1_host" ]; then
check_server_id $maridb_primary1_host
replication_info
fi

if [ "$ip" == "$maridb_primary2_host" ]; then
check_server_id $maridb_primary2_host
replication_info
fi
done
Loading