pull/149/head
midoks 3 years ago
parent f104666bc4
commit 5170a9aba9
  1. 0
      plugins/mysql/conf/classic.cnf
  2. 0
      plugins/mysql/conf/gtid.cnf
  3. 8
      plugins/mysql/conf/my.cnf
  4. 6
      plugins/mysql/conf/my5.7.cnf
  5. 7
      plugins/mysql/conf/my8.0.cnf
  6. 121
      plugins/mysql/index.py
  7. 12
      plugins/mysql/js/mysql.js

@ -5,6 +5,8 @@ port = 3306
socket = {$SERVER_APP_PATH}/mysql.sock
[mysqld]
!include {$SERVER_APP_PATH}/etc/mode/classic.cnf
sha256_password_private_key_path=mysql.pem
sha256_password_public_key_path=mysql.pub
@ -15,7 +17,9 @@ 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
default_storage_engine = InnoDB
key_buffer_size = 8M
max_allowed_packet = 100M
@ -69,7 +73,7 @@ replicate-ignore-db = performance_schema
replicate-ignore-db = mysql
replicate-ignore-db = test
default_storage_engine = InnoDB
innodb_data_home_dir = {$SERVER_APP_PATH}/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = {$SERVER_APP_PATH}/data

@ -6,6 +6,8 @@ socket = {$SERVER_APP_PATH}/mysql.sock
default-character-set = UTF8MB4
[mysqld]
!include {$SERVER_APP_PATH}/etc/mode/classic.cnf
sha256_password_private_key_path=mysql.pem
sha256_password_public_key_path=mysql.pub
@ -17,6 +19,8 @@ basedir = {$SERVER_APP_PATH}
datadir = {$SERVER_APP_PATH}/data
log-error = {$SERVER_APP_PATH}/data/error.log
default_storage_engine = InnoDB
key_buffer_size = 8M
table_open_cache = 32
sort_buffer_size = 256K
@ -69,7 +73,7 @@ replicate-ignore-db = performance_schema
replicate-ignore-db = mysql
replicate-ignore-db = test
default_storage_engine = InnoDB
innodb_data_home_dir = {$SERVER_APP_PATH}/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = {$SERVER_APP_PATH}/data

@ -6,6 +6,8 @@ socket = {$SERVER_APP_PATH}/mysql.sock
default-character-set = UTF8MB4
[mysqld]
!include {$SERVER_APP_PATH}/etc/mode/classic.cnf
sha256_password_private_key_path=mysql.pem
sha256_password_public_key_path=mysql.pub
authentication_policy=mysql_native_password
@ -18,6 +20,8 @@ basedir = {$SERVER_APP_PATH}
datadir = {$SERVER_APP_PATH}/data
log-error = {$SERVER_APP_PATH}/data/error.log
default_storage_engine = InnoDB
key_buffer_size = 8M
table_open_cache = 32
sort_buffer_size = 256K
@ -41,7 +45,6 @@ skip_name_resolve = 1
#loose-skip-innodb
#skip-grant-tables
log-bin=mysql-bin
binlog_format=mixed
server-id = 1
@ -71,7 +74,7 @@ replicate-ignore-db = performance_schema
replicate-ignore-db = mysql
replicate-ignore-db = test
default_storage_engine = InnoDB
innodb_data_home_dir = {$SERVER_APP_PATH}/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = {$SERVER_APP_PATH}/data

