diff --git a/plugins/mysql/conf/gtid.cnf b/plugins/mysql/conf/gtid.cnf index e69de29bb..081e62c39 100644 --- a/plugins/mysql/conf/gtid.cnf +++ b/plugins/mysql/conf/gtid.cnf @@ -0,0 +1,2 @@ +gtid_mode=ON +enforce_gtid_consistency=ON diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index f6d7daafc..8da3ccf40 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -1402,6 +1402,29 @@ def getDbrunMode(version=''): return mw.returnJson(True, "ok", {'mode': mode}) +def setDbrunMode(version=''): + args = getArgs() + data = checkArgs(args, ['mode', 'reload']) + if not data[0]: + return data[1] + + mode = args['mode'] + dbreload = args['reload'] + + if not mode in ['classic', 'gtid']: + return mw.returnJson(False, "mode的值无效:" + mode) + + origin_mode = recognizeDbMode() + path = getConf() + con = mw.readFile(path) + rep = r"!include %s/%s\.cnf" % (getServerDir() + "/etc/mode", origin_mode) + rep_after = "!include %s/%s.cnf" % (getServerDir() + "/etc/mode", mode) + con = re.sub(rep, rep_after, con) + mw.writeFile(path, con) + + return mw.returnJson(True, "切换成功!") + + def findBinlogDoDb(): conf = getConf() con = mw.readFile(conf) @@ -2258,6 +2281,8 @@ if __name__ == "__main__": print(getTotalStatistics()) elif func == 'get_dbrun_mode': print(getDbrunMode(version)) + elif func == 'set_dbrun_mode': + print(setDbrunMode(version)) elif func == 'get_masterdb_list': print(getMasterDbList(version)) elif func == 'get_master_status': diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index 9ba010b10..19279ba07 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -1844,8 +1844,8 @@ function masterOrSlaveConf(version=''){ var limitCon = '\

\ 主从同步模式\ - \ - \ + \ + \

\
\

\ @@ -1892,6 +1892,44 @@ function masterOrSlaveConf(version=''){ }); }); + $('.db-mode').click(function(){ + if ($(this).hasClass('btn-success')){ + //no action + return; + } + + var mode = 'classic'; + if ($(this).hasClass('btn-gtid')){ + mode = 'gtid'; + } + + layer.open({ + type:1, + title:"MySQL主从模式切换", + shadeClose:false, + btnAlign: 'c', + btn: ['切换并重启', '切换不重启'], + yes: function(index, layero){ + this.change(index,mode,"yes"); + + }, + btn2: function(index, layero){ + this.change(index,mode,"no"); + return false; + }, + change:function(index,mode,reload){ + console.log(index,mode,reload); + myPost('set_dbrun_mode',{'mode':mode,'reload':reload},function(data){ + layer.close(index); + var rdata = $.parseJSON(data.data); + showMsg(rdata.msg ,function(){ + getMasterStatus(); + },{ icon: rdata.status ? 1 : 5 },2000); + }); + } + }); + }); + if (rdata.status){ getMasterDbList(); } diff --git a/scripts/install.sh b/scripts/install.sh index 91e78049e..901cc55ba 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -58,6 +58,12 @@ if [ $OSNAME != "macos" ];then mkdir -p /www/backup/database mkdir -p /www/backup/site + + # cn=$(curl -fsSL -m 10 http://ipinfo.io/json | grep "\"country\": \"CN\"") + # if [ ! -z "$cn" ];then + + # fi + if [ ! -d /www/server/mdserver-web ];then wget -O /tmp/master.zip https://codeload.github.com/midoks/mdserver-web/zip/master cd /tmp && unzip /tmp/master.zip