#!/bin/bash
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來(lái)自于我們對(duì)這個(gè)行業(yè)的熱愛(ài)。我們立志把好的技術(shù)通過(guò)有效、簡(jiǎn)單的方式提供給客戶,將通過(guò)不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:域名注冊(cè)、虛擬主機(jī)、營(yíng)銷軟件、網(wǎng)站建設(shè)、瑞麗網(wǎng)站維護(hù)、網(wǎng)站推廣。#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 另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
文章標(biāo)題:shell之路--mysql主從自動(dòng)部署-創(chuàng)新互聯(lián)
URL地址:http://weahome.cn/article/ddecod.html