@ -101,15 +101,9 @@ def getInitdTpl(version=''):
def contentReplace(content):
service_path = mw.getServerDir()
if content.find('{$ROOT_PATH}') != -1:
content = content.replace('{$ROOT_PATH}', mw.getRootDir())
if content.find('{$SERVER_PATH}') != -1:
content = content.replace('{$SERVER_PATH}', service_path)
if content.find('{$SERVER_APP_PATH}') != -1:
content = content.replace(
'{$SERVER_APP_PATH}', service_path + '/mysql')
content = content.replace('{$SERVER_APP_PATH}', service_path + '/mysql')
return content
@ -161,55 +155,74 @@ def makeInitRsaKey(version=''):
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)
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):
content = mw.readFile(initd_tpl)
conf_dir = getServerDir() + '/etc'
mode_dir = conf_dir + '/mode'
conf_list = [
conf_dir,
mode_dir,
]
for conf in conf_list:
if not os.path.exists(conf):
os.mkdir(conf)
tmp_dir = getServerDir() + '/tmp'
if not os.path.exists(tmp_dir):
os.mkdir(tmp_dir)
mw.execShell("chown -R mysql:mysql " + tmp_dir)
mw.execShell("chmod 750 " + tmp_dir)
my_conf = conf_dir + '/my.cnf'
if not os.path.exists(my_conf):
tpl = getPluginDir() + '/conf/my' + version + '.cnf'
content = mw.readFile(tpl)
content = contentReplace(content)
mw.writeFile(file_bin, content)
mw.execShell('chmod +x ' + file_bin)
mw.writeFile(my_conf, content)
mysql_conf_dir = getServerDir() + '/etc'
if not os.path.exists(mysql_conf_dir):
os.mkdir(mysql_conf_dir)
mysql_tmp = getServerDir() + '/tmp'
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)
classic_conf = mode_dir + '/classic.cnf'
if not os.path.exists(classic_conf):
tpl = getPluginDir() + '/conf/classic.cnf'
content = mw.readFile(tpl)
content = contentReplace(content)
mw.writeFile(classic_conf, content)
mysql_conf = mysql_conf_dir + '/my.cnf'
if not os.path.exists(mysql_conf):
mysql_conf_tpl = getPluginDir() + '/conf/my' + version + '.cnf'
content = mw.readFile(mysql_conf_tpl)
gtid_conf = mode_dir + '/gtid.cnf'
if not os.path.exists(gtid_conf):
tpl = getPluginDir() + '/conf/gtid.cnf'
content = mw.readFile(tpl)
content = contentReplace(content)
mw.writeFile(mysql_conf, content)
mw.writeFile(gtid_conf, content)
# systemd
systemDir = mw.systemdCfgDir()
systemService = systemDir + '/mysql.service'
systemServiceTpl = getPluginDir() + '/init.d/mysql.service.tpl'
if os.path.exists(systemDir) and not os.path.exists(systemService):
system_dir = mw.systemdCfgDir()
service = system_dir + '/mysql.service'
if os.path.exists(system_dir) and not os.path.exists(service):
tpl = getPluginDir() + '/init.d/mysql.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)
content = mw.readFile(tpl)
content = content.replace('{$SERVER_PATH}', service_path)
mw.writeFile(service, content)
mw.execShell('systemctl daemon-reload')
if mw.getOs() != 'darwin':
if not mw.isAppleSystem():
mw.execShell('chown -R mysql mysql ' + 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
@ -1371,6 +1384,24 @@ def getTotalStatistics():
return mw.returnJson(False, 'fail', data)
def recognizeDbMode():
conf = getConf()
con = mw.readFile(conf)
rep = r"!include %s/(.*)?\.cnf" % (getServerDir() + "/etc/mode",)
mode = 'none'
try:
data = re.findall(rep, con, re.M)
mode = data[0]
except Exception as e:
pass
return mode
def getDbrunMode(version=''):
mode = recognizeDbMode()
return mw.returnJson(True, "ok", {'mode': mode})
def findBinlogDoDb():
conf = getConf()
con = mw.readFile(conf)
@ -1506,13 +1537,15 @@ def getMasterStatus(version=''):
return mw.returnJson(False, 'MySQL未启动,或正在启动中...!', [])
conf = getConf()
con = mw.readFile(conf)
content = mw.readFile(conf)
master_status = False
if con.find('#log-bin') == -1 and con.find('log-bin') > 1:
if content.find('#log-bin') == -1 and content.find('log-bin') > 1:
dodb = findBinlogDoDb()
if len(dodb) > 0:
master_status = True
data = {}
data['mode'] = recognizeDbMode()
data['status'] = master_status
db = pMysqlDb()
@ -2223,6 +2256,8 @@ if __name__ == "__main__":
print(alterTable())
elif func == 'get_total_statistics':
print(getTotalStatistics())
elif func == 'get_dbrun_mode':
print(getDbrunMode(version))
elif func == 'get_masterdb_list':
print(getMasterDbList(version))
elif func == 'get_master_status':

@ -1839,11 +1839,13 @@ function masterOrSlaveConf(version=''){
function getMasterStatus(){
myPost('get_master_status', '', function(data){
var rdata = $.parseJSON(data.data);
// console.log('mode:',rdata.data);
var rdata = rdata.data;
var limitCon = '\
<p class="conf_p">\
<span class="f14 c6 mr20">运行模式</span><span class="f14 c6 mr20"></span>\
<button class="btn '+(!rdata.status ? 'btn-danger' : 'btn-success')+' btn-xs">经典</button>\
<button class="btn '+(!rdata.status ? 'btn-danger' : 'btn-success')+' btn-xs">GTID</button>\
<span class="f14 c6 mr20">主从同步模式</span><span class="f14 c6 mr20"></span>\
<button class="btn '+(!(rdata.mode == "classic") ? 'btn-danger' : 'btn-success')+' btn-xs btn-classic">经典</button>\
<button class="btn '+(!(rdata.mode == "gtid") ? 'btn-danger' : 'btn-success')+' btn-xs btn-gtid">GTID</button>\
</p>\
<hr/>\
<p class="conf_p">\
@ -1857,7 +1859,7 @@ function masterOrSlaveConf(version=''){
<!-- class="conf_p" -->\
<p class="conf_p">\
<span class="f14 c6 mr20">Slave[]配置</span><span class="f14 c6 mr20"></span>\
<button class="btn '+(!rdata.data.slave_status ? 'btn-danger' : 'btn-success')+' btn-xs btn-slave">'+(!rdata.data.slave_status ? '未启动' : '已启动') +'</button>\
<button class="btn '+(!rdata.slave_status ? 'btn-danger' : 'btn-success')+' btn-xs btn-slave">'+(!rdata.slave_status ? '未启动' : '已启动') +'</button>\
<button class="btn btn-success btn-xs" onclick="getSlaveSSHList()" >[]SSH配置</button>\
<button class="btn btn-success btn-xs" onclick="initSlaveStatus()" >初始化</button>\
</p>\
@ -1894,7 +1896,7 @@ function masterOrSlaveConf(version=''){
getMasterDbList();
}
if (rdata.data.slave_status){
if (rdata.slave_status){
getAsyncMasterDbList();
getAsyncDataList()
}

Loading…
Cancel
Save