From 5a955c2a3358b9c3b68da952b7c0f71d546f7951 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 11 May 2024 20:21:07 +0800 Subject: [PATCH 001/327] =?UTF-8?q?tidb=E6=8F=92=E4=BB=B6init?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/tidb/conf/tidb.conf | 0 plugins/tidb/ico.png | Bin 0 -> 5927 bytes plugins/tidb/index.html | 35 ++ plugins/tidb/index.py | 586 +++++++++++++++++++++++++++ plugins/tidb/info.json | 17 + plugins/tidb/init.d/tidb.service.tpl | 12 + plugins/tidb/init.d/tidb.tpl | 77 ++++ plugins/tidb/install.sh | 55 +++ plugins/tidb/js/tidb.js | 297 ++++++++++++++ 9 files changed, 1079 insertions(+) create mode 100644 plugins/tidb/conf/tidb.conf create mode 100644 plugins/tidb/ico.png create mode 100755 plugins/tidb/index.html create mode 100755 plugins/tidb/index.py create mode 100755 plugins/tidb/info.json create mode 100644 plugins/tidb/init.d/tidb.service.tpl create mode 100644 plugins/tidb/init.d/tidb.tpl create mode 100755 plugins/tidb/install.sh create mode 100755 plugins/tidb/js/tidb.js diff --git a/plugins/tidb/conf/tidb.conf b/plugins/tidb/conf/tidb.conf new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/tidb/ico.png b/plugins/tidb/ico.png new file mode 100644 index 0000000000000000000000000000000000000000..78ec24547b5237e17eabdc49f8878032c6c5e314 GIT binary patch literal 5927 zcmdUTXE=qa^Ai5<)}-Q6fRKAcBPGErby5 z(M5?~Mz0xB-;?M1eto~*zwf@zb)9?fwbs4vv)BG{){ZvNQ>Q|)pa1|=ni?ub0Kg## z2jmFo)tb-U0RXJcK*vNCn$A;-&!fc`D8-g3M3yK-Ah3WETl{}ObP*-GOpaYe3NDjj zm&irtDaGbdVoT&$0vZ1@xzJxvl;|P_WDyyXL^vIhepK zT5J|AF$?(4{~VpHtS<{0EV3z{%q;%-F?f*kd67~6c=XrrlDfU5{0*njB@Wf|lhf@7 zFIH6@mv}T!*S6M-JPA0v6>-y}zR|<_@5GvKn|CADv|Z2kfA7EjxcfAH{ig2{MrVOe z=6GWEXkh%HpmH}hb0;iu%m3MySLB9uz>1Xl>DCVMbJK?1gZ1)iR3}DUaU1`M8hWn`B8@&(n6h$X$Eri2l3%y z7F(^(w^Vk^U)k#7j<@>D;{1+>UGuXmqT32T6mO(C0zluZsiJ6de|&w)Lf=@Co@~2c z$xKDdqWG0+%u~!W1}D3HKk=1Tk@>c4G}3B*cZTJ%&3sO@$PVSRE(Cc}a%JGsujBL3 zCz`y=C;Gjyki7rZD8t=#syD@X-wv7(g+D4PeDRci6OY&Gd7N5F@ZL|tH`lPaJX=EDVj)}VpzUqKzAb6iN z!a;bgamhfJ&Bk(_VMZ4beNDUQ6^rg0`Wbn4Mn@h0caC)IaJeNd)|3KUC)R;mUW7OU z8_jeP6KEqv}H31#YUG9B`djCXRu@mqG|AtqWv+39Pf3y(xh&fuU%l*fn& zor5OTKXIrs)9^QiJ98JW@EtwTIYSIgljR4#nQKs)K1m5u{Jt*u@6DX z@MT>!F$T!KvEV@D+J0ksNu@{qTr_QFrBetU^E^G(k=HRlo;uw>FQt2qM^5y%-k@~a z(#j+Uvd#I;3hE`5$$d5aae{HoHA83@YL`9~Y5a~K#bN@CkNx7-uMBo+L`{8ud+hc( zPEBS#VURJE{d4?k8<#QJcF3j`XFH2w1l5}^(Vt!YKRJ`&RN_9d9yiVv;&jRH#A-K; z_?_J@gIts=_6unre3KrS4U&~`Qs1;x4SHl?y}a=2!E5V6sYy5sN8lOIus;cY_hO4ZrXWWDrie zIx>{6dUJD$?2?_R`F(p=%AIMTT1;bF$TRn~w~4LYOT|=!iYoZ?o^X`%^0uPKlionL z>B%$M6-RTfA{FQEiMQd`%|5C5rRFzU?0%Y*wrue=G8Co?eW4V!Y=~mRFcWPys>}+> zBIZsdUOWg`HU4Mh`%cG@?Z@ahmwl&y$Wc*xc1 zuMrhUh${=|0Po9oW?g1!(!SE5W6qZv6JyZvL^HGLsm^6Pc>#A#QAKJlb_R#+!GAZJ z{E2JJRewD68>j5*csfHhqQcKtdUbdw`HQEIGtQTnzW02mW;V1$?XnnZJB@U2G#OT( z&Z~w+rRZOFPvAyKGmc4Q4|O|5>zLaK%7tW3Zw#im++|IOWr{<7rq^iijAeZymAMxz zAKviAwSe9LrV|zZDR5a{SH+ONxgWEct)?q3B*H1=6WuPcxijVZR;Zw&@28A2(vshU zhF?3cnAAy-gFM96wK!5i<>f|w?>v!0V+p$%3j z5sKoM_Ld^%T928Eh+oDV2f{zB{c??xGVCD)Q=t_Nzrl$ zsLrZ47$mq)s!KV9nrt#!WKYR(%*Xn4Na252F=DOpdjMJ*=y-*)_5o+d)&;$%E#*p8NIk+%XofvM38UJo#Cq zRY@eIGbv-ma~h&0b+;G=9|yUtTP)tdlstH7v06l;SsnbHL#`=@Uhg2l*0;RvZesMe(KZSJlr~w#9Uw6`4=2+|3spko9Z_n$kV zZjJl?u?~69ZabA>`ERF!n~aB@t5qxy*Nw=2bAbTakX=8Ch3O_aLY)n=U92E_t{rhq zdV}_o0#k(b`EKskYm*?^?$olnRpO>I6RelP??T3iWBTqJ)bO!!X8(PMcbbhNo@kM5d6DE`~HgsIC1%521hyX+NH61#g z+QhmmAIlR3K@fH~DEpbguYei-GXYITd_f_DIz?VykLV8H`KtvK&UJvOeBs?=N^QAj z6)r>ICzar#dr?cK)09*1OrVnoi4^7Gx&7p6Xy6HG63Gr!zY*f(AJPWx{HeE{(!*cmfBAaSJ2T zY3-Q|p<_Z$9|dDU$#0){dt~_}pXb(bM1yRg|T*_bXI z9xWCWW(y-9xjAO4UFWY(XJ@Qf$IyRo57j&=A$wP#t3xs2XT+weQQqe2Q)p- zGME8|)IegRR1gW?0`5xS zHgS>>JQat>=Xdsn!Z`FVgJ|?(L>$2Cv4X<nvM}jK{>%Om;!DeST zpd~vv5OfCBQd=;MJIF07G`O%Ji|=UvQ!fnUQu{!z<%PX_cHq8rCTs|v*mn$X&iO;h zp+NKy0dg6o(5DTDe7FweUcLuzu1Ai^%pjvz8PG~}&pc%YD+Di9Uw_$Q8axDvHnA4e^}`3zzN4Em|Vl3r9AXN(SW3UC765Z z1eO<$r#0ok_eaHWa)SG&`6vWde!85B6Asm+wu|@tE5PyLdp+GW0q!dP)mx{NY+0xP z|H^o#KYsex^o%M!2H=gr+djpMlr)g3%&%7Z29XrJ0!L<-JuoUzC7ZnhHvHd5V^FQz zja9=}mAc3~38FAbna()SGShl3!Q%ah zMMsm6I5^^|OlLVHBnF)|mAnkcJ%s7df)=PzaJdQqP6|AR0niIIuXxY@I@dROkZB5B zL;@hK4Vh|T9B2T%lcC<$4}oI>VCEVr04qp57Jz08sQLYu3fzLC%jp5gV*S5BY&=BP zyzmcAvlY6^z}&p*o%8cm8XOk~ zL+j0Xa+j0hC*jp{TM`pu)0e?@(lSXmaaqw|(7}hFwQU$oK*MpDVD$=mgKFFsB={3p zb^R8vM<)g>P&E&%RE7U>p##21`@8ZMFVP6RMjQwk>pMCD_c44xa!b~yjwcO?kMf1h z>`w%g^IMRC%uryp<|CZYjllQG;A=7k!iYUG;Lsg0c4Dq8lT8akl3~Re9*0wAT;LFm zV4BR|qv}V28|C0g-L>dJ7&wfDOV=j{)$zo@nq6p{>t<~~V`?Et10Aj6aLB$68>=a7 z-_WRlGO*xVKio7*WF!YS96==6fu*+X6>z8nBM%F?3Tfd4vUOiy2rq&eF@(MAzQo~9 z9y>TI3w$rHOKQl3CwnGn9)I)ayGJ8Mq^hbvr}X3Uvzf)L5jIZ;_}wOnq$w)TyQESS z+$q%NA8Eh4=X|}->;7QPz24B^lvG;$hf-fg93OQvtr)y)TP}qHCjenOxcB170IQv) z4@fp3n{jwR2o{tg8&6}vUo^NL$JYVJ25;%r5M-lpoV+@pkp&BTnH_NNlYzZ;KRgas zn1t2xQi4-->xWhA(Sz=c9|+Q`biq$IJPAZpK zce0s14>Ne@@w~;)g9gXpbGAOuDnyn=E>G2hlpVyuBM8P9rmI=NH{FO9hEPEqobTS( zsRvRBgF)eIpE+Nf;9z^kRbI7>cq88lhFd9{IXL*OfZzR(tY8M-Wx8YU#RMO!NCuv@ z`Uk=}Zr2){7d8l?Ns{whx9p^80dofSe6{Kgm6hy84JY4}lG=;lm7M#;?0HU!gtLBB z4>eBll8u0SRVaJEpLCrxd*yY289hLeiC0E)$ESALocZ;SgM#fl<=)Dzp13UhB4OJ~ z7Gd!CrR8i~j|j)ZpKXM)P#BI4`+#5-y)mDKR|=B}4*XRK(9DhdAHOjasqS>o`Hkg+ zq<{)Z3PuSPJPEQqO`URtgyU(o-{JY4W!_rC_Qy3z65Nk5z1gz%Xa)|Ed%iw0?jgWQ zyGg*TX;GYA?}`C**Co^-Aq(8X-EzF`h_EEwmBiq%_DMkRlxubPP722D{Mn_vZ>a|j zesCoVg$fuk=D()aPkG;pMB;|^$xDagV*7QYyiytPbBzUsw=-8QWC1r;R-U-~+z@8) zeckTp=9L>Hw3uspQJ0zMz!xDQxnXgZD-eg?)cO7IPeGEB{|)QYWa9}06qa67Wsd{x z0mp%d=k*xgbm~lg{iw`~NRD`4`|@qud*M{^7%vLDrr;nC+5)EO{oy?MFA;7sA+x{N z0LFX(nhU~dF(iM027NA%uAPm{;0(=&*NwG0LlJQOihYXT&kp*jNiNVQ7E(Pr)g!Wa zXXHU%zj<+wx=hBa!|#i0*BGvQ!cDGDem83hze699BcrzNd9*qpu|CskKcg~86fX9n zH+v=vMX^*p$<0K>&CDc6M~Q9lJ7^t2kr3Zl!LSHI?KC?tevsNag(sh%2OH zg@8SpfVQL1zv&YN=4c9noDNHV=Fc~l@=7m7h#)eN|44-%xc)MBw1ig^K8&^(7(Sb0 zze=aDvQ=40p2|6sFZ{B%f`SOU<~^9wt`Hg%*BfM~Xh3+?T+4 z!RZZfo=30WH3+H11J5HCr_es8l{}fs-C3`Ml3S+mP1|H)OYhcx7{I749q_<@$14UrS?jb*PG{5Flzx0^KCe_Eh)(Nk;EAr?RuXF)`80iNXvo2y?nafGi0|O2 zz8z~@b!19oW6TQy&!eD^r`|Dk#NU>zUZKp6u_EnEj&|b_%73r8f#SJcF!X2r|Bq%> XEZhWf%_lMAuSHW;Po+f3{?Y#cQ_Y2* literal 0 HcmV?d00001 diff --git a/plugins/tidb/index.html b/plugins/tidb/index.html new file mode 100755 index 000000000..49eda1061 --- /dev/null +++ b/plugins/tidb/index.html @@ -0,0 +1,35 @@ + + +
+
+
+
+

服务

+

自启动

+

配置修改

+ +

性能调整

+

负载状态

+

复制状态

+

集群状态

+

集群节点

+

运行日志

+

相关说明

+
+
+
+
+
+
+ \ No newline at end of file diff --git a/plugins/tidb/index.py b/plugins/tidb/index.py new file mode 100755 index 000000000..3f8a69ed9 --- /dev/null +++ b/plugins/tidb/index.py @@ -0,0 +1,586 @@ +# coding:utf-8 + +import sys +import io +import os +import time +import re + +sys.path.append(os.getcwd() + "/class/core") +import mw + +app_debug = False +if mw.isAppleSystem(): + app_debug = True + + +def getPluginName(): + return 'tidb' + + +def getPluginDir(): + return mw.getPluginDir() + '/' + getPluginName() + + +def getServerDir(): + return mw.getServerDir() + '/' + getPluginName() + + +def getInitDFile(): + current_os = mw.getOs() + if current_os == 'darwin': + return '/tmp/' + getPluginName() + + if current_os.startswith('freebsd'): + return '/etc/rc.d/' + getPluginName() + + return '/etc/init.d/' + getPluginName() + + +def getConf(): + path = getServerDir() + "/redis.conf" + return path + + +def getConfTpl(): + path = getPluginDir() + "/config/redis.conf" + return path + + +def getInitDTpl(): + path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl" + return path + +def getArgs(): + args = sys.argv[2:] + tmp = {} + args_len = len(args) + + if args_len == 1: + t = args[0].strip('{').strip('}') + t = t.split(':', 1) + tmp[t[0]] = t[1] + elif args_len > 1: + for i in range(len(args)): + t = args[i].split(':', 1) + tmp[t[0]] = t[1] + return tmp + +def getArgsBk(): + args = sys.argv[3:] + tmp = {} + args_len = len(args) + + if args_len == 1: + t = args[0].strip('{').strip('}') + if t.strip() == '': + tmp = [] + else: + t = t.split(':') + tmp[t[0]] = t[1] + tmp[t[0]] = t[1] + elif args_len > 1: + for i in range(len(args)): + t = args[i].split(':') + tmp[t[0]] = t[1] + return tmp + +def checkArgs(data, ck=[]): + for i in range(len(ck)): + if not ck[i] in data: + return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!')) + return (True, mw.returnJson(True, 'ok')) + +def configTpl(): + path = getPluginDir() + '/tpl' + pathFile = os.listdir(path) + tmp = [] + for one in pathFile: + file = path + '/' + one + tmp.append(file) + return mw.getJson(tmp) + + +def readConfigTpl(): + args = getArgs() + data = checkArgs(args, ['file']) + if not data[0]: + return data[1] + + content = mw.readFile(args['file']) + content = contentReplace(content) + return mw.returnJson(True, 'ok', content) + +def getPidFile(): + file = getConf() + content = mw.readFile(file) + rep = 'pidfile\s*(.*)' + tmp = re.search(rep, content) + return tmp.groups()[0].strip() + +def status(): + pid_file = getPidFile() + if not os.path.exists(pid_file): + return 'stop' + + # data = mw.execShell( + # "ps aux|grep redis |grep -v grep | grep -v python | grep -v mdserver-web | awk '{print $2}'") + + # if data[0] == '': + # return 'stop' + return 'start' + +def contentReplace(content): + service_path = mw.getServerDir() + content = content.replace('{$ROOT_PATH}', mw.getRootDir()) + content = content.replace('{$SERVER_PATH}', service_path) + content = content.replace('{$SERVER_APP}', service_path + '/redis') + content = content.replace('{$REDIS_PASS}', mw.getRandomString(10)) + return content + + + +def initDreplace(): + + file_tpl = getInitDTpl() + service_path = os.path.dirname(os.getcwd()) + + initD_path = getServerDir() + '/init.d' + if not os.path.exists(initD_path): + os.mkdir(initD_path) + file_bin = initD_path + '/' + getPluginName() + + # initd replace + if not os.path.exists(file_bin): + content = mw.readFile(file_tpl) + content = content.replace('{$SERVER_PATH}', service_path) + mw.writeFile(file_bin, content) + mw.execShell('chmod +x ' + file_bin) + + # log + dataLog = getServerDir() + '/data' + if not os.path.exists(dataLog): + mw.execShell('chmod +x ' + file_bin) + + # config replace + dst_conf = getServerDir() + '/redis.conf' + dst_conf_init = getServerDir() + '/init.pl' + if not os.path.exists(dst_conf_init): + conf_content = mw.readFile(getConfTpl()) + conf_content = conf_content.replace('{$SERVER_PATH}', service_path) + conf_content = conf_content.replace( + '{$REDIS_PASS}', mw.getRandomString(10)) + + mw.writeFile(dst_conf, conf_content) + mw.writeFile(dst_conf_init, 'ok') + + # systemd + systemDir = mw.systemdCfgDir() + systemService = systemDir + '/' + getPluginName() + '.service' + if os.path.exists(systemDir) and not os.path.exists(systemService): + systemServiceTpl = getPluginDir() + '/init.d/' + getPluginName() + '.service.tpl' + service_path = mw.getServerDir() + se_content = mw.readFile(systemServiceTpl) + se_content = se_content.replace('{$SERVER_PATH}', service_path) + mw.writeFile(systemService, se_content) + mw.execShell('systemctl daemon-reload') + + return file_bin + + +def redisOp(method): + file = initDreplace() + + current_os = mw.getOs() + if current_os == "darwin": + data = mw.execShell(file + ' ' + method) + if data[1] == '': + return 'ok' + return data[1] + + if current_os.startswith("freebsd"): + data = mw.execShell('service ' + getPluginName() + ' ' + method) + if data[1] == '': + return 'ok' + return data[1] + + data = mw.execShell('systemctl ' + method + ' ' + getPluginName()) + if data[1] == '': + return 'ok' + return data[1] + + +def start(): + return redisOp('start') + + +def stop(): + return redisOp('stop') + + +def restart(): + status = redisOp('restart') + + log_file = runLog() + mw.execShell("echo '' > " + log_file) + return status + + +def reload(): + return redisOp('reload') + + +def getPort(): + conf = getServerDir() + '/redis.conf' + content = mw.readFile(conf) + + rep = "^(" + 'port' + ')\s*([.0-9A-Za-z_& ~]+)' + tmp = re.search(rep, content, re.M) + if tmp: + return tmp.groups()[1] + + return '6379' + + +def getRedisCmd(): + requirepass = "" + conf = getServerDir() + '/redis.conf' + content = mw.readFile(conf) + rep = "^(requirepass" + ')\s*([.0-9A-Za-z_& ~]+)' + tmp = re.search(rep, content, re.M) + if tmp: + requirepass = tmp.groups()[1] + + default_ip = '127.0.0.1' + port = getPort() + # findDebian = mw.execShell('cat /etc/issue |grep Debian') + # if findDebian[0] != '': + # default_ip = mw.getLocalIp() + cmd = getServerDir() + "/bin/redis-cli -h " + \ + default_ip + ' -p ' + port + " " + + if requirepass != "": + cmd = getServerDir() + '/bin/redis-cli -h ' + default_ip + \ + ' -p ' + port + ' -a "' + requirepass + '" ' + + return cmd + +def runInfo(): + s = status() + if s == 'stop': + return mw.returnJson(False, '未启动') + + + cmd = getRedisCmd() + cmd = cmd + 'info' + + # print(cmd) + data = mw.execShell(cmd)[0] + # print(data) + res = [ + 'tcp_port', + 'uptime_in_days', # 已运行天数 + 'connected_clients', # 连接的客户端数量 + 'used_memory', # Redis已分配的内存总量 + 'used_memory_rss', # Redis占用的系统内存总量 + 'used_memory_peak', # Redis所用内存的高峰值 + 'mem_fragmentation_ratio', # 内存碎片比率 + 'total_connections_received', # 运行以来连接过的客户端的总数量 + 'total_commands_processed', # 运行以来执行过的命令的总数量 + 'instantaneous_ops_per_sec', # 服务器每秒钟执行的命令数量 + 'keyspace_hits', # 查找数据库键成功的次数 + 'keyspace_misses', # 查找数据库键失败的次数 + 'latest_fork_usec' # 最近一次 fork() 操作耗费的毫秒数 + ] + data = data.split("\n") + result = {} + for d in data: + if len(d) < 3: + continue + t = d.strip().split(':') + if not t[0] in res: + continue + result[t[0]] = t[1] + return mw.getJson(result) + +def infoReplication(): + # 复制信息 + s = status() + if s == 'stop': + return mw.returnJson(False, '未启动') + + cmd = getRedisCmd() + cmd = cmd + 'info replication' + + # print(cmd) + data = mw.execShell(cmd)[0] + # print(data) + res = [ + #slave + 'role',#角色 + 'master_host', # 连接主库HOST + 'master_port', # 连接主库PORT + 'master_link_status', # 连接主库状态 + 'master_last_io_seconds_ago', # 上次同步时间 + 'master_sync_in_progress', # 正在同步中 + 'slave_read_repl_offset', # 从库读取复制位置 + 'slave_repl_offset', # 从库复制位置 + 'slave_priority', # 从库同步优先级 + 'slave_read_only', # 从库是否仅读 + 'replica_announced', # 已复制副本 + 'connected_slaves', # 连接从库数量 + 'master_failover_state', # 主库故障状态 + 'master_replid', # 主库复制ID + 'master_repl_offset', # 主库复制位置 + 'second_repl_offset', # 主库复制位置时间 + 'repl_backlog_active', # 复制状态 + 'repl_backlog_size', # 复制大小 + 'repl_backlog_first_byte_offset', # 第一个字节偏移量 + 'repl_backlog_histlen', # backlog中数据的长度 + ] + + data = data.split("\n") + result = {} + for d in data: + if len(d) < 3: + continue + t = d.strip().split(':') + if not t[0] in res: + continue + result[t[0]] = t[1] + + if 'role' in result and result['role'] == 'master': + connected_slaves = int(result['connected_slaves']) + slave_l = [] + for x in range(connected_slaves): + slave_l.append('slave'+str(x)) + + for d in data: + if len(d) < 3: + continue + t = d.strip().split(':') + if not t[0] in slave_l: + continue + result[t[0]] = t[1] + + return mw.getJson(result) + + +def clusterInfo(): + #集群信息 + # https://redis.io/commands/cluster-info/ + s = status() + if s == 'stop': + return mw.returnJson(False, '未启动') + + cmd = getRedisCmd() + cmd = cmd + 'cluster info' + + # print(cmd) + data = mw.execShell(cmd)[0] + # print(data) + + res = [ + 'cluster_state',#状态 + 'cluster_slots_assigned', # 被分配的槽 + 'cluster_slots_ok', # 被分配的槽状态 + 'cluster_slots_pfail', # 连接主库状态 + 'cluster_slots_fail', # 失败的槽 + 'cluster_known_nodes', # 知道的节点 + 'cluster_size', # 大小 + 'cluster_current_epoch', # + 'cluster_my_epoch', # + 'cluster_stats_messages_sent', # 发送 + 'cluster_stats_messages_received', # 接受 + 'total_cluster_links_buffer_limit_exceeded', # + ] + + data = data.split("\n") + result = {} + for d in data: + if len(d) < 3: + continue + t = d.strip().split(':') + if not t[0] in res: + continue + result[t[0]] = t[1] + + return mw.getJson(result) + +def clusterNodes(): + s = status() + if s == 'stop': + return mw.returnJson(False, '未启动') + + cmd = getRedisCmd() + cmd = cmd + 'cluster nodes' + + # print(cmd) + data = mw.execShell(cmd)[0] + # print(data) + + data = data.strip().split("\n") + return mw.getJson(data) + +def initdStatus(): + current_os = mw.getOs() + if current_os == 'darwin': + return "Apple Computer does not support" + + if current_os.startswith('freebsd'): + initd_bin = getInitDFile() + if os.path.exists(initd_bin): + return 'ok' + + shell_cmd = 'systemctl status ' + \ + getPluginName() + ' | grep loaded | grep "enabled;"' + data = mw.execShell(shell_cmd) + if data[0] == '': + return 'fail' + return 'ok' + + +def initdInstall(): + current_os = mw.getOs() + if current_os == 'darwin': + return "Apple Computer does not support" + + # freebsd initd install + if current_os.startswith('freebsd'): + import shutil + source_bin = initDreplace() + initd_bin = getInitDFile() + shutil.copyfile(source_bin, initd_bin) + mw.execShell('chmod +x ' + initd_bin) + mw.execShell('sysrc ' + getPluginName() + '_enable="YES"') + return 'ok' + + mw.execShell('systemctl enable ' + getPluginName()) + return 'ok' + + +def initdUinstall(): + current_os = mw.getOs() + if current_os == 'darwin': + return "Apple Computer does not support" + + if current_os.startswith('freebsd'): + initd_bin = getInitDFile() + os.remove(initd_bin) + mw.execShell('sysrc ' + getPluginName() + '_enable="NO"') + return 'ok' + + mw.execShell('systemctl disable ' + getPluginName()) + return 'ok' + + +def runLog(): + return getServerDir() + '/data/redis.log' + + +def getRedisConfInfo(): + conf = getServerDir() + '/redis.conf' + + gets = [ + {'name': 'bind', 'type': 2, 'ps': '绑定IP(修改绑定IP可能会存在安全隐患)','must_show':1}, + {'name': 'port', 'type': 2, 'ps': '绑定端口','must_show':1}, + {'name': 'timeout', 'type': 2, 'ps': '空闲链接超时时间,0表示不断开','must_show':1}, + {'name': 'maxclients', 'type': 2, 'ps': '最大连接数','must_show':1}, + {'name': 'databases', 'type': 2, 'ps': '数据库数量','must_show':1}, + {'name': 'requirepass', 'type': 2, 'ps': 'redis密码,留空代表没有设置密码','must_show':1}, + {'name': 'maxmemory', 'type': 2, 'ps': 'MB,最大使用内存,0表示不限制','must_show':1}, + {'name': 'slaveof', 'type': 2, 'ps': '同步主库地址','must_show':0}, + {'name': 'masterauth', 'type': 2, 'ps': '同步主库密码', 'must_show':0} + ] + content = mw.readFile(conf) + + result = [] + for g in gets: + rep = "^(" + g['name'] + ')\s*([.0-9A-Za-z_& ~]+)' + tmp = re.search(rep, content, re.M) + if not tmp: + if g['must_show'] == 0: + continue + + g['value'] = '' + result.append(g) + continue + g['value'] = tmp.groups()[1] + if g['name'] == 'maxmemory': + g['value'] = g['value'].strip("mb") + result.append(g) + + return result + + +def getRedisConf(): + data = getRedisConfInfo() + return mw.getJson(data) + + +def submitRedisConf(): + gets = ['bind', 'port', 'timeout', 'maxclients', + 'databases', 'requirepass', 'maxmemory','slaveof','masterauth'] + args = getArgs() + conf = getServerDir() + '/redis.conf' + content = mw.readFile(conf) + for g in gets: + if g in args: + rep = g + '\s*([.0-9A-Za-z_& ~]+)' + val = g + ' ' + args[g] + + if g == 'maxmemory': + val = g + ' ' + args[g] + "mb" + + if g == 'requirepass' and args[g] == '': + content = re.sub('requirepass', '#requirepass', content) + if g == 'requirepass' and args[g] != '': + content = re.sub('#requirepass', 'requirepass', content) + content = re.sub(rep, val, content) + + if g != 'requirepass': + content = re.sub(rep, val, content) + mw.writeFile(conf, content) + reload() + return mw.returnJson(True, '设置成功') + +if __name__ == "__main__": + func = sys.argv[1] + if func == 'status': + print(status()) + elif func == 'start': + print(start()) + elif func == 'stop': + print(stop()) + elif func == 'restart': + print(restart()) + elif func == 'reload': + print(reload()) + elif func == 'initd_status': + print(initdStatus()) + elif func == 'initd_install': + print(initdInstall()) + elif func == 'initd_uninstall': + print(initdUinstall()) + elif func == 'run_info': + print(runInfo()) + elif func == 'info_replication': + print(infoReplication()) + elif func == 'cluster_info': + print(clusterInfo()) + elif func == 'cluster_nodes': + print(clusterNodes()) + elif func == 'conf': + print(getConf()) + elif func == 'run_log': + print(runLog()) + elif func == 'get_redis_conf': + print(getRedisConf()) + elif func == 'submit_redis_conf': + print(submitRedisConf()) + elif func == 'config_tpl': + print(configTpl()) + elif func == 'read_config_tpl': + print(readConfigTpl()) + else: + print('error') diff --git a/plugins/tidb/info.json b/plugins/tidb/info.json new file mode 100755 index 000000000..6a4e38b58 --- /dev/null +++ b/plugins/tidb/info.json @@ -0,0 +1,17 @@ +{ + "sort": 10, + "ps": "分布式数据库(高度兼容MySQL)[社区版][暂时不可用]", + "name": "tidb", + "title": "TiDB", + "shell": "install.sh", + "versions":["v7.5.1","v8.0.0"], + "tip": "soft", + "checks": "server/tidb", + "path": "server/tidb", + "display": 1, + "author": "tidb", + "date": "2024-05-11", + "home": "https://cn.pingcap.com/product-community/", + "type": 0, + "pid": "2" +} diff --git a/plugins/tidb/init.d/tidb.service.tpl b/plugins/tidb/init.d/tidb.service.tpl new file mode 100644 index 000000000..8e8eb5693 --- /dev/null +++ b/plugins/tidb/init.d/tidb.service.tpl @@ -0,0 +1,12 @@ +[Unit] +Description=Redis In-Memory Data Store +After=network.target + +[Service] +Type=forking +ExecStart={$SERVER_PATH}/redis/bin/redis-server {$SERVER_PATH}/redis/redis.conf +ExecReload=/bin/kill -USR2 $MAINPID +Restart=on-failure + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/plugins/tidb/init.d/tidb.tpl b/plugins/tidb/init.d/tidb.tpl new file mode 100644 index 000000000..b7cf93630 --- /dev/null +++ b/plugins/tidb/init.d/tidb.tpl @@ -0,0 +1,77 @@ +#!/bin/sh +# chkconfig: 2345 55 25 +# description: Redis Service + +### BEGIN INIT INFO +# Provides: Redis +# Required-Start: $all +# Required-Stop: $all +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: starts Redis +# Description: starts the MDW-Web +### END INIT INFO + +# Simple Redis init.d script conceived to work on Linux systems +# as it does use of the /proc filesystem. + +CONF="{$SERVER_PATH}/redis/redis.conf" +REDISPORT=$(cat $CONF |grep port|grep -v '#'|awk '{print $2}') +REDISPASS=$(cat $CONF |grep requirepass|grep -v '#'|awk '{print $2}') +if [ "$REDISPASS" != "" ];then + REDISPASS=" -a $REDISPASS" +fi +EXEC={$SERVER_PATH}/redis/bin/redis-server +CLIEXEC="{$SERVER_PATH}/redis/bin/redis-cli -p $REDISPORT$REDISPASS" +PIDFILE={$SERVER_PATH}/redis/redis_6379.pid + +echo $REDISPASS +echo $REDISPORT +echo $CLIEXEC + +mkdir -p {$SERVER_PATH}/redis/data + +redis_start(){ + if [ -f $PIDFILE ];then + kill -9 `cat $PIDFILE` + fi + + echo "Starting Redis server..." + nohup $EXEC $CONF >> {$SERVER_PATH}/redis/logs.pl 2>&1 & +} +redis_stop(){ + if [ ! -f $PIDFILE ] + then + echo "$PIDFILE does not exist, process is not running" + else + PID=$(cat $PIDFILE) + echo "Stopping ..." + $CLIEXEC shutdown save 2>/dev/null + while [ -x /proc/${PID} ] + do + echo "Waiting for Redis to shutdown ..." + sleep 1 + done + echo "Redis stopped" + rm -rf $PIDFILE + fi +} + + +case "$1" in + start) + redis_start + ;; + stop) + redis_stop + ;; + restart|reload) + redis_stop + sleep 0.3 + redis_start + ;; + *) + echo "Please use start or stop as first argument" + ;; +esac + diff --git a/plugins/tidb/install.sh b/plugins/tidb/install.sh new file mode 100755 index 000000000..05118f331 --- /dev/null +++ b/plugins/tidb/install.sh @@ -0,0 +1,55 @@ +#!/bin/bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/homebrew/bin +export PATH + +curPath=`pwd` +rootPath=$(dirname "$curPath") +rootPath=$(dirname "$rootPath") +serverPath=$(dirname "$rootPath") + +# https://docs.pingcap.com/zh/tidb/stable/quick-start-with-tidb + +install_tmp=${rootPath}/tmp/mw_install.pl +VERSION=$2 + +Install_App() +{ + echo '正在安装脚本文件...' > $install_tmp + mkdir -p $serverPath/source + mkdir -p $serverPath/source/tidb + + app_name=tidb-community-server-${VERSION}-linux-arm64.tar.gz + + if [ ! -f $serverPath/source/tidb/${app_name} ];then + wget -O $serverPath/source/tidb/${app_name} https://download.pingcap.org/${app_name} + fi + + cd $serverPath/source/tidb && tar -zxvf $serverPath/source/tidb/${app_name} + + if [ -d $serverPath/tidb ];then + echo "${VERSION}" > $serverPath/tidb/version.pl + + cd ${rootPath} && python3 ${rootPath}/plugins/tidb/index.py start + cd ${rootPath} && python3 ${rootPath}/plugins/tidb/index.py initd_install + echo '安装完成' + else + echo '安装失败!' + fi + + if [ -d $serverPath/source/redis-${VERSION} ];then + rm -rf $serverPath/source/redis-${VERSION} + fi +} + +Uninstall_App() +{ + rm -rf $serverPath/tidb + echo "卸载TiDB" +} + +action=$1 +if [ "${1}" == 'install' ];then + Install_App +else + Uninstall_App +fi diff --git a/plugins/tidb/js/tidb.js b/plugins/tidb/js/tidb.js new file mode 100755 index 000000000..a52a87a42 --- /dev/null +++ b/plugins/tidb/js/tidb.js @@ -0,0 +1,297 @@ +function tiPost(method, version, args,callback){ + var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); + + var req_data = {}; + req_data['name'] = 'redis'; + req_data['func'] = method; + req_data['version'] = version; + + if (typeof(args) == 'string'){ + req_data['args'] = JSON.stringify(toArrayObject(args)); + } else { + req_data['args'] = JSON.stringify(args); + } + + $.post('/plugins/run', req_data, function(data) { + layer.close(loadT); + if (!data.status){ + //错误展示10S + layer.msg(data.msg,{icon:0,time:2000,shade: [10, '#000']}); + return; + } + + if(typeof(callback) == 'function'){ + callback(data); + } + },'json'); +} + +function redisPostCallbak(method, version, args,callback){ + var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); + + var req_data = {}; + req_data['name'] = 'redis'; + req_data['func'] = method; + args['version'] = version; + + if (typeof(args) == 'string'){ + 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'); +} + +//redis状态 start +function redisStatus(version) { + + redisPost('run_info',version, {},function(data){ + var rdata = $.parseJSON(data.data); + + if ('status' in rdata && !rdata.status){ + layer.msg(rdata.msg,{icon:0,time:2000,shade: [0.3, '#000']}); + return; + } + + hit = (parseInt(rdata.keyspace_hits) / (parseInt(rdata.keyspace_hits) + parseInt(rdata.keyspace_misses)) * 100).toFixed(2); + var con = '
\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
字段当前值说明
uptime_in_days' + rdata.uptime_in_days + '已运行天数
tcp_port' + rdata.tcp_port + '当前监听端口
connected_clients' + rdata.connected_clients + '连接的客户端数量
used_memory_rss' + toSize(rdata.used_memory_rss) + 'Redis当前占用的系统内存总量
used_memory' + toSize(rdata.used_memory) + 'Redis当前已分配的内存总量
used_memory_peak' + toSize(rdata.used_memory_peak) + 'Redis历史分配内存的峰值
mem_fragmentation_ratio' + rdata.mem_fragmentation_ratio + '%内存碎片比率
total_connections_received' + rdata.total_connections_received + '运行以来连接过的客户端的总数量
total_commands_processed' + rdata.total_commands_processed + '运行以来执行过的命令的总数量
instantaneous_ops_per_sec' + rdata.instantaneous_ops_per_sec + '服务器每秒钟执行的命令数量
keyspace_hits' + rdata.keyspace_hits + '查找数据库键成功的次数
keyspace_misses' + rdata.keyspace_misses + '查找数据库键失败的次数
hit' + hit + '%查找数据库键命中率
latest_fork_usec' + rdata.latest_fork_usec + '最近一次 fork() 操作耗费的微秒数
'; + $(".soft-man-con").html(con); + }); +} + +function replStatus(version){ + redisPost('info_replication', version, {},function(data){ + var rdata = $.parseJSON(data.data); + + if ('status' in rdata && !rdata.status){ + layer.msg(rdata.msg,{icon:0,time:2000,shade: [0.3, '#000']}); + return; + } + + var kv = { + 'role':'角色', + 'master_host':'连接主库HOST', + 'master_port':'连接主库PORT', + 'master_link_status':'连接主库状态', + 'master_last_io_seconds_ago':'上次同步时间', + 'master_sync_in_progress':'正在同步中', + 'slave_read_repl_offset':'从库读取复制位置', + 'slave_repl_offset':'从库复制位置', + 'slave_read_only':'从库是否仅读', + 'replica_announced':'已复制副本', + 'connected_slaves':'连接数量', + 'master_failover_state':'主库故障状态', + 'master_replid':'主库复制ID', + 'master_repl_offset':'主库复制位置', + 'repl_backlog_size':'backlog复制大小', + 'second_repl_offset':'复制位置时间', + 'repl_backlog_first_byte_offset':'第一个字节偏移量', + 'repl_backlog_histlen':'backlog中数据的长度', + 'repl_backlog_active':'开启复制缓冲区', + 'slave_priority':'同步优先级', + } + + var tbody_text = ''; + for (k in rdata){ + if (k == 'master_replid'){ + tbody_text += ''+k+'' + rdata[k] + ''+kv[k]+''; + } else{ + + if (k.substring(0,5) == 'slave' && !isNaN(k.substring(5))){ + tbody_text += ''+k+'' + rdata[k] + '从库配置信息'; + } else{ + tbody_text += ''+k+'' + rdata[k] + ''+kv[k]+''; + } + + + } + } + + var con = '
\ + \ + \ + '+tbody_text+'\ +
字段当前值说明
'; + $(".soft-man-con").html(con); + }); +} + +function clusterStatus(version){ + redisPost('cluster_info', version, {},function(data){ + var rdata = $.parseJSON(data.data); + + if ('status' in rdata && !rdata.status){ + layer.msg(rdata.msg,{icon:0,time:2000,shade: [0.3, '#000']}); + return; + } + + var kv = { + 'cluster_state':'集群状态', + 'cluster_slots_assigned':'被分配的槽', + 'cluster_slots_ok':'被分配的槽状态', + 'cluster_known_nodes':'知道的节点', + 'cluster_size':'大小', + 'cluster_stats_messages_sent':'发送', + 'cluster_stats_messages_received':'接收', + 'cluster_current_epoch':'集群当前epoch', + 'cluster_my_epoch':'当前我的epoch', + 'cluster_slots_pfail':'处于PFAIL状态的槽数', + 'cluster_slots_fail':'处于FAIL状态的槽数', + 'total_cluster_links_buffer_limit_exceeded':'超出缓冲区总数', + } + + var tbody_text = ''; + for (k in rdata){ + var desc = k; + if (k in kv){ + desc = kv[k]; + } + + if (k == 'master_replid'){ + tbody_text += ''+k+'' + rdata[k] + ''+desc+''; + } else{ + tbody_text += ''+k+'' + rdata[k] + ''+desc+''; + } + } + + if (tbody_text == ''){ + tbody_text += '无数据/未设置集群'; + } + + var con = '
\ + \ + \ + '+tbody_text+'\ +
字段当前值说明
'; + $(".soft-man-con").html(con); + }); +} + +function clusterNodes(version){ + redisPost('cluster_nodes', version, {},function(data){ + var rdata = $.parseJSON(data.data); + + if ('status' in rdata && !rdata.status){ + layer.msg(rdata.msg,{icon:0,time:2000,shade: [0.3, '#000']}); + return; + } + + // console.log(rdata); + var tbody_text = ''; + for (k in rdata){ + tbody_text += ''+ rdata[k] +''; + } + + if (tbody_text == ''){ + tbody_text += '无数据/未设置集群'; + } + + var con = '
\ + \ + \ + '+tbody_text+'\ +
节点信息
'; + $(".soft-man-con").html(con); + }); +} + +//redis状态 end + +//配置修改 +function getRedisConfig(version) { + redisPost('get_redis_conf', version,'',function(data){ + // console.log(data); + var rdata = $.parseJSON(data.data); + // console.log(rdata); + var mlist = ''; + for (var i = 0; i < rdata.length; i++) { + var w = '70' + if (rdata[i].name == 'error_reporting') w = '250'; + var ibody = ''; + switch (rdata[i].type) { + case 0: + var selected_1 = (rdata[i].value == 1) ? 'selected' : ''; + var selected_0 = (rdata[i].value == 0) ? 'selected' : ''; + ibody = '' + break; + case 1: + var selected_1 = (rdata[i].value == 'On') ? 'selected' : ''; + var selected_0 = (rdata[i].value == 'Off') ? 'selected' : ''; + ibody = '' + break; + } + mlist += '

' + rdata[i].name + '' + ibody + ', ' + rdata[i].ps + '

' + } + var con = '
' + mlist + '\ +
\ +
\ +
' + $(".soft-man-con").html(con); + }); +} + +//提交配置 +function submitConf(version) { + var data = { + version: version, + bind: $("input[name='bind']").val(), + 'port': $("input[name='port']").val(), + 'timeout': $("input[name='timeout']").val(), + maxclients: $("input[name='maxclients']").val(), + databases: $("input[name='databases']").val(), + requirepass: $("input[name='requirepass']").val(), + maxmemory: $("input[name='maxmemory']").val(), + }; + + redisPost('submit_redis_conf', version, data, function(ret_data){ + var rdata = $.parseJSON(ret_data.data); + layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 }); + }); +} + + +function tidbReadme(){ + var cmd_01 = '/www/server/redis/bin/redis-cli --cluster create 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 --cluster-replicas 0'; + var cmd_02 = '/www/server/redis/bin/redis-cli --cluster create 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 --cluster-replicas 1'; + + + var readme = '
    '; + readme += '
  • 集群创建1
  • '; + readme += '
  • '+cmd_01+'
  • '; + readme += '
  • 集群创建2
  • '; + readme += '
  • '+cmd_02+'
  • '; + readme += '
'; + + $('.soft-man-con').html(readme); +} + From 0262d2921862080496230f91e921e14d423821f2 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 11 May 2024 21:46:48 +0800 Subject: [PATCH 002/327] Update install.sh --- plugins/tidb/install.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/plugins/tidb/install.sh b/plugins/tidb/install.sh index 05118f331..a5b5cda9c 100755 --- a/plugins/tidb/install.sh +++ b/plugins/tidb/install.sh @@ -7,10 +7,25 @@ rootPath=$(dirname "$curPath") rootPath=$(dirname "$rootPath") serverPath=$(dirname "$rootPath") +sysName=`uname` +sysArch=`arch` +echo "use system: ${sysName}" + # https://docs.pingcap.com/zh/tidb/stable/quick-start-with-tidb +# cd /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/tidb && bash install.sh install v7.5.1 +# cd /www/server/mdserver-web/plugins/tidb && bash install.sh install v7.5.1 + install_tmp=${rootPath}/tmp/mw_install.pl VERSION=$2 +TIDB_ARCH=arm64 +if [ "$sysArch" == "x86_64" ];then + TIDB_ARCH=amd +fi + +if [ "$sysArch" == "aarch64" ];then + TIDB_ARCH=arm64 +fi Install_App() { @@ -18,7 +33,7 @@ Install_App() mkdir -p $serverPath/source mkdir -p $serverPath/source/tidb - app_name=tidb-community-server-${VERSION}-linux-arm64.tar.gz + app_name=tidb-community-server-${VERSION}-linux-${TIDB_ARCH}.tar.gz if [ ! -f $serverPath/source/tidb/${app_name} ];then wget -O $serverPath/source/tidb/${app_name} https://download.pingcap.org/${app_name} From 7ac1cb29440e09cb27de0c2b04eb6f071f165b0d Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 11 May 2024 21:47:46 +0800 Subject: [PATCH 003/327] Update index.py --- plugins/tidb/index.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/plugins/tidb/index.py b/plugins/tidb/index.py index 3f8a69ed9..0bfe2363e 100755 --- a/plugins/tidb/index.py +++ b/plugins/tidb/index.py @@ -163,7 +163,7 @@ def initDreplace(): mw.execShell('chmod +x ' + file_bin) # config replace - dst_conf = getServerDir() + '/redis.conf' + dst_conf = getServerDir() + '/tidb.conf' dst_conf_init = getServerDir() + '/init.pl' if not os.path.exists(dst_conf_init): conf_content = mw.readFile(getConfTpl()) @@ -188,7 +188,7 @@ def initDreplace(): return file_bin -def redisOp(method): +def tiOp(method): file = initDreplace() current_os = mw.getOs() @@ -211,23 +211,20 @@ def redisOp(method): def start(): - return redisOp('start') + return tiOp('start') def stop(): - return redisOp('stop') + return tiOp('stop') def restart(): - status = redisOp('restart') - - log_file = runLog() - mw.execShell("echo '' > " + log_file) + status = tiOp('restart') return status def reload(): - return redisOp('reload') + return tiOp('reload') def getPort(): From cb7228c681db4a8702cb954515abc9275f22a9ed Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 11 May 2024 21:47:55 +0800 Subject: [PATCH 004/327] Update index.py --- plugins/tidb/index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/tidb/index.py b/plugins/tidb/index.py index 0bfe2363e..4933220b5 100755 --- a/plugins/tidb/index.py +++ b/plugins/tidb/index.py @@ -38,7 +38,7 @@ def getInitDFile(): def getConf(): - path = getServerDir() + "/redis.conf" + path = getServerDir() + "/tidb.conf" return path From 941dbecfa24e762dbe0a1a988a304c034c127e60 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 11 May 2024 21:48:05 +0800 Subject: [PATCH 005/327] Update index.py --- plugins/tidb/index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/tidb/index.py b/plugins/tidb/index.py index 4933220b5..bd0415246 100755 --- a/plugins/tidb/index.py +++ b/plugins/tidb/index.py @@ -43,7 +43,7 @@ def getConf(): def getConfTpl(): - path = getPluginDir() + "/config/redis.conf" + path = getPluginDir() + "/config/tidb.conf" return path From d9d814202a1107a70bf84a564fdfc3b11d9e5d5e Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 11 May 2024 21:51:40 +0800 Subject: [PATCH 006/327] Update install.sh --- plugins/tidb/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/tidb/install.sh b/plugins/tidb/install.sh index a5b5cda9c..9af4c0264 100755 --- a/plugins/tidb/install.sh +++ b/plugins/tidb/install.sh @@ -20,7 +20,7 @@ install_tmp=${rootPath}/tmp/mw_install.pl VERSION=$2 TIDB_ARCH=arm64 if [ "$sysArch" == "x86_64" ];then - TIDB_ARCH=amd + TIDB_ARCH=amd64 fi if [ "$sysArch" == "aarch64" ];then From 53c2c71d3ebbc7ac521f010ad0c50e043089382f Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 11 May 2024 21:56:24 +0800 Subject: [PATCH 007/327] Update install.sh --- plugins/tidb/install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/tidb/install.sh b/plugins/tidb/install.sh index 9af4c0264..64d2e9ac6 100755 --- a/plugins/tidb/install.sh +++ b/plugins/tidb/install.sh @@ -11,6 +11,7 @@ sysName=`uname` sysArch=`arch` echo "use system: ${sysName}" +# https://cn.pingcap.com/product-community/ # https://docs.pingcap.com/zh/tidb/stable/quick-start-with-tidb # cd /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/tidb && bash install.sh install v7.5.1 From 59aab80eabf65b306d62d2f0c914f6507f7cb46f Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 11 May 2024 22:03:56 +0800 Subject: [PATCH 008/327] Update install.sh --- plugins/tidb/install.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/plugins/tidb/install.sh b/plugins/tidb/install.sh index 64d2e9ac6..1dffc7cfb 100755 --- a/plugins/tidb/install.sh +++ b/plugins/tidb/install.sh @@ -34,13 +34,18 @@ Install_App() mkdir -p $serverPath/source mkdir -p $serverPath/source/tidb - app_name=tidb-community-server-${VERSION}-linux-${TIDB_ARCH}.tar.gz + tidb_name=tidb-community-server-${VERSION}-linux-${TIDB_ARCH} + tgz_name=${tidb_name}.tar.gz - if [ ! -f $serverPath/source/tidb/${app_name} ];then - wget -O $serverPath/source/tidb/${app_name} https://download.pingcap.org/${app_name} + if [ ! -f $serverPath/source/tidb/${tgz_name} ];then + wget -O $serverPath/source/tidb/${tgz_name} https://download.pingcap.org/${tgz_name} + fi + + + if [ !-d $serverPath/source/tidb/${tidb_name} ];then + cd $serverPath/source/tidb && tar -zxvf $serverPath/source/tidb/${tgz_name} fi - cd $serverPath/source/tidb && tar -zxvf $serverPath/source/tidb/${app_name} if [ -d $serverPath/tidb ];then echo "${VERSION}" > $serverPath/tidb/version.pl From cef6db80a2794af0c141a149b6d602ae60a6d9a4 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 11 May 2024 22:08:06 +0800 Subject: [PATCH 009/327] Update install.sh --- plugins/tidb/install.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/tidb/install.sh b/plugins/tidb/install.sh index 1dffc7cfb..3a1c2c9a7 100755 --- a/plugins/tidb/install.sh +++ b/plugins/tidb/install.sh @@ -17,6 +17,8 @@ echo "use system: ${sysName}" # cd /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/tidb && bash install.sh install v7.5.1 # cd /www/server/mdserver-web/plugins/tidb && bash install.sh install v7.5.1 +# cd /www/server/source/tidb/tidb-community-server-v7.5.1-linux-amd64 && ./local_install.sh + install_tmp=${rootPath}/tmp/mw_install.pl VERSION=$2 TIDB_ARCH=arm64 @@ -45,7 +47,13 @@ Install_App() if [ !-d $serverPath/source/tidb/${tidb_name} ];then cd $serverPath/source/tidb && tar -zxvf $serverPath/source/tidb/${tgz_name} fi - + + if [ !-d $serverPath/tidb/mirror ];then + mkdir -p $serverPath/tidb/mirror + cp -rf $serverPath/source/tidb/${tidb_name}/* $serverPath/tidb/mirror + fi + + cd $serverPath/tidb/mirror && ./local_install.sh if [ -d $serverPath/tidb ];then echo "${VERSION}" > $serverPath/tidb/version.pl From 3fc3d90b6f2e49d4a51cf113fb3cb9c1dec8f3a3 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 11 May 2024 22:09:57 +0800 Subject: [PATCH 010/327] Update install.sh --- plugins/tidb/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/tidb/install.sh b/plugins/tidb/install.sh index 3a1c2c9a7..81c2b9019 100755 --- a/plugins/tidb/install.sh +++ b/plugins/tidb/install.sh @@ -44,11 +44,11 @@ Install_App() fi - if [ !-d $serverPath/source/tidb/${tidb_name} ];then + if [ ! -d $serverPath/source/tidb/${tidb_name} ];then cd $serverPath/source/tidb && tar -zxvf $serverPath/source/tidb/${tgz_name} fi - if [ !-d $serverPath/tidb/mirror ];then + if [ ! -d $serverPath/tidb/mirror ];then mkdir -p $serverPath/tidb/mirror cp -rf $serverPath/source/tidb/${tidb_name}/* $serverPath/tidb/mirror fi From 20b20d3cce52125d04e301fa8c9a701a1c52c304 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 11 May 2024 22:13:53 +0800 Subject: [PATCH 011/327] Update index.py --- plugins/tidb/index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/tidb/index.py b/plugins/tidb/index.py index bd0415246..eb2e1bab2 100755 --- a/plugins/tidb/index.py +++ b/plugins/tidb/index.py @@ -43,7 +43,7 @@ def getConf(): def getConfTpl(): - path = getPluginDir() + "/config/tidb.conf" + path = getPluginDir() + "/conf/tidb.conf" return path From 1788054cc49899ed4059a7ae099094428ddfb33c Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 11 May 2024 22:14:51 +0800 Subject: [PATCH 012/327] Update install.sh --- plugins/tidb/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/tidb/install.sh b/plugins/tidb/install.sh index 81c2b9019..5007f2040 100755 --- a/plugins/tidb/install.sh +++ b/plugins/tidb/install.sh @@ -15,7 +15,7 @@ echo "use system: ${sysName}" # https://docs.pingcap.com/zh/tidb/stable/quick-start-with-tidb # cd /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/tidb && bash install.sh install v7.5.1 -# cd /www/server/mdserver-web/plugins/tidb && bash install.sh install v7.5.1 +# mw update_dev && cd /www/server/mdserver-web/plugins/tidb && bash install.sh install v7.5.1 # cd /www/server/source/tidb/tidb-community-server-v7.5.1-linux-amd64 && ./local_install.sh @@ -59,7 +59,7 @@ Install_App() echo "${VERSION}" > $serverPath/tidb/version.pl cd ${rootPath} && python3 ${rootPath}/plugins/tidb/index.py start - cd ${rootPath} && python3 ${rootPath}/plugins/tidb/index.py initd_install + # cd ${rootPath} && python3 ${rootPath}/plugins/tidb/index.py initd_install echo '安装完成' else echo '安装失败!' From ae69d58ee84329251f43a12d4a6f632773f8cd8a Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 11 May 2024 23:40:45 +0800 Subject: [PATCH 013/327] Update install.sh --- plugins/tidb/install.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/plugins/tidb/install.sh b/plugins/tidb/install.sh index 5007f2040..c9a63009f 100755 --- a/plugins/tidb/install.sh +++ b/plugins/tidb/install.sh @@ -19,6 +19,9 @@ echo "use system: ${sysName}" # cd /www/server/source/tidb/tidb-community-server-v7.5.1-linux-amd64 && ./local_install.sh +# tiup cluster deploy tidb v7.5.1 /www/server/tidb/tidb.yaml --user root -p -i /root/.ssh/id_rsa +# ssh 192.168.4.1 -l root + install_tmp=${rootPath}/tmp/mw_install.pl VERSION=$2 TIDB_ARCH=arm64 @@ -37,7 +40,10 @@ Install_App() mkdir -p $serverPath/source/tidb tidb_name=tidb-community-server-${VERSION}-linux-${TIDB_ARCH} + tidb_toolkit_name=tidb-community-toolkit-${VERSION}-linux-${TIDB_ARCH} tgz_name=${tidb_name}.tar.gz + tgz_toolkit_name=${tidb_toolkit_name}.tar.gz + if [ ! -f $serverPath/source/tidb/${tgz_name} ];then wget -O $serverPath/source/tidb/${tgz_name} https://download.pingcap.org/${tgz_name} @@ -48,6 +54,14 @@ Install_App() cd $serverPath/source/tidb && tar -zxvf $serverPath/source/tidb/${tgz_name} fi + if [ ! -f $serverPath/source/tidb/${tgz_toolkit_name} ];then + wget -O $serverPath/source/tidb/${tgz_name} https://download.pingcap.org/${tgz_toolkit_name} + fi + + if [ ! -d $serverPath/source/tidb/${tgz_toolkit_name} ];then + cd $serverPath/source/tidb && tar -zxvf $serverPath/source/tidb/${tgz_toolkit_name} + fi + if [ ! -d $serverPath/tidb/mirror ];then mkdir -p $serverPath/tidb/mirror cp -rf $serverPath/source/tidb/${tidb_name}/* $serverPath/tidb/mirror From 3e6f4f32d5ad3520f96f92cadae529d872763fa0 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 11 May 2024 23:42:26 +0800 Subject: [PATCH 014/327] Update install.sh --- plugins/tidb/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/tidb/install.sh b/plugins/tidb/install.sh index c9a63009f..ee77205c1 100755 --- a/plugins/tidb/install.sh +++ b/plugins/tidb/install.sh @@ -55,7 +55,7 @@ Install_App() fi if [ ! -f $serverPath/source/tidb/${tgz_toolkit_name} ];then - wget -O $serverPath/source/tidb/${tgz_name} https://download.pingcap.org/${tgz_toolkit_name} + wget -O $serverPath/source/tidb/${tgz_toolkit_name} https://download.pingcap.org/${tgz_toolkit_name} fi if [ ! -d $serverPath/source/tidb/${tgz_toolkit_name} ];then From 9f49595badbbffc482d9789db2bfeb54bad5359d Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 12 May 2024 00:28:08 +0800 Subject: [PATCH 015/327] Update r3.6.txt --- version/r3.6.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/version/r3.6.txt b/version/r3.6.txt index 0159917d2..0863401ee 100644 --- a/version/r3.6.txt +++ b/version/r3.6.txt @@ -35,4 +35,5 @@ whitenoise==5.3.0 pyotp pytz pyTelegramBotAPI -telebot \ No newline at end of file +telebot +pyyaml \ No newline at end of file From 47ff1e44585a4556644df4a6f555a7c249351097 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 12 May 2024 00:28:20 +0800 Subject: [PATCH 016/327] Update r3.7.txt --- version/r3.7.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/version/r3.7.txt b/version/r3.7.txt index b11b01dba..a1be3eaa3 100644 --- a/version/r3.7.txt +++ b/version/r3.7.txt @@ -1,3 +1,4 @@ urllib3==1.21.1 gevent==22.10.2 -gunicorn==21.2.0 \ No newline at end of file +gunicorn==21.2.0 +pyyaml \ No newline at end of file From 2e9561dd8606ec0e34ad795a149be9bd11d186fa Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 12 May 2024 01:10:04 +0800 Subject: [PATCH 017/327] Update files_api.py --- class/core/files_api.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/class/core/files_api.py b/class/core/files_api.py index 3c8843201..d44715129 100755 --- a/class/core/files_api.py +++ b/class/core/files_api.py @@ -121,6 +121,7 @@ class files_api: def fileAccessApi(self): filename = request.form.get('filename', '') data = self.getAccess(filename) + data['sys_users'] = self.getSysUserList() return mw.getJson(data) def setFileAccessApi(self): @@ -933,6 +934,20 @@ class files_api: data['chown'] = 'www' return data + def getSysUserList(self): + pwd_file = '/etc/passwd' + if os.path.exists(pwd_file): + content = mw.readFile(pwd_file) + clist = content.split('\n') + sys_users = [] + for line in clist: + if line.find(":")<0: + continue + lines = line.split(":",1) + sys_users.append(lines[0]) + return sys_users + return ['root','mysql','www'] + # 计算文件数量 def getCount(self, path, search): i = 0 From 66a9ca2a5a8a67dfabf2c70c8a4c59ecc7969084 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 12 May 2024 01:18:32 +0800 Subject: [PATCH 018/327] Update files.js --- route/static/app/files.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/route/static/app/files.js b/route/static/app/files.js index 52a0cc182..2efbaa1e7 100755 --- a/route/static/app/files.js +++ b/route/static/app/files.js @@ -1592,6 +1592,22 @@ function setChmod(action,fileName){ var toExec = fileName == lan.files.all?'batch(3,1)':'setChmod(1,\''+fileName+'\')'; $.post('/files/file_access','filename='+encodeURIComponent(fileName),function(rdata){ // console.log(rdata); + var sys_users = rdata.sys_users; + var own_html = ''; + var is_find_own_option = false; + for (var i = 0; i < sys_users.length; i++) { + var own = sys_users[i]; + if (rdata.chown==own){ + is_find_own_option = true; + own_html += ''; + } else { + own_html += ''; + } + } + if (!is_find_own_option){ + own_html += ''; + } + layer.open({ type:1, closeBtn: 1, @@ -1619,10 +1635,8 @@ function setChmod(action,fileName){ \
权限,\ 所有者\ - \ + '+own_html+'\
\
\ \ From fb6dbde4c9ff7f71bcb4a088f768cc90ecdf5f2a Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 12 May 2024 01:18:49 +0800 Subject: [PATCH 019/327] Update config_api.py --- class/core/config_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/class/core/config_api.py b/class/core/config_api.py index f3702440d..bdb75e932 100755 --- a/class/core/config_api.py +++ b/class/core/config_api.py @@ -28,7 +28,7 @@ from flask import request class config_api: - __version = '0.16.8' + __version = '0.16.8.1' __api_addr = 'data/api.json' # 统一默认配置文件 From 00269662bfcb9128052971f42e38e90d0cd28f24 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 12 May 2024 01:25:10 +0800 Subject: [PATCH 020/327] Create tidb.yaml --- plugins/tidb/conf/tidb.yaml | 58 +++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 plugins/tidb/conf/tidb.yaml diff --git a/plugins/tidb/conf/tidb.yaml b/plugins/tidb/conf/tidb.yaml new file mode 100644 index 000000000..8891729cc --- /dev/null +++ b/plugins/tidb/conf/tidb.yaml @@ -0,0 +1,58 @@ +# # Global variables are applied to all deployments and used as the default value of +# # the deployments if a specific deployment value is missing. +global: + user: "tidb" + ssh_port: 2022 + deploy_dir: "/home/tidb/tidb-deploy" + data_dir: "/home/tidb/tidb-data" + +# # Monitored variables are applied to all the machines. +monitored: + node_exporter_port: 9100 + blackbox_exporter_port: 9115 + +server_configs: + tidb: + instance.tidb_slow_log_threshold: 300 + tikv: + readpool.storage.use-unified-pool: false + readpool.coprocessor.use-unified-pool: true + pd: + replication.enable-placement-rules: true + replication.location-labels: ["host"] + tiflash: + logger.level: "info" + +pd_servers: + - host: 192.168.4.1 + +tidb_servers: + - host: 192.168.4.1 + +tikv_servers: + - host: 192.168.4.1 + port: 20160 + status_port: 20180 + config: + server.labels: { host: "logic-host-1" } + + - host: 192.168.4.1 + port: 20161 + status_port: 20181 + config: + server.labels: { host: "logic-host-2" } + + - host: 192.168.4.1 + port: 20162 + status_port: 20182 + config: + server.labels: { host: "logic-host-3" } + +tiflash_servers: + - host: 192.168.4.1 + +monitoring_servers: + - host: 192.168.4.1 + +grafana_servers: + - host: 192.168.4.1 \ No newline at end of file From 7952570b451c498bdab3ac6db6b90c711ee50d57 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 12 May 2024 10:58:12 +0800 Subject: [PATCH 021/327] update --- plugins/tidb/index.py | 8 ++++---- plugins/tidb/install.sh | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/tidb/index.py b/plugins/tidb/index.py index eb2e1bab2..74a6f0296 100755 --- a/plugins/tidb/index.py +++ b/plugins/tidb/index.py @@ -119,16 +119,16 @@ def getPidFile(): return tmp.groups()[0].strip() def status(): - pid_file = getPidFile() - if not os.path.exists(pid_file): - return 'stop' + # pid_file = getPidFile() + # if not os.path.exists(pid_file): + # return 'stop' # data = mw.execShell( # "ps aux|grep redis |grep -v grep | grep -v python | grep -v mdserver-web | awk '{print $2}'") # if data[0] == '': # return 'stop' - return 'start' + return 'stop' def contentReplace(content): service_path = mw.getServerDir() diff --git a/plugins/tidb/install.sh b/plugins/tidb/install.sh index ee77205c1..566cf9f28 100755 --- a/plugins/tidb/install.sh +++ b/plugins/tidb/install.sh @@ -19,8 +19,10 @@ echo "use system: ${sysName}" # cd /www/server/source/tidb/tidb-community-server-v7.5.1-linux-amd64 && ./local_install.sh -# tiup cluster deploy tidb v7.5.1 /www/server/tidb/tidb.yaml --user root -p -i /root/.ssh/id_rsa +# tiup cluster deploy tidb v7.5.1 /www/server/tidb/tidb.yaml --user root -i /root/.ssh/id_rsa +# tiup cluster deploy tidb v7.5.1 /www/server/tidb/tidb.yaml --user root -p # ssh 192.168.4.1 -l root +# useradd -d /home/tidb1 tidb1 && passwd tidb1 install_tmp=${rootPath}/tmp/mw_install.pl VERSION=$2 From 2de399b70f09773d369a5bf8e8c6023357b83b22 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 12 May 2024 12:46:41 +0800 Subject: [PATCH 022/327] Update index.py --- plugins/tidb/index.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/plugins/tidb/index.py b/plugins/tidb/index.py index 74a6f0296..2c4dbe2ea 100755 --- a/plugins/tidb/index.py +++ b/plugins/tidb/index.py @@ -162,16 +162,17 @@ def initDreplace(): if not os.path.exists(dataLog): mw.execShell('chmod +x ' + file_bin) - # config replace - dst_conf = getServerDir() + '/tidb.conf' - dst_conf_init = getServerDir() + '/init.pl' - if not os.path.exists(dst_conf_init): - conf_content = mw.readFile(getConfTpl()) - conf_content = conf_content.replace('{$SERVER_PATH}', service_path) - conf_content = conf_content.replace( - '{$REDIS_PASS}', mw.getRandomString(10)) - mw.writeFile(dst_conf, conf_content) + conf_list = ['tidb.conf', 'tidb.yaml'] + dst_conf_init = getServerDir() + '/init.pl' + if os.path.exists(dst_conf_init): + for conf in conf_list: + dst_conf = getServerDir() + '/'+ conf + src_conf = getPluginDir() + '/conf/'+ conf + if not os.path.exists(dst_conf): + content = mw.readFile(src_conf) + content = content.replace('{$SERVER_PATH}', service_path) + mw.writeFile(dst_conf, content) mw.writeFile(dst_conf_init, 'ok') # systemd From 3d552379bc6b2d340223e8f3408201d2b9525971 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 12 May 2024 12:55:14 +0800 Subject: [PATCH 023/327] update --- plugins/tidb/index.py | 2 +- plugins/tidb/install.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/tidb/index.py b/plugins/tidb/index.py index 2c4dbe2ea..ab0e08358 100755 --- a/plugins/tidb/index.py +++ b/plugins/tidb/index.py @@ -165,7 +165,7 @@ def initDreplace(): conf_list = ['tidb.conf', 'tidb.yaml'] dst_conf_init = getServerDir() + '/init.pl' - if os.path.exists(dst_conf_init): + if not os.path.exists(dst_conf_init): for conf in conf_list: dst_conf = getServerDir() + '/'+ conf src_conf = getPluginDir() + '/conf/'+ conf diff --git a/plugins/tidb/install.sh b/plugins/tidb/install.sh index 566cf9f28..00ab32e70 100755 --- a/plugins/tidb/install.sh +++ b/plugins/tidb/install.sh @@ -16,7 +16,7 @@ echo "use system: ${sysName}" # cd /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/tidb && bash install.sh install v7.5.1 # mw update_dev && cd /www/server/mdserver-web/plugins/tidb && bash install.sh install v7.5.1 - +# python3 /www/server/mdserver-web/plugins/tidb/index.py start # cd /www/server/source/tidb/tidb-community-server-v7.5.1-linux-amd64 && ./local_install.sh # tiup cluster deploy tidb v7.5.1 /www/server/tidb/tidb.yaml --user root -i /root/.ssh/id_rsa From 4bb345abc4d2b8d20d9184f3939011d4ff508194 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 12 May 2024 14:06:56 +0800 Subject: [PATCH 024/327] update --- plugins/mongodb/index.py | 20 +++++++++++++++----- plugins/mongodb/js/mongodb.js | 17 ++++++++++++++--- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/plugins/mongodb/index.py b/plugins/mongodb/index.py index 1300bd55c..225026eb9 100755 --- a/plugins/mongodb/index.py +++ b/plugins/mongodb/index.py @@ -18,7 +18,6 @@ if mw.isAppleSystem(): # /usr/lib/systemd/system/mongod.service -# /var/lib/mongo # python3 /www/server/mdserver-web/plugins/mongodb/index.py repl_init # python3 /www/server/mdserver-web/plugins/mongodb/index.py run_repl_info @@ -494,6 +493,11 @@ def runReplInfo(): except Exception as e: return mw.returnJson(False, str(e)) + try: + replStatus = db.command('replSetGetStatus') + except Exception as e: + return mw.returnJson(False, str(e)) + d = getConfigData() result = {} if 'replication' in d and 'replSetName' in d['replication']: @@ -518,6 +522,16 @@ def runReplInfo(): hosts = mw.getDefault(repl,'hosts', '') result['hosts'] = ','.join(hosts) + members_list = [] + if 'members' in replStatus: + members = replStatus['members'] + for m in members: + t = {} + t['name'] = m['name'] + t['stateStr'] = m['stateStr'] + t['uptime'] = m['uptime'] + members_list.append(t) + result['members'] = members_list return mw.returnJson(True, 'OK', result) @@ -1011,10 +1025,6 @@ def replSetNode(): add_node = args['node'].strip() idx = int(args['idx']) - - - - priority = -1 if 'priority' in args: priority = args['priority'].strip() diff --git a/plugins/mongodb/js/mongodb.js b/plugins/mongodb/js/mongodb.js index ef370d5af..afacf0afb 100644 --- a/plugins/mongodb/js/mongodb.js +++ b/plugins/mongodb/js/mongodb.js @@ -159,6 +159,12 @@ function mongoReplStatus() { me' + rdata.me + '本机'; } + var tbody_members = ''; + var member_list = rdata['members']; + for (var i = 0; i < member_list.length; i++) { + tbody_members += ''+member_list['name']+'' + member_list[i]['stateStr'] + ''+member_list[i]['uptime']+''; + } + // console.log(rdata); var repl_on = 'btn-danger'; var repl_on_title = '未开启'; @@ -176,9 +182,14 @@ function mongoReplStatus() { con += '
\ \ \ - \ - '+tbody+'\ - \ + '+tbody+'\ +
字段当前值说明
\ +
'; + + con += '
\ + \ + \ + '+tbody_members+'\
IP状态在线
\
'; From c0aa4bcc1e456b30e793b416a0b355ec6e0a9e78 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 12 May 2024 14:10:52 +0800 Subject: [PATCH 025/327] Update mongodb.js --- plugins/mongodb/js/mongodb.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mongodb/js/mongodb.js b/plugins/mongodb/js/mongodb.js index afacf0afb..c56e19a67 100644 --- a/plugins/mongodb/js/mongodb.js +++ b/plugins/mongodb/js/mongodb.js @@ -162,7 +162,7 @@ function mongoReplStatus() { var tbody_members = ''; var member_list = rdata['members']; for (var i = 0; i < member_list.length; i++) { - tbody_members += ''+member_list['name']+'' + member_list[i]['stateStr'] + ''+member_list[i]['uptime']+''; + tbody_members += ''+member_list[i]['name']+'' + member_list[i]['stateStr'] + ''+member_list[i]['uptime']+''; } // console.log(rdata); @@ -186,7 +186,7 @@ function mongoReplStatus() { \
'; - con += '
\ + con += '
\ \ \ '+tbody_members+'\ From 2f65839b9aceae503c63e621a6b950603fc536a5 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 12 May 2024 14:17:49 +0800 Subject: [PATCH 026/327] Update index.py --- plugins/mongodb/index.py | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/plugins/mongodb/index.py b/plugins/mongodb/index.py index 225026eb9..dd8bb0a78 100755 --- a/plugins/mongodb/index.py +++ b/plugins/mongodb/index.py @@ -487,19 +487,13 @@ def runDocInfo(): def runReplInfo(): client = mongdbClient() db = client.admin - + result = {} try: serverStatus = db.command('serverStatus') except Exception as e: return mw.returnJson(False, str(e)) - try: - replStatus = db.command('replSetGetStatus') - except Exception as e: - return mw.returnJson(False, str(e)) - d = getConfigData() - result = {} if 'replication' in d and 'replSetName' in d['replication']: result['repl_name'] = d['replication']['replSetName'] @@ -522,17 +516,21 @@ def runReplInfo(): hosts = mw.getDefault(repl,'hosts', '') result['hosts'] = ','.join(hosts) - members_list = [] - if 'members' in replStatus: - members = replStatus['members'] - for m in members: - t = {} - t['name'] = m['name'] - t['stateStr'] = m['stateStr'] - t['uptime'] = m['uptime'] - members_list.append(t) - result['members'] = members_list - + result['members'] = [] + try: + replStatus = db.command('replSetGetStatus') + if 'members' in replStatus: + members = replStatus['members'] + for m in members: + t = {} + t['name'] = m['name'] + t['stateStr'] = m['stateStr'] + t['uptime'] = m['uptime'] + members_list.append(t) + result['members'] = members_list + except Exception as e: + pass + return mw.returnJson(True, 'OK', result) def getDbList(): From 00fa001c91c7af53d6dca0f4f92efc52a6d447c6 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 12 May 2024 14:27:36 +0800 Subject: [PATCH 027/327] update --- plugins/mongodb/index.html | 1 + plugins/mongodb/js/mongodb.js | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/plugins/mongodb/index.html b/plugins/mongodb/index.html index 954e0bb6a..46f25956f 100755 --- a/plugins/mongodb/index.html +++ b/plugins/mongodb/index.html @@ -63,6 +63,7 @@

负载状态

复制状态

日志

+

相关说明

diff --git a/plugins/mongodb/js/mongodb.js b/plugins/mongodb/js/mongodb.js index c56e19a67..0ee552180 100644 --- a/plugins/mongodb/js/mongodb.js +++ b/plugins/mongodb/js/mongodb.js @@ -1204,3 +1204,12 @@ function importDbExternal(file,name){ }); } +function mgdbReadme(){ + var readme = '
    '; + readme += '
  • 认证同步说明
  • '; + readme += '
  • root/用户,配置Key完全一致才能同步。
  • '; + readme += '
'; + + $('.soft-man-con').html(readme); +} + From 4bce8bb56df0bba16303eb73335d71f15d740dc5 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 12 May 2024 14:35:53 +0800 Subject: [PATCH 028/327] Update index.py --- plugins/mongodb/index.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/mongodb/index.py b/plugins/mongodb/index.py index dd8bb0a78..d922635fb 100755 --- a/plugins/mongodb/index.py +++ b/plugins/mongodb/index.py @@ -518,6 +518,7 @@ def runReplInfo(): result['members'] = [] try: + members_list = [] replStatus = db.command('replSetGetStatus') if 'members' in replStatus: members = replStatus['members'] From 968827480ee9d04330854cc1ee70fc7df3fc7fda Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 12 May 2024 14:42:07 +0800 Subject: [PATCH 029/327] Update install.sh --- plugins/tidb/install.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/tidb/install.sh b/plugins/tidb/install.sh index 00ab32e70..1c9a7fb5e 100755 --- a/plugins/tidb/install.sh +++ b/plugins/tidb/install.sh @@ -21,6 +21,8 @@ echo "use system: ${sysName}" # tiup cluster deploy tidb v7.5.1 /www/server/tidb/tidb.yaml --user root -i /root/.ssh/id_rsa # tiup cluster deploy tidb v7.5.1 /www/server/tidb/tidb.yaml --user root -p +# source /root/.bashrc + # ssh 192.168.4.1 -l root # useradd -d /home/tidb1 tidb1 && passwd tidb1 From 0dd6f47b2a745765b6136280657a0f33e0ef2f10 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 12 May 2024 15:59:19 +0800 Subject: [PATCH 030/327] Update index.py --- plugins/clean/index.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/clean/index.py b/plugins/clean/index.py index b42abdac1..5a04076f2 100755 --- a/plugins/clean/index.py +++ b/plugins/clean/index.py @@ -116,6 +116,7 @@ def initConf(): "/www/server/php/82/var/log", "/www/server/php/83/var/log", "/www/server/php/84/var/log", + "/www/server/openresty/nginx/logs", "/www/server/phpmyadmin", "/www/server/redis/data", "/www/server/cron", From ec6c1b2024386fe78cf737845982879d925a87f6 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 12 May 2024 16:09:36 +0800 Subject: [PATCH 031/327] Update nginx.conf --- plugins/openresty/conf/nginx.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/openresty/conf/nginx.conf b/plugins/openresty/conf/nginx.conf index 066868f62..9533df6c7 100644 --- a/plugins/openresty/conf/nginx.conf +++ b/plugins/openresty/conf/nginx.conf @@ -51,7 +51,7 @@ http gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; - gzip_comp_level 2; + gzip_comp_level 9; gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml; gzip_vary on; gzip_proxied expired no-cache no-store private auth; From 574007da2c6bbef7acc331de5aa7b4848eab08c9 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Mon, 13 May 2024 02:47:13 +0800 Subject: [PATCH 032/327] Update stats.js --- plugins/webstats/js/stats.js | 42 ++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/plugins/webstats/js/stats.js b/plugins/webstats/js/stats.js index 31039c988..00294c6b6 100644 --- a/plugins/webstats/js/stats.js +++ b/plugins/webstats/js/stats.js @@ -2213,8 +2213,18 @@ function wsTableLogRequest(page){ "12":"其他", } + var req_status = $('#logs_search').attr('req'); + // console.log(req_status); + if (typeof(req_status) != 'undefined'){ + if (req_status == 'start'){ + layer.msg("正在请求中,请稍候!"); + return; + } + } + $('#logs_search').attr('req','start'); wsPostCallbak('get_logs_list', '' ,args, function(rdata){ + $('#logs_search').attr('req','end'); var rdata = $.parseJSON(rdata.data); var list = ''; var data = rdata.data.data; @@ -2267,22 +2277,6 @@ function wsTableLogRequest(page){ $('#ws_table').html(table); $('#wsPage').html(rdata.data.page); - $('input[name="ip"]').bind('focus', function(e){ - $(this).keyup(function(e){ - if(e.keyCode == 13) { - wsTableLogRequest(1); - } - }); - }); - - $('input[name="search_uri"]').bind('focus', function(e){ - $(this).keyup(function(e){ - if(e.keyCode == 13) { - wsTableLogRequest(1); - } - }); - }); - $(".tablescroll .details").click(function(){ var index = $(this).attr('data-id'); var res = data[index]; @@ -2444,6 +2438,22 @@ var html = '
\
'; $(".soft-man-con").html(html); +$('input[name="ip"]').bind('focus', function(e){ + $(this).keyup(function(e){ + if(e.keyCode == 13) { + wsTableLogRequest(1); + } + }); +}); + +$('input[name="search_uri"]').bind('focus', function(e){ + $(this).keyup(function(e){ + if(e.keyCode == 13) { + wsTableLogRequest(1); + } + }); +}); + //日期范围 laydate.render({ elem: '#time_choose', From fd3e074cc3fde041d20ae7eeed0992aabf855aad Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Mon, 13 May 2024 03:18:02 +0800 Subject: [PATCH 033/327] Update install.sh --- plugins/tidb/install.sh | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/plugins/tidb/install.sh b/plugins/tidb/install.sh index 1c9a7fb5e..21b1073e5 100755 --- a/plugins/tidb/install.sh +++ b/plugins/tidb/install.sh @@ -18,14 +18,36 @@ echo "use system: ${sysName}" # mw update_dev && cd /www/server/mdserver-web/plugins/tidb && bash install.sh install v7.5.1 # python3 /www/server/mdserver-web/plugins/tidb/index.py start # cd /www/server/source/tidb/tidb-community-server-v7.5.1-linux-amd64 && ./local_install.sh - -# tiup cluster deploy tidb v7.5.1 /www/server/tidb/tidb.yaml --user root -i /root/.ssh/id_rsa -# tiup cluster deploy tidb v7.5.1 /www/server/tidb/tidb.yaml --user root -p +# cd /www/server/tidb/mirror && ./local_install.sh # source /root/.bashrc # ssh 192.168.4.1 -l root # useradd -d /home/tidb1 tidb1 && passwd tidb1 +# tidb ssh +# /root/.tiup/storage/cluster/clusters/tidb/ssh + +# ssh-copy-id -p 2022 root@154.21.203.138 +# ssh -p 2022 root@154.21.203.138 -i /root/.tiup/storage/cluster/clusters/tidb/ssh/id_rsa + +# grafana +# http://154.21.203.138:3000 + +# grafana +# http://154.21.203.138:3000 + +# rm -rf /root/.tiup +# tiup cluster deploy tidb v7.5.1 /www/server/tidb/tidb.yaml --user root -p +# tiup cluster deploy mw v7.5.1 /www/server/tidb/tidb.yaml --user root -p + +# tiup cluster clean tidb --all +# tiup cluster display tidb +# tiup cluster destroy tidb + +# tiup cluster clean tidb --all --ignore-role prometheus grafana + + + install_tmp=${rootPath}/tmp/mw_install.pl VERSION=$2 TIDB_ARCH=arm64 From 9fbf09f2ef82de5da321309913dddd716ce28544 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Mon, 13 May 2024 10:41:00 +0800 Subject: [PATCH 034/327] Create tidb_debug.yaml --- plugins/tidb/conf/tidb_debug.yaml | 46 +++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 plugins/tidb/conf/tidb_debug.yaml diff --git a/plugins/tidb/conf/tidb_debug.yaml b/plugins/tidb/conf/tidb_debug.yaml new file mode 100644 index 000000000..7bccc1e4b --- /dev/null +++ b/plugins/tidb/conf/tidb_debug.yaml @@ -0,0 +1,46 @@ +# # Global variables are applied to all deployments and used as the default value of +# # the deployments if a specific deployment value is missing. +global: + user: "root" + ssh_port: 2022 + deploy_dir: "/tidb/tidb-deploy" + data_dir: "/tidb/tidb-data" + +# # Monitored variables are applied to all the machines. +monitored: + node_exporter_port: 9100 + blackbox_exporter_port: 9115 + +server_configs: + tidb: + instance.tidb_slow_log_threshold: 300 + tikv: + readpool.storage.use-unified-pool: false + readpool.coprocessor.use-unified-pool: true + pd: + replication.enable-placement-rules: true + replication.location-labels: ["host"] + tiflash: + logger.level: "info" + +pd_servers: + - host: 154.21.203.138 + +tidb_servers: + - host: 154.21.203.138 + +tikv_servers: + - host: 154.21.203.138 + port: 20160 + status_port: 20180 + config: + server.labels: { host: "logic-host-1" } + +tiflash_servers: + - host: 154.21.203.138 + +monitoring_servers: + - host: 154.21.203.138 + +grafana_servers: + - host: 154.21.203.138 \ No newline at end of file From 3213cee5f8abea2e18af7c12d43369714cb00b99 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Mon, 13 May 2024 20:50:45 +0800 Subject: [PATCH 035/327] Update mongodb.sh --- plugins/php/versions/common/mongodb.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/php/versions/common/mongodb.sh b/plugins/php/versions/common/mongodb.sh index 616543409..4b6a3f2f3 100755 --- a/plugins/php/versions/common/mongodb.sh +++ b/plugins/php/versions/common/mongodb.sh @@ -17,6 +17,10 @@ sysName=`uname` actionType=$1 version=$2 +if [ "$version" -ge '74' ];then + LIBV=1.18.1 +fi + if [ "$version" == '71' ];then LIBV=1.11.1 fi From 924e1ddbece984fa95f83fca5040e842d61ba2a5 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Mon, 13 May 2024 22:35:10 +0800 Subject: [PATCH 036/327] Update layout.html --- route/templates/default/layout.html | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/route/templates/default/layout.html b/route/templates/default/layout.html index d9dea68ee..45881f842 100755 --- a/route/templates/default/layout.html +++ b/route/templates/default/layout.html @@ -14,15 +14,6 @@ - - - - {% for menu in data['hook_menu'] %} @@ -188,4 +179,14 @@ if (thisPath.indexOf('?')>-1){ {% endif %} {% endfor %} + + + + + \ No newline at end of file From 77b4d0452a1c925737cc4d175492431f270d877b Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Mon, 13 May 2024 23:18:00 +0800 Subject: [PATCH 037/327] Update mongodb.sh --- plugins/php/versions/common/mongodb.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/php/versions/common/mongodb.sh b/plugins/php/versions/common/mongodb.sh index 4b6a3f2f3..3f60b9f79 100755 --- a/plugins/php/versions/common/mongodb.sh +++ b/plugins/php/versions/common/mongodb.sh @@ -18,7 +18,7 @@ actionType=$1 version=$2 if [ "$version" -ge '74' ];then - LIBV=1.18.1 + LIBV=1.19.0 fi if [ "$version" == '71' ];then From dd498c2cfced972017c10d23b14dd9d0549bb57a Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 14 May 2024 14:12:21 +0800 Subject: [PATCH 038/327] update --- plugins/data_query/static/html/index.html | 13 ++++++++++--- plugins/data_query/static/js/app.js | 4 ++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/plugins/data_query/static/html/index.html b/plugins/data_query/static/html/index.html index 95292cf54..ab943d3a6 100644 --- a/plugins/data_query/static/html/index.html +++ b/plugins/data_query/static/html/index.html @@ -123,9 +123,16 @@
- +
+ + + + +
diff --git a/plugins/data_query/static/js/app.js b/plugins/data_query/static/js/app.js index 2e8d74db5..166479a19 100755 --- a/plugins/data_query/static/js/app.js +++ b/plugins/data_query/static/js/app.js @@ -738,6 +738,10 @@ function mongodbInitField(f, data){ } mongodbDataList(1); }); + + $('#mongodb .mongodb_refresh').unbind('click').click(function(){ + mongodbDataList(1); + }); } var mogodb_db_list; From d473f0769f52fade9e8f28ad367613c1bddc23af Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 14 May 2024 16:11:23 +0800 Subject: [PATCH 039/327] Update mongodb.js --- plugins/mongodb/js/mongodb.js | 119 +++++++++++++++++----------------- 1 file changed, 59 insertions(+), 60 deletions(-) diff --git a/plugins/mongodb/js/mongodb.js b/plugins/mongodb/js/mongodb.js index 0ee552180..b606ed04d 100644 --- a/plugins/mongodb/js/mongodb.js +++ b/plugins/mongodb/js/mongodb.js @@ -199,67 +199,66 @@ function mongoReplStatus() { //设置副本名称 function mongoReplCfgReplSetName(){ - mgPost('run_doc_info', '', '', function(rdata){ - var rdata = $.parseJSON(rdata.data); + // + layer.open({ + type: 1, + area: '300px', + title: '设置副本名称', + closeBtn: 1, + shift: 5, + shadeClose: false, + btn:["提交","关闭"], + content: "
\ +
\ + 同步副本名称\ +
\ + \ +
\ +
\ + ", - layer.open({ - type: 1, - area: '300px', - title: '设置副本名称', - closeBtn: 1, - shift: 5, - shadeClose: false, - btn:["提交","关闭"], - content: "
\ -
\ - 同步副本\ -
\ - \ -
\ -
\ - ", - - success: function(){ - // console.log(rdata); - var rlist = rdata['dbs']; - var dbs = []; - var selectHtml = ''; - for (var i = 0; i < rlist.length; i++) { - // console.log(rlist[i]['db']); - var dbname = rlist[i]['db']; - - if (['admin','local','config'].includes(dbname)){ - } else { - dbs.push(dbname); - } - } - - if (dbs.length == 0 ){ - selectHtml += ""; - } - - for (index in dbs) { - selectHtml += ""; - } - - $('select[name="replSetName"]').html(selectHtml); - }, - yes:function(index){ - var data = {}; - data['name'] = $('select[name=replSetName]').val(); - mgPost('repl_set_name', '',data, function(data){ - var rdata = $.parseJSON(data.data); - showMsg(rdata.msg,function(){ - if (rdata['status']){ - layer.close(index); - mongoReplCfgInit(); - } - },{icon: rdata.status ? 1 : 2}); - }); - } - }); + success: function(){ + // // console.log(rdata); + // var rlist = rdata['dbs']; + // var dbs = []; + // var selectHtml = ''; + // for (var i = 0; i < rlist.length; i++) { + // // console.log(rlist[i]['db']); + // var dbname = rlist[i]['db']; + + // if (['admin','local','config'].includes(dbname)){ + // } else { + // dbs.push(dbname); + // } + // } + + // if (dbs.length == 0 ){ + // selectHtml += ""; + // } + + // for (index in dbs) { + // selectHtml += ""; + // } + + // $('select[name="replSetName"]').html(selectHtml); + }, + yes:function(index){ + var data = {}; + data['name'] = $('input[name=replSetName]').val(); + if (data['name'] == ''){ + layer.msg("副本名称不能为空"); + return; + } + mgPost('repl_set_name', '',data, function(data){ + var rdata = $.parseJSON(data.data); + showMsg(rdata.msg,function(){ + if (rdata['status']){ + layer.close(index); + mongoReplCfgInit(); + } + },{icon: rdata.status ? 1 : 2}); + }); + } }); } From 0b95db3bd5e2a2bdbed7f5615a64033712508e62 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 14 May 2024 16:13:06 +0800 Subject: [PATCH 040/327] Update index.py --- plugins/mongodb/index.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/mongodb/index.py b/plugins/mongodb/index.py index d922635fb..68e41c6ef 100755 --- a/plugins/mongodb/index.py +++ b/plugins/mongodb/index.py @@ -106,6 +106,9 @@ def getConfIp(): data = getConfigData() return data['net']['bindIp'] +def getConfLocalIp(): + return '127.0.0.1' + def getConfPort(): data = getConfigData() return data['net']['port'] @@ -185,7 +188,7 @@ def mongdbClientS(): import pymongo port = getConfPort() auth = getConfAuth() - ip = getConfIp() + ip = getConfLocalIp() mg_root = pSqliteDb('config').where('id=?', (1,)).getField('mg_root') if auth == 'disabled': @@ -199,7 +202,7 @@ def mongdbClient(): import pymongo port = getConfPort() auth = getConfAuth() - ip = getConfIp() + ip = getConfLocalIp() mg_root = pSqliteDb('config').where('id=?', (1,)).getField('mg_root') # print(ip,port,auth,mg_root) if auth == 'disabled': From cc0cdd62b83bd9a1958ab2bc9b4ede4d249b919f Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 14 May 2024 16:24:33 +0800 Subject: [PATCH 041/327] 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 27f51e426..0d4788e6d 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3097,7 +3097,7 @@ def doFullSyncUser(version=''): writeDbSyncStatus({'code': 2, 'msg': '远程导出数据...', 'progress': 20}) if not os.path.exists(bak_file): - dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --force --opt --default-character-set=utf8 --single-transaction -h" + ip + " -P" + \ + dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --skip-opt --create-options --default-character-set=utf8 --single-transaction -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + \ "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file print(dump_sql_data) From abd48636abff5a8192f783b7854d2c4c7c3ef708 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 14 May 2024 19:03:17 +0800 Subject: [PATCH 042/327] Update index.py --- plugins/mysql/index.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 0d4788e6d..ba50dc89d 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3096,8 +3096,9 @@ def doFullSyncUser(version=''): writeDbSyncStatus({'code': 2, 'msg': '远程导出数据...', 'progress': 20}) + # --force --opt --single-transaction if not os.path.exists(bak_file): - dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --skip-opt --create-options --default-character-set=utf8 --single-transaction -h" + ip + " -P" + \ + dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --skip-opt --create-options --default-character-set=utf8 -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + \ "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file print(dump_sql_data) From cf44889c741377ea2581621a673b30365733912c Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 14 May 2024 19:25:00 +0800 Subject: [PATCH 043/327] Update index.py --- plugins/mysql/index.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index ba50dc89d..0d8510519 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3104,9 +3104,12 @@ def doFullSyncUser(version=''): print(dump_sql_data) mw.execShell(dump_sql_data) + # 重置 + db.execute('reset master') writeDbSyncStatus({'code': 3, 'msg': '正在到本地导入数据中...', 'progress': 40}) if os.path.exists(bak_file): + pwd = pSqliteDb('config').where('id=?', (1,)).getField('mysql_root') sock = getSocketFile() my_import_cmd = getServerDir() + '/bin/mysql -S ' + sock + " -uroot -p'" + pwd + \ From a1e900f5c9cf5f5ae6bd86e4d32b3be104124429 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 14 May 2024 19:25:18 +0800 Subject: [PATCH 044/327] Update index.py --- plugins/mysql/index.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 0d8510519..6d05f6949 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3104,11 +3104,12 @@ def doFullSyncUser(version=''): print(dump_sql_data) mw.execShell(dump_sql_data) - # 重置 - db.execute('reset master') + writeDbSyncStatus({'code': 3, 'msg': '正在到本地导入数据中...', 'progress': 40}) if os.path.exists(bak_file): + # 重置 + db.execute('reset master') pwd = pSqliteDb('config').where('id=?', (1,)).getField('mysql_root') sock = getSocketFile() From 253de5e70f19b4b0e7494aafe9fb21ee19f7960b Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 14 May 2024 20:11:59 +0800 Subject: [PATCH 045/327] Update index.py --- plugins/mysql/index.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 6d05f6949..43fc72fec 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3070,6 +3070,7 @@ def doFullSyncUser(version=''): else: data = conn.field('ip,port,user,pass,mode,cmd').find() + # print(data) user = data['user'] apass = data['pass'] port = data['port'] @@ -3098,19 +3099,26 @@ def doFullSyncUser(version=''): # --force --opt --single-transaction if not os.path.exists(bak_file): - dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --skip-opt --create-options --default-character-set=utf8 -h" + ip + " -P" + \ - port + " -u" + user + " -p'" + apass + \ - "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file + # 不锁表导出 + dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --skip-opt --create-options --default-character-set=utf8 -h" + ip + " -P" + \ + port + " -u" + user + " -p'" + apass + "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file print(dump_sql_data) mw.execShell(dump_sql_data) - - writeDbSyncStatus({'code': 3, 'msg': '正在到本地导入数据中...', 'progress': 40}) + if os.path.exists(bak_file): # 重置 db.execute('reset master') + # 不锁表,需要删除数据表 + tables = db.query('show tables from `%s`' % sync_db_import) + table_key = "Tables_in_" + sync_db_import + for tname in tables: + drop_db_cmd = 'drop table if exists '+sync_db_import+'.'+tname[table_key] + # print(drop_db_cmd) + db.query(drop_db_cmd) + pwd = pSqliteDb('config').where('id=?', (1,)).getField('mysql_root') sock = getSocketFile() my_import_cmd = getServerDir() + '/bin/mysql -S ' + sock + " -uroot -p'" + pwd + \ From 5d2dd11163a8ea51ed164185d850ff9d126ee642 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 14 May 2024 20:54:47 +0800 Subject: [PATCH 046/327] 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 43fc72fec..60e22a790 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3100,7 +3100,7 @@ def doFullSyncUser(version=''): # --force --opt --single-transaction if not os.path.exists(bak_file): # 不锁表导出 - dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --skip-opt --create-options --default-character-set=utf8 -h" + ip + " -P" + \ + dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --single-transaction --master-data=1 --skip-opt --create-options --default-character-set=utf8 -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file print(dump_sql_data) mw.execShell(dump_sql_data) From b825ed9c76da0ae45dc9a6d5a4f9f585ba41b6b9 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 14 May 2024 20:56:01 +0800 Subject: [PATCH 047/327] 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 60e22a790..ff9221f6a 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3109,7 +3109,7 @@ def doFullSyncUser(version=''): if os.path.exists(bak_file): # 重置 - db.execute('reset master') + # db.execute('reset master') # 不锁表,需要删除数据表 tables = db.query('show tables from `%s`' % sync_db_import) From 2942e47630e40e83ba31da479660568968baf3b7 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 14 May 2024 20:58:49 +0800 Subject: [PATCH 048/327] Update backup.py --- scripts/backup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/backup.py b/scripts/backup.py index c20cab572..1d03ff0d2 100755 --- a/scripts/backup.py +++ b/scripts/backup.py @@ -142,7 +142,7 @@ class backupTools: # name + " | gzip > " + filename # skip-opt 不会lock表 - cmd = db_path + "/bin/mysqldump --defaults-file=" + my_cnf + " --skip-opt --create-options --default-character-set=utf8 " + \ + cmd = db_path + "/bin/mysqldump --defaults-file=" + my_cnf + " --single-transaction --skip-opt --create-options --default-character-set=utf8 " + \ name + " | gzip > " + filename # print(cmd) mw.execShell(cmd) From ddc9defe51cdc3f96a2ace0aa3fe8a7d9e28de57 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 14 May 2024 20:59:46 +0800 Subject: [PATCH 049/327] Update index.py --- plugins/mysql/index.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index ff9221f6a..f69742429 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3097,6 +3097,12 @@ def doFullSyncUser(version=''): writeDbSyncStatus({'code': 2, 'msg': '远程导出数据...', 'progress': 20}) + # --master-data=2表示在dump过程中记录主库的binlog和pos点,并在dump文件中注释掉这一行 + # --master-data=1表示在dump过程中记录主库的binlog和pos点,并在dump文件中不注释掉这一行,即恢复时会执行 + + # --dump-slave=2表示在dump过程中,在从库dump,mysqldump进程也要在从库执行,记录当时主库的binlog和pos点,并在dump文件中注释掉这一行 + # --dump-slave=1表示在dump过程中,在从库dump,mysqldump进程也要在从库执行,记录当时主库的binlog和pos点,并在dump文件中不注释掉这一行 + # --force --opt --single-transaction if not os.path.exists(bak_file): # 不锁表导出 From b1ff41350c027b8a9fc0af1c59536531807938b1 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 14 May 2024 21:02:24 +0800 Subject: [PATCH 050/327] 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 f69742429..4eb5fb60f 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3117,7 +3117,7 @@ def doFullSyncUser(version=''): # 重置 # db.execute('reset master') - # 不锁表,需要删除数据表 + # 不锁表,需要删除原来数据表 tables = db.query('show tables from `%s`' % sync_db_import) table_key = "Tables_in_" + sync_db_import for tname in tables: From 69b8c609aa4d6e6d4003ca6044bf6e23384fca92 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 14 May 2024 21:36:07 +0800 Subject: [PATCH 051/327] 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 4eb5fb60f..a41063f9d 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3106,7 +3106,7 @@ def doFullSyncUser(version=''): # --force --opt --single-transaction if not os.path.exists(bak_file): # 不锁表导出 - dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --single-transaction --master-data=1 --skip-opt --create-options --default-character-set=utf8 -h" + ip + " -P" + \ + dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --single-transaction --dump-slave=1 --skip-opt --create-options --default-character-set=utf8 -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file print(dump_sql_data) mw.execShell(dump_sql_data) From b71e3196b81509a5cfdb97723b78a29db27dbdf6 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 14 May 2024 21:38:07 +0800 Subject: [PATCH 052/327] 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 a41063f9d..63cfeaaab 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3106,7 +3106,7 @@ def doFullSyncUser(version=''): # --force --opt --single-transaction if not os.path.exists(bak_file): # 不锁表导出 - dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --single-transaction --dump-slave=1 --skip-opt --create-options --default-character-set=utf8 -h" + ip + " -P" + \ + dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --single-transaction --skip-opt --create-options --default-character-set=utf8 -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file print(dump_sql_data) mw.execShell(dump_sql_data) From bc9b5ab51190591fc415150013c4194e582bee3e Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 14 May 2024 21:48:55 +0800 Subject: [PATCH 053/327] Update install.sh --- plugins/mysql/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mysql/install.sh b/plugins/mysql/install.sh index da748592f..4b1bfee60 100755 --- a/plugins/mysql/install.sh +++ b/plugins/mysql/install.sh @@ -7,7 +7,7 @@ export PATH # cd /www/server/mdserver-web/plugins/mysql && bash install.sh install 8.2 # cd /www/server/mdserver-web && source bin/activate && python3 /www/server/mdserver-web/plugins/mysql/index.py try_slave_sync_bugfix {} - +# cd /www/server/mdserver-web && python3 /www/server/mdserver-web/plugins/mysql/index.py do_full_sync {"db":"xxx","sign":"","begin":1} curPath=`pwd` rootPath=$(dirname "$curPath") rootPath=$(dirname "$rootPath") From d9eb331f32570c26ad5c3633be2144d8f010841f Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 14 May 2024 22:23:24 +0800 Subject: [PATCH 054/327] 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 63cfeaaab..fab976df0 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3115,7 +3115,7 @@ def doFullSyncUser(version=''): if os.path.exists(bak_file): # 重置 - # db.execute('reset master') + db.execute('reset master') # 不锁表,需要删除原来数据表 tables = db.query('show tables from `%s`' % sync_db_import) From f9020d3c7f9e30ba624bbe2df3bc60be77986878 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 14 May 2024 22:24:08 +0800 Subject: [PATCH 055/327] Update index.py --- plugins/mysql/index.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index fab976df0..a9b0b872c 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3082,9 +3082,9 @@ def doFullSyncUser(version=''): writeDbSyncStatus({'code': 0, 'msg': '开始同步...', 'progress': 0}) dmp_option = '' - mode = recognizeDbMode() - if mode == 'gtid': - dmp_option = ' --set-gtid-purged=off ' + # mode = recognizeDbMode() + # if mode == 'gtid': + # dmp_option = ' --set-gtid-purged=off ' time.sleep(1) writeDbSyncStatus({'code': 1, 'msg': '正在停止从库...', 'progress': 15}) From 342dfe407ce053b1ed0a41376be12f5c929d6c40 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 14 May 2024 22:36:37 +0800 Subject: [PATCH 056/327] Create README.md --- plugins/mysql/README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 plugins/mysql/README.md diff --git a/plugins/mysql/README.md b/plugins/mysql/README.md new file mode 100644 index 000000000..4e4dc435c --- /dev/null +++ b/plugins/mysql/README.md @@ -0,0 +1,2 @@ + +show global variables like '%gtid%'; \ No newline at end of file From b4c0030baa046f48d85c24a0669a8186ab19644d Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 14 May 2024 23:20:26 +0800 Subject: [PATCH 057/327] 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 a9b0b872c..26e9e663e 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3106,7 +3106,7 @@ def doFullSyncUser(version=''): # --force --opt --single-transaction if not os.path.exists(bak_file): # 不锁表导出 - dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --single-transaction --skip-opt --create-options --default-character-set=utf8 -h" + ip + " -P" + \ + dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --single-transaction -q --skip-opt --create-options --default-character-set=utf8 -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file print(dump_sql_data) mw.execShell(dump_sql_data) From 89052225f90280a14b109f1998b7f408dc1d8b2a Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 14 May 2024 23:20:55 +0800 Subject: [PATCH 058/327] 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 26e9e663e..5811ef91c 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3106,7 +3106,7 @@ def doFullSyncUser(version=''): # --force --opt --single-transaction if not os.path.exists(bak_file): # 不锁表导出 - dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --single-transaction -q --skip-opt --create-options --default-character-set=utf8 -h" + ip + " -P" + \ + dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --single-transaction -q -R --skip-opt --create-options --default-character-set=utf8 -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file print(dump_sql_data) mw.execShell(dump_sql_data) From 8a1b64a5246f072c8420f4c85ea8f38db7f0a542 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 14 May 2024 23:21:44 +0800 Subject: [PATCH 059/327] 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 5811ef91c..5c015c873 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3106,7 +3106,7 @@ def doFullSyncUser(version=''): # --force --opt --single-transaction if not os.path.exists(bak_file): # 不锁表导出 - dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --single-transaction -q -R --skip-opt --create-options --default-character-set=utf8 -h" + ip + " -P" + \ + dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --single-transaction -q -R --skip-opt --create-options --default-character-set=utf8mb4 -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file print(dump_sql_data) mw.execShell(dump_sql_data) From 7baecfc4a0f22de604a6106891d0ff24bbf9ea6e Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 14 May 2024 23:57:17 +0800 Subject: [PATCH 060/327] Update README.md --- plugins/mysql/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/mysql/README.md b/plugins/mysql/README.md index 4e4dc435c..0427303eb 100644 --- a/plugins/mysql/README.md +++ b/plugins/mysql/README.md @@ -1,2 +1,4 @@ -show global variables like '%gtid%'; \ No newline at end of file +show global variables like '%gtid%'; + +show global variables like 'server_uuid'; \ No newline at end of file From 507b34797d39911e9500607fd852d7b3cd40ba1e Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 01:18:56 +0800 Subject: [PATCH 061/327] Update backup.py --- scripts/backup.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/scripts/backup.py b/scripts/backup.py index 1d03ff0d2..e6bac68a2 100755 --- a/scripts/backup.py +++ b/scripts/backup.py @@ -87,6 +87,18 @@ class backupTools: path = mw.getServerDir() + '/' + mtype + '/etc/my.cnf' return path + def recognizeDbMode(self, mtype='mysql'): + conf = self.getConf(mtype) + con = mw.readFile(conf) + rep = r"!include %s/(.*)?\.cnf" % (mw.getServerDir() +'/'+ mtype +"/etc/mode",) + mode = 'none' + try: + data = re.findall(rep, con, re.M) + mode = data[0] + except Exception as e: + pass + return mode + # 数据库密码处理 def mypass(self, act, root): conf_file = self.getConf('mysql') @@ -140,9 +152,14 @@ class backupTools: # 开启一致性事务 会lock表 # cmd = db_path + "/bin/mysqldump --defaults-file=" + my_cnf + " --force --opt --default-character-set=utf8 " + \ # name + " | gzip > " + filename + option = '' + mode = self.recognizeDbMode('mysql') + if mode == 'gtid': + option = ' --set-gtid-purged=off ' # skip-opt 不会lock表 - cmd = db_path + "/bin/mysqldump --defaults-file=" + my_cnf + " --single-transaction --skip-opt --create-options --default-character-set=utf8 " + \ + # --skip-opt --create-options + cmd = db_path + "/bin/mysqldump --defaults-file=" + my_cnf +" " + option +" --single-transaction --default-character-set=utf8 " + \ name + " | gzip > " + filename # print(cmd) mw.execShell(cmd) From ea7310502f72c505dc9ef196c58c422b8f4f4fb9 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 01:19:02 +0800 Subject: [PATCH 062/327] Update index.py --- plugins/mysql/index.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 5c015c873..3eaf94229 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -63,12 +63,12 @@ def getArgs(): if t.strip() == '': tmp = [] else: - t = t.split(':', 1) + t = t.split(':',1) tmp[t[0]] = t[1] tmp[t[0]] = t[1] elif args_len > 1: for i in range(len(args)): - t = args[i].split(':', 1) + t = args[i].split(':',1) tmp[t[0]] = t[1] return tmp @@ -3104,9 +3104,10 @@ def doFullSyncUser(version=''): # --dump-slave=1表示在dump过程中,在从库dump,mysqldump进程也要在从库执行,记录当时主库的binlog和pos点,并在dump文件中不注释掉这一行 # --force --opt --single-transaction + # --skip-opt --create-options if not os.path.exists(bak_file): # 不锁表导出 - dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --single-transaction -q -R --skip-opt --create-options --default-character-set=utf8mb4 -h" + ip + " -P" + \ + dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --single-transaction --default-character-set=utf8mb4 -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file print(dump_sql_data) mw.execShell(dump_sql_data) From c89ee89061517e6f11b1ca8044748d2ef6b64e4a Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 01:20:42 +0800 Subject: [PATCH 063/327] Update index.py --- plugins/mysql/index.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 3eaf94229..7f6922978 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3119,12 +3119,12 @@ def doFullSyncUser(version=''): db.execute('reset master') # 不锁表,需要删除原来数据表 - tables = db.query('show tables from `%s`' % sync_db_import) - table_key = "Tables_in_" + sync_db_import - for tname in tables: - drop_db_cmd = 'drop table if exists '+sync_db_import+'.'+tname[table_key] - # print(drop_db_cmd) - db.query(drop_db_cmd) + # tables = db.query('show tables from `%s`' % sync_db_import) + # table_key = "Tables_in_" + sync_db_import + # for tname in tables: + # drop_db_cmd = 'drop table if exists '+sync_db_import+'.'+tname[table_key] + # # print(drop_db_cmd) + # db.query(drop_db_cmd) pwd = pSqliteDb('config').where('id=?', (1,)).getField('mysql_root') sock = getSocketFile() From 585cd8b53217e14d7c9c151aa9da46f0fa5c3344 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 04:06:15 +0800 Subject: [PATCH 064/327] update_dev --- plugins/mysql/index.py | 55 ++++++++++++++++++++++++++++++++++++++++ plugins/mysql/install.sh | 5 ++-- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 7f6922978..48aba1a78 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3018,6 +3018,58 @@ def dumpMysqlData(version=''): return 'fail' +############### --- 重要 数据补足同步 ---- ########### + +def syncDatabaseRepair(version=''): + args = getArgs() + data = checkArgs(args, ['db','sign']) + if not data[0]: + return data[1] + + sync_args_db = args['db'] + sync_args_sign = args['sign'] + conn = pSqliteDb('slave_sync_user') + if sync_args_sign != '': + data = conn.field('ip,port,user,pass,mode,cmd').where('ip=?', (sync_sign,)).find() + else: + data = conn.field('ip,port,user,pass,mode,cmd').find() + + # print(data) + user = data['user'] + apass = data['pass'] + port = data['port'] + ip = data['ip'] + + # 本地数据 + local_db = pMysqlDb() + + # 远程数据 + sync_db = mw.getMyORM() + # MySQLdb | + sync_db.setPort(port) + sync_db.setHost(ip) + sync_db.setUser(user) + sync_db.setPwd(apass) + sync_db.setDbName(sync_args_db) + + tables = local_db.query('show tables from `%s`' % sync_args_db) + table_key = "Tables_in_" + sync_args_db + for tb in tables: + table_name = sync_args_db+'.'+tb[table_key] + + # 比较总数 + cmd_count_sql = 'select count(*) as num from '+table_name + local_count_data = local_db.query(cmd_count_sql) + sync_count_data = sync_db.query(cmd_count_sql) + + print(local_count_data,sync_count_data) + + + + data = sync_db.query("select version()") + print(data) + return True + ############### --- 重要 同步---- ########### def asyncTmpfile(): @@ -3028,6 +3080,7 @@ def asyncTmpfile(): def writeDbSyncStatus(data): path = asyncTmpfile() mw.writeFile(path, json.dumps(data)) + return True def doFullSync(version=''): @@ -3516,5 +3569,7 @@ if __name__ == "__main__": print(doFullSync(version)) elif func == 'dump_mysql_data': print(dumpMysqlData(version)) + elif func == 'sync_database_repair': + print(syncDatabaseRepair()) else: print('error') diff --git a/plugins/mysql/install.sh b/plugins/mysql/install.sh index 4b1bfee60..de9ce8fa9 100755 --- a/plugins/mysql/install.sh +++ b/plugins/mysql/install.sh @@ -6,8 +6,9 @@ export PATH # https://www.cnblogs.com/whiteY/p/17331882.html # cd /www/server/mdserver-web/plugins/mysql && bash install.sh install 8.2 -# cd /www/server/mdserver-web && source bin/activate && python3 /www/server/mdserver-web/plugins/mysql/index.py try_slave_sync_bugfix {} -# cd /www/server/mdserver-web && python3 /www/server/mdserver-web/plugins/mysql/index.py do_full_sync {"db":"xxx","sign":"","begin":1} +# cd /www/server/mdserver-web && source bin/activate && python3 plugins/mysql/index.py try_slave_sync_bugfix {} +# cd /www/server/mdserver-web && python3 plugins/mysql/index.py do_full_sync {"db":"xxx","sign":"","begin":1} +# cd /www/server/mdserver-web && python3 plugins/mysql/index.py sync_database_repair {"db":"xxx","sign":""} curPath=`pwd` rootPath=$(dirname "$curPath") rootPath=$(dirname "$rootPath") From e8a3f8b014bf88af6dfb8e31e8b59f3780f49705 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 04:16:49 +0800 Subject: [PATCH 065/327] Update orm.py --- class/plugin/orm.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/class/plugin/orm.py b/class/plugin/orm.py index 3e96ff9f1..65d3a2135 100755 --- a/class/plugin/orm.py +++ b/class/plugin/orm.py @@ -25,7 +25,19 @@ class ORM: '''连接数据库''' try: - if os.path.exists(self.__DB_SOCKET): + if self.__DB_HOST != 'localhost': + try: + self.__DB_CONN = pymysql.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS, + database=self.__DB_NAME, + port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1, + cursorclass=pymysql.cursors.DictCursor) + except Exception as e: + self.__DB_HOST = '127.0.0.1' + self.__DB_CONN = pymysql.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS, + database=self.__DB_NAME, + port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1, + cursorclass=pymysql.cursors.DictCursor) + else if os.path.exists(self.__DB_SOCKET): try: self.__DB_CONN = pymysql.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS, database=self.__DB_NAME, From e85e6a7299220e822c8fa3886f70b6839683e84a Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 04:22:14 +0800 Subject: [PATCH 066/327] update --- class/plugin/orm.py | 3 ++- plugins/mysql/index.py | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/class/plugin/orm.py b/class/plugin/orm.py index 65d3a2135..34a5605e4 100755 --- a/class/plugin/orm.py +++ b/class/plugin/orm.py @@ -22,6 +22,7 @@ class ORM: __DB_CHARSET = "utf8" def __Conn(self): + # print(self.__DB_HOST, self.__DB_USER) '''连接数据库''' try: @@ -37,7 +38,7 @@ class ORM: database=self.__DB_NAME, port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1, cursorclass=pymysql.cursors.DictCursor) - else if os.path.exists(self.__DB_SOCKET): + elif os.path.exists(self.__DB_SOCKET): try: self.__DB_CONN = pymysql.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS, database=self.__DB_NAME, diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 48aba1a78..d6710cc5a 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3054,6 +3054,7 @@ def syncDatabaseRepair(version=''): tables = local_db.query('show tables from `%s`' % sync_args_db) table_key = "Tables_in_" + sync_args_db + inconsistent_table = [] for tb in tables: table_name = sync_args_db+'.'+tb[table_key] @@ -3062,9 +3063,11 @@ def syncDatabaseRepair(version=''): local_count_data = local_db.query(cmd_count_sql) sync_count_data = sync_db.query(cmd_count_sql) - print(local_count_data,sync_count_data) - - + if local_count_data[0]['num'] != local_count_data[0]['num']: + inconsistent_table.append(table_name) + else: + print(table_name+', 正常OK') + print(inconsistent_table) data = sync_db.query("select version()") print(data) From 8d875fe589646221fb539dfa52f8efc39f419f5b Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 04:23:17 +0800 Subject: [PATCH 067/327] 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 d6710cc5a..7596aaa09 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3063,7 +3063,7 @@ def syncDatabaseRepair(version=''): local_count_data = local_db.query(cmd_count_sql) sync_count_data = sync_db.query(cmd_count_sql) - if local_count_data[0]['num'] != local_count_data[0]['num']: + if local_count_data[0]['num'] != sync_count_data[0]['num']: inconsistent_table.append(table_name) else: print(table_name+', 正常OK') From 272b13b29cf756936d38db5ff1b2beaa3ce11c14 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 04:24:13 +0800 Subject: [PATCH 068/327] Update index.py --- plugins/mysql/index.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 7596aaa09..59d16b28a 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3065,6 +3065,7 @@ def syncDatabaseRepair(version=''): if local_count_data[0]['num'] != sync_count_data[0]['num']: inconsistent_table.append(table_name) + print(table_name+', 需要同步。') else: print(table_name+', 正常OK') print(inconsistent_table) From e114b07d7df02ab6fe6195d66d172abeccd0bec9 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 04:30:04 +0800 Subject: [PATCH 069/327] Update index.py --- plugins/mysql/index.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 59d16b28a..f788fce4d 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3068,6 +3068,19 @@ def syncDatabaseRepair(version=''): print(table_name+', 需要同步。') else: print(table_name+', 正常OK') + + # 数据对齐 + for table_name in inconsistent_table: + data_select_sql = 'select * from '+table_name + ' id > 0 limit 1' + local_select_data = local_db.query(data_select_sql) + sync_select_data = sync_db.query(data_select_sql) + + print(local_select_data) + print(sync_select_data) + + + + print(inconsistent_table) data = sync_db.query("select version()") From ff7d2f358e1d17e5760650a9ca52c9eca274011a Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 04:35:12 +0800 Subject: [PATCH 070/327] Update index.py --- plugins/mysql/index.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index f788fce4d..66dfd5626 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3055,8 +3055,17 @@ def syncDatabaseRepair(version=''): tables = local_db.query('show tables from `%s`' % sync_args_db) table_key = "Tables_in_" + sync_args_db inconsistent_table = [] + + tmp_dir = '/tmp/sync_db_repair' + mw.execShell('mkdir -p '+tmp_dir) + for tb in tables: table_name = sync_args_db+'.'+tb[table_key] + table_check_file = tmp_dir+'/'+table_name+'.txt' + + if os.path.exists(table_check_file): + print(table_name+', 已检查OK') + continue # 比较总数 cmd_count_sql = 'select count(*) as num from '+table_name @@ -3068,6 +3077,7 @@ def syncDatabaseRepair(version=''): print(table_name+', 需要同步。') else: print(table_name+', 正常OK') + mw.execShell("echo 'ok' > "+table_check_file) # 数据对齐 for table_name in inconsistent_table: From f4cff7bcf712ef1f2e12c05ceedfe36db1e6a8c3 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 04:35:52 +0800 Subject: [PATCH 071/327] 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 66dfd5626..98e37fb4f 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3081,7 +3081,7 @@ def syncDatabaseRepair(version=''): # 数据对齐 for table_name in inconsistent_table: - data_select_sql = 'select * from '+table_name + ' id > 0 limit 1' + data_select_sql = 'select * from '+table_name + ' where id > 0 limit 1' local_select_data = local_db.query(data_select_sql) sync_select_data = sync_db.query(data_select_sql) From 478e03bca18e081e3c4204b6570a9c92669b4e65 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 04:42:42 +0800 Subject: [PATCH 072/327] Update index.py --- plugins/mysql/index.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 98e37fb4f..cf9c4b140 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3081,7 +3081,11 @@ def syncDatabaseRepair(version=''): # 数据对齐 for table_name in inconsistent_table: - data_select_sql = 'select * from '+table_name + ' where id > 0 limit 1' + primary_key_sql = "SHOW INDEX FROM "+table_name+" WHERE Key_name = 'PRIMARY';"; + primary_key_data = local_db.query(primary_key_sql) + pkey_name = primary_key_data[0]['Column_name'] + data_select_sql = 'select * from '+table_name + ' where '+pkey_name+' > 0 limit 1' + print(data_select_sql) local_select_data = local_db.query(data_select_sql) sync_select_data = sync_db.query(data_select_sql) From c6a742a9327b4f0da1ddb5690e4d83fb02903fd3 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 04:57:51 +0800 Subject: [PATCH 073/327] Update index.py --- plugins/mysql/index.py | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index cf9c4b140..8217c719f 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3080,17 +3080,35 @@ def syncDatabaseRepair(version=''): mw.execShell("echo 'ok' > "+table_check_file) # 数据对齐 - for table_name in inconsistent_table: - primary_key_sql = "SHOW INDEX FROM "+table_name+" WHERE Key_name = 'PRIMARY';"; - primary_key_data = local_db.query(primary_key_sql) - pkey_name = primary_key_data[0]['Column_name'] - data_select_sql = 'select * from '+table_name + ' where '+pkey_name+' > 0 limit 1' - print(data_select_sql) - local_select_data = local_db.query(data_select_sql) - sync_select_data = sync_db.query(data_select_sql) - - print(local_select_data) - print(sync_select_data) + while True: + for table_name in inconsistent_table: + print("正在校验表,"+table_name) + table_name_pos = 0 + table_name_pos_file = tmp_dir+'/'+table_name+'.pos.txt' + primary_key_sql = "SHOW INDEX FROM "+table_name+" WHERE Key_name = 'PRIMARY';"; + primary_key_data = local_db.query(primary_key_sql) + pkey_name = primary_key_data[0]['Column_name'] + + data_select_sql = 'select * from '+table_name + ' where '+pkey_name+' > '+str(table_name_pos)+' limit 1' + local_select_data = local_db.query(data_select_sql) + sync_select_data = sync_db.query(data_select_sql) + + print(local_select_data) + print(sync_select_data) + print(local_select_data == sync_select_data) + + if local_select_data == sync_select_data: + data_count = len(local_select_data) + print(local_select_data[data_count-1][pkey_name]) + pkey_val = local_select_data[data_count-1][pkey_name] + print(pkey_val) + mw.writeFile(table_name_pos_file, str(pkey_val)) + + time.sleep(1) + + + + From 994ee32fbf55ab0626d42c7934007ad713c1d6f5 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 05:00:03 +0800 Subject: [PATCH 074/327] Update index.py --- plugins/mysql/index.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 8217c719f..5e41e50e6 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3088,13 +3088,16 @@ def syncDatabaseRepair(version=''): primary_key_sql = "SHOW INDEX FROM "+table_name+" WHERE Key_name = 'PRIMARY';"; primary_key_data = local_db.query(primary_key_sql) pkey_name = primary_key_data[0]['Column_name'] + + if os.path.exists(table_name_pos_file): + table_name_pos = mw.readFile(table_name_pos_file) - data_select_sql = 'select * from '+table_name + ' where '+pkey_name+' > '+str(table_name_pos)+' limit 1' + data_select_sql = 'select * from '+table_name + ' where '+pkey_name+' > '+str(table_name_pos)+' limit 1000' local_select_data = local_db.query(data_select_sql) sync_select_data = sync_db.query(data_select_sql) - print(local_select_data) - print(sync_select_data) + # print(local_select_data) + # print(sync_select_data) print(local_select_data == sync_select_data) if local_select_data == sync_select_data: @@ -3103,6 +3106,9 @@ def syncDatabaseRepair(version=''): pkey_val = local_select_data[data_count-1][pkey_name] print(pkey_val) mw.writeFile(table_name_pos_file, str(pkey_val)) + else: + print(local_select_data) + print(sync_select_data) time.sleep(1) From 4b200765aa9222b408dbcd44d2a8be6f208cf95d Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 05:02:01 +0800 Subject: [PATCH 075/327] Update index.py --- plugins/mysql/index.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 5e41e50e6..80262dbc6 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3107,8 +3107,10 @@ def syncDatabaseRepair(version=''): print(pkey_val) mw.writeFile(table_name_pos_file, str(pkey_val)) else: - print(local_select_data) - print(sync_select_data) + # print(local_select_data) + # print(sync_select_data) + print(len(local_select_data)) + print(len(sync_select_data)) time.sleep(1) From 24d3fc18d67956459f4cf6d8d78bce38b3c54b31 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 05:05:29 +0800 Subject: [PATCH 076/327] Update index.py --- plugins/mysql/index.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 80262dbc6..720fc3145 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3072,6 +3072,7 @@ def syncDatabaseRepair(version=''): local_count_data = local_db.query(cmd_count_sql) sync_count_data = sync_db.query(cmd_count_sql) + print("总数据比较: ",local_count_data[0]['num'], sync_count_data[0]['num']) if local_count_data[0]['num'] != sync_count_data[0]['num']: inconsistent_table.append(table_name) print(table_name+', 需要同步。') From 8031ea2c4578b21063b843581947c388fe236ef1 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 05:35:14 +0800 Subject: [PATCH 077/327] Update index.py --- plugins/mysql/index.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 720fc3145..e3322aa87 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3080,6 +3080,7 @@ def syncDatabaseRepair(version=''): print(table_name+', 正常OK') mw.execShell("echo 'ok' > "+table_check_file) + # inconsistent_table = ['99cms.mc_telcode'] # 数据对齐 while True: for table_name in inconsistent_table: @@ -3099,15 +3100,39 @@ def syncDatabaseRepair(version=''): # print(local_select_data) # print(sync_select_data) - print(local_select_data == sync_select_data) + # print(local_select_data == sync_select_data) if local_select_data == sync_select_data: data_count = len(local_select_data) + if data_count == 0: + break + print(data_count) print(local_select_data[data_count-1][pkey_name]) pkey_val = local_select_data[data_count-1][pkey_name] print(pkey_val) mw.writeFile(table_name_pos_file, str(pkey_val)) else: + + for insert_data in sync_select_data: + # print(insert_data) + local_inquery_sql = 'select id from ' + table_name+ ' where ' +pkey_name+' = '+ str(insert_data[pkey_name]) + # print(local_inquery_sql) + tdata = local_db.query(local_inquery_sql) + if len(tdata) == 0: + print("id:"+ str(insert_data[pkey_name])+ " 不存在,插入中") + insert_sql = 'insert into ' + table_name + field_str = '' + value_str = '' + for field in insert_data: + field_str += '`'+field+'`,' + value_str += '\''+str(insert_data[field])+'\',' + field_str = '(' +field_str.strip(',')+')' + value_str = '(' +value_str.strip(',')+')' + insert_sql = insert_sql+' '+field_str+' values'+value_str+';' + print(insert_sql) + r = local_db.query(insert_sql) + print(r) + # print(local_select_data) # print(sync_select_data) print(len(local_select_data)) From a07ed6130517b9a578464f8546fafd043c8fb788 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 05:38:59 +0800 Subject: [PATCH 078/327] Update index.py --- plugins/mysql/index.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index e3322aa87..a43e66c8b 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3021,6 +3021,7 @@ def dumpMysqlData(version=''): ############### --- 重要 数据补足同步 ---- ########### def syncDatabaseRepair(version=''): + import pymysql args = getArgs() data = checkArgs(args, ['db','sign']) if not data[0]: @@ -3125,7 +3126,7 @@ def syncDatabaseRepair(version=''): value_str = '' for field in insert_data: field_str += '`'+field+'`,' - value_str += '\''+str(insert_data[field])+'\',' + value_str += '\''+pymysql.escape_string(insert_data[field])+'\',' field_str = '(' +field_str.strip(',')+')' value_str = '(' +value_str.strip(',')+')' insert_sql = insert_sql+' '+field_str+' values'+value_str+';' From 6ec2e4f29f8403752dad2581b7bb691a33c58f5d Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 05:41:51 +0800 Subject: [PATCH 079/327] Update index.py --- plugins/mysql/index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index a43e66c8b..35c8fad6b 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3021,7 +3021,7 @@ def dumpMysqlData(version=''): ############### --- 重要 数据补足同步 ---- ########### def syncDatabaseRepair(version=''): - import pymysql + from pymysql.converters import escape_string args = getArgs() data = checkArgs(args, ['db','sign']) if not data[0]: @@ -3126,7 +3126,7 @@ def syncDatabaseRepair(version=''): value_str = '' for field in insert_data: field_str += '`'+field+'`,' - value_str += '\''+pymysql.escape_string(insert_data[field])+'\',' + value_str += '\''+escape_string(insert_data[field])+'\',' field_str = '(' +field_str.strip(',')+')' value_str = '(' +value_str.strip(',')+')' insert_sql = insert_sql+' '+field_str+' values'+value_str+';' From 2079076638060f5659207479a25655173ec7d27e Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 05:42:44 +0800 Subject: [PATCH 080/327] Update index.py --- plugins/mysql/index.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 35c8fad6b..368157a1e 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3126,7 +3126,7 @@ def syncDatabaseRepair(version=''): value_str = '' for field in insert_data: field_str += '`'+field+'`,' - value_str += '\''+escape_string(insert_data[field])+'\',' + value_str += '\''+escape_string(str(insert_data[field]))+'\',' field_str = '(' +field_str.strip(',')+')' value_str = '(' +value_str.strip(',')+')' insert_sql = insert_sql+' '+field_str+' values'+value_str+';' @@ -3143,15 +3143,7 @@ def syncDatabaseRepair(version=''): - - - - - print(inconsistent_table) - - data = sync_db.query("select version()") - print(data) return True ############### --- 重要 同步---- ########### From 2f18bf5fb24aefdd6102d145d814ed7f20dc503c Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 05:50:25 +0800 Subject: [PATCH 081/327] Update index.py --- plugins/mysql/index.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 368157a1e..e4f5f10bd 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3081,7 +3081,7 @@ def syncDatabaseRepair(version=''): print(table_name+', 正常OK') mw.execShell("echo 'ok' > "+table_check_file) - # inconsistent_table = ['99cms.mc_telcode'] + # inconsistent_table = ['99cms.mc_order'] # 数据对齐 while True: for table_name in inconsistent_table: @@ -3106,11 +3106,12 @@ def syncDatabaseRepair(version=''): if local_select_data == sync_select_data: data_count = len(local_select_data) if data_count == 0: + print(table_name+"完全一致..") break - print(data_count) - print(local_select_data[data_count-1][pkey_name]) + # print(data_count) + print(table_name,local_select_data[data_count-1][pkey_name]) pkey_val = local_select_data[data_count-1][pkey_name] - print(pkey_val) + # print(pkey_val) mw.writeFile(table_name_pos_file, str(pkey_val)) else: @@ -3131,7 +3132,7 @@ def syncDatabaseRepair(version=''): value_str = '(' +value_str.strip(',')+')' insert_sql = insert_sql+' '+field_str+' values'+value_str+';' print(insert_sql) - r = local_db.query(insert_sql) + r = local_db.execute(insert_sql) print(r) # print(local_select_data) From b708d4821a89e2ac1f8cce38571b47e78e83e621 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 05:59:39 +0800 Subject: [PATCH 082/327] Update index.py --- plugins/mysql/index.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index e4f5f10bd..1d7fef88e 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3083,8 +3083,8 @@ def syncDatabaseRepair(version=''): # inconsistent_table = ['99cms.mc_order'] # 数据对齐 - while True: - for table_name in inconsistent_table: + for table_name in inconsistent_table: + while True: print("正在校验表,"+table_name) table_name_pos = 0 table_name_pos_file = tmp_dir+'/'+table_name+'.pos.txt' @@ -3101,14 +3101,27 @@ def syncDatabaseRepair(version=''): # print(local_select_data) # print(sync_select_data) - # print(local_select_data == sync_select_data) + + is_break = False + # print(len(local_select_data)) + # print(len(sync_select_data)) + print(local_select_data == sync_select_data) if local_select_data == sync_select_data: data_count = len(local_select_data) if data_count == 0: print(table_name+"完全一致..") + is_break = True break - # print(data_count) + + cmd_count_sql = 'select count(*) as num from '+table_name + local_count_data = local_db.query(cmd_count_sql) + sync_count_data = sync_db.query(cmd_count_sql) + + if local_count_data[0]['num'] == sync_count_data[0]['num']: + is_break = True + break + print(table_name,data_count) print(table_name,local_select_data[data_count-1][pkey_name]) pkey_val = local_select_data[data_count-1][pkey_name] # print(pkey_val) @@ -3137,13 +3150,12 @@ def syncDatabaseRepair(version=''): # print(local_select_data) # print(sync_select_data) - print(len(local_select_data)) - print(len(sync_select_data)) + + if is_break: + break time.sleep(1) - - print(inconsistent_table) return True From d0881ff3ebe1fa82da9f75e945373d162e3a8953 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 06:04:24 +0800 Subject: [PATCH 083/327] Update index.py --- plugins/mysql/index.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 1d7fef88e..f7124cf7f 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3084,7 +3084,10 @@ def syncDatabaseRepair(version=''): # inconsistent_table = ['99cms.mc_order'] # 数据对齐 for table_name in inconsistent_table: - while True: + is_break = False + if table_name == '99cms.mc_guest': + continue + while not is_break: print("正在校验表,"+table_name) table_name_pos = 0 table_name_pos_file = tmp_dir+'/'+table_name+'.pos.txt' @@ -3102,7 +3105,6 @@ def syncDatabaseRepair(version=''): # print(local_select_data) # print(sync_select_data) - is_break = False # print(len(local_select_data)) # print(len(sync_select_data)) print(local_select_data == sync_select_data) @@ -3117,12 +3119,12 @@ def syncDatabaseRepair(version=''): cmd_count_sql = 'select count(*) as num from '+table_name local_count_data = local_db.query(cmd_count_sql) sync_count_data = sync_db.query(cmd_count_sql) - + print(local_count_data,sync_count_data) if local_count_data[0]['num'] == sync_count_data[0]['num']: is_break = True break - print(table_name,data_count) - print(table_name,local_select_data[data_count-1][pkey_name]) + # print(table_name,data_count) + print('pos',local_select_data[data_count-1][pkey_name]) pkey_val = local_select_data[data_count-1][pkey_name] # print(pkey_val) mw.writeFile(table_name_pos_file, str(pkey_val)) @@ -3153,6 +3155,7 @@ def syncDatabaseRepair(version=''): if is_break: + print("break all") break time.sleep(1) From 661faf85035dcb4e26d9daa9f6f68b15047571bb Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 11:57:58 +0800 Subject: [PATCH 084/327] 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 f7124cf7f..09d248a6a 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3073,7 +3073,7 @@ def syncDatabaseRepair(version=''): local_count_data = local_db.query(cmd_count_sql) sync_count_data = sync_db.query(cmd_count_sql) - print("总数据比较: ",local_count_data[0]['num'], sync_count_data[0]['num']) + print("总数据比较: ",local_count_data, sync_count_data) if local_count_data[0]['num'] != sync_count_data[0]['num']: inconsistent_table.append(table_name) print(table_name+', 需要同步。') From 6b8716ae59b2a5502765903659149887a62ba51d Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 12:07:57 +0800 Subject: [PATCH 085/327] Update index.py --- plugins/mysql/index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 09d248a6a..0a7d335f0 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3105,8 +3105,8 @@ def syncDatabaseRepair(version=''): # print(local_select_data) # print(sync_select_data) - # print(len(local_select_data)) - # print(len(sync_select_data)) + print(len(local_select_data)) + print(len(sync_select_data)) print(local_select_data == sync_select_data) if local_select_data == sync_select_data: From ae4af02909a63ab71d49555afc31a11ebfeb5b7d Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 12:27:54 +0800 Subject: [PATCH 086/327] Update index.py --- plugins/mysql/index.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 0a7d335f0..595d0d175 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3105,9 +3105,11 @@ def syncDatabaseRepair(version=''): # print(local_select_data) # print(sync_select_data) - print(len(local_select_data)) - print(len(sync_select_data)) - print(local_select_data == sync_select_data) + # print(len(local_select_data)) + # print(len(sync_select_data)) + print('local compare sync,',local_select_data == sync_select_data) + diff = sync_count_data[0]['num'] - local_count_data[0]['num'] + print("diff," + str(diff)+' line data!') if local_select_data == sync_select_data: data_count = len(local_select_data) @@ -3130,11 +3132,13 @@ def syncDatabaseRepair(version=''): mw.writeFile(table_name_pos_file, str(pkey_val)) else: + for insert_data in sync_select_data: # print(insert_data) local_inquery_sql = 'select id from ' + table_name+ ' where ' +pkey_name+' = '+ str(insert_data[pkey_name]) - # print(local_inquery_sql) + print(local_inquery_sql) tdata = local_db.query(local_inquery_sql) + print(tdata) if len(tdata) == 0: print("id:"+ str(insert_data[pkey_name])+ " 不存在,插入中") insert_sql = 'insert into ' + table_name @@ -3149,6 +3153,9 @@ def syncDatabaseRepair(version=''): print(insert_sql) r = local_db.execute(insert_sql) print(r) + else: + mw.writeFile(table_name_pos_file, str(insert_data[pkey_name])) + # print(local_select_data) # print(sync_select_data) From fc1e23f12dcba1904a3c3699fd1d6c162016b482 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 12:31:52 +0800 Subject: [PATCH 087/327] Update index.py --- plugins/mysql/index.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 595d0d175..059a92c3c 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3108,8 +3108,7 @@ def syncDatabaseRepair(version=''): # print(len(local_select_data)) # print(len(sync_select_data)) print('local compare sync,',local_select_data == sync_select_data) - diff = sync_count_data[0]['num'] - local_count_data[0]['num'] - print("diff," + str(diff)+' line data!') + if local_select_data == sync_select_data: data_count = len(local_select_data) @@ -3125,6 +3124,10 @@ def syncDatabaseRepair(version=''): if local_count_data[0]['num'] == sync_count_data[0]['num']: is_break = True break + + diff = sync_count_data[0]['num'] - local_count_data[0]['num'] + print("diff," + str(diff)+' line data!') + # print(table_name,data_count) print('pos',local_select_data[data_count-1][pkey_name]) pkey_val = local_select_data[data_count-1][pkey_name] @@ -3136,7 +3139,7 @@ def syncDatabaseRepair(version=''): for insert_data in sync_select_data: # print(insert_data) local_inquery_sql = 'select id from ' + table_name+ ' where ' +pkey_name+' = '+ str(insert_data[pkey_name]) - print(local_inquery_sql) + # print(local_inquery_sql) tdata = local_db.query(local_inquery_sql) print(tdata) if len(tdata) == 0: From 29c73679060713a407ff00ab23c2e5367fd4849c Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 13:01:44 +0800 Subject: [PATCH 088/327] Update index.py --- plugins/mysql/index.py | 45 ++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 059a92c3c..74e7a3b09 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3065,7 +3065,7 @@ def syncDatabaseRepair(version=''): table_check_file = tmp_dir+'/'+table_name+'.txt' if os.path.exists(table_check_file): - print(table_name+', 已检查OK') + # print(table_name+', 已检查OK') continue # 比较总数 @@ -3073,12 +3073,13 @@ def syncDatabaseRepair(version=''): local_count_data = local_db.query(cmd_count_sql) sync_count_data = sync_db.query(cmd_count_sql) - print("总数据比较: ",local_count_data, sync_count_data) - if local_count_data[0]['num'] != sync_count_data[0]['num']: + if local_count_data != sync_count_data: + print("总数据比较: ",local_count_data, sync_count_data) inconsistent_table.append(table_name) - print(table_name+', 需要同步。') + diff = sync_count_data[0]['num'] - local_count_data[0]['num'] + print(table_name+', need sync. diff,'+str(diff)) else: - print(table_name+', 正常OK') + # print(table_name+', 正常OK') mw.execShell("echo 'ok' > "+table_check_file) # inconsistent_table = ['99cms.mc_order'] @@ -3113,7 +3114,7 @@ def syncDatabaseRepair(version=''): if local_select_data == sync_select_data: data_count = len(local_select_data) if data_count == 0: - print(table_name+"完全一致..") + print(table_name+",完全一致..") is_break = True break @@ -3121,27 +3122,26 @@ def syncDatabaseRepair(version=''): local_count_data = local_db.query(cmd_count_sql) sync_count_data = sync_db.query(cmd_count_sql) print(local_count_data,sync_count_data) - if local_count_data[0]['num'] == sync_count_data[0]['num']: - is_break = True - break + # if local_count_data[0]['num'] == sync_count_data[0]['num']: + # is_break = True + # break diff = sync_count_data[0]['num'] - local_count_data[0]['num'] print("diff," + str(diff)+' line data!') - + # print(table_name,data_count) print('pos',local_select_data[data_count-1][pkey_name]) pkey_val = local_select_data[data_count-1][pkey_name] # print(pkey_val) mw.writeFile(table_name_pos_file, str(pkey_val)) else: - - - for insert_data in sync_select_data: + for idx in range(len(sync_select_data)): + insert_data = sync_select_data[idx] # print(insert_data) local_inquery_sql = 'select id from ' + table_name+ ' where ' +pkey_name+' = '+ str(insert_data[pkey_name]) # print(local_inquery_sql) tdata = local_db.query(local_inquery_sql) - print(tdata) + # print(tdata) if len(tdata) == 0: print("id:"+ str(insert_data[pkey_name])+ " 不存在,插入中") insert_sql = 'insert into ' + table_name @@ -3157,7 +3157,22 @@ def syncDatabaseRepair(version=''): r = local_db.execute(insert_sql) print(r) else: - mw.writeFile(table_name_pos_file, str(insert_data[pkey_name])) + if sync_select_data[idx] == local_select_data[idx]: + continue + print("id:"+ str(insert_data[pkey_name])+ " 数据不一致,更新中") + update_sql = 'update ' + table_name + field_str = '' + value_str = '' + for field in insert_data: + if field == pkey_name: + continue + field_str += '`'+field+'`=\''+escape_string(str(insert_data[field]))+'\',' + field_str = field_str.strip(',') + update_sql = update_sql+' set '+field_str+' where '+pkey_name+'=\''+str(insert_data[pkey_name])+'\';' + print(update_sql) + r = local_db.execute(update_sql) + print(r) + # print(local_select_data) From 3e95e3aaf227d36834e6c2620455892493e43615 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 13:28:46 +0800 Subject: [PATCH 089/327] Update index.py --- plugins/mysql/index.py | 52 ++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 74e7a3b09..557b53ef3 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3074,7 +3074,7 @@ def syncDatabaseRepair(version=''): sync_count_data = sync_db.query(cmd_count_sql) if local_count_data != sync_count_data: - print("总数据比较: ",local_count_data, sync_count_data) + print("all data compare: ",local_count_data, sync_count_data) inconsistent_table.append(table_name) diff = sync_count_data[0]['num'] - local_count_data[0]['num'] print(table_name+', need sync. diff,'+str(diff)) @@ -3082,14 +3082,12 @@ def syncDatabaseRepair(version=''): # print(table_name+', 正常OK') mw.execShell("echo 'ok' > "+table_check_file) - # inconsistent_table = ['99cms.mc_order'] + # inconsistent_table = ['99cms.mc_read'] # 数据对齐 for table_name in inconsistent_table: is_break = False - if table_name == '99cms.mc_guest': - continue while not is_break: - print("正在校验表,"+table_name) + print("check table:"+table_name) table_name_pos = 0 table_name_pos_file = tmp_dir+'/'+table_name+'.pos.txt' primary_key_sql = "SHOW INDEX FROM "+table_name+" WHERE Key_name = 'PRIMARY';"; @@ -3099,7 +3097,8 @@ def syncDatabaseRepair(version=''): if os.path.exists(table_name_pos_file): table_name_pos = mw.readFile(table_name_pos_file) - data_select_sql = 'select * from '+table_name + ' where '+pkey_name+' > '+str(table_name_pos)+' limit 1000' + data_select_sql = 'select * from '+table_name + ' where '+pkey_name+' > '+str(table_name_pos)+' limit 10000' + print(data_select_sql) local_select_data = local_db.query(data_select_sql) sync_select_data = sync_db.query(data_select_sql) @@ -3110,40 +3109,43 @@ def syncDatabaseRepair(version=''): # print(len(sync_select_data)) print('local compare sync,',local_select_data == sync_select_data) + cmd_count_sql = 'select count(*) as num from '+table_name + local_count_data = local_db.query(cmd_count_sql) + sync_count_data = sync_db.query(cmd_count_sql) + print(local_count_data,sync_count_data) + # if local_count_data[0]['num'] == sync_count_data[0]['num']: + # is_break = True + # break + + diff = sync_count_data[0]['num'] - local_count_data[0]['num'] + print("diff," + str(diff)+' line data!') if local_select_data == sync_select_data: data_count = len(local_select_data) if data_count == 0: - print(table_name+",完全一致..") + # mw.writeFile(table_name_pos_file, '0') + print(table_name+",data is equal ok..") is_break = True break - cmd_count_sql = 'select count(*) as num from '+table_name - local_count_data = local_db.query(cmd_count_sql) - sync_count_data = sync_db.query(cmd_count_sql) - print(local_count_data,sync_count_data) - # if local_count_data[0]['num'] == sync_count_data[0]['num']: - # is_break = True - # break - - diff = sync_count_data[0]['num'] - local_count_data[0]['num'] - print("diff," + str(diff)+' line data!') - # print(table_name,data_count) - print('pos',local_select_data[data_count-1][pkey_name]) - pkey_val = local_select_data[data_count-1][pkey_name] - # print(pkey_val) - mw.writeFile(table_name_pos_file, str(pkey_val)) + pos = local_select_data[data_count-1][pkey_name] + print('pos',pos) + progress = pos/sync_count_data[0]['num'] + print('progress,%.2f' % progress+'%') + mw.writeFile(table_name_pos_file, str(pos)) else: + if len(sync_select_data) == 0: + continue for idx in range(len(sync_select_data)): insert_data = sync_select_data[idx] # print(insert_data) - local_inquery_sql = 'select id from ' + table_name+ ' where ' +pkey_name+' = '+ str(insert_data[pkey_name]) + local_inquery_sql = 'select '+pkey_name+' from ' + table_name+ ' where ' +pkey_name+' = '+ str(insert_data[pkey_name]) # print(local_inquery_sql) tdata = local_db.query(local_inquery_sql) # print(tdata) if len(tdata) == 0: - print("id:"+ str(insert_data[pkey_name])+ " 不存在,插入中") + print("id:"+ str(insert_data[pkey_name])+ " no exists, insert") insert_sql = 'insert into ' + table_name field_str = '' value_str = '' @@ -3159,7 +3161,7 @@ def syncDatabaseRepair(version=''): else: if sync_select_data[idx] == local_select_data[idx]: continue - print("id:"+ str(insert_data[pkey_name])+ " 数据不一致,更新中") + print("id:"+ str(insert_data[pkey_name])+ " data is not equal, update") update_sql = 'update ' + table_name field_str = '' value_str = '' From 21d86f0583de359cd7bcca6922c4feaf1973f5d7 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 13:33:08 +0800 Subject: [PATCH 090/327] Update index.py --- plugins/mysql/index.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 557b53ef3..00e6040f5 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3079,7 +3079,7 @@ def syncDatabaseRepair(version=''): diff = sync_count_data[0]['num'] - local_count_data[0]['num'] print(table_name+', need sync. diff,'+str(diff)) else: - # print(table_name+', 正常OK') + print(table_name+', OK') mw.execShell("echo 'ok' > "+table_check_file) # inconsistent_table = ['99cms.mc_read'] @@ -3179,14 +3179,13 @@ def syncDatabaseRepair(version=''): # print(local_select_data) # print(sync_select_data) - if is_break: print("break all") break - time.sleep(1) - + time.sleep(3) print(inconsistent_table) + mw.execShell('rm -rf '+tmp_dir) return True ############### --- 重要 同步---- ########### From 1dcd4520f1144bb3fa821ec70f5373e2d5d2befa Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 13:37:23 +0800 Subject: [PATCH 091/327] Update index.py --- plugins/mysql/index.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 00e6040f5..8ee3df184 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3087,6 +3087,7 @@ def syncDatabaseRepair(version=''): for table_name in inconsistent_table: is_break = False while not is_break: + local_db = pMysqlDb() print("check table:"+table_name) table_name_pos = 0 table_name_pos_file = tmp_dir+'/'+table_name+'.pos.txt' From ff52646fd298533854736c80f0b3743b9f0a3a34 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 13:40:00 +0800 Subject: [PATCH 092/327] 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 8ee3df184..4f3c9b6b7 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3082,7 +3082,7 @@ def syncDatabaseRepair(version=''): print(table_name+', OK') mw.execShell("echo 'ok' > "+table_check_file) - # inconsistent_table = ['99cms.mc_read'] + # inconsistent_table = ['xx.xx'] # 数据对齐 for table_name in inconsistent_table: is_break = False From 53952d267e935a702d37bd8a8d906eaae90bbade Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 13:42:57 +0800 Subject: [PATCH 093/327] 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 4f3c9b6b7..19b7563ce 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3079,7 +3079,7 @@ def syncDatabaseRepair(version=''): diff = sync_count_data[0]['num'] - local_count_data[0]['num'] print(table_name+', need sync. diff,'+str(diff)) else: - print(table_name+', OK') + # print(table_name+', OK') mw.execShell("echo 'ok' > "+table_check_file) # inconsistent_table = ['xx.xx'] From 700b9a7c6198a738a3df9d8b6cd158f6a8a766fd Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 13:53:30 +0800 Subject: [PATCH 094/327] Update index.py --- plugins/mysql/index.py | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 19b7563ce..cbf10cf57 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3020,30 +3020,17 @@ def dumpMysqlData(version=''): ############### --- 重要 数据补足同步 ---- ########### -def syncDatabaseRepair(version=''): - from pymysql.converters import escape_string - args = getArgs() - data = checkArgs(args, ['db','sign']) - if not data[0]: - return data[1] - - sync_args_db = args['db'] - sync_args_sign = args['sign'] +def getSyncMysqlDB(dbname,sign = ''): conn = pSqliteDb('slave_sync_user') - if sync_args_sign != '': + if sign != '': data = conn.field('ip,port,user,pass,mode,cmd').where('ip=?', (sync_sign,)).find() else: data = conn.field('ip,port,user,pass,mode,cmd').find() - # print(data) user = data['user'] apass = data['pass'] port = data['port'] ip = data['ip'] - - # 本地数据 - local_db = pMysqlDb() - # 远程数据 sync_db = mw.getMyORM() # MySQLdb | @@ -3051,7 +3038,24 @@ def syncDatabaseRepair(version=''): sync_db.setHost(ip) sync_db.setUser(user) sync_db.setPwd(apass) - sync_db.setDbName(sync_args_db) + sync_db.setDbName(dbname) + return sync_db + + +def syncDatabaseRepair(version=''): + from pymysql.converters import escape_string + args = getArgs() + data = checkArgs(args, ['db','sign']) + if not data[0]: + return data[1] + + sync_args_db = args['db'] + sync_args_sign = args['sign'] + + # 本地数据 + local_db = pMysqlDb() + # 远程数据 + sync_db = getSyncMysqlDB(sync_args_db,sync_args_sign) tables = local_db.query('show tables from `%s`' % sync_args_db) table_key = "Tables_in_" + sync_args_db @@ -3088,6 +3092,8 @@ def syncDatabaseRepair(version=''): is_break = False while not is_break: local_db = pMysqlDb() + # 远程数据 + sync_db = getSyncMysqlDB(sync_args_db,sync_args_sign) print("check table:"+table_name) table_name_pos = 0 table_name_pos_file = tmp_dir+'/'+table_name+'.pos.txt' From faca0b183e2121f8a9046786257f11c2667b1451 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 13:59:59 +0800 Subject: [PATCH 095/327] update --- class/plugin/orm.py | 7 +++++++ plugins/mysql/index.py | 9 +++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/class/plugin/orm.py b/class/plugin/orm.py index 34a5605e4..8fa55c94f 100755 --- a/class/plugin/orm.py +++ b/class/plugin/orm.py @@ -108,6 +108,13 @@ class ORM: except Exception as ex: return ex + def ping(self): + try: + self.__DB_CONN.ping() + except Exception as e: + print(e) + return True + def query(self, sql): # 执行SQL语句返回数据集 if not self.__Conn(): diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index cbf10cf57..7490ad67c 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3023,10 +3023,10 @@ def dumpMysqlData(version=''): def getSyncMysqlDB(dbname,sign = ''): conn = pSqliteDb('slave_sync_user') if sign != '': - data = conn.field('ip,port,user,pass,mode,cmd').where('ip=?', (sync_sign,)).find() + data = conn.field('ip,port,user,pass,mode,cmd').where('ip=?', (sign,)).find() else: data = conn.field('ip,port,user,pass,mode,cmd').find() - # print(data) + print(data) user = data['user'] apass = data['pass'] port = data['port'] @@ -3091,9 +3091,10 @@ def syncDatabaseRepair(version=''): for table_name in inconsistent_table: is_break = False while not is_break: - local_db = pMysqlDb() + local_db.ping() # 远程数据 - sync_db = getSyncMysqlDB(sync_args_db,sync_args_sign) + sync_db.ping() + print("check table:"+table_name) table_name_pos = 0 table_name_pos_file = tmp_dir+'/'+table_name+'.pos.txt' From 7bff08b3e5a4f67a23a04028481c086d4df33348 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 14:02:10 +0800 Subject: [PATCH 096/327] Update index.py --- plugins/mysql/index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 7490ad67c..b1e2708ec 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3083,7 +3083,7 @@ def syncDatabaseRepair(version=''): diff = sync_count_data[0]['num'] - local_count_data[0]['num'] print(table_name+', need sync. diff,'+str(diff)) else: - # print(table_name+', OK') + print('.') mw.execShell("echo 'ok' > "+table_check_file) # inconsistent_table = ['xx.xx'] @@ -3094,7 +3094,7 @@ def syncDatabaseRepair(version=''): local_db.ping() # 远程数据 sync_db.ping() - + print("check table:"+table_name) table_name_pos = 0 table_name_pos_file = tmp_dir+'/'+table_name+'.pos.txt' From ee99d14df3ccd93cb9b785e46f5f9af426f76ed4 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 14:03:41 +0800 Subject: [PATCH 097/327] Update index.py --- plugins/mysql/index.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index b1e2708ec..c86a084d0 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3182,17 +3182,11 @@ def syncDatabaseRepair(version=''): print(update_sql) r = local_db.execute(update_sql) print(r) - - - - # print(local_select_data) - # print(sync_select_data) - if is_break: print("break all") break time.sleep(3) - print(inconsistent_table) + print("data supplementation completed") mw.execShell('rm -rf '+tmp_dir) return True From de15101a76fdc48f65ec8b2f318beb699f9b91ca Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 14:06:17 +0800 Subject: [PATCH 098/327] Update orm.py --- class/plugin/orm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/class/plugin/orm.py b/class/plugin/orm.py index 8fa55c94f..3f776322e 100755 --- a/class/plugin/orm.py +++ b/class/plugin/orm.py @@ -30,7 +30,7 @@ class ORM: try: self.__DB_CONN = pymysql.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS, database=self.__DB_NAME, - port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1, + port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=5, cursorclass=pymysql.cursors.DictCursor) except Exception as e: self.__DB_HOST = '127.0.0.1' From 1da8f6bbb639bf9b7ed30cd4423209ee927811d8 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 14:21:43 +0800 Subject: [PATCH 099/327] update --- class/plugin/orm.py | 18 +++++++++++------- plugins/mysql/index.py | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/class/plugin/orm.py b/class/plugin/orm.py index 3f776322e..a1852451d 100755 --- a/class/plugin/orm.py +++ b/class/plugin/orm.py @@ -17,6 +17,7 @@ class ORM: __DB_CUR = None __DB_ERR = None __DB_CNF = '/etc/my.cnf' + __DB_TIMEOUT=1 __DB_SOCKET = '/www/server/mysql/mysql.sock' __DB_CHARSET = "utf8" @@ -30,37 +31,36 @@ class ORM: try: self.__DB_CONN = pymysql.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS, database=self.__DB_NAME, - port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=5, + port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=self.__DB_TIMEOUT, cursorclass=pymysql.cursors.DictCursor) except Exception as e: - self.__DB_HOST = '127.0.0.1' self.__DB_CONN = pymysql.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS, database=self.__DB_NAME, - port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1, + port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=self.__DB_TIMEOUT, cursorclass=pymysql.cursors.DictCursor) elif os.path.exists(self.__DB_SOCKET): try: self.__DB_CONN = pymysql.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS, database=self.__DB_NAME, - port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1, + port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=self.__DB_TIMEOUT, unix_socket=self.__DB_SOCKET, cursorclass=pymysql.cursors.DictCursor) except Exception as e: self.__DB_HOST = '127.0.0.1' self.__DB_CONN = pymysql.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS, database=self.__DB_NAME, - port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1, + port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=self.__DB_TIMEOUT, unix_socket=self.__DB_SOCKET, cursorclass=pymysql.cursors.DictCursor) else: try: self.__DB_CONN = pymysql.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS, database=self.__DB_NAME, - port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1, + port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=self.__DB_TIMEOUT, cursorclass=pymysql.cursors.DictCursor) except Exception as e: self.__DB_HOST = '127.0.0.1' self.__DB_CONN = pymysql.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS, database=self.__DB_NAME, - port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1, + port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=self.__DB_TIMEOUT, cursorclass=pymysql.cursors.DictCursor) self.__DB_CUR = self.__DB_CONN.cursor() @@ -93,6 +93,10 @@ class ORM: def getPwd(self): return self.__DB_PASS + def setTimeout(self, timeout = 1): + self.__DB_TIMEOUT = timeout + return True + def setDbName(self, name): self.__DB_NAME = name diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index c86a084d0..60dc2990b 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3039,9 +3039,9 @@ def getSyncMysqlDB(dbname,sign = ''): sync_db.setUser(user) sync_db.setPwd(apass) sync_db.setDbName(dbname) + sync_db.setTimeout(60) return sync_db - def syncDatabaseRepair(version=''): from pymysql.converters import escape_string args = getArgs() From bbc0dee2b60503ed19938e66f7b9bf7bf9bb97ad Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 14:28:23 +0800 Subject: [PATCH 100/327] Update index.py --- plugins/mysql/index.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 60dc2990b..e20b47be1 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3104,11 +3104,15 @@ def syncDatabaseRepair(version=''): if os.path.exists(table_name_pos_file): table_name_pos = mw.readFile(table_name_pos_file) - + + data_select_sql = 'select * from '+table_name + ' where '+pkey_name+' > '+str(table_name_pos)+' limit 10000' print(data_select_sql) local_select_data = local_db.query(data_select_sql) + + time_s = time.time() sync_select_data = sync_db.query(data_select_sql) + print(f'sync query cos:{time.time() - time_s:.4f}s') # print(local_select_data) # print(sync_select_data) From 5535d563045ed14c680fb182d7151b2997af52ed Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 14:30:56 +0800 Subject: [PATCH 101/327] 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 e20b47be1..00b8e1a4c 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3123,7 +3123,9 @@ def syncDatabaseRepair(version=''): cmd_count_sql = 'select count(*) as num from '+table_name local_count_data = local_db.query(cmd_count_sql) + time_s = time.time() sync_count_data = sync_db.query(cmd_count_sql) + print(f'sync count data cos:{time.time() - time_s:.4f}s') print(local_count_data,sync_count_data) # if local_count_data[0]['num'] == sync_count_data[0]['num']: # is_break = True From 6b6e1f415fdcc46b0990a1365a918f9f15a5d60d Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 14:40:33 +0800 Subject: [PATCH 102/327] Update index.py --- plugins/mysql/index.py | 81 +++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 00b8e1a4c..37b346cd8 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3127,9 +3127,9 @@ def syncDatabaseRepair(version=''): sync_count_data = sync_db.query(cmd_count_sql) print(f'sync count data cos:{time.time() - time_s:.4f}s') print(local_count_data,sync_count_data) - # if local_count_data[0]['num'] == sync_count_data[0]['num']: - # is_break = True - # break + if local_count_data[0]['num'] == sync_count_data[0]['num']: + is_break = True + break diff = sync_count_data[0]['num'] - local_count_data[0]['num'] print("diff," + str(diff)+' line data!') @@ -3149,45 +3149,44 @@ def syncDatabaseRepair(version=''): print('progress,%.2f' % progress+'%') mw.writeFile(table_name_pos_file, str(pos)) else: - if len(sync_select_data) == 0: - continue - for idx in range(len(sync_select_data)): - insert_data = sync_select_data[idx] - # print(insert_data) - local_inquery_sql = 'select '+pkey_name+' from ' + table_name+ ' where ' +pkey_name+' = '+ str(insert_data[pkey_name]) - # print(local_inquery_sql) - tdata = local_db.query(local_inquery_sql) - # print(tdata) - if len(tdata) == 0: - print("id:"+ str(insert_data[pkey_name])+ " no exists, insert") - insert_sql = 'insert into ' + table_name - field_str = '' - value_str = '' - for field in insert_data: - field_str += '`'+field+'`,' - value_str += '\''+escape_string(str(insert_data[field]))+'\',' - field_str = '(' +field_str.strip(',')+')' - value_str = '(' +value_str.strip(',')+')' - insert_sql = insert_sql+' '+field_str+' values'+value_str+';' - print(insert_sql) - r = local_db.execute(insert_sql) - print(r) - else: - if sync_select_data[idx] == local_select_data[idx]: - continue - print("id:"+ str(insert_data[pkey_name])+ " data is not equal, update") - update_sql = 'update ' + table_name - field_str = '' - value_str = '' - for field in insert_data: - if field == pkey_name: + if len(sync_select_data) != 0: + for idx in range(len(sync_select_data)): + insert_data = sync_select_data[idx] + # print(insert_data) + local_inquery_sql = 'select '+pkey_name+' from ' + table_name+ ' where ' +pkey_name+' = '+ str(insert_data[pkey_name]) + # print(local_inquery_sql) + tdata = local_db.query(local_inquery_sql) + # print(tdata) + if len(tdata) == 0: + print("id:"+ str(insert_data[pkey_name])+ " no exists, insert") + insert_sql = 'insert into ' + table_name + field_str = '' + value_str = '' + for field in insert_data: + field_str += '`'+field+'`,' + value_str += '\''+escape_string(str(insert_data[field]))+'\',' + field_str = '(' +field_str.strip(',')+')' + value_str = '(' +value_str.strip(',')+')' + insert_sql = insert_sql+' '+field_str+' values'+value_str+';' + # print(insert_sql) + r = local_db.execute(insert_sql) + print(r) + else: + if sync_select_data[idx] == local_select_data[idx]: continue - field_str += '`'+field+'`=\''+escape_string(str(insert_data[field]))+'\',' - field_str = field_str.strip(',') - update_sql = update_sql+' set '+field_str+' where '+pkey_name+'=\''+str(insert_data[pkey_name])+'\';' - print(update_sql) - r = local_db.execute(update_sql) - print(r) + print("id:"+ str(insert_data[pkey_name])+ " data is not equal, update") + update_sql = 'update ' + table_name + field_str = '' + value_str = '' + for field in insert_data: + if field == pkey_name: + continue + field_str += '`'+field+'`=\''+escape_string(str(insert_data[field]))+'\',' + field_str = field_str.strip(',') + update_sql = update_sql+' set '+field_str+' where '+pkey_name+'=\''+str(insert_data[pkey_name])+'\';' + # print(update_sql) + r = local_db.execute(update_sql) + print(r) if is_break: print("break all") break From bf121ee6f85f7614f8d7194933112898030142ca Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 14:41:19 +0800 Subject: [PATCH 103/327] Update index.py --- plugins/mysql/index.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 37b346cd8..3b79b83d7 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3127,6 +3127,7 @@ def syncDatabaseRepair(version=''): sync_count_data = sync_db.query(cmd_count_sql) print(f'sync count data cos:{time.time() - time_s:.4f}s') print(local_count_data,sync_count_data) + # 数据同步有延迟,相等即任务数据补足完成 if local_count_data[0]['num'] == sync_count_data[0]['num']: is_break = True break From 1da749aea93fdd2c2d6f9bb86d79b3bbcc2d52fd Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 14:45:23 +0800 Subject: [PATCH 104/327] Update index.py --- plugins/mysql/index.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 3b79b83d7..2b615ced4 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3026,7 +3026,6 @@ def getSyncMysqlDB(dbname,sign = ''): data = conn.field('ip,port,user,pass,mode,cmd').where('ip=?', (sign,)).find() else: data = conn.field('ip,port,user,pass,mode,cmd').find() - print(data) user = data['user'] apass = data['pass'] port = data['port'] From 1a48e880d0d5185c3dab924e037e071037c62860 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 17:29:02 +0800 Subject: [PATCH 105/327] update --- plugins/mysql/index.py | 38 +++++++++++++++++- plugins/mysql/js/mysql.js | 81 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 116 insertions(+), 3 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 2b615ced4..c9a7dee50 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3041,7 +3041,38 @@ def getSyncMysqlDB(dbname,sign = ''): sync_db.setTimeout(60) return sync_db +def syncDatabaseRepairLog(version=''): + args = getArgs() + data = checkArgs(args, ['db','sign','op']) + if not data[0]: + return data[1] + + sync_args_db = args['db'] + sync_args_sign = args['sign'] + op = args['op'] + tmp_log = '/tmp/t.log' + cmd = 'cd '+mw.getServerDir()+'/mdserver-web && source bin/activate && python3 plugins/mysql/index.py sync_database_repair {"db":"'+sync_args_db+'","sign":"'+sync_args_sign+'"}' + # print(cmd) + + if op == 'get': + log = mw.getLastLine(tmp_log, 50) + return mw.returnJson(True, log) + + if op == 'cmd': + return mw.returnJson(True, 'ok', cmd) + + if op == 'do': + os.system(' echo "开始执行" > '+ tmp_log) + os.system(cmd +' >> '+ tmp_log +' &') + time.sleep(10) + # mw.execShell('rm -rf '+tmp_log) + return mw.returnJson(True, 'ok') + + return mw.returnJson(False, '无效请求!') + + def syncDatabaseRepair(version=''): + time_stats_s = time.time() from pymysql.converters import escape_string args = getArgs() data = checkArgs(args, ['db','sign']) @@ -3082,7 +3113,7 @@ def syncDatabaseRepair(version=''): diff = sync_count_data[0]['num'] - local_count_data[0]['num'] print(table_name+', need sync. diff,'+str(diff)) else: - print('.') + print(table_name+' check ok.') mw.execShell("echo 'ok' > "+table_check_file) # inconsistent_table = ['xx.xx'] @@ -3191,9 +3222,10 @@ def syncDatabaseRepair(version=''): print("break all") break time.sleep(3) + print(f'data check cos:{time.time() - time_stats_s:.4f}s') print("data supplementation completed") mw.execShell('rm -rf '+tmp_dir) - return True + return 'ok' ############### --- 重要 同步---- ########### @@ -3696,5 +3728,7 @@ if __name__ == "__main__": print(dumpMysqlData(version)) elif func == 'sync_database_repair': print(syncDatabaseRepair()) + elif func == 'sync_database_repair_log': + print(syncDatabaseRepairLog()) else: print('error') diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index 1ccb51c8a..32aaa922e 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -2028,6 +2028,84 @@ function getFullSyncStatus(db){ } } +function dataSyncVerify(db){ + var reqTimer = null; + + function requestLogs(layerIndex){ + myPostN('sync_database_repair_log', {db:db, sign:'',op:'get'}, function(rdata){ + var rdata = $.parseJSON(rdata.data); + + if(!rdata.status) { + layer.close(layerIndex); + layer.msg(rdata.msg,{icon:2, time:2000}); + clearInterval(reqTimer); + return; + }; + + if (rdata.msg == ''){ + rdata.msg = '暂无数据!'; + } + + $("#data_verify_log").html(rdata.msg); + //滚动到最低 + var ob = document.getElementById('data_verify_log'); + ob.scrollTop = ob.scrollHeight; + }); + } + + layer.open({ + type: 1, + title: '同步数据库['+db+']数据校验', + area: '500px', + btn:[ "开始","取消","手动"], + content:"
\ + "+'
'+"\
+            
", + cancel: function(){ + if (reqTimer){ + clearInterval(reqTimer); + } + }, + yes:function(index,layer_index){ + myPostN('sync_database_repair_log', {db:db, sign:'',op:'do'}, function(data){}); + layer.msg("执行成功"); + + requestLogs(layer_index); + reqTimer = setInterval(function(){ + requestLogs(layer_index); + },3000); + }, + success:function(){ + }, + btn3: function(){ + myPostN('sync_database_repair_log', {db:db, sign:'',op:'cmd'}, function(rdata){ + var rdata = $.parseJSON(rdata.data); + layer.open({ + title: "手动执行命令CMD", + area: ['600px', '180px'], + type:1, + closeBtn: 1, + shadeClose: false, + btn:["复制","取消"], + content: '
\ +
\ +
'+rdata.data+'
\ +
\ +
', + success:function(){ + copyText(rdata.data); + }, + yes:function(){ + copyText(rdata.data); + } + }); + }); + return false; + } + + }); +} + function addSlaveSSH(ip=''){ myPost('get_slave_ssh_by_ip', {ip:ip}, function(rdata){ @@ -2692,7 +2770,8 @@ function masterOrSlaveConf(version=''){ list += '
'; list += ''; list += ''; } From 05992b5f829d12d6184e7001e0e33cd475c401a9 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 17:31:49 +0800 Subject: [PATCH 106/327] 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 c9a7dee50..461eec92c 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3055,7 +3055,7 @@ def syncDatabaseRepairLog(version=''): # print(cmd) if op == 'get': - log = mw.getLastLine(tmp_log, 50) + log = mw.getLastLine(tmp_log, 17) return mw.returnJson(True, log) if op == 'cmd': From aa6748c09d9039cb33bd62ab4fadcf571313cce2 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 17:32:11 +0800 Subject: [PATCH 107/327] 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 461eec92c..ab5ab037e 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3055,7 +3055,7 @@ def syncDatabaseRepairLog(version=''): # print(cmd) if op == 'get': - log = mw.getLastLine(tmp_log, 17) + log = mw.getLastLine(tmp_log, 16) return mw.returnJson(True, log) if op == 'cmd': From 85adb449c2a87e958263d2a30c226200e3e8fd98 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 17:38:49 +0800 Subject: [PATCH 108/327] Update index.py --- plugins/mysql/index.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index ab5ab037e..1416b5292 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3041,7 +3041,12 @@ def getSyncMysqlDB(dbname,sign = ''): sync_db.setTimeout(60) return sync_db +def syncDatabaseRepairTempFile(): + tmp_log = '/tmp/t.log' + return tmp_log + def syncDatabaseRepairLog(version=''): + import subprocess args = getArgs() data = checkArgs(args, ['db','sign','op']) if not data[0]: @@ -3050,12 +3055,12 @@ def syncDatabaseRepairLog(version=''): sync_args_db = args['db'] sync_args_sign = args['sign'] op = args['op'] - tmp_log = '/tmp/t.log' + tmp_log = syncDatabaseRepairTempFile() cmd = 'cd '+mw.getServerDir()+'/mdserver-web && source bin/activate && python3 plugins/mysql/index.py sync_database_repair {"db":"'+sync_args_db+'","sign":"'+sync_args_sign+'"}' # print(cmd) if op == 'get': - log = mw.getLastLine(tmp_log, 16) + log = mw.getLastLine(tmp_log, 15) return mw.returnJson(True, log) if op == 'cmd': @@ -3063,7 +3068,7 @@ def syncDatabaseRepairLog(version=''): if op == 'do': os.system(' echo "开始执行" > '+ tmp_log) - os.system(cmd +' >> '+ tmp_log +' &') + subprocess.Popen(cmd +' >> '+ tmp_log +' &') time.sleep(10) # mw.execShell('rm -rf '+tmp_log) return mw.returnJson(True, 'ok') @@ -3073,6 +3078,8 @@ def syncDatabaseRepairLog(version=''): def syncDatabaseRepair(version=''): time_stats_s = time.time() + tmp_log = syncDatabaseRepairTempFile() + from pymysql.converters import escape_string args = getArgs() data = checkArgs(args, ['db','sign']) @@ -3114,8 +3121,10 @@ def syncDatabaseRepair(version=''): print(table_name+', need sync. diff,'+str(diff)) else: print(table_name+' check ok.') + mw.writeFile(tmp_log, table_name+' check ok.\n','a+') mw.execShell("echo 'ok' > "+table_check_file) + # inconsistent_table = ['xx.xx'] # 数据对齐 for table_name in inconsistent_table: From 500ccff90b0f624feb48f9fe2c2cd04e402a5024 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 17:48:41 +0800 Subject: [PATCH 109/327] update --- class/core/mw.py | 3 ++- plugins/mysql/index.py | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/class/core/mw.py b/class/core/mw.py index b54ad11dd..e88a3f57e 100755 --- a/class/core/mw.py +++ b/class/core/mw.py @@ -79,10 +79,11 @@ def getRootDir(): def getPluginDir(): return getRunDir() + '/plugins' - def getPanelDataDir(): return getRunDir() + '/data' +def getMWLogs(): + return getRunDir() + '/logs' def getPanelTmp(): return getRunDir() + '/tmp' diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 1416b5292..85b319a70 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3042,7 +3042,7 @@ def getSyncMysqlDB(dbname,sign = ''): return sync_db def syncDatabaseRepairTempFile(): - tmp_log = '/tmp/t.log' + tmp_log = mw.getMWLogs()+ '/mysql-check.log' return tmp_log def syncDatabaseRepairLog(version=''): @@ -3069,7 +3069,7 @@ def syncDatabaseRepairLog(version=''): if op == 'do': os.system(' echo "开始执行" > '+ tmp_log) subprocess.Popen(cmd +' >> '+ tmp_log +' &') - time.sleep(10) + # time.sleep(10) # mw.execShell('rm -rf '+tmp_log) return mw.returnJson(True, 'ok') @@ -3119,6 +3119,7 @@ def syncDatabaseRepair(version=''): inconsistent_table.append(table_name) diff = sync_count_data[0]['num'] - local_count_data[0]['num'] print(table_name+', need sync. diff,'+str(diff)) + mw.writeFile(tmp_log, table_name+', need sync. diff,'+str(diff)+'\n','a+') else: print(table_name+' check ok.') mw.writeFile(tmp_log, table_name+' check ok.\n','a+') @@ -3135,6 +3136,7 @@ def syncDatabaseRepair(version=''): sync_db.ping() print("check table:"+table_name) + mw.writeFile(tmp_log, "check table:"+table_name+'\n','a+') table_name_pos = 0 table_name_pos_file = tmp_dir+'/'+table_name+'.pos.txt' primary_key_sql = "SHOW INDEX FROM "+table_name+" WHERE Key_name = 'PRIMARY';"; @@ -3152,6 +3154,7 @@ def syncDatabaseRepair(version=''): time_s = time.time() sync_select_data = sync_db.query(data_select_sql) print(f'sync query cos:{time.time() - time_s:.4f}s') + mw.writeFile(tmp_log, f'sync query cos:{time.time() - time_s:.4f}s\n','a+') # print(local_select_data) # print(sync_select_data) From 8685f21ad94f2b5a039de8947503d4ea6d67796f Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 18:50:52 +0800 Subject: [PATCH 110/327] Update index.py --- plugins/mysql/index.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 85b319a70..77950c841 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -2349,7 +2349,7 @@ def addMasterRepSlaveUser(version=''): if isError != None: return isError - sql_select = "grant select,lock tables,PROCESS on *.* to " + username + "@'%';" + sql_select = "grant select,REPLICATION CLIENT,PROCESS on *.* to " + username + "@'%';" pdb.execute(sql_select) pdb.execute('FLUSH PRIVILEGES;') @@ -3298,6 +3298,8 @@ def doFullSyncUser(version=''): port = data['port'] ip = data['ip'] + sync_mdb = getSyncMysqlDB(sync_db,sync_sign) + bak_file = '/tmp/tmp.sql' if os.path.exists(bak_file): os.system("rm -rf " + bak_file) @@ -3355,6 +3357,15 @@ def doFullSyncUser(version=''): print(my_import_cmd) mw.execShell(my_import_cmd) + # 重设同步信息 + master_info = sync_mdb.query('show master status') + print(master_info) + if len(master_info)>0: + change_cmd = "CHANGE MASTER TO MASTER_LOG_FILE='"+master_info[0]['File']+"', MASTER_LOG_POS="+str(master_info[0]['Position'])+" channel 'r1711438835';" + print(change_cmd) + r = db.execute(change_cmd) + print(r) + if version == '8.0': db.query("start slave user='{}' password='{}';".format(user, apass)) else: From 5a64835969b238832d90643c31b4ea17058c8222 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 18:56:00 +0800 Subject: [PATCH 111/327] Update index.py --- plugins/mysql/index.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 77950c841..07579a2be 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3334,7 +3334,7 @@ def doFullSyncUser(version=''): dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --single-transaction --default-character-set=utf8mb4 -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file print(dump_sql_data) - mw.execShell(dump_sql_data) + # mw.execShell(dump_sql_data) writeDbSyncStatus({'code': 3, 'msg': '正在到本地导入数据中...', 'progress': 40}) @@ -3355,13 +3355,16 @@ def doFullSyncUser(version=''): my_import_cmd = getServerDir() + '/bin/mysql -S ' + sock + " -uroot -p'" + pwd + \ "' " + sync_db_import + ' < ' + bak_file print(my_import_cmd) - mw.execShell(my_import_cmd) + # mw.execShell(my_import_cmd) - # 重设同步信息 + # 修改同步位置 master_info = sync_mdb.query('show master status') - print(master_info) + slave_info = db.query('show slave status') + # print(master_info) + # print(slave_info) if len(master_info)>0: - change_cmd = "CHANGE MASTER TO MASTER_LOG_FILE='"+master_info[0]['File']+"', MASTER_LOG_POS="+str(master_info[0]['Position'])+" channel 'r1711438835';" + channel_name = slave_info[0]['Channel_Name'] + change_cmd = "CHANGE MASTER TO MASTER_LOG_FILE='"+master_info[0]['File']+"', MASTER_LOG_POS="+str(master_info[0]['Position'])+" for channel '"+channel_name+"';" print(change_cmd) r = db.execute(change_cmd) print(r) From 9475dbecfe619b7e0c4a82b055b36dd5209846b2 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 18:56:38 +0800 Subject: [PATCH 112/327] Update index.py --- plugins/mysql/index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 07579a2be..1161407d5 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3334,7 +3334,7 @@ def doFullSyncUser(version=''): dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --single-transaction --default-character-set=utf8mb4 -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file print(dump_sql_data) - # mw.execShell(dump_sql_data) + mw.execShell(dump_sql_data) writeDbSyncStatus({'code': 3, 'msg': '正在到本地导入数据中...', 'progress': 40}) @@ -3355,7 +3355,7 @@ def doFullSyncUser(version=''): my_import_cmd = getServerDir() + '/bin/mysql -S ' + sock + " -uroot -p'" + pwd + \ "' " + sync_db_import + ' < ' + bak_file print(my_import_cmd) - # mw.execShell(my_import_cmd) + mw.execShell(my_import_cmd) # 修改同步位置 master_info = sync_mdb.query('show master status') From 5b9b03a1532a066ed5c1ceef310596a33b51025e Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 19:09:01 +0800 Subject: [PATCH 113/327] Update index.py --- plugins/mysql/index.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 1161407d5..e98aa54fb 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3265,6 +3265,7 @@ def doFullSync(version=''): def doFullSyncUser(version=''): + time_s = time.time() args = getArgs() data = checkArgs(args, ['db', 'sign']) if not data[0]: @@ -3378,6 +3379,9 @@ def doFullSyncUser(version=''): if os.path.exists(bak_file): os.system("rm -rf " + bak_file) + + time_e = time.time() + print("cos:", time_e - time_s) return True From 952a173535b73ec07ab4a83d4e94bd9d2941ba46 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 19:11:28 +0800 Subject: [PATCH 114/327] 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 e98aa54fb..ef6324d1c 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3357,6 +3357,8 @@ def doFullSyncUser(version=''): "' " + sync_db_import + ' < ' + bak_file print(my_import_cmd) mw.execShell(my_import_cmd) + time_e = time.time() + print("export cos:", time_e - time_s) # 修改同步位置 master_info = sync_mdb.query('show master status') From 9ae61517a455e986715dbafb121b19eea1187501 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 19:20:02 +0800 Subject: [PATCH 115/327] Update index.py --- plugins/mysql/index.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index ef6324d1c..79e21855f 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3361,16 +3361,14 @@ def doFullSyncUser(version=''): print("export cos:", time_e - time_s) # 修改同步位置 - master_info = sync_mdb.query('show master status') - slave_info = db.query('show slave status') - # print(master_info) - # print(slave_info) - if len(master_info)>0: - channel_name = slave_info[0]['Channel_Name'] - change_cmd = "CHANGE MASTER TO MASTER_LOG_FILE='"+master_info[0]['File']+"', MASTER_LOG_POS="+str(master_info[0]['Position'])+" for channel '"+channel_name+"';" - print(change_cmd) - r = db.execute(change_cmd) - print(r) + # master_info = sync_mdb.query('show master status') + # slave_info = db.query('show slave status') + # if len(master_info)>0: + # channel_name = slave_info[0]['Channel_Name'] + # change_cmd = "CHANGE MASTER TO MASTER_LOG_FILE='"+master_info[0]['File']+"', MASTER_LOG_POS="+str(master_info[0]['Position'])+" for channel '"+channel_name+"';" + # print(change_cmd) + # r = db.execute(change_cmd) + # print(r) if version == '8.0': db.query("start slave user='{}' password='{}';".format(user, apass)) From 4c9e717559d0650217f1e6bd7bc27b3529ac603c Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 19:30:04 +0800 Subject: [PATCH 116/327] Update index.py --- plugins/mysql/index.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 79e21855f..1533f2b1f 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -2395,9 +2395,15 @@ def getMasterRepSlaveUserCmd(version): channel_name = " for channel 'r{}';".format(sid) if mode == "gtid": + # sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \ + # clist[0]['username'] + "', MASTER_PASSWORD='" + \ + # clist[0]['password'] + "', MASTER_AUTO_POSITION=1" + channel_name sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \ - clist[0]['username'] + "', MASTER_PASSWORD='" + \ - clist[0]['password'] + "', MASTER_AUTO_POSITION=1" + channel_name + clist[0]['username'] + "', MASTER_PASSWORD='" + \ + clist[0]['password'] + \ + "', MASTER_LOG_FILE='" + mstatus[0]["File"] + \ + "',MASTER_LOG_POS=" + str(mstatus[0]["Position"]) + channel_name + if version == '8.0': sql = "CHANGE REPLICATION SOURCE TO SOURCE_HOST='" + ip + "', SOURCE_PORT=" + port + ", SOURCE_USER='" + \ clist[0]['username'] + "', SOURCE_PASSWORD='" + \ From 76229b6651597c066b6d0522bf735f8c28be02eb Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 19:31:30 +0800 Subject: [PATCH 117/327] Update index.py --- plugins/mysql/index.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 1533f2b1f..8386f16cb 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -2403,8 +2403,8 @@ def getMasterRepSlaveUserCmd(version): clist[0]['password'] + \ "', MASTER_LOG_FILE='" + mstatus[0]["File"] + \ "',MASTER_LOG_POS=" + str(mstatus[0]["Position"]) + channel_name - - if version == '8.0': + + if version == '8.0' or version == '8.1' or version == '8.2' or version == '8.3': sql = "CHANGE REPLICATION SOURCE TO SOURCE_HOST='" + ip + "', SOURCE_PORT=" + port + ", SOURCE_USER='" + \ clist[0]['username'] + "', SOURCE_PASSWORD='" + \ clist[0]['password'] + \ @@ -2416,7 +2416,7 @@ def getMasterRepSlaveUserCmd(version): "', MASTER_LOG_FILE='" + mstatus[0]["File"] + \ "',MASTER_LOG_POS=" + str(mstatus[0]["Position"]) + channel_name - if version == "8.0": + if version == '8.0' or version == '8.1' or version == '8.2' or version == '8.3': sql = "CHANGE REPLICATION SOURCE TO SOURCE_HOST='" + ip + "', SOURCE_PORT=" + port + ", SOURCE_USER='" + \ clist[0]['username'] + "', SOURCE_PASSWORD='" + \ clist[0]['password'] + \ From 1069fd5252739a131d6c23962b9b62456620f361 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 19:33:53 +0800 Subject: [PATCH 118/327] Update index.py --- plugins/mysql/index.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 8386f16cb..e8d8ef8e7 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -2394,6 +2394,7 @@ def getMasterRepSlaveUserCmd(version): if sid != '': channel_name = " for channel 'r{}';".format(sid) + mdb8 = ['8.0','8.1','8.2','8.3'] if mode == "gtid": # sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \ # clist[0]['username'] + "', MASTER_PASSWORD='" + \ @@ -2404,7 +2405,7 @@ def getMasterRepSlaveUserCmd(version): "', MASTER_LOG_FILE='" + mstatus[0]["File"] + \ "',MASTER_LOG_POS=" + str(mstatus[0]["Position"]) + channel_name - if version == '8.0' or version == '8.1' or version == '8.2' or version == '8.3': + if mw.inArray(mdb8,version): sql = "CHANGE REPLICATION SOURCE TO SOURCE_HOST='" + ip + "', SOURCE_PORT=" + port + ", SOURCE_USER='" + \ clist[0]['username'] + "', SOURCE_PASSWORD='" + \ clist[0]['password'] + \ @@ -2416,7 +2417,7 @@ def getMasterRepSlaveUserCmd(version): "', MASTER_LOG_FILE='" + mstatus[0]["File"] + \ "',MASTER_LOG_POS=" + str(mstatus[0]["Position"]) + channel_name - if version == '8.0' or version == '8.1' or version == '8.2' or version == '8.3': + if mw.inArray(mdb8,version): sql = "CHANGE REPLICATION SOURCE TO SOURCE_HOST='" + ip + "', SOURCE_PORT=" + port + ", SOURCE_USER='" + \ clist[0]['username'] + "', SOURCE_PASSWORD='" + \ clist[0]['password'] + \ From 5818fb46f127fd54460f198f5542bbabc2803771 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 19:36:15 +0800 Subject: [PATCH 119/327] Update mysql.js --- plugins/mysql/js/mysql.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index 32aaa922e..cb4548056 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -2309,10 +2309,10 @@ function addSlaveSyncUser(ip=''){ $('input[name="user"]').val(a['MASTER_USER']); $('input[name="pass"]').val(a['MASTER_PASSWORD']); - console.log(a['MASTER_AUTO_POSITION'],typeof(a['MASTER_AUTO_POSITION'])); - if (typeof(a['MASTER_AUTO_POSITION']) != 'undefined' ){ - $('input[name="mode"]').val('1'); - } + // console.log(a['MASTER_AUTO_POSITION'],typeof(a['MASTER_AUTO_POSITION'])); + // if (typeof(a['MASTER_AUTO_POSITION']) != 'undefined' ){ + // $('input[name="mode"]').val('1'); + // } }); }, yes:function(index){ From 1af9b1ddaa26a6127ed65d5ba7f5be4f802cefcf Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 19:59:35 +0800 Subject: [PATCH 120/327] Update index.py --- plugins/mysql/index.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index e8d8ef8e7..8f9fa59e4 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -2979,18 +2979,21 @@ def setSlaveStatus(version=''): return mw.returnJson(True, '设置成功!') - -def deleteSlave(version=''): - args = getArgs() +def deleteSlaveFunc(sign = ''): db = pMysqlDb() - if 'sign' in args: - sign = args['sign'] + if sign != '': db.query("stop slave for channel '{}'".format(sign)) db.query("reset slave all for channel '{}'".format(sign)) else: db.query('stop slave') db.query('reset slave all') +def deleteSlave(version=''): + args = getArgs() + sign = '' + if 'sign' in args: + sign = args['sign'] + deleteSlaveFunc(sign) return mw.returnJson(True, '删除成功!') @@ -3292,6 +3295,8 @@ def doFullSyncUser(version=''): sync_sign = args['sign'] db = pMysqlDb() + # 重置 + deleteSlaveFunc(sign) conn = pSqliteDb('slave_sync_user') if sync_sign != '': @@ -3305,6 +3310,7 @@ def doFullSyncUser(version=''): apass = data['pass'] port = data['port'] ip = data['ip'] + cmd = data['cmd'] sync_mdb = getSyncMysqlDB(sync_db,sync_sign) @@ -3376,12 +3382,16 @@ def doFullSyncUser(version=''): # print(change_cmd) # r = db.execute(change_cmd) # print(r) - + r = db.query(cmd) + print(r) + if version == '8.0': db.query("start slave user='{}' password='{}';".format(user, apass)) else: db.query("start slave") + + db.query("start all slaves") writeDbSyncStatus({'code': 6, 'msg': '从库重启完成...', 'progress': 100}) if os.path.exists(bak_file): From 454b03690803fe7a2f72fbe7fec40aef65b3164f Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 20:00:01 +0800 Subject: [PATCH 121/327] Update index.py --- plugins/mysql/index.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 8f9fa59e4..8313dc2e7 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3326,10 +3326,10 @@ def doFullSyncUser(version=''): time.sleep(1) writeDbSyncStatus({'code': 1, 'msg': '正在停止从库...', 'progress': 15}) - if version == '8.0': - db.query("stop slave user='{}' password='{}';".format(user, apass)) - else: - db.query("stop slave") + # if version == '8.0': + # db.query("stop slave user='{}' password='{}';".format(user, apass)) + # else: + # db.query("stop slave") time.sleep(2) From a3bd0c6bda50423a8fdd567a8341a3e4f11d5ed0 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 20:00:19 +0800 Subject: [PATCH 122/327] Update index.py --- plugins/mysql/index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 8313dc2e7..8b4ce2fc1 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3331,7 +3331,7 @@ def doFullSyncUser(version=''): # else: # db.query("stop slave") - time.sleep(2) + time.sleep(1) writeDbSyncStatus({'code': 2, 'msg': '远程导出数据...', 'progress': 20}) @@ -3384,7 +3384,7 @@ def doFullSyncUser(version=''): # print(r) r = db.query(cmd) print(r) - + if version == '8.0': db.query("start slave user='{}' password='{}';".format(user, apass)) else: From 3fada8166139d4d466327f7d3c4db997ccc2e2a4 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 20:00:36 +0800 Subject: [PATCH 123/327] Update index.py --- plugins/mysql/index.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 8b4ce2fc1..ae4e11cb8 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3320,9 +3320,9 @@ def doFullSyncUser(version=''): writeDbSyncStatus({'code': 0, 'msg': '开始同步...', 'progress': 0}) dmp_option = '' - # mode = recognizeDbMode() - # if mode == 'gtid': - # dmp_option = ' --set-gtid-purged=off ' + mode = recognizeDbMode() + if mode == 'gtid': + dmp_option = ' --set-gtid-purged=off ' time.sleep(1) writeDbSyncStatus({'code': 1, 'msg': '正在停止从库...', 'progress': 15}) From c5800763078c8c8afb964615c5f08754598650df Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 20:01:59 +0800 Subject: [PATCH 124/327] 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 ae4e11cb8..6ad495d23 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3296,7 +3296,7 @@ def doFullSyncUser(version=''): db = pMysqlDb() # 重置 - deleteSlaveFunc(sign) + deleteSlaveFunc(sync_sign) conn = pSqliteDb('slave_sync_user') if sync_sign != '': From 63d624d08492b808f7e481b957b35d8218919859 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 20:11:59 +0800 Subject: [PATCH 125/327] Update index.py --- plugins/mysql/index.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 6ad495d23..6d6e69b7d 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -2396,14 +2396,15 @@ def getMasterRepSlaveUserCmd(version): mdb8 = ['8.0','8.1','8.2','8.3'] if mode == "gtid": - # sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \ - # clist[0]['username'] + "', MASTER_PASSWORD='" + \ - # clist[0]['password'] + "', MASTER_AUTO_POSITION=1" + channel_name sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \ - clist[0]['username'] + "', MASTER_PASSWORD='" + \ - clist[0]['password'] + \ - "', MASTER_LOG_FILE='" + mstatus[0]["File"] + \ - "',MASTER_LOG_POS=" + str(mstatus[0]["Position"]) + channel_name + clist[0]['username'] + "', MASTER_PASSWORD='" + \ + clist[0]['password'] + "', MASTER_AUTO_POSITION=1" + channel_name + + # sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \ + # clist[0]['username'] + "', MASTER_PASSWORD='" + \ + # clist[0]['password'] + \ + # "', MASTER_LOG_FILE='" + mstatus[0]["File"] + \ + # "',MASTER_LOG_POS=" + str(mstatus[0]["Position"]) + channel_name if mw.inArray(mdb8,version): sql = "CHANGE REPLICATION SOURCE TO SOURCE_HOST='" + ip + "', SOURCE_PORT=" + port + ", SOURCE_USER='" + \ From 862ea95a775fc92f94bb12c5167d74a53714d743 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 20:22:58 +0800 Subject: [PATCH 126/327] Update index.py --- plugins/mysql/index.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 6d6e69b7d..60bb26617 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3321,9 +3321,9 @@ def doFullSyncUser(version=''): writeDbSyncStatus({'code': 0, 'msg': '开始同步...', 'progress': 0}) dmp_option = '' - mode = recognizeDbMode() - if mode == 'gtid': - dmp_option = ' --set-gtid-purged=off ' + # mode = recognizeDbMode() + # if mode == 'gtid': + # dmp_option = ' --set-gtid-purged=off ' time.sleep(1) writeDbSyncStatus({'code': 1, 'msg': '正在停止从库...', 'progress': 15}) From 3abed25d71ef95aae3e5e563ab7155469998b365 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 20:52:58 +0800 Subject: [PATCH 127/327] Update index.py --- plugins/mysql/index.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 60bb26617..e32d7b498 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -2396,15 +2396,15 @@ def getMasterRepSlaveUserCmd(version): mdb8 = ['8.0','8.1','8.2','8.3'] if mode == "gtid": - sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \ - clist[0]['username'] + "', MASTER_PASSWORD='" + \ - clist[0]['password'] + "', MASTER_AUTO_POSITION=1" + channel_name - # sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \ - # clist[0]['username'] + "', MASTER_PASSWORD='" + \ - # clist[0]['password'] + \ - # "', MASTER_LOG_FILE='" + mstatus[0]["File"] + \ - # "',MASTER_LOG_POS=" + str(mstatus[0]["Position"]) + channel_name + # clist[0]['username'] + "', MASTER_PASSWORD='" + \ + # clist[0]['password'] + "', MASTER_AUTO_POSITION=1" + channel_name + + sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \ + clist[0]['username'] + "', MASTER_PASSWORD='" + \ + clist[0]['password'] + \ + "', MASTER_LOG_FILE='" + mstatus[0]["File"] + \ + "',MASTER_LOG_POS=0" + channel_name if mw.inArray(mdb8,version): sql = "CHANGE REPLICATION SOURCE TO SOURCE_HOST='" + ip + "', SOURCE_PORT=" + port + ", SOURCE_USER='" + \ From 00008b657c313e9fcc5f18dd230196126aafcc9e Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 21:11:29 +0800 Subject: [PATCH 128/327] 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 e32d7b498..83a906551 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3383,6 +3383,8 @@ def doFullSyncUser(version=''): # print(change_cmd) # r = db.execute(change_cmd) # print(r) + + print(cmd) r = db.query(cmd) print(r) From d5864db956abc6d7612c24d698c92660239ac5ec Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 15 May 2024 23:56:52 +0800 Subject: [PATCH 129/327] update --- plugins/mysql/index.py | 4 +++- plugins/mysql/install.sh | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 83a906551..04cd9e57b 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -2777,6 +2777,7 @@ def initSlaveStatus(version=''): return mw.returnJson(False, 'MySQL未启动', []) mode_file = getSyncModeFile() + # print(mode_file) if not os.path.exists(mode_file): return mw.returnJson(False, '需要先设置同步配置') @@ -2864,8 +2865,9 @@ def initSlaveStatusSyncUser(version=''): pinfo = parseSlaveSyncCmd(cmd_sql) except Exception as e: return mw.returnJson(False, base_t + '->CMD同步命令不合规范!') - # print(u['cmd']) + # print(cmd_sql) t = pdb.query(cmd_sql) + # print(t) isError = isSqlError(t) if isError: return isError diff --git a/plugins/mysql/install.sh b/plugins/mysql/install.sh index de9ce8fa9..e1a545a02 100755 --- a/plugins/mysql/install.sh +++ b/plugins/mysql/install.sh @@ -8,7 +8,8 @@ export PATH # cd /www/server/mdserver-web/plugins/mysql && bash install.sh install 8.2 # cd /www/server/mdserver-web && source bin/activate && python3 plugins/mysql/index.py try_slave_sync_bugfix {} # cd /www/server/mdserver-web && python3 plugins/mysql/index.py do_full_sync {"db":"xxx","sign":"","begin":1} -# cd /www/server/mdserver-web && python3 plugins/mysql/index.py sync_database_repair {"db":"xxx","sign":""} +# cd /www/server/mdserver-web && python3 plugins/mysql/index.py sync_database_repair {"db":"xxx","sign":""} +# cd /www/server/mdserver-web && python3 plugins/mysql/index.py init_slave_status curPath=`pwd` rootPath=$(dirname "$curPath") rootPath=$(dirname "$rootPath") From 36c15411796a5a26cc8f83a26dfe726eda6082f9 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 16 May 2024 16:13:05 +0800 Subject: [PATCH 130/327] Update index.py --- plugins/mysql/index.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 04cd9e57b..243d4f245 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -2396,11 +2396,13 @@ def getMasterRepSlaveUserCmd(version): mdb8 = ['8.0','8.1','8.2','8.3'] if mode == "gtid": - # sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \ - # clist[0]['username'] + "', MASTER_PASSWORD='" + \ - # clist[0]['password'] + "', MASTER_AUTO_POSITION=1" + channel_name - sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \ + clist[0]['username'] + "', MASTER_PASSWORD='" + \ + clist[0]['password'] + "', MASTER_AUTO_POSITION=1" + channel_name + + sql += "
" + + sql += "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \ clist[0]['username'] + "', MASTER_PASSWORD='" + \ clist[0]['password'] + \ "', MASTER_LOG_FILE='" + mstatus[0]["File"] + \ From ea94fa21d56ca73ab5716b5e44933f3d2ccbb3aa Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 16 May 2024 16:14:51 +0800 Subject: [PATCH 131/327] Update index.py --- plugins/mysql/index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 243d4f245..038e60033 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -2400,8 +2400,8 @@ def getMasterRepSlaveUserCmd(version): clist[0]['username'] + "', MASTER_PASSWORD='" + \ clist[0]['password'] + "', MASTER_AUTO_POSITION=1" + channel_name - sql += "
" - + sql += "

" + sql += "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \ clist[0]['username'] + "', MASTER_PASSWORD='" + \ clist[0]['password'] + \ From b033bd1c73c6768ecb44f81464fc0a468c763af7 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 16 May 2024 16:17:04 +0800 Subject: [PATCH 132/327] 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 038e60033..56795297d 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -2394,7 +2394,7 @@ def getMasterRepSlaveUserCmd(version): if sid != '': channel_name = " for channel 'r{}';".format(sid) - mdb8 = ['8.0','8.1','8.2','8.3'] + mdb8 = ['8.0','8.1','8.2','8.3','8.4'] if mode == "gtid": sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \ clist[0]['username'] + "', MASTER_PASSWORD='" + \ From 362f5eb4271cd19f5af79c6850322732b81ffe4b Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 16 May 2024 16:28:07 +0800 Subject: [PATCH 133/327] Update index.py --- plugins/mysql/index.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 56795297d..a8ba837fa 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3350,7 +3350,7 @@ def doFullSyncUser(version=''): # --skip-opt --create-options if not os.path.exists(bak_file): # 不锁表导出 - dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --single-transaction --default-character-set=utf8mb4 -h" + ip + " -P" + \ + dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --single-transaction --master-data=2 --default-character-set=utf8mb4 -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file print(dump_sql_data) mw.execShell(dump_sql_data) @@ -3388,9 +3388,9 @@ def doFullSyncUser(version=''): # r = db.execute(change_cmd) # print(r) - print(cmd) - r = db.query(cmd) - print(r) + # print(cmd) + # r = db.query(cmd) + # print(r) if version == '8.0': db.query("start slave user='{}' password='{}';".format(user, apass)) From 681dfc96cb1454779df74a5d52d83a9a62ce3f87 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 16 May 2024 16:33:19 +0800 Subject: [PATCH 134/327] update --- plugins/mysql/index.py | 2 +- plugins/mysql/install.sh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index a8ba837fa..3390a177d 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -2349,7 +2349,7 @@ def addMasterRepSlaveUser(version=''): if isError != None: return isError - sql_select = "grant select,REPLICATION CLIENT,PROCESS on *.* to " + username + "@'%';" + sql_select = "grant select,reload,REPLICATION CLIENT,PROCESS on *.* to " + username + "@'%';" pdb.execute(sql_select) pdb.execute('FLUSH PRIVILEGES;') diff --git a/plugins/mysql/install.sh b/plugins/mysql/install.sh index e1a545a02..a902ff4eb 100755 --- a/plugins/mysql/install.sh +++ b/plugins/mysql/install.sh @@ -7,9 +7,9 @@ export PATH # cd /www/server/mdserver-web/plugins/mysql && bash install.sh install 8.2 # cd /www/server/mdserver-web && source bin/activate && python3 plugins/mysql/index.py try_slave_sync_bugfix {} -# cd /www/server/mdserver-web && python3 plugins/mysql/index.py do_full_sync {"db":"xxx","sign":"","begin":1} -# cd /www/server/mdserver-web && python3 plugins/mysql/index.py sync_database_repair {"db":"xxx","sign":""} -# cd /www/server/mdserver-web && python3 plugins/mysql/index.py init_slave_status +# cd /www/server/mdserver-web && source bin/activate && python3 plugins/mysql/index.py do_full_sync {"db":"xxx","sign":"","begin":1} +# cd /www/server/mdserver-web && source bin/activate && python3 plugins/mysql/index.py sync_database_repair {"db":"xxx","sign":""} +# cd /www/server/mdserver-web && source bin/activate && python3 plugins/mysql/index.py init_slave_status curPath=`pwd` rootPath=$(dirname "$curPath") rootPath=$(dirname "$rootPath") From fa2d5c690c83f54e7e1f5ffe0f64d56eeb09910f Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 16 May 2024 17:46:25 +0800 Subject: [PATCH 135/327] Update index.py --- plugins/mysql/index.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 3390a177d..e7e94341a 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3280,7 +3280,6 @@ def doFullSync(version=''): def doFullSyncUser(version=''): - time_s = time.time() args = getArgs() data = checkArgs(args, ['db', 'sign']) if not data[0]: @@ -3300,8 +3299,9 @@ def doFullSyncUser(version=''): sync_sign = args['sign'] db = pMysqlDb() + # 重置 - deleteSlaveFunc(sync_sign) + # deleteSlaveFunc(sync_sign) conn = pSqliteDb('slave_sync_user') if sync_sign != '': @@ -3331,10 +3331,10 @@ def doFullSyncUser(version=''): time.sleep(1) writeDbSyncStatus({'code': 1, 'msg': '正在停止从库...', 'progress': 15}) - # if version == '8.0': - # db.query("stop slave user='{}' password='{}';".format(user, apass)) - # else: - # db.query("stop slave") + if version == '8.0': + db.query("stop slave user='{}' password='{}';".format(user, apass)) + else: + db.query("stop slave") time.sleep(1) @@ -3350,10 +3350,14 @@ def doFullSyncUser(version=''): # --skip-opt --create-options if not os.path.exists(bak_file): # 不锁表导出 - dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --single-transaction --master-data=2 --default-character-set=utf8mb4 -h" + ip + " -P" + \ + dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --single-transaction --master-data=1 --compress --include-master-host-port --default-character-set=utf8mb4 -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file print(dump_sql_data) - mw.execShell(dump_sql_data) + time_s = time.time() + r = mw.execShell(dump_sql_data) + print(r) + time_e = time.time() + print("export cos:", time_e - time_s) writeDbSyncStatus({'code': 3, 'msg': '正在到本地导入数据中...', 'progress': 40}) @@ -3374,9 +3378,11 @@ def doFullSyncUser(version=''): my_import_cmd = getServerDir() + '/bin/mysql -S ' + sock + " -uroot -p'" + pwd + \ "' " + sync_db_import + ' < ' + bak_file print(my_import_cmd) - mw.execShell(my_import_cmd) + time_s = time.time() + r = mw.execShell(my_import_cmd) + print(r) time_e = time.time() - print("export cos:", time_e - time_s) + print("import cos:", time_e - time_s) # 修改同步位置 # master_info = sync_mdb.query('show master status') @@ -3401,8 +3407,8 @@ def doFullSyncUser(version=''): db.query("start all slaves") writeDbSyncStatus({'code': 6, 'msg': '从库重启完成...', 'progress': 100}) - if os.path.exists(bak_file): - os.system("rm -rf " + bak_file) + # if os.path.exists(bak_file): + # os.system("rm -rf " + bak_file) time_e = time.time() print("cos:", time_e - time_s) From 8bbfdbbf66f96bb4c81d3dbd516c8d9ae3984f82 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 16 May 2024 17:57:46 +0800 Subject: [PATCH 136/327] Update index.py --- plugins/mysql/index.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index e7e94341a..9e0fd3f53 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3325,9 +3325,9 @@ def doFullSyncUser(version=''): writeDbSyncStatus({'code': 0, 'msg': '开始同步...', 'progress': 0}) dmp_option = '' - # mode = recognizeDbMode() - # if mode == 'gtid': - # dmp_option = ' --set-gtid-purged=off ' + mode = recognizeDbMode() + if mode == 'gtid': + dmp_option = ' --set-gtid-purged=off ' time.sleep(1) writeDbSyncStatus({'code': 1, 'msg': '正在停止从库...', 'progress': 15}) @@ -3348,9 +3348,10 @@ def doFullSyncUser(version=''): # --force --opt --single-transaction # --skip-opt --create-options + # --master-data=1 if not os.path.exists(bak_file): # 不锁表导出 - dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --single-transaction --master-data=1 --compress --include-master-host-port --default-character-set=utf8mb4 -h" + ip + " -P" + \ + dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --single-transaction --master-data=1 --apply-slave-statements --compress --default-character-set=utf8mb4 -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file print(dump_sql_data) time_s = time.time() From 9046a09c0a504f553d7cdcf02d9494b349a786a4 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 16 May 2024 18:18:22 +0800 Subject: [PATCH 137/327] Update mysql.js --- plugins/mysql/js/mysql.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index cb4548056..74e0f6cdb 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -2618,6 +2618,8 @@ function masterOrSlaveConf(version=''){ if (isHasSign){ list += '
'; + } else { + list += ''; } list += ''; From 87b26a14dfc9693beb392555bcd88350a3091acf Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 16 May 2024 18:25:02 +0800 Subject: [PATCH 138/327] Update mysql.js --- plugins/mysql/js/mysql.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index 74e0f6cdb..523292339 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -2599,7 +2599,7 @@ function masterOrSlaveConf(version=''){ for(i in rdata.data){ var v = rdata.data[i]; - if ('Channel_Name' in v){ + if ('Channel_Name' in v && v['Channel_Name'] !=''){ isHasSign = true; } @@ -2618,8 +2618,6 @@ function masterOrSlaveConf(version=''){ if (isHasSign){ list += ''; - } else { - list += ''; } list += ''; From b3ceb03365bebcf021e7bd7dd62e7466e66ddf5a Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 16 May 2024 18:25:20 +0800 Subject: [PATCH 139/327] 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 9e0fd3f53..2e892e345 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3351,7 +3351,7 @@ def doFullSyncUser(version=''): # --master-data=1 if not os.path.exists(bak_file): # 不锁表导出 - dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --single-transaction --master-data=1 --apply-slave-statements --compress --default-character-set=utf8mb4 -h" + ip + " -P" + \ + dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --single-transaction --master-data=1 --apply-slave-statements --include-master-host-port --compress -E -R -q -c --default-character-set=utf8mb4 -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file print(dump_sql_data) time_s = time.time() From 6b3f50374a53e28eb87e603dfb41a2563239ac13 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 16 May 2024 18:32:59 +0800 Subject: [PATCH 140/327] Update index.py --- plugins/mysql/index.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 2e892e345..0377db9ce 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -2397,6 +2397,12 @@ def getMasterRepSlaveUserCmd(version): mdb8 = ['8.0','8.1','8.2','8.3','8.4'] if mode == "gtid": sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \ + clist[0]['username'] + "', MASTER_PASSWORD='" + \ + clist[0]['password'] + "'" + + sql += "

" + + sql += "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \ clist[0]['username'] + "', MASTER_PASSWORD='" + \ clist[0]['password'] + "', MASTER_AUTO_POSITION=1" + channel_name From d241ceea3e5bf5f7178560f350191ccae91e7569 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 16 May 2024 18:55:07 +0800 Subject: [PATCH 141/327] Update index.py --- plugins/mysql/index.py | 50 ++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 0377db9ce..1d4d5a8e1 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -2395,44 +2395,28 @@ def getMasterRepSlaveUserCmd(version): channel_name = " for channel 'r{}';".format(sid) mdb8 = ['8.0','8.1','8.2','8.3','8.4'] - if mode == "gtid": - sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \ - clist[0]['username'] + "', MASTER_PASSWORD='" + \ - clist[0]['password'] + "'" - - sql += "

" - - sql += "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \ - clist[0]['username'] + "', MASTER_PASSWORD='" + \ - clist[0]['password'] + "', MASTER_AUTO_POSITION=1" + channel_name + sql = '' + if not mw.inArray(mdb8,version): + base_sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \ + clist[0]['username'] + "', MASTER_PASSWORD='" + \ + clist[0]['password'] + "'" + sql += base_sql +';' + sql += "

" + sql += base_sql + ", MASTER_AUTO_POSITION=1" + channel_name sql += "

" - sql += "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \ - clist[0]['username'] + "', MASTER_PASSWORD='" + \ - clist[0]['password'] + \ - "', MASTER_LOG_FILE='" + mstatus[0]["File"] + \ - "',MASTER_LOG_POS=0" + channel_name - - if mw.inArray(mdb8,version): - sql = "CHANGE REPLICATION SOURCE TO SOURCE_HOST='" + ip + "', SOURCE_PORT=" + port + ", SOURCE_USER='" + \ - clist[0]['username'] + "', SOURCE_PASSWORD='" + \ - clist[0]['password'] + \ - "', MASTER_AUTO_POSITION=1" + channel_name + sql += base_sql + "', MASTER_LOG_FILE='" + mstatus[0]["File"] + "',MASTER_LOG_POS=" + str(mstatus[0]["Position"]) + channel_name else: - sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \ - clist[0]['username'] + "', MASTER_PASSWORD='" + \ - clist[0]['password'] + \ - "', MASTER_LOG_FILE='" + mstatus[0]["File"] + \ - "',MASTER_LOG_POS=" + str(mstatus[0]["Position"]) + channel_name - - if mw.inArray(mdb8,version): - sql = "CHANGE REPLICATION SOURCE TO SOURCE_HOST='" + ip + "', SOURCE_PORT=" + port + ", SOURCE_USER='" + \ + base_sql = "CHANGE REPLICATION SOURCE TO SOURCE_HOST='" + ip + "', SOURCE_PORT=" + port + ", SOURCE_USER='" + \ clist[0]['username'] + "', SOURCE_PASSWORD='" + \ - clist[0]['password'] + \ - "', SOURCE_LOG_FILE='" + mstatus[0]["File"] + \ - "',SOURCE_LOG_POS=" + \ - str(mstatus[0]["Position"]) + channel_name + clist[0]['password']+"'" + sql += base_sql +';' + sql += "

" + sql += base_sql + ", MASTER_AUTO_POSITION=1" + channel_name + sql += "

" + sql += base_sql + "', SOURCE_LOG_FILE='" + mstatus[0]["File"] + "',SOURCE_LOG_POS=" + str(mstatus[0]["Position"]) + channel_name + data = {} data['cmd'] = sql From 8ea3ac1a3ccb0b93f451273f3f20fb12866cff43 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 16 May 2024 19:04:21 +0800 Subject: [PATCH 142/327] Update index.py --- plugins/mysql/index.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 1d4d5a8e1..bb1dfb1cd 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3341,7 +3341,9 @@ def doFullSyncUser(version=''): # --master-data=1 if not os.path.exists(bak_file): # 不锁表导出 - dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --single-transaction --master-data=1 --apply-slave-statements --include-master-host-port --compress -E -R -q -c --default-character-set=utf8mb4 -h" + ip + " -P" + \ + dmp_option += "--master-data=1 --apply-slave-statements --include-master-host-port --compress -E -R -q -c --default-character-set=utf8mb4" + + dump_sql_data = getServerDir() + "/bin/mysqldump --single-transaction " + dmp_option + " -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file print(dump_sql_data) time_s = time.time() From f5edd83164e571d192f0c4e4172482ee0a2d0247 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 16 May 2024 19:04:38 +0800 Subject: [PATCH 143/327] Update index.py --- plugins/mysql/index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index bb1dfb1cd..e03ec0e45 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3341,9 +3341,9 @@ def doFullSyncUser(version=''): # --master-data=1 if not os.path.exists(bak_file): # 不锁表导出 - dmp_option += "--master-data=1 --apply-slave-statements --include-master-host-port --compress -E -R -q -c --default-character-set=utf8mb4" + dmp_option += "--master-data=1 --apply-slave-statements --include-master-host-port --compress -E -R -q -c " - dump_sql_data = getServerDir() + "/bin/mysqldump --single-transaction " + dmp_option + " -h" + ip + " -P" + \ + dump_sql_data = getServerDir() + "/bin/mysqldump --single-transaction --default-character-set=utf8mb4 " + dmp_option + " -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file print(dump_sql_data) time_s = time.time() From 7a7acd3a4d162b302e0fff05ccdd63cc195f3d7b Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 16 May 2024 19:39:45 +0800 Subject: [PATCH 144/327] Update index.py --- plugins/mysql/index.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index e03ec0e45..00a14f4ce 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3269,6 +3269,14 @@ def doFullSync(version=''): return doFullSyncUser(version) +def isSimpleSyncCmd(sql): + new_sql = sql.lower() + if new_sql.find('master_auto_position') > 0 and sql.find('channel') > 0: + return False + return True + + + def doFullSyncUser(version=''): args = getArgs() data = checkArgs(args, ['db', 'sign']) @@ -3342,6 +3350,8 @@ def doFullSyncUser(version=''): if not os.path.exists(bak_file): # 不锁表导出 dmp_option += "--master-data=1 --apply-slave-statements --include-master-host-port --compress -E -R -q -c " + if not isSimpleSyncCmd(cmd): + dmp_option = '' dump_sql_data = getServerDir() + "/bin/mysqldump --single-transaction --default-character-set=utf8mb4 " + dmp_option + " -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file From c212a3053637f006db867e1f5c427276290e5d03 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 16 May 2024 19:42:04 +0800 Subject: [PATCH 145/327] Update index.py --- plugins/mysql/index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 00a14f4ce..06a4823ab 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3349,11 +3349,11 @@ def doFullSyncUser(version=''): # --master-data=1 if not os.path.exists(bak_file): # 不锁表导出 - dmp_option += "--master-data=1 --apply-slave-statements --include-master-host-port --compress -E -R -q -c " + dmp_option += "--master-data=1 --apply-slave-statements --include-master-host-port -E -R -q -c " if not isSimpleSyncCmd(cmd): dmp_option = '' - dump_sql_data = getServerDir() + "/bin/mysqldump --single-transaction --default-character-set=utf8mb4 " + dmp_option + " -h" + ip + " -P" + \ + dump_sql_data = getServerDir() + "/bin/mysqldump --single-transaction --default-character-set=utf8mb4 --compress " + dmp_option + " -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file print(dump_sql_data) time_s = time.time() From fb7dbd69e5a59c834443470a2af15539719f47e7 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 16 May 2024 19:43:55 +0800 Subject: [PATCH 146/327] Update index.py --- plugins/mysql/index.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 06a4823ab..6ceda45d4 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3349,8 +3349,9 @@ def doFullSyncUser(version=''): # --master-data=1 if not os.path.exists(bak_file): # 不锁表导出 - dmp_option += "--master-data=1 --apply-slave-statements --include-master-host-port -E -R -q -c " - if not isSimpleSyncCmd(cmd): + if isSimpleSyncCmd(cmd): + dmp_option += " --master-data=1 --apply-slave-statements --include-master-host-port -E -R -q -c " + else: dmp_option = '' dump_sql_data = getServerDir() + "/bin/mysqldump --single-transaction --default-character-set=utf8mb4 --compress " + dmp_option + " -h" + ip + " -P" + \ From 08a2295cdc2bc90e7eb9b1e6ecedf8305405c528 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 16 May 2024 19:57:51 +0800 Subject: [PATCH 147/327] Update index.py --- plugins/mysql/index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 6ceda45d4..63c986447 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3350,11 +3350,11 @@ def doFullSyncUser(version=''): if not os.path.exists(bak_file): # 不锁表导出 if isSimpleSyncCmd(cmd): - dmp_option += " --master-data=1 --apply-slave-statements --include-master-host-port -E -R -q -c " + dmp_option += " --master-data=1 --apply-slave-statements --include-master-host-port " else: dmp_option = '' - dump_sql_data = getServerDir() + "/bin/mysqldump --single-transaction --default-character-set=utf8mb4 --compress " + dmp_option + " -h" + ip + " -P" + \ + dump_sql_data = getServerDir() + "/bin/mysqldump --single-transaction --default-character-set=utf8mb4 --compress -q " + dmp_option + " -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file print(dump_sql_data) time_s = time.time() From 59b4ec32a6d9edc3c10a6be409c9a832cdb06536 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 16 May 2024 19:58:22 +0800 Subject: [PATCH 148/327] 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 63c986447..2987063ac 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3354,7 +3354,7 @@ def doFullSyncUser(version=''): else: dmp_option = '' - dump_sql_data = getServerDir() + "/bin/mysqldump --single-transaction --default-character-set=utf8mb4 --compress -q " + dmp_option + " -h" + ip + " -P" + \ + dump_sql_data = getServerDir() + "/bin/mysqldump --single-transaction --default-character-set=utf8mb4 --compress -q --no-autocommit -e" + dmp_option + " -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file print(dump_sql_data) time_s = time.time() From 160634d3d4fb7315aacbda9208bbc140de2e3841 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 16 May 2024 20:09:21 +0800 Subject: [PATCH 149/327] 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 2987063ac..276f7cdf3 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3352,7 +3352,7 @@ def doFullSyncUser(version=''): if isSimpleSyncCmd(cmd): dmp_option += " --master-data=1 --apply-slave-statements --include-master-host-port " else: - dmp_option = '' + dmp_option += '' dump_sql_data = getServerDir() + "/bin/mysqldump --single-transaction --default-character-set=utf8mb4 --compress -q --no-autocommit -e" + dmp_option + " -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file From 01c9633a1b508afaa33d2bb62a11874e0d06c8b1 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 16 May 2024 20:32:22 +0800 Subject: [PATCH 150/327] 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 276f7cdf3..43bfe11bd 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3354,7 +3354,7 @@ def doFullSyncUser(version=''): else: dmp_option += '' - dump_sql_data = getServerDir() + "/bin/mysqldump --single-transaction --default-character-set=utf8mb4 --compress -q --no-autocommit -e" + dmp_option + " -h" + ip + " -P" + \ + dump_sql_data = getServerDir() + "/bin/mysqldump --single-transaction --default-character-set=utf8mb4 --compress -q" + dmp_option + " -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file print(dump_sql_data) time_s = time.time() From 8cfc5c5344e1d8b2e1f0a243b2b489078a9fa684 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 16 May 2024 21:09:10 +0800 Subject: [PATCH 151/327] Update stats.js --- plugins/webstats/js/stats.js | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/webstats/js/stats.js b/plugins/webstats/js/stats.js index 00294c6b6..76a967748 100644 --- a/plugins/webstats/js/stats.js +++ b/plugins/webstats/js/stats.js @@ -2076,6 +2076,7 @@ var html = '
\ \ \ \ + \ \ \ \ From 22b97ab255f39e41bcaa0d2a6378019393cf36b3 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 00:21:06 +0800 Subject: [PATCH 152/327] updatae --- plugins/mysql/index.py | 2 +- plugins/mysql/js/mysql.js | 8 +++++--- plugins/webstats/js/stats.js | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 43bfe11bd..c884c8de4 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -2843,7 +2843,7 @@ def initSlaveStatusSyncUser(version=''): if slave_t['mode'] == '1': mode_name = 'gtid' - + print(local_mode, mode_name) if local_mode != mode_name: msg += base_t + '->同步模式不一致' continue diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index 523292339..bc5bfcc70 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -2310,9 +2310,11 @@ function addSlaveSyncUser(ip=''){ $('input[name="pass"]').val(a['MASTER_PASSWORD']); // console.log(a['MASTER_AUTO_POSITION'],typeof(a['MASTER_AUTO_POSITION'])); - // if (typeof(a['MASTER_AUTO_POSITION']) != 'undefined' ){ - // $('input[name="mode"]').val('1'); - // } + if (typeof(a['MASTER_AUTO_POSITION']) != 'undefined' ){ + $('input[name="mode"]').val('1'); + } else{ + $('input[name="mode"]').val('0'); + } }); }, yes:function(index){ diff --git a/plugins/webstats/js/stats.js b/plugins/webstats/js/stats.js index 76a967748..caf90bfda 100644 --- a/plugins/webstats/js/stats.js +++ b/plugins/webstats/js/stats.js @@ -2076,12 +2076,12 @@ var html = '
\ \ \ \ - \ \ \ \ \ \ + \ \ 时间: \
\ From 8d4ffc431a17af30ef102d306c7661f85f2a3cb1 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 00:21:37 +0800 Subject: [PATCH 153/327] 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 c884c8de4..c6814157f 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -2843,7 +2843,7 @@ def initSlaveStatusSyncUser(version=''): if slave_t['mode'] == '1': mode_name = 'gtid' - print(local_mode, mode_name) + # print(local_mode, mode_name) if local_mode != mode_name: msg += base_t + '->同步模式不一致' continue From cfd3a070460da18a3117981b659ac6c7ee2df445 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 00:32:27 +0800 Subject: [PATCH 154/327] Update mysql.js --- plugins/mysql/js/mysql.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index bc5bfcc70..085706856 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -2261,7 +2261,7 @@ function addSlaveSyncUser(ip=''){ var index = layer.open({ type: 1, - area: ['500px','470px'], + area: ['500px','510px'], title: '同步账户', closeBtn: 1, shift: 5, @@ -2272,6 +2272,15 @@ function addSlaveSyncUser(ip=''){
端口
\
同步账户
\
同步密码
\ +
\ + 同步模式\ +
\ + \ +
\ +
\
\ CMD[必须填写]\
\ @@ -2308,13 +2317,6 @@ function addSlaveSyncUser(ip=''){ $('input[name="port"]').val(a['MASTER_PORT']); $('input[name="user"]').val(a['MASTER_USER']); $('input[name="pass"]').val(a['MASTER_PASSWORD']); - - // console.log(a['MASTER_AUTO_POSITION'],typeof(a['MASTER_AUTO_POSITION'])); - if (typeof(a['MASTER_AUTO_POSITION']) != 'undefined' ){ - $('input[name="mode"]').val('1'); - } else{ - $('input[name="mode"]').val('0'); - } }); }, yes:function(index){ @@ -2323,7 +2325,7 @@ function addSlaveSyncUser(ip=''){ var user = $('input[name="user"]').val(); var pass = $('input[name="pass"]').val(); var cmd = $('textarea[name="cmd"]').val(); - var mode = $('input[name="mode"]').val(); + var mode = $('select[name="mode"]').val(); var data = {ip:ip,port:port,cmd:cmd,user:user,pass:pass,mode:mode}; myPost('add_slave_sync_user', data, function(ret_data){ From edb26fd11cac92981a6537cf0396d0949a82e9cd Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 00:44:52 +0800 Subject: [PATCH 155/327] update --- route/static/app/index.js | 2 +- route/templates/default/layout.html | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/route/static/app/index.js b/route/static/app/index.js index de94a797e..d0f23f1e7 100755 --- a/route/static/app/index.js +++ b/route/static/app/index.js @@ -1427,7 +1427,7 @@ var index = { },'json'); }, task:function(){ - index.getData(); + // index.getData(); setInterval(function() { index.getData(); }, 3000); diff --git a/route/templates/default/layout.html b/route/templates/default/layout.html index 45881f842..e9596ed63 100755 --- a/route/templates/default/layout.html +++ b/route/templates/default/layout.html @@ -179,14 +179,28 @@ if (thisPath.indexOf('?')>-1){ {% endif %} {% endfor %} + + + - + \ No newline at end of file From 8cab94e26c1d9e3c94a3be59171e2fc408b37f9d Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 00:45:56 +0800 Subject: [PATCH 156/327] Update config_api.py --- class/core/config_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/class/core/config_api.py b/class/core/config_api.py index bdb75e932..5825c9c0c 100755 --- a/class/core/config_api.py +++ b/class/core/config_api.py @@ -28,7 +28,7 @@ from flask import request class config_api: - __version = '0.16.8.1' + __version = '0.16.8.2' __api_addr = 'data/api.json' # 统一默认配置文件 From e944c9fbc52a1fae752851a695cca237a06225c6 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 01:01:16 +0800 Subject: [PATCH 157/327] Update layout.html --- route/templates/default/layout.html | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/route/templates/default/layout.html b/route/templates/default/layout.html index e9596ed63..ca7f8b8bc 100755 --- a/route/templates/default/layout.html +++ b/route/templates/default/layout.html @@ -182,14 +182,18 @@ if (thisPath.indexOf('?')>-1){ From 5d0b8b18771f4b62f43a74d79ccd9b3586184e90 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 01:01:48 +0800 Subject: [PATCH 158/327] Update layout.html --- route/templates/default/layout.html | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/route/templates/default/layout.html b/route/templates/default/layout.html index ca7f8b8bc..b8994f6d1 100755 --- a/route/templates/default/layout.html +++ b/route/templates/default/layout.html @@ -182,9 +182,7 @@ if (thisPath.indexOf('?')>-1){ From 56c1cd88ee89f32778392089ca7e14e0b67b0549 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 01:02:36 +0800 Subject: [PATCH 159/327] Update config_api.py --- class/core/config_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/class/core/config_api.py b/class/core/config_api.py index 5825c9c0c..15d33a730 100755 --- a/class/core/config_api.py +++ b/class/core/config_api.py @@ -28,7 +28,7 @@ from flask import request class config_api: - __version = '0.16.8.2' + __version = '0.16.8.3' __api_addr = 'data/api.json' # 统一默认配置文件 From 7f707f9aac6835a47a4e1f3c3878822bdf2f99bb Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 01:08:13 +0800 Subject: [PATCH 160/327] Update index.py --- plugins/mysql/index.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index c6814157f..aa4cfb8d6 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3347,6 +3347,7 @@ def doFullSyncUser(version=''): # --force --opt --single-transaction # --skip-opt --create-options # --master-data=1 + time_s = time.time() if not os.path.exists(bak_file): # 不锁表导出 if isSimpleSyncCmd(cmd): @@ -3360,10 +3361,11 @@ def doFullSyncUser(version=''): time_s = time.time() r = mw.execShell(dump_sql_data) print(r) - time_e = time.time() - print("export cos:", time_e - time_s) + time_e = time.time() + export_cos = time_e - time_s + print("export cos:", export_cos) - writeDbSyncStatus({'code': 3, 'msg': '正在到本地导入数据中...', 'progress': 40}) + writeDbSyncStatus({'code': 3, 'msg': '导出耗时:'+str(export_cos)+',正在到本地导入数据中...', 'progress': 40}) if os.path.exists(bak_file): # 重置 From 6128186a2cda1c920ba3cdee1b2de6d575410be7 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 01:26:35 +0800 Subject: [PATCH 161/327] Update index.py --- plugins/mysql/index.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index aa4cfb8d6..1e13d64ed 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3278,6 +3278,7 @@ def isSimpleSyncCmd(sql): def doFullSyncUser(version=''): + time_all_s = time.time() args = getArgs() data = checkArgs(args, ['db', 'sign']) if not data[0]: @@ -3416,8 +3417,8 @@ def doFullSyncUser(version=''): # if os.path.exists(bak_file): # os.system("rm -rf " + bak_file) - time_e = time.time() - print("cos:", time_e - time_s) + time_all_e = time.time() + print("cos:", time_all_e - time_all_s) return True From 8f4949cf8deb83a0334e343f565f627b57accf13 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 01:35:43 +0800 Subject: [PATCH 162/327] Update index.py --- plugins/mysql/index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 1e13d64ed..0d2b0d74f 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3216,7 +3216,7 @@ def syncDatabaseRepair(version=''): field_str = '(' +field_str.strip(',')+')' value_str = '(' +value_str.strip(',')+')' insert_sql = insert_sql+' '+field_str+' values'+value_str+';' - # print(insert_sql) + print(insert_sql) r = local_db.execute(insert_sql) print(r) else: @@ -3232,7 +3232,7 @@ def syncDatabaseRepair(version=''): field_str += '`'+field+'`=\''+escape_string(str(insert_data[field]))+'\',' field_str = field_str.strip(',') update_sql = update_sql+' set '+field_str+' where '+pkey_name+'=\''+str(insert_data[pkey_name])+'\';' - # print(update_sql) + print(update_sql) r = local_db.execute(update_sql) print(r) if is_break: From 1f8dbe1a5f5a1cbf2afa8443cbe147e77f4279f2 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 01:37:54 +0800 Subject: [PATCH 163/327] 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 0d2b0d74f..2bb56b85c 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3204,7 +3204,7 @@ def syncDatabaseRepair(version=''): local_inquery_sql = 'select '+pkey_name+' from ' + table_name+ ' where ' +pkey_name+' = '+ str(insert_data[pkey_name]) # print(local_inquery_sql) tdata = local_db.query(local_inquery_sql) - # print(tdata) + print(tdata) if len(tdata) == 0: print("id:"+ str(insert_data[pkey_name])+ " no exists, insert") insert_sql = 'insert into ' + table_name From de02bcd800db5ec28b3517591f7a81e7b8295f17 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 01:39:46 +0800 Subject: [PATCH 164/327] Update index.py --- plugins/mysql/index.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 2bb56b85c..a00a47f73 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3220,6 +3220,7 @@ def syncDatabaseRepair(version=''): r = local_db.execute(insert_sql) print(r) else: + print("compare: ",sync_select_data[idx], local_select_data[idx]) if sync_select_data[idx] == local_select_data[idx]: continue print("id:"+ str(insert_data[pkey_name])+ " data is not equal, update") From d9f657c236cc2b1aef2f2a84ccf7cd44213a2d8e Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 01:42:05 +0800 Subject: [PATCH 165/327] Update index.py --- plugins/mysql/index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index a00a47f73..b454dcfb4 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3203,8 +3203,8 @@ def syncDatabaseRepair(version=''): # print(insert_data) local_inquery_sql = 'select '+pkey_name+' from ' + table_name+ ' where ' +pkey_name+' = '+ str(insert_data[pkey_name]) # print(local_inquery_sql) - tdata = local_db.query(local_inquery_sql) - print(tdata) + ldata = local_db.query(local_inquery_sql) + print('ldata:',ldata) if len(tdata) == 0: print("id:"+ str(insert_data[pkey_name])+ " no exists, insert") insert_sql = 'insert into ' + table_name From b0d8d4bef8c1671cc6495486999ee9efe868ed28 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 01:43:19 +0800 Subject: [PATCH 166/327] 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 b454dcfb4..759ace24d 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3205,7 +3205,7 @@ def syncDatabaseRepair(version=''): # print(local_inquery_sql) ldata = local_db.query(local_inquery_sql) print('ldata:',ldata) - if len(tdata) == 0: + if len(ldata) == 0: print("id:"+ str(insert_data[pkey_name])+ " no exists, insert") insert_sql = 'insert into ' + table_name field_str = '' From a65d42ed2e02dba50b30d9773a6033b7fa5e319a Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 01:43:57 +0800 Subject: [PATCH 167/327] 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 759ace24d..e59bf34d9 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3201,7 +3201,7 @@ def syncDatabaseRepair(version=''): for idx in range(len(sync_select_data)): insert_data = sync_select_data[idx] # print(insert_data) - local_inquery_sql = 'select '+pkey_name+' from ' + table_name+ ' where ' +pkey_name+' = '+ str(insert_data[pkey_name]) + local_inquery_sql = 'select * from ' + table_name+ ' where ' +pkey_name+' = '+ str(insert_data[pkey_name]) # print(local_inquery_sql) ldata = local_db.query(local_inquery_sql) print('ldata:',ldata) From 608b40a110dc3c6353b1106f51d65cd39fcb4ac4 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 01:46:17 +0800 Subject: [PATCH 168/327] Update index.py --- plugins/mysql/index.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index e59bf34d9..0bb688fca 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3199,9 +3199,9 @@ def syncDatabaseRepair(version=''): else: if len(sync_select_data) != 0: for idx in range(len(sync_select_data)): - insert_data = sync_select_data[idx] + sync_insert_data = sync_select_data[idx] # print(insert_data) - local_inquery_sql = 'select * from ' + table_name+ ' where ' +pkey_name+' = '+ str(insert_data[pkey_name]) + local_inquery_sql = 'select * from ' + table_name+ ' where ' +pkey_name+' = '+ str(sync_insert_data[pkey_name]) # print(local_inquery_sql) ldata = local_db.query(local_inquery_sql) print('ldata:',ldata) @@ -3221,7 +3221,7 @@ def syncDatabaseRepair(version=''): print(r) else: print("compare: ",sync_select_data[idx], local_select_data[idx]) - if sync_select_data[idx] == local_select_data[idx]: + if ldata[0] == sync_insert_data: continue print("id:"+ str(insert_data[pkey_name])+ " data is not equal, update") update_sql = 'update ' + table_name From cd2655a6f9ee53f6a638068cfd9be78d6ac08c94 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 01:47:40 +0800 Subject: [PATCH 169/327] Update index.py --- plugins/mysql/index.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 0bb688fca..f1589f7ac 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3206,13 +3206,13 @@ def syncDatabaseRepair(version=''): ldata = local_db.query(local_inquery_sql) print('ldata:',ldata) if len(ldata) == 0: - print("id:"+ str(insert_data[pkey_name])+ " no exists, insert") + print("id:"+ str(sync_insert_data[pkey_name])+ " no exists, insert") insert_sql = 'insert into ' + table_name field_str = '' value_str = '' - for field in insert_data: + for field in sync_insert_data: field_str += '`'+field+'`,' - value_str += '\''+escape_string(str(insert_data[field]))+'\',' + value_str += '\''+escape_string(str(sync_insert_data[field]))+'\',' field_str = '(' +field_str.strip(',')+')' value_str = '(' +value_str.strip(',')+')' insert_sql = insert_sql+' '+field_str+' values'+value_str+';' @@ -3227,12 +3227,12 @@ def syncDatabaseRepair(version=''): update_sql = 'update ' + table_name field_str = '' value_str = '' - for field in insert_data: + for field in sync_insert_data: if field == pkey_name: continue - field_str += '`'+field+'`=\''+escape_string(str(insert_data[field]))+'\',' + field_str += '`'+field+'`=\''+escape_string(str(sync_insert_data[field]))+'\',' field_str = field_str.strip(',') - update_sql = update_sql+' set '+field_str+' where '+pkey_name+'=\''+str(insert_data[pkey_name])+'\';' + update_sql = update_sql+' set '+field_str+' where '+pkey_name+'=\''+str(sync_insert_data[pkey_name])+'\';' print(update_sql) r = local_db.execute(update_sql) print(r) From b570a4552a4d6ee69c5807a1f3b0bac723e93c3b Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 01:48:00 +0800 Subject: [PATCH 170/327] Update index.py --- plugins/mysql/index.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index f1589f7ac..5f2e9e104 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3199,20 +3199,20 @@ def syncDatabaseRepair(version=''): else: if len(sync_select_data) != 0: for idx in range(len(sync_select_data)): - sync_insert_data = sync_select_data[idx] + sync_idx_data = sync_select_data[idx] # print(insert_data) - local_inquery_sql = 'select * from ' + table_name+ ' where ' +pkey_name+' = '+ str(sync_insert_data[pkey_name]) + local_inquery_sql = 'select * from ' + table_name+ ' where ' +pkey_name+' = '+ str(sync_idx_data[pkey_name]) # print(local_inquery_sql) ldata = local_db.query(local_inquery_sql) print('ldata:',ldata) if len(ldata) == 0: - print("id:"+ str(sync_insert_data[pkey_name])+ " no exists, insert") + print("id:"+ str(sync_idx_data[pkey_name])+ " no exists, insert") insert_sql = 'insert into ' + table_name field_str = '' value_str = '' - for field in sync_insert_data: + for field in sync_idx_data: field_str += '`'+field+'`,' - value_str += '\''+escape_string(str(sync_insert_data[field]))+'\',' + value_str += '\''+escape_string(str(sync_idx_data[field]))+'\',' field_str = '(' +field_str.strip(',')+')' value_str = '(' +value_str.strip(',')+')' insert_sql = insert_sql+' '+field_str+' values'+value_str+';' @@ -3227,12 +3227,12 @@ def syncDatabaseRepair(version=''): update_sql = 'update ' + table_name field_str = '' value_str = '' - for field in sync_insert_data: + for field in sync_idx_data: if field == pkey_name: continue - field_str += '`'+field+'`=\''+escape_string(str(sync_insert_data[field]))+'\',' + field_str += '`'+field+'`=\''+escape_string(str(sync_idx_data[field]))+'\',' field_str = field_str.strip(',') - update_sql = update_sql+' set '+field_str+' where '+pkey_name+'=\''+str(sync_insert_data[pkey_name])+'\';' + update_sql = update_sql+' set '+field_str+' where '+pkey_name+'=\''+str(sync_idx_data[pkey_name])+'\';' print(update_sql) r = local_db.execute(update_sql) print(r) From 9964745e46f6a8040ccec44b4c0bed20b08933bc Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 01:49:11 +0800 Subject: [PATCH 171/327] Update index.py --- plugins/mysql/index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 5f2e9e104..7a7e40ab9 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3221,9 +3221,9 @@ def syncDatabaseRepair(version=''): print(r) else: print("compare: ",sync_select_data[idx], local_select_data[idx]) - if ldata[0] == sync_insert_data: + if ldata[0] == sync_idx_data: continue - print("id:"+ str(insert_data[pkey_name])+ " data is not equal, update") + print("id:"+ str(sync_idx_data[pkey_name])+ " data is not equal, update") update_sql = 'update ' + table_name field_str = '' value_str = '' From f6663ad370ffc7bdc84b0d1323d41cc8777dca85 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 03:18:59 +0800 Subject: [PATCH 172/327] Update index.py --- plugins/mysql/index.py | 56 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 7a7e40ab9..321e175b0 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3166,7 +3166,7 @@ def syncDatabaseRepair(version=''): # print(len(local_select_data)) # print(len(sync_select_data)) - print('local compare sync,',local_select_data == sync_select_data) + print('pos:',str(table_name_pos),'local compare sync,',local_select_data == sync_select_data) cmd_count_sql = 'select count(*) as num from '+table_name local_count_data = local_db.query(cmd_count_sql) @@ -3197,14 +3197,25 @@ def syncDatabaseRepair(version=''): print('progress,%.2f' % progress+'%') mw.writeFile(table_name_pos_file, str(pos)) else: - if len(sync_select_data) != 0: - for idx in range(len(sync_select_data)): + sync_select_data_len = len(sync_select_data) + skip_idx = 0 + # 主库PK -> 查询本地 | 保证一致 + if sync_select_data_len > 0: + for idx in range(sync_select_data_len): sync_idx_data = sync_select_data[idx] + local_idx_data = None + if idx in local_select_data: + local_idx_data = local_select_data[idx] + if sync_select_data[idx] == local_idx_data: + skip_idx = idx + pos = local_select_data[idx][pkey_name] + mw.writeFile(table_name_pos_file, str(pos)) + # print(insert_data) local_inquery_sql = 'select * from ' + table_name+ ' where ' +pkey_name+' = '+ str(sync_idx_data[pkey_name]) # print(local_inquery_sql) ldata = local_db.query(local_inquery_sql) - print('ldata:',ldata) + # print('ldata:',ldata) if len(ldata) == 0: print("id:"+ str(sync_idx_data[pkey_name])+ " no exists, insert") insert_sql = 'insert into ' + table_name @@ -3220,9 +3231,10 @@ def syncDatabaseRepair(version=''): r = local_db.execute(insert_sql) print(r) else: - print("compare: ",sync_select_data[idx], local_select_data[idx]) + # print('compare sync->local:',sync_idx_data == ldata[0] ) if ldata[0] == sync_idx_data: continue + print("id:"+ str(sync_idx_data[pkey_name])+ " data is not equal, update") update_sql = 'update ' + table_name field_str = '' @@ -3236,6 +3248,28 @@ def syncDatabaseRepair(version=''): print(update_sql) r = local_db.execute(update_sql) print(r) + + # 本地PK -> 查询主库 | 保证一致 + # local_select_data_len = len(local_select_data) + # if local_select_data_len > 0: + # for idx in range(local_select_data_len): + # if idx < skip_idx: + # continue + # local_idx_data = local_select_data[idx] + # print('local idx check', idx, skip_idx) + # local_inquery_sql = 'select * from ' + table_name+ ' where ' +pkey_name+' = '+ str(local_idx_data[pkey_name]) + # print(local_inquery_sql) + # sdata = sync_db.query(local_inquery_sql) + # sdata_len = len(sdata) + # print('sdata:',sdata,sdata_len) + # if sdata_len == 0: + # delete_sql = 'delete from ' + table_name + ' where ' +pkey_name+' = '+ str(local_idx_data[pkey_name]) + # print(delete_sql) + # r = local_db.execute(delete_sql) + # print(r) + # break + + if is_break: print("break all") break @@ -3367,8 +3401,9 @@ def doFullSyncUser(version=''): export_cos = time_e - time_s print("export cos:", export_cos) - writeDbSyncStatus({'code': 3, 'msg': '导出耗时:'+str(export_cos)+',正在到本地导入数据中...', 'progress': 40}) + writeDbSyncStatus({'code': 3, 'msg': '导出耗时:'+str(int(export_cos))+'秒,正在到本地导入数据中...', 'progress': 40}) + time_s = time.time() if os.path.exists(bak_file): # 重置 db.execute('reset master') @@ -3386,12 +3421,8 @@ def doFullSyncUser(version=''): my_import_cmd = getServerDir() + '/bin/mysql -S ' + sock + " -uroot -p'" + pwd + \ "' " + sync_db_import + ' < ' + bak_file print(my_import_cmd) - time_s = time.time() r = mw.execShell(my_import_cmd) print(r) - time_e = time.time() - print("import cos:", time_e - time_s) - # 修改同步位置 # master_info = sync_mdb.query('show master status') # slave_info = db.query('show slave status') @@ -3401,7 +3432,12 @@ def doFullSyncUser(version=''): # print(change_cmd) # r = db.execute(change_cmd) # print(r) + time_e = time.time() + import_cos = time_e - time_s + print("import cos:", import_cos) + writeDbSyncStatus({'code': 4, 'msg': '导入耗时:'+str(int(import_cos))+'秒', 'progress': 60}) + time.sleep(3) # print(cmd) # r = db.query(cmd) # print(r) From 8d9eb6302cdddba9a978a1bb2eb34b6e9f4a4d6d Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 03:20:29 +0800 Subject: [PATCH 173/327] Update index.py --- plugins/mysql/index.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 321e175b0..df9c4cf2f 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3449,13 +3449,13 @@ def doFullSyncUser(version=''): db.query("start all slaves") - writeDbSyncStatus({'code': 6, 'msg': '从库重启完成...', 'progress': 100}) - - # if os.path.exists(bak_file): - # os.system("rm -rf " + bak_file) - time_all_e = time.time() - print("cos:", time_all_e - time_all_s) + cos = time_all_e - time_all_s + writeDbSyncStatus({'code': 6, 'msg': '总耗时'+str(int(cos))+'从库重启完成...', 'progress': 100}) + + if os.path.exists(bak_file): + os.system("rm -rf " + bak_file) + return True From a679c0e90c8d74d88f57fe8d15ec4c7bec3c1137 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 03:26:37 +0800 Subject: [PATCH 174/327] Update index.py --- plugins/mysql/index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index df9c4cf2f..bfe3d52cc 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3451,11 +3451,11 @@ def doFullSyncUser(version=''): db.query("start all slaves") time_all_e = time.time() cos = time_all_e - time_all_s - writeDbSyncStatus({'code': 6, 'msg': '总耗时'+str(int(cos))+'从库重启完成...', 'progress': 100}) + writeDbSyncStatus({'code': 6, 'msg': '总耗时:'+str(int(cos))+'秒,从库重启完成...', 'progress': 100}) if os.path.exists(bak_file): os.system("rm -rf " + bak_file) - + return True From 848021a63928a64fd24affbafaf6137289f7db55 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 03:27:20 +0800 Subject: [PATCH 175/327] 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 bfe3d52cc..cf290ff05 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3389,7 +3389,7 @@ def doFullSyncUser(version=''): if isSimpleSyncCmd(cmd): dmp_option += " --master-data=1 --apply-slave-statements --include-master-host-port " else: - dmp_option += '' + dmp_option += ' --master-data=1 ' dump_sql_data = getServerDir() + "/bin/mysqldump --single-transaction --default-character-set=utf8mb4 --compress -q" + dmp_option + " -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file From 01e95fa6fbb77d87e0ab326a800091f1c42ca9c6 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 03:36:27 +0800 Subject: [PATCH 176/327] 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 cf290ff05..fe1331177 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3389,7 +3389,7 @@ def doFullSyncUser(version=''): if isSimpleSyncCmd(cmd): dmp_option += " --master-data=1 --apply-slave-statements --include-master-host-port " else: - dmp_option += ' --master-data=1 ' + dmp_option += ' ' dump_sql_data = getServerDir() + "/bin/mysqldump --single-transaction --default-character-set=utf8mb4 --compress -q" + dmp_option + " -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file From 310409c52baa202cc8c11f1a675e450eddc60637 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 04:06:01 +0800 Subject: [PATCH 177/327] Update mw.tpl --- scripts/init.d/mw.tpl | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/scripts/init.d/mw.tpl b/scripts/init.d/mw.tpl index 31a884391..f4d359047 100755 --- a/scripts/init.d/mw.tpl +++ b/scripts/init.d/mw.tpl @@ -258,7 +258,7 @@ mw_mirror() else bash <(curl --insecure -sSL https://gitee.com/SuperManito/LinuxMirrors/raw/main/ChangeMirrors.sh) fi - cd /www/server/mdserver-web + cd ${ROOT_PATH}/mdserver-web } mw_install_app() @@ -297,8 +297,8 @@ mw_debug(){ port=$(cat $mw_path/data/port.pl) fi - if [ -d /www/server/mdserver-web ];then - cd /www/server/mdserver-web + if [ -d ${ROOT_PATH}/mdserver-web ];then + cd ${ROOT_PATH}/mdserver-web fi gunicorn -b :$port -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 app:app } @@ -373,7 +373,8 @@ mw_connect_mysql(){ INPUT_KEY=${SOURCE_LIST_KEY[$INPUT]} CHOICE_DB=${DB_TYPE[$INPUT_KEY]} echo "login to ${CHOICE_DB}:" - pwd=$(cd /www/server/mdserver-web && python3 /www/server/mdserver-web/plugins/${CHOICE_DB}/index.py root_pwd) + + pwd=$(cd ${ROOT_PATH}/mdserver-web && python3 ${ROOT_PATH}/mdserver-web/plugins/${CHOICE_DB}/index.py root_pwd) if [ "$CHOICE_DB" == "mysql" ];then ${ROOT_PATH}/mysql/bin/mysql -uroot -p"${pwd}" fi @@ -393,14 +394,14 @@ mw_connect_mysql(){ } mw_venv(){ - cd /www/server/mdserver-web && source bin/activate + cd ${ROOT_PATH}/mdserver-web && source bin/activate } mw_clean_lib(){ - cd /www/server/mdserver-web && rm -rf lib - cd /www/server/mdserver-web && rm -rf lib64 - cd /www/server/mdserver-web && rm -rf bin - cd /www/server/mdserver-web && rm -rf include + cd ${ROOT_PATH}/mdserver-web && rm -rf lib + cd ${ROOT_PATH}/mdserver-web && rm -rf lib64 + cd ${ROOT_PATH}/mdserver-web && rm -rf bin + cd ${ROOT_PATH}/mdserver-web && rm -rf include } case "$1" in From 2b8804e9603cc209bdcb3702de86b3bf436b34b6 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 05:01:39 +0800 Subject: [PATCH 178/327] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/mysql/README.md | 13 +++++++++- plugins/mysql/index.py | 55 ++++++++++++++++++++++++++++++----------- 2 files changed, 53 insertions(+), 15 deletions(-) diff --git a/plugins/mysql/README.md b/plugins/mysql/README.md index 0427303eb..c3f3e59c1 100644 --- a/plugins/mysql/README.md +++ b/plugins/mysql/README.md @@ -1,4 +1,15 @@ +``` show global variables like '%gtid%'; +show global variables like 'server_uuid'; +``` -show global variables like 'server_uuid'; \ No newline at end of file +``` +# 不锁表,需要删除原来数据表 +# tables = db.query('show tables from `%s`' % sync_db_import) +# table_key = "Tables_in_" + sync_db_import +# for tname in tables: +# drop_db_cmd = 'drop table if exists '+sync_db_import+'.'+tname[table_key] +# # print(drop_db_cmd) +# db.query(drop_db_cmd) +``` \ No newline at end of file diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index fe1331177..079f04619 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3310,6 +3310,37 @@ def isSimpleSyncCmd(sql): return False return True +def getChannelNameForCmd(cmd): + cmd = cmd.lower() + cmd_arr = cmd.split('channel') + if len(cmd_arr) == 2: + cmd_channel_info = cmd_arr[1] + channel_name = cmd_channel_info.strip() + channel_name = channel_name.strip(';') + channel_name = channel_name.strip("'") + return channel_name + return '' + + +def doFullSyncUserImportContentForChannel(file, channel_name): + # print(file, channel_name) + content = mw.readFile(file) + + content = content.replace('STOP SLAVE;', "STOP SLAVE for channel '{}';".format(channel_name)) + content = content.replace('START SLAVE;', "START SLAVE for channel '{}';".format(channel_name)) + + find_head = "CHANGE MASTER TO " + find_re = find_head+"(.*?);" + find_r = re.search(find_re, content, re.I|re.M) + if find_r: + find_rg = find_r.groups() + if len(find_rg)>0: + find_str = find_head+find_rg[0] + if find_str.lower().find('channel')==-1: + content = content.replace(find_str+';', find_str+" for channel '{}';".format(channel_name)) + + mw.writeFile(file,content) + return True def doFullSyncUser(version=''): @@ -3350,12 +3381,13 @@ def doFullSyncUser(version=''): port = data['port'] ip = data['ip'] cmd = data['cmd'] + channel_name = getChannelNameForCmd(cmd) sync_mdb = getSyncMysqlDB(sync_db,sync_sign) bak_file = '/tmp/tmp.sql' - if os.path.exists(bak_file): - os.system("rm -rf " + bak_file) + # if os.path.exists(bak_file): + # os.system("rm -rf " + bak_file) writeDbSyncStatus({'code': 0, 'msg': '开始同步...', 'progress': 0}) dmp_option = '' @@ -3383,15 +3415,15 @@ def doFullSyncUser(version=''): # --force --opt --single-transaction # --skip-opt --create-options # --master-data=1 + time_s = time.time() if not os.path.exists(bak_file): - # 不锁表导出 if isSimpleSyncCmd(cmd): dmp_option += " --master-data=1 --apply-slave-statements --include-master-host-port " else: - dmp_option += ' ' + dmp_option += ' --master-data=1 --apply-slave-statements --include-master-host-port ' - dump_sql_data = getServerDir() + "/bin/mysqldump --single-transaction --default-character-set=utf8mb4 --compress -q" + dmp_option + " -h" + ip + " -P" + \ + dump_sql_data = getServerDir() + "/bin/mysqldump --single-transaction --default-character-set=utf8mb4 --compress -q " + dmp_option + " -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file print(dump_sql_data) time_s = time.time() @@ -3408,13 +3440,8 @@ def doFullSyncUser(version=''): # 重置 db.execute('reset master') - # 不锁表,需要删除原来数据表 - # tables = db.query('show tables from `%s`' % sync_db_import) - # table_key = "Tables_in_" + sync_db_import - # for tname in tables: - # drop_db_cmd = 'drop table if exists '+sync_db_import+'.'+tname[table_key] - # # print(drop_db_cmd) - # db.query(drop_db_cmd) + doFullSyncUserImportContentForChannel(bak_file, channel_name) + pwd = pSqliteDb('config').where('id=?', (1,)).getField('mysql_root') sock = getSocketFile() @@ -3453,8 +3480,8 @@ def doFullSyncUser(version=''): cos = time_all_e - time_all_s writeDbSyncStatus({'code': 6, 'msg': '总耗时:'+str(int(cos))+'秒,从库重启完成...', 'progress': 100}) - if os.path.exists(bak_file): - os.system("rm -rf " + bak_file) + # if os.path.exists(bak_file): + # os.system("rm -rf " + bak_file) return True From 572207105cd5775fb96eb7448baadebd76889193 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 05:04:18 +0800 Subject: [PATCH 179/327] Update index.py --- plugins/mysql/index.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 079f04619..609faec6e 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -2403,7 +2403,8 @@ def getMasterRepSlaveUserCmd(version): sql += base_sql +';' sql += "

" - sql += base_sql + ", MASTER_AUTO_POSITION=1" + channel_name + # sql += base_sql + ", MASTER_AUTO_POSITION=1" + channel_name + sql += base_sql + " " + channel_name sql += "

" sql += base_sql + "', MASTER_LOG_FILE='" + mstatus[0]["File"] + "',MASTER_LOG_POS=" + str(mstatus[0]["Position"]) + channel_name @@ -2413,7 +2414,8 @@ def getMasterRepSlaveUserCmd(version): clist[0]['password']+"'" sql += base_sql +';' sql += "

" - sql += base_sql + ", MASTER_AUTO_POSITION=1" + channel_name + # sql += base_sql + ", MASTER_AUTO_POSITION=1" + channel_name + sql += base_sql + " " + channel_name sql += "

" sql += base_sql + "', SOURCE_LOG_FILE='" + mstatus[0]["File"] + "',SOURCE_LOG_POS=" + str(mstatus[0]["Position"]) + channel_name From 2572bde607864c641eb3a2e8e5fd5954fbb61a58 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 05:05:06 +0800 Subject: [PATCH 180/327] Update index.py --- plugins/mysql/index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 609faec6e..acdad65df 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -2404,7 +2404,7 @@ def getMasterRepSlaveUserCmd(version): sql += base_sql +';' sql += "

" # sql += base_sql + ", MASTER_AUTO_POSITION=1" + channel_name - sql += base_sql + " " + channel_name + sql += base_sql + channel_name sql += "

" sql += base_sql + "', MASTER_LOG_FILE='" + mstatus[0]["File"] + "',MASTER_LOG_POS=" + str(mstatus[0]["Position"]) + channel_name @@ -2415,7 +2415,7 @@ def getMasterRepSlaveUserCmd(version): sql += base_sql +';' sql += "

" # sql += base_sql + ", MASTER_AUTO_POSITION=1" + channel_name - sql += base_sql + " " + channel_name + sql += base_sql + channel_name sql += "

" sql += base_sql + "', SOURCE_LOG_FILE='" + mstatus[0]["File"] + "',SOURCE_LOG_POS=" + str(mstatus[0]["Position"]) + channel_name From 9925daa363c9754155ae14d773dae83dca5be4da Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 05:08:45 +0800 Subject: [PATCH 181/327] Update index.py --- plugins/mysql/index.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index acdad65df..b77252960 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3388,8 +3388,8 @@ def doFullSyncUser(version=''): sync_mdb = getSyncMysqlDB(sync_db,sync_sign) bak_file = '/tmp/tmp.sql' - # if os.path.exists(bak_file): - # os.system("rm -rf " + bak_file) + if os.path.exists(bak_file): + os.system("rm -rf " + bak_file) writeDbSyncStatus({'code': 0, 'msg': '开始同步...', 'progress': 0}) dmp_option = '' @@ -3482,8 +3482,8 @@ def doFullSyncUser(version=''): cos = time_all_e - time_all_s writeDbSyncStatus({'code': 6, 'msg': '总耗时:'+str(int(cos))+'秒,从库重启完成...', 'progress': 100}) - # if os.path.exists(bak_file): - # os.system("rm -rf " + bak_file) + if os.path.exists(bak_file): + os.system("rm -rf " + bak_file) return True From 5f42f37ee284c55d76cc01b17df040ef9c668392 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 05:24:48 +0800 Subject: [PATCH 182/327] Update mysql.sql --- plugins/mysql/conf/mysql.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/mysql/conf/mysql.sql b/plugins/mysql/conf/mysql.sql index 8262a9ec2..f98ddf79b 100755 --- a/plugins/mysql/conf/mysql.sql +++ b/plugins/mysql/conf/mysql.sql @@ -50,7 +50,9 @@ CREATE TABLE IF NOT EXISTS `slave_sync_user` ( `pass` TEXT, `mode` TEXT, `cmd` TEXT, + `db` TEXT, `addtime` TEXT ); +ALTER TABLE `slave_sync_user` ADD COLUMN `db` TEXT DEFAULT ''; From 975a69fce84018d8abf2408f3c988116c206df27 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 13:35:13 +0800 Subject: [PATCH 183/327] Update layout.html --- route/templates/default/layout.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/route/templates/default/layout.html b/route/templates/default/layout.html index b8994f6d1..f86b59826 100755 --- a/route/templates/default/layout.html +++ b/route/templates/default/layout.html @@ -191,7 +191,7 @@ $(document).ready(function(){ gtag('js', new Date()); gtag('config', 'G-FC74BB2RGD'); }); - },500); + },3000); }); From 24750cfdb260c0baf0b22ceccd003b539ed27f7f Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 13:35:26 +0800 Subject: [PATCH 184/327] Update config_api.py --- class/core/config_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/class/core/config_api.py b/class/core/config_api.py index 15d33a730..fc4dbfb21 100755 --- a/class/core/config_api.py +++ b/class/core/config_api.py @@ -28,7 +28,7 @@ from flask import request class config_api: - __version = '0.16.8.3' + __version = '0.16.8.4' __api_addr = 'data/api.json' # 统一默认配置文件 From 030e05b2cfcf9a1bc57a85363002dfea42d5bd66 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 13:52:19 +0800 Subject: [PATCH 185/327] Update index.py --- plugins/mysql/index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index b77252960..9e1e20414 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3308,7 +3308,7 @@ def doFullSync(version=''): def isSimpleSyncCmd(sql): new_sql = sql.lower() - if new_sql.find('master_auto_position') > 0 and sql.find('channel') > 0: + if new_sql.find('master_auto_position') > 0: return False return True @@ -3423,7 +3423,7 @@ def doFullSyncUser(version=''): if isSimpleSyncCmd(cmd): dmp_option += " --master-data=1 --apply-slave-statements --include-master-host-port " else: - dmp_option += ' --master-data=1 --apply-slave-statements --include-master-host-port ' + dmp_option += ' ' dump_sql_data = getServerDir() + "/bin/mysqldump --single-transaction --default-character-set=utf8mb4 --compress -q " + dmp_option + " -h" + ip + " -P" + \ port + " -u" + user + " -p'" + apass + "' --ssl-mode=DISABLED " + sync_db + " > " + bak_file From 61e136fb39b2321978c68a69b36feff76bea4cd3 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 13:54:59 +0800 Subject: [PATCH 186/327] Update backup.py --- scripts/backup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/backup.py b/scripts/backup.py index e6bac68a2..313b95daa 100755 --- a/scripts/backup.py +++ b/scripts/backup.py @@ -159,7 +159,7 @@ class backupTools: # skip-opt 不会lock表 # --skip-opt --create-options - cmd = db_path + "/bin/mysqldump --defaults-file=" + my_cnf +" " + option +" --single-transaction --default-character-set=utf8 " + \ + cmd = db_path + "/bin/mysqldump --defaults-file=" + my_cnf +" " + option +" --single-transaction --compress -q --default-character-set=utf8mb4 " + \ name + " | gzip > " + filename # print(cmd) mw.execShell(cmd) From 07dc74c28329e896d78c764a5af1d5c1e4eb59a4 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 13:56:47 +0800 Subject: [PATCH 187/327] update --- plugins/mysql-apt/scripts/backup.py | 2 +- plugins/mysql-yum/scripts/backup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mysql-apt/scripts/backup.py b/plugins/mysql-apt/scripts/backup.py index 1098abc21..e779c0d6a 100755 --- a/plugins/mysql-apt/scripts/backup.py +++ b/plugins/mysql-apt/scripts/backup.py @@ -63,7 +63,7 @@ class backupTools: if len(mycnf) > 100: mw.writeFile(db_path + '/etc/my.cnf', mycnf) - cmd = db_path + "/bin/usr/bin/mysqldump --defaults-file=" + my_conf_path + " --single-transaction --quick --default-character-set=utf8 " + \ + cmd = db_path + "/bin/usr/bin/mysqldump --defaults-file=" + my_conf_path + " --single-transaction --compress -q --default-character-set=utf8 " + \ name + " | gzip > " + filename mw.execShell(cmd) diff --git a/plugins/mysql-yum/scripts/backup.py b/plugins/mysql-yum/scripts/backup.py index d1d7f32be..99b0caff7 100755 --- a/plugins/mysql-yum/scripts/backup.py +++ b/plugins/mysql-yum/scripts/backup.py @@ -65,7 +65,7 @@ class backupTools: if len(content) > 100: mw.writeFile(my_cnf, content) - cmd = db_path + "/bin/usr/bin/mysqldump --defaults-file=" + my_cnf + " --single-transaction --quick --default-character-set=utf8 " + \ + cmd = db_path + "/bin/usr/bin/mysqldump --defaults-file=" + my_cnf + " --single-transaction --compress -q --default-character-set=utf8 " + \ name + " | gzip > " + filename mw.execShell(cmd) From 908b1cf684894f09e04c15ac5d51273ef4f71e7c Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 14:05:25 +0800 Subject: [PATCH 188/327] Update backup.py --- scripts/backup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/backup.py b/scripts/backup.py index 313b95daa..799171370 100755 --- a/scripts/backup.py +++ b/scripts/backup.py @@ -159,7 +159,7 @@ class backupTools: # skip-opt 不会lock表 # --skip-opt --create-options - cmd = db_path + "/bin/mysqldump --defaults-file=" + my_cnf +" " + option +" --single-transaction --compress -q --default-character-set=utf8mb4 " + \ + cmd = db_path + "/bin/mysqldump --defaults-file=" + my_cnf +" " + option +" --single-transaction -q --default-character-set=utf8mb4 " + \ name + " | gzip > " + filename # print(cmd) mw.execShell(cmd) From 139f3530348f95f4b3feaf7c6179b1c14b654315 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 14:09:57 +0800 Subject: [PATCH 189/327] update --- plugins/mysql-apt/scripts/backup.py | 2 +- plugins/mysql-yum/scripts/backup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mysql-apt/scripts/backup.py b/plugins/mysql-apt/scripts/backup.py index e779c0d6a..b4236c6fe 100755 --- a/plugins/mysql-apt/scripts/backup.py +++ b/plugins/mysql-apt/scripts/backup.py @@ -63,7 +63,7 @@ class backupTools: if len(mycnf) > 100: mw.writeFile(db_path + '/etc/my.cnf', mycnf) - cmd = db_path + "/bin/usr/bin/mysqldump --defaults-file=" + my_conf_path + " --single-transaction --compress -q --default-character-set=utf8 " + \ + cmd = db_path + "/bin/usr/bin/mysqldump --defaults-file=" + my_conf_path + " --single-transaction -q --default-character-set=utf8 " + \ name + " | gzip > " + filename mw.execShell(cmd) diff --git a/plugins/mysql-yum/scripts/backup.py b/plugins/mysql-yum/scripts/backup.py index 99b0caff7..ddca912c7 100755 --- a/plugins/mysql-yum/scripts/backup.py +++ b/plugins/mysql-yum/scripts/backup.py @@ -65,7 +65,7 @@ class backupTools: if len(content) > 100: mw.writeFile(my_cnf, content) - cmd = db_path + "/bin/usr/bin/mysqldump --defaults-file=" + my_cnf + " --single-transaction --compress -q --default-character-set=utf8 " + \ + cmd = db_path + "/bin/usr/bin/mysqldump --defaults-file=" + my_cnf + " --single-transaction -q --default-character-set=utf8 " + \ name + " | gzip > " + filename mw.execShell(cmd) From 9d89a92b78b0995a9e11faab8208d58e56668281 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 15:33:48 +0800 Subject: [PATCH 190/327] Update mysql.js --- plugins/mysql/js/mysql.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index 085706856..f96ae1163 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -2907,10 +2907,10 @@ function masterOrSlaveConf(version=''){ getMasterDbList(); } - // if (rdata.slave_status){ + if (rdata.slave_status){ getAsyncMasterDbList(); getAsyncDataList() - // } + } }); } getMasterStatus(); From 659ef259b70d43afad80bdc00dc2398bceb5cf50 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 15:44:33 +0800 Subject: [PATCH 191/327] Update index.py --- plugins/mysql/index.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 9e1e20414..84a399837 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3442,6 +3442,10 @@ def doFullSyncUser(version=''): # 重置 db.execute('reset master') + # 加快导入 - 开始 + db.execute('set global innodb_flush_log_at_trx_commit = 2') + db.execute('set global sync_binlog = 2000') + doFullSyncUserImportContentForChannel(bak_file, channel_name) @@ -3452,6 +3456,11 @@ def doFullSyncUser(version=''): print(my_import_cmd) r = mw.execShell(my_import_cmd) print(r) + + # 加快导入 - 结束 + db.execute('set global innodb_flush_log_at_trx_commit = 1') + db.execute('set global sync_binlog = 1') + # 修改同步位置 # master_info = sync_mdb.query('show master status') # slave_info = db.query('show slave status') From 8fb34103663ffd1123ed9b812774a2b4a80f5ccb Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 16:26:55 +0800 Subject: [PATCH 192/327] Update mysql.js --- plugins/mysql/js/mysql.js | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index f96ae1163..7bf1477ef 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -2291,6 +2291,7 @@ function addSlaveSyncUser(ip=''){ $('textarea[name="cmd"]').html(cmd); $('textarea[name="cmd"]').change(function(){ var val = $(this).val(); + val = val.replace(';',''); var a = {}; if (val.toLowerCase().indexOf('for')>0){ cmd_tmp = val.split('for'); From cb9857edf2c33f6d06a01fe35b19f0c6a295a3e2 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 16:51:10 +0800 Subject: [PATCH 193/327] update --- plugins/mysql/README.md | 12 +++++++++++ plugins/mysql/index.py | 44 ++++++++++++++++++++++++--------------- plugins/mysql/js/mysql.js | 26 +++++++++++++++++++++++ 3 files changed, 65 insertions(+), 17 deletions(-) diff --git a/plugins/mysql/README.md b/plugins/mysql/README.md index c3f3e59c1..5b3b7cc89 100644 --- a/plugins/mysql/README.md +++ b/plugins/mysql/README.md @@ -12,4 +12,16 @@ show global variables like 'server_uuid'; # drop_db_cmd = 'drop table if exists '+sync_db_import+'.'+tname[table_key] # # print(drop_db_cmd) # db.query(drop_db_cmd) +``` + +``` +# 修改同步位置 +# master_info = sync_mdb.query('show master status') +# slave_info = db.query('show slave status') +# if len(master_info)>0: +# channel_name = slave_info[0]['Channel_Name'] +# change_cmd = "CHANGE MASTER TO MASTER_LOG_FILE='"+master_info[0]['File']+"', MASTER_LOG_POS="+str(master_info[0]['Position'])+" for channel '"+channel_name+"';" +# print(change_cmd) +# r = db.execute(change_cmd) +# print(r) ``` \ No newline at end of file diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 84a399837..56e778240 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3293,6 +3293,18 @@ def writeDbSyncStatus(data): mw.writeFile(path, json.dumps(data)) return True +def fullSyncCmd(): + time_all_s = time.time() + args = getArgs() + data = checkArgs(args, ['db', 'sign']) + if not data[0]: + return data[1] + + db = args['db'] + sign = args['sign'] + + cmd = 'cd '+mw.getServerDir()+'/mdserver-web && source bin/activate && python3 plugins/mysql/index.py do_full_sync {"db":"'+db+'","sign":"'+sign+'"}' + return mw.returnJson(True,'ok',cmd) def doFullSync(version=''): mode_file = getSyncModeFile() @@ -3324,6 +3336,7 @@ def getChannelNameForCmd(cmd): return '' + def doFullSyncUserImportContentForChannel(file, channel_name): # print(file, channel_name) content = mw.readFile(file) @@ -3443,33 +3456,28 @@ def doFullSyncUser(version=''): db.execute('reset master') # 加快导入 - 开始 - db.execute('set global innodb_flush_log_at_trx_commit = 2') - db.execute('set global sync_binlog = 2000') + # db.execute('set global innodb_flush_log_at_trx_commit = 2') + # db.execute('set global sync_binlog = 2000') doFullSyncUserImportContentForChannel(bak_file, channel_name) pwd = pSqliteDb('config').where('id=?', (1,)).getField('mysql_root') sock = getSocketFile() + # my_import_cmd = getServerDir() + '/bin/mysql -S ' + sock + " -uroot -p'" + pwd + \ + # "' " + sync_db_import + ' < ' + bak_file + # print(my_import_cmd) + my_import_cmd = getServerDir() + '/bin/mysql -S ' + sock + " -uroot -p'" + pwd + \ - "' " + sync_db_import + ' < ' + bak_file + "' " + sync_db_import + my_import_cmd = "pv -t -p " + bak_file + '|' + my_import_cmd print(my_import_cmd) - r = mw.execShell(my_import_cmd) - print(r) + os.system(my_import_cmd) # 加快导入 - 结束 - db.execute('set global innodb_flush_log_at_trx_commit = 1') - db.execute('set global sync_binlog = 1') - - # 修改同步位置 - # master_info = sync_mdb.query('show master status') - # slave_info = db.query('show slave status') - # if len(master_info)>0: - # channel_name = slave_info[0]['Channel_Name'] - # change_cmd = "CHANGE MASTER TO MASTER_LOG_FILE='"+master_info[0]['File']+"', MASTER_LOG_POS="+str(master_info[0]['Position'])+" for channel '"+channel_name+"';" - # print(change_cmd) - # r = db.execute(change_cmd) - # print(r) + # db.execute('set global innodb_flush_log_at_trx_commit = 1') + # db.execute('set global sync_binlog = 1') + time_e = time.time() import_cos = time_e - time_s print("import cos:", import_cos) @@ -3866,6 +3874,8 @@ if __name__ == "__main__": print(fullSync(version)) elif func == 'do_full_sync': print(doFullSync(version)) + elif func == 'full_sync_cmd': + print(fullSyncCmd()) elif func == 'dump_mysql_data': print(dumpMysqlData(version)) elif func == 'sync_database_repair': diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index 7bf1477ef..22927a5b2 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -1985,6 +1985,7 @@ function getFullSyncStatus(db){
\
\ 开始\ + 手动命令\
\
", cancel: function(){ @@ -2007,6 +2008,31 @@ function getFullSyncStatus(db){ layer.msg("正在同步中..",{icon:0}); } }); + + $('#full_sync_cmd').click(function(){ + myPostN('full_sync_cmd', {'db':db,'sign':''}, function(rdata){ + var rdata = $.parseJSON(rdata.data); + layer.open({ + title: "手动执行命令CMD", + area: ['600px', '180px'], + type:1, + closeBtn: 1, + shadeClose: false, + btn:["复制","取消"], + content: '
\ +
\ +
'+rdata.data+'
\ +
\ +
', + success:function(){ + copyText(rdata.data); + }, + yes:function(){ + copyText(rdata.data); + } + }); + }); + }); } }); }); From c370486845c88cb07c6d2930e4c7a709a87096cf Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 16:59:08 +0800 Subject: [PATCH 194/327] Update mysql.js --- plugins/mysql/js/mysql.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index 22927a5b2..47d9f895a 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -2004,6 +2004,7 @@ function getFullSyncStatus(db){ fullSync(db,sign,0); }, 1000); $(this).data('status','starting'); + $('#begin_full_sync').text("同步中"); } else { layer.msg("正在同步中..",{icon:0}); } @@ -2048,6 +2049,7 @@ function getFullSyncStatus(db){ if (rdata['code']==6 ||rdata['code']<0){ layer.msg(rdata['msg']); clearInterval(timeId); + $('#begin_full_sync').text("同步结束,再次同步?"); $("#begin_full_sync").attr('data-status','init'); } }); From 5cd7a65737f8c1585b462f0ecedf8932c64cf00c Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 17:48:40 +0800 Subject: [PATCH 195/327] Update index.py --- plugins/mysql/index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 56e778240..d06900786 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3118,8 +3118,8 @@ def syncDatabaseRepair(version=''): # 比较总数 cmd_count_sql = 'select count(*) as num from '+table_name - local_count_data = local_db.query(cmd_count_sql) sync_count_data = sync_db.query(cmd_count_sql) + local_count_data = local_db.query(cmd_count_sql) if local_count_data != sync_count_data: print("all data compare: ",local_count_data, sync_count_data) @@ -3171,9 +3171,9 @@ def syncDatabaseRepair(version=''): print('pos:',str(table_name_pos),'local compare sync,',local_select_data == sync_select_data) cmd_count_sql = 'select count(*) as num from '+table_name - local_count_data = local_db.query(cmd_count_sql) time_s = time.time() sync_count_data = sync_db.query(cmd_count_sql) + local_count_data = local_db.query(cmd_count_sql) print(f'sync count data cos:{time.time() - time_s:.4f}s') print(local_count_data,sync_count_data) # 数据同步有延迟,相等即任务数据补足完成 From 7cd102c40fb09cee571ea7309fb1e3b82a2cec51 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 17:55:47 +0800 Subject: [PATCH 196/327] Update index.py --- plugins/mysql/index.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index d06900786..a978a7a5b 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3117,9 +3117,9 @@ def syncDatabaseRepair(version=''): continue # 比较总数 + local_count_data = local_db.query(cmd_count_sql) cmd_count_sql = 'select count(*) as num from '+table_name sync_count_data = sync_db.query(cmd_count_sql) - local_count_data = local_db.query(cmd_count_sql) if local_count_data != sync_count_data: print("all data compare: ",local_count_data, sync_count_data) @@ -3169,11 +3169,12 @@ def syncDatabaseRepair(version=''): # print(len(local_select_data)) # print(len(sync_select_data)) print('pos:',str(table_name_pos),'local compare sync,',local_select_data == sync_select_data) - + + + local_count_data = local_db.query(cmd_count_sql) cmd_count_sql = 'select count(*) as num from '+table_name time_s = time.time() sync_count_data = sync_db.query(cmd_count_sql) - local_count_data = local_db.query(cmd_count_sql) print(f'sync count data cos:{time.time() - time_s:.4f}s') print(local_count_data,sync_count_data) # 数据同步有延迟,相等即任务数据补足完成 From 22a21025af2f0c1f70c64d6cb2574f589726b053 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 17:56:11 +0800 Subject: [PATCH 197/327] 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 a978a7a5b..855059aee 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3172,7 +3172,7 @@ def syncDatabaseRepair(version=''): local_count_data = local_db.query(cmd_count_sql) - cmd_count_sql = 'select count(*) as num from '+table_name + cmd_count_sql = 'select count('+pkey_name+') as num from '+table_name time_s = time.time() sync_count_data = sync_db.query(cmd_count_sql) print(f'sync count data cos:{time.time() - time_s:.4f}s') From dc0e6fe78a66b55419c7ad908e4afd14b71510dc Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 17:57:14 +0800 Subject: [PATCH 198/327] 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 855059aee..3ef52612a 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3171,8 +3171,8 @@ def syncDatabaseRepair(version=''): print('pos:',str(table_name_pos),'local compare sync,',local_select_data == sync_select_data) - local_count_data = local_db.query(cmd_count_sql) cmd_count_sql = 'select count('+pkey_name+') as num from '+table_name + local_count_data = local_db.query(cmd_count_sql) time_s = time.time() sync_count_data = sync_db.query(cmd_count_sql) print(f'sync count data cos:{time.time() - time_s:.4f}s') From 222b8bc4de7b37af40917b051d305cd61b60d56e Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 17:58:50 +0800 Subject: [PATCH 199/327] 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 3ef52612a..6657978bb 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3117,8 +3117,8 @@ def syncDatabaseRepair(version=''): continue # 比较总数 - local_count_data = local_db.query(cmd_count_sql) cmd_count_sql = 'select count(*) as num from '+table_name + local_count_data = local_db.query(cmd_count_sql) sync_count_data = sync_db.query(cmd_count_sql) if local_count_data != sync_count_data: From 4fefb0efb228b5deeea15c67d512122e8349cbdd Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 18:26:18 +0800 Subject: [PATCH 200/327] Update index.py --- plugins/mysql/index.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 6657978bb..2fd90e8c5 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3360,6 +3360,11 @@ def doFullSyncUserImportContentForChannel(file, channel_name): def doFullSyncUser(version=''): + which_pv = mw.execShell('which pv') + is_exist_pv = False + if not os.path.exists(which_pv[0]): + is_exist_pv = True + time_all_s = time.time() args = getArgs() data = checkArgs(args, ['db', 'sign']) @@ -3465,15 +3470,15 @@ def doFullSyncUser(version=''): pwd = pSqliteDb('config').where('id=?', (1,)).getField('mysql_root') sock = getSocketFile() - # my_import_cmd = getServerDir() + '/bin/mysql -S ' + sock + " -uroot -p'" + pwd + \ - # "' " + sync_db_import + ' < ' + bak_file - # print(my_import_cmd) - - my_import_cmd = getServerDir() + '/bin/mysql -S ' + sock + " -uroot -p'" + pwd + \ - "' " + sync_db_import - my_import_cmd = "pv -t -p " + bak_file + '|' + my_import_cmd - print(my_import_cmd) - os.system(my_import_cmd) + + if is_exist_pv: + my_import_cmd = getServerDir() + '/bin/mysql -S ' + sock + " -uroot -p'" + pwd + "' " + sync_db_import + my_import_cmd = "pv -t -p " + bak_file + '|' + my_import_cmd + print(my_import_cmd) + os.system(my_import_cmd) + else: + my_import_cmd = getServerDir() + '/bin/mysql -S ' + sock + " -uroot -p'" + pwd + "' " + sync_db_import + ' < ' + bak_file + print(my_import_cmd) # 加快导入 - 结束 # db.execute('set global innodb_flush_log_at_trx_commit = 1') From 56cf0271b8f63163c33cb2c93da2ef850117c91e Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 17 May 2024 18:26:51 +0800 Subject: [PATCH 201/327] Update index.py --- plugins/mysql/index.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 2fd90e8c5..c7d46b1f1 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3479,6 +3479,7 @@ def doFullSyncUser(version=''): else: my_import_cmd = getServerDir() + '/bin/mysql -S ' + sock + " -uroot -p'" + pwd + "' " + sync_db_import + ' < ' + bak_file print(my_import_cmd) + mw.execShell(my_import_cmd) # 加快导入 - 结束 # db.execute('set global innodb_flush_log_at_trx_commit = 1') From 53cd6377bbe6bece7ef962a4cb3cfa6613b61d63 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 18 May 2024 00:57:55 +0800 Subject: [PATCH 202/327] Update stats.js --- plugins/webstats/js/stats.js | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/webstats/js/stats.js b/plugins/webstats/js/stats.js index caf90bfda..6fd849517 100644 --- a/plugins/webstats/js/stats.js +++ b/plugins/webstats/js/stats.js @@ -2383,6 +2383,7 @@ var html = '
\ \ \ \ + \ \ \ \ From 2f9903753f572050b4901c963ecee01f7079c297 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 18 May 2024 02:57:32 +0800 Subject: [PATCH 203/327] Update index.py --- plugins/mongodb/index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mongodb/index.py b/plugins/mongodb/index.py index 68e41c6ef..2517afd98 100755 --- a/plugins/mongodb/index.py +++ b/plugins/mongodb/index.py @@ -618,7 +618,7 @@ def addDb(): username = data_name - client[data_name].chat.insert_one({}) + client[data_name].zchat.insert_one({}) user_roles = [{'role': 'dbOwner', 'db': data_name}, {'role': 'userAdmin', 'db': data_name}] if auth_status: # db.command("dropUser", username) @@ -803,7 +803,7 @@ def toDbBase(find): data_name = find['name'] db = client[data_name] - db.chat.insert_one({}) + db.zchat.insert_one({}) user_roles = [{'role': 'dbOwner', 'db': data_name}, {'role': 'userAdmin', 'db': data_name}] try: db_admin.command("createUser", find['username'], pwd=find['password'], roles=user_roles) From e805910b1be53dfcdc2f4f729bf2bbee4912a42d Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 18 May 2024 10:54:06 +0800 Subject: [PATCH 204/327] Update index.py --- plugins/mysql/index.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index c7d46b1f1..bb3928ea3 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3109,6 +3109,10 @@ def syncDatabaseRepair(version=''): mw.execShell('mkdir -p '+tmp_dir) for tb in tables: + primary_key_sql = "SHOW INDEX FROM "+tb+" WHERE Key_name = 'PRIMARY';"; + primary_key_data = local_db.query(primary_key_sql) + pkey_name = primary_key_data[0]['Column_name'] + table_name = sync_args_db+'.'+tb[table_key] table_check_file = tmp_dir+'/'+table_name+'.txt' @@ -3117,7 +3121,7 @@ def syncDatabaseRepair(version=''): continue # 比较总数 - cmd_count_sql = 'select count(*) as num from '+table_name + cmd_count_sql = 'select count('+pkey_name+') as num from '+table_name local_count_data = local_db.query(cmd_count_sql) sync_count_data = sync_db.query(cmd_count_sql) From 477b8b38fd00feaa83b3297f4f1cedfebc7e9b91 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 18 May 2024 10:58:10 +0800 Subject: [PATCH 205/327] Update index.py --- plugins/mysql/index.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index bb3928ea3..3fee990ef 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3109,9 +3109,6 @@ def syncDatabaseRepair(version=''): mw.execShell('mkdir -p '+tmp_dir) for tb in tables: - primary_key_sql = "SHOW INDEX FROM "+tb+" WHERE Key_name = 'PRIMARY';"; - primary_key_data = local_db.query(primary_key_sql) - pkey_name = primary_key_data[0]['Column_name'] table_name = sync_args_db+'.'+tb[table_key] table_check_file = tmp_dir+'/'+table_name+'.txt' @@ -3120,6 +3117,10 @@ def syncDatabaseRepair(version=''): # print(table_name+', 已检查OK') continue + primary_key_sql = "SHOW INDEX FROM "+table_name+" WHERE Key_name = 'PRIMARY';"; + primary_key_data = local_db.query(primary_key_sql) + pkey_name = primary_key_data[0]['Column_name'] + # 比较总数 cmd_count_sql = 'select count('+pkey_name+') as num from '+table_name local_count_data = local_db.query(cmd_count_sql) From 0897fd9370c83295cefb59389e015e47d2f1f74a Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 18 May 2024 11:51:51 +0800 Subject: [PATCH 206/327] Update index.py --- plugins/mysql/index.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 3fee990ef..2b1dfdf96 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3119,7 +3119,32 @@ def syncDatabaseRepair(version=''): primary_key_sql = "SHOW INDEX FROM "+table_name+" WHERE Key_name = 'PRIMARY';"; primary_key_data = local_db.query(primary_key_sql) - pkey_name = primary_key_data[0]['Column_name'] + # print(primary_key_sql,primary_key_data) + pkey_name = '*' + if len(primary_key_data) == 1: + pkey_name = primary_key_data[0]['Column_name'] + # print(pkey_name) + if pkey_name != '*' : + # 智能校验(由于服务器同步可能会慢,比较总数总是对不上) + cmd_local_newpk_sql = 'select ' + pkey_name + ' from ' + table_name + " order by " + pkey_name + " desc limit 1" + cmd_local_newpk_data = local_db.query(cmd_local_newpk_sql) + # print(cmd_local_newpk_data) + if len(cmd_local_newpk_data) == 1: + # 比较总数 + cmd_count_sql = 'select count('+pkey_name+') as num from '+table_name + ' where '+pkey_name + ' < '+ str(cmd_local_newpk_data[0][pkey_name]) + local_count_data = local_db.query(cmd_count_sql) + sync_count_data = sync_db.query(cmd_count_sql) + + if local_count_data != sync_count_data: + print(cmd_count_sql) + print("all data compare: ",local_count_data, sync_count_data) + else: + print(table_name+' smart compare check ok.') + mw.writeFile(tmp_log, table_name+' smart compare check ok.\n','a+') + mw.execShell("echo 'ok' > "+table_check_file) + continue + + # 比较总数 cmd_count_sql = 'select count('+pkey_name+') as num from '+table_name From 70012ea7ee3086c9abe6259b5cca31b5b5120a14 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 18 May 2024 11:56:56 +0800 Subject: [PATCH 207/327] 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 2b1dfdf96..aa22add40 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3131,7 +3131,7 @@ def syncDatabaseRepair(version=''): # print(cmd_local_newpk_data) if len(cmd_local_newpk_data) == 1: # 比较总数 - cmd_count_sql = 'select count('+pkey_name+') as num from '+table_name + ' where '+pkey_name + ' < '+ str(cmd_local_newpk_data[0][pkey_name]) + cmd_count_sql = 'select count('+pkey_name+') as num from '+table_name + ' where '+pkey_name + ' <= '+ str(cmd_local_newpk_data[0][pkey_name]) local_count_data = local_db.query(cmd_count_sql) sync_count_data = sync_db.query(cmd_count_sql) From 1d1e6b1d5bddb02f7e8c80ba6bba31bce6ed4a84 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 18 May 2024 12:49:46 +0800 Subject: [PATCH 208/327] Update index.py --- plugins/mysql/index.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index aa22add40..4bc9bc393 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3494,9 +3494,9 @@ def doFullSyncUser(version=''): # 加快导入 - 开始 # db.execute('set global innodb_flush_log_at_trx_commit = 2') # db.execute('set global sync_binlog = 2000') - - doFullSyncUserImportContentForChannel(bak_file, channel_name) - + + if channel_name != '': + doFullSyncUserImportContentForChannel(bak_file, channel_name) pwd = pSqliteDb('config').where('id=?', (1,)).getField('mysql_root') sock = getSocketFile() From b778c8cdebf6dc5718426fb8ad00a13848ea9e78 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 18 May 2024 13:57:34 +0800 Subject: [PATCH 209/327] Update index.py --- plugins/mysql/index.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 4bc9bc393..a736b314b 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3467,6 +3467,11 @@ def doFullSyncUser(version=''): # --skip-opt --create-options # --master-data=1 + find_run_dump = mw.execShell('ps -ef | grep mysqldump | grep -v grep') + if find_run_dump[0] != "": + print("正在远程导出数据中,别着急...") + writeDbSyncStatus({'code': 3.1, 'msg': '正在远程导出数据中,别着急...', 'progress': 21}) + return False time_s = time.time() if not os.path.exists(bak_file): if isSimpleSyncCmd(cmd): @@ -3486,6 +3491,12 @@ def doFullSyncUser(version=''): writeDbSyncStatus({'code': 3, 'msg': '导出耗时:'+str(int(export_cos))+'秒,正在到本地导入数据中...', 'progress': 40}) + find_run_sync = mw.execShell('ps -ef | grep do_full_sync | grep -v grep') + if find_run_sync[0] != "": + print("正在导入数据中,别着急...") + writeDbSyncStatus({'code': 4.1, 'msg': '正在导入数据中,别着急...', 'progress': 41}) + return False + time_s = time.time() if os.path.exists(bak_file): # 重置 @@ -3494,7 +3505,7 @@ def doFullSyncUser(version=''): # 加快导入 - 开始 # db.execute('set global innodb_flush_log_at_trx_commit = 2') # db.execute('set global sync_binlog = 2000') - + if channel_name != '': doFullSyncUserImportContentForChannel(bak_file, channel_name) From 9ee3aebc8c0a3ba4405d85e2a2ca754ddf4640dd Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 18 May 2024 14:02:17 +0800 Subject: [PATCH 210/327] Update index.py --- plugins/mysql/index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index a736b314b..8a09b62f9 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3470,7 +3470,7 @@ def doFullSyncUser(version=''): find_run_dump = mw.execShell('ps -ef | grep mysqldump | grep -v grep') if find_run_dump[0] != "": print("正在远程导出数据中,别着急...") - writeDbSyncStatus({'code': 3.1, 'msg': '正在远程导出数据中,别着急...', 'progress': 21}) + writeDbSyncStatus({'code': 3.1, 'msg': '正在远程导出数据中,别着急...', 'progress': 19}) return False time_s = time.time() if not os.path.exists(bak_file): @@ -3494,7 +3494,7 @@ def doFullSyncUser(version=''): find_run_sync = mw.execShell('ps -ef | grep do_full_sync | grep -v grep') if find_run_sync[0] != "": print("正在导入数据中,别着急...") - writeDbSyncStatus({'code': 4.1, 'msg': '正在导入数据中,别着急...', 'progress': 41}) + writeDbSyncStatus({'code': 4.1, 'msg': '正在导入数据中,别着急...', 'progress': 39}) return False time_s = time.time() From fa1778257333fc61bfe2d741c13b2a7be085927f Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 18 May 2024 14:15:57 +0800 Subject: [PATCH 211/327] Update index.py --- plugins/mysql/index.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 8a09b62f9..29a70248f 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3472,6 +3472,7 @@ def doFullSyncUser(version=''): print("正在远程导出数据中,别着急...") writeDbSyncStatus({'code': 3.1, 'msg': '正在远程导出数据中,别着急...', 'progress': 19}) return False + time_s = time.time() if not os.path.exists(bak_file): if isSimpleSyncCmd(cmd): @@ -3491,8 +3492,8 @@ def doFullSyncUser(version=''): writeDbSyncStatus({'code': 3, 'msg': '导出耗时:'+str(int(export_cos))+'秒,正在到本地导入数据中...', 'progress': 40}) - find_run_sync = mw.execShell('ps -ef | grep do_full_sync | grep -v grep') - if find_run_sync[0] != "": + find_run_import = mw.execShell('ps -ef | grep mysql| grep '+ bak_file +' | grep -v grep') + if find_run_import[0] != "": print("正在导入数据中,别着急...") writeDbSyncStatus({'code': 4.1, 'msg': '正在导入数据中,别着急...', 'progress': 39}) return False From efd07f6de29c1101c5be35160aca777294f8919c Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 00:51:35 +0800 Subject: [PATCH 212/327] =?UTF-8?q?=E7=BD=91=E7=AB=99=E7=BB=9F=E8=AE=A1=20?= =?UTF-8?q?-=20=20=E5=AE=9E=E6=97=B6=E8=AF=B7=E6=B1=82=20=E5=8F=AF?= =?UTF-8?q?=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/webstats/index.html | 4 +-- plugins/webstats/index.py | 6 +++-- plugins/webstats/js/stats.js | 49 ++++++++++++++++++++++++++++++------ 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/plugins/webstats/index.html b/plugins/webstats/index.html index bd0580289..028f37282 100755 --- a/plugins/webstats/index.html +++ b/plugins/webstats/index.html @@ -86,13 +86,13 @@ .indicators-label { display: inline-block; - width: 95px; + width: 88px; height: 26px; line-height: 26px; cursor: pointer; } -.indicators-label input { +.indicators-label input[type=radio] { height: 13px; margin: 0 5px 0 0; vertical-align: -2px; diff --git a/plugins/webstats/index.py b/plugins/webstats/index.py index 1101447d2..c89944e88 100755 --- a/plugins/webstats/index.py +++ b/plugins/webstats/index.py @@ -654,17 +654,19 @@ def getLogsRealtimeInfo(): ''' import datetime args = getArgs() - check = checkArgs(args, ['site', 'type']) + check = checkArgs(args, ['site', 'type','second']) if not check[0]: return check[1] domain = args['site'] dtype = args['type'] + second = int(args['second']) + conn = pSqliteDb('web_logs', domain) timeInt = time.mktime(datetime.datetime.now().timetuple()) - conn = conn.where("time>=?", (int(timeInt) - 10,)) + conn = conn.where("time>=?", (int(timeInt) - second,)) field = 'time,body_length' field_sum = toSumField(field.replace("time,", "")) diff --git a/plugins/webstats/js/stats.js b/plugins/webstats/js/stats.js index 6fd849517..c7678d694 100644 --- a/plugins/webstats/js/stats.js +++ b/plugins/webstats/js/stats.js @@ -192,7 +192,7 @@ function wsOverviewRequest(page){ var data = rdata.data.data; var statData = rdata.data.stat_list; - console.log(statData, data); + // console.log(statData, data); var stat_pv = statData['pv'] == null?0:statData['pv']; var stat_uv = statData['uv'] == null?0:statData['uv']; @@ -383,11 +383,13 @@ function wsOverviewRequest(page){ var select_option = $('.indicators-container input:checked').parent().attr('data-name'); if (select_option != "realtime_traffic" && select_option != 'realtime_request' ){ clearInterval(ovTimer); - console.log("get_logs_realtime_info over:"+select_option); + // console.log("get_logs_realtime_info over:"+select_option); return; } - wsOriginPost("get_logs_realtime_info",'',{"site":args["site"], "type":select_option} , function(rdata){ + var second = $('#check_realtime_second').val(); + + wsOriginPost("get_logs_realtime_info",'',{"site":args["site"], "type":select_option,'second':second} , function(rdata){ var rdata = $.parseJSON(rdata.data); @@ -488,11 +490,11 @@ var html = '
\

0

\
\
\ -

实时流量?

\ +

实时流量?

\

0

\
\
\ -

每秒请求?

\ +

每秒请求?

\

0

\
\
\ @@ -525,7 +527,11 @@ var html = '
\
\
\ \ - 每秒请求\ + 每X秒请求\ +
\ +
\ + \ + \
\
\
\ @@ -592,8 +598,35 @@ $('#search_time button').click(function(){ }); -$('.indicators-container input').click(function(){ - $('.indicators-container input').each(function(){ +function initRealtimeTraffic(){ + var check_realtime_second = $('#check_realtime_second').val(); + if (check_realtime_second<1){ + check_realtime_second = 1; + $('#check_realtime_second').val(check_realtime_second); + } + + if (check_realtime_second>10){ + check_realtime_second = 10; + $('#check_realtime_second').val(check_realtime_second); + } + var title = "每秒请求"; + if (check_realtime_second > 1){ + title = '每'+check_realtime_second+'秒请求' + } + + $('#ov_title_req_second').text(title) + $('.check_realtime_request').text(title); +} + + +initRealtimeTraffic(); +$('#check_realtime_second').change(function(){ + initRealtimeTraffic(); + wsOverviewRequest(1); +}); + +$('.indicators-container input[type=radio]').click(function(){ + $('.indicators-container input[type=radio]').each(function(){ $(this).removeAttr('checked'); }); $(this).prop({'checked':true}); From aac516c8f8e19bcb460f53b652b690537f7ce335 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 00:56:35 +0800 Subject: [PATCH 213/327] Update stats.js --- plugins/webstats/js/stats.js | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/webstats/js/stats.js b/plugins/webstats/js/stats.js index c7678d694..149cc8c4e 100644 --- a/plugins/webstats/js/stats.js +++ b/plugins/webstats/js/stats.js @@ -622,7 +622,6 @@ function initRealtimeTraffic(){ initRealtimeTraffic(); $('#check_realtime_second').change(function(){ initRealtimeTraffic(); - wsOverviewRequest(1); }); $('.indicators-container input[type=radio]').click(function(){ From 002639936e259d63fedb916570412f968b59e0cd Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 01:32:31 +0800 Subject: [PATCH 214/327] update --- plugins/sphinx/index.py | 7 ++++--- plugins/sphinx/init.d/sphinx.tpl | 2 +- plugins/sphinx/install.sh | 2 ++ plugins/sphinx/js/sphinx.js | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/plugins/sphinx/index.py b/plugins/sphinx/index.py index d4a73e6e2..d3738699d 100755 --- a/plugins/sphinx/index.py +++ b/plugins/sphinx/index.py @@ -210,9 +210,10 @@ def reload(): def rebuild(): file = initDreplace() - subprocess.Popen(file + ' rebuild &', - stdout=subprocess.PIPE, shell=True) - # data = mw.execShell(file + ' rebuild') + cmd = file + ' rebuild &' + data = mw.execShell(cmd) + if data[1] != '': + return data[0] return 'ok' diff --git a/plugins/sphinx/init.d/sphinx.tpl b/plugins/sphinx/init.d/sphinx.tpl index 4652aa078..8de34003c 100644 --- a/plugins/sphinx/init.d/sphinx.tpl +++ b/plugins/sphinx/init.d/sphinx.tpl @@ -33,7 +33,7 @@ start () { } rebuild () { - ${APP_PATH}/bin/bin/indexer -c ${APP_CONF} --all --rotate & + ${APP_PATH}/bin/bin/indexer -c ${APP_CONF} --all --rotate } diff --git a/plugins/sphinx/install.sh b/plugins/sphinx/install.sh index b6a0494f6..9bddb2904 100755 --- a/plugins/sphinx/install.sh +++ b/plugins/sphinx/install.sh @@ -10,6 +10,8 @@ sysName=`uname` install_tmp=${rootPath}/tmp/mw_install.pl +# cd /www/server/mdserver-web && source bin/activate && python3 plugins/sphinx/index.py rebuild + bash ${rootPath}/scripts/getos.sh OSNAME=`cat ${rootPath}/data/osname.pl` diff --git a/plugins/sphinx/js/sphinx.js b/plugins/sphinx/js/sphinx.js index bacda023a..37b7c3e01 100755 --- a/plugins/sphinx/js/sphinx.js +++ b/plugins/sphinx/js/sphinx.js @@ -38,7 +38,7 @@ function rebuild(){ function rebuildIndex(){ spPost('rebuild', '', function(data){ if (data.data == 'ok'){ - layer.msg('在重建中..',{icon:1,time:2000,shade: [0.3, '#000']}); + layer.msg('重建成功!',{icon:1,time:2000,shade: [0.3, '#000']}); } else { layer.msg(data.data,{icon:2,time:2000,shade: [0.3, '#000']}); } From b07b6f0c942842fc7ce68cdbcdb5efd735bd34f2 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 02:35:03 +0800 Subject: [PATCH 215/327] update --- plugins/sphinx/index.html | 2 +- plugins/sphinx/index.py | 4 ++-- plugins/sphinx/js/sphinx.js | 10 +++++++++- route/static/app/public.js | 22 ++++++++++++++-------- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/plugins/sphinx/index.html b/plugins/sphinx/index.html index fd332a0d3..bcdf6a922 100755 --- a/plugins/sphinx/index.html +++ b/plugins/sphinx/index.html @@ -3,7 +3,7 @@

服务

自启动

-

配置修改

+

配置修改

运行日志

查询日志

运行状态

diff --git a/plugins/sphinx/index.py b/plugins/sphinx/index.py index d3738699d..026f88e16 100755 --- a/plugins/sphinx/index.py +++ b/plugins/sphinx/index.py @@ -212,8 +212,8 @@ def rebuild(): file = initDreplace() cmd = file + ' rebuild &' data = mw.execShell(cmd) - if data[1] != '': - return data[0] + if data[0].find('successfully'): + return data[0].replace("\n","
") return 'ok' diff --git a/plugins/sphinx/js/sphinx.js b/plugins/sphinx/js/sphinx.js index 37b7c3e01..23329a2bb 100755 --- a/plugins/sphinx/js/sphinx.js +++ b/plugins/sphinx/js/sphinx.js @@ -40,11 +40,19 @@ function rebuildIndex(){ if (data.data == 'ok'){ layer.msg('重建成功!',{icon:1,time:2000,shade: [0.3, '#000']}); } else { - layer.msg(data.data,{icon:2,time:2000,shade: [0.3, '#000']}); + layer.msg(data.data,{icon:2,time:10000,shade: [0.3, '#000']}); } }); } + +function tryRebuildIndex(){ + layer.confirm("修改配置后,是否尝试重建索引。", {icon:3,closeBtn: 1} , function(){ + rebuildIndex(); + }); +} + + function secToTime(s) { var t; if(s > -1){ diff --git a/route/static/app/public.js b/route/static/app/public.js index 5b3e886a1..404eca408 100755 --- a/route/static/app/public.js +++ b/route/static/app/public.js @@ -2255,7 +2255,7 @@ function pluginConfig(_name, version, func){ //配置修改模版 --- start -function pluginConfigTpl(_name, version, func, config_tpl_func, read_config_tpl_func){ +function pluginConfigTpl(_name, version, func, config_tpl_func, read_config_tpl_func, save_callback_func){ if ( typeof(version) == 'undefined' ){ version = ''; } @@ -2281,7 +2281,7 @@ function pluginConfigTpl(_name, version, func, config_tpl_func, read_config_tpl_ \ \
    \ -
  • 此处为'+ _name + version +'主配置文件,若您不了解配置规则,请勿随意修改。
  • \ +
  • 此处为【'+ _name + version +'】主配置文件,若您不了解配置规则,请勿随意修改。
  • \
'; $(".soft-man-con").html(con); @@ -2321,7 +2321,7 @@ function pluginConfigTpl(_name, version, func, config_tpl_func, read_config_tpl_ "Ctrl-H": "replaceAll", "Ctrl-S": function() { $("#textBody").text(editor.getValue()); - pluginConfigSave(fileName); + pluginConfigSave(fileName,save_callback_func); } }, lineNumbers: true, @@ -2332,7 +2332,7 @@ function pluginConfigTpl(_name, version, func, config_tpl_func, read_config_tpl_ $("#onlineEditFileBtn").unbind('click'); $("#onlineEditFileBtn").click(function(){ $("#textBody").text(editor.getValue()); - pluginConfigSave(fileName); + pluginConfigSave(fileName, save_callback_func); }); },'json'); } @@ -2361,7 +2361,7 @@ function pluginConfigTpl(_name, version, func, config_tpl_func, read_config_tpl_ "Ctrl-H": "replaceAll", "Ctrl-S": function() { $("#textBody").text(editor.getValue()); - pluginConfigSave(fileName); + pluginConfigSave(fileName,save_callback_func); } }, lineNumbers: true, @@ -2371,7 +2371,7 @@ function pluginConfigTpl(_name, version, func, config_tpl_func, read_config_tpl_ $(".CodeMirror-scroll").css({"height":"300px","margin":0,"padding":0}); $("#onlineEditFileBtn").click(function(){ $("#textBody").text(editor.getValue()); - pluginConfigSave(fileName); + pluginConfigSave(fileName,save_callback_func); }); },'json'); },'json'); @@ -2498,13 +2498,19 @@ function pluginConfigListTpl(_name, version, config_tpl_func, read_config_tpl_fu //配置保存 -function pluginConfigSave(fileName) { +function pluginConfigSave(fileName, callback) { var data = encodeURIComponent($("#textBody").val()); var encoding = 'utf-8'; var loadT = layer.msg('保存中...', {icon: 16,time: 0}); $.post('/files/save_body', 'data=' + data + '&path=' + fileName + '&encoding=' + encoding, function(rdata) { layer.close(loadT); - layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2}); + + showMsg(rdata.msg, function(){ + if ( rdata.status && typeof(callback) == 'function'){ + callback(); + } + },{icon: rdata.status ? 1 : 2}); + },'json'); } From 10edf675f51232281e3e0112d75f4dcec3a6f2e5 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 02:35:24 +0800 Subject: [PATCH 216/327] Update config_api.py --- class/core/config_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/class/core/config_api.py b/class/core/config_api.py index fc4dbfb21..24b2776d6 100755 --- a/class/core/config_api.py +++ b/class/core/config_api.py @@ -28,7 +28,7 @@ from flask import request class config_api: - __version = '0.16.8.4' + __version = '0.16.8.5' __api_addr = 'data/api.json' # 统一默认配置文件 From 02f3a147aae1e2eb5613a1871ee295105ee9950d Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 02:36:34 +0800 Subject: [PATCH 217/327] Update index.py --- plugins/sphinx/index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/sphinx/index.py b/plugins/sphinx/index.py index 026f88e16..0ae17d7b4 100755 --- a/plugins/sphinx/index.py +++ b/plugins/sphinx/index.py @@ -212,7 +212,7 @@ def rebuild(): file = initDreplace() cmd = file + ' rebuild &' data = mw.execShell(cmd) - if data[0].find('successfully'): + if data[0].find('successfully')<0: return data[0].replace("\n","
") return 'ok' From b3b23994ebeac972fd1c7939319f384875f50cd0 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 02:40:11 +0800 Subject: [PATCH 218/327] Update sphinx.js --- plugins/sphinx/js/sphinx.js | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/sphinx/js/sphinx.js b/plugins/sphinx/js/sphinx.js index 23329a2bb..770caea46 100755 --- a/plugins/sphinx/js/sphinx.js +++ b/plugins/sphinx/js/sphinx.js @@ -121,6 +121,7 @@ function readme(){ var con = '
    '; con += '
  • 如果数据量比较大,第一次启动会失败!(可通过手动建立索引)
  • '; + con += '
  • 以下内容,需手动加入计划任务。
  • '; //主索引 for (var i = 0; i < rdata['data']['index'].length; i++) { var index_t = rdata['data']['index'][i]; From 41109af522be8f4f9ade4cc378b98bbeeeeac105 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 11:27:13 +0800 Subject: [PATCH 219/327] Update install.sh --- plugins/sphinx/install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/sphinx/install.sh b/plugins/sphinx/install.sh index 9bddb2904..25d81d21c 100755 --- a/plugins/sphinx/install.sh +++ b/plugins/sphinx/install.sh @@ -11,6 +11,7 @@ sysName=`uname` install_tmp=${rootPath}/tmp/mw_install.pl # cd /www/server/mdserver-web && source bin/activate && python3 plugins/sphinx/index.py rebuild +# /www/server/sphinx/bin/bin/indexer -c /www/server/sphinx/sphinx.conf --rotate bash ${rootPath}/scripts/getos.sh From a74ca20d0eddabc1b0bc3a1e422f9efa082ab49b Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 14:58:14 +0800 Subject: [PATCH 220/327] up --- README.md | 6 +- plugins/mysql/index.py | 19 ++-- plugins/sphinx/class/sphinx_make.py | 149 ++++++++++++++++++++++++++++ plugins/sphinx/index.html | 2 +- plugins/sphinx/index.py | 28 +++++- plugins/sphinx/install.sh | 1 + plugins/sphinx/js/sphinx.js | 2 +- 7 files changed, 194 insertions(+), 13 deletions(-) create mode 100644 plugins/sphinx/class/sphinx_make.py diff --git a/README.md b/README.md index 301884e66..7239c235d 100644 --- a/README.md +++ b/README.md @@ -110,9 +110,11 @@ docker run -itd --name mw-server --privileged=true -p 7200:7200 -p 80:80 -p 443: ``` -### 版本更新 0.16.8 +### 版本更新 0.16.8.x -- 首页对网络/磁盘IO进行更细致的展示。 +- mysql同步优化,享受丝滑般感觉。 +- 网站统计实时-可调节1-10s。 +- Sphinx优化。 ### JSDelivr安装地址 diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 29a70248f..6f409ce3b 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3448,7 +3448,9 @@ def doFullSyncUser(version=''): time.sleep(1) writeDbSyncStatus({'code': 1, 'msg': '正在停止从库...', 'progress': 15}) - if version == '8.0': + + mdb8 = ['8.0','8.1','8.2','8.3','8.4'] + if mw.inArray(mdb8,version): db.query("stop slave user='{}' password='{}';".format(user, apass)) else: db.query("stop slave") @@ -3537,12 +3539,12 @@ def doFullSyncUser(version=''): # r = db.query(cmd) # print(r) - if version == '8.0': + mdb8 = ['8.0','8.1','8.2','8.3','8.4'] + if mw.inArray(mdb8,version): db.query("start slave user='{}' password='{}';".format(user, apass)) else: db.query("start slave") - db.query("start all slaves") time_all_e = time.time() cos = time_all_e - time_all_s @@ -3681,10 +3683,13 @@ def doFullSyncSSH(version=''): print(import_data[0]) writeDbSyncStatus({'code': 5, 'msg': '导入数据失败...', 'progress': 100}) return 'fail' - - # "start slave user='{}' password='{}';".format(uinfo['username'], uinfo['password']) - - db.query("start slave") + + mdb8 = ['8.0','8.1','8.2','8.3','8.4'] + if mw.inArray(mdb8,version): + db.query("start slave user='{}' password='{}';".format(uinfo['username'], uinfo['password'])) + else: + db.query("start slave") + writeDbSyncStatus({'code': 6, 'msg': '从库重启完成...', 'progress': 100}) os.system("rm -rf " + SSH_PRIVATE_KEY) diff --git a/plugins/sphinx/class/sphinx_make.py b/plugins/sphinx/class/sphinx_make.py new file mode 100644 index 000000000..94ff3bddf --- /dev/null +++ b/plugins/sphinx/class/sphinx_make.py @@ -0,0 +1,149 @@ +# 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 + + +def getServerDir(): + return mw.getServerDir() + '/mysql' + +def getPluginDir(): + return mw.getPluginDir() + '/mysql' + +def getConf(): + path = getServerDir() + '/etc/my.cnf' + return path + +def getDbPort(): + file = getConf() + content = mw.readFile(file) + rep = 'port\s*=\s*(.*)' + tmp = re.search(rep, content) + return tmp.groups()[0].strip() + +def getSocketFile(): + file = getConf() + content = mw.readFile(file) + rep = 'socket\s*=\s*(.*)' + tmp = re.search(rep, content) + return tmp.groups()[0].strip() + +def pSqliteDb(dbname='databases'): + file = getServerDir() + '/mysql.db' + name = 'mysql' + + conn = mw.M(dbname).dbPos(getServerDir(), name) + return conn + +def pMysqlDb(): + # pymysql + db = mw.getMyORM() + + db.setPort(getDbPort()) + db.setSocket(getSocketFile()) + # db.setCharset("utf8") + db.setPwd(pSqliteDb('config').where('id=?', (1,)).getField('mysql_root')) + return db + +def makeSqlToSphinx(): + pass + +def makeSqlToSphinxDb(db, table = []): + pdb = pMysqlDb() + + tables = pdb.query("show tables in "+ db) + for x in range(len(tables)): + key = 'Tables_in_'+db + table_name = tables[x][key] + pkey_name = getTablePk(db,table_name) + + if pkey_name == '': + continue + + # print(table_name+':'+pkey_name) + makeSqlToSphinxTable(db,table_name) + + +def getTablePk(db, table): + pdb = pMysqlDb() + pkey_sql = "SHOW INDEX FROM {}.{} WHERE Key_name = 'PRIMARY';".format(db,table,); + pkey_data = pdb.query(pkey_sql) + + if len(pkey_data) == 1: + return pkey_data[0]['Column_name'] + + return '' + +def makeSqlToSphinxTable(db,table): + pdb = pMysqlDb() + + sql = "select COLUMN_NAME,DATA_TYPE from information_schema.COLUMNS where `TABLE_SCHEMA`='{}' and `TABLE_NAME` = '{}';" + sql = sql.format(db,table,) + cols = pdb.query(sql) + cols_len = len(cols) + conf = '' + run_pos = 0 + for x in range(cols_len): + data_type = cols[x]['DATA_TYPE'] + column_name = cols[x]['COLUMN_NAME'] + print(column_name+":"+data_type) + + # if mw.inArray(['tinyint'], data_type): + # conf += 'sql_attr_bool = '+ column_name + "\n" + + if mw.inArray(['enum'], data_type): + run_pos += 1 + conf += 'sql_attr_string = '+ column_name + "\n" + + if mw.inArray(['decimal'], data_type): + run_pos += 1 + conf += 'sql_attr_float = '+ column_name + "\n" + + if mw.inArray(['bigint','smallint','tinyint','int','mediumint'], data_type): + run_pos += 1 + conf += 'sql_attr_bigint = '+ column_name + "\n" + + + if mw.inArray(['float'], data_type): + run_pos += 1 + conf += 'sql_attr_float = '+ column_name + "\n" + + if mw.inArray(['varchar','char'], data_type): + run_pos += 1 + conf += 'sql_attr_string = '+ column_name + "\n" + + if mw.inArray(['text','mediumtext','tinytext','longtext'], data_type): + run_pos += 1 + conf += 'sql_field_string = '+ column_name + "\n" + + if mw.inArray(['datetime','date'], data_type): + run_pos += 1 + conf += 'sql_attr_timestamp = '+ column_name + "\n" + + if cols_len != run_pos: + print(db,table) + + print(cols_len,run_pos) + + + # print(conf) + return conf + + + + + + + + + + diff --git a/plugins/sphinx/index.html b/plugins/sphinx/index.html index bcdf6a922..3fcb4494c 100755 --- a/plugins/sphinx/index.html +++ b/plugins/sphinx/index.html @@ -7,7 +7,7 @@

    运行日志

    查询日志

    运行状态

    -

    重建索引

    +

    常用功能

    说明

diff --git a/plugins/sphinx/index.py b/plugins/sphinx/index.py index 0ae17d7b4..0903cd9c7 100755 --- a/plugins/sphinx/index.py +++ b/plugins/sphinx/index.py @@ -15,14 +15,13 @@ app_debug = False if mw.isAppleSystem(): app_debug = True - def getPluginName(): return 'sphinx' - def getPluginDir(): return mw.getPluginDir() + '/' + getPluginName() +sys.path.append(getPluginDir() +"/class") def getServerDir(): return mw.getServerDir() + '/' + getPluginName() @@ -318,6 +317,29 @@ def sphinxCmd(): else: return mw.returnJson(False, 'no index') +def makeDbToSphinx(): + + + import sphinx_make + pdb = sphinx_make.pMysqlDb() + + filter_db = ['information_schema','performance_schema','sys','mysql'] + + db_list = pdb.query('show databases') + print(db_list) + + for x in range(len(db_list)): + dbname = db_list[x]['Database'] + if mw.inArray(filter_db, dbname): + continue + + sphinx_make.makeSqlToSphinxDb(dbname) + + print(dbname) + + # makeSqlToSphinxTable() + + if __name__ == "__main__": func = sys.argv[1] @@ -353,5 +375,7 @@ if __name__ == "__main__": print(runStatus()) elif func == 'sphinx_cmd': print(sphinxCmd()) + elif func == 'db_to_sphinx': + print(makeDbToSphinx()) else: print('error') diff --git a/plugins/sphinx/install.sh b/plugins/sphinx/install.sh index 25d81d21c..3b636167f 100755 --- a/plugins/sphinx/install.sh +++ b/plugins/sphinx/install.sh @@ -12,6 +12,7 @@ install_tmp=${rootPath}/tmp/mw_install.pl # cd /www/server/mdserver-web && source bin/activate && python3 plugins/sphinx/index.py rebuild # /www/server/sphinx/bin/bin/indexer -c /www/server/sphinx/sphinx.conf --rotate +# cd /www/server/mdserver-web && source bin/activate && python3 plugins/sphinx/index.py db_to_sphinx bash ${rootPath}/scripts/getos.sh diff --git a/plugins/sphinx/js/sphinx.js b/plugins/sphinx/js/sphinx.js index 770caea46..43294e24d 100755 --- a/plugins/sphinx/js/sphinx.js +++ b/plugins/sphinx/js/sphinx.js @@ -30,7 +30,7 @@ function spPost(method, args, callback){ }); } -function rebuild(){ +function commonFunc(){ var con = ''; $(".soft-man-con").html(con); } From 5a0e7a3b600e3228c29c0b908563af2025b60b21 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 15:09:25 +0800 Subject: [PATCH 221/327] update --- plugins/mysql/index.py | 9 ++++++++- plugins/mysql/install.sh | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 6f409ce3b..d97e3d1f1 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -3734,9 +3734,16 @@ def fullSync(version=''): def installPreInspection(version): + import psutil + mem = psutil.virtual_memory() + memTotal = mem.total + memG = memTotal/1024/1024/1024 + if memG > 2: + return 'ok' + swap_path = mw.getServerDir() + "/swap" if not os.path.exists(swap_path): - return "为了稳定安装MySQL,先安装swap插件!" + return "内存小,为了稳定安装MySQL,先安装swap插件!" return 'ok' diff --git a/plugins/mysql/install.sh b/plugins/mysql/install.sh index a902ff4eb..45718b124 100755 --- a/plugins/mysql/install.sh +++ b/plugins/mysql/install.sh @@ -10,6 +10,7 @@ export PATH # cd /www/server/mdserver-web && source bin/activate && python3 plugins/mysql/index.py do_full_sync {"db":"xxx","sign":"","begin":1} # cd /www/server/mdserver-web && source bin/activate && python3 plugins/mysql/index.py sync_database_repair {"db":"xxx","sign":""} # cd /www/server/mdserver-web && source bin/activate && python3 plugins/mysql/index.py init_slave_status +# cd /www/server/mdserver-web && source bin/activate && python3 plugins/mysql/index.py install_pre_inspection curPath=`pwd` rootPath=$(dirname "$curPath") rootPath=$(dirname "$rootPath") From 0046d02ddf2513fb2a8b9dcd0f3e52b54c4fd654 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 16:24:33 +0800 Subject: [PATCH 222/327] update --- plugins/sphinx/class/sphinx_make.py | 183 ++++++++++++++++++++++++---- plugins/sphinx/index.py | 22 ++-- plugins/sphinx/install.sh | 2 +- 3 files changed, 164 insertions(+), 43 deletions(-) diff --git a/plugins/sphinx/class/sphinx_make.py b/plugins/sphinx/class/sphinx_make.py index 94ff3bddf..5d2b9b1ea 100644 --- a/plugins/sphinx/class/sphinx_make.py +++ b/plugins/sphinx/class/sphinx_make.py @@ -54,12 +54,151 @@ def pMysqlDb(): db.setPwd(pSqliteDb('config').where('id=?', (1,)).getField('mysql_root')) return db +def getTablePk(db, table): + pdb = pMysqlDb() + pkey_sql = "SHOW INDEX FROM {}.{} WHERE Key_name = 'PRIMARY';".format(db,table,); + pkey_data = pdb.query(pkey_sql) + + if len(pkey_data) == 1: + return pkey_data[0]['Column_name'] + + return '' + +def getTableFieldStr(db, table): + pdb = pMysqlDb() + sql = "select COLUMN_NAME,DATA_TYPE from information_schema.COLUMNS where `TABLE_SCHEMA`='{}' and `TABLE_NAME` = '{}';" + sql = sql.format(db,table,) + fields = pdb.query(sql) + + field_str = '' + for x in range(len(fields)): + field_str += fields[x]['COLUMN_NAME']+',' + + field_str = field_str.strip(',') + return field_str + + def makeSqlToSphinx(): pass -def makeSqlToSphinxDb(db, table = []): +def makeSphinxHeader(): + conf = ''' +indexer +{ + mem_limit = 128M +} + + searchd +{ + listen = 9312 + listen = 9306:mysql41 + log = {$server_dir}/sphinx/index/searchd.log + query_log = {$server_dir}/sphinx/index/query.log + read_timeout = 5 + max_children = 0 + pid_file = {$server_dir}/sphinx/index/searchd.pid + seamless_rotate = 1 + preopen_indexes = 1 + unlink_old = 1 + #workers = threads # for RT to work + binlog_path = {$server_dir}/sphinx/index/binlog +} + ''' + conf = conf.replace("{$server_dir}", mw.getServerDir()) + return conf + +def makeSphinxDbSourceRangeSql(db, table): + pdb = pMysqlDb() + pkey_name = getTablePk(db, table) + sql = "SELECT min("+pkey_name+"), max("+pkey_name+") FROM "+table + return sql + +def makeSphinxDbSourceQuerySql(db, table): pdb = pMysqlDb() + pkey_name = getTablePk(db, table) + field_str = getTableFieldStr(db,table) + # print(field_str) + sql = "SELECT "+field_str+" FROM "+table+ " where "+pkey_name+" >= $start AND "+pkey_name+" <= $end" + return sql + +def makeSphinxDbSource(db, table): + + db_info = pSqliteDb('databases').field('username,password').where('name=?', (db,)).find() + port = getDbPort() + + conf = ''' + +source {$DB_NAME}_{$TABLE_NAME} +{ + type = mysql + sql_host = 127.0.0.1 + sql_user = {$DB_USER} + sql_pass = {$DB_PASS} + sql_db = {$DB_NAME} + sql_port = {$DB_PORT} + + sql_query_range = {$DB_RANGE_SQL} + sql_range_step = 1000 + + sql_query_pre = SET NAMES utf8bm4 + sql_query = {$DB_QUERY_SQL} + +{$SPH_FIELD} +} + +index {$DB_NAME}_{$TABLE_NAME} +{ + source = {$DB_NAME}_{$TABLE_NAME} + path = {$server_dir}/sphinx/index/db/{$DB_NAME}.{$TABLE_NAME}/index + + ngram_len = 1 + ngram_chars = U+3000..U+2FA1F +} +''' + conf = conf.replace("{$server_dir}", mw.getServerDir()) + + conf = conf.replace("{$DB_NAME}", db) + conf = conf.replace("{$TABLE_NAME}", table) + conf = conf.replace("{$DB_USER}", db_info['username']) + conf = conf.replace("{$DB_PASS}", db_info['password']) + conf = conf.replace("{$DB_PORT}", port) + + range_sql = makeSphinxDbSourceRangeSql(db,table) + conf = conf.replace("{$DB_RANGE_SQL}", range_sql) + query_sql = makeSphinxDbSourceQuerySql(db,table) + conf = conf.replace("{$DB_QUERY_SQL}", query_sql) + + sph_field = makeSqlToSphinxTable(db,table) + conf = conf.replace("{$SPH_FIELD}", sph_field) + + + + return conf + + +def makeSqlToSphinxAll(): + + filter_db = ['information_schema','performance_schema','sys','mysql'] + + pdb = pMysqlDb() + dblist = pdb.query('show databases') + + conf = '' + conf += makeSphinxHeader() + for x in range(len(dblist)): + dbname = dblist[x]['Database'] + if mw.inArray(filter_db, dbname): + continue + conf += makeSqlToSphinxDb(dbname) + return conf + + + +def makeSqlToSphinxDb(db, table = []): + conf = '' + + pdb = pMysqlDb() tables = pdb.query("show tables in "+ db) for x in range(len(tables)): key = 'Tables_in_'+db @@ -69,19 +208,12 @@ def makeSqlToSphinxDb(db, table = []): if pkey_name == '': continue + conf += makeSphinxDbSource(db,table_name) + # print(conf) # print(table_name+':'+pkey_name) - makeSqlToSphinxTable(db,table_name) - - -def getTablePk(db, table): - pdb = pMysqlDb() - pkey_sql = "SHOW INDEX FROM {}.{} WHERE Key_name = 'PRIMARY';".format(db,table,); - pkey_data = pdb.query(pkey_sql) - - if len(pkey_data) == 1: - return pkey_data[0]['Column_name'] - - return '' + # db_field_str = makeSqlToSphinxTable(db,table_name) + # print(db_field_str) + return conf def makeSqlToSphinxTable(db,table): pdb = pMysqlDb() @@ -95,46 +227,43 @@ def makeSqlToSphinxTable(db,table): for x in range(cols_len): data_type = cols[x]['DATA_TYPE'] column_name = cols[x]['COLUMN_NAME'] - print(column_name+":"+data_type) + # print(column_name+":"+data_type) # if mw.inArray(['tinyint'], data_type): # conf += 'sql_attr_bool = '+ column_name + "\n" if mw.inArray(['enum'], data_type): run_pos += 1 - conf += 'sql_attr_string = '+ column_name + "\n" + conf += '\tsql_attr_string = '+ column_name + "\n" if mw.inArray(['decimal'], data_type): run_pos += 1 - conf += 'sql_attr_float = '+ column_name + "\n" + conf += '\tsql_attr_float = '+ column_name + "\n" if mw.inArray(['bigint','smallint','tinyint','int','mediumint'], data_type): run_pos += 1 - conf += 'sql_attr_bigint = '+ column_name + "\n" + conf += '\tsql_attr_bigint = '+ column_name + "\n" if mw.inArray(['float'], data_type): run_pos += 1 - conf += 'sql_attr_float = '+ column_name + "\n" + conf += '\tsql_attr_float = '+ column_name + "\n" if mw.inArray(['varchar','char'], data_type): run_pos += 1 - conf += 'sql_attr_string = '+ column_name + "\n" + conf += '\tsql_attr_string = '+ column_name + "\n" if mw.inArray(['text','mediumtext','tinytext','longtext'], data_type): run_pos += 1 - conf += 'sql_field_string = '+ column_name + "\n" + conf += '\tsql_field_string = '+ column_name + "\n" if mw.inArray(['datetime','date'], data_type): run_pos += 1 - conf += 'sql_attr_timestamp = '+ column_name + "\n" - - if cols_len != run_pos: - print(db,table) - - print(cols_len,run_pos) - + conf += '\tsql_attr_timestamp = '+ column_name + "\n" + # if cols_len != run_pos: + # print(db,table) + # print(cols_len,run_pos) # print(conf) return conf diff --git a/plugins/sphinx/index.py b/plugins/sphinx/index.py index 0903cd9c7..8c8ddb70b 100755 --- a/plugins/sphinx/index.py +++ b/plugins/sphinx/index.py @@ -210,6 +210,7 @@ def reload(): def rebuild(): file = initDreplace() cmd = file + ' rebuild &' + # print(cmd) data = mw.execShell(cmd) if data[0].find('successfully')<0: return data[0].replace("\n","
") @@ -319,25 +320,16 @@ def sphinxCmd(): def makeDbToSphinx(): + sphinx_file = getConf() - import sphinx_make - pdb = sphinx_make.pMysqlDb() - - filter_db = ['information_schema','performance_schema','sys','mysql'] - - db_list = pdb.query('show databases') - print(db_list) - for x in range(len(db_list)): - dbname = db_list[x]['Database'] - if mw.inArray(filter_db, dbname): - continue - - sphinx_make.makeSqlToSphinxDb(dbname) + import sphinx_make + conf = sphinx_make.makeSqlToSphinxAll() - print(dbname) + mw.writeFile(sphinx_file,conf) + print(conf) - # makeSqlToSphinxTable() + # makeSqlToSphinxTable() diff --git a/plugins/sphinx/install.sh b/plugins/sphinx/install.sh index 3b636167f..831b7e0c6 100755 --- a/plugins/sphinx/install.sh +++ b/plugins/sphinx/install.sh @@ -11,7 +11,7 @@ sysName=`uname` install_tmp=${rootPath}/tmp/mw_install.pl # cd /www/server/mdserver-web && source bin/activate && python3 plugins/sphinx/index.py rebuild -# /www/server/sphinx/bin/bin/indexer -c /www/server/sphinx/sphinx.conf --rotate +# /www/server/sphinx/bin/bin/indexer -c /www/server/sphinx/sphinx.conf --all --rotate # cd /www/server/mdserver-web && source bin/activate && python3 plugins/sphinx/index.py db_to_sphinx From bf859f7c7c0a65a1d05a83fbcb2e72a9cffb4046 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 16:29:16 +0800 Subject: [PATCH 223/327] Update sphinx_make.py --- plugins/sphinx/class/sphinx_make.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/plugins/sphinx/class/sphinx_make.py b/plugins/sphinx/class/sphinx_make.py index 5d2b9b1ea..2091ab52b 100644 --- a/plugins/sphinx/class/sphinx_make.py +++ b/plugins/sphinx/class/sphinx_make.py @@ -77,10 +77,6 @@ def getTableFieldStr(db, table): field_str = field_str.strip(',') return field_str - -def makeSqlToSphinx(): - pass - def makeSphinxHeader(): conf = ''' indexer @@ -140,7 +136,7 @@ source {$DB_NAME}_{$TABLE_NAME} sql_query_range = {$DB_RANGE_SQL} sql_range_step = 1000 - sql_query_pre = SET NAMES utf8bm4 + sql_query_pre = SET NAMES utf8 sql_query = {$DB_QUERY_SQL} {$SPH_FIELD} @@ -172,8 +168,6 @@ index {$DB_NAME}_{$TABLE_NAME} sph_field = makeSqlToSphinxTable(db,table) conf = conf.replace("{$SPH_FIELD}", sph_field) - - return conf From 53134b7ecc49a07e0f558ab10d461668ccd23b16 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 16:36:14 +0800 Subject: [PATCH 224/327] Update sphinx_make.py --- plugins/sphinx/class/sphinx_make.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/sphinx/class/sphinx_make.py b/plugins/sphinx/class/sphinx_make.py index 2091ab52b..c85e3f588 100644 --- a/plugins/sphinx/class/sphinx_make.py +++ b/plugins/sphinx/class/sphinx_make.py @@ -72,7 +72,7 @@ def getTableFieldStr(db, table): field_str = '' for x in range(len(fields)): - field_str += fields[x]['COLUMN_NAME']+',' + field_str += '`'+fields[x]['COLUMN_NAME']+'`,' field_str = field_str.strip(',') return field_str From 7c96bbe72fcf411ff51b1a65e7cff9258a32c82e Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 16:56:27 +0800 Subject: [PATCH 225/327] Update sphinx_make.py --- plugins/sphinx/class/sphinx_make.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/plugins/sphinx/class/sphinx_make.py b/plugins/sphinx/class/sphinx_make.py index c85e3f588..98e3e2a57 100644 --- a/plugins/sphinx/class/sphinx_make.py +++ b/plugins/sphinx/class/sphinx_make.py @@ -56,11 +56,21 @@ def pMysqlDb(): def getTablePk(db, table): pdb = pMysqlDb() + # SHOW INDEX FROM bbs.bbs_ucenter_vars WHERE Key_name = 'PRIMARY' pkey_sql = "SHOW INDEX FROM {}.{} WHERE Key_name = 'PRIMARY';".format(db,table,); pkey_data = pdb.query(pkey_sql) if len(pkey_data) == 1: - return pkey_data[0]['Column_name'] + pkey_name = pkey_data[0]['Column_name'] + sql = "select COLUMN_NAME,DATA_TYPE from information_schema.COLUMNS where `TABLE_SCHEMA`='{}' and `TABLE_NAME` = '{}' and `COLUMN_NAME`='{}';" + sql = sql.format(db,table,pkey_name,) + # print(sql) + fields = pdb.query(sql) + + if len(fields) == 1: + # print(fields[0]['DATA_TYPE']) + if mw.inArray(['bigint','smallint','tinyint','int','mediumint'], fields[0]['DATA_TYPE']): + return pkey_name return '' From c90d752ae7a01dce028b7d162e187d27d7610809 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 17:21:19 +0800 Subject: [PATCH 226/327] update --- plugins/sphinx/class/sphinx_make.py | 6 ++++-- plugins/sphinx/install.sh | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/sphinx/class/sphinx_make.py b/plugins/sphinx/class/sphinx_make.py index 98e3e2a57..147151edc 100644 --- a/plugins/sphinx/class/sphinx_make.py +++ b/plugins/sphinx/class/sphinx_make.py @@ -124,7 +124,10 @@ def makeSphinxDbSourceQuerySql(db, table): pkey_name = getTablePk(db, table) field_str = getTableFieldStr(db,table) # print(field_str) - sql = "SELECT "+field_str+" FROM "+table+ " where "+pkey_name+" >= $start AND "+pkey_name+" <= $end" + if pkey_name == 'id': + sql = "SELECT " + field_str + " FROM " + table + " where id >= $start AND id <= $end" + else: + sql = "SELECT "+pkey_name+' as id,' + field_str + " FROM " + table + " where id >= $start AND id <= $end" return sql def makeSphinxDbSource(db, table): @@ -182,7 +185,6 @@ index {$DB_NAME}_{$TABLE_NAME} def makeSqlToSphinxAll(): - filter_db = ['information_schema','performance_schema','sys','mysql'] pdb = pMysqlDb() diff --git a/plugins/sphinx/install.sh b/plugins/sphinx/install.sh index 831b7e0c6..c9db0833a 100755 --- a/plugins/sphinx/install.sh +++ b/plugins/sphinx/install.sh @@ -11,9 +11,10 @@ sysName=`uname` install_tmp=${rootPath}/tmp/mw_install.pl # cd /www/server/mdserver-web && source bin/activate && python3 plugins/sphinx/index.py rebuild -# /www/server/sphinx/bin/bin/indexer -c /www/server/sphinx/sphinx.conf --all --rotate -# cd /www/server/mdserver-web && source bin/activate && python3 plugins/sphinx/index.py db_to_sphinx +# cd /www/server/mdserver-web && source bin/activate && python3 plugins/sphinx/index.py db_to_sphinx +# /www/server/sphinx/bin/bin/indexer -c /www/server/sphinx/sphinx.conf --all --rotate +# /Users/midoks/Desktop/mwdev/server/sphinx/bin/bin/indexer /Users/midoks/Desktop/mwdev/server/sphinx/sphinx.conf --all --rotate bash ${rootPath}/scripts/getos.sh OSNAME=`cat ${rootPath}/data/osname.pl` From 8e47c73f5c64bb9cf06273108e597d7ab523e325 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 17:27:22 +0800 Subject: [PATCH 227/327] Update sphinx_make.py --- plugins/sphinx/class/sphinx_make.py | 38 ++++++++++++----------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/plugins/sphinx/class/sphinx_make.py b/plugins/sphinx/class/sphinx_make.py index 147151edc..f24524ff5 100644 --- a/plugins/sphinx/class/sphinx_make.py +++ b/plugins/sphinx/class/sphinx_make.py @@ -54,8 +54,7 @@ def pMysqlDb(): db.setPwd(pSqliteDb('config').where('id=?', (1,)).getField('mysql_root')) return db -def getTablePk(db, table): - pdb = pMysqlDb() +def getTablePk(pdb, db, table): # SHOW INDEX FROM bbs.bbs_ucenter_vars WHERE Key_name = 'PRIMARY' pkey_sql = "SHOW INDEX FROM {}.{} WHERE Key_name = 'PRIMARY';".format(db,table,); pkey_data = pdb.query(pkey_sql) @@ -74,8 +73,7 @@ def getTablePk(db, table): return '' -def getTableFieldStr(db, table): - pdb = pMysqlDb() +def getTableFieldStr(pdb, db, table): sql = "select COLUMN_NAME,DATA_TYPE from information_schema.COLUMNS where `TABLE_SCHEMA`='{}' and `TABLE_NAME` = '{}';" sql = sql.format(db,table,) fields = pdb.query(sql) @@ -113,16 +111,14 @@ indexer conf = conf.replace("{$server_dir}", mw.getServerDir()) return conf -def makeSphinxDbSourceRangeSql(db, table): - pdb = pMysqlDb() - pkey_name = getTablePk(db, table) +def makeSphinxDbSourceRangeSql(pdb, db, table): + pkey_name = getTablePk(pdb, db, table) sql = "SELECT min("+pkey_name+"), max("+pkey_name+") FROM "+table return sql -def makeSphinxDbSourceQuerySql(db, table): - pdb = pMysqlDb() - pkey_name = getTablePk(db, table) - field_str = getTableFieldStr(db,table) +def makeSphinxDbSourceQuerySql(pdb, db, table): + pkey_name = getTablePk(pdb, db, table) + field_str = getTableFieldStr(pdb, db,table) # print(field_str) if pkey_name == 'id': sql = "SELECT " + field_str + " FROM " + table + " where id >= $start AND id <= $end" @@ -130,7 +126,7 @@ def makeSphinxDbSourceQuerySql(db, table): sql = "SELECT "+pkey_name+' as id,' + field_str + " FROM " + table + " where id >= $start AND id <= $end" return sql -def makeSphinxDbSource(db, table): +def makeSphinxDbSource(pdb, db, table): db_info = pSqliteDb('databases').field('username,password').where('name=?', (db,)).find() port = getDbPort() @@ -172,13 +168,13 @@ index {$DB_NAME}_{$TABLE_NAME} conf = conf.replace("{$DB_PASS}", db_info['password']) conf = conf.replace("{$DB_PORT}", port) - range_sql = makeSphinxDbSourceRangeSql(db,table) + range_sql = makeSphinxDbSourceRangeSql(pdb, db, table) conf = conf.replace("{$DB_RANGE_SQL}", range_sql) - query_sql = makeSphinxDbSourceQuerySql(db,table) + query_sql = makeSphinxDbSourceQuerySql(pdb, db,table) conf = conf.replace("{$DB_QUERY_SQL}", query_sql) - sph_field = makeSqlToSphinxTable(db,table) + sph_field = makeSqlToSphinxTable(pdb, db,table) conf = conf.replace("{$SPH_FIELD}", sph_field) return conf @@ -196,33 +192,31 @@ def makeSqlToSphinxAll(): dbname = dblist[x]['Database'] if mw.inArray(filter_db, dbname): continue - conf += makeSqlToSphinxDb(dbname) + conf += makeSqlToSphinxDb(pdb, dbname) return conf -def makeSqlToSphinxDb(db, table = []): +def makeSqlToSphinxDb(pdb, db, table = []): conf = '' - pdb = pMysqlDb() tables = pdb.query("show tables in "+ db) for x in range(len(tables)): key = 'Tables_in_'+db table_name = tables[x][key] - pkey_name = getTablePk(db,table_name) + pkey_name = getTablePk(pdb, db, table_name) if pkey_name == '': continue - conf += makeSphinxDbSource(db,table_name) + conf += makeSphinxDbSource(pdb, db, table_name) # print(conf) # print(table_name+':'+pkey_name) # db_field_str = makeSqlToSphinxTable(db,table_name) # print(db_field_str) return conf -def makeSqlToSphinxTable(db,table): - pdb = pMysqlDb() +def makeSqlToSphinxTable(pdb,db,table): sql = "select COLUMN_NAME,DATA_TYPE from information_schema.COLUMNS where `TABLE_SCHEMA`='{}' and `TABLE_NAME` = '{}';" sql = sql.format(db,table,) From 2f0797daabd012e40295596cfde5483ca44ce4d8 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 17:34:37 +0800 Subject: [PATCH 228/327] Update sphinx_make.py --- plugins/sphinx/class/sphinx_make.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/plugins/sphinx/class/sphinx_make.py b/plugins/sphinx/class/sphinx_make.py index f24524ff5..e8cd36293 100644 --- a/plugins/sphinx/class/sphinx_make.py +++ b/plugins/sphinx/class/sphinx_make.py @@ -217,6 +217,7 @@ def makeSqlToSphinxDb(pdb, db, table = []): return conf def makeSqlToSphinxTable(pdb,db,table): + pkey_name = getTablePk(pdb, db, table) sql = "select COLUMN_NAME,DATA_TYPE from information_schema.COLUMNS where `TABLE_SCHEMA`='{}' and `TABLE_NAME` = '{}';" sql = sql.format(db,table,) @@ -232,9 +233,19 @@ def makeSqlToSphinxTable(pdb,db,table): # if mw.inArray(['tinyint'], data_type): # conf += 'sql_attr_bool = '+ column_name + "\n" + if pkey_name == column_name: + run_pos += 1 + if pkey_name == 'id': + conf += '\tsql_attr_bigint = '+column_name+"\n" + else: + conf += '\tsql_attr_bigint = '+"id\n" + conf += '\tsql_attr_bigint = '+column_name+"\n" + continue + if mw.inArray(['enum'], data_type): run_pos += 1 conf += '\tsql_attr_string = '+ column_name + "\n" + continue if mw.inArray(['decimal'], data_type): run_pos += 1 @@ -243,23 +254,28 @@ def makeSqlToSphinxTable(pdb,db,table): if mw.inArray(['bigint','smallint','tinyint','int','mediumint'], data_type): run_pos += 1 conf += '\tsql_attr_bigint = '+ column_name + "\n" + continue if mw.inArray(['float'], data_type): run_pos += 1 conf += '\tsql_attr_float = '+ column_name + "\n" + continue if mw.inArray(['varchar','char'], data_type): run_pos += 1 conf += '\tsql_attr_string = '+ column_name + "\n" + continue if mw.inArray(['text','mediumtext','tinytext','longtext'], data_type): run_pos += 1 conf += '\tsql_field_string = '+ column_name + "\n" + continue if mw.inArray(['datetime','date'], data_type): run_pos += 1 conf += '\tsql_attr_timestamp = '+ column_name + "\n" + continue # if cols_len != run_pos: # print(db,table) From 79b4d09d500cdbc4b1126dbb80f0709f9a88d952 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 17:37:47 +0800 Subject: [PATCH 229/327] Update index.py --- plugins/sphinx/index.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/sphinx/index.py b/plugins/sphinx/index.py index 8c8ddb70b..894cf22da 100755 --- a/plugins/sphinx/index.py +++ b/plugins/sphinx/index.py @@ -319,17 +319,15 @@ def sphinxCmd(): return mw.returnJson(False, 'no index') def makeDbToSphinx(): - sphinx_file = getConf() - import sphinx_make conf = sphinx_make.makeSqlToSphinxAll() mw.writeFile(sphinx_file,conf) print(conf) - # makeSqlToSphinxTable() + return True From 706ee146b5c695a1a0196fca432365206d2ddc8c Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 17:43:52 +0800 Subject: [PATCH 230/327] Update sphinx_make.py --- plugins/sphinx/class/sphinx_make.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/sphinx/class/sphinx_make.py b/plugins/sphinx/class/sphinx_make.py index e8cd36293..1aa828895 100644 --- a/plugins/sphinx/class/sphinx_make.py +++ b/plugins/sphinx/class/sphinx_make.py @@ -116,8 +116,7 @@ def makeSphinxDbSourceRangeSql(pdb, db, table): sql = "SELECT min("+pkey_name+"), max("+pkey_name+") FROM "+table return sql -def makeSphinxDbSourceQuerySql(pdb, db, table): - pkey_name = getTablePk(pdb, db, table) +def makeSphinxDbSourceQuerySql(pdb, db, table,pkey_name): field_str = getTableFieldStr(pdb, db,table) # print(field_str) if pkey_name == 'id': @@ -130,6 +129,8 @@ def makeSphinxDbSource(pdb, db, table): db_info = pSqliteDb('databases').field('username,password').where('name=?', (db,)).find() port = getDbPort() + pkey_name = getTablePk(pdb, db, table) + conf = ''' @@ -171,10 +172,10 @@ index {$DB_NAME}_{$TABLE_NAME} range_sql = makeSphinxDbSourceRangeSql(pdb, db, table) conf = conf.replace("{$DB_RANGE_SQL}", range_sql) - query_sql = makeSphinxDbSourceQuerySql(pdb, db,table) + query_sql = makeSphinxDbSourceQuerySql(pdb, db,table,pkey_name) conf = conf.replace("{$DB_QUERY_SQL}", query_sql) - sph_field = makeSqlToSphinxTable(pdb, db,table) + sph_field = makeSqlToSphinxTable(pdb, db,table,pkey_name) conf = conf.replace("{$SPH_FIELD}", sph_field) return conf @@ -216,8 +217,7 @@ def makeSqlToSphinxDb(pdb, db, table = []): # print(db_field_str) return conf -def makeSqlToSphinxTable(pdb,db,table): - pkey_name = getTablePk(pdb, db, table) +def makeSqlToSphinxTable(pdb,db,table,pk): sql = "select COLUMN_NAME,DATA_TYPE from information_schema.COLUMNS where `TABLE_SCHEMA`='{}' and `TABLE_NAME` = '{}';" sql = sql.format(db,table,) @@ -233,7 +233,7 @@ def makeSqlToSphinxTable(pdb,db,table): # if mw.inArray(['tinyint'], data_type): # conf += 'sql_attr_bool = '+ column_name + "\n" - if pkey_name == column_name: + if pk == column_name: run_pos += 1 if pkey_name == 'id': conf += '\tsql_attr_bigint = '+column_name+"\n" From 2f4cf46bcf58d73e20c0ecf25b20d8308cf62e9c Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 17:45:27 +0800 Subject: [PATCH 231/327] Update sphinx_make.py --- plugins/sphinx/class/sphinx_make.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/sphinx/class/sphinx_make.py b/plugins/sphinx/class/sphinx_make.py index 1aa828895..36663a73d 100644 --- a/plugins/sphinx/class/sphinx_make.py +++ b/plugins/sphinx/class/sphinx_make.py @@ -217,7 +217,7 @@ def makeSqlToSphinxDb(pdb, db, table = []): # print(db_field_str) return conf -def makeSqlToSphinxTable(pdb,db,table,pk): +def makeSqlToSphinxTable(pdb,db,table,pkey_name): sql = "select COLUMN_NAME,DATA_TYPE from information_schema.COLUMNS where `TABLE_SCHEMA`='{}' and `TABLE_NAME` = '{}';" sql = sql.format(db,table,) @@ -233,7 +233,7 @@ def makeSqlToSphinxTable(pdb,db,table,pk): # if mw.inArray(['tinyint'], data_type): # conf += 'sql_attr_bool = '+ column_name + "\n" - if pk == column_name: + if pkey_name == column_name: run_pos += 1 if pkey_name == 'id': conf += '\tsql_attr_bigint = '+column_name+"\n" From 7e049a381b6427a6fa6a85e5b013cd91764d3d6f Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 17:45:39 +0800 Subject: [PATCH 232/327] Update sphinx_make.py --- plugins/sphinx/class/sphinx_make.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/sphinx/class/sphinx_make.py b/plugins/sphinx/class/sphinx_make.py index 36663a73d..b61dbcf76 100644 --- a/plugins/sphinx/class/sphinx_make.py +++ b/plugins/sphinx/class/sphinx_make.py @@ -235,7 +235,7 @@ def makeSqlToSphinxTable(pdb,db,table,pkey_name): if pkey_name == column_name: run_pos += 1 - if pkey_name == 'id': + if column_name == 'id': conf += '\tsql_attr_bigint = '+column_name+"\n" else: conf += '\tsql_attr_bigint = '+"id\n" From 2b019a704ae5371401d82deb0dbc57c6732705c5 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 17:47:27 +0800 Subject: [PATCH 233/327] Update sphinx_make.py --- plugins/sphinx/class/sphinx_make.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plugins/sphinx/class/sphinx_make.py b/plugins/sphinx/class/sphinx_make.py index b61dbcf76..34beef28b 100644 --- a/plugins/sphinx/class/sphinx_make.py +++ b/plugins/sphinx/class/sphinx_make.py @@ -125,11 +125,10 @@ def makeSphinxDbSourceQuerySql(pdb, db, table,pkey_name): sql = "SELECT "+pkey_name+' as id,' + field_str + " FROM " + table + " where id >= $start AND id <= $end" return sql -def makeSphinxDbSource(pdb, db, table): +def makeSphinxDbSource(pdb, db, table, pkey_name): db_info = pSqliteDb('databases').field('username,password').where('name=?', (db,)).find() port = getDbPort() - pkey_name = getTablePk(pdb, db, table) conf = ''' @@ -172,10 +171,10 @@ index {$DB_NAME}_{$TABLE_NAME} range_sql = makeSphinxDbSourceRangeSql(pdb, db, table) conf = conf.replace("{$DB_RANGE_SQL}", range_sql) - query_sql = makeSphinxDbSourceQuerySql(pdb, db,table,pkey_name) + query_sql = makeSphinxDbSourceQuerySql(pdb, db, table, pkey_name) conf = conf.replace("{$DB_QUERY_SQL}", query_sql) - sph_field = makeSqlToSphinxTable(pdb, db,table,pkey_name) + sph_field = makeSqlToSphinxTable(pdb, db, table, pkey_name) conf = conf.replace("{$SPH_FIELD}", sph_field) return conf @@ -210,7 +209,7 @@ def makeSqlToSphinxDb(pdb, db, table = []): if pkey_name == '': continue - conf += makeSphinxDbSource(pdb, db, table_name) + conf += makeSphinxDbSource(pdb, db, table_name, pkey_name) # print(conf) # print(table_name+':'+pkey_name) # db_field_str = makeSqlToSphinxTable(db,table_name) From 60747c2f04dbb1318ef73ae3e8dfe9174ea1623c Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 17:47:51 +0800 Subject: [PATCH 234/327] Update sphinx_make.py --- plugins/sphinx/class/sphinx_make.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/sphinx/class/sphinx_make.py b/plugins/sphinx/class/sphinx_make.py index 34beef28b..f16a2a3a3 100644 --- a/plugins/sphinx/class/sphinx_make.py +++ b/plugins/sphinx/class/sphinx_make.py @@ -111,8 +111,8 @@ indexer conf = conf.replace("{$server_dir}", mw.getServerDir()) return conf -def makeSphinxDbSourceRangeSql(pdb, db, table): - pkey_name = getTablePk(pdb, db, table) +def makeSphinxDbSourceRangeSql(pdb, db, table, pkey_name): + # pkey_name = getTablePk(pdb, db, table) sql = "SELECT min("+pkey_name+"), max("+pkey_name+") FROM "+table return sql From 2742ecfc67bcc3f0373601614f153ecdb840ecd4 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 17:49:08 +0800 Subject: [PATCH 235/327] Update sphinx_make.py --- plugins/sphinx/class/sphinx_make.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/sphinx/class/sphinx_make.py b/plugins/sphinx/class/sphinx_make.py index f16a2a3a3..c5f12097b 100644 --- a/plugins/sphinx/class/sphinx_make.py +++ b/plugins/sphinx/class/sphinx_make.py @@ -168,7 +168,7 @@ index {$DB_NAME}_{$TABLE_NAME} conf = conf.replace("{$DB_PASS}", db_info['password']) conf = conf.replace("{$DB_PORT}", port) - range_sql = makeSphinxDbSourceRangeSql(pdb, db, table) + range_sql = makeSphinxDbSourceRangeSql(pdb, db, table,pkey_name) conf = conf.replace("{$DB_RANGE_SQL}", range_sql) query_sql = makeSphinxDbSourceQuerySql(pdb, db, table, pkey_name) From a6d96bb4d8e849c104f03326c54ad2c64cbcf607 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 17:57:27 +0800 Subject: [PATCH 236/327] Update sphinx_make.py --- plugins/sphinx/class/sphinx_make.py | 37 +++++++++++++++++------------ 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/plugins/sphinx/class/sphinx_make.py b/plugins/sphinx/class/sphinx_make.py index c5f12097b..bf2ed8b94 100644 --- a/plugins/sphinx/class/sphinx_make.py +++ b/plugins/sphinx/class/sphinx_make.py @@ -188,11 +188,15 @@ def makeSqlToSphinxAll(): conf = '' conf += makeSphinxHeader() - for x in range(len(dblist)): - dbname = dblist[x]['Database'] - if mw.inArray(filter_db, dbname): - continue - conf += makeSqlToSphinxDb(pdb, dbname) + + conf += makeSqlToSphinxDb(pdb, 'bbs', ['bbs_bbs_ucenter_pm_messages_9']) + + + # for x in range(len(dblist)): + # dbname = dblist[x]['Database'] + # if mw.inArray(filter_db, dbname): + # continue + # conf += makeSqlToSphinxDb(pdb, dbname) return conf @@ -200,20 +204,23 @@ def makeSqlToSphinxAll(): def makeSqlToSphinxDb(pdb, db, table = []): conf = '' - tables = pdb.query("show tables in "+ db) - for x in range(len(tables)): - key = 'Tables_in_'+db - table_name = tables[x][key] + for t in table: pkey_name = getTablePk(pdb, db, table_name) - if pkey_name == '': continue - conf += makeSphinxDbSource(pdb, db, table_name, pkey_name) - # print(conf) - # print(table_name+':'+pkey_name) - # db_field_str = makeSqlToSphinxTable(db,table_name) - # print(db_field_str) + + if len(table) == 0: + tables = pdb.query("show tables in "+ db) + for x in range(len(tables)): + key = 'Tables_in_'+db + table_name = tables[x][key] + pkey_name = getTablePk(pdb, db, table_name) + + if pkey_name == '': + continue + + conf += makeSphinxDbSource(pdb, db, table_name, pkey_name) return conf def makeSqlToSphinxTable(pdb,db,table,pkey_name): From 45b7abd0fb84c365487b2590483ed699e8ebad1d Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 17:58:50 +0800 Subject: [PATCH 237/327] Update sphinx_make.py --- plugins/sphinx/class/sphinx_make.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/sphinx/class/sphinx_make.py b/plugins/sphinx/class/sphinx_make.py index bf2ed8b94..47e44393e 100644 --- a/plugins/sphinx/class/sphinx_make.py +++ b/plugins/sphinx/class/sphinx_make.py @@ -205,10 +205,10 @@ def makeSqlToSphinxDb(pdb, db, table = []): conf = '' for t in table: - pkey_name = getTablePk(pdb, db, table_name) + pkey_name = getTablePk(pdb, db, t) if pkey_name == '': continue - conf += makeSphinxDbSource(pdb, db, table_name, pkey_name) + conf += makeSphinxDbSource(pdb, db, t, pkey_name) if len(table) == 0: tables = pdb.query("show tables in "+ db) From 57e7021be2d91f81873f74180499b3d8aa73c979 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 18:10:54 +0800 Subject: [PATCH 238/327] Update sphinx_make.py --- plugins/sphinx/class/sphinx_make.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/sphinx/class/sphinx_make.py b/plugins/sphinx/class/sphinx_make.py index 47e44393e..85d77ff23 100644 --- a/plugins/sphinx/class/sphinx_make.py +++ b/plugins/sphinx/class/sphinx_make.py @@ -59,6 +59,9 @@ def getTablePk(pdb, db, table): pkey_sql = "SHOW INDEX FROM {}.{} WHERE Key_name = 'PRIMARY';".format(db,table,); pkey_data = pdb.query(pkey_sql) + # print(db, table) + # print(pkey_data) + if len(pkey_data) == 1: pkey_name = pkey_data[0]['Column_name'] sql = "select COLUMN_NAME,DATA_TYPE from information_schema.COLUMNS where `TABLE_SCHEMA`='{}' and `TABLE_NAME` = '{}' and `COLUMN_NAME`='{}';" @@ -92,7 +95,7 @@ indexer mem_limit = 128M } - searchd +searchd { listen = 9312 listen = 9306:mysql41 @@ -122,7 +125,7 @@ def makeSphinxDbSourceQuerySql(pdb, db, table,pkey_name): if pkey_name == 'id': sql = "SELECT " + field_str + " FROM " + table + " where id >= $start AND id <= $end" else: - sql = "SELECT "+pkey_name+' as id,' + field_str + " FROM " + table + " where id >= $start AND id <= $end" + sql = "SELECT "+pkey_name+' as id,' + field_str + " FROM " + table + " where "+pkey_name+" >= $start AND "+pkey_name+" <= $end" return sql def makeSphinxDbSource(pdb, db, table, pkey_name): @@ -189,7 +192,7 @@ def makeSqlToSphinxAll(): conf = '' conf += makeSphinxHeader() - conf += makeSqlToSphinxDb(pdb, 'bbs', ['bbs_bbs_ucenter_pm_messages_9']) + conf += makeSqlToSphinxDb(pdb, 'bbs', ['bbs_ucenter_admins']) # for x in range(len(dblist)): From 70370fcb0b8dba07615a2b42b1bb0ea859295e26 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 18:19:57 +0800 Subject: [PATCH 239/327] Update sphinx_make.py --- plugins/sphinx/class/sphinx_make.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/plugins/sphinx/class/sphinx_make.py b/plugins/sphinx/class/sphinx_make.py index 85d77ff23..6b18988b9 100644 --- a/plugins/sphinx/class/sphinx_make.py +++ b/plugins/sphinx/class/sphinx_make.py @@ -244,11 +244,7 @@ def makeSqlToSphinxTable(pdb,db,table,pkey_name): if pkey_name == column_name: run_pos += 1 - if column_name == 'id': - conf += '\tsql_attr_bigint = '+column_name+"\n" - else: - conf += '\tsql_attr_bigint = '+"id\n" - conf += '\tsql_attr_bigint = '+column_name+"\n" + conf += '\tsql_attr_bigint = '+column_name+"\n" continue if mw.inArray(['enum'], data_type): From abcf6250e381f4b03f8993690236ed66a38754d5 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 18:20:10 +0800 Subject: [PATCH 240/327] Update sphinx_make.py --- plugins/sphinx/class/sphinx_make.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/sphinx/class/sphinx_make.py b/plugins/sphinx/class/sphinx_make.py index 6b18988b9..2609030e8 100644 --- a/plugins/sphinx/class/sphinx_make.py +++ b/plugins/sphinx/class/sphinx_make.py @@ -192,7 +192,7 @@ def makeSqlToSphinxAll(): conf = '' conf += makeSphinxHeader() - conf += makeSqlToSphinxDb(pdb, 'bbs', ['bbs_ucenter_admins']) + conf += makeSqlToSphinxDb(pdb, 'bbs') # for x in range(len(dblist)): From 390df934771716edcb9b13b3fa3adb0f0fce9874 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 18:20:55 +0800 Subject: [PATCH 241/327] Update sphinx_make.py --- plugins/sphinx/class/sphinx_make.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/sphinx/class/sphinx_make.py b/plugins/sphinx/class/sphinx_make.py index 2609030e8..c90b23543 100644 --- a/plugins/sphinx/class/sphinx_make.py +++ b/plugins/sphinx/class/sphinx_make.py @@ -267,11 +267,15 @@ def makeSqlToSphinxTable(pdb,db,table,pkey_name): conf += '\tsql_attr_float = '+ column_name + "\n" continue - if mw.inArray(['varchar','char'], data_type): - run_pos += 1 + if mw.inArray(['char'], data_type): conf += '\tsql_attr_string = '+ column_name + "\n" continue + if mw.inArray(['varchar'], data_type): + run_pos += 1 + conf += '\tsql_field_string = '+ column_name + "\n" + continue + if mw.inArray(['text','mediumtext','tinytext','longtext'], data_type): run_pos += 1 conf += '\tsql_field_string = '+ column_name + "\n" From 7503907f342f8db5a5e31e6b769709cc549b90ba Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 18:22:13 +0800 Subject: [PATCH 242/327] Update sphinx_make.py --- plugins/sphinx/class/sphinx_make.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/sphinx/class/sphinx_make.py b/plugins/sphinx/class/sphinx_make.py index c90b23543..a6ca679ad 100644 --- a/plugins/sphinx/class/sphinx_make.py +++ b/plugins/sphinx/class/sphinx_make.py @@ -125,7 +125,7 @@ def makeSphinxDbSourceQuerySql(pdb, db, table,pkey_name): if pkey_name == 'id': sql = "SELECT " + field_str + " FROM " + table + " where id >= $start AND id <= $end" else: - sql = "SELECT "+pkey_name+' as id,' + field_str + " FROM " + table + " where "+pkey_name+" >= $start AND "+pkey_name+" <= $end" + sql = "SELECT `"+pkey_name+'` as `id`,' + field_str + " FROM " + table + " where "+pkey_name+" >= $start AND "+pkey_name+" <= $end" return sql def makeSphinxDbSource(pdb, db, table, pkey_name): From b4e130c6640e9e23003ff1b070f71832f7c19b96 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 18:25:51 +0800 Subject: [PATCH 243/327] Update sphinx_make.py --- plugins/sphinx/class/sphinx_make.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/plugins/sphinx/class/sphinx_make.py b/plugins/sphinx/class/sphinx_make.py index a6ca679ad..c715283f3 100644 --- a/plugins/sphinx/class/sphinx_make.py +++ b/plugins/sphinx/class/sphinx_make.py @@ -192,14 +192,13 @@ def makeSqlToSphinxAll(): conf = '' conf += makeSphinxHeader() - conf += makeSqlToSphinxDb(pdb, 'bbs') + # conf += makeSqlToSphinxDb(pdb, 'bbs') - - # for x in range(len(dblist)): - # dbname = dblist[x]['Database'] - # if mw.inArray(filter_db, dbname): - # continue - # conf += makeSqlToSphinxDb(pdb, dbname) + for x in range(len(dblist)): + dbname = dblist[x]['Database'] + if mw.inArray(filter_db, dbname): + continue + conf += makeSqlToSphinxDb(pdb, dbname) return conf From d0ba1429336d7599d45e0b64f8b040b16ebb0ad1 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 18:42:43 +0800 Subject: [PATCH 244/327] Update sphinx_make.py --- plugins/sphinx/class/sphinx_make.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/sphinx/class/sphinx_make.py b/plugins/sphinx/class/sphinx_make.py index c715283f3..8abc11f00 100644 --- a/plugins/sphinx/class/sphinx_make.py +++ b/plugins/sphinx/class/sphinx_make.py @@ -193,7 +193,6 @@ def makeSqlToSphinxAll(): conf += makeSphinxHeader() # conf += makeSqlToSphinxDb(pdb, 'bbs') - for x in range(len(dblist)): dbname = dblist[x]['Database'] if mw.inArray(filter_db, dbname): @@ -242,8 +241,8 @@ def makeSqlToSphinxTable(pdb,db,table,pkey_name): # conf += 'sql_attr_bool = '+ column_name + "\n" if pkey_name == column_name: - run_pos += 1 - conf += '\tsql_attr_bigint = '+column_name+"\n" + # run_pos += 1 + # conf += '\tsql_attr_bigint = '+column_name+"\n" continue if mw.inArray(['enum'], data_type): From d8e08812f93af03df2bac765af591c7b115878f1 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 19:49:15 +0800 Subject: [PATCH 245/327] update --- plugins/sphinx/class/sphinx_make.py | 20 +++++++++++++++++++- plugins/sphinx/install.sh | 4 ++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/plugins/sphinx/class/sphinx_make.py b/plugins/sphinx/class/sphinx_make.py index 8abc11f00..e8a86f6fc 100644 --- a/plugins/sphinx/class/sphinx_make.py +++ b/plugins/sphinx/class/sphinx_make.py @@ -182,6 +182,23 @@ index {$DB_NAME}_{$TABLE_NAME} return conf +def makeSqlToSphinxTableIsHaveFulltext(pdb, db, table): + sql = "select COLUMN_NAME,DATA_TYPE from information_schema.COLUMNS where `TABLE_SCHEMA`='{}' and `TABLE_NAME` = '{}';" + sql = sql.format(db,table,) + cols = pdb.query(sql) + cols_len = len(cols) + + for x in range(cols_len): + data_type = cols[x]['DATA_TYPE'] + column_name = cols[x]['COLUMN_NAME'] + + if mw.inArray(['varchar'], data_type): + return True + + if mw.inArray(['text','mediumtext','tinytext','longtext'], data_type): + return True + + return False def makeSqlToSphinxAll(): filter_db = ['information_schema','performance_schema','sys','mysql'] @@ -221,7 +238,8 @@ def makeSqlToSphinxDb(pdb, db, table = []): if pkey_name == '': continue - conf += makeSphinxDbSource(pdb, db, table_name, pkey_name) + if makeSqlToSphinxTableIsHaveFulltext(pdb, db, table_name): + conf += makeSphinxDbSource(pdb, db, table_name, pkey_name) return conf def makeSqlToSphinxTable(pdb,db,table,pkey_name): diff --git a/plugins/sphinx/install.sh b/plugins/sphinx/install.sh index c9db0833a..231489a0d 100755 --- a/plugins/sphinx/install.sh +++ b/plugins/sphinx/install.sh @@ -13,8 +13,8 @@ install_tmp=${rootPath}/tmp/mw_install.pl # cd /www/server/mdserver-web && source bin/activate && python3 plugins/sphinx/index.py rebuild # cd /www/server/mdserver-web && source bin/activate && python3 plugins/sphinx/index.py db_to_sphinx -# /www/server/sphinx/bin/bin/indexer -c /www/server/sphinx/sphinx.conf --all --rotate -# /Users/midoks/Desktop/mwdev/server/sphinx/bin/bin/indexer /Users/midoks/Desktop/mwdev/server/sphinx/sphinx.conf --all --rotate +# /www/server/sphinx/bin/bin/indexer -c /www/server/sphinx/sphinx.conf 99cms_mc_comic --rotate +# /Users/midoks/Desktop/mwdev/server/sphinx/bin/bin/indexer /Users/midoks/Desktop/mwdev/server/sphinx/sphinx.conf 99cms_mc_comic --rotate bash ${rootPath}/scripts/getos.sh OSNAME=`cat ${rootPath}/data/osname.pl` From fcfdfe822acee5c88b6976e1e75cf6d5cfa70171 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 21:36:25 +0800 Subject: [PATCH 246/327] up --- plugins/sphinx/info.json | 3 +- plugins/sphinx/install.sh | 100 ++++++++++++++++++++++++++++++-------- 2 files changed, 81 insertions(+), 22 deletions(-) diff --git a/plugins/sphinx/info.json b/plugins/sphinx/info.json index cecab533c..9150c8822 100755 --- a/plugins/sphinx/info.json +++ b/plugins/sphinx/info.json @@ -4,8 +4,7 @@ "name": "sphinx", "title": "sphinx", "shell": "install.sh", - "versions":["3.1.1"], - "updates":["3.1.1"], + "versions":["3.1.1","3.2.1","3.3.1","3.4.1","3.5.1","3.6.1","3.7.1"], "tip": "soft", "checks": "server/sphinx", "path": "server/sphinx", diff --git a/plugins/sphinx/install.sh b/plugins/sphinx/install.sh index 231489a0d..b9f3ec800 100755 --- a/plugins/sphinx/install.sh +++ b/plugins/sphinx/install.sh @@ -7,6 +7,7 @@ rootPath=$(dirname "$curPath") rootPath=$(dirname "$rootPath") serverPath=$(dirname "$rootPath") sysName=`uname` +sysArch=`arch` install_tmp=${rootPath}/tmp/mw_install.pl @@ -17,40 +18,90 @@ install_tmp=${rootPath}/tmp/mw_install.pl # /Users/midoks/Desktop/mwdev/server/sphinx/bin/bin/indexer /Users/midoks/Desktop/mwdev/server/sphinx/sphinx.conf 99cms_mc_comic --rotate bash ${rootPath}/scripts/getos.sh -OSNAME=`cat ${rootPath}/data/osname.pl` -OSNAME_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'` +echo "bash ${rootPath}/scripts/getos.sh" -if [ ${OSNAME} == "centos" ] || - [ ${OSNAME} == "fedora" ] || - [ ${OSNAME} == "alma" ]; then +OSNAME="macos" +if [ -f ${rootPath}/data/osname.pl ];then + OSNAME=`cat ${rootPath}/data/osname.pl` +fi + +if [ "${OSNAME}" == "centos" ] || + [ "${OSNAME}" == "fedora" ] || + [ "${OSNAME}" == "alma" ]; then yum install -y postgresql-libs unixODBC fi +# http://sphinxsearch.com/files/sphinx-3.7.1-da9f8a4-linux-amd64.tar.gz + +VERSION=$2 + +# echo $VERSION + +if [ "$VERSION" == "3.1.1" ];then + VERSION_NUM=${VERSION}-612d99f +elif [ "$VERSION" == "3.2.1" ]; then + VERSION_NUM=${VERSION}-f152e0b +elif [ "$VERSION" == "3.3.1" ]; then + VERSION_NUM=${VERSION}-b72d67b +elif [ "$VERSION" == "3.4.1" ]; then + VERSION_NUM=${VERSION}-efbcc65 +elif [ "$VERSION" == "3.5.1" ]; then + VERSION_NUM=${VERSION}-82c60cb +elif [ "$VERSION" == "3.6.1" ]; then + VERSION_NUM=${VERSION}-c9dbeda +elif [ "$VERSION" == "3.7.1" ]; then + VERSION_NUM=${VERSION}-da9f8a4 +fi + +# echo $VERSION_NUM -VERSION=3.1.1 Install_sphinx() { - echo '正在安装Sphinx...' mkdir -p $serverPath/sphinx SPHINX_DIR=${serverPath}/source/sphinx mkdir -p $SPHINX_DIR - - if [ ! -f ${SPHINX_DIR}/sphinx-${VERSION}.tar.gz ];then + + SPH_NAME=amd64 + if [ "$sysArch" == "arm64" ];then + SPH_NAME=amd64 + elif [ "$sysArch" == "x86_64" ]; then + SPH_NAME=amd64 + elif [ "$sysArch" == "aarch64" ]; then + SPH_NAME=aarch64 + fi + + if [ "$sysName" == "Darwin" ] && [ "$VERSION" == "3.7.1" ];then + SPH_NAME=aarch64 + fi + + SPH_SYSNAME=linux + if [ $sysName == 'Darwin' ]; then + SPH_SYSNAME=darwin + elif [ "$sysName" == "aarch64" ]; then + SPH_NAME=aarch64 + elif [ "$sysName" == "freebsd" ]; then + SPH_NAME=freebsd + fi + + FILE_NAME=sphinx-${VERSION_NUM}-${SPH_SYSNAME}-${SPH_NAME} + FILE_TGZ=${FILE_NAME}.tar.gz + + echo "${SPHINX_DIR}/${FILE_TGZ}" + if [ ! -f ${SPHINX_DIR}/${FILE_TGZ} ];then if [ $sysName == 'Darwin' ]; then - wget -O ${SPHINX_DIR}/sphinx-${VERSION}.tar.gz http://sphinxsearch.com/files/sphinx-${VERSION}-612d99f-darwin-amd64.tar.gz + wget -O ${SPHINX_DIR}/sphinx-${VERSION}.tar.gz http://sphinxsearch.com/files/${FILE_TGZ} else - curl -sSLo ${SPHINX_DIR}/sphinx-${VERSION}.tar.gz http://sphinxsearch.com/files/sphinx-${VERSION}-612d99f-linux-amd64.tar.gz + curl -sSLo ${SPHINX_DIR}/sphinx-${VERSION}.tar.gz http://sphinxsearch.com/files/${FILE_TGZ} fi fi - if [ ! -f ${SPHINX_DIR}/sphinx-${VERSION}.tar.gz ];then - curl -sSLo ${SPHINX_DIR}/sphinx-${VERSION}.tar.gz https://github.com/midoks/mdserver-web/releases/download/init/sphinx-${VERSION}.tar.gz - fi + # if [ ! -f ${SPHINX_DIR}/sphinx-${VERSION}.tar.gz ];then + # curl -sSLo ${SPHINX_DIR}/sphinx-${VERSION}.tar.gz https://github.com/midoks/mdserver-web/releases/download/init/sphinx-${VERSION}.tar.gz + # fi - - cd ${SPHINX_DIR} && tar -zxvf sphinx-${VERSION}.tar.gz + cd ${SPHINX_DIR} && tar -zxvf ${FILE_TGZ} if [ "$?" == "0" ];then mkdir -p $SPHINX_DIR @@ -74,8 +125,14 @@ Uninstall_sphinx() if [ -f /usr/lib/systemd/system/sphinx.service ] || [ -f /lib/systemd/system/sphinx.service ];then systemctl stop sphinx systemctl disable sphinx - rm -rf /usr/lib/systemd/system/sphinx.service - rm -rf /lib/systemd/system/sphinx.service + + if [ -f /usr/lib/systemd/system/sphinx.service ];then + rm -rf /usr/lib/systemd/system/sphinx.service + fi + + if [ -f /lib/systemd/system/sphinx.service ];then + rm -rf /lib/systemd/system/sphinx.service + fi systemctl daemon-reload fi @@ -83,8 +140,11 @@ Uninstall_sphinx() $serverPath/sphinx/initd/sphinx stop fi - rm -rf $serverPath/sphinx - echo "Uninstall_sphinx" > $install_tmp + if [ -f $serverPath/sphinx ];then + rm -rf $serverPath/sphinx + fi + + echo "卸载sphinx成功" } action=$1 From f0fcec44ffe6b9f6bd96918c9593503edb7eaa4f Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 21:46:52 +0800 Subject: [PATCH 247/327] Update install.sh --- plugins/sphinx/install.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/sphinx/install.sh b/plugins/sphinx/install.sh index b9f3ec800..eb49fa970 100755 --- a/plugins/sphinx/install.sh +++ b/plugins/sphinx/install.sh @@ -91,9 +91,9 @@ Install_sphinx() echo "${SPHINX_DIR}/${FILE_TGZ}" if [ ! -f ${SPHINX_DIR}/${FILE_TGZ} ];then if [ $sysName == 'Darwin' ]; then - wget -O ${SPHINX_DIR}/sphinx-${VERSION}.tar.gz http://sphinxsearch.com/files/${FILE_TGZ} + wget -O ${SPHINX_DIR}/${FILE_TGZ} http://sphinxsearch.com/files/${FILE_TGZ} else - curl -sSLo ${SPHINX_DIR}/sphinx-${VERSION}.tar.gz http://sphinxsearch.com/files/${FILE_TGZ} + curl -sSLo ${SPHINX_DIR}/${FILE_TGZ} http://sphinxsearch.com/files/${FILE_TGZ} fi fi @@ -136,6 +136,7 @@ Uninstall_sphinx() systemctl daemon-reload fi + echo "$serverPath/sphinx/initd/sphinx" if [ -f $serverPath/sphinx/initd/sphinx ];then $serverPath/sphinx/initd/sphinx stop fi From 2f0f6eaed6f349c084fe5bf83d33422bb08b2225 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 21:54:20 +0800 Subject: [PATCH 248/327] Update install.sh --- plugins/sphinx/install.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/sphinx/install.sh b/plugins/sphinx/install.sh index eb49fa970..32ba62636 100755 --- a/plugins/sphinx/install.sh +++ b/plugins/sphinx/install.sh @@ -112,7 +112,10 @@ Install_sphinx() echo "${VERSION}" > $serverPath/sphinx/version.pl echo '安装Sphinx完成' cd ${rootPath} && python3 ${rootPath}/plugins/sphinx/index.py start - cd ${rootPath} && python3 ${rootPath}/plugins/sphinx/index.py initd_install + + if [ $sysName != 'Darwin' ]; then + cd ${rootPath} && python3 ${rootPath}/plugins/sphinx/index.py initd_install + fi fi if [ -d ${SPHINX_DIR}/sphinx-${VERSION} ];then From cbf3a15bf09e8168e8a6bacbd87829dd998d20ef Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 22:06:47 +0800 Subject: [PATCH 249/327] update --- plugins/redis/install.sh | 23 ++++++++++++++--------- plugins/sphinx/install.sh | 7 +++---- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/plugins/redis/install.sh b/plugins/redis/install.sh index 22b40fd23..444726156 100755 --- a/plugins/redis/install.sh +++ b/plugins/redis/install.sh @@ -25,14 +25,16 @@ Install_App() { echo '正在安装脚本文件...' > $install_tmp mkdir -p $serverPath/source + mkdir -p $serverPath/source/redis - if [ ! -f $serverPath/source/redis-${VERSION}.tar.gz ];then - wget -O $serverPath/source/redis-${VERSION}.tar.gz http://download.redis.io/releases/redis-${VERSION}.tar.gz - fi - - cd $serverPath/source && tar -zxvf redis-${VERSION}.tar.gz + FILE_TGZ=redis-${VERSION}.tar.gz + REDIS_DIR=$serverPath/source/redis + if [ ! -f $REDIS_DIR/${FILE_TGZ} ];then + wget -O $REDIS_DIR/${FILE_TGZ} http://download.redis.io/releases/${FILE_TGZ} + fi + cd $REDIS_DIR && tar -zxvf ${FILE_TGZ} CMD_MAKE=`which gmake` if [ "$?" == "0" ];then @@ -55,8 +57,8 @@ Install_App() echo '安装失败!' fi - if [ -d $serverPath/source/redis-${VERSION} ];then - rm -rf $serverPath/source/redis-${VERSION} + if [ -d ${REDIS_DIR}/redis-${VERSION} ];then + rm -rf ${REDIS_DIR}/redis-${VERSION} fi } @@ -80,8 +82,11 @@ Uninstall_App() $serverPath/redis/initd/redis stop fi - rm -rf $serverPath/redis - echo "Uninstall_redis" > $install_tmp + if [ -d $serverPath/redis ];then + rm -rf $serverPath/redis + fi + + echo "卸载redis成功" } action=$1 diff --git a/plugins/sphinx/install.sh b/plugins/sphinx/install.sh index 32ba62636..054761d46 100755 --- a/plugins/sphinx/install.sh +++ b/plugins/sphinx/install.sh @@ -18,8 +18,7 @@ install_tmp=${rootPath}/tmp/mw_install.pl # /Users/midoks/Desktop/mwdev/server/sphinx/bin/bin/indexer /Users/midoks/Desktop/mwdev/server/sphinx/sphinx.conf 99cms_mc_comic --rotate bash ${rootPath}/scripts/getos.sh -echo "bash ${rootPath}/scripts/getos.sh" - +# echo "bash ${rootPath}/scripts/getos.sh" OSNAME="macos" if [ -f ${rootPath}/data/osname.pl ];then OSNAME=`cat ${rootPath}/data/osname.pl` @@ -139,12 +138,12 @@ Uninstall_sphinx() systemctl daemon-reload fi - echo "$serverPath/sphinx/initd/sphinx" if [ -f $serverPath/sphinx/initd/sphinx ];then $serverPath/sphinx/initd/sphinx stop fi - if [ -f $serverPath/sphinx ];then + if [ -d $serverPath/sphinx ];then + echo "rm -rf $serverPath/sphinx" rm -rf $serverPath/sphinx fi From 01d5b75d90f1f15ffc919184388a06952c003fa0 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 22:15:43 +0800 Subject: [PATCH 250/327] Update install.sh --- plugins/sphinx/install.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/plugins/sphinx/install.sh b/plugins/sphinx/install.sh index 054761d46..5f9b457c5 100755 --- a/plugins/sphinx/install.sh +++ b/plugins/sphinx/install.sh @@ -89,11 +89,7 @@ Install_sphinx() echo "${SPHINX_DIR}/${FILE_TGZ}" if [ ! -f ${SPHINX_DIR}/${FILE_TGZ} ];then - if [ $sysName == 'Darwin' ]; then - wget -O ${SPHINX_DIR}/${FILE_TGZ} http://sphinxsearch.com/files/${FILE_TGZ} - else - curl -sSLo ${SPHINX_DIR}/${FILE_TGZ} http://sphinxsearch.com/files/${FILE_TGZ} - fi + wget --no-check-certificate -O ${SPHINX_DIR}/${FILE_TGZ} http://sphinxsearch.com/files/${FILE_TGZ} fi # if [ ! -f ${SPHINX_DIR}/sphinx-${VERSION}.tar.gz ];then From 56b3aae0c78d323458ff6a4b3c1ca4094c8d6118 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 22:22:52 +0800 Subject: [PATCH 251/327] Update install.sh --- plugins/sphinx/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/sphinx/install.sh b/plugins/sphinx/install.sh index 5f9b457c5..fd522bf82 100755 --- a/plugins/sphinx/install.sh +++ b/plugins/sphinx/install.sh @@ -87,13 +87,13 @@ Install_sphinx() FILE_NAME=sphinx-${VERSION_NUM}-${SPH_SYSNAME}-${SPH_NAME} FILE_TGZ=${FILE_NAME}.tar.gz - echo "${SPHINX_DIR}/${FILE_TGZ}" + # curl -sSLo ${SPHINX_DIR}/${FILE_TGZ} http://sphinxsearch.com/files/${FILE_TGZ} if [ ! -f ${SPHINX_DIR}/${FILE_TGZ} ];then wget --no-check-certificate -O ${SPHINX_DIR}/${FILE_TGZ} http://sphinxsearch.com/files/${FILE_TGZ} fi # if [ ! -f ${SPHINX_DIR}/sphinx-${VERSION}.tar.gz ];then - # curl -sSLo ${SPHINX_DIR}/sphinx-${VERSION}.tar.gz https://github.com/midoks/mdserver-web/releases/download/init/sphinx-${VERSION}.tar.gz + # wget --no-check-certificate -O ${SPHINX_DIR}/sphinx-${VERSION}.tar.gz https://github.com/midoks/mdserver-web/releases/download/init/sphinx-${VERSION}.tar.gz # fi cd ${SPHINX_DIR} && tar -zxvf ${FILE_TGZ} From db3350e85c33090b135d31d3080f57bafd3891f7 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 23:03:59 +0800 Subject: [PATCH 252/327] Update install.sh --- plugins/sphinx/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/sphinx/install.sh b/plugins/sphinx/install.sh index fd522bf82..4c43bba06 100755 --- a/plugins/sphinx/install.sh +++ b/plugins/sphinx/install.sh @@ -14,8 +14,8 @@ install_tmp=${rootPath}/tmp/mw_install.pl # cd /www/server/mdserver-web && source bin/activate && python3 plugins/sphinx/index.py rebuild # cd /www/server/mdserver-web && source bin/activate && python3 plugins/sphinx/index.py db_to_sphinx -# /www/server/sphinx/bin/bin/indexer -c /www/server/sphinx/sphinx.conf 99cms_mc_comic --rotate -# /Users/midoks/Desktop/mwdev/server/sphinx/bin/bin/indexer /Users/midoks/Desktop/mwdev/server/sphinx/sphinx.conf 99cms_mc_comic --rotate +# /www/server/sphinx/bin/bin/indexer -c /www/server/sphinx/sphinx.conf --all --rotate +# /Users/midoks/Desktop/mwdev/server/sphinx/bin/bin/indexer /Users/midoks/Desktop/mwdev/server/sphinx/sphinx.conf --all --rotate bash ${rootPath}/scripts/getos.sh # echo "bash ${rootPath}/scripts/getos.sh" From 87bceced805e1c4f68de76485d1f339d5a6ad398 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 19 May 2024 23:18:48 +0800 Subject: [PATCH 253/327] update --- plugins/sphinx/index.html | 3 ++- plugins/sphinx/js/sphinx.js | 25 ++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/plugins/sphinx/index.html b/plugins/sphinx/index.html index 3fcb4494c..92caca382 100755 --- a/plugins/sphinx/index.html +++ b/plugins/sphinx/index.html @@ -11,11 +11,12 @@

说明

-
+
\ No newline at end of file diff --git a/plugins/tidb/index.py b/plugins/tidb/index.py deleted file mode 100755 index ab0e08358..000000000 --- a/plugins/tidb/index.py +++ /dev/null @@ -1,584 +0,0 @@ -# coding:utf-8 - -import sys -import io -import os -import time -import re - -sys.path.append(os.getcwd() + "/class/core") -import mw - -app_debug = False -if mw.isAppleSystem(): - app_debug = True - - -def getPluginName(): - return 'tidb' - - -def getPluginDir(): - return mw.getPluginDir() + '/' + getPluginName() - - -def getServerDir(): - return mw.getServerDir() + '/' + getPluginName() - - -def getInitDFile(): - current_os = mw.getOs() - if current_os == 'darwin': - return '/tmp/' + getPluginName() - - if current_os.startswith('freebsd'): - return '/etc/rc.d/' + getPluginName() - - return '/etc/init.d/' + getPluginName() - - -def getConf(): - path = getServerDir() + "/tidb.conf" - return path - - -def getConfTpl(): - path = getPluginDir() + "/conf/tidb.conf" - return path - - -def getInitDTpl(): - path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl" - return path - -def getArgs(): - args = sys.argv[2:] - tmp = {} - args_len = len(args) - - if args_len == 1: - t = args[0].strip('{').strip('}') - t = t.split(':', 1) - tmp[t[0]] = t[1] - elif args_len > 1: - for i in range(len(args)): - t = args[i].split(':', 1) - tmp[t[0]] = t[1] - return tmp - -def getArgsBk(): - args = sys.argv[3:] - tmp = {} - args_len = len(args) - - if args_len == 1: - t = args[0].strip('{').strip('}') - if t.strip() == '': - tmp = [] - else: - t = t.split(':') - tmp[t[0]] = t[1] - tmp[t[0]] = t[1] - elif args_len > 1: - for i in range(len(args)): - t = args[i].split(':') - tmp[t[0]] = t[1] - return tmp - -def checkArgs(data, ck=[]): - for i in range(len(ck)): - if not ck[i] in data: - return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!')) - return (True, mw.returnJson(True, 'ok')) - -def configTpl(): - path = getPluginDir() + '/tpl' - pathFile = os.listdir(path) - tmp = [] - for one in pathFile: - file = path + '/' + one - tmp.append(file) - return mw.getJson(tmp) - - -def readConfigTpl(): - args = getArgs() - data = checkArgs(args, ['file']) - if not data[0]: - return data[1] - - content = mw.readFile(args['file']) - content = contentReplace(content) - return mw.returnJson(True, 'ok', content) - -def getPidFile(): - file = getConf() - content = mw.readFile(file) - rep = 'pidfile\s*(.*)' - tmp = re.search(rep, content) - return tmp.groups()[0].strip() - -def status(): - # pid_file = getPidFile() - # if not os.path.exists(pid_file): - # return 'stop' - - # data = mw.execShell( - # "ps aux|grep redis |grep -v grep | grep -v python | grep -v mdserver-web | awk '{print $2}'") - - # if data[0] == '': - # return 'stop' - return 'stop' - -def contentReplace(content): - service_path = mw.getServerDir() - content = content.replace('{$ROOT_PATH}', mw.getRootDir()) - content = content.replace('{$SERVER_PATH}', service_path) - content = content.replace('{$SERVER_APP}', service_path + '/redis') - content = content.replace('{$REDIS_PASS}', mw.getRandomString(10)) - return content - - - -def initDreplace(): - - file_tpl = getInitDTpl() - service_path = os.path.dirname(os.getcwd()) - - initD_path = getServerDir() + '/init.d' - if not os.path.exists(initD_path): - os.mkdir(initD_path) - file_bin = initD_path + '/' + getPluginName() - - # initd replace - if not os.path.exists(file_bin): - content = mw.readFile(file_tpl) - content = content.replace('{$SERVER_PATH}', service_path) - mw.writeFile(file_bin, content) - mw.execShell('chmod +x ' + file_bin) - - # log - dataLog = getServerDir() + '/data' - if not os.path.exists(dataLog): - mw.execShell('chmod +x ' + file_bin) - - - conf_list = ['tidb.conf', 'tidb.yaml'] - dst_conf_init = getServerDir() + '/init.pl' - if not os.path.exists(dst_conf_init): - for conf in conf_list: - dst_conf = getServerDir() + '/'+ conf - src_conf = getPluginDir() + '/conf/'+ conf - if not os.path.exists(dst_conf): - content = mw.readFile(src_conf) - content = content.replace('{$SERVER_PATH}', service_path) - mw.writeFile(dst_conf, content) - mw.writeFile(dst_conf_init, 'ok') - - # systemd - systemDir = mw.systemdCfgDir() - systemService = systemDir + '/' + getPluginName() + '.service' - if os.path.exists(systemDir) and not os.path.exists(systemService): - systemServiceTpl = getPluginDir() + '/init.d/' + getPluginName() + '.service.tpl' - service_path = mw.getServerDir() - se_content = mw.readFile(systemServiceTpl) - se_content = se_content.replace('{$SERVER_PATH}', service_path) - mw.writeFile(systemService, se_content) - mw.execShell('systemctl daemon-reload') - - return file_bin - - -def tiOp(method): - file = initDreplace() - - current_os = mw.getOs() - if current_os == "darwin": - data = mw.execShell(file + ' ' + method) - if data[1] == '': - return 'ok' - return data[1] - - if current_os.startswith("freebsd"): - data = mw.execShell('service ' + getPluginName() + ' ' + method) - if data[1] == '': - return 'ok' - return data[1] - - data = mw.execShell('systemctl ' + method + ' ' + getPluginName()) - if data[1] == '': - return 'ok' - return data[1] - - -def start(): - return tiOp('start') - - -def stop(): - return tiOp('stop') - - -def restart(): - status = tiOp('restart') - return status - - -def reload(): - return tiOp('reload') - - -def getPort(): - conf = getServerDir() + '/redis.conf' - content = mw.readFile(conf) - - rep = "^(" + 'port' + ')\s*([.0-9A-Za-z_& ~]+)' - tmp = re.search(rep, content, re.M) - if tmp: - return tmp.groups()[1] - - return '6379' - - -def getRedisCmd(): - requirepass = "" - conf = getServerDir() + '/redis.conf' - content = mw.readFile(conf) - rep = "^(requirepass" + ')\s*([.0-9A-Za-z_& ~]+)' - tmp = re.search(rep, content, re.M) - if tmp: - requirepass = tmp.groups()[1] - - default_ip = '127.0.0.1' - port = getPort() - # findDebian = mw.execShell('cat /etc/issue |grep Debian') - # if findDebian[0] != '': - # default_ip = mw.getLocalIp() - cmd = getServerDir() + "/bin/redis-cli -h " + \ - default_ip + ' -p ' + port + " " - - if requirepass != "": - cmd = getServerDir() + '/bin/redis-cli -h ' + default_ip + \ - ' -p ' + port + ' -a "' + requirepass + '" ' - - return cmd - -def runInfo(): - s = status() - if s == 'stop': - return mw.returnJson(False, '未启动') - - - cmd = getRedisCmd() - cmd = cmd + 'info' - - # print(cmd) - data = mw.execShell(cmd)[0] - # print(data) - res = [ - 'tcp_port', - 'uptime_in_days', # 已运行天数 - 'connected_clients', # 连接的客户端数量 - 'used_memory', # Redis已分配的内存总量 - 'used_memory_rss', # Redis占用的系统内存总量 - 'used_memory_peak', # Redis所用内存的高峰值 - 'mem_fragmentation_ratio', # 内存碎片比率 - 'total_connections_received', # 运行以来连接过的客户端的总数量 - 'total_commands_processed', # 运行以来执行过的命令的总数量 - 'instantaneous_ops_per_sec', # 服务器每秒钟执行的命令数量 - 'keyspace_hits', # 查找数据库键成功的次数 - 'keyspace_misses', # 查找数据库键失败的次数 - 'latest_fork_usec' # 最近一次 fork() 操作耗费的毫秒数 - ] - data = data.split("\n") - result = {} - for d in data: - if len(d) < 3: - continue - t = d.strip().split(':') - if not t[0] in res: - continue - result[t[0]] = t[1] - return mw.getJson(result) - -def infoReplication(): - # 复制信息 - s = status() - if s == 'stop': - return mw.returnJson(False, '未启动') - - cmd = getRedisCmd() - cmd = cmd + 'info replication' - - # print(cmd) - data = mw.execShell(cmd)[0] - # print(data) - res = [ - #slave - 'role',#角色 - 'master_host', # 连接主库HOST - 'master_port', # 连接主库PORT - 'master_link_status', # 连接主库状态 - 'master_last_io_seconds_ago', # 上次同步时间 - 'master_sync_in_progress', # 正在同步中 - 'slave_read_repl_offset', # 从库读取复制位置 - 'slave_repl_offset', # 从库复制位置 - 'slave_priority', # 从库同步优先级 - 'slave_read_only', # 从库是否仅读 - 'replica_announced', # 已复制副本 - 'connected_slaves', # 连接从库数量 - 'master_failover_state', # 主库故障状态 - 'master_replid', # 主库复制ID - 'master_repl_offset', # 主库复制位置 - 'second_repl_offset', # 主库复制位置时间 - 'repl_backlog_active', # 复制状态 - 'repl_backlog_size', # 复制大小 - 'repl_backlog_first_byte_offset', # 第一个字节偏移量 - 'repl_backlog_histlen', # backlog中数据的长度 - ] - - data = data.split("\n") - result = {} - for d in data: - if len(d) < 3: - continue - t = d.strip().split(':') - if not t[0] in res: - continue - result[t[0]] = t[1] - - if 'role' in result and result['role'] == 'master': - connected_slaves = int(result['connected_slaves']) - slave_l = [] - for x in range(connected_slaves): - slave_l.append('slave'+str(x)) - - for d in data: - if len(d) < 3: - continue - t = d.strip().split(':') - if not t[0] in slave_l: - continue - result[t[0]] = t[1] - - return mw.getJson(result) - - -def clusterInfo(): - #集群信息 - # https://redis.io/commands/cluster-info/ - s = status() - if s == 'stop': - return mw.returnJson(False, '未启动') - - cmd = getRedisCmd() - cmd = cmd + 'cluster info' - - # print(cmd) - data = mw.execShell(cmd)[0] - # print(data) - - res = [ - 'cluster_state',#状态 - 'cluster_slots_assigned', # 被分配的槽 - 'cluster_slots_ok', # 被分配的槽状态 - 'cluster_slots_pfail', # 连接主库状态 - 'cluster_slots_fail', # 失败的槽 - 'cluster_known_nodes', # 知道的节点 - 'cluster_size', # 大小 - 'cluster_current_epoch', # - 'cluster_my_epoch', # - 'cluster_stats_messages_sent', # 发送 - 'cluster_stats_messages_received', # 接受 - 'total_cluster_links_buffer_limit_exceeded', # - ] - - data = data.split("\n") - result = {} - for d in data: - if len(d) < 3: - continue - t = d.strip().split(':') - if not t[0] in res: - continue - result[t[0]] = t[1] - - return mw.getJson(result) - -def clusterNodes(): - s = status() - if s == 'stop': - return mw.returnJson(False, '未启动') - - cmd = getRedisCmd() - cmd = cmd + 'cluster nodes' - - # print(cmd) - data = mw.execShell(cmd)[0] - # print(data) - - data = data.strip().split("\n") - return mw.getJson(data) - -def initdStatus(): - current_os = mw.getOs() - if current_os == 'darwin': - return "Apple Computer does not support" - - if current_os.startswith('freebsd'): - initd_bin = getInitDFile() - if os.path.exists(initd_bin): - return 'ok' - - shell_cmd = 'systemctl status ' + \ - getPluginName() + ' | grep loaded | grep "enabled;"' - data = mw.execShell(shell_cmd) - if data[0] == '': - return 'fail' - return 'ok' - - -def initdInstall(): - current_os = mw.getOs() - if current_os == 'darwin': - return "Apple Computer does not support" - - # freebsd initd install - if current_os.startswith('freebsd'): - import shutil - source_bin = initDreplace() - initd_bin = getInitDFile() - shutil.copyfile(source_bin, initd_bin) - mw.execShell('chmod +x ' + initd_bin) - mw.execShell('sysrc ' + getPluginName() + '_enable="YES"') - return 'ok' - - mw.execShell('systemctl enable ' + getPluginName()) - return 'ok' - - -def initdUinstall(): - current_os = mw.getOs() - if current_os == 'darwin': - return "Apple Computer does not support" - - if current_os.startswith('freebsd'): - initd_bin = getInitDFile() - os.remove(initd_bin) - mw.execShell('sysrc ' + getPluginName() + '_enable="NO"') - return 'ok' - - mw.execShell('systemctl disable ' + getPluginName()) - return 'ok' - - -def runLog(): - return getServerDir() + '/data/redis.log' - - -def getRedisConfInfo(): - conf = getServerDir() + '/redis.conf' - - gets = [ - {'name': 'bind', 'type': 2, 'ps': '绑定IP(修改绑定IP可能会存在安全隐患)','must_show':1}, - {'name': 'port', 'type': 2, 'ps': '绑定端口','must_show':1}, - {'name': 'timeout', 'type': 2, 'ps': '空闲链接超时时间,0表示不断开','must_show':1}, - {'name': 'maxclients', 'type': 2, 'ps': '最大连接数','must_show':1}, - {'name': 'databases', 'type': 2, 'ps': '数据库数量','must_show':1}, - {'name': 'requirepass', 'type': 2, 'ps': 'redis密码,留空代表没有设置密码','must_show':1}, - {'name': 'maxmemory', 'type': 2, 'ps': 'MB,最大使用内存,0表示不限制','must_show':1}, - {'name': 'slaveof', 'type': 2, 'ps': '同步主库地址','must_show':0}, - {'name': 'masterauth', 'type': 2, 'ps': '同步主库密码', 'must_show':0} - ] - content = mw.readFile(conf) - - result = [] - for g in gets: - rep = "^(" + g['name'] + ')\s*([.0-9A-Za-z_& ~]+)' - tmp = re.search(rep, content, re.M) - if not tmp: - if g['must_show'] == 0: - continue - - g['value'] = '' - result.append(g) - continue - g['value'] = tmp.groups()[1] - if g['name'] == 'maxmemory': - g['value'] = g['value'].strip("mb") - result.append(g) - - return result - - -def getRedisConf(): - data = getRedisConfInfo() - return mw.getJson(data) - - -def submitRedisConf(): - gets = ['bind', 'port', 'timeout', 'maxclients', - 'databases', 'requirepass', 'maxmemory','slaveof','masterauth'] - args = getArgs() - conf = getServerDir() + '/redis.conf' - content = mw.readFile(conf) - for g in gets: - if g in args: - rep = g + '\s*([.0-9A-Za-z_& ~]+)' - val = g + ' ' + args[g] - - if g == 'maxmemory': - val = g + ' ' + args[g] + "mb" - - if g == 'requirepass' and args[g] == '': - content = re.sub('requirepass', '#requirepass', content) - if g == 'requirepass' and args[g] != '': - content = re.sub('#requirepass', 'requirepass', content) - content = re.sub(rep, val, content) - - if g != 'requirepass': - content = re.sub(rep, val, content) - mw.writeFile(conf, content) - reload() - return mw.returnJson(True, '设置成功') - -if __name__ == "__main__": - func = sys.argv[1] - if func == 'status': - print(status()) - elif func == 'start': - print(start()) - elif func == 'stop': - print(stop()) - elif func == 'restart': - print(restart()) - elif func == 'reload': - print(reload()) - elif func == 'initd_status': - print(initdStatus()) - elif func == 'initd_install': - print(initdInstall()) - elif func == 'initd_uninstall': - print(initdUinstall()) - elif func == 'run_info': - print(runInfo()) - elif func == 'info_replication': - print(infoReplication()) - elif func == 'cluster_info': - print(clusterInfo()) - elif func == 'cluster_nodes': - print(clusterNodes()) - elif func == 'conf': - print(getConf()) - elif func == 'run_log': - print(runLog()) - elif func == 'get_redis_conf': - print(getRedisConf()) - elif func == 'submit_redis_conf': - print(submitRedisConf()) - elif func == 'config_tpl': - print(configTpl()) - elif func == 'read_config_tpl': - print(readConfigTpl()) - else: - print('error') diff --git a/plugins/tidb/info.json b/plugins/tidb/info.json deleted file mode 100755 index 6a4e38b58..000000000 --- a/plugins/tidb/info.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "sort": 10, - "ps": "分布式数据库(高度兼容MySQL)[社区版][暂时不可用]", - "name": "tidb", - "title": "TiDB", - "shell": "install.sh", - "versions":["v7.5.1","v8.0.0"], - "tip": "soft", - "checks": "server/tidb", - "path": "server/tidb", - "display": 1, - "author": "tidb", - "date": "2024-05-11", - "home": "https://cn.pingcap.com/product-community/", - "type": 0, - "pid": "2" -} diff --git a/plugins/tidb/init.d/tidb.service.tpl b/plugins/tidb/init.d/tidb.service.tpl deleted file mode 100644 index 8e8eb5693..000000000 --- a/plugins/tidb/init.d/tidb.service.tpl +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=Redis In-Memory Data Store -After=network.target - -[Service] -Type=forking -ExecStart={$SERVER_PATH}/redis/bin/redis-server {$SERVER_PATH}/redis/redis.conf -ExecReload=/bin/kill -USR2 $MAINPID -Restart=on-failure - -[Install] -WantedBy=multi-user.target \ No newline at end of file diff --git a/plugins/tidb/init.d/tidb.tpl b/plugins/tidb/init.d/tidb.tpl deleted file mode 100644 index b7cf93630..000000000 --- a/plugins/tidb/init.d/tidb.tpl +++ /dev/null @@ -1,77 +0,0 @@ -#!/bin/sh -# chkconfig: 2345 55 25 -# description: Redis Service - -### BEGIN INIT INFO -# Provides: Redis -# Required-Start: $all -# Required-Stop: $all -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: starts Redis -# Description: starts the MDW-Web -### END INIT INFO - -# Simple Redis init.d script conceived to work on Linux systems -# as it does use of the /proc filesystem. - -CONF="{$SERVER_PATH}/redis/redis.conf" -REDISPORT=$(cat $CONF |grep port|grep -v '#'|awk '{print $2}') -REDISPASS=$(cat $CONF |grep requirepass|grep -v '#'|awk '{print $2}') -if [ "$REDISPASS" != "" ];then - REDISPASS=" -a $REDISPASS" -fi -EXEC={$SERVER_PATH}/redis/bin/redis-server -CLIEXEC="{$SERVER_PATH}/redis/bin/redis-cli -p $REDISPORT$REDISPASS" -PIDFILE={$SERVER_PATH}/redis/redis_6379.pid - -echo $REDISPASS -echo $REDISPORT -echo $CLIEXEC - -mkdir -p {$SERVER_PATH}/redis/data - -redis_start(){ - if [ -f $PIDFILE ];then - kill -9 `cat $PIDFILE` - fi - - echo "Starting Redis server..." - nohup $EXEC $CONF >> {$SERVER_PATH}/redis/logs.pl 2>&1 & -} -redis_stop(){ - if [ ! -f $PIDFILE ] - then - echo "$PIDFILE does not exist, process is not running" - else - PID=$(cat $PIDFILE) - echo "Stopping ..." - $CLIEXEC shutdown save 2>/dev/null - while [ -x /proc/${PID} ] - do - echo "Waiting for Redis to shutdown ..." - sleep 1 - done - echo "Redis stopped" - rm -rf $PIDFILE - fi -} - - -case "$1" in - start) - redis_start - ;; - stop) - redis_stop - ;; - restart|reload) - redis_stop - sleep 0.3 - redis_start - ;; - *) - echo "Please use start or stop as first argument" - ;; -esac - diff --git a/plugins/tidb/install.sh b/plugins/tidb/install.sh deleted file mode 100755 index 21b1073e5..000000000 --- a/plugins/tidb/install.sh +++ /dev/null @@ -1,124 +0,0 @@ -#!/bin/bash -PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/homebrew/bin -export PATH - -curPath=`pwd` -rootPath=$(dirname "$curPath") -rootPath=$(dirname "$rootPath") -serverPath=$(dirname "$rootPath") - -sysName=`uname` -sysArch=`arch` -echo "use system: ${sysName}" - -# https://cn.pingcap.com/product-community/ -# https://docs.pingcap.com/zh/tidb/stable/quick-start-with-tidb - -# cd /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/tidb && bash install.sh install v7.5.1 -# mw update_dev && cd /www/server/mdserver-web/plugins/tidb && bash install.sh install v7.5.1 -# python3 /www/server/mdserver-web/plugins/tidb/index.py start -# cd /www/server/source/tidb/tidb-community-server-v7.5.1-linux-amd64 && ./local_install.sh -# cd /www/server/tidb/mirror && ./local_install.sh -# source /root/.bashrc - -# ssh 192.168.4.1 -l root -# useradd -d /home/tidb1 tidb1 && passwd tidb1 - -# tidb ssh -# /root/.tiup/storage/cluster/clusters/tidb/ssh - -# ssh-copy-id -p 2022 root@154.21.203.138 -# ssh -p 2022 root@154.21.203.138 -i /root/.tiup/storage/cluster/clusters/tidb/ssh/id_rsa - -# grafana -# http://154.21.203.138:3000 - -# grafana -# http://154.21.203.138:3000 - -# rm -rf /root/.tiup -# tiup cluster deploy tidb v7.5.1 /www/server/tidb/tidb.yaml --user root -p -# tiup cluster deploy mw v7.5.1 /www/server/tidb/tidb.yaml --user root -p - -# tiup cluster clean tidb --all -# tiup cluster display tidb -# tiup cluster destroy tidb - -# tiup cluster clean tidb --all --ignore-role prometheus grafana - - - -install_tmp=${rootPath}/tmp/mw_install.pl -VERSION=$2 -TIDB_ARCH=arm64 -if [ "$sysArch" == "x86_64" ];then - TIDB_ARCH=amd64 -fi - -if [ "$sysArch" == "aarch64" ];then - TIDB_ARCH=arm64 -fi - -Install_App() -{ - echo '正在安装脚本文件...' > $install_tmp - mkdir -p $serverPath/source - mkdir -p $serverPath/source/tidb - - tidb_name=tidb-community-server-${VERSION}-linux-${TIDB_ARCH} - tidb_toolkit_name=tidb-community-toolkit-${VERSION}-linux-${TIDB_ARCH} - tgz_name=${tidb_name}.tar.gz - tgz_toolkit_name=${tidb_toolkit_name}.tar.gz - - - if [ ! -f $serverPath/source/tidb/${tgz_name} ];then - wget -O $serverPath/source/tidb/${tgz_name} https://download.pingcap.org/${tgz_name} - fi - - - if [ ! -d $serverPath/source/tidb/${tidb_name} ];then - cd $serverPath/source/tidb && tar -zxvf $serverPath/source/tidb/${tgz_name} - fi - - if [ ! -f $serverPath/source/tidb/${tgz_toolkit_name} ];then - wget -O $serverPath/source/tidb/${tgz_toolkit_name} https://download.pingcap.org/${tgz_toolkit_name} - fi - - if [ ! -d $serverPath/source/tidb/${tgz_toolkit_name} ];then - cd $serverPath/source/tidb && tar -zxvf $serverPath/source/tidb/${tgz_toolkit_name} - fi - - if [ ! -d $serverPath/tidb/mirror ];then - mkdir -p $serverPath/tidb/mirror - cp -rf $serverPath/source/tidb/${tidb_name}/* $serverPath/tidb/mirror - fi - - cd $serverPath/tidb/mirror && ./local_install.sh - - if [ -d $serverPath/tidb ];then - echo "${VERSION}" > $serverPath/tidb/version.pl - - cd ${rootPath} && python3 ${rootPath}/plugins/tidb/index.py start - # cd ${rootPath} && python3 ${rootPath}/plugins/tidb/index.py initd_install - echo '安装完成' - else - echo '安装失败!' - fi - - if [ -d $serverPath/source/redis-${VERSION} ];then - rm -rf $serverPath/source/redis-${VERSION} - fi -} - -Uninstall_App() -{ - rm -rf $serverPath/tidb - echo "卸载TiDB" -} - -action=$1 -if [ "${1}" == 'install' ];then - Install_App -else - Uninstall_App -fi diff --git a/plugins/tidb/js/tidb.js b/plugins/tidb/js/tidb.js deleted file mode 100755 index a52a87a42..000000000 --- a/plugins/tidb/js/tidb.js +++ /dev/null @@ -1,297 +0,0 @@ -function tiPost(method, version, args,callback){ - var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); - - var req_data = {}; - req_data['name'] = 'redis'; - req_data['func'] = method; - req_data['version'] = version; - - if (typeof(args) == 'string'){ - req_data['args'] = JSON.stringify(toArrayObject(args)); - } else { - req_data['args'] = JSON.stringify(args); - } - - $.post('/plugins/run', req_data, function(data) { - layer.close(loadT); - if (!data.status){ - //错误展示10S - layer.msg(data.msg,{icon:0,time:2000,shade: [10, '#000']}); - return; - } - - if(typeof(callback) == 'function'){ - callback(data); - } - },'json'); -} - -function redisPostCallbak(method, version, args,callback){ - var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); - - var req_data = {}; - req_data['name'] = 'redis'; - req_data['func'] = method; - args['version'] = version; - - if (typeof(args) == 'string'){ - 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'); -} - -//redis状态 start -function redisStatus(version) { - - redisPost('run_info',version, {},function(data){ - var rdata = $.parseJSON(data.data); - - if ('status' in rdata && !rdata.status){ - layer.msg(rdata.msg,{icon:0,time:2000,shade: [0.3, '#000']}); - return; - } - - hit = (parseInt(rdata.keyspace_hits) / (parseInt(rdata.keyspace_hits) + parseInt(rdata.keyspace_misses)) * 100).toFixed(2); - var con = '
\ -
IP状态在线
' + rdata.data[i]['name'] +'' + ''+(rdata.data[i]['slave']?'退出':'加入')+' | ' + - '同步' + + '同步 | ' + + '数据校验' + '
' + v['Channel_Name'] +'' + status +'' + v['Channel_Name'] +'' + status +'
\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
字段当前值说明
uptime_in_days' + rdata.uptime_in_days + '已运行天数
tcp_port' + rdata.tcp_port + '当前监听端口
connected_clients' + rdata.connected_clients + '连接的客户端数量
used_memory_rss' + toSize(rdata.used_memory_rss) + 'Redis当前占用的系统内存总量
used_memory' + toSize(rdata.used_memory) + 'Redis当前已分配的内存总量
used_memory_peak' + toSize(rdata.used_memory_peak) + 'Redis历史分配内存的峰值
mem_fragmentation_ratio' + rdata.mem_fragmentation_ratio + '%内存碎片比率
total_connections_received' + rdata.total_connections_received + '运行以来连接过的客户端的总数量
total_commands_processed' + rdata.total_commands_processed + '运行以来执行过的命令的总数量
instantaneous_ops_per_sec' + rdata.instantaneous_ops_per_sec + '服务器每秒钟执行的命令数量
keyspace_hits' + rdata.keyspace_hits + '查找数据库键成功的次数
keyspace_misses' + rdata.keyspace_misses + '查找数据库键失败的次数
hit' + hit + '%查找数据库键命中率
latest_fork_usec' + rdata.latest_fork_usec + '最近一次 fork() 操作耗费的微秒数
'; - $(".soft-man-con").html(con); - }); -} - -function replStatus(version){ - redisPost('info_replication', version, {},function(data){ - var rdata = $.parseJSON(data.data); - - if ('status' in rdata && !rdata.status){ - layer.msg(rdata.msg,{icon:0,time:2000,shade: [0.3, '#000']}); - return; - } - - var kv = { - 'role':'角色', - 'master_host':'连接主库HOST', - 'master_port':'连接主库PORT', - 'master_link_status':'连接主库状态', - 'master_last_io_seconds_ago':'上次同步时间', - 'master_sync_in_progress':'正在同步中', - 'slave_read_repl_offset':'从库读取复制位置', - 'slave_repl_offset':'从库复制位置', - 'slave_read_only':'从库是否仅读', - 'replica_announced':'已复制副本', - 'connected_slaves':'连接数量', - 'master_failover_state':'主库故障状态', - 'master_replid':'主库复制ID', - 'master_repl_offset':'主库复制位置', - 'repl_backlog_size':'backlog复制大小', - 'second_repl_offset':'复制位置时间', - 'repl_backlog_first_byte_offset':'第一个字节偏移量', - 'repl_backlog_histlen':'backlog中数据的长度', - 'repl_backlog_active':'开启复制缓冲区', - 'slave_priority':'同步优先级', - } - - var tbody_text = ''; - for (k in rdata){ - if (k == 'master_replid'){ - tbody_text += ''+k+'' + rdata[k] + ''+kv[k]+''; - } else{ - - if (k.substring(0,5) == 'slave' && !isNaN(k.substring(5))){ - tbody_text += ''+k+'' + rdata[k] + '从库配置信息'; - } else{ - tbody_text += ''+k+'' + rdata[k] + ''+kv[k]+''; - } - - - } - } - - var con = '
\ - \ - \ - '+tbody_text+'\ -
字段当前值说明
'; - $(".soft-man-con").html(con); - }); -} - -function clusterStatus(version){ - redisPost('cluster_info', version, {},function(data){ - var rdata = $.parseJSON(data.data); - - if ('status' in rdata && !rdata.status){ - layer.msg(rdata.msg,{icon:0,time:2000,shade: [0.3, '#000']}); - return; - } - - var kv = { - 'cluster_state':'集群状态', - 'cluster_slots_assigned':'被分配的槽', - 'cluster_slots_ok':'被分配的槽状态', - 'cluster_known_nodes':'知道的节点', - 'cluster_size':'大小', - 'cluster_stats_messages_sent':'发送', - 'cluster_stats_messages_received':'接收', - 'cluster_current_epoch':'集群当前epoch', - 'cluster_my_epoch':'当前我的epoch', - 'cluster_slots_pfail':'处于PFAIL状态的槽数', - 'cluster_slots_fail':'处于FAIL状态的槽数', - 'total_cluster_links_buffer_limit_exceeded':'超出缓冲区总数', - } - - var tbody_text = ''; - for (k in rdata){ - var desc = k; - if (k in kv){ - desc = kv[k]; - } - - if (k == 'master_replid'){ - tbody_text += ''+k+'' + rdata[k] + ''+desc+''; - } else{ - tbody_text += ''+k+'' + rdata[k] + ''+desc+''; - } - } - - if (tbody_text == ''){ - tbody_text += '无数据/未设置集群'; - } - - var con = '
\ - \ - \ - '+tbody_text+'\ -
字段当前值说明
'; - $(".soft-man-con").html(con); - }); -} - -function clusterNodes(version){ - redisPost('cluster_nodes', version, {},function(data){ - var rdata = $.parseJSON(data.data); - - if ('status' in rdata && !rdata.status){ - layer.msg(rdata.msg,{icon:0,time:2000,shade: [0.3, '#000']}); - return; - } - - // console.log(rdata); - var tbody_text = ''; - for (k in rdata){ - tbody_text += ''+ rdata[k] +''; - } - - if (tbody_text == ''){ - tbody_text += '无数据/未设置集群'; - } - - var con = '
\ - \ - \ - '+tbody_text+'\ -
节点信息
'; - $(".soft-man-con").html(con); - }); -} - -//redis状态 end - -//配置修改 -function getRedisConfig(version) { - redisPost('get_redis_conf', version,'',function(data){ - // console.log(data); - var rdata = $.parseJSON(data.data); - // console.log(rdata); - var mlist = ''; - for (var i = 0; i < rdata.length; i++) { - var w = '70' - if (rdata[i].name == 'error_reporting') w = '250'; - var ibody = ''; - switch (rdata[i].type) { - case 0: - var selected_1 = (rdata[i].value == 1) ? 'selected' : ''; - var selected_0 = (rdata[i].value == 0) ? 'selected' : ''; - ibody = '' - break; - case 1: - var selected_1 = (rdata[i].value == 'On') ? 'selected' : ''; - var selected_0 = (rdata[i].value == 'Off') ? 'selected' : ''; - ibody = '' - break; - } - mlist += '

' + rdata[i].name + '' + ibody + ', ' + rdata[i].ps + '

' - } - var con = '
' + mlist + '\ -
\ -
\ -
' - $(".soft-man-con").html(con); - }); -} - -//提交配置 -function submitConf(version) { - var data = { - version: version, - bind: $("input[name='bind']").val(), - 'port': $("input[name='port']").val(), - 'timeout': $("input[name='timeout']").val(), - maxclients: $("input[name='maxclients']").val(), - databases: $("input[name='databases']").val(), - requirepass: $("input[name='requirepass']").val(), - maxmemory: $("input[name='maxmemory']").val(), - }; - - redisPost('submit_redis_conf', version, data, function(ret_data){ - var rdata = $.parseJSON(ret_data.data); - layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 }); - }); -} - - -function tidbReadme(){ - var cmd_01 = '/www/server/redis/bin/redis-cli --cluster create 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 --cluster-replicas 0'; - var cmd_02 = '/www/server/redis/bin/redis-cli --cluster create 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 --cluster-replicas 1'; - - - var readme = '
    '; - readme += '
  • 集群创建1
  • '; - readme += '
  • '+cmd_01+'
  • '; - readme += '
  • 集群创建2
  • '; - readme += '
  • '+cmd_02+'
  • '; - readme += '
'; - - $('.soft-man-con').html(readme); -} - From 71c1034d12bc5455960d122ed3511a802a56323d Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 22 May 2024 22:01:37 +0800 Subject: [PATCH 324/327] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1d2433fdc..a12c0744b 100644 --- a/.gitignore +++ b/.gitignore @@ -178,3 +178,4 @@ debug.out mdioks.session-journal *.session +/plugins/tidb From 990fb0656769bb7a271e99b85d1abcf3e71c5317 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 22 May 2024 22:02:17 +0800 Subject: [PATCH 325/327] Update .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a12c0744b..c47314ad2 100644 --- a/.gitignore +++ b/.gitignore @@ -173,9 +173,9 @@ plugins/v2ray plugins/frp plugins/file_search plugins/proxysql +plugins/tidb debug.out mdioks.session-journal *.session -/plugins/tidb From ba96e62126994d6d85e37e504e3857d1c46a53eb Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 22 May 2024 22:11:07 +0800 Subject: [PATCH 326/327] Update cmd.md --- cmd.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd.md b/cmd.md index 0214eb241..202efe7d5 100644 --- a/cmd.md +++ b/cmd.md @@ -5,7 +5,8 @@ ``` /etc/init.d/mw default | 显示登录信息 -/etc/init.d/mw db | 快捷连接数据库 +/etc/init.d/mw db | 快捷连接MySQL +/etc/init.d/mw redis | 快捷连接Redis ---------------------------------------- mw open | 开启面板 mw close | 关闭面板 From de4e134be8162c10b18d0452fc8ce17801c20a8a Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 22 May 2024 22:12:03 +0800 Subject: [PATCH 327/327] 0.16.9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - mysql同步优化,享受丝滑般感觉。 - 网站统计 - 实时-可调节1-10s。 - 网站统计 - 加入大小条件。 - Sphinx优化。 --- README.md | 2 +- class/core/config_api.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d3cade916..2337f28e7 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ docker run -itd --name mw-server --privileged=true -p 7200:7200 -p 80:80 -p 443: ``` -### 版本更新 0.16.8.x +### 版本更新 0.16.9 - mysql同步优化,享受丝滑般感觉。 - 网站统计 - 实时-可调节1-10s。 diff --git a/class/core/config_api.py b/class/core/config_api.py index 24b2776d6..71dd0d896 100755 --- a/class/core/config_api.py +++ b/class/core/config_api.py @@ -28,7 +28,7 @@ from flask import request class config_api: - __version = '0.16.8.5' + __version = '0.16.9' __api_addr = 'data/api.json' # 统一默认配置文件