From 55b6aa79f619b1dd70b97555826ea4927c83504b Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 2 Aug 2022 17:51:30 +0800 Subject: [PATCH 01/89] =?UTF-8?q?mysql=E9=85=8D=E7=BD=AE=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- class/core/config_api.py | 2 +- plugins/mysql/conf/my.cnf | 5 +++-- plugins/mysql/conf/my5.7.cnf | 19 +++++++++++-------- plugins/mysql/conf/my8.0.cnf | 18 ++++++++++-------- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/class/core/config_api.py b/class/core/config_api.py index 5c5b49dd5..d5f928285 100755 --- a/class/core/config_api.py +++ b/class/core/config_api.py @@ -17,7 +17,7 @@ class config_api: # 进行中. # 兼容主流Linux系统 - __version = '0.8.6.13' + __version = '0.8.6.14' def __init__(self): pass diff --git a/plugins/mysql/conf/my.cnf b/plugins/mysql/conf/my.cnf index 369e55b28..6f1f1e278 100644 --- a/plugins/mysql/conf/my.cnf +++ b/plugins/mysql/conf/my.cnf @@ -15,6 +15,7 @@ log-error = {$SERVER_APP_PATH}/data/error.log default_storage_engine = MyISAM key_buffer_size = 8M max_allowed_packet = 100M + table_open_cache = 32 sort_buffer_size = 256K net_buffer_length = 4K @@ -30,8 +31,8 @@ max_connections = 500 max_connect_errors = 100 open_files_limit = 65535 +skip_name_resolve = 1 #skip-networking -#skip-name-resolve #skip-external-locking #loose-skip-innodb #skip-grant-tables @@ -73,7 +74,7 @@ innodb_buffer_pool_size = 16M innodb_additional_mem_pool_size = 2M innodb_log_file_size = 5M innodb_log_buffer_size = 8M -innodb_flush_log_at_trx_commit = 1 +innodb_flush_log_at_trx_commit = 2 innodb_lock_wait_timeout = 120 innodb_max_dirty_pages_pct = 90 innodb_read_io_threads = 1 diff --git a/plugins/mysql/conf/my5.7.cnf b/plugins/mysql/conf/my5.7.cnf index 5053013b6..78e9ce773 100644 --- a/plugins/mysql/conf/my5.7.cnf +++ b/plugins/mysql/conf/my5.7.cnf @@ -13,7 +13,6 @@ socket = {$SERVER_APP_PATH}/mysql.sock basedir = {$SERVER_APP_PATH} datadir = {$SERVER_APP_PATH}/data log-error = {$SERVER_APP_PATH}/data/error.log -default_storage_engine = MyISAM key_buffer_size = 8M table_open_cache = 32 @@ -32,11 +31,11 @@ max_connect_errors = 100 open_files_limit = 2560 max_allowed_packet = 128M +skip_name_resolve = 1 +#skip-networking #skip-external-locking -#skip-grant-tables #loose-skip-innodb -#skip-networking -#skip-name-resolve +#skip-grant-tables skip-ssl log-bin=mysql-bin @@ -44,8 +43,11 @@ binlog_format=mixed server-id = 1 slow_query_log=1 slow-query-log-file={$SERVER_APP_PATH}/data/mysql-slow.log -long_query_time=3 -#log_queries_not_using_indexes=on +long_query_time=10 +log_queries_not_using_indexes=1 +log_slow_admin_statements=1 +log_slow_slave_statements=1 +expire_logs_days=30 relay-log=mdserver relay-log-index=mdserver @@ -72,12 +74,13 @@ innodb_log_group_home_dir = {$SERVER_APP_PATH}/data innodb_buffer_pool_size = 16M innodb_log_file_size = 5M innodb_log_buffer_size = 8M -innodb_flush_log_at_trx_commit = 1 +innodb_flush_log_at_trx_commit = 2 innodb_lock_wait_timeout = 120 innodb_max_dirty_pages_pct = 90 innodb_read_io_threads = 1 innodb_write_io_threads = 1 -innodb_file_per_table=1 +innodb_file_per_table = 1 +innodb_large_prefix = 1 secure-file-priv={$SERVER_APP_PATH}/tmp diff --git a/plugins/mysql/conf/my8.0.cnf b/plugins/mysql/conf/my8.0.cnf index e1e82a44a..8668373de 100644 --- a/plugins/mysql/conf/my8.0.cnf +++ b/plugins/mysql/conf/my8.0.cnf @@ -14,7 +14,6 @@ socket = {$SERVER_APP_PATH}/mysql.sock basedir = {$SERVER_APP_PATH} datadir = {$SERVER_APP_PATH}/data log-error = {$SERVER_APP_PATH}/data/error.log -default_storage_engine = MyISAM key_buffer_size = 8M table_open_cache = 32 @@ -33,11 +32,11 @@ max_connect_errors = 100 open_files_limit = 2560 max_allowed_packet = 128M +skip_name_resolve = 1 +#skip-networking #skip-external-locking -#skip-grant-tables #loose-skip-innodb -#skip-networking -#skip-name-resolve +#skip-grant-tables skip-ssl @@ -46,8 +45,11 @@ binlog_format=mixed server-id = 1 slow_query_log=1 slow-query-log-file={$SERVER_APP_PATH}/data/mysql-slow.log -long_query_time=3 -#log_queries_not_using_indexes=on +long_query_time=10 +log_queries_not_using_indexes=1 +log_slow_admin_statements=1 +log_slow_slave_statements=1 +expire_logs_days=30 relay-log=mdserver relay-log-index=mdserver @@ -74,13 +76,13 @@ innodb_log_group_home_dir = {$SERVER_APP_PATH}/data innodb_buffer_pool_size = 16M innodb_log_file_size = 5M innodb_log_buffer_size = 8M -innodb_flush_log_at_trx_commit = 1 +innodb_flush_log_at_trx_commit = 2 innodb_lock_wait_timeout = 120 innodb_max_dirty_pages_pct = 90 innodb_read_io_threads = 1 innodb_write_io_threads = 1 innodb_file_per_table=1 -binlog_expire_logs_seconds=2592000 +innodb_large_prefix = 1 secure-file-priv={$SERVER_APP_PATH}/tmp From d9e41aaa6d57818f1d6241359232106d51cb2931 Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 2 Aug 2022 18:00:21 +0800 Subject: [PATCH 02/89] Update my.cnf --- plugins/mysql/conf/my.cnf | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/mysql/conf/my.cnf b/plugins/mysql/conf/my.cnf index 6f1f1e278..2df4d69da 100644 --- a/plugins/mysql/conf/my.cnf +++ b/plugins/mysql/conf/my.cnf @@ -31,22 +31,22 @@ max_connections = 500 max_connect_errors = 100 open_files_limit = 65535 -skip_name_resolve = 1 +skip-grant-tables #skip-networking #skip-external-locking #loose-skip-innodb -#skip-grant-tables skip-ssl - log-bin=mysql-bin binlog_format=mixed server-id = 1 -expire_logs_days = 10 slow_query_log=1 slow-query-log-file={$SERVER_APP_PATH}/data/mysql-slow.log -long_query_time=3 -#log_queries_not_using_indexes=on +long_query_time=10 +log_queries_not_using_indexes=on +log_slow_admin_statements=1 +log_slow_slave_statements=1 +expire_logs_days=30 relay-log=mdserver relay-log-index=mdserver From eb58a61859578eb50b27ab534cd29bc822de3072 Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 2 Aug 2022 18:00:24 +0800 Subject: [PATCH 03/89] Update init.lua --- plugins/op_waf/waf/lua/init.lua | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/plugins/op_waf/waf/lua/init.lua b/plugins/op_waf/waf/lua/init.lua index 61dd62774..c9d079881 100644 --- a/plugins/op_waf/waf/lua/init.lua +++ b/plugins/op_waf/waf/lua/init.lua @@ -214,16 +214,15 @@ function cc() insert_ip_list(ip,lock_time,os.time(),server_name) end --- ngx.exit(config['cc']['status']) --- return true --- else --- ngx.shared.limit:incr(token,1) --- end --- else --- ngx.shared.limit:set(token,1,cycle) --- end --- end + ngx.exit(config['cc']['status']) + return true + else + ngx.shared.limit:incr(token,1) end + else + ngx.shared.limit:set(token,1,cycle) + end +end --强制验证是否使用正常浏览器访问网站 function waf_cc_increase() From d6bd6a5c42fc322e7fce82933c591aa37bbeb452 Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 2 Aug 2022 19:00:09 +0800 Subject: [PATCH 04/89] mysql update --- plugins/mysql/conf/my.cnf | 4 ++++ plugins/mysql/conf/my5.7.cnf | 3 +++ plugins/mysql/conf/my8.0.cnf | 3 +++ plugins/mysql/index.py | 27 +++++++++++++++++++++++++-- 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/plugins/mysql/conf/my.cnf b/plugins/mysql/conf/my.cnf index 2df4d69da..946b83079 100644 --- a/plugins/mysql/conf/my.cnf +++ b/plugins/mysql/conf/my.cnf @@ -5,6 +5,9 @@ port = 3306 socket = {$SERVER_APP_PATH}/mysql.sock [mysqld] +sha256_password_private_key_path=mysql.pem +sha256_password_public_key_path=mysql.pub + pid-file = {$SERVER_APP_PATH}/data/mysql.pid user = mysql port = 3306 @@ -80,6 +83,7 @@ innodb_max_dirty_pages_pct = 90 innodb_read_io_threads = 1 innodb_write_io_threads = 1 innodb_file_per_table=1 +innodb_large_prefix = 1 secure-file-priv={$SERVER_APP_PATH}/tmp diff --git a/plugins/mysql/conf/my5.7.cnf b/plugins/mysql/conf/my5.7.cnf index 78e9ce773..5b8efc7df 100644 --- a/plugins/mysql/conf/my5.7.cnf +++ b/plugins/mysql/conf/my5.7.cnf @@ -6,6 +6,9 @@ socket = {$SERVER_APP_PATH}/mysql.sock default-character-set = UTF8MB4 [mysqld] +sha256_password_private_key_path=mysql.pem +sha256_password_public_key_path=mysql.pub + pid-file = {$SERVER_APP_PATH}/data/mysql.pid user = mysql port = 3306 diff --git a/plugins/mysql/conf/my8.0.cnf b/plugins/mysql/conf/my8.0.cnf index 8668373de..83e601070 100644 --- a/plugins/mysql/conf/my8.0.cnf +++ b/plugins/mysql/conf/my8.0.cnf @@ -6,7 +6,10 @@ socket = {$SERVER_APP_PATH}/mysql.sock default-character-set = UTF8MB4 [mysqld] +sha256_password_private_key_path=mysql.pem +sha256_password_public_key_path=mysql.pub default_authentication_plugin=mysql_native_password + pid-file = {$SERVER_APP_PATH}/data/mysql.pid user = mysql port = 3306 diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 52157e3cf..fb7023a7d 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -146,6 +146,26 @@ def pMysqlDb(): return db +def makeInitRsaKey(version=''): + datadir = getServerDir() + "/data" + + mysql_pem = datadir + "/mysql.pem" + if not os.path.exists(mysql_pem): + rdata = mw.execShell( + 'cd ' + datadir + ' && openssl genrsa -out mysql.pem 1024') + # print(data) + rdata = mw.execShell( + 'cd ' + datadir + ' && openssl rsa -in mysql.pem -pubout -out mysql.pub') + # print(rdata) + + if not mw.isAppleSystem(): + mw.execShell('cd ' + datadir + ' && chmod 400 mysql.pem') + mw.execShell('cd ' + datadir + ' && chmod 444 mysql.pub') + + mw.execShell('cd ' + datadir + ' && chown mysql:mysql mysql.pem') + mw.execShell('cd ' + datadir + ' && chown mysql:mysql mysql.pub') + + def initDreplace(version=''): initd_tpl = getInitdTpl(version) @@ -486,8 +506,11 @@ def my8cmd(version, method): def appCMD(version, action): if version == '8.0' or version == '5.7': - return my8cmd(version, action) - return myOp(version, action) + status = my8cmd(version, action) + else: + status = myOp(version, action) + makeInitRsaKey(version) + return status def start(version=''): From 19ae6d4579e7ed53d4a86020c4281058b546fc38 Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 2 Aug 2022 23:08:44 +0800 Subject: [PATCH 05/89] up --- plugins/mysql/conf/my8.0.cnf | 1 - plugins/mysql/index.html | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/mysql/conf/my8.0.cnf b/plugins/mysql/conf/my8.0.cnf index 83e601070..5405bb876 100644 --- a/plugins/mysql/conf/my8.0.cnf +++ b/plugins/mysql/conf/my8.0.cnf @@ -85,7 +85,6 @@ innodb_max_dirty_pages_pct = 90 innodb_read_io_threads = 1 innodb_write_io_threads = 1 innodb_file_per_table=1 -innodb_large_prefix = 1 secure-file-priv={$SERVER_APP_PATH}/tmp diff --git a/plugins/mysql/index.html b/plugins/mysql/index.html index 78645b3b6..f7db357ea 100755 --- a/plugins/mysql/index.html +++ b/plugins/mysql/index.html @@ -2,7 +2,7 @@
- +

