#!/bin/bash
让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名注册、虚拟主机、营销软件、网站建设、瑞丽网站维护、网站推广。#auto make install Mysql AB Relication
#by author max
#date 2017-05-04
MYSQL_SOFT="mysql mysql-server mysql-devel php-mysql"
NUM=`rpm -qa |grep -i mysql |wc -l`
CODE=$?
#Mysql To Install 2017
if [ $NUM -ne 0 ];then
echo -e "\033[32mThis server mysql already install.\033[0m"
read -p "Please ensure yum remove mysql server , Yes or No[y/n]": INPUT
if [ $INPUT == "y" ];then
yum remove $MYSQL_SOFT -y
rm -rf /var/lib/mysql /etc/my.cnf
yum -y install $MYSQL_SOFT
else
exit 0
fi
else
rm -rf /var/lib/mysql
yum -y install $MYSQL_SOFT
if [ $CODE -eq 0 ];then
echo -e "\033[32mThe mysql install successfully.\033[0m"
exit 1
fi
fi
#mysql to start and config
cat >/etc/my.cnf< [mysqld] datadir=/car/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql symbpolic-links=0 log-bin=mysql-bin server-id=1 auto_increment_offset=1 auto_increment_increment=2 [mysql_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysql/mysqld.pid replicate-do-db=all EOF /etc/init.d/mysqld restart ps -ef |grep mysql function MYSQL_CONFIG(){ #master config mysql mysql -e "grant replication slave on *.* to 'max'@'%' identified by 'zhaomiao';" MASTER_FILE=`mysql -e "show master status;"|tail -1|awk '{print $1}'` MASTER_POS=`mysql -e "show master status;"|tail -1|awk '{print $2}'` MASTER_IPADDR=`ifconfig eth0 |grep "Bcast"|awk '{print $2}'|cut -d: -f2` read -p "please enter input slave ip address": SLAVE_IPADDR #slave config mysql ssh -l root $SLAVE_IPADDR "sed -i 's#server-id = 1#server-id = 2#g' /etc/my.cnf" ssh -l root $SLAVE_IPADDR "/etc/init.d/mysqld restart" ssh -l root $SLAVE_IPADDR "mysql -e \"change master to master_host='$MASTER_IPADDR',master_user='max',master_password='zhaomiao',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 ? yes or no[y/n]": INPUT if [ $INPUT == "y" ];then MYSQL_CONFIG else exit 0 fi 另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
标题名称:shell之路--mysql主从自动部署-创新互联
分享地址:http://cdkjz.cn/article/ddecod.html