腳本部署mysql主從

#!/bin/bash
yum -y install mysql mysql-server #安裝數據庫
sed -i '/0/a\server-id=1' /etc/my.cnf
sed -i '/1/a\log-bin=mysql-log' /etc/my.cnf
service mysqld restart
mysql -e "grant all on *.* to cwh@'%' identified by '123';"
mysql -e "flush privileges;"
file=`mysql -e "show master status"|awk '/mysql{print $1}'`
rz=`mysql -e "show master status"|awk '/mysql/{print $2}'`
yum -y install expect

/usr/bin/expect<<EOF
spawn ssh [email protected]
set timeout 1000
expect "~" {send "yum -y install mysql mysql-server\n"}
expect "~" {send "sed -i '/0/aserver-id=2' /etc/my.cnf\n"}
expect "~" {send "sed -i '/2/arelay-log=mysql-relay' /etc/my.cnf\n"}
expect "~" {send "service mysqld restart\n"}
expect "~" {send "mysql -e \"change master to master_host='10.0.0.21',master_user='cwh',master_password='123',master_log_file='$file',master_log_pos=$rz;\"\n"}
expect "~" {send "exit\n"}
expect eof
EOF

發佈了38 篇原創文章 · 獲贊 23 · 訪問量 5589
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章