CentOS   发布时间:2022-04-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了auto_install_mariadb_ab.sh大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

#!/bin/bash #auto make install mariadb ab repliation #by author efoni #20180914 MARIADB_SOFT="mariadb mariadb-server mariadb-devel php-mysql" #MYSQL_SOFT="mysql mysql-server mysql-devel php-mysql" NUM
#!/bin/bash
#auto make install mariadb ab repliation
#by author efoni
#20180914

@H_648_21@mARIADB_SOFT="mariadb mariadb-server mariadb-devel PHP-MysqL"
#MysqL_SOFT="MysqL MysqL-server MysqL-devel PHP-MysqL"
NUM=rpm -qa | grep -i mariadb | wc -l
CODE=$?

#mariadb install
if [ $NUM -ne 0 ]; then
echo -e "\033[32mthis server had installed MysqL .\033[0m"
read -p "please ensure yum remove mariadb server .yes or no?": INPUT
if [ $INPUT == "y" -o $INPUT == "yes" ]; then
yum remove -y $MARIADB_SOFT;rm -rf /usr/lib64/MysqL;rm -rf /usr/share/MysqL;rm -f /etc/my.cnf
yum install -y $MARIADB_SOFT
else
exit 0
fi
else
yum install -y $MARIADB_SOFT
if [ $CODE -eq 0 ]; then
echo -e "\033[32m mariadb installed successfully .\033[0m"
else
echo -e "\033[32m mariadb installtion Failed .\033[0m"
exit 1
fi
fi

systemctl start mariadb
for i in seq 10 ;do sleep 1;done
systemctl stop mariadb
for i in seq 5 ;do sleep 1;done@H_256_18@mv /etc/my.cnf /etc/my.cnf.bak
touch /etc/my.cnf

#master mariadb configuration
cat >/etc/my.cnf<<EOF
[MysqLd]
datadir=/var/lib/MysqL
socket=/var/lib/MysqL/MysqL.sock
user=MysqL
symbolic-links=0
log-bin=MysqL-bin
server-id=1
auto_increment_offset=1
auto_increment_increment=2
[MysqLd_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
Replication-do-db=all
EOF

systemctl restart mariadb
#/etc/init.d/MysqLd restart
ps -ef | grep mariadb

function MARIADB_CONfig(){
#master configuration
MysqL -e "grant FILE on . to ‘tongbu‘@‘192.168.3.228‘ identified by ‘tongbu‘;"
MysqL -e "grant Replication slave on . to ‘tongbu‘@‘%‘ identified by ‘tongbu‘;"
MysqL -e "flush privileges;"

@H_648_21@mASTER_FILE=MysqL -e "show master status;"|tail -l|awk ‘{print $1}‘|grep -v ‘File‘@H_256_18@mASTER_POS=MysqL -e "show master status;"|tail -l|awk ‘{print $2}‘|grep -v ‘Position‘

@H_648_21@mASTER_Ipaddr=ifconfig ens32|grep "netmask"|awk ‘{print $2}‘|cut -d: -f2

read -p "please input slave ip address": SLAVE_Ipaddr

#slave configuration
ssh -l root $SLAVE_Ipaddr "systemctl stop mariadb"
ssh -l root $SLAVE_Ipaddr "yum remove -y mariadb mariadb-server mariadb-devel PHP-MysqL"
ssh -l root $SLAVE_Ipaddr "rm -rf /var/lib/MysqL; rm -f /etc/my.cnf"
ssh -l root $SLAVE_Ipaddr "yum install -y mariadb mariadb-server mariadb-devel PHP-MysqL"
ssh -l root $SLAVE_Ipaddr "systemctl restart mariadb"
ssh -l root $SLAVE_Ipaddr "echo [MysqLd] >>/etc/my.cnf"
ssh -l root $SLAVE_Ipaddr "echo datadir=/var/lib/MysqL >>/etc/my.cnf"
ssh -l root $SLAVE_Ipaddr "echo socket=/var/lib/MysqL/MysqL.sock >>/etc/my.cnf"
ssh -l root $SLAVE_Ipaddr "echo user=MysqL >>/etc/my.cnf"
ssh -l root $SLAVE_Ipaddr "echo symbolic-links=0 >>/etc/my.cnf"
ssh -l root $SLAVE_Ipaddr "echo log-bin=MysqL-bin >>/etc/my.cnf"
ssh -l root $SLAVE_Ipaddr "echo server-id=2 >>/etc/my.cnf"
ssh -l root $SLAVE_Ipaddr "echo auto_increment_offset=1 >>/etc/my.cnf"
ssh -l root $SLAVE_Ipaddr "echo auto_increment_increment=2 >>/etc/my.cnf"
ssh -l root $SLAVE_Ipaddr "echo [MysqLd_safe] >>/etc/my.cnf"
ssh -l root $SLAVE_Ipaddr "echo log-error=/var/log/mariadb/mariadb.log >>/etc/my.cnf"
ssh -l root $SLAVE_Ipaddr "echo pid-file=/var/run/mariadb/mariadb.pid >>/etc/my.cnf"
ssh -l root $SLAVE_Ipaddr "echo Replication-do-db=all >>/etc/my.cnf"
ssh -l root $SLAVE_Ipaddr "systemctl restart mariadb"
ssh -l root $SLAVE_Ipaddr "MysqL -e \"slave stop;\""
ssh -l root $SLAVE_Ipaddr "MysqL -e \"change master to master_host=‘$MASTER_Ipaddr‘,master_user=‘tongbu‘,master_password=‘tongbu‘,master_log_file=‘$MASTER_FILE‘,master_log_pos=$MASTER_POS;\""

ssh -l root $SLAVE_Ipaddr "MysqL -e \"slave start;\""
ssh -l root $SLAVE_Ipaddr "MysqL -e \"show slave status\G;\""

}

read -p "please ensure your server is master role,yes or no ?": INPUTif [ $INPUT == "y" -o $INPUT == "yes" ]; thenMARIADB_CONfigelseexit 0fi

大佬总结

以上是大佬教程为你收集整理的auto_install_mariadb_ab.sh全部内容,希望文章能够帮你解决auto_install_mariadb_ab.sh所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:abinstallsh