服务

自启动

配置文件

From 3a4622d8b73a89dcc3e5491de66a43850928359f Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 2 Aug 2022 23:11:19 +0800 Subject: [PATCH 06/89] Update my8.0.cnf --- plugins/mysql/conf/my8.0.cnf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mysql/conf/my8.0.cnf b/plugins/mysql/conf/my8.0.cnf index 5405bb876..448a8fe1d 100644 --- a/plugins/mysql/conf/my8.0.cnf +++ b/plugins/mysql/conf/my8.0.cnf @@ -52,7 +52,7 @@ long_query_time=10 log_queries_not_using_indexes=1 log_slow_admin_statements=1 log_slow_slave_statements=1 -expire_logs_days=30 +binlog_expire_logs_seconds=2592000 relay-log=mdserver relay-log-index=mdserver From 391be0f52ba4b1e7d97ff74b7b76b44b00eadd38 Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 2 Aug 2022 23:29:12 +0800 Subject: [PATCH 07/89] up --- class/plugin/orm.py | 4 ++-- plugins/mysql/conf/my8.0.cnf | 2 +- plugins/mysql/index.py | 10 ---------- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/class/plugin/orm.py b/class/plugin/orm.py index 64ffd1790..562d16906 100755 --- a/class/plugin/orm.py +++ b/class/plugin/orm.py @@ -26,11 +26,11 @@ class ORM: try: self.__DB_CONN = pymysql.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS, - port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1, cursorclass=pymysql.cursors.DictCursor) + port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1, 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, - port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1, cursorclass=pymysql.cursors.DictCursor) + port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1, unix_socket=self.__DB_SOCKET, cursorclass=pymysql.cursors.DictCursor) self.__DB_CUR = self.__DB_CONN.cursor() return True diff --git a/plugins/mysql/conf/my8.0.cnf b/plugins/mysql/conf/my8.0.cnf index 448a8fe1d..21526ddca 100644 --- a/plugins/mysql/conf/my8.0.cnf +++ b/plugins/mysql/conf/my8.0.cnf @@ -51,7 +51,7 @@ slow-query-log-file={$SERVER_APP_PATH}/data/mysql-slow.log long_query_time=10 log_queries_not_using_indexes=1 log_slow_admin_statements=1 -log_slow_slave_statements=1 +log_slow_replica_statements=1 binlog_expire_logs_seconds=2592000 relay-log=mdserver diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index fb7023a7d..816b4be67 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -732,16 +732,6 @@ def isSqlError(mysqlMsg): return None -def mapToList(map_obj): - # map to list - try: - if type(map_obj) != list and type(map_obj) != str: - map_obj = list(map_obj) - return map_obj - except: - return [] - - def __createUser(dbname, username, password, address): pdb = pMysqlDb() From b697cb2d070409b9f94892715d77914450d457fc Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 2 Aug 2022 23:42:39 +0800 Subject: [PATCH 08/89] up --- plugins/mysql/conf/my8.0.cnf | 2 +- plugins/mysql/index.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/mysql/conf/my8.0.cnf b/plugins/mysql/conf/my8.0.cnf index 21526ddca..a247f5663 100644 --- a/plugins/mysql/conf/my8.0.cnf +++ b/plugins/mysql/conf/my8.0.cnf @@ -8,7 +8,7 @@ default-character-set = UTF8MB4 [mysqld] sha256_password_private_key_path=mysql.pem sha256_password_public_key_path=mysql.pub -default_authentication_plugin=mysql_native_password +authentication_policy=mysql_native_password pid-file = {$SERVER_APP_PATH}/data/mysql.pid user = mysql diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 816b4be67..6d07b4716 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -188,6 +188,7 @@ def initDreplace(version=''): if not os.path.exists(mysql_tmp): os.mkdir(mysql_tmp) mw.execShell("chown -R mysql:mysql " + mysql_tmp) + mw.execShell("chmod 750 " + mysql_tmp) mysql_conf = mysql_conf_dir + '/my.cnf' if not os.path.exists(mysql_conf): From be7aeab88347cabd6d42750ecc75c48f7b4059cd Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 2 Aug 2022 23:43:25 +0800 Subject: [PATCH 09/89] up --- plugins/mysql/conf/my.cnf | 1 - plugins/mysql/conf/my5.7.cnf | 1 - plugins/mysql/conf/my8.0.cnf | 1 - 3 files changed, 3 deletions(-) diff --git a/plugins/mysql/conf/my.cnf b/plugins/mysql/conf/my.cnf index 946b83079..0712c4144 100644 --- a/plugins/mysql/conf/my.cnf +++ b/plugins/mysql/conf/my.cnf @@ -38,7 +38,6 @@ skip-grant-tables #skip-networking #skip-external-locking #loose-skip-innodb -skip-ssl log-bin=mysql-bin binlog_format=mixed diff --git a/plugins/mysql/conf/my5.7.cnf b/plugins/mysql/conf/my5.7.cnf index 5b8efc7df..b685bfbb6 100644 --- a/plugins/mysql/conf/my5.7.cnf +++ b/plugins/mysql/conf/my5.7.cnf @@ -39,7 +39,6 @@ skip_name_resolve = 1 #skip-external-locking #loose-skip-innodb #skip-grant-tables -skip-ssl log-bin=mysql-bin binlog_format=mixed diff --git a/plugins/mysql/conf/my8.0.cnf b/plugins/mysql/conf/my8.0.cnf index a247f5663..fe6122534 100644 --- a/plugins/mysql/conf/my8.0.cnf +++ b/plugins/mysql/conf/my8.0.cnf @@ -40,7 +40,6 @@ skip_name_resolve = 1 #skip-external-locking #loose-skip-innodb #skip-grant-tables -skip-ssl log-bin=mysql-bin From 83cab0a5b384b2da8483d1b2ef27fa25dd666bca Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 3 Aug 2022 00:21:14 +0800 Subject: [PATCH 10/89] up --- plugins/mysql/index.py | 3 ++- plugins/mysql/init.d/mysql.tpl | 3 ++- plugins/mysql/init.d/mysql8.0.tpl | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 6d07b4716..affce11e7 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -2022,6 +2022,7 @@ def doFullSync(): db.query('stop slave') writeDbSyncStatus({'code': 3, 'msg': '停止从库完成...', 'progress': 45}) + print(cmd_data) dlist = db.query(cmd_data['data']) writeDbSyncStatus({'code': 4, 'msg': '刷新从库同步信息完成...', 'progress': 50}) @@ -2055,7 +2056,7 @@ def fullSync(version=''): status_file = '/tmp/db_async_status.txt' if args['begin'] == '1': - cmd = 'cd ' + mw.getRunDir() + ' && python ' + \ + cmd = 'cd ' + mw.getRunDir() + ' && python3 ' + \ getPluginDir() + \ '/index.py do_full_sync {"db":"' + args['db'] + '"} &' print(cmd) diff --git a/plugins/mysql/init.d/mysql.tpl b/plugins/mysql/init.d/mysql.tpl index d2dac7bc3..6a0a54174 100644 --- a/plugins/mysql/init.d/mysql.tpl +++ b/plugins/mysql/init.d/mysql.tpl @@ -250,9 +250,10 @@ parse_server_arguments `$print_defaults $extra_args mysqld server mysql_server m # # Set pid file if not given # +found_pid=`cd $datadir && ls |grep '.pid'` if test -z "$mysqld_pid_file_path" then - mysqld_pid_file_path=$datadir/`hostname`.pid + mysqld_pid_file_path=$datadir/$found_pid else case "$mysqld_pid_file_path" in /* ) ;; diff --git a/plugins/mysql/init.d/mysql8.0.tpl b/plugins/mysql/init.d/mysql8.0.tpl index 5e62992a7..dda204c6b 100755 --- a/plugins/mysql/init.d/mysql8.0.tpl +++ b/plugins/mysql/init.d/mysql8.0.tpl @@ -241,9 +241,10 @@ parse_server_arguments `$print_defaults $extra_args mysqld server mysql_server m # # Set pid file if not given # +found_pid=`cd $datadir && ls |grep '.pid'` if test -z "$mysqld_pid_file_path" then - mysqld_pid_file_path=$datadir/`hostname`.pid + mysqld_pid_file_path=$datadir/$found_pid else case "$mysqld_pid_file_path" in /* ) ;; From 209488b0ed875ddb27751e6f3d8c7f6989cd9a21 Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 3 Aug 2022 01:49:42 +0800 Subject: [PATCH 11/89] =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/mysql/index.py | 54 +++++++++++++++++++++++++++++++++++++-- plugins/mysql/js/mysql.js | 38 +++++++++++++++++++-------- 2 files changed, 79 insertions(+), 13 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index affce11e7..e74c00c43 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -1863,11 +1863,58 @@ def getSlaveSyncCmd(version=''): return mw.returnJson(True, 'ok', cmd) +def initSlaveStatus(version=''): + db = pMysqlDb() + dlist = db.query('show slave status') + if len(dlist) > 0: + return mw.returnJson(False, '已经初始化好了zz...') + + id_rsa_conn = pSqliteDb('slave_id_rsa') + data = id_rsa_conn.field('ip,port,id_rsa').select() + + if len(data) < 1: + return mw.returnJson(False, '需要先配置【[主]SSH配置】!') + + SSH_PRIVATE_KEY = "/tmp/t_ssh.txt" + ip = data[0]['ip'] + master_port = int(data[0]['port']) + mw.writeFile(SSH_PRIVATE_KEY, data[0]['id_rsa'].replace('\\n', '\n')) + + try: + import paramiko + paramiko.util.log_to_file('paramiko.log') + ssh = paramiko.SSHClient() + mw.execShell("chmod 600 " + SSH_PRIVATE_KEY) + key = paramiko.RSAKey.from_private_key_file(SSH_PRIVATE_KEY) + ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + ssh.connect(hostname=ip, port=master_port, + username='root', pkey=key) + + cmd = 'cd /www/server/mdserver-web && \ + python3 /www/server/mdserver-web/plugins/mysql/index.py get_master_rep_slave_user_cmd {"username":"","db":""}' + stdin, stdout, stderr = ssh.exec_command(cmd) + result = stdout.read() + # result_err = stderr.read() + result = result.decode('utf-8') + cmd_data = json.loads(result) + + db.query('stop slave') + db.query(cmd_data['data']) + db.query('start slave') + except Exception as e: + return mw.returnJson(True, 'SSH认证配置连接失败!' + str(e)) + + time.sleep(0.5) + ssh.close() + os.system("rm -rf " + SSH_PRIVATE_KEY) + return mw.returnJson(True, '设置成功!') + + def setSlaveStatus(version=''): db = pMysqlDb() dlist = db.query('show slave status') if len(dlist) == 0: - return mw.returnJson(False, '需要手动添加主服务同步命令!') + return mw.returnJson(False, '需要手动添加主服务同步命令或者执行[初始化]!') if len(dlist) > 0 and (dlist[0]["Slave_IO_Running"] == 'Yes' or dlist[0]["Slave_SQL_Running"] == 'Yes'): db.query('stop slave') @@ -1879,7 +1926,8 @@ def setSlaveStatus(version=''): def deleteSlave(version=''): db = pMysqlDb() - dlist = db.query('stop slave;reset slave all') + dlist = db.query('stop slave') + dlist = db.query('reset slave all') return mw.returnJson(True, '删除成功!') @@ -2216,6 +2264,8 @@ if __name__ == "__main__": print(delSlaveSSH(version)) elif func == 'update_slave_ssh': print(updateSlaveSSH(version)) + elif func == 'init_slave_status': + print(initSlaveStatus(version)) elif func == 'set_slave_status': print(setSlaveStatus(version)) elif func == 'delete_slave': diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index 57272caea..50ac5ee1d 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -1081,7 +1081,7 @@ function myLogs(){ } else { error_body = rdata.msg; } - $("#error_log").text(error_body); + $("#error_log").html(error_body); var ob = document.getElementById('error_log'); ob.scrollTop = ob.scrollHeight; }); @@ -1467,11 +1467,9 @@ function getMasterRepSlaveList(){ function deleteSlave(){ myPost('delete_slave', {}, function(data){ var rdata = $.parseJSON(data.data); - layer.msg(rdata['msg']); - setTimeout(function(){ + showMsg(rdata['msg'], function(){ masterOrSlaveConf(); - }, 3000); - + },{},3000); }); } @@ -1546,7 +1544,7 @@ function addSlaveSSH(ip=''){ var index = layer.open({ type: 1, - area: ['500px','400px'], + area: ['500px','450px'], title: '添加SSH', closeBtn: 1, shift: 5, @@ -1557,11 +1555,13 @@ function addSlaveSSH(ip=''){
端口
\
\ ID_RSA\ -
\ +
\
\ \ ", - success:function(){}, + success:function(){ + $('textarea[name="id_rsa"]').html(id_rsa); + }, yes:function(index){ var ip = $('input[name="ip"]').val(); var port = $('input[name="port"]').val(); @@ -1671,6 +1671,17 @@ function handlerRun(){ }); } +function initSlaveStatus(){ + myPost('init_slave_status', '', function(data){ + var rdata = $.parseJSON(data.data); + showMsg(rdata.msg,function(){ + if (rdata.status){ + masterOrSlaveConf(); + } + },{icon:rdata.status?1:2},2000); + }); +} + function masterOrSlaveConf(version=''){ function getMasterDbList(){ @@ -1813,7 +1824,6 @@ function masterOrSlaveConf(version=''){
\ 手动命令\ 全量同步\ - [主]SSH配置\
\
'; @@ -1822,20 +1832,26 @@ function masterOrSlaveConf(version=''){ }); } + + function getMasterStatus(){ myPost('get_master_status', '', function(data){ var rdata = $.parseJSON(data.data); var limitCon = '

