From d8123d9350b9e8f6ff9ca42eabb4b715506e8115 Mon Sep 17 00:00:00 2001 From: midoks Date: Sun, 5 Nov 2023 19:57:14 +0800 Subject: [PATCH 01/20] Update install.sh --- plugins/php/versions/83/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/php/versions/83/install.sh b/plugins/php/versions/83/install.sh index e0989cf2d..cab5e055c 100755 --- a/plugins/php/versions/83/install.sh +++ b/plugins/php/versions/83/install.sh @@ -52,7 +52,7 @@ if [ ! -d $sourcePath/php/php${PHP_VER} ];then if [ ! -f $sourcePath/php/php-${version}.tar.xz ];then - wget --no-check-certificate -O $sourcePath/php/php-${version}.tar.xz https://downloads.php.net/~eric/php-${version}.tar.xz + wget --no-check-certificate -O $sourcePath/php/php-${version}.tar.xz https://downloads.php.net/~jakub/php-${version}.tar.xz fi #检测文件是否损坏. From 83466e927e45f5099cbf9d1d569cb534ebd84241 Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 6 Nov 2023 18:29:20 +0800 Subject: [PATCH 02/20] update --- plugins/mysql/conf/my5.5.cnf | 2 +- plugins/mysql/conf/my5.6.cnf | 2 +- plugins/mysql/conf/my5.7.cnf | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/mysql/conf/my5.5.cnf b/plugins/mysql/conf/my5.5.cnf index 5b257948b..3b9050e57 100644 --- a/plugins/mysql/conf/my5.5.cnf +++ b/plugins/mysql/conf/my5.5.cnf @@ -53,7 +53,7 @@ long_query_time=10 #log_queries_not_using_indexes=on #log_slow_admin_statements=1 #log_slow_slave_statements=1 -expire_logs_days=30 +expire_logs_days=7 relay-log=mdserver relay-log-index=mdserver diff --git a/plugins/mysql/conf/my5.6.cnf b/plugins/mysql/conf/my5.6.cnf index 983e95fdb..09404b10d 100644 --- a/plugins/mysql/conf/my5.6.cnf +++ b/plugins/mysql/conf/my5.6.cnf @@ -56,7 +56,7 @@ long_query_time=10 #log_queries_not_using_indexes=on #log_slow_admin_statements=1 #log_slow_slave_statements=1 -expire_logs_days=30 +expire_logs_days=7 relay-log=mdserver relay-log-index=mdserver diff --git a/plugins/mysql/conf/my5.7.cnf b/plugins/mysql/conf/my5.7.cnf index 95801b7cd..6c0e3d682 100644 --- a/plugins/mysql/conf/my5.7.cnf +++ b/plugins/mysql/conf/my5.7.cnf @@ -57,7 +57,7 @@ long_query_time=10 #log_queries_not_using_indexes=1 #log_slow_admin_statements=1 #log_slow_slave_statements=1 -expire_logs_days=30 +expire_logs_days=7 relay-log=mdserver relay-log-index=mdserver From 462f7b78ec9271b5064571f2ed9d9e1ac842a207 Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 7 Nov 2023 12:17:04 +0800 Subject: [PATCH 03/20] Update tool_task.py --- plugins/clean/tool_task.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/clean/tool_task.py b/plugins/clean/tool_task.py index e7f27e86a..d61b4f41f 100644 --- a/plugins/clean/tool_task.py +++ b/plugins/clean/tool_task.py @@ -52,8 +52,8 @@ def createBgTask(): removeBgTask() args = { "period": "day", - "hour": "2", - "minute": "30", + "hour": "0", + "minute": "15", } createBgTaskByName(getPluginName(), args) From 7c4231d9c07d1b16f40582ac76d0eec9165fcbe3 Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 7 Nov 2023 16:36:16 +0800 Subject: [PATCH 04/20] Update debian.sh --- scripts/install/debian.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/install/debian.sh b/scripts/install/debian.sh index e6bb20590..349822217 100644 --- a/scripts/install/debian.sh +++ b/scripts/install/debian.sh @@ -54,7 +54,8 @@ fi apt-get update -y apt install -y wget curl lsof unzip tar cron expect locate lrzsz -apt install -y rar unrar +apt install -y rar +apt install -y unrar apt install -y python3-pip python3-dev python3-venv From 2c31318a5cabf1fb4a97335171eed21db2a6b14d Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 7 Nov 2023 18:06:09 +0800 Subject: [PATCH 05/20] Update index.py --- plugins/mysql/index.py | 56 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index a1c3da9d6..e51b0f3b7 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -2431,11 +2431,65 @@ def getSlaveList(version=''): db = pMysqlDb() dlist = db.query('show slave status') + + # print(dlist) data = {} data['data'] = dlist return mw.getJson(data) +def trySlaveSyncBugfix(version=''): + if status(version) == 'stop': + return mw.returnJson(False, 'MySQL未启动', []) + + mode_file = getSyncModeFile() + if not os.path.exists(mode_file): + return mw.returnJson(False, '需要先设置同步配置') + + mode = mw.readFile(mode_file) + if mode != 'sync-user': + return mw.returnJson(False, '仅支持【同步账户】模式') + + conn = pSqliteDb('slave_sync_user') + slave_sync_data = conn.field('ip,port,user,pass,mode,cmd').select() + if len(slave_sync_data) < 1: + return mw.returnJson(False, '需要先添加【同步用户】配置!') + + # print(slave_sync_data) + # 本地从库 + sdb = pMysqlDb() + + gtid_purged = '' + + for i in range(len(slave_sync_data)): + port = slave_sync_data[i]['port'] + password = slave_sync_data[i]['pass'] + host = slave_sync_data[i]['ip'] + user = slave_sync_data[i]['user'] + + # print(port, password, host) + + mdb = mw.getMyORM() + mdb.setHost(host) + mdb.setPort(port) + mdb.setUser(user) + mdb.setPwd(password) + mdb.setSocket('') + + var_gtid = mdb.query('show VARIABLES like "%gtid_purged%"') + if len(var_gtid) > 0: + gtid_purged += var_gtid[0]['Value'] + ',' + + gtid_purged = gtid_purged.strip(',') + sql = "set @@global.gtid_purged='" + gtid_purged + "'" + + sdb.query('stop slave') + # print(sql) + sdb.query(sql) + sdb.query('start slave') + return mw.returnJson(True, 'ok') + + def getSlaveSyncCmd(version=''): root = mw.getRunDir() cmd = 'cd ' + root + ' && python3 ' + root + \ @@ -3115,6 +3169,8 @@ if __name__ == "__main__": print(getMasterRepSlaveUserCmd(version)) elif func == 'get_slave_list': print(getSlaveList(version)) + elif func == 'try_slave_sync_bugfix': + print(trySlaveSyncBugfix(version)) elif func == 'get_slave_sync_cmd': print(getSlaveSyncCmd(version)) elif func == 'get_slave_ssh_list': From f17a9864617d203f1a946fe4cf4476d4b76c5e6d Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 7 Nov 2023 18:55:44 +0800 Subject: [PATCH 06/20] =?UTF-8?q?mysql=20=E5=90=8C=E6=AD=A51236=E9=94=99?= =?UTF-8?q?=E8=AF=AF-=E4=BF=AE=E5=A4=8D=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/mysql/index.py | 2 +- plugins/mysql/js/mysql.js | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index e51b0f3b7..1f5989d5e 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -2487,7 +2487,7 @@ def trySlaveSyncBugfix(version=''): # print(sql) sdb.query(sql) sdb.query('start slave') - return mw.returnJson(True, 'ok') + return mw.returnJson(True, '修复成功!') def getSlaveSyncCmd(version=''): diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index 6754df892..c02528ac3 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -2346,11 +2346,16 @@ function masterOrSlaveConf(version=''){ "+(info['Slave_SQL_Running_State'] == '' ? '无':info['Slave_SQL_Running_State']) +"\ "; + + var btn_list = ['复制错误',"取消"]; + if (info['Last_IO_Error'].search(/1236/i)>0){ + btn_list = ['复制错误',"取消","尝试修复"]; + } layer.open({ type: 1, title: '同步异常信息', area: ['600px','300px'], - btn:['复制错误',"取消"], + btn:btn_list, content:"
\
\
\ @@ -2385,6 +2390,14 @@ function masterOrSlaveConf(version=''){ copyText(info['Slave_SQL_Running_State']); return; } + }, + btn3:function(){ + myPost('try_slave_sync_bugfix', {}, function(data){ + var rdata = $.parseJSON(data.data); + showMsg(rdata.msg, function(){ + masterOrSlaveConf(); + },{ icon: rdata.status ? 1 : 5 },2000); + }); } }); }); From e24bf5313c42168dd34c0bdb2e68bb6d966d1a8e Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 7 Nov 2023 19:41:29 +0800 Subject: [PATCH 07/20] Update debian.sh --- scripts/install/debian.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/install/debian.sh b/scripts/install/debian.sh index 349822217..a5fffa898 100644 --- a/scripts/install/debian.sh +++ b/scripts/install/debian.sh @@ -179,7 +179,9 @@ apt install -y libmagickwand-dev apt install -y libxml2 libxml2-dev libbz2-dev libmcrypt-dev libpspell-dev librecode-dev apt install -y libgmp-dev libgmp3-dev libreadline-dev libxpm-dev -apt install -y dia pkg-config +apt install -y dia + +apt install -y pkg-config apt install -y zlib1g-dev apt install -y libevent-dev libncurses5-dev libldap2-dev From bb5240dc43abb4d4233dda4e1c2e46ce33636a95 Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 7 Nov 2023 19:42:02 +0800 Subject: [PATCH 08/20] Update ubuntu.sh --- scripts/install/ubuntu.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/install/ubuntu.sh b/scripts/install/ubuntu.sh index f0d69f13f..1a9fe9759 100644 --- a/scripts/install/ubuntu.sh +++ b/scripts/install/ubuntu.sh @@ -103,8 +103,11 @@ apt install -y libmagickwand-dev apt install -y libxml2 libxml2-dev libbz2-dev libmcrypt-dev libpspell-dev librecode-dev apt install -y libgmp-dev libgmp3-dev libreadline-dev libxpm-dev -apt install -y dia pkg-config +apt install -y dia + +apt install -y pkg-config apt install -y zlib1g-dev + apt install -y libjpeg-dev libpng-dev apt install -y libfreetype6 apt install -y libjpeg62-turbo-dev From f67be6d59f9c58f2c76fd2e45c7585f8cc2c31d5 Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 8 Nov 2023 00:49:01 +0800 Subject: [PATCH 09/20] update --- plugins/mysql/index.html | 1 + plugins/mysql/index.py | 74 +++++++++++++++ plugins/mysql/index_mysql.py | 74 +++++++++++++++ plugins/mysql/js/mysql.js | 171 +++++++++++++++++++++++++++++++++++ 4 files changed, 320 insertions(+) create mode 100644 plugins/mysql/index_mysql.py diff --git a/plugins/mysql/index.html b/plugins/mysql/index.html index 1789a0965..78ec5cd5c 100755 --- a/plugins/mysql/index.html +++ b/plugins/mysql/index.html @@ -12,6 +12,7 @@

