{"rsdb":{"rid":"156497","subhead":"","postdate":"0","aid":"117466","fid":"57","uid":"1","topic":"1","content":"

\u8fd9\u91cc\u5047\u8bbe\u6211\u4eec\u5df2\u7ecf\u5728\u8fdc\u7a0b\u4e3b\u673a\u5b89\u88c5\u597d\u4e86MySQL 5.6\uff0c\u5e76\u4e14\u5404\u79cd\u53c2\u6570\u57fa\u672c\u548c\u4e3b\u5e93\u4e00\u81f4\uff0c\u4e3b\u5e93\u80fd\u514d\u5bc6\u7801SSH\u767b\u5f55\u5230\u4ece\u5e93,\u4e3b\u4ece\u5e93\u90fd\u5b89\u88c5\u4e86xtrabackup\u3002<\/p>

\u5047\u8bbe\u4e3b\u5e93\u5730\u5740\uff1a192.168.2.11<\/p>

\u5c06\u8981\u914d\u7f6e\u7684\u4ece\u5e93\u5730\u5740\uff1a192.168.2.12<\/p>

\u811a\u672c\u5982\u4e0b\uff0c\u8f7b\u62cd\uff1a<\/p>

#!\/bin\/bash
# \u4e00\u952e\u521b\u5efa\u4ece\u5e93\uff0c\u9700\u8981\u786e\u4fdd\u672c\u673a\u80fdssh\u514d\u5bc6\u7801\u767b\u5f55\u5230\u4ece\u5e93\u673a\u5668\u3002\u9700\u8981\u786e\u4fdd\u4e8c\u8005\u673a\u5668\u7684\u65f6\u95f4\u540c\u6b65\u3002
# \u5199\u7684\u6bd4\u8f83\u70c2\uff0c\u6709\u65f6\u95f4\u518d\u6539\u6539\u3002
# Date: 2017\/02\/10 By \u4e00\u53ea\u83dc\u9e21
?
echo \"
######################################################################################
\u8bf7\u786e\u4fdd\u4ece\u5e93\u7684server-id\u4e0e\u672c\u673a\u4e0d\u76f8\u540c\uff0c\u4e14\u5176\u4ed6\u6d89\u53ca\u5230\u65e5\u5fd7\u7c7b\u7684\u53c2\u6570\u5c3d\u91cf\u4e0e\u672c\u673a\u4e00\u81f4\u3002
(\u811a\u672c\u91cc\u9762\u9ed8\u8ba4\u4ece\u5e93\u7684datadir\u4e3a\/data\/mysql)
\u8fd9\u91cc\u6211\u4eec\u9ed8\u8ba4\u5df2\u7ecf\u5728\u4e3b\u5e93\u4e0a\u6267\u884c\u8fc7\u521b\u5efa\u540c\u6b65\u7684\u8d26\u6237\u7684SQL\u4e86,\u4e14\u4e3b\u5e93\u80fdSSH\u79d8\u94a5\u65b9\u5f0f\u767b\u5f55\u5230\u4ece\u5e93\u673a\u5668
10s\u5185\u4f60\u53ef\u4ee5ctrl+c\u53d6\u6d88\u6267\u884c\u672c\u811a\u672c
######################################################################################
\"
?
sleep 10
?
# \u5f85\u914d\u7f6e\u7684\u4ece\u5e93IP
REMOTE_HOST='192.168.2.12'
?
# \u672c\u673aMySQL\u914d\u7f6e\u4fe1\u606f
USER='root'
PASS='Abcd@1234'
SOCKET='\/tmp\/mysql.sock'
?
# \u5b9a\u4e49\u4e09\u4e2a\u51fd\u6570
function init_remote(){
? # \u7ed9\u8fdc\u7a0b\u4e3b\u673a\u5b89\u88c5lz4\u3001\u521b\u5efa\u5b58\u653e\u5907\u4efd\u6587\u4ef6\u7684\u76ee\u5f55
? ssh root@$REMOTE_HOST 'yum install lz4 -y'
? ssh root@$REMOTE_HOST 'mkdir \/tmp\/mysql -p'
}
?
function copy_to_remote() {
? # \u8be5\u5907\u4efd\u65b9\u6cd5\u53c2\u8003\u81ea\u59dc\u627f\u5c27\u5927\u725b\u7684\u5fae\u4fe1\u516c\u4f17\u53f7
? \/usr\/bin\/innobackupex --user=$USER --password=$PASS --parallel=4 --socket=$SOCKET --no-timestamp --stream=xbstream . |\\
? lz4 -B4 |\\
? ssh root@$REMOTE_HOST \\
? \"cat - | lz4 -d -B7 | xbstream -x -C \/tmp\/mysql\"
}
?
function apply_to_remote (){
? ssh root@$REMOTE_HOST 'innobackupex --apply-log \/tmp\/mysql\/'
? ssh root@$REMOTE_HOST '\/bin\/rm -fr \/data\/mysql\/*'
? ssh root@$REMOTE_HOST 'mv \/tmp\/mysql\/* \/data\/mysql\/'
? ssh root@$REMOTE_HOST 'chown mysql.mysql \/data\/mysql\/ -R'
? ssh root@$REMOTE_HOST '\/etc\/init.d\/mysqld start'
}
?
# \u4f9d\u6b21\u6267\u884c\u4e0a\u9762\u76843\u4e2a\u51fd\u6570
init_remote || echo \"init_remote failed. exit\"
copy_to_remote
apply_to_remote || echo \"apply to remote failed. exit\"
?
?
echo \"
###############################################################################
\u4ece\u5e93\u7684\u6570\u636e\u5df2\u7ecf\u540c\u6b65\u5b8c\u6210\uff0c\u8fd8\u9700\u8981\u53bb\u4ece\u5e93\u4fee\u6539my.cnf \u5728
[mysqld]\u6bb5\u52a0\u4e0arelay_log = mysql-relay.bin \u91cd\u542f\u6570\u636e\u5e93\uff0c
\u7136\u540e\u767b\u5f55\u6570\u636e\u5e93\u6267\u884c\uff1a
RESET MASTER;
\u518d\u6267\u884cCHANGE MASTER TO\u7684\u6307\u4ee4\uff0c\u7136\u540estart slave;\u5373\u53ef\u3002
?
\u683c\u5f0f\u5982\u4e0b\uff1a
CHANGE MASTER TO
? MASTER_HOST='192.168.2.11',
? MASTER_USER='repluser',
? MASTER_PASSWORD='Abcd@123456',
? MASTER_PORT=3306,
? MASTER_LOG_FILE='mysql-bin.000012',
? MASTER_LOG_POS=500,
? MASTER_CONNECT_RETRY=10,
? MASTER_HEARTBEAT_PERIOD=60;
###############################################################################
\"<\/p>

\u8fd9\u6837\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>","orderid":"0","title":"\u811a\u672c\u65b9\u5f0f\u4e00\u952e\u5feb\u901f\u521b\u5efaMySQL\u4ece\u5e93","smalltitle":"","mid":"0","fname":"\u6570\u636e\u5e93\u7f16\u7a0b","special_id":"0","bak_id":"0","info":"0","hits":"279","pages":"1","comments":"0","posttime":"2017-02-21 08:15:59","list":"1487636159","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"\u811a\u672c<\/A> \u65b9\u5f0f<\/A> \u5feb\u901f<\/A> \u521b\u5efa<\/A> MySQL<\/A> \u4ece\u5e93<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"14.17.22.31","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"\u811a\u672c\u65b9\u5f0f\u4e00\u952e\u5feb\u901f\u521b\u5efaMySQL\u4ece\u5e93","lastview":"1713606225","digg_num":"1395","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}