\ Master[主]配置\ -


\ +
\

\ \
\
\ + \

\ Slave[从]配置\ -


\ + \ + \ + \

\ +
\ \
\ \ From 0277ca280ea30b61e313e5d0972ed93a4528c8ae Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 3 Aug 2022 08:53:45 +0800 Subject: [PATCH 12/89] 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 e74c00c43..bd3b277e0 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -1902,7 +1902,7 @@ def initSlaveStatus(version=''): db.query(cmd_data['data']) db.query('start slave') except Exception as e: - return mw.returnJson(True, 'SSH认证配置连接失败!' + str(e)) + return mw.returnJson(False, 'SSH认证配置连接失败!' + str(e)) time.sleep(0.5) ssh.close() From 085ddad7eaa8198984b81eb9da97d53ec2d4fcd6 Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 3 Aug 2022 11:17:20 +0800 Subject: [PATCH 13/89] up --- plugins/mysql/conf/my.cnf | 4 ++-- plugins/mysql/conf/my5.7.cnf | 4 ++-- plugins/mysql/conf/my8.0.cnf | 4 ++-- plugins/mysql/index.py | 22 +++++++++++++--------- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/plugins/mysql/conf/my.cnf b/plugins/mysql/conf/my.cnf index 0712c4144..44d312086 100644 --- a/plugins/mysql/conf/my.cnf +++ b/plugins/mysql/conf/my.cnf @@ -46,8 +46,8 @@ slow_query_log=1 slow-query-log-file={$SERVER_APP_PATH}/data/mysql-slow.log long_query_time=10 log_queries_not_using_indexes=on -log_slow_admin_statements=1 -log_slow_slave_statements=1 +#log_slow_admin_statements=1 +#log_slow_slave_statements=1 expire_logs_days=30 relay-log=mdserver diff --git a/plugins/mysql/conf/my5.7.cnf b/plugins/mysql/conf/my5.7.cnf index b685bfbb6..c66e871c0 100644 --- a/plugins/mysql/conf/my5.7.cnf +++ b/plugins/mysql/conf/my5.7.cnf @@ -47,8 +47,8 @@ slow_query_log=1 slow-query-log-file={$SERVER_APP_PATH}/data/mysql-slow.log long_query_time=10 log_queries_not_using_indexes=1 -log_slow_admin_statements=1 -log_slow_slave_statements=1 +#log_slow_admin_statements=1 +#log_slow_slave_statements=1 expire_logs_days=30 relay-log=mdserver diff --git a/plugins/mysql/conf/my8.0.cnf b/plugins/mysql/conf/my8.0.cnf index fe6122534..ffe2dc5a7 100644 --- a/plugins/mysql/conf/my8.0.cnf +++ b/plugins/mysql/conf/my8.0.cnf @@ -49,8 +49,8 @@ slow_query_log=1 slow-query-log-file={$SERVER_APP_PATH}/data/mysql-slow.log long_query_time=10 log_queries_not_using_indexes=1 -log_slow_admin_statements=1 -log_slow_replica_statements=1 +#log_slow_admin_statements=1 +#log_slow_replica_statements=1 binlog_expire_logs_seconds=2592000 relay-log=mdserver diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index bd3b277e0..117483239 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -1880,34 +1880,38 @@ def initSlaveStatus(version=''): master_port = int(data[0]['port']) mw.writeFile(SSH_PRIVATE_KEY, data[0]['id_rsa'].replace('\\n', '\n')) + import paramiko + paramiko.util.log_to_file('paramiko.log') + ssh = paramiko.SSHClient() + try: - import paramiko - paramiko.util.log_to_file('paramiko.log') - ssh = paramiko.SSHClient() + mw.execShell("chmod 600 " + SSH_PRIVATE_KEY) key = paramiko.RSAKey.from_private_key_file(SSH_PRIVATE_KEY) ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - ssh.connect(hostname=ip, port=master_port, - username='root', pkey=key) + ssh.connect(hostname=ip, port=master_port, username='root', pkey=key) - cmd = 'cd /www/server/mdserver-web && \ - python3 /www/server/mdserver-web/plugins/mysql/index.py get_master_rep_slave_user_cmd {"username":"","db":""}' + cmd = 'cd /www/server/mdserver-web && python3 plugins/mysql/index.py get_master_rep_slave_user_cmd {"username":"","db":""}' stdin, stdout, stderr = ssh.exec_command(cmd) result = stdout.read() # result_err = stderr.read() + result = result.decode('utf-8') cmd_data = json.loads(result) + if not cmd_data['status']: + return mw.returnJson(False, '[主]:' + cmd_data['msg']) + db.query('stop slave') db.query(cmd_data['data']) db.query('start slave') except Exception as e: return mw.returnJson(False, 'SSH认证配置连接失败!' + str(e)) - time.sleep(0.5) ssh.close() + time.sleep(1) os.system("rm -rf " + SSH_PRIVATE_KEY) - return mw.returnJson(True, '设置成功!') + return mw.returnJson(True, '初始化成功!') def setSlaveStatus(version=''): From cb2466b65ca1dc8d77a885cd5d9c09d24a9cc9d5 Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 3 Aug 2022 15:06:10 +0800 Subject: [PATCH 14/89] up --- class/plugin/orm.py | 27 ++++++++++++++++++++------- plugins/mysql/index.py | 27 ++++++++------------------- plugins/mysql/js/mysql.js | 6 +++--- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/class/plugin/orm.py b/class/plugin/orm.py index 562d16906..aac2b9e36 100755 --- a/class/plugin/orm.py +++ b/class/plugin/orm.py @@ -24,13 +24,26 @@ class ORM: '''连接数据库''' try: - try: - self.__DB_CONN = pymysql.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS, - port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1, 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, - port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1, unix_socket=self.__DB_SOCKET, cursorclass=pymysql.cursors.DictCursor) + 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, + port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1, + 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, + port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1, + 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, + 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, + port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1, + cursorclass=pymysql.cursors.DictCursor) self.__DB_CUR = self.__DB_CONN.cursor() return True diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 117483239..de76df55e 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -1656,10 +1656,6 @@ def addMasterRepSlaveUser(version=''): def getMasterRepSlaveUserCmd(version): - version_pl = getServerDir() + "/version.pl" - if os.path.exists(version_pl): - version = mw.readFile(version_pl).strip() - args = getArgs() data = checkArgs(args, ['username', 'db']) if not data[0]: @@ -1681,8 +1677,8 @@ def getMasterRepSlaveUserCmd(version): ip = mw.getLocalIp() port = getMyPort() - db = pMysqlDb() + mstatus = db.query('show master status') if len(mstatus) == 0: return mw.returnJson(False, '未开启!') @@ -1915,14 +1911,17 @@ def initSlaveStatus(version=''): def setSlaveStatus(version=''): + db = pMysqlDb() dlist = db.query('show slave status') if len(dlist) == 0: - return mw.returnJson(False, '需要手动添加主服务同步命令或者执行[初始化]!') + return mw.returnJson(False, '需要手动添加主服务命令或者执行[初始化]!') if len(dlist) > 0 and (dlist[0]["Slave_IO_Running"] == 'Yes' or dlist[0]["Slave_SQL_Running"] == 'Yes'): db.query('stop slave') else: + + print(dlist[0]) db.query('start slave') return mw.returnJson(True, '设置成功!') @@ -1959,17 +1958,6 @@ def dumpMysqlData(version): return 'fail' -from threading import Thread -from time import sleep - - -def mw_async(f): - def wrapper(*args, **kwargs): - thr = Thread(target=f, args=args, kwargs=kwargs) - thr.start() - return wrapper - - ############### --- 重要 同步---- ########### def writeDbSyncStatus(data): @@ -2147,8 +2135,9 @@ if __name__ == "__main__": func = sys.argv[1] version = "5.6" - if (len(sys.argv) > 2): - version = sys.argv[2] + version_pl = getServerDir() + "/version.pl" + if os.path.exists(version_pl): + version = mw.readFile(version_pl).strip() if func == 'status': print(status(version)) diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index 50ac5ee1d..1f5e903c3 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -1034,9 +1034,9 @@ function myLogs(){ var line_status = "" if (rdata.status){ line_status = '\ - ' + '; } else { - line_status = '' + line_status = ''; } var limitCon = '

