首先配置主服务器
#!/bin/bash
echo "关闭防火墙"
systemctl stop firewalld.service
setenforce 0
yum -y install mariadb mariadb-server &> /dev/null
if [ $? -eq 0 ];then
echo "MysqL安装成功"
else
echo "MysqL安装失败,请重新安装"
yum -y install mariadb mariadb-server &> /dev/null
fi
sed -i '10aserver-id=1' /etc/my.cnf
sed -i '11alog-bin=MysqL-bin' /etc/my.cnf
sed -i '12arelay-log=relays' /etc/my.cnf
systemctl start mariadb
if [ $? -eq 0 ];then
echo "MysqL启动成功"
else
echo "MysqL启动失败,请重启"
systemctl restart mariadb
fi
MysqL -e "grant all on *.* to tom@'%' identified by '123456';"
if [ $? -eq 0 ];then
echo "授权成功"
else
echo "授权失败,请重试"
MysqL -e "DROP USER tom@'%';"
MysqL -e "grant all on *.* to tom@'%' identified by '123456';"
fi
MysqL -e "flush privileges;"
MysqL -e "show master status;"
然后再进行从服务器的配置
#!/bin/bash
echo "关闭防火墙"
systemctl stop firewalld.service
setenforce 0
yum -y install mariadb mariadb-server &> /dev/null
if [ $? -eq 0 ];then
echo "MysqL安装成功"
else
echo "MysqL安装失败,请重新安装"
yum -y install mariadb mariadb-server &> /dev/null
fi
sed -i '10aserver-id=2' /etc/my.cnf
sed -i '11alog-bin=MysqL-bin' /etc/my.cnf
sed -i '12arelay-log=relays' /etc/my.cnf
systemctl start mariadb
if [ $? -eq 0 ];then
echo "MysqL启动成功"
else
echo "MysqL启动失败,请重启"
systemctl restart mariadb
fi
MysqL -e "stop slave;"
echo "停止slave"
read -ep "请输入主数据库的ip:" ip
read -ep "请到主数据库查看log_file,并且输入:" file
read -ep "请到主数据库查看pos,并且输入:" pos
MysqL -e "change master to master_user='tom', master_host='$ip', master_password='123456', master_log_file='$file', master_log_pos=$pos;"
MysqL -e "start slave;"
echo "启动slave"
IO=$(MysqL -e "show slave status \G;" | grep Slave_IO_Running | awk '{print $2}')
sql=$(MysqL -e "show slave status \G;" | grep Slave_sql_Running | awk '{print $2}')
if [ $IO == "Yes" -a $sql == "Yes" ];then
echo "主从配置成功"
else
echo "主从配置失败,请检查配置"
fi
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。