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); }