\ @@ -1044,7 +1044,7 @@ function myLogs(){ '+line_status+'\

错误日志

\ \ -

' +

'; $(".soft-man-con").html(limitCon); //设置二进制日志 From 5352e3e5faf6e73d68db8469d8ab62cb4bb47422 Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 3 Aug 2022 19:53:38 +0800 Subject: [PATCH 15/89] up --- plugins/mysql/conf/my.cnf | 3 ++- plugins/php/versions/common/gd.sh | 2 +- plugins/php/versions/common/gd_old.sh | 2 +- plugins/php/versions/common/yaf.sh | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/mysql/conf/my.cnf b/plugins/mysql/conf/my.cnf index 44d312086..b5b955337 100644 --- a/plugins/mysql/conf/my.cnf +++ b/plugins/mysql/conf/my.cnf @@ -34,7 +34,8 @@ max_connections = 500 max_connect_errors = 100 open_files_limit = 65535 -skip-grant-tables +skip-name-resolve=1 +#skip-grant-tables #skip-networking #skip-external-locking #loose-skip-innodb diff --git a/plugins/php/versions/common/gd.sh b/plugins/php/versions/common/gd.sh index 462f72063..0e54103a6 100755 --- a/plugins/php/versions/common/gd.sh +++ b/plugins/php/versions/common/gd.sh @@ -79,7 +79,7 @@ Install_lib() echo "[${LIBNAME}]" >> $serverPath/php/$version/etc/php.ini echo "extension=${LIBNAME}.so" >> $serverPath/php/$version/etc/php.ini - $serverPath/php/init.d/php${version} restart + bash ${rootPath}/plugins/php/versions/lib.sh $version restart echo '===========================================================' echo 'successful!' } diff --git a/plugins/php/versions/common/gd_old.sh b/plugins/php/versions/common/gd_old.sh index 40a13fcd8..abb16a1f1 100755 --- a/plugins/php/versions/common/gd_old.sh +++ b/plugins/php/versions/common/gd_old.sh @@ -89,7 +89,7 @@ Install_lib() echo "[${LIBNAME}]" >> $serverPath/php/$version/etc/php.ini echo "extension=${LIBNAME}.so" >> $serverPath/php/$version/etc/php.ini - $serverPath/php/init.d/php${version} restart + bash ${rootPath}/plugins/php/versions/lib.sh $version restart echo '===========================================================' echo 'successful!' } diff --git a/plugins/php/versions/common/yaf.sh b/plugins/php/versions/common/yaf.sh index 1ab4fc4aa..5b3bf8fb0 100755 --- a/plugins/php/versions/common/yaf.sh +++ b/plugins/php/versions/common/yaf.sh @@ -109,7 +109,7 @@ Uninstall_lib() sed -i $BAK "/${LIBNAME}.use_namespace/d" $serverPath/php/$version/etc/php.ini sed -i $BAK "/\[${LIBNAME}\]/d" $serverPath/php/$version/etc/php.ini - rm -f $extFile + rm -rf $extFile bash ${rootPath}/plugins/php/versions/lib.sh $version restart echo '===============================================' echo 'successful!' From d90b139714d171a434cc5e7bccde306f219f35fa Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 3 Aug 2022 21:06:08 +0800 Subject: [PATCH 16/89] Update crontab.js --- route/static/app/crontab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/route/static/app/crontab.js b/route/static/app/crontab.js index 459e65d50..3509bdcf4 100755 --- a/route/static/app/crontab.js +++ b/route/static/app/crontab.js @@ -35,7 +35,7 @@ function getLogs(id){ }); setTimeout(function(){ - $("#crontab-log").text(rdata.msg); + $("#crontab-log").html(rdata.msg); },200); },'json'); } From 5906ce18b56ec499cafefaa93fd5d41fe76374c1 Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 3 Aug 2022 21:10:37 +0800 Subject: [PATCH 17/89] 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 317f0a10b..51e1e6325 100755 --- a/scripts/backup.py +++ b/scripts/backup.py @@ -135,7 +135,7 @@ class backupTools: mw.M('backup').add('type,name,pid,filename,addtime,size', (1, os.path.basename( filename), pid, filename, endDate, os.path.getsize(filename))) - log = "数据库[" + name + "]备份成功,用时[" + str(round(outTime, 2)) + u"]秒" + log = "数据库[" + name + "]备份成功,用时[" + str(round(outTime, 2)) + "]秒" mw.writeLog('计划任务', log) print("★[" + endDate + "] " + log) print("|---保留最新的[" + count + "]份备份") From d708383ce6f2777aea83957600c212b21bce61da Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 3 Aug 2022 21:11:41 +0800 Subject: [PATCH 18/89] Update backup.py --- scripts/backup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/backup.py b/scripts/backup.py index 51e1e6325..a3ea8cf9d 100755 --- a/scripts/backup.py +++ b/scripts/backup.py @@ -112,8 +112,8 @@ class backupTools: if len(mycnf) > 100: mw.writeFile(db_path + '/etc/my.cnf', mycnf) - mw.execShell( - db_path + "/bin/mysqldump --opt --default-character-set=utf8 " + name + " | gzip > " + filename) + mw.execShell(db_path + "/bin/mysqldump --opt --default-character-set=utf8 " + + name + " | gzip > " + filename) if not os.path.exists(filename): endDate = time.strftime('%Y/%m/%d %X', time.localtime()) From 3f9d6737c9395565a12e86ab25280af9aa498425 Mon Sep 17 00:00:00 2001 From: midoks Date: Thu, 4 Aug 2022 02:05:55 +0800 Subject: [PATCH 19/89] up --- plugins/mysql/index.html | 7 +++++++ plugins/mysql/index.py | 8 ++++---- plugins/mysql/js/mysql.js | 13 +++++++++++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/plugins/mysql/index.html b/plugins/mysql/index.html index f7db357ea..ee348dbdc 100755 --- a/plugins/mysql/index.html +++ b/plugins/mysql/index.html @@ -49,6 +49,13 @@ #db_tools button:last-child{ margin-right: 0; } + +.conf_p span { + display: inline-block; + margin-right: 10px; + width: 95px; + text-align: right; +} \ No newline at end of file diff --git a/plugins/postgresql/index.py b/plugins/postgresql/index.py new file mode 100755 index 000000000..63e4f43d4 --- /dev/null +++ b/plugins/postgresql/index.py @@ -0,0 +1,745 @@ +# coding:utf-8 + +import sys +import io +import os +import time +import subprocess +import re +import json + + +# reload(sys) +# sys.setdefaultencoding('utf-8') + +sys.path.append(os.getcwd() + "/class/core") +import mw + + +if mw.isAppleSystem(): + cmd = 'ls /usr/local/lib/ | grep python | cut -d \\ -f 1 | awk \'END {print}\'' + info = mw.execShell(cmd) + p = "/usr/local/lib/" + info[0].strip() + "/site-packages" + sys.path.append(p) + + +app_debug = False +if mw.isAppleSystem(): + app_debug = True + + +def getPluginName(): + return 'postgresql' + + +def getPluginDir(): + return mw.getPluginDir() + '/' + getPluginName() + + +def getServerDir(): + return mw.getServerDir() + '/' + getPluginName() + + +def getInitDFile(): + if app_debug: + return '/tmp/' + getPluginName() + return '/etc/init.d/' + getPluginName() + + +def getArgs(): + args = sys.argv[2:] + + tmp = {} + args_len = len(args) + + if args_len == 1: + t = args[0].strip('{').strip('}') + t = t.split(':') + 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 getConf(): + path = getServerDir() + '/data/postgresql.conf' + 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 getInitdTpl(version=''): + path = getPluginDir() + '/init.d/postgresql.tpl' + if not os.path.exists(path): + path = getPluginDir() + '/init.d/postgresql.tpl' + return path + + +def contentReplace(content): + service_path = mw.getServerDir() + content = content.replace('{$ROOT_PATH}', mw.getRootDir()) + content = content.replace('{$SERVER_PATH}', service_path) + content = content.replace('{$APP_PATH}', service_path + '/postgresql') + return content + + +def pSqliteDb(dbname='databases'): + file = getServerDir() + '/pgsql.db' + name = 'pgsql' + if not os.path.exists(file): + conn = mw.M(dbname).dbPos(getServerDir(), name) + csql = mw.readFile(getPluginDir() + '/conf/pgsql.sql') + csql_list = csql.split(';') + for index in range(len(csql_list)): + conn.execute(csql_list[index], ()) + else: + # 现有run + # conn = mw.M(dbname).dbPos(getServerDir(), name) + # csql = mw.readFile(getPluginDir() + '/conf/mysql.sql') + # csql_list = csql.split(';') + # for index in range(len(csql_list)): + # conn.execute(csql_list[index], ()) + conn = mw.M(dbname).dbPos(getServerDir(), name) + return conn + + +def pMysqlDb(): + # pymysql + db = mw.getMyORM() + # MySQLdb | + # db = mw.getMyORMDb() + + db.setPort(getDbPort()) + db.setSocket(getSocketFile()) + # db.setCharset("utf8") + db.setPwd(pSqliteDb('config').where('id=?', (1,)).getField('mysql_root')) + return db + + +def initDreplace(version=''): + + conf_dir = getServerDir() + '/etc' + log_dir = getServerDir() + "/logs" + conf_list = [ + conf_dir, + log_dir + ] + for conf in conf_list: + if not os.path.exists(conf): + os.mkdir(conf) + + my_conf = conf_dir + '/my.cnf' + if not os.path.exists(my_conf): + tpl = getPluginDir() + '/conf/my.cnf' + content = mw.readFile(tpl) + content = contentReplace(content) + mw.writeFile(my_conf, content) + + # systemd + system_dir = mw.systemdCfgDir() + service = system_dir + '/postgresql.service' + if os.path.exists(system_dir) and not os.path.exists(service): + tpl = getPluginDir() + '/init.d/postgresql.service.tpl' + service_path = mw.getServerDir() + content = mw.readFile(tpl) + content = content.replace('{$SERVER_PATH}', service_path) + mw.writeFile(service, content) + mw.execShell('systemctl daemon-reload') + + if not mw.isAppleSystem(): + mw.execShell('chown -R postgresql:postgresql ' + getServerDir()) + + initd_path = getServerDir() + '/init.d' + if not os.path.exists(initd_path): + os.mkdir(initd_path) + + file_bin = initd_path + '/' + getPluginName() + if not os.path.exists(file_bin): + initd_tpl = getInitdTpl(version) + content = mw.readFile(initd_tpl) + content = contentReplace(content) + mw.writeFile(file_bin, content) + mw.execShell('chmod +x ' + file_bin) + return file_bin + + +def status(version=''): + data = mw.execShell( + "ps -ef|grep postgres |grep -v grep | grep -v python | grep -v mdserver-web | awk '{print $2}'") + if data[0] == '': + return 'stop' + return 'start' + + +def getDataDir(): + file = getConf() + content = mw.readFile(file) + rep = 'datadir\s*=\s*(.*)' + tmp = re.search(rep, content) + return tmp.groups()[0].strip() + + +def getPidFile(): + file = getConf() + content = mw.readFile(file) + rep = 'pid-file\s*=\s*(.*)' + tmp = re.search(rep, content) + return tmp.groups()[0].strip() + + +def getErrorLog(): + args = getArgs() + path = getDataDir() + filename = '' + for n in os.listdir(path): + if len(n) < 5: + continue + if n == 'error.log': + filename = path + '/' + n + break + # print filename + if not os.path.exists(filename): + return mw.returnJson(False, '指定文件不存在!') + if 'close' in args: + mw.writeFile(filename, '') + return mw.returnJson(False, '日志已清空') + info = mw.getNumLines(filename, 18) + return mw.returnJson(True, 'OK', info) + + +def getShowLogFile(): + file = getConf() + content = mw.readFile(file) + rep = 'slow-query-log-file\s*=\s*(.*)' + tmp = re.search(rep, content) + return tmp.groups()[0].strip() + + +def pGetDbUser(): + if mw.isAppleSystem(): + user = mw.execShell( + "who | sed -n '2, 1p' |awk '{print $1}'")[0].strip() + return user + return 'postgresql' + + +def initPgData(): + datadir = getDataDir() + if not os.path.exists(datadir + '/postgresql'): + serverdir = getServerDir() + myconf = serverdir + "/etc/my.cnf" + user = pGetDbUser() + cmd = 'cd ' + serverdir + ' && ./bin/initdb -D ' + serverdir + "/data" + mw.execShell(cmd) + return False + return True + + +def initPgPwd(): + + serverdir = getServerDir() + pwd = mw.getRandomString(16) + + cmd_pass = serverdir + '/bin/mysql -uroot -e' + cmd_pass = cmd_pass + "\"UPDATE mysql.user SET password=PASSWORD('" + \ + pwd + "') WHERE user='root';" + cmd_pass = cmd_pass + "flush privileges;\"" + data = mw.execShell(cmd_pass) + # print(cmd_pass) + # print(data) + + # 删除测试数据库 + drop_test_db = serverdir + '/bin/mysql -uroot -p' + \ + pwd + ' -e "drop database test";' + mw.execShell(drop_test_db) + + pSqliteDb('config').where('id=?', (1,)).save('mysql_root', (pwd,)) + return True + + +def myOp(version, method): + # import commands + init_file = initDreplace() + cmd = init_file + ' ' + method + try: + isInited = initPgData() + if not isInited: + if mw.isAppleSystem(): + cmd_init_start = init_file + ' start' + subprocess.Popen(cmd_init_start, stdout=subprocess.PIPE, shell=True, + bufsize=4096, stderr=subprocess.PIPE) + + time.sleep(6) + else: + mw.execShell('systemctl start postgresql') + + initPgPwd() + + if mw.isAppleSystem(): + cmd_init_stop = init_file + ' stop' + subprocess.Popen(cmd_init_stop, stdout=subprocess.PIPE, shell=True, + bufsize=4096, stderr=subprocess.PIPE) + time.sleep(3) + else: + mw.execShell('systemctl stop postgresql') + + if mw.isAppleSystem(): + sub = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True, + bufsize=4096, stderr=subprocess.PIPE) + sub.wait(5) + else: + mw.execShell('systemctl ' + method + ' postgresql') + return 'ok' + except Exception as e: + return str(e) + + +def appCMD(version, action): + return myOp(version, action) + + +def start(version=''): + return appCMD(version, 'start') + + +def stop(version=''): + return appCMD(version, 'stop') + + +def restart(version=''): + return appCMD(version, 'restart') + + +def reload(version=''): + return appCMD(version, 'reload') + + +def initdStatus(): + if mw.isAppleSystem(): + return "Apple Computer does not support" + + shell_cmd = 'systemctl status mysql | grep loaded | grep "enabled;"' + data = mw.execShell(shell_cmd) + if data[0] == '': + return 'fail' + return 'ok' + + +def initdInstall(): + if mw.isAppleSystem(): + return "Apple Computer does not support" + + mw.execShell('systemctl enable mysql') + return 'ok' + + +def initdUinstall(): + if mw.isAppleSystem(): + return "Apple Computer does not support" + + mw.execShell('systemctl disable mysql') + return 'ok' + + +def getMyDbPos(): + file = getConf() + content = mw.readFile(file) + rep = 'datadir\s*=\s*(.*)' + tmp = re.search(rep, content) + return tmp.groups()[0].strip() + + +def setMyDbPos(): + args = getArgs() + data = checkArgs(args, ['datadir']) + if not data[0]: + return data[1] + + s_datadir = getMyDbPos() + t_datadir = args['datadir'] + if t_datadir == s_datadir: + return mw.returnJson(False, '与当前存储目录相同,无法迁移文件!') + + if not os.path.exists(t_datadir): + mw.execShell('mkdir -p ' + t_datadir) + + # mw.execShell('/etc/init.d/mysqld stop') + stop() + mw.execShell('cp -rf ' + s_datadir + '/* ' + t_datadir + '/') + mw.execShell('chown -R mysql mysql ' + t_datadir) + mw.execShell('chmod -R 755 ' + t_datadir) + mw.execShell('rm -f ' + t_datadir + '/*.pid') + mw.execShell('rm -f ' + t_datadir + '/*.err') + + path = getServerDir() + myfile = path + '/etc/my.cnf' + mycnf = mw.readFile(myfile) + mw.writeFile(path + '/etc/my_backup.cnf', mycnf) + + mycnf = mycnf.replace(s_datadir, t_datadir) + mw.writeFile(myfile, mycnf) + start() + + result = mw.execShell( + 'ps aux|grep mysqld| grep -v grep|grep -v python') + if len(result[0]) > 10: + mw.writeFile('data/datadir.pl', t_datadir) + return mw.returnJson(True, '存储目录迁移成功!') + else: + mw.execShell('pkill -9 mysqld') + mw.writeFile(myfile, mw.readFile(path + '/etc/my_backup.cnf')) + start() + return mw.returnJson(False, '文件迁移失败!') + + +def getMyPort(): + file = getConf() + content = mw.readFile(file) + rep = 'port\s*=\s*(.*)' + tmp = re.search(rep, content) + return tmp.groups()[0].strip() + + +def setMyPort(): + args = getArgs() + data = checkArgs(args, ['port']) + if not data[0]: + return data[1] + + port = args['port'] + file = getConf() + content = mw.readFile(file) + rep = "port\s*=\s*([0-9]+)\s*\n" + content = re.sub(rep, 'port = ' + port + '\n', content) + mw.writeFile(file, content) + restart() + return mw.returnJson(True, '编辑成功!') + + +def runInfo(): + + if status(version) == 'stop': + return mw.returnJson(False, 'PG未启动', []) + + db = pMysqlDb() + data = db.query('show global status') + gets = ['Max_used_connections', 'Com_commit', 'Com_rollback', 'Questions', 'Innodb_buffer_pool_reads', 'Innodb_buffer_pool_read_requests', 'Key_reads', 'Key_read_requests', 'Key_writes', + 'Key_write_requests', 'Qcache_hits', 'Qcache_inserts', 'Bytes_received', 'Bytes_sent', 'Aborted_clients', 'Aborted_connects', + 'Created_tmp_disk_tables', 'Created_tmp_tables', 'Innodb_buffer_pool_pages_dirty', 'Opened_files', 'Open_tables', 'Opened_tables', 'Select_full_join', + 'Select_range_check', 'Sort_merge_passes', 'Table_locks_waited', 'Threads_cached', 'Threads_connected', 'Threads_created', 'Threads_running', 'Connections', 'Uptime'] + + result = {} + # print(data) + for d in data: + vname = d["Variable_name"] + for g in gets: + if vname == g: + result[g] = d["Value"] + + # print(result, int(result['Uptime'])) + result['Run'] = int(time.time()) - int(result['Uptime']) + tmp = db.query('show master status') + try: + result['File'] = tmp[0]["File"] + result['Position'] = tmp[0]["Position"] + except: + result['File'] = 'OFF' + result['Position'] = 'OFF' + return mw.getJson(result) + + +def myDbStatus(): + result = {} + db = pMysqlDb() + data = db.query('show variables') + isError = isSqlError(data) + if isError != None: + return isError + + gets = ['table_open_cache', 'thread_cache_size', 'key_buffer_size', 'tmp_table_size', 'max_heap_table_size', 'innodb_buffer_pool_size', + 'innodb_additional_mem_pool_size', 'innodb_log_buffer_size', 'max_connections', 'sort_buffer_size', 'read_buffer_size', 'read_rnd_buffer_size', 'join_buffer_size', 'thread_stack', 'binlog_cache_size'] + result['mem'] = {} + for d in data: + vname = d['Variable_name'] + for g in gets: + # print(g) + if vname == g: + result['mem'][g] = d["Value"] + return mw.getJson(result) + + +def setDbStatus(): + gets = ['key_buffer_size', 'tmp_table_size', 'max_heap_table_size', 'innodb_buffer_pool_size', 'innodb_log_buffer_size', 'max_connections', + 'table_open_cache', 'thread_cache_size', 'sort_buffer_size', 'read_buffer_size', 'read_rnd_buffer_size', 'join_buffer_size', 'thread_stack', 'binlog_cache_size'] + emptys = ['max_connections', 'thread_cache_size', 'table_open_cache'] + args = getArgs() + conFile = getConf() + content = mw.readFile(conFile) + n = 0 + for g in gets: + s = 'M' + if n > 5: + s = 'K' + if g in emptys: + s = '' + rep = '\s*' + g + '\s*=\s*\d+(M|K|k|m|G)?\n' + c = g + ' = ' + args[g] + s + '\n' + if content.find(g) != -1: + content = re.sub(rep, '\n' + c, content, 1) + else: + content = content.replace('[mysqld]\n', '[mysqld]\n' + c) + n += 1 + mw.writeFile(conFile, content) + return mw.returnJson(True, '设置成功!') + + +def isSqlError(mysqlMsg): + # 检测数据库执行错误 + mysqlMsg = str(mysqlMsg) + if "MySQLdb" in mysqlMsg: + return mw.returnJson(False, 'MySQLdb组件缺失!
进入SSH命令行输入: pip install mysql-python | pip install mysqlclient==2.0.3') + if "2002," in mysqlMsg: + return mw.returnJson(False, '数据库连接失败,请检查数据库服务是否启动!') + if "2003," in mysqlMsg: + return mw.returnJson(False, "Can't connect to MySQL server on '127.0.0.1' (61)") + if "using password:" in mysqlMsg: + return mw.returnJson(False, '数据库管理密码错误!') + if "1045" in mysqlMsg: + return mw.returnJson(False, '连接错误!') + if "SQL syntax" in mysqlMsg: + return mw.returnJson(False, 'SQL语法错误!') + if "Connection refused" in mysqlMsg: + return mw.returnJson(False, '数据库连接失败,请检查数据库服务是否启动!') + if "1133" in mysqlMsg: + return mw.returnJson(False, '数据库用户不存在!') + if "1007" in mysqlMsg: + return mw.returnJson(False, '数据库已经存在!') + return None + + +def __createUser(dbname, username, password, address): + pdb = pMysqlDb() + + if username == 'root': + dbname = '*' + + pdb.execute( + "CREATE USER `%s`@`localhost` IDENTIFIED BY '%s'" % (username, password)) + pdb.execute( + "grant all privileges on %s.* to `%s`@`localhost`" % (dbname, username)) + for a in address.split(','): + pdb.execute( + "CREATE USER `%s`@`%s` IDENTIFIED BY '%s'" % (username, a, password)) + pdb.execute( + "grant all privileges on %s.* to `%s`@`%s`" % (dbname, username, a)) + pdb.execute("flush privileges") + + +def getDbBackupListFunc(dbname=''): + bkDir = mw.getRootDir() + '/backup/database' + blist = os.listdir(bkDir) + r = [] + + bname = 'db_' + dbname + blen = len(bname) + for x in blist: + fbstr = x[0:blen] + if fbstr == bname: + r.append(x) + return r + + +def setDbBackup(): + args = getArgs() + data = checkArgs(args, ['name']) + if not data[0]: + return data[1] + + scDir = mw.getRunDir() + '/scripts/backup.py' + + cmd = 'python ' + scDir + ' database ' + args['name'] + ' 3' + os.system(cmd) + return mw.returnJson(True, 'ok') + + +def importDbBackup(): + args = getArgs() + data = checkArgs(args, ['file', 'name']) + if not data[0]: + return data[1] + + file = args['file'] + name = args['name'] + + file_path = mw.getRootDir() + '/backup/database/' + file + file_path_sql = mw.getRootDir() + '/backup/database/' + file.replace('.gz', '') + + if not os.path.exists(file_path_sql): + cmd = 'cd ' + mw.getRootDir() + '/backup/database && gzip -d ' + file + mw.execShell(cmd) + + pwd = pSqliteDb('config').where('id=?', (1,)).getField('mysql_root') + + mysql_cmd = mw.getRootDir() + '/server/mysql/bin/mysql -uroot -p' + pwd + \ + ' ' + name + ' < ' + file_path_sql + + # print(mysql_cmd) + os.system(mysql_cmd) + return mw.returnJson(True, 'ok') + + +def deleteDbBackup(): + args = getArgs() + data = checkArgs(args, ['filename']) + if not data[0]: + return data[1] + + bkDir = mw.getRootDir() + '/backup/database' + + os.remove(bkDir + '/' + args['filename']) + return mw.returnJson(True, 'ok') + + +def getDbBackupList(): + args = getArgs() + data = checkArgs(args, ['name']) + if not data[0]: + return data[1] + + r = getDbBackupListFunc(args['name']) + bkDir = mw.getRootDir() + '/backup/database' + rr = [] + for x in range(0, len(r)): + p = bkDir + '/' + r[x] + data = {} + data['name'] = r[x] + + rsize = os.path.getsize(p) + data['size'] = mw.toSize(rsize) + + t = os.path.getctime(p) + t = time.localtime(t) + + data['time'] = time.strftime('%Y-%m-%d %H:%M:%S', t) + rr.append(data) + + data['file'] = p + + return mw.returnJson(True, 'ok', rr) + + +def getDbList(): + args = getArgs() + page = 1 + page_size = 10 + search = '' + data = {} + if 'page' in args: + page = int(args['page']) + + if 'page_size' in args: + page_size = int(args['page_size']) + + if 'search' in args: + search = args['search'] + + conn = pSqliteDb('databases') + limit = str((page - 1) * page_size) + ',' + str(page_size) + condition = '' + if not search == '': + condition = "name like '%" + search + "%'" + field = 'id,pid,name,username,password,accept,rw,ps,addtime' + clist = conn.where(condition, ()).field( + field).limit(limit).order('id desc').select() + + for x in range(0, len(clist)): + dbname = clist[x]['name'] + blist = getDbBackupListFunc(dbname) + # print(blist) + clist[x]['is_backup'] = False + if len(blist) > 0: + clist[x]['is_backup'] = True + + count = conn.where(condition, ()).count() + _page = {} + _page['count'] = count + _page['p'] = page + _page['row'] = page_size + _page['tojs'] = 'dbList' + data['page'] = mw.getPage(_page) + data['data'] = clist + + info = {} + info['root_pwd'] = pSqliteDb('config').where( + 'id=?', (1,)).getField('mysql_root') + data['info'] = info + + return mw.getJson(data) + + +def installPreInspection(version): + return 'ok' + + +def uninstallPreInspection(version): + # return "请手动删除MySQL[{}]".format(version) + return 'ok' + +if __name__ == "__main__": + func = sys.argv[1] + + version = "14.4" + version_pl = getServerDir() + "/version.pl" + if os.path.exists(version_pl): + version = mw.readFile(version_pl).strip() + + if func == 'status': + print(status(version)) + elif func == 'start': + print(start(version)) + elif func == 'stop': + print(stop(version)) + elif func == 'restart': + print(restart(version)) + elif func == 'reload': + print(reload(version)) + elif func == 'initd_status': + print(initdStatus()) + elif func == 'initd_install': + print(initdInstall()) + elif func == 'initd_uninstall': + print(initdUinstall()) + elif func == 'install_pre_inspection': + print(installPreInspection(version)) + elif func == 'uninstall_pre_inspection': + print(uninstallPreInspection(version)) + elif func == 'conf': + print(getConf()) + elif func == 'run_info': + print(runInfo()) + else: + print('error') diff --git a/plugins/postgresql/info.json b/plugins/postgresql/info.json new file mode 100755 index 000000000..76f6540e7 --- /dev/null +++ b/plugins/postgresql/info.json @@ -0,0 +1,18 @@ +{ + "title":"PostgreSQL", + "tip":"soft", + "name":"postgresql", + "type":"运行环境", + "ps":"功能强大的开源数据库", + "coexist": false, + "install_pre_inspection":true, + "uninstall_pre_inspection":true, + "versions":["14.4"], + "shell":"install.sh", + "checks":"server/postgresql", + "path":"server/postgresql", + "author":"postgresql", + "home":"https://www.postgresql.org/", + "date":"2022-08-07", + "pid": "2" +} \ No newline at end of file diff --git a/plugins/postgresql/init.d/postgresql.service.tpl b/plugins/postgresql/init.d/postgresql.service.tpl new file mode 100644 index 000000000..fd856395a --- /dev/null +++ b/plugins/postgresql/init.d/postgresql.service.tpl @@ -0,0 +1,16 @@ +[Unit] +Description=PostgreSQL: a powerful open source database +After=network.target + +[Service] +Type=forking +User=postgres +Group=postgres +WorkingDirectory={$APP_PATH} +ExecStart={$APP_PATH}/pg_ctl start -D {$APP_PATH}/data +ExecReload={$APP_PATH}/pg_ctl restart -D {$APP_PATH}/data +ExecStop={$APP_PATH}/pg_ctl stop -D {$APP_PATH}/data +PrivateTmp=false + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/plugins/postgresql/init.d/postgresql.tpl b/plugins/postgresql/init.d/postgresql.tpl new file mode 100644 index 000000000..9c811c514 --- /dev/null +++ b/plugins/postgresql/init.d/postgresql.tpl @@ -0,0 +1,60 @@ +#!/bin/bash +# chkconfig: 2345 55 25 +# description: PostgreSQL Service + +### BEGIN INIT INFO +# Provides: Midoks +# Required-Start: $all +# Required-Stop: $all +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: starts PostgreSQL +# Description: starts the PostgreSQL +### END INIT INFO + + +PATH=/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin +export LC_ALL="en_US.UTF-8" + +MW_PATH={$SERVER_PATH} +PATH=$PATH:$MW_PATH/bin + +if [ -f $MW_PATH/bin/activate ];then + source $MW_PATH/bin/activate +fi + +pg_start() +{ + touch {$APP_PATH}/logs/server.log + {$APP_PATH}/bin/pg_ctl -D {$APP_PATH}/data -l {$APP_PATH}/logs/server.log start +} + + +pg_stop() +{ + {$APP_PATH}/bin/pg_ctl -D {$APP_PATH}/data -l {$APP_PATH}/logs/server.log stop +} + + + +pg_status() +{ + echo "123123" +} + + +pg_reload() +{ + echo "123" +} + + + +case "$1" in + 'start') pg_start;; + 'stop') pg_stop;; + 'reload') pg_reload;; + 'restart') + pg_stop + pg_start;; +esac diff --git a/plugins/postgresql/install.sh b/plugins/postgresql/install.sh new file mode 100755 index 000000000..62e70eb4c --- /dev/null +++ b/plugins/postgresql/install.sh @@ -0,0 +1,42 @@ +#!/bin/bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin +export PATH + +curPath=`pwd` +rootPath=$(dirname "$curPath") +rootPath=$(dirname "$rootPath") +serverPath=$(dirname "$rootPath") + + +install_tmp=${rootPath}/tmp/mw_install.pl + +action=$1 +type=$2 + +if [ "${2}" == "" ];then + echo '缺少安装脚本...' > $install_tmp + exit 0 +fi + +if [ ! -d $curPath/versions/$2 ];then + echo '缺少安装脚本2...' > $install_tmp + exit 0 +fi + +# if [ "${action}" == "uninstall" ];then +# if [ -f /usr/lib/systemd/system/postgresql.service ] || [ -f /lib/systemd/system/postgresql.service ];then +# systemctl stop postgresql +# systemctl disable postgresql +# rm -rf /usr/lib/systemd/system/postgresql.service +# rm -rf /lib/systemd/system/postgresql.service +# systemctl daemon-reload +# fi +# fi + +sh -x $curPath/versions/$2/install.sh $1 + +if [ "${action}" == "install" ] && [ -d $serverPath/postgresql ];then + #初始化 + # cd ${rootPath} && python3 ${rootPath}/plugins/postgresql/index.py start ${type} + # cd ${rootPath} && python3 ${rootPath}/plugins/postgresql/index.py initd_install ${type} +fi diff --git a/plugins/postgresql/versions/14.4/install.sh b/plugins/postgresql/versions/14.4/install.sh new file mode 100755 index 000000000..c596b3829 --- /dev/null +++ b/plugins/postgresql/versions/14.4/install.sh @@ -0,0 +1,97 @@ +#!/bin/bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin +export PATH + +#https://www.postgresql.org/ftp/source/ + +curPath=`pwd` +rootPath=$(dirname "$curPath") +rootPath=$(dirname "$rootPath") +serverPath=$(dirname "$rootPath") +sysName=`uname` + +install_tmp=${rootPath}/tmp/mw_install.pl +postgreDir=${serverPath}/source/postgresql + +VERSION=14.4 + +Install_App() +{ + mkdir -p ${postgreDir} + echo '正在安装脚本文件...' > $install_tmp + + if id postgres &> /dev/null ;then + echo "postgres UID is `id -u postgres`" + echo "postgres Shell is `grep "^postgres:" /etc/passwd |cut -d':' -f7 `" + else + groupadd postgres + useradd -g postgres postgres + fi + + if [ "$sysName" != "Darwin" ];then + mkdir -p /var/log/mariadb + touch /var/log/mariadb/mariadb.log + fi + + # ----- cpu start ------ + if [ -z "${cpuCore}" ]; then + cpuCore="1" + fi + + if [ -f /proc/cpuinfo ];then + cpuCore=`cat /proc/cpuinfo | grep "processor" | wc -l` + fi + + MEM_INFO=$(free -m|grep Mem|awk '{printf("%.f",($2)/1024)}') + if [ "${cpuCore}" != "1" ] && [ "${MEM_INFO}" != "0" ];then + if [ "${cpuCore}" -gt "${MEM_INFO}" ];then + cpuCore="${MEM_INFO}" + fi + else + cpuCore="1" + fi + # ----- cpu end ------ + + if [ ! -f ${postgreDir}/postgresql-${VERSION}.tar.bz2 ];then + wget --no-check-certificate -O ${postgreDir}/postgresql-${VERSION}.tar.bz2 --tries=3 https://ftp.postgresql.org/pub/source/v${VERSION}/postgresql-${VERSION}.tar.bz2 + fi + + if [ ! -d ${postgreDir}/postgresql-${VERSION} ];then + cd ${postgreDir} && tar -zxvf ${postgreDir}/postgresql-${VERSION}.tar.bz2 + fi + + + if [ ! -d $serverPath/postgresql ];then + cd ${postgreDir}/postgresql-${VERSION} && ./configure \ + --prefix=$serverPath/postgresql + # --with-openssl \ + # --with-pgport=33206 + + echo "cd ${postgreDir}/postgresql-${VERSION} && ./configure \ + --prefix=$serverPath/postgresql" + # --with-openssl \ + # --with-pgport=33206 + make -j${cpuCore} && make install && make clean + fi + + if [ -d $serverPath/postgresql ];then + echo "{$VERSION}" > $serverPath/postgresql/version.pl + echo 'install successful' > $install_tmp + else + echo 'install fail' > $install_tmp + echo 'install fail'>&2 + fi +} + +Uninstall_App() +{ + rm -rf $serverPath/postgresql + echo '卸载完成' > $install_tmp +} + +action=$1 +if [ "${1}" == "install" ];then + Install_App +else + Uninstall_App +fi From 91debbbee1724a2bc3a05f38dc701ce14734e260 Mon Sep 17 00:00:00 2001 From: midoks Date: Sun, 7 Aug 2022 21:38:44 +0800 Subject: [PATCH 82/89] ip --- class/core/mw.py | 7 ++++++- class/core/site_api.py | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/class/core/mw.py b/class/core/mw.py index d2e694633..70141afea 100755 --- a/class/core/mw.py +++ b/class/core/mw.py @@ -98,7 +98,12 @@ def systemdCfgDir(): return cfg_dir # debian,centos - return "/usr/lib/systemd/system" + cfg_dir = '/usr/lib/systemd/system' + if os.path.exists(cfg_dir): + return cfg_dir + + # local test + return "/tmp" def getOs(): diff --git a/class/core/site_api.py b/class/core/site_api.py index c1b49c174..ad597ada0 100755 --- a/class/core/site_api.py +++ b/class/core/site_api.py @@ -730,11 +730,11 @@ class site_api: if conf.find('ssl_certificate') == -1: return mw.returnJson(False, '当前未开启SSL') to = """#error_page 404/404.html; - # HTTP_TO_HTTPS_START + #HTTP_TO_HTTPS_START if ($server_port !~ 443){ rewrite ^(/.*)$ https://$host$1 permanent; } - # HTTP_TO_HTTPS_END""" + #HTTP_TO_HTTPS_END""" conf = conf.replace('#error_page 404/404.html;', to) mw.writeFile(file, conf) From d79ef624d2c4f376f0453447a50c22026b49d73d Mon Sep 17 00:00:00 2001 From: midoks Date: Sun, 7 Aug 2022 22:44:31 +0800 Subject: [PATCH 83/89] pg up1 --- plugins/postgresql/index.html | 14 +-- plugins/postgresql/index.py | 99 ++++++++------------- plugins/postgresql/info.json | 2 +- plugins/postgresql/init.d/postgresql.tpl | 10 ++- plugins/postgresql/js/postgresql.js | 74 +-------------- plugins/postgresql/versions/14.4/install.sh | 10 +-- 6 files changed, 64 insertions(+), 145 deletions(-) diff --git a/plugins/postgresql/index.html b/plugins/postgresql/index.html index 2519cc07e..66a7ca866 100755 --- a/plugins/postgresql/index.html +++ b/plugins/postgresql/index.html @@ -6,14 +6,14 @@

服务

自启动

配置文件

- +

端口

+ +

日志

+

管理列表

-

主从配置

--> +
diff --git a/plugins/postgresql/index.py b/plugins/postgresql/index.py index 63e4f43d4..0a834c1fb 100755 --- a/plugins/postgresql/index.py +++ b/plugins/postgresql/index.py @@ -148,16 +148,16 @@ def initDreplace(version=''): conf_dir, log_dir ] - for conf in conf_list: - if not os.path.exists(conf): - os.mkdir(conf) + for c in conf_list: + if not os.path.exists(c): + os.mkdir(c) - my_conf = conf_dir + '/my.cnf' - if not os.path.exists(my_conf): - tpl = getPluginDir() + '/conf/my.cnf' - content = mw.readFile(tpl) - content = contentReplace(content) - mw.writeFile(my_conf, content) + # my_conf = conf_dir + '/my.cnf' + # if not os.path.exists(my_conf): + # tpl = getPluginDir() + '/conf/my.cnf' + # content = mw.readFile(tpl) + # content = contentReplace(content) + # mw.writeFile(my_conf, content) # systemd system_dir = mw.systemdCfgDir() @@ -166,7 +166,7 @@ def initDreplace(version=''): tpl = getPluginDir() + '/init.d/postgresql.service.tpl' service_path = mw.getServerDir() content = mw.readFile(tpl) - content = content.replace('{$SERVER_PATH}', service_path) + content = contentReplace(content) mw.writeFile(service, content) mw.execShell('systemctl daemon-reload') @@ -248,11 +248,8 @@ def pGetDbUser(): def initPgData(): - datadir = getDataDir() - if not os.path.exists(datadir + '/postgresql'): - serverdir = getServerDir() - myconf = serverdir + "/etc/my.cnf" - user = pGetDbUser() + serverdir = getServerDir() + if not os.path.exists(serverdir + '/postgresql'): cmd = 'cd ' + serverdir + ' && ./bin/initdb -D ' + serverdir + "/data" mw.execShell(cmd) return False @@ -264,20 +261,13 @@ def initPgPwd(): serverdir = getServerDir() pwd = mw.getRandomString(16) - cmd_pass = serverdir + '/bin/mysql -uroot -e' - cmd_pass = cmd_pass + "\"UPDATE mysql.user SET password=PASSWORD('" + \ - pwd + "') WHERE user='root';" - cmd_pass = cmd_pass + "flush privileges;\"" + cmd_pass = "echo \"create user root with superuser password '" + pwd + "'\" | " + cmd_pass = cmd_pass + serverdir + '/bin/psql -d postgres' data = mw.execShell(cmd_pass) - # print(cmd_pass) - # print(data) - - # 删除测试数据库 - drop_test_db = serverdir + '/bin/mysql -uroot -p' + \ - pwd + ' -e "drop database test";' - mw.execShell(drop_test_db) + print(cmd_pass) + print(data) - pSqliteDb('config').where('id=?', (1,)).save('mysql_root', (pwd,)) + pSqliteDb('config').where('id=?', (1,)).save('pg_root', (pwd,)) return True @@ -285,6 +275,7 @@ def myOp(version, method): # import commands init_file = initDreplace() cmd = init_file + ' ' + method + # print(cmd) try: isInited = initPgData() if not isInited: @@ -315,7 +306,8 @@ def myOp(version, method): mw.execShell('systemctl ' + method + ' postgresql') return 'ok' except Exception as e: - return str(e) + # raise + return method + ":" + str(e) def appCMD(version, action): @@ -342,7 +334,7 @@ def initdStatus(): if mw.isAppleSystem(): return "Apple Computer does not support" - shell_cmd = 'systemctl status mysql | grep loaded | grep "enabled;"' + shell_cmd = 'systemctl status postgresql | grep loaded | grep "enabled;"' data = mw.execShell(shell_cmd) if data[0] == '': return 'fail' @@ -353,7 +345,7 @@ def initdInstall(): if mw.isAppleSystem(): return "Apple Computer does not support" - mw.execShell('systemctl enable mysql') + mw.execShell('systemctl enable postgresql') return 'ok' @@ -361,7 +353,7 @@ def initdUinstall(): if mw.isAppleSystem(): return "Apple Computer does not support" - mw.execShell('systemctl disable mysql') + mw.execShell('systemctl disable postgresql') return 'ok' @@ -416,7 +408,7 @@ def setMyDbPos(): return mw.returnJson(False, '文件迁移失败!') -def getMyPort(): +def getPgPort(): file = getConf() content = mw.readFile(file) rep = 'port\s*=\s*(.*)' @@ -424,7 +416,7 @@ def getMyPort(): return tmp.groups()[0].strip() -def setMyPort(): +def setPgPort(): args = getArgs() data = checkArgs(args, ['port']) if not data[0]: @@ -472,6 +464,10 @@ def runInfo(): return mw.getJson(result) +def runLog(): + return getServerDir() + "/logs/server.log" + + def myDbStatus(): result = {} db = pMysqlDb() @@ -517,30 +513,6 @@ def setDbStatus(): return mw.returnJson(True, '设置成功!') -def isSqlError(mysqlMsg): - # 检测数据库执行错误 - mysqlMsg = str(mysqlMsg) - if "MySQLdb" in mysqlMsg: - return mw.returnJson(False, 'MySQLdb组件缺失!
进入SSH命令行输入: pip install mysql-python | pip install mysqlclient==2.0.3') - if "2002," in mysqlMsg: - return mw.returnJson(False, '数据库连接失败,请检查数据库服务是否启动!') - if "2003," in mysqlMsg: - return mw.returnJson(False, "Can't connect to MySQL server on '127.0.0.1' (61)") - if "using password:" in mysqlMsg: - return mw.returnJson(False, '数据库管理密码错误!') - if "1045" in mysqlMsg: - return mw.returnJson(False, '连接错误!') - if "SQL syntax" in mysqlMsg: - return mw.returnJson(False, 'SQL语法错误!') - if "Connection refused" in mysqlMsg: - return mw.returnJson(False, '数据库连接失败,请检查数据库服务是否启动!') - if "1133" in mysqlMsg: - return mw.returnJson(False, '数据库用户不存在!') - if "1007" in mysqlMsg: - return mw.returnJson(False, '数据库已经存在!') - return None - - def __createUser(dbname, username, password, address): pdb = pMysqlDb() @@ -579,9 +551,8 @@ def setDbBackup(): if not data[0]: return data[1] - scDir = mw.getRunDir() + '/scripts/backup.py' - - cmd = 'python ' + scDir + ' database ' + args['name'] + ' 3' + scDir = getPluginDir() + '/scripts/backup.py' + cmd = 'python3 ' + scDir + ' database ' + args['name'] + ' 3' os.system(cmd) return mw.returnJson(True, 'ok') @@ -741,5 +712,13 @@ if __name__ == "__main__": print(getConf()) elif func == 'run_info': print(runInfo()) + elif func == 'run_log': + print(runLog()) + elif func == 'pg_port': + print(getPgPort()) + elif func == 'set_pg_port': + print(setPgPort()) + elif func == 'get_db_list': + print(getDbList()) else: print('error') diff --git a/plugins/postgresql/info.json b/plugins/postgresql/info.json index 76f6540e7..342f924d8 100755 --- a/plugins/postgresql/info.json +++ b/plugins/postgresql/info.json @@ -3,7 +3,7 @@ "tip":"soft", "name":"postgresql", "type":"运行环境", - "ps":"功能强大的开源数据库", + "ps":"[DEV]功能强大的开源数据库", "coexist": false, "install_pre_inspection":true, "uninstall_pre_inspection":true, diff --git a/plugins/postgresql/init.d/postgresql.tpl b/plugins/postgresql/init.d/postgresql.tpl index 9c811c514..a0c5cf3db 100644 --- a/plugins/postgresql/init.d/postgresql.tpl +++ b/plugins/postgresql/init.d/postgresql.tpl @@ -39,13 +39,19 @@ pg_stop() pg_status() { - echo "123123" + isStart=$(ps aux |grep 'postgres'|grep -v grep|awk '{print $2}') + if [ "$isStart" != '' ];then + echo -e "\033[32mPostgreSQL (pid $isStart) already running\033[0m" + else + echo -e "\033[31mPostgreSQL not running\033[0m" + fi } pg_reload() { - echo "123" + pg_stop + pg_start } diff --git a/plugins/postgresql/js/postgresql.js b/plugins/postgresql/js/postgresql.js index afcbdf340..ad71f3468 100755 --- a/plugins/postgresql/js/postgresql.js +++ b/plugins/postgresql/js/postgresql.js @@ -128,8 +128,8 @@ function myDbPos(){ }); } -function myPort(){ - myPost('my_port','',function(data){ +function pgPort(){ + myPost('pg_port','',function(data){ var con = '
\
\ \ @@ -139,7 +139,7 @@ function myPort(){ $('#btn_change_port').click(function(){ var port = $("input[name='port']").val(); - myPost('set_my_port','port='+port,function(data){ + myPost('set_pg_port','port='+port,function(data){ var rdata = $.parseJSON(data.data); if (rdata.status){ layer.msg('修改成功!',{icon:1,time:2000,shade: [0.3, '#000']}); @@ -978,8 +978,7 @@ function dbList(page, search){ } - list += '管理 | ' + - '工具 | ' + + list += '工具 | ' + '权限 | ' + rw + '改密 | ' + @@ -992,7 +991,6 @@ function dbList(page, search){ var con = '
\ \ \ - \ \ \ \ @@ -1036,70 +1034,6 @@ function dbList(page, search){ }); } - -function myLogs(){ - - myPost('bin_log', {status:1}, function(data){ - var rdata = $.parseJSON(data.data); - - var line_status = "" - if (rdata.status){ - line_status = '\ - '; - } else { - line_status = ''; - } - - var limitCon = '

\ - 二进制日志 ' + toSize(rdata.msg) + '\ - '+line_status+'\ -

错误日志

\ - \ -

'; - $(".soft-man-con").html(limitCon); - - //设置二进制日志 - $(".btn-bin").click(function () { - myPost('bin_log', 'close=change', function(data){ - var rdata = $.parseJSON(data.data); - layer.msg(rdata.msg, { icon: rdata.status ? 1 : 5 }); - setTimeout(function(){myLogs();}, 2000); - }); - }); - - $(".clean-btn-bin").click(function () { - myPost('clean_bin_log', '', function(data){ - var rdata = $.parseJSON(data.data); - layer.msg(rdata.msg, { icon: rdata.status ? 1 : 5 }); - setTimeout(function(){myLogs();}, 2000); - }); - }); - - //清空日志 - $(".btn-clear").click(function () { - myPost('error_log', 'close=1', function(data){ - var rdata = $.parseJSON(data.data); - layer.msg(rdata.msg, { icon: rdata.status ? 1 : 5 }); - setTimeout(function(){myLogs();}, 2000); - }); - }) - - myPost('error_log', 'p=1', function(data){ - var rdata = $.parseJSON(data.data); - var error_body = ''; - if (rdata.status){ - error_body = rdata.data; - } else { - error_body = rdata.msg; - } - $("#error_log").html(error_body); - var ob = document.getElementById('error_log'); - ob.scrollTop = ob.scrollHeight; - }); - }); -} - - function repCheckeds(tables) { var dbs = [] if (tables) { diff --git a/plugins/postgresql/versions/14.4/install.sh b/plugins/postgresql/versions/14.4/install.sh index c596b3829..274437a99 100755 --- a/plugins/postgresql/versions/14.4/install.sh +++ b/plugins/postgresql/versions/14.4/install.sh @@ -20,12 +20,12 @@ Install_App() mkdir -p ${postgreDir} echo '正在安装脚本文件...' > $install_tmp - if id postgres &> /dev/null ;then - echo "postgres UID is `id -u postgres`" - echo "postgres Shell is `grep "^postgres:" /etc/passwd |cut -d':' -f7 `" + if id postgresql &> /dev/null ;then + echo "postgresql UID is `id -u postgresql`" + echo "postgresql Shell is `grep "^postgresql:" /etc/passwd |cut -d':' -f7 `" else - groupadd postgres - useradd -g postgres postgres + groupadd postgresql + useradd -g postgresql postgresql fi if [ "$sysName" != "Darwin" ];then From 9274358e956fa3b5cd9c5715e0ade299ba75cb4e Mon Sep 17 00:00:00 2001 From: midoks Date: Sun, 7 Aug 2022 22:55:23 +0800 Subject: [PATCH 84/89] Update install.sh --- plugins/postgresql/versions/14.4/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/postgresql/versions/14.4/install.sh b/plugins/postgresql/versions/14.4/install.sh index 274437a99..20af411b4 100755 --- a/plugins/postgresql/versions/14.4/install.sh +++ b/plugins/postgresql/versions/14.4/install.sh @@ -57,7 +57,7 @@ Install_App() fi if [ ! -d ${postgreDir}/postgresql-${VERSION} ];then - cd ${postgreDir} && tar -zxvf ${postgreDir}/postgresql-${VERSION}.tar.bz2 + cd ${postgreDir} && tar -jxvf ${postgreDir}/postgresql-${VERSION}.tar.bz2 fi @@ -79,7 +79,7 @@ Install_App() echo 'install successful' > $install_tmp else echo 'install fail' > $install_tmp - echo 'install fail'>&2 + echo 'install fail' > &2 fi } From b9292981ef217096fdf747af404b25c74b9d66fa Mon Sep 17 00:00:00 2001 From: midoks Date: Sun, 7 Aug 2022 22:55:59 +0800 Subject: [PATCH 85/89] Update install.sh --- plugins/postgresql/versions/14.4/install.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/postgresql/versions/14.4/install.sh b/plugins/postgresql/versions/14.4/install.sh index 20af411b4..7b0f30705 100755 --- a/plugins/postgresql/versions/14.4/install.sh +++ b/plugins/postgresql/versions/14.4/install.sh @@ -75,11 +75,10 @@ Install_App() fi if [ -d $serverPath/postgresql ];then - echo "{$VERSION}" > $serverPath/postgresql/version.pl + echo "${VERSION}" > $serverPath/postgresql/version.pl echo 'install successful' > $install_tmp else echo 'install fail' > $install_tmp - echo 'install fail' > &2 fi } From 79095a3e71d8cc97e0588f8e1ecea3b497425a55 Mon Sep 17 00:00:00 2001 From: midoks Date: Sun, 7 Aug 2022 23:04:53 +0800 Subject: [PATCH 86/89] Update install.sh --- plugins/postgresql/versions/14.4/install.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/postgresql/versions/14.4/install.sh b/plugins/postgresql/versions/14.4/install.sh index 7b0f30705..aa686a4d3 100755 --- a/plugins/postgresql/versions/14.4/install.sh +++ b/plugins/postgresql/versions/14.4/install.sh @@ -50,6 +50,11 @@ Install_App() else cpuCore="1" fi + + # for stable installation + if [ "$cpuCore" -gt "1" ];then + cpuCore=`echo "$cpuCore" | awk '{printf("%.f",($1)*0.8)}'` + fi # ----- cpu end ------ if [ ! -f ${postgreDir}/postgresql-${VERSION}.tar.bz2 ];then From f6672d6bd5ae414eea734583a6bae3fe1d88aa83 Mon Sep 17 00:00:00 2001 From: midoks Date: Sun, 7 Aug 2022 23:07:43 +0800 Subject: [PATCH 87/89] Update install.sh --- plugins/postgresql/versions/14.4/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/postgresql/versions/14.4/install.sh b/plugins/postgresql/versions/14.4/install.sh index aa686a4d3..6dd3a80b8 100755 --- a/plugins/postgresql/versions/14.4/install.sh +++ b/plugins/postgresql/versions/14.4/install.sh @@ -38,9 +38,9 @@ Install_App() cpuCore="1" fi - if [ -f /proc/cpuinfo ];then + if [ -f /proc/cpuinfo ];then cpuCore=`cat /proc/cpuinfo | grep "processor" | wc -l` - fi + fi MEM_INFO=$(free -m|grep Mem|awk '{printf("%.f",($2)/1024)}') if [ "${cpuCore}" != "1" ] && [ "${MEM_INFO}" != "0" ];then From c731197e954fb190e2e42d5e411d14b665bfd6ca Mon Sep 17 00:00:00 2001 From: midoks Date: Sun, 7 Aug 2022 23:09:37 +0800 Subject: [PATCH 88/89] Update install.sh --- plugins/postgresql/install.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/postgresql/install.sh b/plugins/postgresql/install.sh index 62e70eb4c..741fc3540 100755 --- a/plugins/postgresql/install.sh +++ b/plugins/postgresql/install.sh @@ -35,8 +35,8 @@ fi sh -x $curPath/versions/$2/install.sh $1 -if [ "${action}" == "install" ] && [ -d $serverPath/postgresql ];then - #初始化 - # cd ${rootPath} && python3 ${rootPath}/plugins/postgresql/index.py start ${type} - # cd ${rootPath} && python3 ${rootPath}/plugins/postgresql/index.py initd_install ${type} -fi +# if [ "${action}" == "install" ] && [ -d $serverPath/postgresql ];then +# #初始化 +# cd ${rootPath} && python3 ${rootPath}/plugins/postgresql/index.py start ${type} +# cd ${rootPath} && python3 ${rootPath}/plugins/postgresql/index.py initd_install ${type} +# fi From ade7600fa1f760ae460a81cf646da0b690016626 Mon Sep 17 00:00:00 2001 From: midoks Date: Sun, 7 Aug 2022 23:12:17 +0800 Subject: [PATCH 89/89] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E5=AE=89=E8=A3=85=EF=BC=8Ccpu=E4=B8=8D=E8=A6=81?= =?UTF-8?q?=E9=A3=99=E5=88=B0100%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/mariadb/versions/10.6/install.sh | 4 ++++ plugins/mariadb/versions/10.7/install.sh | 4 ++++ plugins/mariadb/versions/10.8/install.sh | 4 ++++ plugins/mysql/versions/5.5/install.sh | 4 ++++ plugins/mysql/versions/5.6/install.sh | 4 ++++ plugins/mysql/versions/5.7/install.sh | 4 ++++ plugins/mysql/versions/8.0/install.sh | 4 ++++ 7 files changed, 28 insertions(+) diff --git a/plugins/mariadb/versions/10.6/install.sh b/plugins/mariadb/versions/10.6/install.sh index 83ff89cb1..8a0f55cf4 100755 --- a/plugins/mariadb/versions/10.6/install.sh +++ b/plugins/mariadb/versions/10.6/install.sh @@ -51,6 +51,10 @@ Install_app() else cpuCore="1" fi + + if [ "$cpuCore" -gt "1" ];then + cpuCore=`echo "$cpuCore" | awk '{printf("%.f",($1)*0.8)}'` + fi # ----- cpu end ------ if [ ! -f ${mariadbDir}/mariadb-${MY_VER}.tar.gz ];then diff --git a/plugins/mariadb/versions/10.7/install.sh b/plugins/mariadb/versions/10.7/install.sh index b7a157592..ab3508dab 100755 --- a/plugins/mariadb/versions/10.7/install.sh +++ b/plugins/mariadb/versions/10.7/install.sh @@ -51,6 +51,10 @@ Install_app() else cpuCore="1" fi + + if [ "$cpuCore" -gt "1" ];then + cpuCore=`echo "$cpuCore" | awk '{printf("%.f",($1)*0.8)}'` + fi # ----- cpu end ------ if [ ! -f ${mariadbDir}/mariadb-${MY_VER}.tar.gz ];then diff --git a/plugins/mariadb/versions/10.8/install.sh b/plugins/mariadb/versions/10.8/install.sh index b3bee2bdc..8321b1fad 100755 --- a/plugins/mariadb/versions/10.8/install.sh +++ b/plugins/mariadb/versions/10.8/install.sh @@ -51,6 +51,10 @@ Install_app() else cpuCore="1" fi + + if [ "$cpuCore" -gt "1" ];then + cpuCore=`echo "$cpuCore" | awk '{printf("%.f",($1)*0.8)}'` + fi # ----- cpu end ------ if [ ! -f ${mariadbDir}/mariadb-${MY_VER}.tar.gz ];then diff --git a/plugins/mysql/versions/5.5/install.sh b/plugins/mysql/versions/5.5/install.sh index a24c248b7..972dfc431 100755 --- a/plugins/mysql/versions/5.5/install.sh +++ b/plugins/mysql/versions/5.5/install.sh @@ -50,6 +50,10 @@ Install_mysql() else cpuCore="1" fi + + if [ "$cpuCore" -gt "1" ];then + cpuCore=`echo "$cpuCore" | awk '{printf("%.f",($1)*0.8)}'` + fi # ----- cpu end ------ if [ ! -f ${mysqlDir}/mysql-5.5.62.tar.gz ];then diff --git a/plugins/mysql/versions/5.6/install.sh b/plugins/mysql/versions/5.6/install.sh index 734ec47bc..b0d67d46f 100755 --- a/plugins/mysql/versions/5.6/install.sh +++ b/plugins/mysql/versions/5.6/install.sh @@ -53,6 +53,10 @@ Install_mysql() else cpuCore="1" fi + + if [ "$cpuCore" -gt "1" ];then + cpuCore=`echo "$cpuCore" | awk '{printf("%.f",($1)*0.8)}'` + fi # ----- cpu end ------ diff --git a/plugins/mysql/versions/5.7/install.sh b/plugins/mysql/versions/5.7/install.sh index 2c06faf29..955bbea78 100755 --- a/plugins/mysql/versions/5.7/install.sh +++ b/plugins/mysql/versions/5.7/install.sh @@ -55,6 +55,10 @@ Install_mysql() else cpuCore="1" fi + + if [ "$cpuCore" -gt "1" ];then + cpuCore=`echo "$cpuCore" | awk '{printf("%.f",($1)*0.8)}'` + fi # ----- cpu end ------ cd $serverPath/mdserver-web/plugins/mysql/lib && /bin/bash rpcgen.sh diff --git a/plugins/mysql/versions/8.0/install.sh b/plugins/mysql/versions/8.0/install.sh index 06b27d1ea..79a02406f 100755 --- a/plugins/mysql/versions/8.0/install.sh +++ b/plugins/mysql/versions/8.0/install.sh @@ -92,6 +92,10 @@ Install_mysql() else cpuCore="1" fi + + if [ "$cpuCore" -gt "1" ];then + cpuCore=`echo "$cpuCore" | awk '{printf("%.f",($1)*0.8)}'` + fi # ----- cpu end ------ cd $serverPath/mdserver-web/plugins/mysql/lib && /bin/bash rpcgen.sh