#!/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<<eof
[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 '} '
Master_pos= ' mysql-e ' show master status; | Tail-1|awk ' {print $} '
Master_ipaddr= ' ifconfig eth0 |grep "bcast" |awk ' {print $} ' |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 "Ensure your server is master?" Yes or no[y/n] ": INPUT
if [$INPUT = = "Y"];then
Mysql_config
Else
Exit 0
Fi
Shell Road--mysql Master-Slave Automatic deployment