性能优化

日志

慢日志

+

BINLOG

管理列表

主从配置

diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 1f5989d5e..459a830d0 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -293,6 +293,14 @@ def getDataDir(): return tmp.groups()[0].strip() +def getLogBinName(): + file = getConf() + content = mw.readFile(file) + rep = 'log-bin\s*=\s*(.*)' + tmp = re.search(rep, content) + return tmp.groups()[0].strip() + + def getPidFile(): file = getConf() content = mw.readFile(file) @@ -333,6 +341,68 @@ def binLog(): return mw.returnJson(True, '设置成功!') +def binLogList(): + args = getArgs() + data = checkArgs(args, ['page', 'page_size', 'tojs']) + if not data[0]: + return data[1] + + page = int(args['page']) + page_size = int(args['page_size']) + + data_dir = getDataDir() + log_bin_name = getLogBinName() + + alist = os.listdir(data_dir) + log_bin_l = [] + for x in range(len(alist)): + f = alist[x] + t = {} + if f.startswith(log_bin_name) and f != (log_bin_name + '.index'): + abspath = data_dir + '/' + f + t['name'] = f + t['size'] = os.path.getsize(abspath) + t['time'] = mw.getDataFromInt(os.path.getctime(abspath)) + log_bin_l.append(t) + + # print(log_bin_l) + # print(data_dir, log_bin_name) + + count = len(log_bin_l) + + page_start = (page - 1) * page_size + page_end = page_start + page_size + if page_end > count: + page_end = count + + data = {} + page_args = {} + page_args['count'] = count + page_args['p'] = page + page_args['row'] = page_size + page_args['tojs'] = args['tojs'] + data['page'] = mw.getPage(page_args) + data['data'] = log_bin_l[page_start:page_end] + + return mw.getJson(data) + + +def binLogListLook(): + args = getArgs() + data = checkArgs(args, ['file']) + if not data[0]: + return data[1] + + data_dir = getDataDir() + my_bin = getServerDir() + '/bin' + my_binlog_cmd = my_bin + '/mysqlbinlog' + + cmd = my_binlog_cmd + ' --no-defaults --base64-output=decode-rows -vvvv ' + \ + data_dir + '/' + args['file'] + '|tail -50' + + print(cmd) + + def cleanBinLog(): db = pMysqlDb() cleanTime = time.strftime('%Y-%m-%d %H:%i:%s', time.localtime()) @@ -3075,6 +3145,10 @@ if __name__ == "__main__": print(getConf()) elif func == 'bin_log': print(binLog()) + elif func == 'binlog_list': + print(binLogList()) + elif func == 'binlog_look': + print(binLogListLook()) elif func == 'clean_bin_log': print(cleanBinLog()) elif func == 'error_log': diff --git a/plugins/mysql/index_mysql.py b/plugins/mysql/index_mysql.py new file mode 100644 index 000000000..31f132b87 --- /dev/null +++ b/plugins/mysql/index_mysql.py @@ -0,0 +1,74 @@ +# coding:utf-8 + +import sys +import io +import os +import time +import subprocess +import re +import json + +sys.path.append(os.getcwd() + "/class/core") +import mw + + +if mw.isAppleSystem(): + cmd = 'ls /usr/local/lib/ | grep python | cut -d \\ -f 1 | awk \'END {print}\'' + info = mw.execShell(cmd) + p = "/usr/local/lib/" + info[0].strip() + "/site-packages" + sys.path.append(p) + + +app_debug = False +if mw.isAppleSystem(): + app_debug = True + + +def getPluginName(): + return 'mysql' + + +def getPluginDir(): + return mw.getPluginDir() + '/' + getPluginName() + + +def getSPluginDir(): + return '/www/server/mdserver-web/plugins/' + getPluginName() + + +def getServerDir(): + return mw.getServerDir() + '/' + getPluginName() + + +def getConf(): + path = getServerDir() + '/etc/my.cnf' + return path + + +def getDataDir(): + file = getConf() + content = mw.readFile(file) + rep = 'datadir\s*=\s*(.*)' + tmp = re.search(rep, content) + return tmp.groups()[0].strip() + + +def binLogListLook(args): + + file = args['file'] + line = args['line'] + + data_dir = getDataDir() + my_bin = getServerDir() + '/bin' + my_binlog_cmd = my_bin + '/mysqlbinlog' + + cmd = my_binlog_cmd + ' --no-defaults --base64-output=decode-rows -vvvv ' + \ + data_dir + '/' + file + '|tail -' + line + + data = mw.execShell(cmd) + + rdata = {} + rdata['cmd'] = cmd + rdata['data'] = data[0] + + return rdata diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index c02528ac3..dc8274fca 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -59,6 +59,63 @@ function myAsyncPost(method,args){ return syncPost('/plugins/run', {name:'mysql', func:method, args:_args}); } + +function myPostCallbak(method, version, args,callback){ + var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); + + var req_data = {}; + req_data['name'] = 'mysql'; + req_data['func'] = method; + req_data['script']='index_mysql'; + args['version'] = version; + + + if (typeof(args) == 'string' && args == ''){ + req_data['args'] = JSON.stringify(toArrayObject(args)); + } else { + req_data['args'] = JSON.stringify(args); + } + + $.post('/plugins/callback', req_data, function(data) { + layer.close(loadT); + if (!data.status){ + layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']}); + return; + } + + if(typeof(callback) == 'function'){ + callback(data); + } + },'json'); +} + +function myPostCallbakN(method, version, args,callback){ + + var req_data = {}; + req_data['name'] = 'mysql'; + req_data['func'] = method; + req_data['script']='index_mysql'; + args['version'] = version; + + + if (typeof(args) == 'string' && args == ''){ + req_data['args'] = JSON.stringify(toArrayObject(args)); + } else { + req_data['args'] = JSON.stringify(args); + } + + $.post('/plugins/callback', req_data, function(data) { + if (!data.status){ + layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']}); + return; + } + + if(typeof(callback) == 'function'){ + callback(data); + } + },'json'); +} + function vaildPhpmyadmin(url,username,password){ // console.log("Authorization: Basic " + btoa(username + ":" + password)); $.ajax({ @@ -1163,6 +1220,120 @@ function dbList(page, search){ } +function myBinRollingLogs(_name, func, _args, line){ + + var file_line = 100; + if ( typeof(line) != 'undefined' ){ + file_line = line; + } + + var reqTimer = null; + + function requestLogs(func,file,line){ + myPostCallbakN(func,'',{'file':file,"line":line}, function(rdata){ + var data = rdata.data.data; + if(data == '') { + data = '当前没有日志!'; + } + + var ebody = ''; + $("#my_rolling_logs").html(ebody); + var ob = document.getElementById('roll_info_log'); + ob.scrollTop = ob.scrollHeight; + }); + } + + + layer.open({ + type: 1, + title: _name + '日志', + area: '640px', + end: function(){ + if (reqTimer){ + clearInterval(reqTimer); + } + }, + content:'
\ + \ + \ + \ +
', + success:function(){ + var fileName = _args['file']; + // requestLogs(func,fileName,file_line); + // reqTimer = setInterval(function(){ + // requestLogs(func,fileName,file_line); + // },3000); + } + }); +} +function myBinLogsRender(page){ + var _data = {}; + if (typeof(page) =='undefined'){ + var page = 1; + } + + _data['page'] = page; + _data['page_size'] = 10; + _data['tojs'] = 'myBinLogsRender'; + myPost('binlog_list', _data, function(data){ + var rdata = $.parseJSON(data.data); + // console.log(rdata); + var list = ''; + for(i in rdata.data){ + list += ''; + + list += '' + rdata.data[i]['name'] +''; + list += '' + toSize(rdata.data[i]['size'])+''; + list += '' + rdata.data[i]['time'] +''; + + + list += ''; + list += '查看 | '; + list += '解码查看'; + list += ''; + } + + $("#binlog_list tbody").html(list); + $('#binlog_page').html(rdata.page); + + + $('#binlog_list .look').click(function(){ + var i = $(this).data('index'); + var file = rdata.data[i]['name']; + + myBinRollingLogs('查看','binLogListLook',{'file':file },100); + // myPostCallbak('binLogListLook','',{'file':file}, function(rdata){ + // console.log(rdata); + // }); + }); + + + }); +} + +function myBinLogs(){ + var con = '
\ + \ + \ +
\ +
\ + \ + \ + \ + \ + \ + \ + \ +
文件名称大小时间操作
\ +
\ +
\ +
\ +
'; + $(".soft-man-con").html(con); + myBinLogsRender(1); +} + function myLogs(){ myPost('bin_log', {status:1}, function(data){ From aba594caf224ba705e914ae4de0fbd33beec3d1a Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 8 Nov 2023 01:00:29 +0800 Subject: [PATCH 10/20] update --- plugins/mysql/index.html | 6 ++++-- plugins/mysql/js/mysql.js | 12 +++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/plugins/mysql/index.html b/plugins/mysql/index.html index 78ec5cd5c..187869409 100755 --- a/plugins/mysql/index.html +++ b/plugins/mysql/index.html @@ -58,12 +58,14 @@ text-align: right; } + + \ No newline at end of file diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index dc8274fca..e76b7b9f9 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -1253,9 +1253,15 @@ function myBinRollingLogs(_name, func, _args, line){ clearInterval(reqTimer); } }, - content:'
\ - \ - \ + content:'\ +
\ +
\ + \ + \ + \ + \ +
cmd
\ +
\ \
', success:function(){ From 9e123f067b97d6acf82c12493c2ef85f2450bddf Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 8 Nov 2023 01:12:02 +0800 Subject: [PATCH 11/20] update --- plugins/mysql/index_mysql.py | 2 +- plugins/mysql/js/mysql.js | 40 +++++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/plugins/mysql/index_mysql.py b/plugins/mysql/index_mysql.py index 31f132b87..a1357c8d4 100644 --- a/plugins/mysql/index_mysql.py +++ b/plugins/mysql/index_mysql.py @@ -63,7 +63,7 @@ def binLogListLook(args): my_binlog_cmd = my_bin + '/mysqlbinlog' cmd = my_binlog_cmd + ' --no-defaults --base64-output=decode-rows -vvvv ' + \ - data_dir + '/' + file + '|tail -' + line + data_dir + '/' + file + '|tail -' + str(line) data = mw.execShell(cmd) diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index e76b7b9f9..3919958bb 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -1232,14 +1232,21 @@ function myBinRollingLogs(_name, func, _args, line){ function requestLogs(func,file,line){ myPostCallbakN(func,'',{'file':file,"line":line}, function(rdata){ var data = rdata.data.data; + var cmd = rdata.data.cmd; if(data == '') { data = '当前没有日志!'; } + $('#my_rolling_cmd').html(cmd); + + $('#my_rolling_copy').click(function(){ + copyText(cmd); + }); + var ebody = ''; $("#my_rolling_logs").html(ebody); var ob = document.getElementById('roll_info_log'); - ob.scrollTop = ob.scrollHeight; + ob.scrollTop = ob.scrollHeight; }); } @@ -1253,23 +1260,24 @@ function myBinRollingLogs(_name, func, _args, line){ clearInterval(reqTimer); } }, - content:'\ -
\ -
\ - \ - \ - \ - \ -
cmd
\ -
\ - \ -
', + content:'
\ +
\ + \ + \ + \ + \ +
cmd
\ +
\ +
\ +
\ + \ +
', success:function(){ var fileName = _args['file']; - // requestLogs(func,fileName,file_line); - // reqTimer = setInterval(function(){ - // requestLogs(func,fileName,file_line); - // },3000); + requestLogs(func,fileName,file_line); + reqTimer = setInterval(function(){ + requestLogs(func,fileName,file_line); + },3000); } }); } From beb00d46e046b4288fec0a150b64bd420641b60d Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 8 Nov 2023 01:15:28 +0800 Subject: [PATCH 12/20] update --- plugins/mysql/index_mysql.py | 21 +++++++++++++++++++++ plugins/mysql/js/mysql.js | 10 +++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/plugins/mysql/index_mysql.py b/plugins/mysql/index_mysql.py index a1357c8d4..9a03ca285 100644 --- a/plugins/mysql/index_mysql.py +++ b/plugins/mysql/index_mysql.py @@ -62,6 +62,27 @@ def binLogListLook(args): my_bin = getServerDir() + '/bin' my_binlog_cmd = my_bin + '/mysqlbinlog' + cmd = my_binlog_cmd + ' --no-defaults ' + \ + data_dir + '/' + file + '|tail -' + str(line) + + data = mw.execShell(cmd) + + rdata = {} + rdata['cmd'] = cmd + rdata['data'] = data[0] + + return rdata + + +def binLogListLookDecode(args): + + file = args['file'] + line = args['line'] + + data_dir = getDataDir() + my_bin = getServerDir() + '/bin' + my_binlog_cmd = my_bin + '/mysqlbinlog' + cmd = my_binlog_cmd + ' --no-defaults --base64-output=decode-rows -vvvv ' + \ data_dir + '/' + file + '|tail -' + str(line) diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index 3919958bb..f6be7302a 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -1315,14 +1315,14 @@ function myBinLogsRender(page){ $('#binlog_list .look').click(function(){ var i = $(this).data('index'); var file = rdata.data[i]['name']; - myBinRollingLogs('查看','binLogListLook',{'file':file },100); - // myPostCallbak('binLogListLook','',{'file':file}, function(rdata){ - // console.log(rdata); - // }); }); - + $('#binlog_list .look_decode').click(function(){ + var i = $(this).data('index'); + var file = rdata.data[i]['name']; + myBinRollingLogs('查看','binLogListLookDecode',{'file':file },100); + }); }); } From 496e94ad54fd0199bc9866818f9049f82578578e Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 8 Nov 2023 01:16:55 +0800 Subject: [PATCH 13/20] Update mysql.js --- plugins/mysql/js/mysql.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index f6be7302a..d94181e4a 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -1346,6 +1346,14 @@ function myBinLogs(){
'; $(".soft-man-con").html(con); myBinLogsRender(1); + + $('.soft-man-con .relay_trace').click(function(){ + + }); + + $('.soft-man-con .binlog_trace').click(function(){ + + }); } function myLogs(){ From c0310a26288b7c97624173cd47cc739e5359348c Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 8 Nov 2023 01:44:17 +0800 Subject: [PATCH 14/20] =?UTF-8?q?binlog=E6=97=A5=E5=BF=97=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=9F=BA=E6=9C=ACOK?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/mysql/index.py | 18 +------- plugins/mysql/index_mysql.py | 85 ++++++++++++++++++++++++++++++++++++ plugins/mysql/js/mysql.js | 16 +++---- 3 files changed, 94 insertions(+), 25 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 459a830d0..2314bfd24 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -358,7 +358,7 @@ def binLogList(): for x in range(len(alist)): f = alist[x] t = {} - if f.startswith(log_bin_name) and f != (log_bin_name + '.index'): + if f.startswith(log_bin_name) and not f.endswith('.index'): abspath = data_dir + '/' + f t['name'] = f t['size'] = os.path.getsize(abspath) @@ -387,22 +387,6 @@ def binLogList(): return mw.getJson(data) -def binLogListLook(): - args = getArgs() - data = checkArgs(args, ['file']) - if not data[0]: - return data[1] - - data_dir = getDataDir() - my_bin = getServerDir() + '/bin' - my_binlog_cmd = my_bin + '/mysqlbinlog' - - cmd = my_binlog_cmd + ' --no-defaults --base64-output=decode-rows -vvvv ' + \ - data_dir + '/' + args['file'] + '|tail -50' - - print(cmd) - - def cleanBinLog(): db = pMysqlDb() cleanTime = time.strftime('%Y-%m-%d %H:%i:%s', time.localtime()) diff --git a/plugins/mysql/index_mysql.py b/plugins/mysql/index_mysql.py index 9a03ca285..5b3254622 100644 --- a/plugins/mysql/index_mysql.py +++ b/plugins/mysql/index_mysql.py @@ -53,6 +53,22 @@ def getDataDir(): return tmp.groups()[0].strip() +def getRelayLogName(): + file = getConf() + content = mw.readFile(file) + rep = 'relay-log\s*=\s*(.*)' + tmp = re.search(rep, content) + return tmp.groups()[0].strip() + + +def getLogBinName(): + file = getConf() + content = mw.readFile(file) + rep = 'log-bin\s*=\s*(.*)' + tmp = re.search(rep, content) + return tmp.groups()[0].strip() + + def binLogListLook(args): file = args['file'] @@ -93,3 +109,72 @@ def binLogListLookDecode(args): rdata['data'] = data[0] return rdata + + +def binLogListTraceRelay(args): + + file = args['file'] + line = args['line'] + + relay_name = getRelayLogName() + data_dir = getDataDir() + alist = os.listdir(data_dir) + relay_list = [] + for x in range(len(alist)): + f = alist[x] + t = {} + if f.startswith(relay_name) and not f.endswith('.index'): + relay_list.append(f) + + file = relay_list[0] + + my_bin = getServerDir() + '/bin' + my_binlog_cmd = my_bin + '/mysqlbinlog' + + cmd = my_binlog_cmd + ' --no-defaults --base64-output=decode-rows -vvvv ' + \ + data_dir + '/' + file + '|tail -' + str(line) + + data = mw.execShell(cmd) + + rdata = {} + rdata['cmd'] = cmd + rdata['data'] = data[0] + + return rdata + + +def binLogListTraceBinLog(args): + rdata = {} + file = args['file'] + line = args['line'] + + data_dir = getDataDir() + log_bin_name = getLogBinName() + + alist = os.listdir(data_dir) + log_bin_l = [] + for x in range(len(alist)): + f = alist[x] + t = {} + if f.startswith(log_bin_name) and not f.endswith('.index'): + log_bin_l.append(f) + + if len(log_bin_l) == 0: + rdata['cmd'] = '' + rdata['data'] = '无BINLOG' + return rdata + + file = log_bin_l[0] + + my_bin = getServerDir() + '/bin' + my_binlog_cmd = my_bin + '/mysqlbinlog' + + cmd = my_binlog_cmd + ' --no-defaults --base64-output=decode-rows -vvvv ' + \ + data_dir + '/' + file + '|tail -' + str(line) + + data = mw.execShell(cmd) + + rdata['cmd'] = cmd + rdata['data'] = data[0] + + return rdata diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index d94181e4a..45e2656da 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -1243,7 +1243,7 @@ function myBinRollingLogs(_name, func, _args, line){ copyText(cmd); }); - var ebody = ''; + var ebody = ''; $("#my_rolling_logs").html(ebody); var ob = document.getElementById('roll_info_log'); ob.scrollTop = ob.scrollHeight; @@ -1254,7 +1254,7 @@ function myBinRollingLogs(_name, func, _args, line){ layer.open({ type: 1, title: _name + '日志', - area: '640px', + area: ['800px','700px'], end: function(){ if (reqTimer){ clearInterval(reqTimer); @@ -1270,14 +1270,14 @@ function myBinRollingLogs(_name, func, _args, line){
\ \
\ - \ + \
', success:function(){ var fileName = _args['file']; requestLogs(func,fileName,file_line); reqTimer = setInterval(function(){ requestLogs(func,fileName,file_line); - },3000); + },1000); } }); } @@ -1315,13 +1315,13 @@ function myBinLogsRender(page){ $('#binlog_list .look').click(function(){ var i = $(this).data('index'); var file = rdata.data[i]['name']; - myBinRollingLogs('查看','binLogListLook',{'file':file },100); + myBinRollingLogs('查看BINLOG','binLogListLook',{'file':file },100); }); $('#binlog_list .look_decode').click(function(){ var i = $(this).data('index'); var file = rdata.data[i]['name']; - myBinRollingLogs('查看','binLogListLookDecode',{'file':file },100); + myBinRollingLogs('查看解码BINLOG','binLogListLookDecode',{'file':file },100); }); }); } @@ -1348,11 +1348,11 @@ function myBinLogs(){ myBinLogsRender(1); $('.soft-man-con .relay_trace').click(function(){ - + myBinRollingLogs('中继日志跟踪','binLogListTraceRelay',{'file':''},100); }); $('.soft-man-con .binlog_trace').click(function(){ - + myBinRollingLogs('最新BINLOG日志跟踪','binLogListTraceBinLog',{'file':''},100); }); } From b3f495efb819ed86f7fadd56b397909396a5960c Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 8 Nov 2023 01:49:44 +0800 Subject: [PATCH 15/20] Update index.py --- plugins/mysql/index.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 2314bfd24..0a2b9653c 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -365,6 +365,8 @@ def binLogList(): t['time'] = mw.getDataFromInt(os.path.getctime(abspath)) log_bin_l.append(t) + sorted(log_bin_l, key=lambda x: x['name'], reverse=True) + # print(log_bin_l) # print(data_dir, log_bin_name) From e5a9f2c1979d25b88730133cfb3f4e6f0863c709 Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 8 Nov 2023 01:52:49 +0800 Subject: [PATCH 16/20] Update index_mysql.py --- plugins/mysql/index_mysql.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/mysql/index_mysql.py b/plugins/mysql/index_mysql.py index 5b3254622..6dc14cf1c 100644 --- a/plugins/mysql/index_mysql.py +++ b/plugins/mysql/index_mysql.py @@ -126,6 +126,7 @@ def binLogListTraceRelay(args): if f.startswith(relay_name) and not f.endswith('.index'): relay_list.append(f) + relay_list = sorted(relay_list, reverse=True) file = relay_list[0] my_bin = getServerDir() + '/bin' @@ -164,6 +165,7 @@ def binLogListTraceBinLog(args): rdata['data'] = '无BINLOG' return rdata + log_bin_l = sorted(log_bin_l, reverse=True) file = log_bin_l[0] my_bin = getServerDir() + '/bin' From 69cde4ebc3746d3458a448ec143e062734d3e06b Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 8 Nov 2023 01:56:55 +0800 Subject: [PATCH 17/20] Update index_mysql.py --- plugins/mysql/index_mysql.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index_mysql.py b/plugins/mysql/index_mysql.py index 6dc14cf1c..791d9038f 100644 --- a/plugins/mysql/index_mysql.py +++ b/plugins/mysql/index_mysql.py @@ -112,7 +112,7 @@ def binLogListLookDecode(args): def binLogListTraceRelay(args): - + rdata = {} file = args['file'] line = args['line'] @@ -127,6 +127,11 @@ def binLogListTraceRelay(args): relay_list.append(f) relay_list = sorted(relay_list, reverse=True) + if len(relay_list) == 0: + rdata['cmd'] = '' + rdata['data'] = '无Relay日志' + return rdata + file = relay_list[0] my_bin = getServerDir() + '/bin' @@ -137,7 +142,6 @@ def binLogListTraceRelay(args): data = mw.execShell(cmd) - rdata = {} rdata['cmd'] = cmd rdata['data'] = data[0] From 283d3c5f1f1b0fc0e2274289fb80fb25cc0590ec Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 8 Nov 2023 01:57:27 +0800 Subject: [PATCH 18/20] Update index.py --- plugins/mysql/index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 0a2b9653c..6767a0d43 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -365,7 +365,7 @@ def binLogList(): t['time'] = mw.getDataFromInt(os.path.getctime(abspath)) log_bin_l.append(t) - sorted(log_bin_l, key=lambda x: x['name'], reverse=True) + sorted(log_bin_l, key=lambda x: x['time'], reverse=True) # print(log_bin_l) # print(data_dir, log_bin_name) From 89e5d579262260163a8369fe1436b3b7989f93b1 Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 8 Nov 2023 01:58:45 +0800 Subject: [PATCH 19/20] Update index.py --- plugins/mysql/index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 6767a0d43..b4c7a0ff9 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -365,7 +365,7 @@ def binLogList(): t['time'] = mw.getDataFromInt(os.path.getctime(abspath)) log_bin_l.append(t) - sorted(log_bin_l, key=lambda x: x['time'], reverse=True) + log_bin_l = sorted(log_bin_l, key=lambda x: x['time'], reverse=True) # print(log_bin_l) # print(data_dir, log_bin_name) From e73533b6116c5b74a2dd6b45951f4ffe0dd6dafc Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 8 Nov 2023 02:04:14 +0800 Subject: [PATCH 20/20] Update mysql.js --- plugins/mysql/js/mysql.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index 45e2656da..bfb8ea425 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -1308,6 +1308,10 @@ function myBinLogsRender(page){ list += ''; } + if (rdata.data.length ==0){ + list = '无数据'; + } + $("#binlog_list tbody").html(list); $('#binlog_page').html(rdata.page);