mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-10 02:09:26 +08:00
Compare commits
230
Commits
midoks-patch-1
...
0.15.4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b9652a7940 | ||
|
|
dc7ddbcf6b | ||
|
|
87a8bfe59e | ||
|
|
cfdd5e5f73 | ||
|
|
e2acf621ca | ||
|
|
0711a922d2 | ||
|
|
055ea0ca0c | ||
|
|
772d9c50f6 | ||
|
|
0809b51725 | ||
|
|
4e901e6750 | ||
|
|
5c62397234 | ||
|
|
63021a3eab | ||
|
|
e617b07790 | ||
|
|
960eeed4ce | ||
|
|
ccf020bf6b | ||
|
|
c4918d8cd7 | ||
|
|
b3d3ceb058 | ||
|
|
17a301c745 | ||
|
|
1bfa2ae3ab | ||
|
|
9be5dcfd8a | ||
|
|
d9e8f1d4ad | ||
|
|
d85f544773 | ||
|
|
577ac1f8ee | ||
|
|
ed117a1b40 | ||
|
|
9d54f0b6cd | ||
|
|
707eced7bf | ||
|
|
dd96833c09 | ||
|
|
4c61143918 | ||
|
|
8cb8a1bc70 | ||
|
|
c55c3c23d1 | ||
|
|
04e6b9367a | ||
|
|
f4f25b8ab3 | ||
|
|
a0b0b9b294 | ||
|
|
699ad0b8ca | ||
|
|
a45eaf1c3b | ||
|
|
0f51a6d481 | ||
|
|
142d5f7ed8 | ||
|
|
72bd528a24 | ||
|
|
af2dc0585b | ||
|
|
0a0021b09d | ||
|
|
c5811d4494 | ||
|
|
e329892cd2 | ||
|
|
368324a813 | ||
|
|
6a7cc4f054 | ||
|
|
1d3cba599c | ||
|
|
7d902a50eb | ||
|
|
25feb7c0ad | ||
|
|
e15d1716e5 | ||
|
|
ee16e0142e | ||
|
|
68e06aa8f5 | ||
|
|
d88003ca52 | ||
|
|
8757c646f6 | ||
|
|
c3e9d8aa4c | ||
|
|
7e3983f612 | ||
|
|
a4e43b492d | ||
|
|
1f57517ea7 | ||
|
|
b2fe35771d | ||
|
|
00ce3e00d3 | ||
|
|
c7c28731a4 | ||
|
|
3305eab770 | ||
|
|
b595359f38 | ||
|
|
5dc06b90ca | ||
|
|
651fa7672c | ||
|
|
7a0db5abef | ||
|
|
d21a5dfacc | ||
|
|
0c49749b63 | ||
|
|
11bb65a739 | ||
|
|
ce44353cbf | ||
|
|
2e5c5ef5b9 | ||
|
|
d1b687476b | ||
|
|
a46eabce10 | ||
|
|
08e378a3e4 | ||
|
|
c80ce63a4b | ||
|
|
72bb94df42 | ||
|
|
e9b7aca47a | ||
|
|
f25d4f5a4f | ||
|
|
59fcef76fe | ||
|
|
4ab6ccbcbb | ||
|
|
fd457df3c8 | ||
|
|
147bec02a5 | ||
|
|
34c126fbb7 | ||
|
|
4d21c920a8 | ||
|
|
2d810fe7ab | ||
|
|
fb5260b9a5 | ||
|
|
32b5542534 | ||
|
|
c665486122 | ||
|
|
d3b885b1f9 | ||
|
|
e476e36420 | ||
|
|
587503dc67 | ||
|
|
cecfe9470f | ||
|
|
abc37acacc | ||
|
|
e0197fef3a | ||
|
|
04c4e7ddc8 | ||
|
|
6fb3e29a91 | ||
|
|
66fe66b479 | ||
|
|
4329d2470c | ||
|
|
0cd4527234 | ||
|
|
bdba9149f2 | ||
|
|
e05f7a9c3f | ||
|
|
bddd81c94d | ||
|
|
f470392382 | ||
|
|
895a250f06 | ||
|
|
dd579b7e5c | ||
|
|
cd0653d092 | ||
|
|
f2bc938ade | ||
|
|
dc694cae35 | ||
|
|
0b98e40fec | ||
|
|
10c40800ff | ||
|
|
424d9fa799 | ||
|
|
1350fc7a4a | ||
|
|
d678ade262 | ||
|
|
0b0b0bc9c5 | ||
|
|
f3eee40e1e | ||
|
|
8e0327a084 | ||
|
|
0a4b5529b9 | ||
|
|
a8c17e1f3c | ||
|
|
4d242dd322 | ||
|
|
272a08f4eb | ||
|
|
453009da40 | ||
|
|
9c8880e1bb | ||
|
|
4f716830ef | ||
|
|
b4d799f8bd | ||
|
|
e9fc7d5344 | ||
|
|
585d3d1839 | ||
|
|
3278dd23b5 | ||
|
|
5b406eaeb1 | ||
|
|
0a354f649d | ||
|
|
176dd4a5b8 | ||
|
|
4bb9cc2d67 | ||
|
|
f1edb26540 | ||
|
|
0692537cbd | ||
|
|
0710ca590a | ||
|
|
c19b12e8df | ||
|
|
99eeee19ef | ||
|
|
fff3707031 | ||
|
|
0d0cb4add1 | ||
|
|
5ed37443da | ||
|
|
25b836e6f5 | ||
|
|
4ca5c8e1a8 | ||
|
|
b522287a87 | ||
|
|
05cec7e0bf | ||
|
|
b731868e06 | ||
|
|
9c4ceca41f | ||
|
|
22d266e710 | ||
|
|
d35bf118ff | ||
|
|
1adb2f751c | ||
|
|
54e743037e | ||
|
|
6debb93fd1 | ||
|
|
7229f9c569 | ||
|
|
844dcbda00 | ||
|
|
af2b45a6f4 | ||
|
|
d848d41a71 | ||
|
|
826ebfb2e5 | ||
|
|
e1807c1585 | ||
|
|
6e9d5a19c0 | ||
|
|
6eadad5db4 | ||
|
|
2b2fc08120 | ||
|
|
175061884d | ||
|
|
cc3fa8ac95 | ||
|
|
c9d736e338 | ||
|
|
e4437e42f3 | ||
|
|
644fc2c81f | ||
|
|
d2314bf26f | ||
|
|
c17314b634 | ||
|
|
92a4b28fbf | ||
|
|
733e4e81be | ||
|
|
8b99ae2515 | ||
|
|
2a72422402 | ||
|
|
145a259ef9 | ||
|
|
a34b7719c8 | ||
|
|
4d98455c35 | ||
|
|
c0c9def1fb | ||
|
|
02d8416466 | ||
|
|
d505740269 | ||
|
|
b1f6314df7 | ||
|
|
533653fe47 | ||
|
|
dff4551fb1 | ||
|
|
79723149a5 | ||
|
|
76da8a2ad5 | ||
|
|
645538e633 | ||
|
|
1a1b4e9f3a | ||
|
|
3afde01f93 | ||
|
|
a14db23971 | ||
|
|
316f06911b | ||
|
|
698d049314 | ||
|
|
d397d74f73 | ||
|
|
8a7447a4ee | ||
|
|
98414db41d | ||
|
|
7024185b59 | ||
|
|
495f16f2cf | ||
|
|
62444b7b6d | ||
|
|
50b11457f7 | ||
|
|
393cbc3974 | ||
|
|
ce3bfc2ebd | ||
|
|
b68e8f3650 | ||
|
|
08c83edeb9 | ||
|
|
c114e9aca8 | ||
|
|
c5123268d0 | ||
|
|
54bbc3ff57 | ||
|
|
4658b991a9 | ||
|
|
52145e710b | ||
|
|
4acc48ded2 | ||
|
|
0d858f87ea | ||
|
|
f37f08a9f5 | ||
|
|
0b5fc1de55 | ||
|
|
8748777101 | ||
|
|
48ed0b8034 | ||
|
|
41c9f6b7b6 | ||
|
|
c47336b65f | ||
|
|
24d7204ccc | ||
|
|
8c00fb8859 | ||
|
|
c573b28f16 | ||
|
|
afad548cf9 | ||
|
|
2605849de2 | ||
|
|
77598fa8a7 | ||
|
|
b175ab735d | ||
|
|
54ed17ab8f | ||
|
|
cadf72ea69 | ||
|
|
dadb737f88 | ||
|
|
fef2acf683 | ||
|
|
4b6dbf8887 | ||
|
|
06c99e1cc1 | ||
|
|
afb3e920f8 | ||
|
|
2c346c9850 | ||
|
|
5b6c5be288 | ||
|
|
63bd806222 | ||
|
|
afe3848b71 | ||
|
|
cd361ec7ec | ||
|
|
eb399fe799 | ||
|
|
53e588b6fc |
@@ -80,6 +80,7 @@ PHP[72-82]支持phpMyAdmin[5.2.0]
|
||||
# 特别赞助
|
||||
|
||||
- [找资源 - 阿里云盘资源搜索引擎](https://zhaoziyuan.pw/)
|
||||
- [鲲鹏vpn,免费试用,解锁流媒体和chatGPT](https://down.xbjc888.top/?agent_code=github)
|
||||
|
||||
# AD - VPS推荐 - 🙏
|
||||
|
||||
@@ -99,15 +100,12 @@ docker run -itd --name mw-server --privileged=true -p 7200:7200 -p 80:80 -p 443:
|
||||
```
|
||||
|
||||
|
||||
### 版本更新 0.15.2
|
||||
### 版本更新 0.15.4
|
||||
|
||||
* OpenResty升级到1.21.4.2
|
||||
* 计划任务自动脚本运行时间
|
||||
* rsyncd添加优化
|
||||
* 使用mariadb二进制导入备份文件
|
||||
* docker插件-镜像导入导出功能
|
||||
* 网站设置反向代理升级功能
|
||||
* 优化初始化安装SSH端口识别
|
||||
* OP防火墙-验证优化[cf缓存问题解决]。
|
||||
* OP防火墙-加入地区限制(最好卸载重装)。
|
||||
* 在aarch64架构下低于PHP70的版本[安装/扩展安装]优化。
|
||||
* Mongodb安装优化。
|
||||
|
||||
### JSDelivr安装地址
|
||||
|
||||
@@ -166,6 +164,8 @@ curl --insecure -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/dev
|
||||
curl --insecure -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/install_dev.sh | bash
|
||||
curl --insecure -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/update_dev.sh | bash
|
||||
|
||||
wget --no-check-certificate -O install.sh https://raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/install.sh && bash install.sh
|
||||
|
||||
wget --no-check-certificate -O uninstall.sh https://raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/uninstall.sh && bash uninstall.sh
|
||||
|
||||
curl --insecure -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/quick/debug.sh | bash
|
||||
|
||||
@@ -27,7 +27,7 @@ from flask import request
|
||||
|
||||
class config_api:
|
||||
|
||||
__version = '0.15.2'
|
||||
__version = '0.15.4'
|
||||
__api_addr = 'data/api.json'
|
||||
|
||||
def __init__(self):
|
||||
|
||||
+3
-1
@@ -1550,7 +1550,9 @@ def checkInput(data):
|
||||
|
||||
def checkCert(certPath='ssl/certificate.pem'):
|
||||
# 验证证书
|
||||
openssl = '/usr/local/openssl/bin/openssl'
|
||||
openssl = '/usr/bin/openssl'
|
||||
if not os.path.exists(openssl):
|
||||
openssl = '/usr/local/openssl/bin/openssl'
|
||||
if not os.path.exists(openssl):
|
||||
openssl = 'openssl'
|
||||
certPem = readFile(certPath)
|
||||
|
||||
@@ -2760,7 +2760,7 @@ location ^~ {from} {\n\
|
||||
|
||||
self.saveCert(keyPath, certPath)
|
||||
|
||||
msg = mw.getInfo('网站[{1}]开启SSL成功!', siteName)
|
||||
msg = mw.getInfo('网站[{}]开启SSL成功!', siteName)
|
||||
mw.writeLog('网站管理', msg)
|
||||
|
||||
mw.restartWeb()
|
||||
|
||||
@@ -65,6 +65,7 @@ binlog-ignore-db = performance_schema
|
||||
|
||||
#slave
|
||||
log-slave-updates
|
||||
slave_skip_errors=1062
|
||||
#replicate-do-db
|
||||
replicate-ignore-db = information_schema
|
||||
replicate-ignore-db = performance_schema
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<div class='plugin_version'></div>
|
||||
<div class="bt-w-main">
|
||||
<div class="bt-w-menu">
|
||||
<script type="text/javascript">console.log($('.plugin_version').attr('version'));</script>
|
||||
<!-- <script type="text/javascript">console.log($('.plugin_version').attr('version'));</script> -->
|
||||
<p class="bgw" onclick="pluginService('mariadb', $('.plugin_version').attr('version'));">服务</p>
|
||||
<p onclick="pluginInitD('mariadb', $('.plugin_version').attr('version'));">自启动</p>
|
||||
<p onclick="pluginConfig('mariadb', $('.plugin_version').attr('version'));">配置文件</p>
|
||||
@@ -15,14 +15,12 @@
|
||||
<p onclick="dbList()">管理列表</p>
|
||||
<p onclick="masterOrSlaveConf($('.plugin_version').attr('version'))">主从配置</p>
|
||||
</div>
|
||||
<div class="bt-w-con pd15">
|
||||
<div class="bt-w-con pd15" style="height:555px;overflow: auto;">
|
||||
<div class="soft-man-con"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<style type="text/css">
|
||||
.db_list{
|
||||
padding: 0px 0 10px 0;
|
||||
@@ -52,10 +50,7 @@
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
resetPluginWinWidth(800);
|
||||
|
||||
var loading = layer.msg("资源加载中...", { icon: 16, time: 0, shade: 0.3 });
|
||||
$.getScript( "/plugins/file?name=mariadb&f=js/mariadb.js", function(){
|
||||
layer.close(loading);
|
||||
pluginService('mariadb',$('.plugin_version').attr('version'));
|
||||
});
|
||||
</script>
|
||||
+258
-203
@@ -48,19 +48,19 @@ def getInitDFile():
|
||||
|
||||
def getArgs():
|
||||
args = sys.argv[2:]
|
||||
|
||||
tmp = {}
|
||||
args_len = len(args)
|
||||
|
||||
if args_len == 1:
|
||||
t = args[0].strip('{').strip('}')
|
||||
t = args[0].strip('{').strip('}').strip()
|
||||
if (t == ''):
|
||||
return tmp
|
||||
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
|
||||
|
||||
|
||||
@@ -107,6 +107,14 @@ def getDbPort():
|
||||
return tmp.groups()[0].strip()
|
||||
|
||||
|
||||
def getDbServerId():
|
||||
file = getConf()
|
||||
content = mw.readFile(file)
|
||||
rep = 'server-id\s*=\s*(.*)'
|
||||
tmp = re.search(rep, content)
|
||||
return tmp.groups()[0].strip()
|
||||
|
||||
|
||||
def getSocketFile():
|
||||
file = getConf()
|
||||
content = mw.readFile(file)
|
||||
@@ -664,15 +672,15 @@ def isSqlError(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:
|
||||
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:
|
||||
if "1133," in mysqlMsg:
|
||||
return mw.returnJson(False, '数据库用户不存在!')
|
||||
if "1007" in mysqlMsg:
|
||||
if "1007," in mysqlMsg:
|
||||
return mw.returnJson(False, '数据库已经存在!')
|
||||
return None
|
||||
|
||||
@@ -940,7 +948,7 @@ def getDbList():
|
||||
|
||||
|
||||
def syncGetDatabases():
|
||||
pdb = pMysqlDb()
|
||||
pdb = pMysqlDb('mysql')
|
||||
psdb = pSqliteDb('databases')
|
||||
data = pdb.query('show databases')
|
||||
isError = isSqlError(data)
|
||||
@@ -1706,12 +1714,14 @@ def getMasterStatus(version=''):
|
||||
data['mode'] = recognizeDbMode()
|
||||
data['status'] = master_status
|
||||
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
pdb = pMysqlDb('mysql')
|
||||
dlist = pdb.query('show slave status')
|
||||
if len(dlist) < 1:
|
||||
dlist = pdb.query("show all slaves status")
|
||||
|
||||
# print(dlist[0])
|
||||
if len(dlist) > 0 and (dlist[0]["Slave_IO_Running"] == 'Yes' or dlist[0]["Slave_SQL_Running"] == 'Yes'):
|
||||
data['slave_status'] = True
|
||||
for v in dlist:
|
||||
if v["Slave_IO_Running"] == 'Yes' or v["Slave_SQL_Running"] == 'Yes':
|
||||
data['slave_status'] = True
|
||||
|
||||
return mw.returnJson(master_status, '设置成功', data)
|
||||
except Exception as e:
|
||||
@@ -1855,6 +1865,9 @@ def getMasterRepSlaveUserCmd(version):
|
||||
clist = psdb.field(f).where("username=?", (username,)).limit(
|
||||
'1').order('id desc').select()
|
||||
|
||||
if len(clist) == 0:
|
||||
return mw.returnJson(False, '错误同步账户!')
|
||||
|
||||
ip = mw.getLocalIp()
|
||||
port = getMyPort()
|
||||
db = pMysqlDb()
|
||||
@@ -1868,15 +1881,23 @@ def getMasterRepSlaveUserCmd(version):
|
||||
# 查找同步点
|
||||
# SELECT BINLOG_GTID_POS('master1-bin.000002', 561866201);
|
||||
|
||||
sid = getDbServerId()
|
||||
connection_name = ""
|
||||
if sid != '':
|
||||
connection_name = "'r{}' ".format(sid)
|
||||
|
||||
# MASTER_USE_GTID={current_pos|slave_pos|no}
|
||||
# current_pos 依赖-> select @@global.gtid_current_pos;
|
||||
# slave_pos 依赖-> select @@global.gtid_slave_pos;
|
||||
# no -> 啥都不依赖,保证多主同步成功。同步出现问题,根据日志查找问题。
|
||||
|
||||
if mode == "gtid":
|
||||
sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \
|
||||
sql = "CHANGE MASTER " + connection_name + "TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \
|
||||
clist[0]['username'] + "', MASTER_PASSWORD='" + \
|
||||
clist[0]['password'] + "', " + "MASTER_LOG_FILE='" + mstatus[0]["File"] + \
|
||||
"',MASTER_LOG_POS=" + \
|
||||
str(mstatus[0]["Position"]) + \
|
||||
",MASTER_USE_GTID=slave_pos,MASTER_CONNECT_RETRY=10;"
|
||||
"',MASTER_USE_GTID=no,MASTER_CONNECT_RETRY=10;"
|
||||
else:
|
||||
sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \
|
||||
sql = "CHANGE MASTER " + connection_name + "TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \
|
||||
clist[0]['username'] + "', MASTER_PASSWORD='" + \
|
||||
clist[0]['password'] + \
|
||||
"', MASTER_LOG_FILE='" + mstatus[0]["File"] + \
|
||||
@@ -2151,48 +2172,20 @@ def updateSlaveSSH(version=''):
|
||||
|
||||
|
||||
def getSlaveList(version=''):
|
||||
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
ret = []
|
||||
for x in range(0, len(dlist)):
|
||||
tmp = {}
|
||||
tmp['Master_User'] = dlist[x]["Master_User"]
|
||||
tmp['Master_Host'] = dlist[x]["Master_Host"]
|
||||
tmp['Master_Port'] = dlist[x]["Master_Port"]
|
||||
tmp['Master_Log_File'] = dlist[x]["Master_Log_File"]
|
||||
tmp['Slave_IO_Running'] = dlist[x]["Slave_IO_Running"]
|
||||
tmp['Slave_SQL_Running'] = dlist[x]["Slave_SQL_Running"]
|
||||
tmp['Last_Error'] = dlist[x]["Last_Error"]
|
||||
tmp['Last_IO_Error'] = dlist[x]["Last_IO_Error"]
|
||||
tmp['Last_SQL_Error'] = dlist[x]["Last_SQL_Error"]
|
||||
tmp['Slave_SQL_Running_State'] = dlist[x]["Slave_SQL_Running_State"]
|
||||
if len(dlist) == 0:
|
||||
dlist = db.query('show all slaves status')
|
||||
|
||||
tmp['Error'] = ''
|
||||
if tmp['Last_Error'] != '':
|
||||
tmp['Error'] = tmp['Last_Error']
|
||||
|
||||
if tmp['Last_IO_Error'] != '':
|
||||
tmp['Error'] = tmp['Last_IO_Error']
|
||||
|
||||
if tmp['Last_SQL_Error'] != '':
|
||||
tmp['Error'] = tmp['Last_SQL_Error']
|
||||
|
||||
if tmp['Error'] == '':
|
||||
tmp['Error'] = tmp['Slave_SQL_Running_State']
|
||||
|
||||
ret.append(tmp)
|
||||
data = {}
|
||||
data['data'] = ret
|
||||
|
||||
data['data'] = dlist
|
||||
return mw.getJson(data)
|
||||
|
||||
|
||||
def getSlaveSyncCmd(version=''):
|
||||
|
||||
root = mw.getRunDir()
|
||||
cmd = 'cd ' + root + ' && python3 ' + root + \
|
||||
'/plugins/mysql/index.py do_full_sync {"db":"all"}'
|
||||
'/plugins/mariadb/index.py do_full_sync {"db":"all","sign":""}'
|
||||
return mw.returnJson(True, 'ok', cmd)
|
||||
|
||||
|
||||
@@ -2208,102 +2201,151 @@ def initSlaveStatus(version=''):
|
||||
return initSlaveStatusSyncUser(version)
|
||||
|
||||
|
||||
def parseSlaveSyncCmd(cmd):
|
||||
a = {}
|
||||
vlist = cmd.split(',')
|
||||
|
||||
has_connection_name = vlist[0]
|
||||
|
||||
pattern_c = r"CHANGE MASTER \'(.*)\' TO MASTER_HOST"
|
||||
match_val = re.match(pattern_c, has_connection_name, re.I)
|
||||
if match_val:
|
||||
m_groups = match_val.groups()
|
||||
a['Connection_name'] = m_groups[0]
|
||||
|
||||
for i in vlist:
|
||||
tmp = i.strip()
|
||||
tmp_a = tmp.split(" ")
|
||||
real_tmp = tmp_a[len(tmp_a) - 1]
|
||||
kv = real_tmp.split("=")
|
||||
a[kv[0]] = kv[1].replace("'", '').replace("'", '').replace(";", '')
|
||||
return a
|
||||
|
||||
|
||||
def initSlaveStatusSyncUser(version=''):
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
if len(data) < 1:
|
||||
|
||||
slave_data = conn.field('id,ip,port,user,pass,mode,cmd').select()
|
||||
if len(slave_data) < 1:
|
||||
return mw.returnJson(False, '需要先添加同步用户配置!')
|
||||
|
||||
# print(data)
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
if len(dlist) > 0:
|
||||
return mw.returnJson(False, '已经初始化好了zz...')
|
||||
pdb = pMysqlDb()
|
||||
if len(slave_data) == 1:
|
||||
dlist = pdb.query('show slave status')
|
||||
if len(dlist) > 0:
|
||||
return mw.returnJson(False, '已经初始化好了zz...')
|
||||
|
||||
u = data
|
||||
msg = ''
|
||||
|
||||
mode_name = 'classic'
|
||||
if u['mode'] == '1':
|
||||
mode_name = 'gtid'
|
||||
pdb.query("stop slave")
|
||||
pdb.query("stop all slaves")
|
||||
|
||||
local_mode = recognizeDbMode()
|
||||
if local_mode != mode_name:
|
||||
return mw.returnJson(False, '同步模式不一致!')
|
||||
for x in range(len(slave_data)):
|
||||
slave_t = slave_data[x]
|
||||
base_t = 'IP:' + slave_t['ip'] + ",PORT:" + \
|
||||
slave_t['port'] + ",USER:" + slave_t['user']
|
||||
|
||||
# print(u['cmd'])
|
||||
t = db.query(u['cmd'])
|
||||
# print(t)
|
||||
db.query("start slave")
|
||||
return mw.returnJson(True, '初始化成功!')
|
||||
mode_name = 'classic'
|
||||
if slave_data[x]['mode'] == '1':
|
||||
mode_name = 'gtid'
|
||||
|
||||
if local_mode != mode_name:
|
||||
msg += base_t + '->同步模式不一致'
|
||||
continue
|
||||
|
||||
cmd_sql = slave_t['cmd']
|
||||
if cmd_sql == '':
|
||||
msg += base_t + '->同步命令不能为空'
|
||||
continue
|
||||
|
||||
try:
|
||||
pinfo = parseSlaveSyncCmd(cmd_sql)
|
||||
except Exception as e:
|
||||
return mw.returnJson(False, base_t + '->CMD同步命令不合规范!')
|
||||
|
||||
pdb.query(cmd_sql)
|
||||
|
||||
pdb.query("start slave")
|
||||
pdb.query("start all slaves ")
|
||||
|
||||
if msg == '':
|
||||
msg = '初始化成功!'
|
||||
return mw.returnJson(True, msg)
|
||||
|
||||
|
||||
def initSlaveStatusSSH(version=''):
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
if len(dlist) > 0:
|
||||
return mw.returnJson(False, '已经初始化好了zz...')
|
||||
if len(dlist) == 0:
|
||||
dlist = db.query('show all slaves status')
|
||||
|
||||
conn = pSqliteDb('slave_id_rsa')
|
||||
data = conn.field('ip,port,id_rsa,db_user').find()
|
||||
ssh_list = conn.field('ip,port,id_rsa,db_user').select()
|
||||
|
||||
if len(data) < 1:
|
||||
if len(ssh_list) < 1:
|
||||
return mw.returnJson(False, '需要先配置【[主]SSH配置】!')
|
||||
|
||||
SSH_PRIVATE_KEY = "/tmp/t_ssh.txt"
|
||||
ip = data['ip']
|
||||
master_port = data['port']
|
||||
mw.writeFile(SSH_PRIVATE_KEY, data['id_rsa'].replace('\\n', '\n'))
|
||||
|
||||
import paramiko
|
||||
paramiko.util.log_to_file('paramiko.log')
|
||||
ssh = paramiko.SSHClient()
|
||||
|
||||
try:
|
||||
for data in ssh_list:
|
||||
ip = data['ip']
|
||||
master_port = data['port']
|
||||
SSH_PRIVATE_KEY = "/tmp/t_ssh_" + ip + ".txt"
|
||||
|
||||
mw.writeFile(SSH_PRIVATE_KEY, data['id_rsa'].replace('\\n', '\n'))
|
||||
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=int(master_port),
|
||||
username='root', pkey=key)
|
||||
|
||||
db_user = data['db_user']
|
||||
cmd = 'cd /www/server/mdserver-web && python3 plugins/mariadb/index.py get_master_rep_slave_user_cmd {"username":"' + db_user + '","db":""}'
|
||||
stdin, stdout, stderr = ssh.exec_command(cmd)
|
||||
result = stdout.read()
|
||||
result = result.decode('utf-8')
|
||||
cmd_data = json.loads(result)
|
||||
time.sleep(1)
|
||||
ssh.close()
|
||||
if not cmd_data['status']:
|
||||
return mw.returnJson(False, '[主]:' + cmd_data['msg'])
|
||||
try:
|
||||
key = paramiko.RSAKey.from_private_key_file(SSH_PRIVATE_KEY)
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect(hostname=ip, port=int(master_port),
|
||||
username='root', pkey=key)
|
||||
|
||||
local_mode = recognizeDbMode()
|
||||
if local_mode != cmd_data['data']['mode']:
|
||||
return mw.returnJson(False, '主【{}】从【{}】,运行模式不一致!'.format(cmd_data['data']['mode'], local_mode))
|
||||
db_user = data['db_user']
|
||||
cmd = 'cd /www/server/mdserver-web && source bin/activate && python3 plugins/mariadb/index.py get_master_rep_slave_user_cmd {"username":"' + db_user + '","db":""}'
|
||||
stdin, stdout, stderr = ssh.exec_command(cmd)
|
||||
result = stdout.read()
|
||||
result = result.decode('utf-8')
|
||||
if result.strip() == "":
|
||||
return mw.returnJson(False, '[主][' + ip + ']:获取同步命令失败!')
|
||||
cmd_data = json.loads(result)
|
||||
time.sleep(1)
|
||||
ssh.close()
|
||||
if not cmd_data['status']:
|
||||
return mw.returnJson(False, '[主][' + ip + ']:' + cmd_data['msg'])
|
||||
|
||||
u = cmd_data['data']['info']
|
||||
ps = u['username'] + "|" + u['password']
|
||||
conn.where('ip=?', (ip,)).setField('ps', ps)
|
||||
db.query('stop slave')
|
||||
local_mode = recognizeDbMode()
|
||||
if local_mode != cmd_data['data']['mode']:
|
||||
return mw.returnJson(False, '[主][' + ip + ']【{}】从【{}】,运行模式不一致!'.format(cmd_data['data']['mode'], local_mode))
|
||||
|
||||
# 保证同步IP一致
|
||||
cmd = cmd_data['data']['cmd']
|
||||
if cmd.find('SOURCE_HOST') > -1:
|
||||
cmd = re.sub(r"SOURCE_HOST='(.*?)'",
|
||||
"SOURCE_HOST='" + ip + "'", cmd, 1)
|
||||
u = cmd_data['data']['info']
|
||||
ps = u['username'] + "|" + u['password']
|
||||
conn.where('ip=?', (ip,)).setField('ps', ps)
|
||||
db.query('stop slave')
|
||||
db.query('stop all slaves')
|
||||
|
||||
if cmd.find('MASTER_HOST') > -1:
|
||||
cmd = re.sub(r"MASTER_HOST='(.*?)'",
|
||||
"MASTER_HOST='" + ip + "'", cmd, 1)
|
||||
# 保证同步IP一致
|
||||
cmd = cmd_data['data']['cmd']
|
||||
if cmd.find('SOURCE_HOST') > -1:
|
||||
cmd = re.sub(r"SOURCE_HOST='(.*?)'",
|
||||
"SOURCE_HOST='" + ip + "'", cmd, 1)
|
||||
|
||||
# print(cmd)
|
||||
db.query(cmd)
|
||||
db.query("start slave")
|
||||
if cmd.find('MASTER_HOST') > -1:
|
||||
cmd = re.sub(r"MASTER_HOST='(.*?)'",
|
||||
"MASTER_HOST='" + ip + "'", cmd, 1)
|
||||
|
||||
except Exception as e:
|
||||
return mw.returnJson(False, 'SSH认证配置连接失败!' + str(e))
|
||||
# print(cmd)
|
||||
db.query(cmd)
|
||||
db.query("start slave")
|
||||
db.query("start all slaves")
|
||||
if os.path.exists(SSH_PRIVATE_KEY):
|
||||
os.system("rm -rf " + SSH_PRIVATE_KEY)
|
||||
except Exception as e:
|
||||
return mw.returnJson(False, '[主][' + ip + ']:SSH认证配置连接失败!' + str(e))
|
||||
|
||||
os.system("rm -rf " + SSH_PRIVATE_KEY)
|
||||
return mw.returnJson(True, '初始化成功!')
|
||||
|
||||
|
||||
@@ -2312,61 +2354,39 @@ def setSlaveStatus(version=''):
|
||||
if not os.path.exists(mode_file):
|
||||
return mw.returnJson(False, '需要先设置同步配置')
|
||||
|
||||
mode = mw.readFile(mode_file)
|
||||
if mode == 'ssh':
|
||||
return setSlaveStatusSSH(version)
|
||||
if mode == 'sync-user':
|
||||
return setSlaveStatusSyncUser(version)
|
||||
pdb = pMysqlDb()
|
||||
dlist = pdb.query('show slave status')
|
||||
if len(dlist) == 0:
|
||||
dlist = pdb.query('show all slaves status')
|
||||
|
||||
|
||||
def setSlaveStatusSyncUser(version=''):
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
if len(dlist) == 0:
|
||||
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:
|
||||
ip = dlist[0]['Master_Host']
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
if len(data) == 0:
|
||||
return mw.returnJson(False, '没有数据无法重启!')
|
||||
user = data['user']
|
||||
apass = data['pass']
|
||||
for v in dlist:
|
||||
connection_name = ''
|
||||
cmd = "slave"
|
||||
if 'Connection_name' in v:
|
||||
connection_name = v['Connection_name']
|
||||
cmd = "slave '{}'".format(connection_name)
|
||||
|
||||
db.query("start slave")
|
||||
# db.query("start slave user='{}' password='{}';".format(user, apass))
|
||||
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def setSlaveStatusSSH(version=''):
|
||||
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
if len(dlist) == 0:
|
||||
return mw.returnJson(False, '需要手动添加主服务命令或者执行[初始化]!')
|
||||
|
||||
# print(dlist)
|
||||
if len(dlist) > 0 and (dlist[0]["Slave_IO_Running"] == 'Yes' or dlist[0]["Slave_SQL_Running"] == 'Yes'):
|
||||
db.query('stop slave')
|
||||
else:
|
||||
ip = dlist[0]['Master_Host']
|
||||
conn = pSqliteDb('slave_id_rsa')
|
||||
data = conn.field('ip,ps').where("ip=?", (ip,)).find()
|
||||
if len(data) == 0:
|
||||
return mw.returnJson(False, '没有数据无法重启!')
|
||||
db.query("start slave")
|
||||
if (v["Slave_IO_Running"] == 'Yes' or v["Slave_SQL_Running"] == 'Yes'):
|
||||
pdb.query("stop {}".format(cmd))
|
||||
else:
|
||||
pdb.query("start {}".format(cmd))
|
||||
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def deleteSlave(version=''):
|
||||
args = getArgs()
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('stop slave')
|
||||
dlist = db.query('reset slave all')
|
||||
if 'sign' in args:
|
||||
sign = args['sign']
|
||||
db.query("stop slave '{}'".format(sign))
|
||||
db.query("reset slave '{}' all".format(sign))
|
||||
else:
|
||||
db.query('stop slave')
|
||||
db.query('reset slave all')
|
||||
return mw.returnJson(True, '删除成功!')
|
||||
|
||||
|
||||
@@ -2402,14 +2422,54 @@ def dumpMysqlData(version=''):
|
||||
|
||||
############### --- 重要 同步---- ###########
|
||||
|
||||
|
||||
def asyncTmpfile():
|
||||
path = '/tmp/mariadb_async_status.txt'
|
||||
return path
|
||||
|
||||
|
||||
def writeDbSyncStatus(data):
|
||||
path = '/tmp/db_async_status.txt'
|
||||
# status_data['code'] = 1
|
||||
# status_data['msg'] = '主服务器备份完成...'
|
||||
# status_data['progress'] = 30
|
||||
path = asyncTmpfile()
|
||||
mw.writeFile(path, json.dumps(data))
|
||||
|
||||
|
||||
def fullSync(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['db', 'begin'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
sign = ''
|
||||
if 'sign' in args:
|
||||
sign = args['sign']
|
||||
|
||||
status_file = asyncTmpfile()
|
||||
if args['begin'] == '1':
|
||||
cmd = 'cd ' + mw.getRunDir() + ' && python3 ' + \
|
||||
getPluginDir() + \
|
||||
'/index.py do_full_sync {"db":"' + \
|
||||
args['db'] + '","sign":"' + sign + '"} &'
|
||||
# print(cmd)
|
||||
mw.execShell(cmd)
|
||||
return json.dumps({'code': 0, 'msg': '同步数据中!', 'progress': 0})
|
||||
|
||||
if os.path.exists(status_file):
|
||||
c = mw.readFile(status_file)
|
||||
tmp = json.loads(c)
|
||||
if tmp['code'] == 1:
|
||||
sys_dump_sql = "/tmp/dump.sql"
|
||||
if os.path.exists(sys_dump_sql):
|
||||
dump_size = os.path.getsize(sys_dump_sql)
|
||||
tmp['msg'] = tmp['msg'] + ":" + "同步文件:" + mw.toSize(dump_size)
|
||||
c = json.dumps(tmp)
|
||||
|
||||
# if tmp['code'] == 6:
|
||||
# os.remove(status_file)
|
||||
return c
|
||||
|
||||
return json.dumps({'code': 0, 'msg': '点击开始,开始同步!', 'progress': 0})
|
||||
|
||||
|
||||
def doFullSync(version=''):
|
||||
mode_file = getSyncModeFile()
|
||||
if not os.path.exists(mode_file):
|
||||
@@ -2424,16 +2484,23 @@ def doFullSync(version=''):
|
||||
|
||||
def doFullSyncUser(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['db'])
|
||||
data = checkArgs(args, ['db', 'sign'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
sync_db = args['db']
|
||||
sync_sign = args['sign']
|
||||
|
||||
# print(sync_sign, sync_db)
|
||||
db = pMysqlDb()
|
||||
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
if sync_sign != '':
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').where(
|
||||
'ip=?', (sync_sign,)).find()
|
||||
else:
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
|
||||
user = data['user']
|
||||
apass = data['pass']
|
||||
port = data['port']
|
||||
@@ -2442,12 +2509,12 @@ def doFullSyncUser(version=''):
|
||||
bak_file = '/tmp/tmp.sql'
|
||||
|
||||
writeDbSyncStatus({'code': 0, 'msg': '开始同步...', 'progress': 0})
|
||||
|
||||
writeDbSyncStatus({'code': 1, 'msg': '远程导出数据...', 'progress': 20})
|
||||
writeDbSyncStatus({'code': 1, 'msg': '远程导出数据...', 'progress': 10})
|
||||
|
||||
if not os.path.exists(bak_file):
|
||||
dump_sql_data = getServerDir() + "/bin/mysqldump --force --opt --default-character-set=utf8 --single-transaction -h" + ip + " -P" + \
|
||||
port + " -u" + user + " -p" + apass + " " + sync_db + " > " + bak_file
|
||||
print(dump_sql_data)
|
||||
mw.execShell(dump_sql_data)
|
||||
|
||||
writeDbSyncStatus({'code': 2, 'msg': '本地导入数据...', 'progress': 40})
|
||||
@@ -2458,24 +2525,38 @@ def doFullSyncUser(version=''):
|
||||
' ' + sync_db + ' < ' + bak_file
|
||||
mw.execShell(my_import_cmd)
|
||||
|
||||
db.query("start slave")
|
||||
pinfo = parseSlaveSyncCmd(data['cmd'])
|
||||
# print(pinfo)
|
||||
if 'Connection_name' in pinfo:
|
||||
db.query("start slave '{}'".format(pinfo['Connection_name']))
|
||||
else:
|
||||
db.query("start slave")
|
||||
|
||||
writeDbSyncStatus({'code': 6, 'msg': '从库重启完成...', 'progress': 100})
|
||||
os.system("rm -rf " + bak_file)
|
||||
|
||||
if os.path.exists(bak_file):
|
||||
os.system("rm -rf " + bak_file)
|
||||
return True
|
||||
|
||||
|
||||
def doFullSyncSSH(version=''):
|
||||
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['db'])
|
||||
data = checkArgs(args, ['db', 'sign'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
db = pMysqlDb()
|
||||
|
||||
sync_db = args['db']
|
||||
sync_sign = args['sign']
|
||||
|
||||
id_rsa_conn = pSqliteDb('slave_id_rsa')
|
||||
data = id_rsa_conn.field('ip,port,db_user,id_rsa').find()
|
||||
if sync_sign != '':
|
||||
data = id_rsa_conn.field('ip,port,db_user,id_rsa').where(
|
||||
'ip=?', (sync_sign,)).find()
|
||||
else:
|
||||
data = id_rsa_conn.field('ip,port,db_user,id_rsa').find()
|
||||
|
||||
SSH_PRIVATE_KEY = "/tmp/mysql_sync_id_rsa.txt"
|
||||
id_rsa = data['id_rsa'].replace('\\n', '\n')
|
||||
@@ -2498,7 +2579,6 @@ def doFullSyncSSH(version=''):
|
||||
return 'fail'
|
||||
|
||||
try:
|
||||
# ssh.load_system_host_keys()
|
||||
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())
|
||||
@@ -2516,7 +2596,7 @@ def doFullSyncSSH(version=''):
|
||||
|
||||
writeDbSyncStatus({'code': 0, 'msg': '登录Master成功...', 'progress': 5})
|
||||
dbname = args['db']
|
||||
cmd = "cd /www/server/mdserver-web && python3 plugins/mariadb/index.py dump_mysql_data {\"db\":'" + dbname + "'}"
|
||||
cmd = "cd /www/server/mdserver-web && source bin/activate && python3 plugins/mariadb/index.py dump_mysql_data {\"db\":'" + dbname + "'}"
|
||||
print(cmd)
|
||||
stdin, stdout, stderr = ssh.exec_command(cmd)
|
||||
result = stdout.read()
|
||||
@@ -2539,13 +2619,19 @@ def doFullSyncSSH(version=''):
|
||||
if copy_status == None:
|
||||
writeDbSyncStatus({'code': 2, 'msg': '数据同步本地完成...', 'progress': 40})
|
||||
|
||||
cmd = 'cd /www/server/mdserver-web && python3 plugins/mariadb/index.py get_master_rep_slave_user_cmd {"username":"' + db_user + '","db":""}'
|
||||
cmd = 'cd /www/server/mdserver-web && source bin/activate && python3 plugins/mariadb/index.py get_master_rep_slave_user_cmd {"username":"' + db_user + '","db":""}'
|
||||
stdin, stdout, stderr = ssh.exec_command(cmd)
|
||||
result = stdout.read()
|
||||
result = result.decode('utf-8')
|
||||
|
||||
if result == '':
|
||||
writeDbSyncStatus({'code': 1, 'msg': '同步命令获取失败!', 'progress': 100})
|
||||
return 'fail'
|
||||
|
||||
cmd_data = json.loads(result)
|
||||
|
||||
db.query('stop slave')
|
||||
db.query('stop all slaves')
|
||||
writeDbSyncStatus({'code': 3, 'msg': '停止从库完成...', 'progress': 45})
|
||||
|
||||
cmd = cmd_data['data']['cmd']
|
||||
@@ -2578,6 +2664,7 @@ def doFullSyncSSH(version=''):
|
||||
return 'fail'
|
||||
|
||||
db.query("start slave")
|
||||
db.query("start all slaves")
|
||||
writeDbSyncStatus({'code': 6, 'msg': '从库重启完成...', 'progress': 100})
|
||||
|
||||
os.system("rm -rf " + SSH_PRIVATE_KEY)
|
||||
@@ -2585,38 +2672,6 @@ def doFullSyncSSH(version=''):
|
||||
return True
|
||||
|
||||
|
||||
def fullSync(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['db', 'begin'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
status_file = '/tmp/db_async_status.txt'
|
||||
if args['begin'] == '1':
|
||||
cmd = 'cd ' + mw.getRunDir() + ' && python3 ' + \
|
||||
getPluginDir() + \
|
||||
'/index.py do_full_sync {"db":"' + args['db'] + '"} &'
|
||||
print(cmd)
|
||||
mw.execShell(cmd)
|
||||
return json.dumps({'code': 0, 'msg': '同步数据中!', 'progress': 0})
|
||||
|
||||
if os.path.exists(status_file):
|
||||
c = mw.readFile(status_file)
|
||||
tmp = json.loads(c)
|
||||
if tmp['code'] == 1:
|
||||
sys_dump_sql = "/tmp/dump.sql"
|
||||
if os.path.exists(sys_dump_sql):
|
||||
dump_size = os.path.getsize(sys_dump_sql)
|
||||
tmp['msg'] = tmp['msg'] + ":" + "同步文件:" + mw.toSize(dump_size)
|
||||
c = json.dumps(tmp)
|
||||
|
||||
# if tmp['code'] == 6:
|
||||
# os.remove(status_file)
|
||||
return c
|
||||
|
||||
return json.dumps({'code': 0, 'msg': '点击开始,开始同步!', 'progress': 0})
|
||||
|
||||
|
||||
def installPreInspection(version):
|
||||
swap_path = mw.getServerDir() + "/swap"
|
||||
if not os.path.exists(swap_path):
|
||||
|
||||
+178
-86
@@ -431,7 +431,6 @@ function syncToDatabase(type){
|
||||
var postData = 'type='+type+'&ids='+JSON.stringify(data);
|
||||
myPost('sync_to_databases', postData, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
// console.log(rdata);
|
||||
showMsg(rdata.msg,function(){
|
||||
dbList();
|
||||
},{ icon: rdata.status ? 1 : 2 });
|
||||
@@ -439,18 +438,6 @@ function syncToDatabase(type){
|
||||
}
|
||||
|
||||
function setRootPwd(type, pwd){
|
||||
if (type==1){
|
||||
var password = $("#MyPassword").val();
|
||||
myPost('set_root_pwd', {password:password}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
dbList();
|
||||
$('.layui-layer-close1').click();
|
||||
},{icon: rdata.status ? 1 : 2});
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
var index = layer.open({
|
||||
type: 1,
|
||||
area: '500px',
|
||||
@@ -467,8 +454,16 @@ function setRootPwd(type, pwd){
|
||||
</div>\
|
||||
</div>\
|
||||
</form>",
|
||||
yes:function(){
|
||||
setRootPwd(1);
|
||||
yes:function(index,layero){
|
||||
var password = $("#MyPassword").val();
|
||||
myPost('set_root_pwd', {password:password}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
dbList();
|
||||
layer.close(index);
|
||||
},{icon: rdata.status ? 1 : 2});
|
||||
});
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -490,7 +485,6 @@ function showHidePass(obj){
|
||||
function checkSelect(){
|
||||
setTimeout(function () {
|
||||
var num = $('input[type="checkbox"].check:checked').length;
|
||||
// console.log(num);
|
||||
if (num == 1) {
|
||||
$('button[batch="true"]').hide();
|
||||
$('button[batch="false"]').show();
|
||||
@@ -861,7 +855,6 @@ function downloadBackup(file){
|
||||
|
||||
function importBackup(file,name){
|
||||
myPost('import_db_backup',{file:file,name:name}, function(data){
|
||||
// console.log(data);
|
||||
layer.msg('执行成功!');
|
||||
});
|
||||
}
|
||||
@@ -1619,7 +1612,6 @@ function getMasterRepSlaveList(){
|
||||
_data['page'] = page;
|
||||
_data['page_size'] = 10;
|
||||
myPost('get_master_rep_slave_list', _data, function(data){
|
||||
// console.log(data);
|
||||
var rdata = [];
|
||||
try {
|
||||
rdata = $.parseJSON(data.data);
|
||||
@@ -1672,12 +1664,12 @@ function getMasterRepSlaveListPage(){
|
||||
}
|
||||
|
||||
|
||||
function deleteSlave(){
|
||||
myPost('delete_slave', {}, function(data){
|
||||
function deleteSlave(sign = ''){
|
||||
myPost('delete_slave', {sign:sign}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
showMsg(rdata['msg'], function(){
|
||||
masterOrSlaveConf();
|
||||
},{},3000);
|
||||
},{icon:rdata.status?1:2,time:3000},3000);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1685,28 +1677,72 @@ function deleteSlave(){
|
||||
function getFullSyncStatus(db){
|
||||
var timeId = null;
|
||||
|
||||
var btn = '<div class="table_toolbar" style="left:0px;"><span data-status="init" class="sync btn btn-default btn-sm" id="begin_full_sync" title="">开始</span></div>';
|
||||
var loadOpen = layer.open({
|
||||
type: 1,
|
||||
title: '全量同步['+db+']',
|
||||
area: '500px',
|
||||
content:"<div class='bt-form pd20 c6'>\
|
||||
<div class='divtable mtb10'>\
|
||||
<span id='full_msg'></span>\
|
||||
<div class='progress'>\
|
||||
<div class='progress-bar' role='progressbar' aria-valuenow='0' aria-valuemin='0' aria-valuemax='100' style='min-width: 2em;'>0%</div>\
|
||||
</div>\
|
||||
</div>\
|
||||
"+btn+"\
|
||||
</div>",
|
||||
cancel: function(){
|
||||
clearInterval(timeId);
|
||||
myPost('get_slave_list', {page:1,page_size:100}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
var rsource = rdata.data;
|
||||
|
||||
if (db == 'ALL' && rsource.length>1){
|
||||
layer.msg("多主不支持该模式!",{icon:2});
|
||||
return;
|
||||
}
|
||||
|
||||
var dataSource = '';
|
||||
if (rsource.length>1){
|
||||
var sourceList = '';
|
||||
for (var i = 0; i < rsource.length; i++) {
|
||||
if ('Connection_name' in rsource[i]){
|
||||
sourceList += '<option val="'+rsource[i]['Master_Host']+'">'+rsource[i]['Master_Host']+'</option>';
|
||||
}
|
||||
}
|
||||
|
||||
dataSource = "<p class='line' style='text-align:center;'>\
|
||||
<span>同步数据源:</span>\
|
||||
<select class='bt-input-text' name='data_source' style='width:200px;'>" + sourceList + "</select>\
|
||||
</p>";
|
||||
}
|
||||
|
||||
layer.open({
|
||||
type: 1,
|
||||
title: '全量同步['+db+']',
|
||||
area: '500px',
|
||||
content:"<div class='bt-form pd15'>\
|
||||
<div class='divtable mtb10'>\
|
||||
"+dataSource+"\
|
||||
<span id='full_msg'></span>\
|
||||
<div class='progress'>\
|
||||
<div class='progress-bar' role='progressbar' aria-valuenow='0' aria-valuemin='0' aria-valuemax='100' style='min-width: 2em;'>0%</div>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class='table_toolbar' style='left:0px;'>\
|
||||
<span data-status='init' class='sync btn btn-default btn-sm' id='begin_full_sync'>开始</span>\
|
||||
</div>\
|
||||
</div>",
|
||||
cancel: function(){
|
||||
clearInterval(timeId);
|
||||
},
|
||||
success:function(){
|
||||
$('#begin_full_sync').click(function(){
|
||||
var val = $(this).data('status');
|
||||
var sign = '';
|
||||
if (dataSource !=''){
|
||||
sign = $('select[name="data_source"]').val();
|
||||
}
|
||||
if (val == 'init'){
|
||||
fullSync(db, sign, 1);
|
||||
timeId = setInterval(function(){
|
||||
fullSync(db,sign,0);
|
||||
}, 1000);
|
||||
$(this).data('status','starting');
|
||||
} else {
|
||||
layer.msg("正在同步中..",{icon:0});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function fullSync(db,begin){
|
||||
|
||||
myPostN('full_sync', {db:db,begin:begin}, function(data){
|
||||
function fullSync(db, sign, begin){
|
||||
myPostN('full_sync', {db:db,sign:sign,begin:begin}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
$('#full_msg').text(rdata['msg']);
|
||||
$('.progress-bar').css('width',rdata['progress']+'%');
|
||||
@@ -1715,23 +1751,11 @@ function getFullSyncStatus(db){
|
||||
if (rdata['code']==6 ||rdata['code']<0){
|
||||
layer.msg(rdata['msg']);
|
||||
clearInterval(timeId);
|
||||
$("#begin_full_sync").attr('data-status','init');
|
||||
$("#begin_full_sync").data('status','init');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$('#begin_full_sync').click(function(){
|
||||
var val = $(this).attr('data-status');
|
||||
if (val == 'init'){
|
||||
fullSync(db,1);
|
||||
timeId = setInterval(function(){
|
||||
fullSync(db,0);
|
||||
}, 1000);
|
||||
$(this).attr('data-status','starting');
|
||||
} else {
|
||||
layer.msg("正在同步中..");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function addSlaveSSH(ip=''){
|
||||
@@ -2077,7 +2101,7 @@ function getSlaveUserList(){
|
||||
layerId = layer.open({
|
||||
type: 1,
|
||||
title: '同步账户列表',
|
||||
area: '500px',
|
||||
area: '600px',
|
||||
content:"<div class='bt-form pd20 c6'>\
|
||||
<div class='divtable mtb10'>\
|
||||
<div><table class='table table-hover get-slave-ssh-list'>\
|
||||
@@ -2101,7 +2125,7 @@ function getSlaveSSHList(page=1){
|
||||
layerId = layer.open({
|
||||
type: 1,
|
||||
title: 'SSH列表',
|
||||
area: '500px',
|
||||
area: '600px',
|
||||
content:"<div class='bt-form pd20 c6'>\
|
||||
<div class='divtable mtb10'>\
|
||||
<div><table class='table table-hover get-slave-ssh-list'>\
|
||||
@@ -2142,11 +2166,15 @@ function handlerRun(){
|
||||
function initSlaveStatus(){
|
||||
myPost('init_slave_status', '', function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
if (!rdata.status ){
|
||||
layer.msg(rdata.msg,{icon:2,time:10000});
|
||||
return;
|
||||
}
|
||||
showMsg(rdata.msg,function(){
|
||||
if (rdata.status){
|
||||
masterOrSlaveConf();
|
||||
}
|
||||
},{icon:rdata.status?1:2},2000);
|
||||
},{icon:1},2000);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2204,33 +2232,48 @@ function masterOrSlaveConf(version=''){
|
||||
}
|
||||
|
||||
_data['page'] = page;
|
||||
_data['page_size'] = 10;
|
||||
_data['page_size'] = 100;
|
||||
|
||||
myPost('get_slave_list', _data, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
var list = '';
|
||||
|
||||
var isHasSign = false;
|
||||
for(i in rdata.data){
|
||||
|
||||
var v = rdata.data[i];
|
||||
var status = "<a class='btlink db_error'>异常</>";
|
||||
if ('Connection_name' in v){
|
||||
isHasSign = true;
|
||||
}
|
||||
|
||||
var status = "<a data-id="+i+" class='btlink db_error'>异常</>";
|
||||
if (v['Slave_SQL_Running'] == 'Yes' && v['Slave_IO_Running'] == 'Yes'){
|
||||
status = "正常";
|
||||
}
|
||||
|
||||
list += '<tr>';
|
||||
list += '<td>' + rdata.data[i]['Master_Host'] +'</td>';
|
||||
list += '<td>' + rdata.data[i]['Master_Port'] +'</td>';
|
||||
list += '<td>' + rdata.data[i]['Master_User'] +'</td>';
|
||||
list += '<td>' + rdata.data[i]['Master_Log_File'] +'</td>';
|
||||
list += '<td>' + rdata.data[i]['Slave_IO_Running'] +'</td>';
|
||||
list += '<td>' + rdata.data[i]['Slave_SQL_Running'] +'</td>';
|
||||
list += '<td>' + v['Master_Host'] +'</td>';
|
||||
list += '<td>' + v['Master_Port'] +'</td>';
|
||||
list += '<td>' + v['Master_User'] +'</td>';
|
||||
list += '<td>' + v['Master_Log_File'] +'</td>';
|
||||
list += '<td>' + v['Slave_IO_Running'] +'</td>';
|
||||
list += '<td>' + v['Slave_SQL_Running'] +'</td>';
|
||||
if (isHasSign){
|
||||
list += '<td>' + v['Connection_name'] +'</td>';
|
||||
}
|
||||
|
||||
list += '<td>' + status +'</td>';
|
||||
list += '<td style="text-align:right">' +
|
||||
'<a href="javascript:;" class="btlink" onclick="deleteSlave()" title="删除">删除</a>' +
|
||||
'</td>';
|
||||
list += '<td style="text-align:right">\
|
||||
<a data-id="'+i+'" href="javascript:;" class="btlink btn_delete_slave" title="删除">删除</a>\
|
||||
</td>';
|
||||
list += '</tr>';
|
||||
}
|
||||
|
||||
var signThead_th = '';
|
||||
if (isHasSign){
|
||||
var signThead_th = '<th>标识</th>';
|
||||
}
|
||||
|
||||
var con = '<div class="divtable mtb10">\
|
||||
<div class="tablescroll">\
|
||||
<table id="DataBody" class="table table-hover" width="100%" cellspacing="0" cellpadding="0" border="0" style="border: 0 none;">\
|
||||
@@ -2241,6 +2284,7 @@ function masterOrSlaveConf(version=''){
|
||||
<th>日志</th>\
|
||||
<th>IO</th>\
|
||||
<th>SQL</th>\
|
||||
'+signThead_th+'\
|
||||
<th>状态</th>\
|
||||
<th style="text-align:right;">操作</th></tr></thead>\
|
||||
<tbody>\
|
||||
@@ -2255,22 +2299,75 @@ function masterOrSlaveConf(version=''){
|
||||
// </div>
|
||||
$(".table_slave_status_list").html(con);
|
||||
|
||||
|
||||
$(".btn_delete_slave").click(function(){
|
||||
var id = $(this).data('id');
|
||||
var v = rdata.data[id];
|
||||
if ('Connection_name' in v){
|
||||
deleteSlave(v['Connection_name']);
|
||||
} else{
|
||||
deleteSlave();
|
||||
}
|
||||
});
|
||||
|
||||
$('.db_error').click(function(){
|
||||
var id = $(this).data('id');
|
||||
var info = rdata.data[id];
|
||||
|
||||
var err_line = "";
|
||||
err_line +="<tr>\
|
||||
<td>IO错误</td>\
|
||||
<td>"+ (info['Last_IO_Error'] == '' ? '无':info['Last_IO_Error'])+"</td>\
|
||||
</tr>";
|
||||
err_line +="<tr>\
|
||||
<td>SQL错误</td>\
|
||||
<td>"+(info['Last_SQL_Error'] == '' ? '无':info['Last_SQL_Error'])+"</td>\
|
||||
</tr>";
|
||||
|
||||
err_line +="<tr>\
|
||||
<td>状态</td>\
|
||||
<td>"+(info['Slave_SQL_Running_State'] == '' ? '无':info['Slave_SQL_Running_State']) +"</td>\
|
||||
</tr>";
|
||||
|
||||
layer.open({
|
||||
type: 1,
|
||||
title: '同步异常信息',
|
||||
area: '500px',
|
||||
content:"<form class='bt-form pd20 pb70'>\
|
||||
<div class='line'>"+v['Error']+"</div>\
|
||||
<div class='bt-form-submit-btn'>\
|
||||
<button type='button' class='btn btn-success btn-sm btn-title class-copy-db-err'>复制</button>\
|
||||
area: ['600px','300px'],
|
||||
btn:['复制错误',"取消"],
|
||||
content:"<form class='bt-form pd15'>\
|
||||
<div class='divtable mtb10'>\
|
||||
<div class='tablescroll'>\
|
||||
<table class='table table-hover' width='100%' cellspacing='0' cellpadding='0' border='0' style='border: 0 none;'>\
|
||||
<thead><tr>\
|
||||
<th style='width:80px;'>类型</th>\
|
||||
<th>内容</th>\
|
||||
</tr></thead>\
|
||||
<tbody>"+ err_line +"</tbody>\
|
||||
</table>\
|
||||
</div>\
|
||||
</div>\
|
||||
</form>",
|
||||
</form>",
|
||||
success:function(){
|
||||
copyText(v['Error']);
|
||||
$('.class-copy-db-err').click(function(){
|
||||
copyText(v['Error']);
|
||||
});
|
||||
// copyText(v['Error']);
|
||||
// $('.class-copy-db-err').click(function(){
|
||||
// copyText(v['Error']);
|
||||
// });
|
||||
},
|
||||
yes:function(){
|
||||
if (info['Last_IO_Error'] != ''){
|
||||
copyText(info['Last_IO_Error']);
|
||||
return;
|
||||
}
|
||||
|
||||
if (info['Last_SQL_Error'] != ''){
|
||||
copyText(info['Last_SQL_Error']);
|
||||
return;
|
||||
}
|
||||
|
||||
if (info['Slave_SQL_Running_State'] != ''){
|
||||
copyText(info['Slave_SQL_Running_State']);
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -2320,14 +2417,12 @@ function masterOrSlaveConf(version=''){
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
function getMasterStatus(){
|
||||
myPost('get_master_status', '', function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
// console.log('mode:',rdata.data);
|
||||
if ( typeof(rdata.status) != 'undefined' && !rdata.status && rdata.data == 'pwd'){
|
||||
layer.msg(rdata.msg, {icon:2});
|
||||
layer.msg(rdata.msg, {icon:2,time:2000});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2409,7 +2504,6 @@ function masterOrSlaveConf(version=''){
|
||||
return false;
|
||||
},
|
||||
change:function(index,mode,reload){
|
||||
console.log(index,mode,reload);
|
||||
myPost('set_dbrun_mode',{'mode':mode,'reload':reload},function(data){
|
||||
layer.close(index);
|
||||
var rdata = $.parseJSON(data.data);
|
||||
@@ -2425,10 +2519,8 @@ function masterOrSlaveConf(version=''){
|
||||
getMasterDbList();
|
||||
}
|
||||
|
||||
// if (rdata.slave_status){
|
||||
getAsyncMasterDbList();
|
||||
getAsyncDataList()
|
||||
// }
|
||||
getAsyncMasterDbList();
|
||||
getAsyncDataList()
|
||||
});
|
||||
}
|
||||
getMasterStatus();
|
||||
|
||||
@@ -71,10 +71,19 @@ Install_app()
|
||||
if [ ! -d ${mariadbDir}/mariadb-${MY_VER} ];then
|
||||
cd ${mariadbDir} && tar -zxvf ${mariadbDir}/mariadb-${MY_VER}.tar.gz
|
||||
fi
|
||||
|
||||
INSTALL_CMD=cmake
|
||||
# check cmake version
|
||||
CMAKE_VERSION=`cmake -version | grep version | awk '{print $3}' | awk -F '.' '{print $1}'`
|
||||
if [ "$CMAKE_VERSION" -eq "2" ];then
|
||||
mkdir -p /var/log/mariadb
|
||||
touch /var/log/mariadb/mariadb.log
|
||||
INSTALL_CMD=cmake3
|
||||
fi
|
||||
|
||||
|
||||
if [ ! -d $serverPath/mariadb ];then
|
||||
cd ${mariadbDir}/mariadb-${MY_VER} && cmake \
|
||||
cd ${mariadbDir}/mariadb-${MY_VER} && ${INSTALL_CMD} \
|
||||
-DCMAKE_INSTALL_PREFIX=$serverPath/mariadb \
|
||||
-DMYSQL_DATADIR=$serverPath/mariadb/data/ \
|
||||
-DMYSQL_USER=mysql \
|
||||
|
||||
@@ -73,8 +73,17 @@ Install_app()
|
||||
fi
|
||||
|
||||
|
||||
INSTALL_CMD=cmake
|
||||
# check cmake version
|
||||
CMAKE_VERSION=`cmake -version | grep version | awk '{print $3}' | awk -F '.' '{print $1}'`
|
||||
if [ "$CMAKE_VERSION" -eq "2" ];then
|
||||
mkdir -p /var/log/mariadb
|
||||
touch /var/log/mariadb/mariadb.log
|
||||
INSTALL_CMD=cmake3
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/mariadb ];then
|
||||
cd ${mariadbDir}/mariadb-${MY_VER} && cmake \
|
||||
cd ${mariadbDir}/mariadb-${MY_VER} && ${INSTALL_CMD} \
|
||||
-DCMAKE_INSTALL_PREFIX=$serverPath/mariadb \
|
||||
-DMYSQL_DATADIR=$serverPath/mariadb/data/ \
|
||||
-DMYSQL_USER=mysql \
|
||||
|
||||
@@ -72,9 +72,17 @@ Install_app()
|
||||
cd ${mariadbDir} && tar -zxvf ${mariadbDir}/mariadb-${MY_VER}.tar.gz
|
||||
fi
|
||||
|
||||
INSTALL_CMD=cmake
|
||||
# check cmake version
|
||||
CMAKE_VERSION=`cmake -version | grep version | awk '{print $3}' | awk -F '.' '{print $1}'`
|
||||
if [ "$CMAKE_VERSION" -eq "2" ];then
|
||||
mkdir -p /var/log/mariadb
|
||||
touch /var/log/mariadb/mariadb.log
|
||||
INSTALL_CMD=cmake3
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/mariadb ];then
|
||||
cd ${mariadbDir}/mariadb-${MY_VER} && cmake \
|
||||
cd ${mariadbDir}/mariadb-${MY_VER} && ${INSTALL_CMD} \
|
||||
-DCMAKE_INSTALL_PREFIX=$serverPath/mariadb \
|
||||
-DMYSQL_DATADIR=$serverPath/mariadb/data/ \
|
||||
-DMYSQL_USER=mysql \
|
||||
|
||||
@@ -14,6 +14,10 @@ if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
import warnings
|
||||
warnings.filterwarnings('ignore', category=DeprecationWarning)
|
||||
|
||||
|
||||
def getPluginName():
|
||||
return 'memcached'
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ port = 27017
|
||||
fork = true
|
||||
auth = false
|
||||
|
||||
# 5.0.2 - Master/slave replication is no longer supported
|
||||
# Master/slave replication is no longer supported
|
||||
#master = true
|
||||
|
||||
pidfilepath = {$SERVER_PATH}/mongodb/mongodb.pid
|
||||
|
||||
+37
-51
@@ -35,13 +35,8 @@ def getInitDFile():
|
||||
|
||||
|
||||
def getConf():
|
||||
if mw.isAppleSystem():
|
||||
path = getServerDir() + "/mongodb.conf"
|
||||
return path
|
||||
|
||||
if os.path.exists("/etc/mongodb.conf"):
|
||||
return "/etc/mongodb.conf"
|
||||
return "/etc/mongod.conf"
|
||||
path = getServerDir() + "/mongodb.conf"
|
||||
return path
|
||||
|
||||
|
||||
def getConfTpl():
|
||||
@@ -90,6 +85,14 @@ def initDreplace():
|
||||
os.mkdir(initD_path)
|
||||
file_bin = initD_path + '/' + getPluginName()
|
||||
|
||||
logs_dir = getServerDir() + '/logs'
|
||||
if not os.path.exists(logs_dir):
|
||||
os.mkdir(logs_dir)
|
||||
|
||||
data_dir = getServerDir() + '/data'
|
||||
if not os.path.exists(data_dir):
|
||||
os.mkdir(data_dir)
|
||||
|
||||
# initd replace
|
||||
content = mw.readFile(file_tpl)
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
@@ -101,6 +104,17 @@ def initDreplace():
|
||||
conf_content = conf_content.replace('{$SERVER_PATH}', service_path)
|
||||
mw.writeFile(getServerDir() + '/mongodb.conf', conf_content)
|
||||
|
||||
# systemd
|
||||
systemDir = mw.systemdCfgDir()
|
||||
systemService = systemDir + '/mongodb.service'
|
||||
systemServiceTpl = getPluginDir() + '/init.d/mongodb.service.tpl'
|
||||
if os.path.exists(systemDir) and not os.path.exists(systemService):
|
||||
service_path = mw.getServerDir()
|
||||
se_content = mw.readFile(systemServiceTpl)
|
||||
se_content = se_content.replace('{$SERVER_PATH}', service_path)
|
||||
mw.writeFile(systemService, se_content)
|
||||
mw.execShell('systemctl daemon-reload')
|
||||
|
||||
return file_bin
|
||||
|
||||
|
||||
@@ -112,14 +126,10 @@ def mgOp(method):
|
||||
return 'ok'
|
||||
return data[1]
|
||||
|
||||
cmd = 'systemctl ' + method + ' mongod'
|
||||
if os.path.exists("/usr/lib/systemd/system/mongodb.service"):
|
||||
cmd = 'systemctl ' + start + ' mongodb'
|
||||
|
||||
data = mw.execShell(cmd)
|
||||
data = mw.execShell('systemctl ' + method + ' ' + getPluginName())
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
return 'fail'
|
||||
|
||||
|
||||
def start():
|
||||
@@ -162,13 +172,7 @@ def runInfo():
|
||||
result["version"] = serverStatus['version']
|
||||
result["uptime"] = serverStatus['uptime']
|
||||
|
||||
result['db_path'] = '/var/lib/mongo'
|
||||
|
||||
if os.path.exists("/var/lib/mongodb"):
|
||||
result['db_path'] = '/var/lib/mongodb'
|
||||
|
||||
if mw.isAppleSystem():
|
||||
result['db_path'] = getServerDir() + "/data"
|
||||
result['db_path'] = getServerDir() + "/data"
|
||||
|
||||
result["connections"] = serverStatus['connections']['current']
|
||||
if 'catalogStats' in serverStatus:
|
||||
@@ -182,11 +186,7 @@ def initdStatus():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
shell_cmd = 'systemctl status mongod | grep loaded | grep "enabled;"'
|
||||
|
||||
if os.path.exists("/usr/lib/systemd/system/mongodb.service"):
|
||||
shell_cmd = 'systemctl status mongodb | grep loaded | grep "enabled;"'
|
||||
|
||||
shell_cmd = 'systemctl status mongodb | grep loaded | grep "enabled;"'
|
||||
data = mw.execShell(shell_cmd)
|
||||
if data[0] == '':
|
||||
return 'fail'
|
||||
@@ -197,10 +197,7 @@ def initdInstall():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
if os.path.exists("/usr/lib/systemd/system/mongodb.service"):
|
||||
mw.execShell('systemctl enable mongodb')
|
||||
else:
|
||||
mw.execShell('systemctl enable mongod')
|
||||
mw.execShell('systemctl enable mongodb')
|
||||
return 'ok'
|
||||
|
||||
|
||||
@@ -208,24 +205,21 @@ def initdUinstall():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
if os.path.exists("/usr/lib/systemd/system/mongodb.service"):
|
||||
mw.execShell('systemctl disable mongodb')
|
||||
else:
|
||||
mw.execShell('systemctl disable mongod')
|
||||
mw.execShell('systemctl disable mongodb')
|
||||
return 'ok'
|
||||
|
||||
|
||||
def runLog():
|
||||
if mw.isAppleSystem():
|
||||
return getServerDir() + '/logs/mongodb.log'
|
||||
|
||||
if os.path.exists("/var/log/mongodb/mongodb.log"):
|
||||
return "/var/log/mongodb/mongodb.log"
|
||||
|
||||
return "/var/log/mongodb/mongod.log"
|
||||
f = getServerDir() + '/logs/mongodb.log'
|
||||
if os.path.exists(f):
|
||||
return f
|
||||
return getServerDir() + '/logs.pl'
|
||||
|
||||
|
||||
def installPreInspection(version):
|
||||
if mw.isAppleSystem():
|
||||
return 'ok'
|
||||
|
||||
sys = mw.execShell(
|
||||
"cat /etc/*-release | grep PRETTY_NAME |awk -F = '{print $2}' | awk -F '\"' '{print $2}'| awk '{print $1}'")
|
||||
|
||||
@@ -238,17 +232,9 @@ def installPreInspection(version):
|
||||
sysName = sys[0].strip().lower()
|
||||
sysId = sys_id[0].strip()
|
||||
|
||||
if not sysName in ('centos', 'fedora', 'ubuntu', 'debian'):
|
||||
return '暂时仅不支持{}'.format(sysName)
|
||||
|
||||
if sysName == 'debian':
|
||||
if version > 10:
|
||||
return 'mongodb[' + version + ']不支持安装在debian[' + sysId + ']'
|
||||
|
||||
if sysName == 'ubuntu':
|
||||
if version < 16:
|
||||
return 'mongodb[' + version + ']不支持安装在ubuntu[' + sysId + ']'
|
||||
|
||||
supportOs = ['centos', 'ubuntu', 'debian', 'opensuse']
|
||||
if not sysName in supportOs:
|
||||
return '暂时仅支持{}'.format(','.join(supportOs))
|
||||
return 'ok'
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
"name": "mongodb",
|
||||
"title": "Mongodb",
|
||||
"shell": "install.sh",
|
||||
"versions":["4.4","5.0"],
|
||||
"updates":["4.4","5.0"],
|
||||
"install_pre_inspection":true,
|
||||
"versions":["4.4","5.0","6.0","7.0"],
|
||||
"tip": "soft",
|
||||
"checks": "server/mongodb",
|
||||
"path": "server/mongodb",
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
[Unit]
|
||||
Description=MongoDB Database Server
|
||||
Documentation=https://docs.mongodb.org/manual
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
User=root
|
||||
Group=root
|
||||
#EnvironmentFile=-/etc/default/mongod
|
||||
Environment="MONGODB_CONFIG_OVERRIDE_NOFORK=1"
|
||||
PIDFile={$SERVER_PATH}/mongodb/mongodb.pid
|
||||
ExecStart={$SERVER_PATH}/mongodb/bin/mongod -f {$SERVER_PATH}/mongodb/mongodb.conf
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
#RuntimeDirectory=mongodb
|
||||
# file size
|
||||
LimitFSIZE=infinity
|
||||
# cpu time
|
||||
LimitCPU=infinity
|
||||
# virtual memory size
|
||||
LimitAS=infinity
|
||||
# open files
|
||||
LimitNOFILE=64000
|
||||
# processes/threads
|
||||
LimitNPROC=64000
|
||||
# locked memory
|
||||
LimitMEMLOCK=infinity
|
||||
# total threads (user+kernel)
|
||||
TasksMax=infinity
|
||||
TasksAccounting=false
|
||||
|
||||
# Recommended limits for mongod as specified in
|
||||
# https://docs.mongodb.com/manual/reference/ulimit/#recommended-ulimit-settings
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -32,6 +32,7 @@ app_start(){
|
||||
echo $EXEC -f $CONF
|
||||
$EXEC -f $CONF >> {$SERVER_PATH}/mongodb/logs.pl 2>&1 &
|
||||
}
|
||||
|
||||
app_stop(){
|
||||
if [ ! -f $PIDFILE ]
|
||||
then
|
||||
@@ -42,10 +43,10 @@ app_stop(){
|
||||
kill -9 $PID
|
||||
while [ -x /proc/${PID} ]
|
||||
do
|
||||
echo "Waiting for Redis to shutdown ..."
|
||||
echo "Waiting for mongodb to shutdown ..."
|
||||
sleep 1
|
||||
done
|
||||
echo "Redis stopped"
|
||||
echo "mongodb stopped"
|
||||
rm -rf $PIDFILE
|
||||
fi
|
||||
}
|
||||
|
||||
Executable
+287
@@ -0,0 +1,287 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
# cd /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/mongodb && /bin/bash install.sh install 5.0.4
|
||||
# cd /www/server/mdserver-web/plugins/mongodb && /bin/bash install.sh install 5.0.4
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
VERSION=$2
|
||||
|
||||
sysName=`uname`
|
||||
echo "use system: ${sysName}"
|
||||
|
||||
bash ${rootPath}/scripts/getos.sh
|
||||
OSNAME=`cat ${rootPath}/data/osname.pl`
|
||||
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
|
||||
|
||||
|
||||
Install_app_mac()
|
||||
{
|
||||
mkdir -p $serverPath/mongodb
|
||||
if [ "$VERSION" == "5.0" ];then
|
||||
G_VERSION="5.0.11"
|
||||
elif [[ "$VERSION" == "4.4" ]]; then
|
||||
G_VERSION="4.4.11"
|
||||
fi
|
||||
|
||||
if [ ! -f $serverPath/source/mongodb-macos-x86_64-${G_VERSION}.tgz ];then
|
||||
wget -O $serverPath/source/mongodb-macos-x86_64-${G_VERSION}.tgz https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-${G_VERSION}.tgz
|
||||
fi
|
||||
|
||||
cd $serverPath/source && tar -zxvf mongodb-macos-x86_64-${G_VERSION}.tgz
|
||||
cd mongodb-macos-x86_64-${G_VERSION} && mv ./* $serverPath/mongodb
|
||||
}
|
||||
|
||||
|
||||
Install_Linux_Ubuntu()
|
||||
{
|
||||
##################### Ubuntu start #####################
|
||||
if [ "$SYS_VERSION_ID" == "22" ]; then
|
||||
echo "Not yet supported"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
echo $SYS_VERSION_ID
|
||||
|
||||
SOURCE_NAME=bionic
|
||||
if [ "$SYS_VERSION_ID" == "18.04" ];then
|
||||
SOURCE_NAME=bionic
|
||||
elif [ "$SYS_VERSION_ID" == "16.04" ];then
|
||||
SOURCE_NAME=xenial
|
||||
elif [ "$SYS_VERSION_ID" == "20.04" ];then
|
||||
SOURCE_NAME=focal
|
||||
fi
|
||||
|
||||
# wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
|
||||
# apt install -y gnupg
|
||||
# touch /etc/apt/sources.list.d/mongodb-org-4.4.list
|
||||
# echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
|
||||
|
||||
|
||||
wget -qO - https://www.mongodb.org/static/pgp/server-${VERSION}.asc | sudo apt-key add -
|
||||
apt install -y gnupg
|
||||
touch /etc/apt/sources.list.d/mongodb-org-${VERSION}.list
|
||||
lsb_release -dc
|
||||
|
||||
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu ${SOURCE_NAME}/mongodb-org/${VERSION} multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-${VERSION}.list
|
||||
|
||||
apt update -y
|
||||
apt install -y mongodb-org
|
||||
##################### Ubuntu end #####################
|
||||
}
|
||||
|
||||
|
||||
Uninstall_Linux_Ubuntu()
|
||||
{
|
||||
|
||||
if [ -f /lib/systemd/system/mongod.service ] || [ -f /usr/lib/systemd/system/mongod.service ] ;then
|
||||
systemctl stop mongod
|
||||
fi
|
||||
|
||||
|
||||
|
||||
apt purge -y mongodb-org*
|
||||
apt autoremove -y
|
||||
rm -r /var/log/mongodb
|
||||
rm -r /var/lib/mongodb
|
||||
}
|
||||
|
||||
|
||||
Install_Linux_Debian()
|
||||
{
|
||||
##################### debian start #####################
|
||||
if [ "$SYS_VERSION_ID" -eq "11" ] && [ "$VERSION" -eq "4.4" ]; then
|
||||
echo "Not yet supported"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
if [ -f /usr/lib/systemd/system/mongod.service ];then
|
||||
echo 'alreay install exist!'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
wget -qO - https://www.mongodb.org/static/pgp/server-${VERSION}.asc | sudo apt-key add -
|
||||
apt install -y gnupg
|
||||
wget -qO - https://www.mongodb.org/static/pgp/server-${VERSION}.asc | sudo apt-key add -
|
||||
|
||||
echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/${VERSION} main" | sudo tee /etc/apt/sources.list.d/mongodb-org-${VERSION}.list
|
||||
|
||||
apt update -y
|
||||
apt install -y mongodb-org
|
||||
|
||||
|
||||
echo "mongodb-org hold" | sudo dpkg --set-selections
|
||||
echo "mongodb-org-server hold" | sudo dpkg --set-selections
|
||||
echo "mongodb-org-shell hold" | sudo dpkg --set-selections
|
||||
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
|
||||
echo "mongodb-org-tools hold" | sudo dpkg --set-selections
|
||||
|
||||
##################### debian end #####################
|
||||
}
|
||||
|
||||
|
||||
|
||||
Uninstall_Linux_Debian()
|
||||
{
|
||||
systemctl stop mongod
|
||||
apt purge -y mongodb-org*
|
||||
apt autoremove -y
|
||||
rm -r /var/log/mongodb
|
||||
rm -r /var/lib/mongodb
|
||||
}
|
||||
|
||||
|
||||
Install_Linux_Opensuse()
|
||||
{
|
||||
##################### opensuse start #####################
|
||||
if [ "$SYS_VERSION_ID" -gt "15" ]; then
|
||||
echo "Not yet supported"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
if [ -f /usr/lib/systemd/system/mongod.service ];then
|
||||
echo 'alreay exist!'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
rpm --import https://www.mongodb.org/static/pgp/server-${VERSION}.asc
|
||||
zypper addrepo --gpgcheck "https://repo.mongodb.org/zypper/suse/15/mongodb-org/${VERSION}/x86_64/" mongodb
|
||||
zypper -n install mongodb-org
|
||||
# zypper install mongodb-org-4.4.15 mongodb-org-server-4.4.15 mongodb-org-shell-4.4.15 mongodb-org-mongos-4.4.15 mongodb-org-tools-4.4.15
|
||||
|
||||
|
||||
##################### opensuse end #####################
|
||||
}
|
||||
|
||||
|
||||
Uninstall_Linux_Opensuse()
|
||||
{
|
||||
systemctl stop mongod
|
||||
zypper remove -y $(rpm -qa | grep mongodb-org)
|
||||
rm -r /var/log/mongodb
|
||||
rm -r /var/lib/mongo
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
# https://repo.mongodb.org/yum/redhat/7/mongodb-org/5.0/x86_64/RPMS/mongodb-org-server-5.0.4-1.el7.x86_64.rpm
|
||||
Install_Linux_CentOS()
|
||||
{
|
||||
if [ -f /usr/lib/systemd/system/mongod.service ];then
|
||||
echo 'alreay exist!'
|
||||
exit 0
|
||||
fi
|
||||
#清空mongo的repo源
|
||||
rm -rf /etc/yum.repos.d/mongodb-org-*
|
||||
##################### centos start #####################
|
||||
echo "
|
||||
[mongodb-org-${VERSION}]
|
||||
name=MongoDB Repository
|
||||
baseurl=https://repo.mongodb.org/yum/redhat/\$releasever/mongodb-org/${VERSION}/x86_64/
|
||||
gpgcheck=1
|
||||
enabled=1
|
||||
gpgkey=https://www.mongodb.org/static/pgp/server-${VERSION}.asc
|
||||
" > /etc/yum.repos.d/mongodb-org-${VERSION}.repo
|
||||
|
||||
yum install -y mongodb-org
|
||||
##################### centos end #####################
|
||||
}
|
||||
|
||||
Uninstall_Linux_CentOS()
|
||||
{
|
||||
systemctl stop mongod
|
||||
yum erase -y $(rpm -qa | grep mongodb-org)
|
||||
rm -r /var/log/mongodb
|
||||
rm -r /var/lib/mongo
|
||||
rm -rf /etc/yum.repos.d/mongodb-org-${VERSION}.repo
|
||||
}
|
||||
|
||||
|
||||
Install_app_linux()
|
||||
{
|
||||
if [ "$OSNAME" == "ubuntu" ];then
|
||||
Install_Linux_Ubuntu
|
||||
elif [ "$OSNAME" == "debian" ];then
|
||||
Install_Linux_Debian
|
||||
elif [ "$OSNAME" == "centos" ];then
|
||||
Install_Linux_CentOS
|
||||
elif [ "$OSNAME" == "opensuse" ];then
|
||||
Install_Linux_Opensuse
|
||||
else
|
||||
echo "Not yet supported"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Install_app()
|
||||
{
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
mkdir -p $serverPath/source
|
||||
|
||||
if [ "macos" == "$OSNAME" ];then
|
||||
Install_app_mac
|
||||
else
|
||||
Install_app_linux
|
||||
fi
|
||||
|
||||
if [ "$?" == "0" ];then
|
||||
mkdir -p $serverPath/mongodb
|
||||
echo "${VERSION}" > $serverPath/mongodb/version.pl
|
||||
echo '安装完成' > $install_tmp
|
||||
|
||||
#初始化
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/mongodb/index.py start
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/mongodb/index.py initd_install
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
Uninstall_app_linux()
|
||||
{
|
||||
##################
|
||||
if [ "$OSNAME" == "ubuntu" ];then
|
||||
Uninstall_Linux_Ubuntu
|
||||
elif [ "$OSNAME" == "debian" ];then
|
||||
Uninstall_Linux_Debian
|
||||
elif [ "$OSNAME" == "centos" ];then
|
||||
Uninstall_Linux_CentOS
|
||||
elif [ "$OSNAME" == "opensuse" ];then
|
||||
Uninstall_Linux_Opensuse
|
||||
else
|
||||
echo "ok"
|
||||
fi
|
||||
##################
|
||||
}
|
||||
|
||||
Uninstall_app()
|
||||
{
|
||||
if [ "macos" == "$OSNAME" ];then
|
||||
echo 'mac'
|
||||
else
|
||||
Uninstall_app_linux
|
||||
fi
|
||||
|
||||
rm -rf $serverPath/mongodb
|
||||
echo "Uninstall_mongodb" > $install_tmp
|
||||
}
|
||||
|
||||
action=$1
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_app
|
||||
else
|
||||
Uninstall_app
|
||||
fi
|
||||
Executable
+107
@@ -0,0 +1,107 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
# cd /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/mongodb && /bin/bash install.sh install 5.0.4
|
||||
# cd /www/server/mdserver-web/plugins/mongodb && /bin/bash install.sh install 5.0.4
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
VERSION=$2
|
||||
|
||||
sysName=`uname`
|
||||
echo "use system: ${sysName}"
|
||||
|
||||
# bash ${rootPath}/scripts/getos.sh
|
||||
# OSNAME=`cat ${rootPath}/data/osname.pl`
|
||||
# SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
|
||||
|
||||
|
||||
Install_app()
|
||||
{
|
||||
# ----- 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
|
||||
|
||||
if [ "$cpuCore" -gt "2" ];then
|
||||
cpuCore=`echo "$cpuCore" | awk '{printf("%.f",($1)*0.8)}'`
|
||||
else
|
||||
cpuCore="1"
|
||||
fi
|
||||
# ----- cpu end ------
|
||||
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
MG_DIR=$serverPath/source/mongodb
|
||||
mkdir -p $MG_DIR
|
||||
|
||||
cd ${rootPath}/plugins/php/lib && /bin/bash openssl.sh
|
||||
echo "cd ${rootPath}/plugins/php/lib && /bin/bash openssl.sh"
|
||||
export PKG_CONFIG_PATH=$serverPath/lib/openssl/lib/pkgconfig
|
||||
|
||||
if [ ! -f $MG_DIR/mongodb-src-r${VERSION}.tar.gz ]; then
|
||||
wget --no-check-certificate -O $MG_DIR/mongodb-src-r${VERSION}.tar.gz https://fastdl.mongodb.org/src/mongodb-src-r${VERSION}.tar.gz
|
||||
echo "wget --no-check-certificate -O $MG_DIR/mongodb-src-r${VERSION}.tar.gz https://fastdl.mongodb.org/src/mongodb-src-r${VERSION}.tar.gz"
|
||||
fi
|
||||
|
||||
if [ ! -d $MG_DIR/mongodb-src-r${VERSION} ];then
|
||||
cd $MG_DIR && tar -zxvf $MG_DIR/mongodb-src-r${VERSION}.tar.gz
|
||||
fi
|
||||
|
||||
cd $MG_DIR/mongodb-src-r${VERSION} && python3 -m pip install requirements_parser
|
||||
cd $MG_DIR/mongodb-src-r${VERSION} && python3 -m pip install -r etc/pip/compile-requirements.txt
|
||||
|
||||
# cd $MG_DIR/mongodb-src-r${VERSION} && python3 buildscripts/scons.py all -j 2
|
||||
# echo "cd $MG_DIR/mongodb-src-r${VERSION} && python3 buildscripts/scons.py all -j 2"
|
||||
# cd $MG_DIR/mongodb-src-r${VERSION} && python3 buildscripts/scons.py all MONGO_VERSION=${VERSION} -j 4
|
||||
|
||||
|
||||
cd $MG_DIR/mongodb-src-r${VERSION} && python3 buildscripts/scons.py install-mongod MONGO_VERSION=${VERSION} -j ${cpuCore}
|
||||
cd $MG_DIR/mongodb-src-r${VERSION} && python3 buildscripts/scons.py DESTDIR=$serverPath/mongodb install-mongod MONGO_VERSION=${VERSION} \
|
||||
--ssl=off
|
||||
echo "cd $MG_DIR/mongodb-src-r${VERSION} && python3 buildscripts/scons.py DESTDIR=$serverPath/mongodb install MONGO_VERSION=${VERSION} \
|
||||
--ssl=off CPPPATH=$serverPath/lib/openssl/include \
|
||||
LIBPATH=$serverPath/lib/openssl/lib"
|
||||
|
||||
if [ "$?" == "0" ];then
|
||||
mkdir -p $serverPath/mongodb
|
||||
echo "${VERSION}" > $serverPath/mongodb/version.pl
|
||||
echo '安装完成' > $install_tmp
|
||||
|
||||
#初始化
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/mongodb/index.py start
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/mongodb/index.py initd_install
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Uninstall_app()
|
||||
{
|
||||
|
||||
rm -rf $serverPath/mongodb
|
||||
echo "Uninstall_mongodb" > $install_tmp
|
||||
}
|
||||
|
||||
action=$1
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_app
|
||||
else
|
||||
Uninstall_app
|
||||
fi
|
||||
+51
-240
@@ -2,8 +2,15 @@
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
# cd /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/mongodb && /bin/bash install.sh install 5.0.4
|
||||
# cd /www/server/mdserver-web/plugins/mongodb && /bin/bash install.sh install 5.0.4
|
||||
# https://www.mongodb.com/try/download/community
|
||||
|
||||
'''
|
||||
cd /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/mongodb && /bin/bash install.sh install 5.0.4
|
||||
cd /www/server/mdserver-web/plugins/mongodb && /bin/bash install.sh install 7.0
|
||||
|
||||
cd /www/server/mdserver-web && python3 /www/server/mdserver-web/plugins/mongodb/index.py start
|
||||
'''
|
||||
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
@@ -16,230 +23,48 @@ VERSION=$2
|
||||
sysName=`uname`
|
||||
echo "use system: ${sysName}"
|
||||
|
||||
bash ${rootPath}/scripts/getos.sh
|
||||
OSNAME=`cat ${rootPath}/data/osname.pl`
|
||||
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
|
||||
OSNAME=`bash ${rootPath}/scripts/getos.sh`
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Install_app_mac()
|
||||
{
|
||||
mkdir -p $serverPath/mongodb
|
||||
if [ "$VERSION" == "5.0" ];then
|
||||
G_VERSION="5.0.11"
|
||||
elif [[ "$VERSION" == "4.4" ]]; then
|
||||
G_VERSION="4.4.11"
|
||||
fi
|
||||
|
||||
if [ ! -f $serverPath/source/mongodb-macos-x86_64-${G_VERSION}.tgz ];then
|
||||
wget -O $serverPath/source/mongodb-macos-x86_64-${G_VERSION}.tgz https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-${G_VERSION}.tgz
|
||||
fi
|
||||
|
||||
cd $serverPath/source && tar -zxvf mongodb-macos-x86_64-${G_VERSION}.tgz
|
||||
cd mongodb-macos-x86_64-${G_VERSION} && mv ./* $serverPath/mongodb
|
||||
}
|
||||
|
||||
|
||||
Install_Linux_Ubuntu()
|
||||
{
|
||||
##################### Ubuntu start #####################
|
||||
if [ "$SYS_VERSION_ID" == "22" ]; then
|
||||
echo "Not yet supported"
|
||||
exit 1
|
||||
if [ "" == "$OSNAME" ];then
|
||||
OSNAME=`cat ${rootPath}/data/osname.pl`
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
echo $SYS_VERSION_ID
|
||||
|
||||
SOURCE_NAME=bionic
|
||||
if [ "$SYS_VERSION_ID" == "18.04" ];then
|
||||
SOURCE_NAME=bionic
|
||||
elif [ "$SYS_VERSION_ID" == "16.04" ];then
|
||||
SOURCE_NAME=xenial
|
||||
elif [ "$SYS_VERSION_ID" == "20.04" ];then
|
||||
SOURCE_NAME=focal
|
||||
if [ "macos" != "$OSNAME" ];then
|
||||
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
|
||||
fi
|
||||
|
||||
# wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
|
||||
# apt install -y gnupg
|
||||
# touch /etc/apt/sources.list.d/mongodb-org-4.4.list
|
||||
# echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
|
||||
|
||||
|
||||
wget -qO - https://www.mongodb.org/static/pgp/server-${VERSION}.asc | sudo apt-key add -
|
||||
apt install -y gnupg
|
||||
touch /etc/apt/sources.list.d/mongodb-org-${VERSION}.list
|
||||
lsb_release -dc
|
||||
|
||||
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu ${SOURCE_NAME}/mongodb-org/${VERSION} multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-${VERSION}.list
|
||||
|
||||
apt update -y
|
||||
apt install -y mongodb-org
|
||||
##################### Ubuntu end #####################
|
||||
}
|
||||
|
||||
|
||||
Uninstall_Linux_Ubuntu()
|
||||
{
|
||||
|
||||
if [ -f /lib/systemd/system/mongod.service ] || [ -f /usr/lib/systemd/system/mongod.service ] ;then
|
||||
systemctl stop mongod
|
||||
fi
|
||||
|
||||
|
||||
|
||||
apt purge -y mongodb-org*
|
||||
apt autoremove -y
|
||||
rm -r /var/log/mongodb
|
||||
rm -r /var/lib/mongodb
|
||||
}
|
||||
|
||||
|
||||
Install_Linux_Debian()
|
||||
{
|
||||
##################### debian start #####################
|
||||
if [ "$SYS_VERSION_ID" -eq "11" ] && [ "$VERSION" -eq "4.4" ]; then
|
||||
echo "Not yet supported"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
if [ -f /usr/lib/systemd/system/mongod.service ];then
|
||||
echo 'alreay install exist!'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
wget -qO - https://www.mongodb.org/static/pgp/server-${VERSION}.asc | sudo apt-key add -
|
||||
apt install -y gnupg
|
||||
wget -qO - https://www.mongodb.org/static/pgp/server-${VERSION}.asc | sudo apt-key add -
|
||||
|
||||
echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/${VERSION} main" | sudo tee /etc/apt/sources.list.d/mongodb-org-${VERSION}.list
|
||||
|
||||
apt update -y
|
||||
apt install -y mongodb-org
|
||||
|
||||
|
||||
echo "mongodb-org hold" | sudo dpkg --set-selections
|
||||
echo "mongodb-org-server hold" | sudo dpkg --set-selections
|
||||
echo "mongodb-org-shell hold" | sudo dpkg --set-selections
|
||||
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
|
||||
echo "mongodb-org-tools hold" | sudo dpkg --set-selections
|
||||
|
||||
##################### debian end #####################
|
||||
}
|
||||
|
||||
|
||||
|
||||
Uninstall_Linux_Debian()
|
||||
{
|
||||
systemctl stop mongod
|
||||
apt purge -y mongodb-org*
|
||||
apt autoremove -y
|
||||
rm -r /var/log/mongodb
|
||||
rm -r /var/lib/mongodb
|
||||
}
|
||||
|
||||
|
||||
Install_Linux_Opensuse()
|
||||
{
|
||||
##################### opensuse start #####################
|
||||
if [ "$SYS_VERSION_ID" -gt "15" ]; then
|
||||
echo "Not yet supported"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
if [ -f /usr/lib/systemd/system/mongod.service ];then
|
||||
echo 'alreay exist!'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
rpm --import https://www.mongodb.org/static/pgp/server-${VERSION}.asc
|
||||
zypper addrepo --gpgcheck "https://repo.mongodb.org/zypper/suse/15/mongodb-org/${VERSION}/x86_64/" mongodb
|
||||
zypper -n install mongodb-org
|
||||
# zypper install mongodb-org-4.4.15 mongodb-org-server-4.4.15 mongodb-org-shell-4.4.15 mongodb-org-mongos-4.4.15 mongodb-org-tools-4.4.15
|
||||
|
||||
|
||||
##################### opensuse end #####################
|
||||
}
|
||||
|
||||
|
||||
Uninstall_Linux_Opensuse()
|
||||
{
|
||||
systemctl stop mongod
|
||||
zypper remove -y $(rpm -qa | grep mongodb-org)
|
||||
rm -r /var/log/mongodb
|
||||
rm -r /var/lib/mongo
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
# https://repo.mongodb.org/yum/redhat/7/mongodb-org/5.0/x86_64/RPMS/mongodb-org-server-5.0.4-1.el7.x86_64.rpm
|
||||
Install_Linux_CentOS()
|
||||
{
|
||||
if [ -f /usr/lib/systemd/system/mongod.service ];then
|
||||
echo 'alreay exist!'
|
||||
exit 0
|
||||
fi
|
||||
#清空mongo的repo源
|
||||
rm -rf /etc/yum.repos.d/mongodb-org-*
|
||||
##################### centos start #####################
|
||||
echo "
|
||||
[mongodb-org-${VERSION}]
|
||||
name=MongoDB Repository
|
||||
baseurl=https://repo.mongodb.org/yum/redhat/\$releasever/mongodb-org/${VERSION}/x86_64/
|
||||
gpgcheck=1
|
||||
enabled=1
|
||||
gpgkey=https://www.mongodb.org/static/pgp/server-${VERSION}.asc
|
||||
" > /etc/yum.repos.d/mongodb-org-${VERSION}.repo
|
||||
|
||||
yum install -y mongodb-org
|
||||
##################### centos end #####################
|
||||
}
|
||||
|
||||
Uninstall_Linux_CentOS()
|
||||
{
|
||||
systemctl stop mongod
|
||||
yum erase -y $(rpm -qa | grep mongodb-org)
|
||||
rm -r /var/log/mongodb
|
||||
rm -r /var/lib/mongo
|
||||
rm -rf /etc/yum.repos.d/mongodb-org-${VERSION}.repo
|
||||
}
|
||||
|
||||
|
||||
Install_app_linux()
|
||||
{
|
||||
if [ "$OSNAME" == "ubuntu" ];then
|
||||
Install_Linux_Ubuntu
|
||||
elif [ "$OSNAME" == "debian" ];then
|
||||
Install_Linux_Debian
|
||||
elif [ "$OSNAME" == "centos" ];then
|
||||
Install_Linux_CentOS
|
||||
elif [ "$OSNAME" == "opensuse" ];then
|
||||
Install_Linux_Opensuse
|
||||
else
|
||||
echo "Not yet supported"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Install_app()
|
||||
{
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
mkdir -p $serverPath/source
|
||||
|
||||
if [ "macos" == "$OSNAME" ];then
|
||||
Install_app_mac
|
||||
|
||||
# if id mongodb &> /dev/null ;then
|
||||
# echo "mongodb uid is `id -u mongodb`"
|
||||
# echo "mongodb shell is `grep "^mongodb:" /etc/passwd |cut -d':' -f7 `"
|
||||
# else
|
||||
# groupadd mongodb
|
||||
# useradd -g mongodb mongodb
|
||||
# fi
|
||||
|
||||
# if [ "centos" == "$OSNAME" ];then
|
||||
# OSNAME=rhel
|
||||
# fi
|
||||
|
||||
# if [ "fedora" == "$OSNAME" ];then
|
||||
# OSNAME=rhel
|
||||
# fi
|
||||
|
||||
# if [ "rocky" == "$OSNAME" ];then
|
||||
# OSNAME=rhel
|
||||
# fi
|
||||
|
||||
shell_file=${curPath}/versions/${VERSION}/${OSNAME}.sh
|
||||
|
||||
if [ -f $shell_file ];then
|
||||
bash -x $shell_file
|
||||
else
|
||||
Install_app_linux
|
||||
echo '不支持...' > $install_tmp
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$?" == "0" ];then
|
||||
@@ -253,34 +78,20 @@ Install_app()
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
Uninstall_app_linux()
|
||||
{
|
||||
##################
|
||||
if [ "$OSNAME" == "ubuntu" ];then
|
||||
Uninstall_Linux_Ubuntu
|
||||
elif [ "$OSNAME" == "debian" ];then
|
||||
Uninstall_Linux_Debian
|
||||
elif [ "$OSNAME" == "centos" ];then
|
||||
Uninstall_Linux_CentOS
|
||||
elif [ "$OSNAME" == "opensuse" ];then
|
||||
Uninstall_Linux_Opensuse
|
||||
else
|
||||
echo "ok"
|
||||
fi
|
||||
##################
|
||||
}
|
||||
|
||||
Uninstall_app()
|
||||
{
|
||||
if [ "macos" == "$OSNAME" ];then
|
||||
echo 'mac'
|
||||
else
|
||||
Uninstall_app_linux
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/mongodb/index.py stop
|
||||
rm -rf $serverPath/mongodb
|
||||
|
||||
|
||||
if [ -f /usr/lib/systemd/system/mongodb.service ] || [ -f /lib/systemd/system/mongodb.service ];then
|
||||
systemctl stop mongodb
|
||||
systemctl disable mongodb
|
||||
rm -rf /usr/lib/systemd/system/mongodb.service
|
||||
rm -rf /lib/systemd/system/mongodb.service
|
||||
systemctl daemon-reload
|
||||
fi
|
||||
|
||||
rm -rf $serverPath/mongodb
|
||||
echo "Uninstall_mongodb" > $install_tmp
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
#!/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
|
||||
VERSION=4.4.23
|
||||
SYS_ARCH=`arch`
|
||||
|
||||
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
|
||||
SYS_NAME=${SYS_VERSION_ID/./}
|
||||
SYS_NAME_LEN=`echo "$SYS_NAME" | wc -L`
|
||||
|
||||
if [ "$SYS_NAME_LEN" == "1" ];then
|
||||
SYS_NAME=${SYS_NAME}0
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -gt "82" ];then
|
||||
SYS_NAME="82"
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -lt "62" ];then
|
||||
SYS_NAME="62"
|
||||
fi
|
||||
|
||||
# https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.4.23.tgz
|
||||
# https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel80-4.4.23.tgz
|
||||
# https://fastdl.mongodb.org/linux/mongodb-linux-aarch64-rhel82-4.4.23.tgz
|
||||
|
||||
MG_DIR=$serverPath/source/mongodb
|
||||
mkdir -p $MG_DIR
|
||||
|
||||
FILE_NAME=mongodb-linux-${SYS_ARCH}-rhel${SYS_NAME}-${VERSION}
|
||||
FILE_NAME_TGZ=${FILE_NAME}.tgz
|
||||
|
||||
if [ ! -f $MG_DIR/${FILE_NAME_TGZ} ]; then
|
||||
wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}
|
||||
echo "wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}"
|
||||
fi
|
||||
|
||||
if [ ! -d $MG_DIR/${FILE_NAME} ];then
|
||||
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/mongodb/bin ];then
|
||||
mkdir -p $serverPath/mongodb
|
||||
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
|
||||
fi
|
||||
@@ -0,0 +1,43 @@
|
||||
#!/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
|
||||
VERSION=4.4.23
|
||||
SYS_ARCH=`arch`
|
||||
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
|
||||
SYS_NAME=${SYS_VERSION_ID/./}
|
||||
|
||||
if [ "$SYS_NAME" -gt "10" ];then
|
||||
SYS_NAME="10"
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -lt "10" ];then
|
||||
SYS_NAME="10"
|
||||
fi
|
||||
|
||||
FILE_NAME=mongodb-linux-${SYS_ARCH}-debian${SYS_NAME}-${VERSION}
|
||||
FILE_NAME_TGZ=${FILE_NAME}.tgz
|
||||
|
||||
|
||||
MG_DIR=$serverPath/source/mongodb
|
||||
mkdir -p $MG_DIR
|
||||
|
||||
if [ ! -f $MG_DIR/${FILE_NAME_TGZ} ]; then
|
||||
wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}
|
||||
echo "wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}"
|
||||
fi
|
||||
|
||||
if [ ! -d $MG_DIR/${FILE_NAME_TGZ} ];then
|
||||
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/mongodb/bin ];then
|
||||
mkdir -p $serverPath/mongodb
|
||||
cd $MG_DIR/${FILE_NAME}} && cp -rf ./bin $serverPath/mongodb
|
||||
fi
|
||||
@@ -0,0 +1,28 @@
|
||||
#!/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
|
||||
VERSION=4.4.23
|
||||
|
||||
MG_DIR=$serverPath/source/mongodb
|
||||
mkdir -p $MG_DIR
|
||||
|
||||
if [ ! -f $MG_DIR/mongodb-macos-x86_64-${VERSION}.tgz ]; then
|
||||
wget --no-check-certificate -O $MG_DIR/mongodb-macos-x86_64-${VERSION}.tgz https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-${VERSION}.tgz
|
||||
echo "wget --no-check-certificate -O $MG_DIR/mongodb-macos-x86_64-${VERSION}.tgz https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-${VERSION}.tgz"
|
||||
fi
|
||||
|
||||
if [ ! -d $MG_DIR/mongodb-macos-x86_64-${VERSION} ];then
|
||||
cd $MG_DIR && tar -zxvf mongodb-macos-x86_64-${VERSION}.tgz
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/mongodb/bin ];then
|
||||
mkdir -p $serverPath/mongodb
|
||||
cd $MG_DIR/mongodb-macos-x86_64-${VERSION} && cp -rf ./bin $serverPath/mongodb
|
||||
fi
|
||||
@@ -0,0 +1,46 @@
|
||||
#!/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
|
||||
VERSION=4.4.23
|
||||
SYS_ARCH=`arch`
|
||||
|
||||
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}' | awk -F . '{print $1}'`
|
||||
|
||||
SYS_NAME="15"
|
||||
if [ "$SYS_VERSION_ID" -gt "15" ];then
|
||||
SYS_NAME="15"
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -lt "12" ];then
|
||||
SYS_NAME="12"
|
||||
fi
|
||||
|
||||
# https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-suse15-4.4.23.tgz
|
||||
# https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-suse12-4.4.23.tgz
|
||||
|
||||
MG_DIR=$serverPath/source/mongodb
|
||||
mkdir -p $MG_DIR
|
||||
|
||||
FILE_NAME=mongodb-linux-${SYS_ARCH}-suse${SYS_NAME}-${VERSION}
|
||||
FILE_NAME_TGZ=${FILE_NAME}.tgz
|
||||
|
||||
if [ ! -f $MG_DIR/${FILE_NAME_TGZ} ]; then
|
||||
wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}
|
||||
echo "wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}"
|
||||
fi
|
||||
|
||||
if [ ! -d $MG_DIR/${FILE_NAME} ];then
|
||||
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/mongodb/bin ];then
|
||||
mkdir -p $serverPath/mongodb
|
||||
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
|
||||
fi
|
||||
@@ -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
|
||||
VERSION=4.4.23
|
||||
SYS_ARCH=`arch`
|
||||
|
||||
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
|
||||
SYS_NAME=${SYS_VERSION_ID/./}
|
||||
SYS_NAME_LEN=`echo "$SYS_NAME" | wc -L`
|
||||
|
||||
if [ "$SYS_NAME_LEN" == "1" ];then
|
||||
SYS_NAME=${SYS_NAME}0
|
||||
fi
|
||||
|
||||
# https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.4.23.tgz
|
||||
|
||||
MG_DIR=$serverPath/source/mongodb
|
||||
mkdir -p $MG_DIR
|
||||
|
||||
FILE_NAME=mongodb-linux-${SYS_ARCH}-ubuntu${SYS_NAME}-${VERSION}
|
||||
FILE_NAME_TGZ=${FILE_NAME}.tgz
|
||||
|
||||
if [ ! -f $MG_DIR/${FILE_NAME_TGZ} ]; then
|
||||
wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}
|
||||
echo "wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}"
|
||||
fi
|
||||
|
||||
if [ ! -d $MG_DIR/${FILE_NAME} ];then
|
||||
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/mongodb/bin ];then
|
||||
mkdir -p $serverPath/mongodb
|
||||
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
|
||||
fi
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/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
|
||||
VERSION=4.4.23
|
||||
SYS_ARCH=`arch`
|
||||
|
||||
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
|
||||
SYS_NAME=${SYS_VERSION_ID/./}
|
||||
# https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2004-4.4.23.tgz
|
||||
|
||||
if [ "$SYS_NAME" -gt "2004" ];then
|
||||
SYS_NAME="2004"
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -lt "1604" ];then
|
||||
SYS_NAME="1604"
|
||||
fi
|
||||
|
||||
MG_DIR=$serverPath/source/mongodb
|
||||
mkdir -p $MG_DIR
|
||||
|
||||
FILE_NAME=mongodb-linux-${SYS_ARCH}-ubuntu${SYS_NAME}-${VERSION}
|
||||
FILE_NAME_TGZ=${FILE_NAME}.tgz
|
||||
|
||||
if [ ! -f $MG_DIR/${FILE_NAME_TGZ} ]; then
|
||||
wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}
|
||||
echo "wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}"
|
||||
fi
|
||||
|
||||
if [ ! -d $MG_DIR/${FILE_NAME} ];then
|
||||
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/mongodb/bin ];then
|
||||
mkdir -p $serverPath/mongodb
|
||||
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
|
||||
fi
|
||||
@@ -0,0 +1,48 @@
|
||||
#!/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
|
||||
VERSION=5.0.20
|
||||
SYS_ARCH=`arch`
|
||||
|
||||
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
|
||||
SYS_NAME=${SYS_VERSION_ID/./}
|
||||
SYS_NAME_LEN=`echo "$SYS_NAME" | wc -L`
|
||||
|
||||
if [ "$SYS_NAME_LEN" == "1" ];then
|
||||
SYS_NAME=${SYS_NAME}0
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -gt "82" ];then
|
||||
SYS_NAME="82"
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -lt "70" ];then
|
||||
SYS_NAME="70"
|
||||
fi
|
||||
|
||||
MG_DIR=$serverPath/source/mongodb
|
||||
mkdir -p $MG_DIR
|
||||
|
||||
FILE_NAME=mongodb-linux-${SYS_ARCH}-rhel${SYS_NAME}-${VERSION}
|
||||
FILE_NAME_TGZ=${FILE_NAME}.tgz
|
||||
|
||||
if [ ! -f $MG_DIR/${FILE_NAME_TGZ} ]; then
|
||||
wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}
|
||||
echo "wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}"
|
||||
fi
|
||||
|
||||
if [ ! -d $MG_DIR/${FILE_NAME} ];then
|
||||
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/mongodb/bin ];then
|
||||
mkdir -p $serverPath/mongodb
|
||||
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
|
||||
fi
|
||||
@@ -0,0 +1,43 @@
|
||||
#!/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
|
||||
VERSION=5.0.20
|
||||
SYS_ARCH=`arch`
|
||||
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
|
||||
SYS_NAME=${SYS_VERSION_ID/./}
|
||||
|
||||
if [ "$SYS_NAME" -gt "11" ];then
|
||||
SYS_NAME="11"
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -lt "10" ];then
|
||||
SYS_NAME="10"
|
||||
fi
|
||||
|
||||
FILE_NAME=mongodb-linux-${SYS_ARCH}-debian${SYS_NAME}-${VERSION}
|
||||
FILE_NAME_TGZ=${FILE_NAME}.tgz
|
||||
|
||||
|
||||
MG_DIR=$serverPath/source/mongodb
|
||||
mkdir -p $MG_DIR
|
||||
|
||||
if [ ! -f $MG_DIR/${FILE_NAME_TGZ} ]; then
|
||||
wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}
|
||||
echo "wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}"
|
||||
fi
|
||||
|
||||
if [ ! -d $MG_DIR/${FILE_NAME_TGZ} ];then
|
||||
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/mongodb/bin ];then
|
||||
mkdir -p $serverPath/mongodb
|
||||
cd $MG_DIR/${FILE_NAME}} && cp -rf ./bin $serverPath/mongodb
|
||||
fi
|
||||
@@ -0,0 +1,28 @@
|
||||
#!/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
|
||||
VERSION=5.0.20
|
||||
|
||||
MG_DIR=$serverPath/source/mongodb
|
||||
mkdir -p $MG_DIR
|
||||
|
||||
if [ ! -f $MG_DIR/mongodb-macos-x86_64-${VERSION}.tgz ]; then
|
||||
wget --no-check-certificate -O $MG_DIR/mongodb-macos-x86_64-${VERSION}.tgz https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-${VERSION}.tgz
|
||||
echo "wget --no-check-certificate -O $MG_DIR/mongodb-macos-x86_64-${VERSION}.tgz https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-${VERSION}.tgz"
|
||||
fi
|
||||
|
||||
if [ ! -d $MG_DIR/mongodb-macos-x86_64-${VERSION} ];then
|
||||
cd $MG_DIR && tar -zxvf mongodb-macos-x86_64-${VERSION}.tgz
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/mongodb/bin ];then
|
||||
mkdir -p $serverPath/mongodb
|
||||
cd $MG_DIR/mongodb-macos-x86_64-${VERSION} && cp -rf ./bin $serverPath/mongodb
|
||||
fi
|
||||
@@ -0,0 +1,46 @@
|
||||
#!/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
|
||||
VERSION=5.0.20
|
||||
SYS_ARCH=`arch`
|
||||
|
||||
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}' | awk -F . '{print $1}'`
|
||||
|
||||
SYS_NAME="15"
|
||||
if [ "$SYS_VERSION_ID" -gt "15" ];then
|
||||
SYS_NAME="15"
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -lt "12" ];then
|
||||
SYS_NAME="12"
|
||||
fi
|
||||
|
||||
# https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-suse15-4.4.23.tgz
|
||||
# https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-suse12-4.4.23.tgz
|
||||
|
||||
MG_DIR=$serverPath/source/mongodb
|
||||
mkdir -p $MG_DIR
|
||||
|
||||
FILE_NAME=mongodb-linux-${SYS_ARCH}-suse${SYS_NAME}-${VERSION}
|
||||
FILE_NAME_TGZ=${FILE_NAME}.tgz
|
||||
|
||||
if [ ! -f $MG_DIR/${FILE_NAME_TGZ} ]; then
|
||||
wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}
|
||||
echo "wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}"
|
||||
fi
|
||||
|
||||
if [ ! -d $MG_DIR/${FILE_NAME} ];then
|
||||
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/mongodb/bin ];then
|
||||
mkdir -p $serverPath/mongodb
|
||||
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
|
||||
fi
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/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
|
||||
VERSION=5.0.20
|
||||
SYS_ARCH=`arch`
|
||||
|
||||
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
|
||||
SYS_NAME=${SYS_VERSION_ID/./}
|
||||
# https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2004-4.4.23.tgz
|
||||
|
||||
if [ "$SYS_NAME" -gt "2004" ];then
|
||||
SYS_NAME="2004"
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -lt "1804" ];then
|
||||
SYS_NAME="1804"
|
||||
fi
|
||||
|
||||
MG_DIR=$serverPath/source/mongodb
|
||||
mkdir -p $MG_DIR
|
||||
|
||||
FILE_NAME=mongodb-linux-${SYS_ARCH}-ubuntu${SYS_NAME}-${VERSION}
|
||||
FILE_NAME_TGZ=${FILE_NAME}.tgz
|
||||
|
||||
if [ ! -f $MG_DIR/${FILE_NAME_TGZ} ]; then
|
||||
wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}
|
||||
echo "wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}"
|
||||
fi
|
||||
|
||||
if [ ! -d $MG_DIR/${FILE_NAME} ];then
|
||||
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/mongodb/bin ];then
|
||||
mkdir -p $serverPath/mongodb
|
||||
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
|
||||
fi
|
||||
@@ -0,0 +1,48 @@
|
||||
#!/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
|
||||
VERSION=6.0.9
|
||||
SYS_ARCH=`arch`
|
||||
|
||||
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
|
||||
SYS_NAME=${SYS_VERSION_ID/./}
|
||||
SYS_NAME_LEN=`echo "$SYS_NAME" | wc -L`
|
||||
|
||||
if [ "$SYS_NAME_LEN" == "1" ];then
|
||||
SYS_NAME=${SYS_NAME}0
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -gt "90" ];then
|
||||
SYS_NAME="82"
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -lt "70" ];then
|
||||
SYS_NAME="70"
|
||||
fi
|
||||
|
||||
MG_DIR=$serverPath/source/mongodb
|
||||
mkdir -p $MG_DIR
|
||||
|
||||
FILE_NAME=mongodb-linux-${SYS_ARCH}-rhel${SYS_NAME}-${VERSION}
|
||||
FILE_NAME_TGZ=${FILE_NAME}.tgz
|
||||
|
||||
if [ ! -f $MG_DIR/${FILE_NAME_TGZ} ]; then
|
||||
wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}
|
||||
echo "wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}"
|
||||
fi
|
||||
|
||||
if [ ! -d $MG_DIR/${FILE_NAME} ];then
|
||||
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/mongodb/bin ];then
|
||||
mkdir -p $serverPath/mongodb
|
||||
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
|
||||
fi
|
||||
@@ -0,0 +1,43 @@
|
||||
#!/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
|
||||
VERSION=6.0.9
|
||||
SYS_ARCH=`arch`
|
||||
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
|
||||
SYS_NAME=${SYS_VERSION_ID/./}
|
||||
|
||||
if [ "$SYS_NAME" -gt "11" ];then
|
||||
SYS_NAME="11"
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -lt "10" ];then
|
||||
SYS_NAME="10"
|
||||
fi
|
||||
|
||||
FILE_NAME=mongodb-linux-${SYS_ARCH}-debian${SYS_NAME}-${VERSION}
|
||||
FILE_NAME_TGZ=${FILE_NAME}.tgz
|
||||
|
||||
|
||||
MG_DIR=$serverPath/source/mongodb
|
||||
mkdir -p $MG_DIR
|
||||
|
||||
if [ ! -f $MG_DIR/${FILE_NAME_TGZ} ]; then
|
||||
wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}
|
||||
echo "wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}"
|
||||
fi
|
||||
|
||||
if [ ! -d $MG_DIR/${FILE_NAME_TGZ} ];then
|
||||
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/mongodb/bin ];then
|
||||
mkdir -p $serverPath/mongodb
|
||||
cd $MG_DIR/${FILE_NAME}} && cp -rf ./bin $serverPath/mongodb
|
||||
fi
|
||||
@@ -0,0 +1,28 @@
|
||||
#!/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
|
||||
VERSION=6.0.9
|
||||
|
||||
MG_DIR=$serverPath/source/mongodb
|
||||
mkdir -p $MG_DIR
|
||||
|
||||
if [ ! -f $MG_DIR/mongodb-macos-x86_64-${VERSION}.tgz ]; then
|
||||
wget --no-check-certificate -O $MG_DIR/mongodb-macos-x86_64-${VERSION}.tgz https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-${VERSION}.tgz
|
||||
echo "wget --no-check-certificate -O $MG_DIR/mongodb-macos-x86_64-${VERSION}.tgz https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-${VERSION}.tgz"
|
||||
fi
|
||||
|
||||
if [ ! -d $MG_DIR/mongodb-macos-x86_64-${VERSION} ];then
|
||||
cd $MG_DIR && tar -zxvf mongodb-macos-x86_64-${VERSION}.tgz
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/mongodb/bin ];then
|
||||
mkdir -p $serverPath/mongodb
|
||||
cd $MG_DIR/mongodb-macos-x86_64-${VERSION} && cp -rf ./bin $serverPath/mongodb
|
||||
fi
|
||||
@@ -0,0 +1,46 @@
|
||||
#!/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
|
||||
VERSION=6.0.9
|
||||
SYS_ARCH=`arch`
|
||||
|
||||
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}' | awk -F . '{print $1}'`
|
||||
|
||||
SYS_NAME="15"
|
||||
if [ "$SYS_VERSION_ID" -gt "15" ];then
|
||||
SYS_NAME="15"
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -lt "12" ];then
|
||||
SYS_NAME="12"
|
||||
fi
|
||||
|
||||
# https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-suse15-4.4.23.tgz
|
||||
# https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-suse12-4.4.23.tgz
|
||||
|
||||
MG_DIR=$serverPath/source/mongodb
|
||||
mkdir -p $MG_DIR
|
||||
|
||||
FILE_NAME=mongodb-linux-${SYS_ARCH}-suse${SYS_NAME}-${VERSION}
|
||||
FILE_NAME_TGZ=${FILE_NAME}.tgz
|
||||
|
||||
if [ ! -f $MG_DIR/${FILE_NAME_TGZ} ]; then
|
||||
wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}
|
||||
echo "wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}"
|
||||
fi
|
||||
|
||||
if [ ! -d $MG_DIR/${FILE_NAME} ];then
|
||||
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/mongodb/bin ];then
|
||||
mkdir -p $serverPath/mongodb
|
||||
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
|
||||
fi
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/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
|
||||
VERSION=6.0.9
|
||||
SYS_ARCH=`arch`
|
||||
|
||||
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
|
||||
SYS_NAME=${SYS_VERSION_ID/./}
|
||||
# https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2004-4.4.23.tgz
|
||||
|
||||
if [ "$SYS_NAME" -gt "2204" ];then
|
||||
SYS_NAME="2204"
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -lt "1804" ];then
|
||||
SYS_NAME="1804"
|
||||
fi
|
||||
|
||||
MG_DIR=$serverPath/source/mongodb
|
||||
mkdir -p $MG_DIR
|
||||
|
||||
FILE_NAME=mongodb-linux-${SYS_ARCH}-ubuntu${SYS_NAME}-${VERSION}
|
||||
FILE_NAME_TGZ=${FILE_NAME}.tgz
|
||||
|
||||
if [ ! -f $MG_DIR/${FILE_NAME_TGZ} ]; then
|
||||
wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}
|
||||
echo "wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}"
|
||||
fi
|
||||
|
||||
if [ ! -d $MG_DIR/${FILE_NAME} ];then
|
||||
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/mongodb/bin ];then
|
||||
mkdir -p $serverPath/mongodb
|
||||
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
|
||||
fi
|
||||
@@ -0,0 +1,48 @@
|
||||
#!/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
|
||||
VERSION=7.0.0
|
||||
SYS_ARCH=`arch`
|
||||
|
||||
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
|
||||
SYS_NAME=${SYS_VERSION_ID/./}
|
||||
SYS_NAME_LEN=`echo "$SYS_NAME" | wc -L`
|
||||
|
||||
if [ "$SYS_NAME_LEN" == "1" ];then
|
||||
SYS_NAME=${SYS_NAME}0
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -gt "90" ];then
|
||||
SYS_NAME="82"
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -lt "70" ];then
|
||||
SYS_NAME="70"
|
||||
fi
|
||||
|
||||
MG_DIR=$serverPath/source/mongodb
|
||||
mkdir -p $MG_DIR
|
||||
|
||||
FILE_NAME=mongodb-linux-${SYS_ARCH}-rhel${SYS_NAME}-${VERSION}
|
||||
FILE_NAME_TGZ=${FILE_NAME}.tgz
|
||||
|
||||
if [ ! -f $MG_DIR/${FILE_NAME_TGZ} ]; then
|
||||
wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}
|
||||
echo "wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}"
|
||||
fi
|
||||
|
||||
if [ ! -d $MG_DIR/${FILE_NAME} ];then
|
||||
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/mongodb/bin ];then
|
||||
mkdir -p $serverPath/mongodb
|
||||
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
|
||||
fi
|
||||
@@ -0,0 +1,43 @@
|
||||
#!/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
|
||||
VERSION=7.0.0
|
||||
SYS_ARCH=`arch`
|
||||
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
|
||||
SYS_NAME=${SYS_VERSION_ID/./}
|
||||
|
||||
if [ "$SYS_NAME" -gt "11" ];then
|
||||
SYS_NAME="11"
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -lt "11" ];then
|
||||
SYS_NAME="11"
|
||||
fi
|
||||
|
||||
FILE_NAME=mongodb-linux-${SYS_ARCH}-debian${SYS_NAME}-${VERSION}
|
||||
FILE_NAME_TGZ=${FILE_NAME}.tgz
|
||||
|
||||
|
||||
MG_DIR=$serverPath/source/mongodb
|
||||
mkdir -p $MG_DIR
|
||||
|
||||
if [ ! -f $MG_DIR/${FILE_NAME_TGZ} ]; then
|
||||
wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}
|
||||
echo "wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}"
|
||||
fi
|
||||
|
||||
if [ ! -d $MG_DIR/${FILE_NAME_TGZ} ];then
|
||||
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/mongodb/bin ];then
|
||||
mkdir -p $serverPath/mongodb
|
||||
cd $MG_DIR/${FILE_NAME}} && cp -rf ./bin $serverPath/mongodb
|
||||
fi
|
||||
@@ -0,0 +1,28 @@
|
||||
#!/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
|
||||
VERSION=7.0.0
|
||||
|
||||
MG_DIR=$serverPath/source/mongodb
|
||||
mkdir -p $MG_DIR
|
||||
|
||||
if [ ! -f $MG_DIR/mongodb-macos-x86_64-${VERSION}.tgz ]; then
|
||||
wget --no-check-certificate -O $MG_DIR/mongodb-macos-x86_64-${VERSION}.tgz https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-${VERSION}.tgz
|
||||
echo "wget --no-check-certificate -O $MG_DIR/mongodb-macos-x86_64-${VERSION}.tgz https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-${VERSION}.tgz"
|
||||
fi
|
||||
|
||||
if [ ! -d $MG_DIR/mongodb-macos-x86_64-${VERSION} ];then
|
||||
cd $MG_DIR && tar -zxvf mongodb-macos-x86_64-${VERSION}.tgz
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/mongodb/bin ];then
|
||||
mkdir -p $serverPath/mongodb
|
||||
cd $MG_DIR/mongodb-macos-x86_64-${VERSION} && cp -rf ./bin $serverPath/mongodb
|
||||
fi
|
||||
@@ -0,0 +1,46 @@
|
||||
#!/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
|
||||
VERSION=7.0.0
|
||||
SYS_ARCH=`arch`
|
||||
|
||||
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}' | awk -F . '{print $1}'`
|
||||
|
||||
SYS_NAME="15"
|
||||
if [ "$SYS_VERSION_ID" -gt "15" ];then
|
||||
SYS_NAME="15"
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -lt "12" ];then
|
||||
SYS_NAME="12"
|
||||
fi
|
||||
|
||||
# https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-suse15-4.4.23.tgz
|
||||
# https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-suse12-4.4.23.tgz
|
||||
|
||||
MG_DIR=$serverPath/source/mongodb
|
||||
mkdir -p $MG_DIR
|
||||
|
||||
FILE_NAME=mongodb-linux-${SYS_ARCH}-suse${SYS_NAME}-${VERSION}
|
||||
FILE_NAME_TGZ=${FILE_NAME}.tgz
|
||||
|
||||
if [ ! -f $MG_DIR/${FILE_NAME_TGZ} ]; then
|
||||
wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}
|
||||
echo "wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}"
|
||||
fi
|
||||
|
||||
if [ ! -d $MG_DIR/${FILE_NAME} ];then
|
||||
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/mongodb/bin ];then
|
||||
mkdir -p $serverPath/mongodb
|
||||
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
|
||||
fi
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/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
|
||||
VERSION=7.0.0
|
||||
SYS_ARCH=`arch`
|
||||
|
||||
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
|
||||
SYS_NAME=${SYS_VERSION_ID/./}
|
||||
# https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2004-4.4.23.tgz
|
||||
|
||||
if [ "$SYS_NAME" -gt "2204" ];then
|
||||
SYS_NAME="2204"
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -lt "2004" ];then
|
||||
SYS_NAME="2004"
|
||||
fi
|
||||
|
||||
MG_DIR=$serverPath/source/mongodb
|
||||
mkdir -p $MG_DIR
|
||||
|
||||
FILE_NAME=mongodb-linux-${SYS_ARCH}-ubuntu${SYS_NAME}-${VERSION}
|
||||
FILE_NAME_TGZ=${FILE_NAME}.tgz
|
||||
|
||||
if [ ! -f $MG_DIR/${FILE_NAME_TGZ} ]; then
|
||||
wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}
|
||||
echo "wget --no-check-certificate -O $MG_DIR/${FILE_NAME_TGZ} https://fastdl.mongodb.org/linux/${FILE_NAME_TGZ}"
|
||||
fi
|
||||
|
||||
if [ ! -d $MG_DIR/${FILE_NAME} ];then
|
||||
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/mongodb/bin ];then
|
||||
mkdir -p $serverPath/mongodb
|
||||
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
|
||||
fi
|
||||
@@ -14,6 +14,9 @@ port = 33206
|
||||
socket = {$SERVER_APP_PATH}/mysql.sock
|
||||
datadir = {$SERVER_APP_PATH}/data
|
||||
log-error = {$SERVER_APP_PATH}/data/error.log
|
||||
server-id = {$SERVER_ID}
|
||||
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
|
||||
|
||||
default_storage_engine = InnoDB
|
||||
language={$SERVER_APP_PATH}/bin/usr/share/mysql/english
|
||||
|
||||
@@ -45,7 +48,6 @@ skip-ssl
|
||||
|
||||
log-bin=mysql-bin
|
||||
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
|
||||
@@ -65,12 +67,15 @@ binlog-ignore-db = performance_schema
|
||||
#slave
|
||||
log-slave-updates
|
||||
#replicate-do-db
|
||||
slave_skip_errors=1062
|
||||
slave_skip_errors=1062,1396
|
||||
replicate-ignore-db = information_schema
|
||||
replicate-ignore-db = performance_schema
|
||||
replicate-ignore-db = mysql
|
||||
replicate-ignore-db = test
|
||||
|
||||
master_info_repository = table
|
||||
relay_log_info_repository = table
|
||||
|
||||
default_storage_engine = InnoDB
|
||||
innodb_data_home_dir = {$SERVER_APP_PATH}/data
|
||||
innodb_data_file_path = ibdata1:10M:autoextend
|
||||
|
||||
@@ -16,6 +16,9 @@ mysqlx_port = 33260
|
||||
socket = {$SERVER_APP_PATH}/mysql.sock
|
||||
datadir = {$SERVER_APP_PATH}/data
|
||||
log-error = {$SERVER_APP_PATH}/data/error.log
|
||||
server-id = {$SERVER_ID}
|
||||
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
|
||||
|
||||
default_storage_engine = InnoDB
|
||||
|
||||
key_buffer_size = 8M
|
||||
@@ -43,7 +46,6 @@ max_allowed_packet = 128M
|
||||
|
||||
log-bin=mysql-bin
|
||||
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
|
||||
@@ -62,12 +64,15 @@ binlog-ignore-db = performance_schema
|
||||
#slave
|
||||
log_replica_updates
|
||||
#replicate-do-db
|
||||
slave_skip_errors=1062
|
||||
slave_skip_errors=1062,1396
|
||||
replicate-ignore-db = information_schema
|
||||
replicate-ignore-db = performance_schema
|
||||
replicate-ignore-db = mysql
|
||||
replicate-ignore-db = test
|
||||
|
||||
master_info_repository = table
|
||||
relay_log_info_repository = table
|
||||
|
||||
default_storage_engine = InnoDB
|
||||
innodb_data_home_dir = {$SERVER_APP_PATH}/data
|
||||
innodb_data_file_path = ibdata1:10M:autoextend
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<p onclick="dbList()">管理列表</p>
|
||||
<p onclick="masterOrSlaveConf($('.plugin_version').attr('version'))">主从配置</p>
|
||||
</div>
|
||||
<div class="bt-w-con pd15">
|
||||
<div class="bt-w-con pd15" style="height:555px;overflow: auto;">
|
||||
<div class="soft-man-con"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+225
-141
@@ -28,6 +28,10 @@ def getPluginDir():
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getSPluginDir():
|
||||
return '/www/server/mdserver-web/plugins/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
@@ -116,6 +120,10 @@ def contentReplace(content):
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
content = content.replace('{$SERVER_APP_PATH}',
|
||||
service_path + '/' + getPluginName())
|
||||
|
||||
server_id = int(time.time())
|
||||
content = content.replace('{$SERVER_ID}', str(server_id))
|
||||
|
||||
return content
|
||||
|
||||
|
||||
@@ -161,6 +169,10 @@ def pMysqlDb():
|
||||
|
||||
def initDreplace(version=''):
|
||||
|
||||
t = getServerDir()
|
||||
if not os.path.exists(t):
|
||||
return
|
||||
|
||||
conf_dir = getServerDir() + '/etc'
|
||||
mode_dir = conf_dir + '/mode'
|
||||
|
||||
@@ -654,15 +666,15 @@ def isSqlError(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:
|
||||
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:
|
||||
if "1133," in mysqlMsg:
|
||||
return mw.returnJson(False, '数据库用户不存在!')
|
||||
if "1007" in mysqlMsg:
|
||||
if "1007," in mysqlMsg:
|
||||
return mw.returnJson(False, '数据库已经存在!')
|
||||
return None
|
||||
|
||||
@@ -1885,27 +1897,34 @@ def getMasterRepSlaveUserCmd(version):
|
||||
|
||||
mode = recognizeDbMode()
|
||||
|
||||
sid = getDbServerId()
|
||||
channel_name = ""
|
||||
if sid != '':
|
||||
channel_name = " for channel 'r{}';".format(sid)
|
||||
|
||||
if mode == "gtid":
|
||||
sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \
|
||||
clist[0]['username'] + "', MASTER_PASSWORD='" + \
|
||||
clist[0]['password'] + "', MASTER_AUTO_POSITION=1"
|
||||
clist[0]['password'] + "', MASTER_AUTO_POSITION=1" + channel_name
|
||||
if version == '8.0':
|
||||
sql = "CHANGE REPLICATION SOURCE TO SOURCE_HOST='" + ip + "', SOURCE_PORT=" + port + ", SOURCE_USER='" + \
|
||||
clist[0]['username'] + "', SOURCE_PASSWORD='" + \
|
||||
clist[0]['password'] + "', MASTER_AUTO_POSITION=1"
|
||||
clist[0]['password'] + \
|
||||
"', MASTER_AUTO_POSITION=1" + channel_name
|
||||
else:
|
||||
sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \
|
||||
clist[0]['username'] + "', MASTER_PASSWORD='" + \
|
||||
clist[0]['password'] + \
|
||||
"', MASTER_LOG_FILE='" + mstatus[0]["File"] + \
|
||||
"',MASTER_LOG_POS=" + str(mstatus[0]["Position"])
|
||||
"',MASTER_LOG_POS=" + str(mstatus[0]["Position"]) + channel_name
|
||||
|
||||
if version == "8.0":
|
||||
sql = "CHANGE REPLICATION SOURCE TO SOURCE_HOST='" + ip + "', SOURCE_PORT=" + port + ", SOURCE_USER='" + \
|
||||
clist[0]['username'] + "', SOURCE_PASSWORD='" + \
|
||||
clist[0]['password'] + \
|
||||
"', SOURCE_LOG_FILE='" + mstatus[0]["File"] + \
|
||||
"',SOURCE_LOG_POS=" + str(mstatus[0]["Position"])
|
||||
"',SOURCE_LOG_POS=" + \
|
||||
str(mstatus[0]["Position"]) + channel_name
|
||||
|
||||
data = {}
|
||||
data['cmd'] = sql
|
||||
@@ -2217,7 +2236,7 @@ def getSlaveSyncCmd(version=''):
|
||||
|
||||
root = mw.getRunDir()
|
||||
cmd = 'cd ' + root + ' && python3 ' + root + \
|
||||
'/plugins/mysql/index.py do_full_sync {"db":"all"}'
|
||||
'/plugins/mysql/index.py do_full_sync {"db":"all","sign":""}'
|
||||
return mw.returnJson(True, 'ok', cmd)
|
||||
|
||||
|
||||
@@ -2233,100 +2252,151 @@ def initSlaveStatus(version=''):
|
||||
return initSlaveStatusSyncUser(version)
|
||||
|
||||
|
||||
def parseSlaveSyncCmd(cmd):
|
||||
a = {}
|
||||
if cmd.lower().find('for') > 0:
|
||||
cmd_tmp = cmd.split('for')
|
||||
cmd = cmd_tmp[0].strip()
|
||||
|
||||
pattern_c = r"channel \'(.*)\';"
|
||||
match_val = re.match(pattern_c, cmd_tmp[1].strip(), re.I)
|
||||
if match_val:
|
||||
m_groups = match_val.groups()
|
||||
a['channel'] = m_groups[0]
|
||||
vlist = cmd.split(',')
|
||||
for i in vlist:
|
||||
tmp = i.strip()
|
||||
tmp_a = tmp.split(" ")
|
||||
real_tmp = tmp_a[len(tmp_a) - 1]
|
||||
kv = real_tmp.split("=")
|
||||
a[kv[0]] = kv[1].replace("'", '').replace("'", '').replace(";", '')
|
||||
return a
|
||||
|
||||
|
||||
def initSlaveStatusSyncUser(version=''):
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
if len(data) < 1:
|
||||
slave_data = conn.field('ip,port,user,pass,mode,cmd').select()
|
||||
if len(slave_data) < 1:
|
||||
return mw.returnJson(False, '需要先添加同步用户配置!')
|
||||
|
||||
# print(data)
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
if len(dlist) > 0:
|
||||
return mw.returnJson(False, '已经初始化好了zz...')
|
||||
|
||||
u = data
|
||||
|
||||
mode_name = 'classic'
|
||||
if u['mode'] == '1':
|
||||
mode_name = 'gtid'
|
||||
pdb = pMysqlDb()
|
||||
if len(slave_data) == 1:
|
||||
dlist = pdb.query('show slave status')
|
||||
if len(dlist) > 0:
|
||||
return mw.returnJson(False, '已经初始化好了zz...')
|
||||
|
||||
msg = ''
|
||||
local_mode = recognizeDbMode()
|
||||
if local_mode != mode_name:
|
||||
return mw.returnJson(False, '同步模式不一致!')
|
||||
for x in range(len(slave_data)):
|
||||
slave_t = slave_data[x]
|
||||
mode_name = 'classic'
|
||||
base_t = 'IP:' + slave_t['ip'] + ",PORT:" + \
|
||||
slave_t['port'] + ",USER:" + slave_t['user']
|
||||
|
||||
t = db.query(u['cmd'])
|
||||
# print(t)
|
||||
db.query("start slave user='{}' password='{}';".format(
|
||||
u['user'], u['pass']))
|
||||
return mw.returnJson(True, '初始化成功!')
|
||||
if slave_t['mode'] == '1':
|
||||
mode_name = 'gtid'
|
||||
|
||||
if local_mode != mode_name:
|
||||
msg += base_t + '->同步模式不一致'
|
||||
continue
|
||||
|
||||
cmd_sql = slave_t['cmd']
|
||||
if cmd_sql == '':
|
||||
msg += base_t + '->同步命令不能为空'
|
||||
continue
|
||||
|
||||
try:
|
||||
pinfo = parseSlaveSyncCmd(cmd_sql)
|
||||
except Exception as e:
|
||||
return mw.returnJson(False, base_t + '->CMD同步命令不合规范!')
|
||||
t = pdb.query(cmd_sql)
|
||||
isError = isSqlError(t)
|
||||
if isError:
|
||||
return isError
|
||||
|
||||
# pdb.query("start slave user='{}' password='{}';".format(
|
||||
# u['user'], u['pass']))
|
||||
|
||||
pdb.query("start slave")
|
||||
pdb.query("start all slaves")
|
||||
|
||||
if msg == '':
|
||||
msg = '初始化成功!'
|
||||
return mw.returnJson(True, msg)
|
||||
|
||||
|
||||
def initSlaveStatusSSH(version=''):
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
if len(dlist) > 0:
|
||||
return mw.returnJson(False, '已经初始化好了zz...')
|
||||
|
||||
conn = pSqliteDb('slave_id_rsa')
|
||||
data = conn.field('ip,port,id_rsa').find()
|
||||
ssh_list = conn.field('ip,port,id_rsa,db_user').select()
|
||||
|
||||
if len(data) < 1:
|
||||
if len(ssh_list) < 1:
|
||||
return mw.returnJson(False, '需要先配置【[主]SSH配置】!')
|
||||
|
||||
SSH_PRIVATE_KEY = "/tmp/t_ssh.txt"
|
||||
ip = data['ip']
|
||||
master_port = data['port']
|
||||
mw.writeFile(SSH_PRIVATE_KEY, data['id_rsa'].replace('\\n', '\n'))
|
||||
local_mode = recognizeDbMode()
|
||||
|
||||
import paramiko
|
||||
paramiko.util.log_to_file('paramiko.log')
|
||||
ssh = paramiko.SSHClient()
|
||||
|
||||
try:
|
||||
|
||||
db.query('stop slave')
|
||||
db.query('reset slave all')
|
||||
for data in ssh_list:
|
||||
ip = data['ip']
|
||||
SSH_PRIVATE_KEY = "/tmp/t_ssh_" + ip + ".txt"
|
||||
master_port = data['port']
|
||||
mw.writeFile(SSH_PRIVATE_KEY, data['id_rsa'].replace('\\n', '\n'))
|
||||
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=int(master_port),
|
||||
username='root', pkey=key)
|
||||
try:
|
||||
key = paramiko.RSAKey.from_private_key_file(SSH_PRIVATE_KEY)
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect(hostname=ip, port=int(master_port),
|
||||
username='root', pkey=key)
|
||||
|
||||
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 = result.decode('utf-8')
|
||||
cmd_data = json.loads(result)
|
||||
db_user = data['db_user']
|
||||
cmd = 'cd /www/server/mdserver-web && source bin/activate && python3 ' + \
|
||||
getSPluginDir() + \
|
||||
'/index.py get_master_rep_slave_user_cmd {"username":"' + \
|
||||
db_user + '","db":""}'
|
||||
stdin, stdout, stderr = ssh.exec_command(cmd)
|
||||
result = stdout.read()
|
||||
result = result.decode('utf-8')
|
||||
if result.strip() == "":
|
||||
return mw.returnJson(False, '[主][' + ip + ']:获取同步命令失败!')
|
||||
|
||||
if not cmd_data['status']:
|
||||
return mw.returnJson(False, '[主]:' + cmd_data['msg'])
|
||||
cmd_data = json.loads(result)
|
||||
if not cmd_data['status']:
|
||||
return mw.returnJson(False, '[主][' + ip + ']:' + cmd_data['msg'])
|
||||
|
||||
local_mode = recognizeDbMode()
|
||||
if local_mode != cmd_data['data']['mode']:
|
||||
return mw.returnJson(False, '主【{}】从【{}】,运行模式不一致!'.format(cmd_data['data']['mode'], local_mode))
|
||||
if local_mode != cmd_data['data']['mode']:
|
||||
return mw.returnJson(False, '[主][' + ip + ']:【{}】从【{}】,运行模式不一致!'.format(cmd_data['data']['mode'], local_mode))
|
||||
|
||||
u = cmd_data['data']['info']
|
||||
ps = u['username'] + "|" + u['password']
|
||||
conn.where('ip=?', (ip,)).setField('ps', ps)
|
||||
db.query('stop slave')
|
||||
u = cmd_data['data']['info']
|
||||
|
||||
# 保证同步IP一致
|
||||
cmd = cmd_data['data']['cmd']
|
||||
if cmd.find('SOURCE_HOST') > -1:
|
||||
cmd = re.sub(r"SOURCE_HOST='(.*)'",
|
||||
"SOURCE_HOST='" + ip + "'", cmd, 1)
|
||||
ps = u['username'] + "|" + u['password']
|
||||
print(ps)
|
||||
conn.where('ip=?', (ip,)).setField('ps', ps)
|
||||
db.query('stop slave')
|
||||
|
||||
if cmd.find('MASTER_HOST') > -1:
|
||||
cmd = re.sub(r"MASTER_HOST='(.*)'",
|
||||
"MASTER_HOST='" + ip + "'", cmd, 1)
|
||||
db.query(cmd)
|
||||
db.query("start slave user='{}' password='{}';".format(
|
||||
u['username'], u['password']))
|
||||
except Exception as e:
|
||||
return mw.returnJson(False, 'SSH认证配置连接失败!' + str(e))
|
||||
# 保证同步IP一致
|
||||
cmd = cmd_data['data']['cmd']
|
||||
if cmd.find('SOURCE_HOST') > -1:
|
||||
cmd = re.sub(r"SOURCE_HOST='(.*?)'",
|
||||
"SOURCE_HOST='" + ip + "'", cmd, 1)
|
||||
|
||||
ssh.close()
|
||||
time.sleep(1)
|
||||
os.system("rm -rf " + SSH_PRIVATE_KEY)
|
||||
if cmd.find('MASTER_HOST') > -1:
|
||||
cmd = re.sub(r"MASTER_HOST='(.*?)'",
|
||||
"MASTER_HOST='" + ip + "'", cmd, 1)
|
||||
db.query(cmd)
|
||||
ssh.close()
|
||||
if os.path.exists(SSH_PRIVATE_KEY):
|
||||
os.system("rm -rf " + SSH_PRIVATE_KEY)
|
||||
except Exception as e:
|
||||
return mw.returnJson(False, '[主][' + ip + ']:SSH认证配置连接失败!' + str(e))
|
||||
db.query('start slave')
|
||||
return mw.returnJson(True, '初始化成功!')
|
||||
|
||||
|
||||
@@ -2336,60 +2406,37 @@ def setSlaveStatus(version=''):
|
||||
return mw.returnJson(False, '需要先设置同步配置')
|
||||
|
||||
mode = mw.readFile(mode_file)
|
||||
if mode == 'ssh':
|
||||
return setSlaveStatusSSH(version)
|
||||
if mode == 'sync-user':
|
||||
return setSlaveStatusSyncUser(version)
|
||||
|
||||
|
||||
def setSlaveStatusSyncUser(version=''):
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
pdb = pMysqlDb()
|
||||
dlist = pdb.query('show slave status')
|
||||
if len(dlist) == 0:
|
||||
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:
|
||||
ip = dlist[0]['Master_Host']
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
if len(data) == 0:
|
||||
return mw.returnJson(False, '没有数据无法重启!')
|
||||
user = data['user']
|
||||
apass = data['pass']
|
||||
for v in dlist:
|
||||
connection_name = ''
|
||||
cmd = "slave"
|
||||
if 'Channel_Name' in v:
|
||||
ch_name = v['Channel_Name']
|
||||
cmd = "slave for channel '{}'".format(ch_name)
|
||||
|
||||
db.query("start slave")
|
||||
# db.query("start slave user='{}' password='{}';".format(user, apass))
|
||||
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def setSlaveStatusSSH(version=''):
|
||||
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
if len(dlist) == 0:
|
||||
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:
|
||||
ip = dlist[0]['Master_Host']
|
||||
conn = pSqliteDb('slave_id_rsa')
|
||||
data = conn.field('ip,ps').where("ip=?", (ip,)).find()
|
||||
if len(data) == 0:
|
||||
return mw.returnJson(False, '没有数据无法重启!')
|
||||
u = data['ps'].split("|")
|
||||
db.query("start slave user='{}' password='{}';".format(u[0], u[1]))
|
||||
if (v["Slave_IO_Running"] == 'Yes' or v["Slave_SQL_Running"] == 'Yes'):
|
||||
pdb.query("stop {}".format(cmd))
|
||||
else:
|
||||
pdb.query("start {}".format(cmd))
|
||||
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def deleteSlave(version=''):
|
||||
args = getArgs()
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('stop slave')
|
||||
dlist = db.query('reset slave all')
|
||||
if 'sign' in args:
|
||||
sign = args['sign']
|
||||
db.query("stop slave for channel '{}'".format(sign))
|
||||
db.query("reset slave all for channel '{}'".format(sign))
|
||||
else:
|
||||
db.query('stop slave')
|
||||
db.query('reset slave all')
|
||||
|
||||
return mw.returnJson(True, '删除成功!')
|
||||
|
||||
|
||||
@@ -2425,11 +2472,13 @@ def dumpMysqlData(version=''):
|
||||
|
||||
############### --- 重要 同步---- ###########
|
||||
|
||||
def asyncTmpfile():
|
||||
path = '/tmp/mysql_apt_async_status.txt'
|
||||
return path
|
||||
|
||||
|
||||
def writeDbSyncStatus(data):
|
||||
path = '/tmp/db_async_status.txt'
|
||||
# status_data['code'] = 1
|
||||
# status_data['msg'] = '主服务器备份完成...'
|
||||
# status_data['progress'] = 30
|
||||
path = asyncTmpfile()
|
||||
mw.writeFile(path, json.dumps(data))
|
||||
|
||||
|
||||
@@ -2447,16 +2496,32 @@ def doFullSync(version=''):
|
||||
|
||||
def doFullSyncUser(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['db'])
|
||||
data = checkArgs(args, ['db', 'sign'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
sync_db = args['db']
|
||||
sync_db_import = args['db']
|
||||
|
||||
if sync_db.lower() == 'all':
|
||||
sync_db_import = ''
|
||||
dbs = findBinlogSlaveDoDb()
|
||||
dbs_str = ''
|
||||
for x in dbs:
|
||||
dbs_str += ' ' + x
|
||||
sync_db = "--databases " + dbs_str.strip()
|
||||
|
||||
sync_sign = args['sign']
|
||||
|
||||
db = pMysqlDb()
|
||||
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
if sync_sign != '':
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').where(
|
||||
'ip=?', (sync_sign,)).find()
|
||||
else:
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
|
||||
user = data['user']
|
||||
apass = data['pass']
|
||||
port = data['port']
|
||||
@@ -2473,17 +2538,18 @@ def doFullSyncUser(version=''):
|
||||
writeDbSyncStatus({'code': 1, 'msg': '远程导出数据...', 'progress': 20})
|
||||
|
||||
if not os.path.exists(bak_file):
|
||||
dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --force --opt --default-character-set=utf8 --single-transaction -h" + ip + " -P" + \
|
||||
port + " -u" + user + " -p" + apass + \
|
||||
" --ssl-mode=DISABLED " + sync_db + " > " + bak_file
|
||||
dump_sql_data = getServerDir() + "/bin/usr/bin/mysqldump " + dmp_option + " --force --opt --default-character-set=utf8 --single-transaction -h" + ip + " -P" + \
|
||||
port + " -u" + user + " -p\"" + apass + \
|
||||
"\" --ssl-mode=DISABLED " + sync_db + " > " + bak_file
|
||||
# print(dump_sql_data)
|
||||
mw.execShell(dump_sql_data)
|
||||
|
||||
writeDbSyncStatus({'code': 2, 'msg': '本地导入数据...', 'progress': 40})
|
||||
if os.path.exists(bak_file):
|
||||
pwd = pSqliteDb('config').where('id=?', (1,)).getField('mysql_root')
|
||||
sock = getSocketFile()
|
||||
my_import_cmd = getServerDir() + '/bin/mysql -S ' + sock + ' -uroot -p' + pwd + \
|
||||
' ' + sync_db + ' < ' + bak_file
|
||||
my_import_cmd = getServerDir() + '/bin/usr/bin/mysql -S ' + sock + ' -uroot -p' + pwd + \
|
||||
' ' + sync_db_import + ' < ' + bak_file
|
||||
mw.execShell(my_import_cmd)
|
||||
|
||||
if version == '8.0':
|
||||
@@ -2492,21 +2558,30 @@ def doFullSyncUser(version=''):
|
||||
db.query("start slave")
|
||||
|
||||
writeDbSyncStatus({'code': 6, 'msg': '从库重启完成...', 'progress': 100})
|
||||
os.system("rm -rf " + bak_file)
|
||||
|
||||
if os.path.exists(bak_file):
|
||||
os.system("rm -rf " + bak_file)
|
||||
return True
|
||||
|
||||
|
||||
def doFullSyncSSH(version=''):
|
||||
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['db'])
|
||||
data = checkArgs(args, ['db', 'sign'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
sync_db = args['db']
|
||||
sync_sign = args['sign']
|
||||
|
||||
db = pMysqlDb()
|
||||
|
||||
id_rsa_conn = pSqliteDb('slave_id_rsa')
|
||||
data = id_rsa_conn.field('ip,port,db_user,id_rsa').find()
|
||||
if sync_sign != '':
|
||||
data = id_rsa_conn.field('ip,port,db_user,id_rsa').where(
|
||||
'ip=?', (sync_sign,)).find()
|
||||
else:
|
||||
data = id_rsa_conn.field('ip,port,db_user,id_rsa').find()
|
||||
|
||||
SSH_PRIVATE_KEY = "/tmp/mysql_sync_id_rsa.txt"
|
||||
id_rsa = data['id_rsa'].replace('\\n', '\n')
|
||||
@@ -2548,7 +2623,8 @@ def doFullSyncSSH(version=''):
|
||||
writeDbSyncStatus({'code': 0, 'msg': '登录Master成功...', 'progress': 5})
|
||||
|
||||
dbname = args['db']
|
||||
cmd = "cd /www/server/mdserver-web && python3 plugins/mysql/index.py dump_mysql_data {\"db\":'" + dbname + "'}"
|
||||
cmd = "cd /www/server/mdserver-web && source bin/activate && python3 " + \
|
||||
getSPluginDir() + "/index.py dump_mysql_data {\"db\":'" + dbname + "'}"
|
||||
print(cmd)
|
||||
stdin, stdout, stderr = ssh.exec_command(cmd)
|
||||
result = stdout.read()
|
||||
@@ -2571,7 +2647,10 @@ def doFullSyncSSH(version=''):
|
||||
if copy_status == None:
|
||||
writeDbSyncStatus({'code': 2, 'msg': '数据同步本地完成...', 'progress': 40})
|
||||
|
||||
cmd = 'cd /www/server/mdserver-web && python3 plugins/mysql/index.py get_master_rep_slave_user_cmd {"username":"' + db_user + '","db":""}'
|
||||
cmd = 'cd /www/server/mdserver-web && source bin/activate && python3 ' + \
|
||||
getSPluginDir() + \
|
||||
'/index.py get_master_rep_slave_user_cmd {"username":"' + \
|
||||
db_user + '","db":""}'
|
||||
stdin, stdout, stderr = ssh.exec_command(cmd)
|
||||
result = stdout.read()
|
||||
result = result.decode('utf-8')
|
||||
@@ -2583,10 +2662,12 @@ def doFullSyncSSH(version=''):
|
||||
cmd = cmd_data['data']['cmd']
|
||||
# 保证同步IP一致
|
||||
if cmd.find('SOURCE_HOST') > -1:
|
||||
cmd = re.sub(r"SOURCE_HOST='(.*)'", "SOURCE_HOST='" + ip + "'", cmd, 1)
|
||||
cmd = re.sub(r"SOURCE_HOST='(.*?)'",
|
||||
"SOURCE_HOST='" + ip + "'", cmd, 1)
|
||||
|
||||
if cmd.find('MASTER_HOST') > -1:
|
||||
cmd = re.sub(r"MASTER_HOST='(.*)'", "SOURCE_HOST='" + ip + "'", cmd, 1)
|
||||
cmd = re.sub(r"MASTER_HOST='(.*?)'",
|
||||
"MASTER_HOST='" + ip + "'", cmd, 1)
|
||||
|
||||
db.query(cmd)
|
||||
uinfo = cmd_data['data']['info']
|
||||
@@ -2598,8 +2679,10 @@ def doFullSyncSSH(version=''):
|
||||
root_dir = getServerDir()
|
||||
msock = root_dir + "/mysql.sock"
|
||||
mw.execShell("cd /tmp && gzip -d dump.sql.gz")
|
||||
cmd = root_dir + "/bin/mysql -S " + msock + \
|
||||
cmd = root_dir + "/bin/usr/bin/mysql -S " + msock + \
|
||||
" -uroot -p" + pwd + " < /tmp/dump.sql"
|
||||
|
||||
print(cmd)
|
||||
import_data = mw.execShell(cmd)
|
||||
if import_data[0] == '':
|
||||
print(import_data[1])
|
||||
@@ -2609,8 +2692,9 @@ def doFullSyncSSH(version=''):
|
||||
writeDbSyncStatus({'code': 5, 'msg': '导入数据失败...', 'progress': 100})
|
||||
return 'fail'
|
||||
|
||||
db.query("start slave user='{}' password='{}';".format(
|
||||
uinfo['username'], uinfo['password']))
|
||||
# "start slave user='{}' password='{}';".format(uinfo['username'], uinfo['password'])
|
||||
|
||||
db.query("start slave")
|
||||
writeDbSyncStatus({'code': 6, 'msg': '从库重启完成...', 'progress': 100})
|
||||
|
||||
os.system("rm -rf " + SSH_PRIVATE_KEY)
|
||||
@@ -2624,12 +2708,12 @@ def fullSync(version=''):
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
status_file = '/tmp/db_async_status.txt'
|
||||
status_file = asyncTmpfile()
|
||||
if args['begin'] == '1':
|
||||
cmd = 'cd ' + mw.getRunDir() + ' && python3 ' + \
|
||||
getPluginDir() + \
|
||||
'/index.py do_full_sync {"db":"' + args['db'] + '"} &'
|
||||
print(cmd)
|
||||
cmd = 'cd ' + mw.getRunDir() + ' && python3 ' + getPluginDir() + \
|
||||
'/index.py do_full_sync {"db":"' + \
|
||||
args['db'] + '","sign":"' + sign + '"} &'
|
||||
# print(cmd)
|
||||
mw.execShell(cmd)
|
||||
return json.dumps({'code': 0, 'msg': '同步数据中!', 'progress': 0})
|
||||
|
||||
|
||||
@@ -48,7 +48,11 @@ fi
|
||||
sh -x $curPath/versions/$2/install.sh $1
|
||||
|
||||
if [ "${action}" == "install" ];then
|
||||
# #初始化
|
||||
#初始化
|
||||
|
||||
if [ "$?" != "0" ];then
|
||||
exit $?
|
||||
fi
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/mysql-apt/index.py start ${type}
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/mysql-apt/index.py initd_install ${type}
|
||||
fi
|
||||
|
||||
@@ -162,34 +162,6 @@ function myPort(){
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//数据库存储信置
|
||||
function changeMySQLDataPath(act) {
|
||||
if (act != undefined) {
|
||||
layer.confirm(lan.soft.mysql_to_msg, { closeBtn: 2, icon: 3 }, function() {
|
||||
var datadir = $("#datadir").val();
|
||||
var data = 'datadir=' + datadir;
|
||||
var loadT = layer.msg(lan.soft.mysql_to_msg1, { icon: 16, time: 0, shade: [0.3, '#000'] });
|
||||
$.post('/database?action=SetDataDir', data, function(rdata) {
|
||||
layer.close(loadT)
|
||||
layer.msg(rdata.msg, { icon: rdata.status ? 1 : 5 });
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
$.post('/database?action=GetMySQLInfo', '', function(rdata) {
|
||||
var LimitCon = '<p class="conf_p">\
|
||||
<input id="datadir" class="phpUploadLimit bt-input-text mr5" style="width:350px;" type="text" value="' + rdata.datadir + '" name="datadir">\
|
||||
<span onclick="ChangePath(\'datadir\')" class="glyphicon glyphicon-folder-open cursor mr20" style="width:auto"></span><button class="btn btn-success btn-sm" onclick="changeMySQLDataPath(1)">' + lan.soft.mysql_to + '</button>\
|
||||
</p>';
|
||||
$(".soft-man-con").html(LimitCon);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//数据库配置状态
|
||||
function myPerfOpt() {
|
||||
//获取MySQL配置
|
||||
@@ -1691,12 +1663,12 @@ function getMasterRepSlaveListPage(){
|
||||
}
|
||||
|
||||
|
||||
function deleteSlave(){
|
||||
myPost('delete_slave', {}, function(data){
|
||||
function deleteSlave(sign){
|
||||
myPost('delete_slave', {sign:sign}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
showMsg(rdata['msg'], function(){
|
||||
masterOrSlaveConf();
|
||||
},{},3000);
|
||||
},{icon:rdata.status?1:2,time:3000},3000);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1704,28 +1676,73 @@ function deleteSlave(){
|
||||
function getFullSyncStatus(db){
|
||||
var timeId = null;
|
||||
|
||||
var btn = '<div class="table_toolbar" style="left:0px;"><span data-status="init" class="sync btn btn-default btn-sm" id="begin_full_sync" title="">开始</span></div>';
|
||||
var loadOpen = layer.open({
|
||||
type: 1,
|
||||
title: '全量同步['+db+']',
|
||||
area: '500px',
|
||||
content:"<div class='bt-form pd20 c6'>\
|
||||
<div class='divtable mtb10'>\
|
||||
<span id='full_msg'></span>\
|
||||
<div class='progress'>\
|
||||
<div class='progress-bar' role='progressbar' aria-valuenow='0' aria-valuemin='0' aria-valuemax='100' style='min-width: 2em;'>0%</div>\
|
||||
</div>\
|
||||
</div>\
|
||||
"+btn+"\
|
||||
</div>",
|
||||
cancel: function(){
|
||||
clearInterval(timeId);
|
||||
myPost('get_slave_list', {page:1,page_size:100}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
var rsource = rdata.data;
|
||||
|
||||
if (db == 'ALL' && rsource.length>1){
|
||||
layer.msg("多主不支持该模式!",{icon:2});
|
||||
return;
|
||||
}
|
||||
|
||||
var dataSource = '';
|
||||
if (rsource.length>1){
|
||||
var sourceList = '';
|
||||
for (var i = 0; i < rsource.length; i++) {
|
||||
if ('Channel_Name' in rsource[i]){
|
||||
sourceList += '<option val="'+rsource[i]['Master_Host']+'">'+rsource[i]['Master_Host']+'</option>';
|
||||
}
|
||||
}
|
||||
|
||||
dataSource = "<p class='line' style='text-align:center;'>\
|
||||
<span>同步数据源:</span>\
|
||||
<select class='bt-input-text' name='data_source' style='width:200px;'>" + sourceList + "</select>\
|
||||
</p>";
|
||||
}
|
||||
|
||||
layer.open({
|
||||
type: 1,
|
||||
title: '全量同步['+db+']',
|
||||
area: '500px',
|
||||
content:"<div class='bt-form pd15'>\
|
||||
<div class='divtable mtb10'>\
|
||||
"+dataSource+"\
|
||||
<span id='full_msg'></span>\
|
||||
<div class='progress'>\
|
||||
<div class='progress-bar' role='progressbar' aria-valuenow='0' aria-valuemin='0' aria-valuemax='100' style='min-width: 2em;'>0%</div>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class='table_toolbar' style='left:0px;'>\
|
||||
<span data-status='init' class='sync btn btn-default btn-sm' id='begin_full_sync'>开始</span>\
|
||||
</div>\
|
||||
</div>",
|
||||
cancel: function(){
|
||||
clearInterval(timeId);
|
||||
},
|
||||
success:function(){
|
||||
$('#begin_full_sync').click(function(){
|
||||
var val = $(this).data('status');
|
||||
var sign = '';
|
||||
if (dataSource !=''){
|
||||
sign = $('select[name="data_source"]').val();
|
||||
}
|
||||
if (val == 'init'){
|
||||
fullSync(db, sign, 1);
|
||||
timeId = setInterval(function(){
|
||||
fullSync(db,sign,0);
|
||||
}, 1000);
|
||||
$(this).data('status','starting');
|
||||
} else {
|
||||
layer.msg("正在同步中..",{icon:0});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function fullSync(db,begin){
|
||||
function fullSync(db,sign,begin){
|
||||
|
||||
myPostN('full_sync', {db:db,begin:begin}, function(data){
|
||||
myPostN('full_sync', {db:db,sign:sign,begin:begin}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
$('#full_msg').text(rdata['msg']);
|
||||
$('.progress-bar').css('width',rdata['progress']+'%');
|
||||
@@ -1734,23 +1751,10 @@ function getFullSyncStatus(db){
|
||||
if (rdata['code']==6 ||rdata['code']<0){
|
||||
layer.msg(rdata['msg']);
|
||||
clearInterval(timeId);
|
||||
$("#begin_full_sync").attr('data-status','init');
|
||||
$("#begin_full_sync").data('data','init');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$('#begin_full_sync').click(function(){
|
||||
var val = $(this).attr('data-status');
|
||||
if (val == 'init'){
|
||||
fullSync(db,1);
|
||||
timeId = setInterval(function(){
|
||||
fullSync(db,0);
|
||||
}, 1000);
|
||||
$(this).attr('data-status','starting');
|
||||
} else {
|
||||
layer.msg("正在同步中..");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function addSlaveSSH(ip=''){
|
||||
@@ -1920,18 +1924,29 @@ function addSlaveSyncUser(ip=''){
|
||||
<div class='line'><span class='tname'>同步账户</span><div class='info-r'><input name='user' class='bt-input-text mr5' type='text' style='width:330px;' value='"+user+"'></div></div>\
|
||||
<div class='line'><span class='tname'>同步密码</span><div class='info-r'><input name='pass' class='bt-input-text mr5' type='text' style='width:330px;' value='"+pass+"'></div></div>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>CMD[最好填好]</span>\
|
||||
<span class='tname'>CMD[必须填写]</span>\
|
||||
<div class='info-r'><textarea class='bt-input-text mr5' row='20' cols='30' name='cmd' style='width:330px;height:150px;'></textarea></div>\
|
||||
</div>\
|
||||
<input type='hidden' name='mode' value='"+mode+"' />\
|
||||
</form>",
|
||||
success:function(){
|
||||
$('textarea[name="cmd"]').html(cmd);
|
||||
|
||||
$('textarea[name="cmd"]').change(function(){
|
||||
var val = $(this).val();
|
||||
var vlist = val.split(',');
|
||||
var a = {};
|
||||
if (val.toLowerCase().indexOf('for')>0){
|
||||
cmd_tmp = val.split('for');
|
||||
val = cmd_tmp[0].trim();
|
||||
|
||||
const channel_str = cmd_tmp[1].trim();
|
||||
const ch_reg = /channel \'(.*)\';/;
|
||||
var match_val = channel_str.match(ch_reg);
|
||||
if (match_val.length>1){
|
||||
a['channel'] = match_val[1];
|
||||
}
|
||||
}
|
||||
|
||||
var vlist = val.split(',');
|
||||
for (var i in vlist) {
|
||||
var tmp = toTrim(vlist[i]);
|
||||
var tmp_a = tmp.split(" ");
|
||||
@@ -2098,7 +2113,7 @@ function getSlaveUserList(){
|
||||
layerId = layer.open({
|
||||
type: 1,
|
||||
title: '同步账户列表',
|
||||
area: '500px',
|
||||
area: '600px',
|
||||
content:"<div class='bt-form pd20 c6'>\
|
||||
<div class='divtable mtb10'>\
|
||||
<div><table class='table table-hover get-slave-ssh-list'>\
|
||||
@@ -2122,7 +2137,7 @@ function getSlaveSSHList(page=1){
|
||||
layerId = layer.open({
|
||||
type: 1,
|
||||
title: 'SSH列表',
|
||||
area: '500px',
|
||||
area: '600px',
|
||||
content:"<div class='bt-form pd20 c6'>\
|
||||
<div class='divtable mtb10'>\
|
||||
<div><table class='table table-hover get-slave-ssh-list'>\
|
||||
@@ -2230,10 +2245,16 @@ function masterOrSlaveConf(version=''){
|
||||
myPost('get_slave_list', _data, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
var list = '';
|
||||
|
||||
var isHasSign = false;
|
||||
for(i in rdata.data){
|
||||
|
||||
var v = rdata.data[i];
|
||||
var status = "<a class='btlink db_error'>异常</>";
|
||||
if ('Channel_Name' in v){
|
||||
isHasSign = true;
|
||||
}
|
||||
|
||||
var status = "<a data-id="+i+" class='btlink db_error'>异常</>";
|
||||
if (v['Slave_SQL_Running'] == 'Yes' && v['Slave_IO_Running'] == 'Yes'){
|
||||
status = "正常";
|
||||
}
|
||||
@@ -2245,13 +2266,23 @@ function masterOrSlaveConf(version=''){
|
||||
list += '<td>' + rdata.data[i]['Master_Log_File'] +'</td>';
|
||||
list += '<td>' + rdata.data[i]['Slave_IO_Running'] +'</td>';
|
||||
list += '<td>' + rdata.data[i]['Slave_SQL_Running'] +'</td>';
|
||||
|
||||
if (isHasSign){
|
||||
list += '<td>' + v['Channel_Name'] +'</td>';
|
||||
}
|
||||
|
||||
list += '<td>' + status +'</td>';
|
||||
list += '<td style="text-align:right">' +
|
||||
'<a href="javascript:;" class="btlink" onclick="deleteSlave()" title="删除">删除</a>' +
|
||||
'<a data-id="'+i+'" href="javascript:;" class="btlink btn_delete_slave" title="删除">删除</a>' +
|
||||
'</td>';
|
||||
list += '</tr>';
|
||||
}
|
||||
|
||||
var signThead_th = '';
|
||||
if (isHasSign){
|
||||
var signThead_th = '<th>标识</th>';
|
||||
}
|
||||
|
||||
var con = '<div class="divtable mtb10">\
|
||||
<div class="tablescroll">\
|
||||
<table id="DataBody" class="table table-hover" width="100%" cellspacing="0" cellpadding="0" border="0" style="border: 0 none;">\
|
||||
@@ -2262,6 +2293,7 @@ function masterOrSlaveConf(version=''){
|
||||
<th>日志</th>\
|
||||
<th>IO</th>\
|
||||
<th>SQL</th>\
|
||||
'+signThead_th+'\
|
||||
<th>状态</th>\
|
||||
<th style="text-align:right;">操作</th></tr></thead>\
|
||||
<tbody>\
|
||||
@@ -2276,22 +2308,74 @@ function masterOrSlaveConf(version=''){
|
||||
// </div>
|
||||
$(".table_slave_status_list").html(con);
|
||||
|
||||
$('.db_error').click(function(){
|
||||
$(".btn_delete_slave").click(function(){
|
||||
var id = $(this).data('id');
|
||||
var v = rdata.data[id];
|
||||
if ('Channel_Name' in v){
|
||||
deleteSlave(v['Channel_Name']);
|
||||
} else{
|
||||
deleteSlave();
|
||||
}
|
||||
});
|
||||
|
||||
$('.db_error').click(function(){
|
||||
var id = $(this).data('id');
|
||||
var info = rdata.data[id];
|
||||
|
||||
var err_line = "";
|
||||
err_line +="<tr>\
|
||||
<td>IO错误</td>\
|
||||
<td>"+ (info['Last_IO_Error'] == '' ? '无':info['Last_IO_Error'])+"</td>\
|
||||
</tr>";
|
||||
err_line +="<tr>\
|
||||
<td>SQL错误</td>\
|
||||
<td>"+(info['Last_SQL_Error'] == '' ? '无':info['Last_SQL_Error'])+"</td>\
|
||||
</tr>";
|
||||
|
||||
err_line +="<tr>\
|
||||
<td>状态</td>\
|
||||
<td>"+(info['Slave_SQL_Running_State'] == '' ? '无':info['Slave_SQL_Running_State']) +"</td>\
|
||||
</tr>";
|
||||
|
||||
layer.open({
|
||||
type: 1,
|
||||
title: '同步异常信息',
|
||||
area: '500px',
|
||||
content:"<form class='bt-form pd20 pb70'>\
|
||||
<div class='line'>"+v['Error']+"</div>\
|
||||
<div class='bt-form-submit-btn'>\
|
||||
<button type='button' class='btn btn-success btn-sm btn-title class-copy-db-err'>复制</button>\
|
||||
area: ['600px','300px'],
|
||||
btn:['复制错误',"取消"],
|
||||
content:"<form class='bt-form pd15'>\
|
||||
<div class='divtable mtb10'>\
|
||||
<div class='tablescroll'>\
|
||||
<table class='table table-hover' width='100%' cellspacing='0' cellpadding='0' border='0' style='border: 0 none;'>\
|
||||
<thead><tr>\
|
||||
<th style='width:80px;'>类型</th>\
|
||||
<th>内容</th>\
|
||||
</tr></thead>\
|
||||
<tbody>"+ err_line +"</tbody>\
|
||||
</table>\
|
||||
</div>\
|
||||
</div>\
|
||||
</form>",
|
||||
</form>",
|
||||
success:function(){
|
||||
copyText(v['Error']);
|
||||
$('.class-copy-db-err').click(function(){
|
||||
copyText(v['Error']);
|
||||
});
|
||||
// copyText(v['Error']);
|
||||
// $('.class-copy-db-err').click(function(){
|
||||
// copyText(v['Error']);
|
||||
// });
|
||||
},
|
||||
yes:function(){
|
||||
if (info['Last_IO_Error'] != ''){
|
||||
copyText(info['Last_IO_Error']);
|
||||
return;
|
||||
}
|
||||
|
||||
if (info['Last_SQL_Error'] != ''){
|
||||
copyText(info['Last_SQL_Error']);
|
||||
return;
|
||||
}
|
||||
|
||||
if (info['Slave_SQL_Running_State'] != ''){
|
||||
copyText(info['Slave_SQL_Running_State']);
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -35,7 +35,22 @@ if [ "$OSNAME" == "ubuntu" ];then
|
||||
VERSION_ID="18.04"
|
||||
fi
|
||||
|
||||
SUFFIX_NAME=${MYSQL_VER}-1${OSNAME}${VERSION_ID}_amd64
|
||||
ARCH="amd64"
|
||||
TMP_ARCH=`arch`
|
||||
if [ "$TMP_ARCH" == "x86_64" ];then
|
||||
ARCH="amd64"
|
||||
elif [ "$TMP_ARCH" == "aarch64" ];then
|
||||
ARCH="arm64"
|
||||
else
|
||||
ARCH="amd64"
|
||||
fi
|
||||
|
||||
if [ "$ARCH" != "amd64" ];then
|
||||
echo "暂时不支持该${ARCH}" > $install_tmp
|
||||
exit 0
|
||||
fi
|
||||
|
||||
SUFFIX_NAME=${MYSQL_VER}-1${OSNAME}${VERSION_ID}_${ARCH}
|
||||
|
||||
APT_INSTALL()
|
||||
{
|
||||
|
||||
@@ -22,8 +22,25 @@ VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -
|
||||
|
||||
# cd /www/server/mdserver-web/plugins/mysql-apt && bash install.sh install 8.0
|
||||
|
||||
|
||||
ARCH="amd64"
|
||||
TMP_ARCH=`arch`
|
||||
if [ "$TMP_ARCH" == "x86_64" ];then
|
||||
ARCH="amd64"
|
||||
elif [ "$TMP_ARCH" == "aarch64" ];then
|
||||
ARCH="arm64"
|
||||
else
|
||||
ARCH="amd64"
|
||||
fi
|
||||
|
||||
if [ "$ARCH" != "amd64" ];then
|
||||
echo "暂时不支持该${ARCH}" > $install_tmp
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
MYSQL_VER=8.0.30
|
||||
SUFFIX_NAME=${MYSQL_VER}-1${OSNAME}${VERSION_ID}_amd64
|
||||
SUFFIX_NAME=${MYSQL_VER}-1${OSNAME}${VERSION_ID}_${ARCH}
|
||||
|
||||
|
||||
# /lib/systemd/system/mysql.service
|
||||
@@ -81,7 +98,6 @@ Install_mysql()
|
||||
useradd -g mysql mysql
|
||||
fi
|
||||
|
||||
|
||||
isApt=`which apt`
|
||||
if [ "$isApt" != "" ];then
|
||||
APT_INSTALL
|
||||
|
||||
@@ -14,6 +14,9 @@ port = 33206
|
||||
socket = {$SERVER_APP_PATH}/mysql.sock
|
||||
datadir = {$SERVER_APP_PATH}/data
|
||||
log-error = {$SERVER_APP_PATH}/data/error.log
|
||||
server-id = {$SERVER_ID}
|
||||
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
|
||||
|
||||
default_storage_engine = InnoDB
|
||||
language={$SERVER_APP_PATH}/bin/usr/share/mysql/english
|
||||
|
||||
@@ -46,7 +49,6 @@ skip-ssl
|
||||
|
||||
log-bin=mysql-bin
|
||||
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
|
||||
@@ -66,12 +68,15 @@ binlog-ignore-db = performance_schema
|
||||
#slave
|
||||
log-slave-updates
|
||||
#replicate-do-db
|
||||
slave_skip_errors=1062
|
||||
slave_skip_errors=1062,1396
|
||||
replicate-ignore-db = information_schema
|
||||
replicate-ignore-db = performance_schema
|
||||
replicate-ignore-db = mysql
|
||||
replicate-ignore-db = test
|
||||
|
||||
master_info_repository = table
|
||||
relay_log_info_repository = table
|
||||
|
||||
default_storage_engine = InnoDB
|
||||
innodb_data_home_dir = {$SERVER_APP_PATH}/data
|
||||
innodb_data_file_path = ibdata1:10M:autoextend
|
||||
|
||||
@@ -16,6 +16,9 @@ mysqlx_port = 33260
|
||||
socket = {$SERVER_APP_PATH}/mysql.sock
|
||||
datadir = {$SERVER_APP_PATH}/data
|
||||
log-error = {$SERVER_APP_PATH}/data/error.log
|
||||
server-id = {$SERVER_ID}
|
||||
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
|
||||
|
||||
default_storage_engine = InnoDB
|
||||
|
||||
key_buffer_size = 8M
|
||||
@@ -43,7 +46,6 @@ max_allowed_packet = 128M
|
||||
|
||||
log-bin=mysql-bin
|
||||
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
|
||||
@@ -62,12 +64,15 @@ binlog-ignore-db = performance_schema
|
||||
#slave
|
||||
log_replica_updates
|
||||
#replicate-do-db
|
||||
slave_skip_errors=1062
|
||||
slave_skip_errors=1062,1396
|
||||
replicate-ignore-db = information_schema
|
||||
replicate-ignore-db = performance_schema
|
||||
replicate-ignore-db = mysql
|
||||
replicate-ignore-db = test
|
||||
|
||||
master_info_repository = table
|
||||
relay_log_info_repository = table
|
||||
|
||||
default_storage_engine = InnoDB
|
||||
innodb_data_home_dir = {$SERVER_APP_PATH}/data
|
||||
innodb_data_file_path = ibdata1:10M:autoextend
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<p onclick="dbList()">管理列表</p>
|
||||
<p onclick="masterOrSlaveConf($('.plugin_version').attr('version'))">主从配置</p>
|
||||
</div>
|
||||
<div class="bt-w-con pd15">
|
||||
<div class="bt-w-con pd15" style="height:555px;overflow: auto;">
|
||||
<div class="soft-man-con"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+230
-153
@@ -36,6 +36,10 @@ def getPluginDir():
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getSPluginDir():
|
||||
return '/www/server/mdserver-web/plugins/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
@@ -101,6 +105,14 @@ def getDbPort():
|
||||
return tmp.groups()[0].strip()
|
||||
|
||||
|
||||
def getDbServerId():
|
||||
file = getConf()
|
||||
content = mw.readFile(file)
|
||||
rep = 'server-id\s*=\s*(.*)'
|
||||
tmp = re.search(rep, content)
|
||||
return tmp.groups()[0].strip()
|
||||
|
||||
|
||||
def getSocketFile():
|
||||
file = getConf()
|
||||
content = mw.readFile(file)
|
||||
@@ -123,6 +135,9 @@ def contentReplace(content):
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
content = content.replace('{$SERVER_APP_PATH}',
|
||||
service_path + '/' + getPluginName())
|
||||
|
||||
server_id = int(time.time())
|
||||
content = content.replace('{$SERVER_ID}', str(server_id))
|
||||
return content
|
||||
|
||||
|
||||
@@ -640,15 +655,15 @@ def isSqlError(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:
|
||||
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:
|
||||
if "1133," in mysqlMsg:
|
||||
return mw.returnJson(False, '数据库用户不存在!')
|
||||
if "1007" in mysqlMsg:
|
||||
if "1007," in mysqlMsg:
|
||||
return mw.returnJson(False, '数据库已经存在!')
|
||||
return None
|
||||
|
||||
@@ -1863,27 +1878,34 @@ def getMasterRepSlaveUserCmd(version):
|
||||
|
||||
mode = recognizeDbMode()
|
||||
|
||||
sid = getDbServerId()
|
||||
channel_name = ""
|
||||
if sid != '':
|
||||
channel_name = " for channel 'r{}';".format(sid)
|
||||
|
||||
if mode == "gtid":
|
||||
sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \
|
||||
clist[0]['username'] + "', MASTER_PASSWORD='" + \
|
||||
clist[0]['password'] + "', MASTER_AUTO_POSITION=1"
|
||||
clist[0]['password'] + "', MASTER_AUTO_POSITION=1" + channel_name
|
||||
if version == '8.0':
|
||||
sql = "CHANGE REPLICATION SOURCE TO SOURCE_HOST='" + ip + "', SOURCE_PORT=" + port + ", SOURCE_USER='" + \
|
||||
clist[0]['username'] + "', SOURCE_PASSWORD='" + \
|
||||
clist[0]['password'] + "', MASTER_AUTO_POSITION=1"
|
||||
clist[0]['password'] + \
|
||||
"', MASTER_AUTO_POSITION=1" + channel_name
|
||||
else:
|
||||
sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \
|
||||
clist[0]['username'] + "', MASTER_PASSWORD='" + \
|
||||
clist[0]['password'] + \
|
||||
"', MASTER_LOG_FILE='" + mstatus[0]["File"] + \
|
||||
"',MASTER_LOG_POS=" + str(mstatus[0]["Position"])
|
||||
"',MASTER_LOG_POS=" + str(mstatus[0]["Position"]) + channel_name
|
||||
|
||||
if version == "8.0":
|
||||
sql = "CHANGE REPLICATION SOURCE TO SOURCE_HOST='" + ip + "', SOURCE_PORT=" + port + ", SOURCE_USER='" + \
|
||||
clist[0]['username'] + "', SOURCE_PASSWORD='" + \
|
||||
clist[0]['password'] + \
|
||||
"', SOURCE_LOG_FILE='" + mstatus[0]["File"] + \
|
||||
"',SOURCE_LOG_POS=" + str(mstatus[0]["Position"])
|
||||
"',SOURCE_LOG_POS=" + \
|
||||
str(mstatus[0]["Position"]) + channel_name
|
||||
|
||||
data = {}
|
||||
data['cmd'] = sql
|
||||
@@ -2154,22 +2176,10 @@ def updateSlaveSSH(version=''):
|
||||
|
||||
|
||||
def getSlaveList(version=''):
|
||||
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
ret = []
|
||||
for x in range(0, len(dlist)):
|
||||
tmp = {}
|
||||
tmp['Master_User'] = dlist[x]["Master_User"]
|
||||
tmp['Master_Host'] = dlist[x]["Master_Host"]
|
||||
tmp['Master_Port'] = dlist[x]["Master_Port"]
|
||||
tmp['Master_Log_File'] = dlist[x]["Master_Log_File"]
|
||||
tmp['Slave_IO_Running'] = dlist[x]["Slave_IO_Running"]
|
||||
tmp['Slave_SQL_Running'] = dlist[x]["Slave_SQL_Running"]
|
||||
ret.append(tmp)
|
||||
data = {}
|
||||
data['data'] = ret
|
||||
|
||||
data['data'] = dlist
|
||||
return mw.getJson(data)
|
||||
|
||||
|
||||
@@ -2193,100 +2203,149 @@ def initSlaveStatus(version=''):
|
||||
return initSlaveStatusSyncUser(version)
|
||||
|
||||
|
||||
def parseSlaveSyncCmd(cmd):
|
||||
a = {}
|
||||
if cmd.lower().find('for') > 0:
|
||||
cmd_tmp = cmd.split('for')
|
||||
cmd = cmd_tmp[0].strip()
|
||||
|
||||
pattern_c = r"channel \'(.*)\';"
|
||||
match_val = re.match(pattern_c, cmd_tmp[1].strip(), re.I)
|
||||
if match_val:
|
||||
m_groups = match_val.groups()
|
||||
a['channel'] = m_groups[0]
|
||||
vlist = cmd.split(',')
|
||||
for i in vlist:
|
||||
tmp = i.strip()
|
||||
tmp_a = tmp.split(" ")
|
||||
real_tmp = tmp_a[len(tmp_a) - 1]
|
||||
kv = real_tmp.split("=")
|
||||
a[kv[0]] = kv[1].replace("'", '').replace("'", '').replace(";", '')
|
||||
return a
|
||||
|
||||
|
||||
def initSlaveStatusSyncUser(version=''):
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
if len(data) < 1:
|
||||
slave_data = conn.field('ip,port,user,pass,mode,cmd').select()
|
||||
if len(slave_data) < 1:
|
||||
return mw.returnJson(False, '需要先添加同步用户配置!')
|
||||
|
||||
# print(data)
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
if len(dlist) > 0:
|
||||
return mw.returnJson(False, '已经初始化好了zz...')
|
||||
|
||||
u = data
|
||||
|
||||
mode_name = 'classic'
|
||||
if u['mode'] == '1':
|
||||
mode_name = 'gtid'
|
||||
pdb = pMysqlDb()
|
||||
if len(slave_data) == 1:
|
||||
dlist = pdb.query('show slave status')
|
||||
if len(dlist) > 0:
|
||||
return mw.returnJson(False, '已经初始化好了zz...')
|
||||
|
||||
msg = ''
|
||||
local_mode = recognizeDbMode()
|
||||
if local_mode != mode_name:
|
||||
return mw.returnJson(False, '同步模式不一致!')
|
||||
for x in range(len(slave_data)):
|
||||
slave_t = slave_data[x]
|
||||
mode_name = 'classic'
|
||||
base_t = 'IP:' + slave_t['ip'] + ",PORT:" + \
|
||||
slave_t['port'] + ",USER:" + slave_t['user']
|
||||
|
||||
t = db.query(u['cmd'])
|
||||
# print(t)
|
||||
db.query("start slave user='{}' password='{}';".format(
|
||||
u['user'], u['pass']))
|
||||
return mw.returnJson(True, '初始化成功!')
|
||||
if slave_t['mode'] == '1':
|
||||
mode_name = 'gtid'
|
||||
|
||||
if local_mode != mode_name:
|
||||
msg += base_t + '->同步模式不一致'
|
||||
continue
|
||||
|
||||
cmd_sql = slave_t['cmd']
|
||||
if cmd_sql == '':
|
||||
msg += base_t + '->同步命令不能为空'
|
||||
continue
|
||||
|
||||
try:
|
||||
pinfo = parseSlaveSyncCmd(cmd_sql)
|
||||
except Exception as e:
|
||||
return mw.returnJson(False, base_t + '->CMD同步命令不合规范!')
|
||||
# print(u['cmd'])
|
||||
t = pdb.query(cmd_sql)
|
||||
isError = isSqlError(t)
|
||||
if isError:
|
||||
return isError
|
||||
|
||||
# pdb.query("start slave user='{}' password='{}';".format(
|
||||
# u['user'], u['pass']))
|
||||
|
||||
pdb.query("start slave")
|
||||
pdb.query("start all slaves")
|
||||
|
||||
if msg == '':
|
||||
msg = '初始化成功!'
|
||||
return mw.returnJson(True, msg)
|
||||
|
||||
|
||||
def initSlaveStatusSSH(version=''):
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
if len(dlist) > 0:
|
||||
return mw.returnJson(False, '已经初始化好了zz...')
|
||||
|
||||
conn = pSqliteDb('slave_id_rsa')
|
||||
data = conn.field('ip,port,id_rsa').find()
|
||||
ssh_list = conn.field('ip,port,id_rsa,db_user').select()
|
||||
|
||||
if len(data) < 1:
|
||||
if len(ssh_list) < 1:
|
||||
return mw.returnJson(False, '需要先配置【[主]SSH配置】!')
|
||||
|
||||
SSH_PRIVATE_KEY = "/tmp/t_ssh.txt"
|
||||
ip = data['ip']
|
||||
master_port = data['port']
|
||||
mw.writeFile(SSH_PRIVATE_KEY, data['id_rsa'].replace('\\n', '\n'))
|
||||
local_mode = recognizeDbMode()
|
||||
|
||||
import paramiko
|
||||
paramiko.util.log_to_file('paramiko.log')
|
||||
ssh = paramiko.SSHClient()
|
||||
|
||||
try:
|
||||
|
||||
db.query('stop slave')
|
||||
db.query('reset slave all')
|
||||
for data in ssh_list:
|
||||
ip = data['ip']
|
||||
SSH_PRIVATE_KEY = "/tmp/t_ssh_" + ip + ".txt"
|
||||
master_port = data['port']
|
||||
mw.writeFile(SSH_PRIVATE_KEY, data['id_rsa'].replace('\\n', '\n'))
|
||||
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=int(master_port),
|
||||
username='root', pkey=key)
|
||||
try:
|
||||
key = paramiko.RSAKey.from_private_key_file(SSH_PRIVATE_KEY)
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect(hostname=ip, port=int(master_port),
|
||||
username='root', pkey=key)
|
||||
|
||||
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 = result.decode('utf-8')
|
||||
cmd_data = json.loads(result)
|
||||
db_user = data['db_user']
|
||||
cmd = 'cd /www/server/mdserver-web && source bin/activate && python3 plugins/mysql-yum/index.py get_master_rep_slave_user_cmd {"username":"' + db_user + '","db":""}'
|
||||
stdin, stdout, stderr = ssh.exec_command(cmd)
|
||||
result = stdout.read()
|
||||
result = result.decode('utf-8')
|
||||
if result.strip() == "":
|
||||
return mw.returnJson(False, '[主][' + ip + ']:获取同步命令失败!')
|
||||
|
||||
if not cmd_data['status']:
|
||||
return mw.returnJson(False, '[主]:' + cmd_data['msg'])
|
||||
cmd_data = json.loads(result)
|
||||
if not cmd_data['status']:
|
||||
return mw.returnJson(False, '[主][' + ip + ']:' + cmd_data['msg'])
|
||||
|
||||
local_mode = recognizeDbMode()
|
||||
if local_mode != cmd_data['data']['mode']:
|
||||
return mw.returnJson(False, '主【{}】从【{}】,运行模式不一致!'.format(cmd_data['data']['mode'], local_mode))
|
||||
if local_mode != cmd_data['data']['mode']:
|
||||
return mw.returnJson(False, '[主][' + ip + ']:【{}】从【{}】,运行模式不一致!'.format(cmd_data['data']['mode'], local_mode))
|
||||
|
||||
u = cmd_data['data']['info']
|
||||
ps = u['username'] + "|" + u['password']
|
||||
conn.where('ip=?', (ip,)).setField('ps', ps)
|
||||
db.query('stop slave')
|
||||
u = cmd_data['data']['info']
|
||||
|
||||
# 保证同步IP一致
|
||||
cmd = cmd_data['data']['cmd']
|
||||
if cmd.find('SOURCE_HOST') > -1:
|
||||
cmd = re.sub(r"SOURCE_HOST='(.*)'",
|
||||
"SOURCE_HOST='" + ip + "'", cmd, 1)
|
||||
ps = u['username'] + "|" + u['password']
|
||||
print(ps)
|
||||
conn.where('ip=?', (ip,)).setField('ps', ps)
|
||||
db.query('stop slave')
|
||||
|
||||
if cmd.find('MASTER_HOST') > -1:
|
||||
cmd = re.sub(r"MASTER_HOST='(.*)'",
|
||||
"MASTER_HOST='" + ip + "'", cmd, 1)
|
||||
db.query(cmd)
|
||||
db.query("start slave user='{}' password='{}';".format(
|
||||
u['username'], u['password']))
|
||||
except Exception as e:
|
||||
return mw.returnJson(False, 'SSH认证配置连接失败!' + str(e))
|
||||
# 保证同步IP一致
|
||||
cmd = cmd_data['data']['cmd']
|
||||
if cmd.find('SOURCE_HOST') > -1:
|
||||
cmd = re.sub(r"SOURCE_HOST='(.*?)'",
|
||||
"SOURCE_HOST='" + ip + "'", cmd, 1)
|
||||
|
||||
ssh.close()
|
||||
time.sleep(1)
|
||||
os.system("rm -rf " + SSH_PRIVATE_KEY)
|
||||
if cmd.find('MASTER_HOST') > -1:
|
||||
cmd = re.sub(r"MASTER_HOST='(.*?)'",
|
||||
"MASTER_HOST='" + ip + "'", cmd, 1)
|
||||
db.query(cmd)
|
||||
ssh.close()
|
||||
if os.path.exists(SSH_PRIVATE_KEY):
|
||||
os.system("rm -rf " + SSH_PRIVATE_KEY)
|
||||
except Exception as e:
|
||||
return mw.returnJson(False, '[主][' + ip + ']:SSH认证配置连接失败!' + str(e))
|
||||
db.query('start slave')
|
||||
return mw.returnJson(True, '初始化成功!')
|
||||
|
||||
|
||||
@@ -2296,60 +2355,37 @@ def setSlaveStatus(version=''):
|
||||
return mw.returnJson(False, '需要先设置同步配置')
|
||||
|
||||
mode = mw.readFile(mode_file)
|
||||
if mode == 'ssh':
|
||||
return setSlaveStatusSSH(version)
|
||||
if mode == 'sync-user':
|
||||
return setSlaveStatusSyncUser(version)
|
||||
|
||||
|
||||
def setSlaveStatusSyncUser(version=''):
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
pdb = pMysqlDb()
|
||||
dlist = pdb.query('show slave status')
|
||||
if len(dlist) == 0:
|
||||
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:
|
||||
ip = dlist[0]['Master_Host']
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
if len(data) == 0:
|
||||
return mw.returnJson(False, '没有数据无法重启!')
|
||||
user = data['user']
|
||||
apass = data['pass']
|
||||
for v in dlist:
|
||||
connection_name = ''
|
||||
cmd = "slave"
|
||||
if 'Channel_Name' in v:
|
||||
ch_name = v['Channel_Name']
|
||||
cmd = "slave for channel '{}'".format(ch_name)
|
||||
|
||||
db.query("start slave")
|
||||
# db.query("start slave user='{}' password='{}';".format(user, apass))
|
||||
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def setSlaveStatusSSH(version=''):
|
||||
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
if len(dlist) == 0:
|
||||
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:
|
||||
ip = dlist[0]['Master_Host']
|
||||
conn = pSqliteDb('slave_id_rsa')
|
||||
data = conn.field('ip,ps').where("ip=?", (ip,)).find()
|
||||
if len(data) == 0:
|
||||
return mw.returnJson(False, '没有数据无法重启!')
|
||||
u = data['ps'].split("|")
|
||||
db.query("start slave user='{}' password='{}';".format(u[0], u[1]))
|
||||
if (v["Slave_IO_Running"] == 'Yes' or v["Slave_SQL_Running"] == 'Yes'):
|
||||
pdb.query("stop {}".format(cmd))
|
||||
else:
|
||||
pdb.query("start {}".format(cmd))
|
||||
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def deleteSlave(version=''):
|
||||
args = getArgs()
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('stop slave')
|
||||
dlist = db.query('reset slave all')
|
||||
if 'sign' in args:
|
||||
sign = args['sign']
|
||||
db.query("stop slave for channel '{}'".format(sign))
|
||||
db.query("reset slave all for channel '{}'".format(sign))
|
||||
else:
|
||||
db.query('stop slave')
|
||||
db.query('reset slave all')
|
||||
|
||||
return mw.returnJson(True, '删除成功!')
|
||||
|
||||
|
||||
@@ -2385,11 +2421,13 @@ def dumpMysqlData(version=''):
|
||||
|
||||
############### --- 重要 同步---- ###########
|
||||
|
||||
def asyncTmpfile():
|
||||
path = '/tmp/mysql_yum_async_status.txt'
|
||||
return path
|
||||
|
||||
|
||||
def writeDbSyncStatus(data):
|
||||
path = '/tmp/db_async_status.txt'
|
||||
# status_data['code'] = 1
|
||||
# status_data['msg'] = '主服务器备份完成...'
|
||||
# status_data['progress'] = 30
|
||||
path = asyncTmpfile()
|
||||
mw.writeFile(path, json.dumps(data))
|
||||
|
||||
|
||||
@@ -2407,16 +2445,32 @@ def doFullSync(version=''):
|
||||
|
||||
def doFullSyncUser(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['db'])
|
||||
data = checkArgs(args, ['db', 'sign'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
sync_db = args['db']
|
||||
sync_db_import = args['db']
|
||||
|
||||
if sync_db.lower() == 'all':
|
||||
sync_db_import = ''
|
||||
dbs = findBinlogSlaveDoDb()
|
||||
dbs_str = ''
|
||||
for x in dbs:
|
||||
dbs_str += ' ' + x
|
||||
sync_db = "--databases " + dbs_str.strip()
|
||||
|
||||
sync_sign = args['sign']
|
||||
|
||||
db = pMysqlDb()
|
||||
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
if sync_sign != '':
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').where(
|
||||
'ip=?', (sync_sign,)).find()
|
||||
else:
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
|
||||
user = data['user']
|
||||
apass = data['pass']
|
||||
port = data['port']
|
||||
@@ -2433,17 +2487,18 @@ def doFullSyncUser(version=''):
|
||||
writeDbSyncStatus({'code': 1, 'msg': '远程导出数据...', 'progress': 20})
|
||||
|
||||
if not os.path.exists(bak_file):
|
||||
dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --force --opt --default-character-set=utf8 --single-transaction -h" + ip + " -P" + \
|
||||
port + " -u" + user + " -p" + apass + \
|
||||
" --ssl-mode=DISABLED " + sync_db + " > " + bak_file
|
||||
dump_sql_data = getServerDir() + "/bin/usr/bin/mysqldump " + dmp_option + " --force --opt --default-character-set=utf8 --single-transaction -h" + ip + " -P" + \
|
||||
port + " -u" + user + " -p\"" + apass + \
|
||||
"\" --ssl-mode=DISABLED " + sync_db + " > " + bak_file
|
||||
# print(dump_sql_data)
|
||||
mw.execShell(dump_sql_data)
|
||||
|
||||
writeDbSyncStatus({'code': 2, 'msg': '本地导入数据...', 'progress': 40})
|
||||
if os.path.exists(bak_file):
|
||||
pwd = pSqliteDb('config').where('id=?', (1,)).getField('mysql_root')
|
||||
sock = getSocketFile()
|
||||
my_import_cmd = getServerDir() + '/bin/mysql -S ' + sock + ' -uroot -p' + pwd + \
|
||||
' ' + sync_db + ' < ' + bak_file
|
||||
my_import_cmd = getServerDir() + '/bin/usr/bin/mysql -S ' + sock + ' -uroot -p' + pwd + \
|
||||
' ' + sync_db_import + ' < ' + bak_file
|
||||
mw.execShell(my_import_cmd)
|
||||
|
||||
if version == '8.0':
|
||||
@@ -2452,21 +2507,30 @@ def doFullSyncUser(version=''):
|
||||
db.query("start slave")
|
||||
|
||||
writeDbSyncStatus({'code': 6, 'msg': '从库重启完成...', 'progress': 100})
|
||||
os.system("rm -rf " + bak_file)
|
||||
|
||||
if os.path.exists(bak_file):
|
||||
os.system("rm -rf " + bak_file)
|
||||
return True
|
||||
|
||||
|
||||
def doFullSyncSSH(version=''):
|
||||
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['db'])
|
||||
data = checkArgs(args, ['db', 'sign'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
sync_db = args['db']
|
||||
sync_sign = args['sign']
|
||||
|
||||
db = pMysqlDb()
|
||||
|
||||
id_rsa_conn = pSqliteDb('slave_id_rsa')
|
||||
data = id_rsa_conn.field('ip,port,db_user,id_rsa').find()
|
||||
if sync_sign != '':
|
||||
data = id_rsa_conn.field('ip,port,db_user,id_rsa').where(
|
||||
'ip=?', (sync_sign,)).find()
|
||||
else:
|
||||
data = id_rsa_conn.field('ip,port,db_user,id_rsa').find()
|
||||
|
||||
SSH_PRIVATE_KEY = "/tmp/mysql_sync_id_rsa.txt"
|
||||
id_rsa = data['id_rsa'].replace('\\n', '\n')
|
||||
@@ -2508,7 +2572,8 @@ def doFullSyncSSH(version=''):
|
||||
writeDbSyncStatus({'code': 0, 'msg': '登录Master成功...', 'progress': 5})
|
||||
|
||||
dbname = args['db']
|
||||
cmd = "cd /www/server/mdserver-web && python3 plugins/mysql/index.py dump_mysql_data {\"db\":'" + dbname + "'}"
|
||||
cmd = "cd /www/server/mdserver-web && source bin/activate && python3 " + \
|
||||
getSPluginDir() + "/index.py dump_mysql_data {\"db\":'" + dbname + "'}"
|
||||
print(cmd)
|
||||
stdin, stdout, stderr = ssh.exec_command(cmd)
|
||||
result = stdout.read()
|
||||
@@ -2531,7 +2596,10 @@ def doFullSyncSSH(version=''):
|
||||
if copy_status == None:
|
||||
writeDbSyncStatus({'code': 2, 'msg': '数据同步本地完成...', 'progress': 40})
|
||||
|
||||
cmd = 'cd /www/server/mdserver-web && python3 plugins/mysql/index.py get_master_rep_slave_user_cmd {"username":"' + db_user + '","db":""}'
|
||||
cmd = 'cd /www/server/mdserver-web && source bin/activate && python3 ' + \
|
||||
getSPluginDir() + \
|
||||
'/index.py get_master_rep_slave_user_cmd {"username":"' + \
|
||||
db_user + '","db":""}'
|
||||
stdin, stdout, stderr = ssh.exec_command(cmd)
|
||||
result = stdout.read()
|
||||
result = result.decode('utf-8')
|
||||
@@ -2543,10 +2611,12 @@ def doFullSyncSSH(version=''):
|
||||
cmd = cmd_data['data']['cmd']
|
||||
# 保证同步IP一致
|
||||
if cmd.find('SOURCE_HOST') > -1:
|
||||
cmd = re.sub(r"SOURCE_HOST='(.*)'", "SOURCE_HOST='" + ip + "'", cmd, 1)
|
||||
cmd = re.sub(r"SOURCE_HOST='(.*?)'",
|
||||
"SOURCE_HOST='" + ip + "'", cmd, 1)
|
||||
|
||||
if cmd.find('MASTER_HOST') > -1:
|
||||
cmd = re.sub(r"MASTER_HOST='(.*)'", "SOURCE_HOST='" + ip + "'", cmd, 1)
|
||||
cmd = re.sub(r"MASTER_HOST='(.*?)'",
|
||||
"MASTER_HOST='" + ip + "'", cmd, 1)
|
||||
|
||||
db.query(cmd)
|
||||
uinfo = cmd_data['data']['info']
|
||||
@@ -2558,8 +2628,10 @@ def doFullSyncSSH(version=''):
|
||||
root_dir = getServerDir()
|
||||
msock = root_dir + "/mysql.sock"
|
||||
mw.execShell("cd /tmp && gzip -d dump.sql.gz")
|
||||
cmd = root_dir + "/bin/mysql -S " + msock + \
|
||||
cmd = root_dir + "/bin/usr/bin/mysql -S " + msock + \
|
||||
" -uroot -p" + pwd + " < /tmp/dump.sql"
|
||||
|
||||
print(cmd)
|
||||
import_data = mw.execShell(cmd)
|
||||
if import_data[0] == '':
|
||||
print(import_data[1])
|
||||
@@ -2569,8 +2641,9 @@ def doFullSyncSSH(version=''):
|
||||
writeDbSyncStatus({'code': 5, 'msg': '导入数据失败...', 'progress': 100})
|
||||
return 'fail'
|
||||
|
||||
db.query("start slave user='{}' password='{}';".format(
|
||||
uinfo['username'], uinfo['password']))
|
||||
# "start slave user='{}' password='{}';".format(uinfo['username'], uinfo['password'])
|
||||
|
||||
db.query("start slave")
|
||||
writeDbSyncStatus({'code': 6, 'msg': '从库重启完成...', 'progress': 100})
|
||||
|
||||
os.system("rm -rf " + SSH_PRIVATE_KEY)
|
||||
@@ -2584,12 +2657,16 @@ def fullSync(version=''):
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
status_file = '/tmp/db_async_status.txt'
|
||||
sign = ''
|
||||
if 'sign' in args:
|
||||
sign = args['sign']
|
||||
|
||||
status_file = asyncTmpfile()
|
||||
if args['begin'] == '1':
|
||||
cmd = 'cd ' + mw.getRunDir() + ' && python3 ' + \
|
||||
getPluginDir() + \
|
||||
'/index.py do_full_sync {"db":"' + args['db'] + '"} &'
|
||||
print(cmd)
|
||||
cmd = 'cd ' + mw.getRunDir() + ' && python3 ' + getPluginDir() + \
|
||||
'/index.py do_full_sync {"db":"' + \
|
||||
args['db'] + '","sign":"' + sign + '"} &'
|
||||
# print(cmd)
|
||||
mw.execShell(cmd)
|
||||
return json.dumps({'code': 0, 'msg': '同步数据中!', 'progress': 0})
|
||||
|
||||
|
||||
@@ -162,34 +162,6 @@ function myPort(){
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//数据库存储信置
|
||||
function changeMySQLDataPath(act) {
|
||||
if (act != undefined) {
|
||||
layer.confirm(lan.soft.mysql_to_msg, { closeBtn: 2, icon: 3 }, function() {
|
||||
var datadir = $("#datadir").val();
|
||||
var data = 'datadir=' + datadir;
|
||||
var loadT = layer.msg(lan.soft.mysql_to_msg1, { icon: 16, time: 0, shade: [0.3, '#000'] });
|
||||
$.post('/database?action=SetDataDir', data, function(rdata) {
|
||||
layer.close(loadT)
|
||||
layer.msg(rdata.msg, { icon: rdata.status ? 1 : 5 });
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
$.post('/database?action=GetMySQLInfo', '', function(rdata) {
|
||||
var LimitCon = '<p class="conf_p">\
|
||||
<input id="datadir" class="phpUploadLimit bt-input-text mr5" style="width:350px;" type="text" value="' + rdata.datadir + '" name="datadir">\
|
||||
<span onclick="ChangePath(\'datadir\')" class="glyphicon glyphicon-folder-open cursor mr20" style="width:auto"></span><button class="btn btn-success btn-sm" onclick="changeMySQLDataPath(1)">' + lan.soft.mysql_to + '</button>\
|
||||
</p>';
|
||||
$(".soft-man-con").html(LimitCon);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//数据库配置状态
|
||||
function myPerfOpt() {
|
||||
//获取MySQL配置
|
||||
@@ -1691,12 +1663,12 @@ function getMasterRepSlaveListPage(){
|
||||
}
|
||||
|
||||
|
||||
function deleteSlave(){
|
||||
myPost('delete_slave', {}, function(data){
|
||||
function deleteSlave(sign){
|
||||
myPost('delete_slave', {sign:sign}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
showMsg(rdata['msg'], function(){
|
||||
masterOrSlaveConf();
|
||||
},{},3000);
|
||||
},{icon:rdata.status?1:2,time:3000},3000);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1704,28 +1676,73 @@ function deleteSlave(){
|
||||
function getFullSyncStatus(db){
|
||||
var timeId = null;
|
||||
|
||||
var btn = '<div class="table_toolbar" style="left:0px;"><span data-status="init" class="sync btn btn-default btn-sm" id="begin_full_sync" title="">开始</span></div>';
|
||||
var loadOpen = layer.open({
|
||||
type: 1,
|
||||
title: '全量同步['+db+']',
|
||||
area: '500px',
|
||||
content:"<div class='bt-form pd20 c6'>\
|
||||
<div class='divtable mtb10'>\
|
||||
<span id='full_msg'></span>\
|
||||
<div class='progress'>\
|
||||
<div class='progress-bar' role='progressbar' aria-valuenow='0' aria-valuemin='0' aria-valuemax='100' style='min-width: 2em;'>0%</div>\
|
||||
</div>\
|
||||
</div>\
|
||||
"+btn+"\
|
||||
</div>",
|
||||
cancel: function(){
|
||||
clearInterval(timeId);
|
||||
myPost('get_slave_list', {page:1,page_size:100}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
var rsource = rdata.data;
|
||||
|
||||
if (db == 'ALL' && rsource.length>1){
|
||||
layer.msg("多主不支持该模式!",{icon:2});
|
||||
return;
|
||||
}
|
||||
|
||||
var dataSource = '';
|
||||
if (rsource.length>1){
|
||||
var sourceList = '';
|
||||
for (var i = 0; i < rsource.length; i++) {
|
||||
if ('Channel_Name' in rsource[i]){
|
||||
sourceList += '<option val="'+rsource[i]['Master_Host']+'">'+rsource[i]['Master_Host']+'</option>';
|
||||
}
|
||||
}
|
||||
|
||||
dataSource = "<p class='line' style='text-align:center;'>\
|
||||
<span>同步数据源:</span>\
|
||||
<select class='bt-input-text' name='data_source' style='width:200px;'>" + sourceList + "</select>\
|
||||
</p>";
|
||||
}
|
||||
|
||||
layer.open({
|
||||
type: 1,
|
||||
title: '全量同步['+db+']',
|
||||
area: '500px',
|
||||
content:"<div class='bt-form pd15'>\
|
||||
<div class='divtable mtb10'>\
|
||||
"+dataSource+"\
|
||||
<span id='full_msg'></span>\
|
||||
<div class='progress'>\
|
||||
<div class='progress-bar' role='progressbar' aria-valuenow='0' aria-valuemin='0' aria-valuemax='100' style='min-width: 2em;'>0%</div>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class='table_toolbar' style='left:0px;'>\
|
||||
<span data-status='init' class='sync btn btn-default btn-sm' id='begin_full_sync'>开始</span>\
|
||||
</div>\
|
||||
</div>",
|
||||
cancel: function(){
|
||||
clearInterval(timeId);
|
||||
},
|
||||
success:function(){
|
||||
$('#begin_full_sync').click(function(){
|
||||
var val = $(this).data('status');
|
||||
var sign = '';
|
||||
if (dataSource !=''){
|
||||
sign = $('select[name="data_source"]').val();
|
||||
}
|
||||
if (val == 'init'){
|
||||
fullSync(db, sign, 1);
|
||||
timeId = setInterval(function(){
|
||||
fullSync(db,sign,0);
|
||||
}, 1000);
|
||||
$(this).data('status','starting');
|
||||
} else {
|
||||
layer.msg("正在同步中..",{icon:0});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function fullSync(db,begin){
|
||||
function fullSync(db,sign,begin){
|
||||
|
||||
myPostN('full_sync', {db:db,begin:begin}, function(data){
|
||||
myPostN('full_sync', {db:db,sign:sign,begin:begin}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
$('#full_msg').text(rdata['msg']);
|
||||
$('.progress-bar').css('width',rdata['progress']+'%');
|
||||
@@ -1738,19 +1755,6 @@ function getFullSyncStatus(db){
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$('#begin_full_sync').click(function(){
|
||||
var val = $(this).attr('data-status');
|
||||
if (val == 'init'){
|
||||
fullSync(db,1);
|
||||
timeId = setInterval(function(){
|
||||
fullSync(db,0);
|
||||
}, 1000);
|
||||
$(this).attr('data-status','starting');
|
||||
} else {
|
||||
layer.msg("正在同步中..");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function addSlaveSSH(ip=''){
|
||||
@@ -1920,18 +1924,29 @@ function addSlaveSyncUser(ip=''){
|
||||
<div class='line'><span class='tname'>同步账户</span><div class='info-r'><input name='user' class='bt-input-text mr5' type='text' style='width:330px;' value='"+user+"'></div></div>\
|
||||
<div class='line'><span class='tname'>同步密码</span><div class='info-r'><input name='pass' class='bt-input-text mr5' type='text' style='width:330px;' value='"+pass+"'></div></div>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>CMD[最好填好]</span>\
|
||||
<span class='tname'>CMD[必须填写]</span>\
|
||||
<div class='info-r'><textarea class='bt-input-text mr5' row='20' cols='30' name='cmd' style='width:330px;height:150px;'></textarea></div>\
|
||||
</div>\
|
||||
<input type='hidden' name='mode' value='"+mode+"' />\
|
||||
</form>",
|
||||
success:function(){
|
||||
$('textarea[name="cmd"]').html(cmd);
|
||||
|
||||
$('textarea[name="cmd"]').change(function(){
|
||||
var val = $(this).val();
|
||||
var vlist = val.split(',');
|
||||
var a = {};
|
||||
if (val.toLowerCase().indexOf('for')>0){
|
||||
cmd_tmp = val.split('for');
|
||||
val = cmd_tmp[0].trim();
|
||||
|
||||
const channel_str = cmd_tmp[1].trim();
|
||||
const ch_reg = /channel \'(.*)\';/;
|
||||
var match_val = channel_str.match(ch_reg);
|
||||
if (match_val.length>1){
|
||||
a['channel'] = match_val[1];
|
||||
}
|
||||
}
|
||||
|
||||
var vlist = val.split(',');
|
||||
for (var i in vlist) {
|
||||
var tmp = toTrim(vlist[i]);
|
||||
var tmp_a = tmp.split(" ");
|
||||
@@ -2098,7 +2113,7 @@ function getSlaveUserList(){
|
||||
layerId = layer.open({
|
||||
type: 1,
|
||||
title: '同步账户列表',
|
||||
area: '500px',
|
||||
area: '600px',
|
||||
content:"<div class='bt-form pd20 c6'>\
|
||||
<div class='divtable mtb10'>\
|
||||
<div><table class='table table-hover get-slave-ssh-list'>\
|
||||
@@ -2122,7 +2137,7 @@ function getSlaveSSHList(page=1){
|
||||
layerId = layer.open({
|
||||
type: 1,
|
||||
title: 'SSH列表',
|
||||
area: '500px',
|
||||
area: '600px',
|
||||
content:"<div class='bt-form pd20 c6'>\
|
||||
<div class='divtable mtb10'>\
|
||||
<div><table class='table table-hover get-slave-ssh-list'>\
|
||||
@@ -2230,10 +2245,16 @@ function masterOrSlaveConf(version=''){
|
||||
myPost('get_slave_list', _data, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
var list = '';
|
||||
|
||||
var isHasSign = false;
|
||||
for(i in rdata.data){
|
||||
|
||||
var v = rdata.data[i];
|
||||
var status = "<a class='btlink db_error'>异常</>";
|
||||
if ('Channel_Name' in v){
|
||||
isHasSign = true;
|
||||
}
|
||||
|
||||
var status = "<a data-id="+i+" class='btlink db_error'>异常</>";
|
||||
if (v['Slave_SQL_Running'] == 'Yes' && v['Slave_IO_Running'] == 'Yes'){
|
||||
status = "正常";
|
||||
}
|
||||
@@ -2245,13 +2266,23 @@ function masterOrSlaveConf(version=''){
|
||||
list += '<td>' + rdata.data[i]['Master_Log_File'] +'</td>';
|
||||
list += '<td>' + rdata.data[i]['Slave_IO_Running'] +'</td>';
|
||||
list += '<td>' + rdata.data[i]['Slave_SQL_Running'] +'</td>';
|
||||
|
||||
if (isHasSign){
|
||||
list += '<td>' + v['Channel_Name'] +'</td>';
|
||||
}
|
||||
|
||||
list += '<td>' + status +'</td>';
|
||||
list += '<td style="text-align:right">' +
|
||||
'<a href="javascript:;" class="btlink" onclick="deleteSlave()" title="删除">删除</a>' +
|
||||
'<a data-id="'+i+'" href="javascript:;" class="btlink btn_delete_slave" title="删除">删除</a>' +
|
||||
'</td>';
|
||||
list += '</tr>';
|
||||
}
|
||||
|
||||
var signThead_th = '';
|
||||
if (isHasSign){
|
||||
var signThead_th = '<th>标识</th>';
|
||||
}
|
||||
|
||||
var con = '<div class="divtable mtb10">\
|
||||
<div class="tablescroll">\
|
||||
<table id="DataBody" class="table table-hover" width="100%" cellspacing="0" cellpadding="0" border="0" style="border: 0 none;">\
|
||||
@@ -2262,6 +2293,7 @@ function masterOrSlaveConf(version=''){
|
||||
<th>日志</th>\
|
||||
<th>IO</th>\
|
||||
<th>SQL</th>\
|
||||
'+signThead_th+'\
|
||||
<th>状态</th>\
|
||||
<th style="text-align:right;">操作</th></tr></thead>\
|
||||
<tbody>\
|
||||
@@ -2276,22 +2308,74 @@ function masterOrSlaveConf(version=''){
|
||||
// </div>
|
||||
$(".table_slave_status_list").html(con);
|
||||
|
||||
$('.db_error').click(function(){
|
||||
$(".btn_delete_slave").click(function(){
|
||||
var id = $(this).data('id');
|
||||
var v = rdata.data[id];
|
||||
if ('Channel_Name' in v){
|
||||
deleteSlave(v['Channel_Name']);
|
||||
} else{
|
||||
deleteSlave();
|
||||
}
|
||||
});
|
||||
|
||||
$('.db_error').click(function(){
|
||||
var id = $(this).data('id');
|
||||
var info = rdata.data[id];
|
||||
|
||||
var err_line = "";
|
||||
err_line +="<tr>\
|
||||
<td>IO错误</td>\
|
||||
<td>"+ (info['Last_IO_Error'] == '' ? '无':info['Last_IO_Error'])+"</td>\
|
||||
</tr>";
|
||||
err_line +="<tr>\
|
||||
<td>SQL错误</td>\
|
||||
<td>"+(info['Last_SQL_Error'] == '' ? '无':info['Last_SQL_Error'])+"</td>\
|
||||
</tr>";
|
||||
|
||||
err_line +="<tr>\
|
||||
<td>状态</td>\
|
||||
<td>"+(info['Slave_SQL_Running_State'] == '' ? '无':info['Slave_SQL_Running_State']) +"</td>\
|
||||
</tr>";
|
||||
|
||||
layer.open({
|
||||
type: 1,
|
||||
title: '同步异常信息',
|
||||
area: '500px',
|
||||
content:"<form class='bt-form pd20 pb70'>\
|
||||
<div class='line'>"+v['Error']+"</div>\
|
||||
<div class='bt-form-submit-btn'>\
|
||||
<button type='button' class='btn btn-success btn-sm btn-title class-copy-db-err'>复制</button>\
|
||||
area: ['600px','300px'],
|
||||
btn:['复制错误',"取消"],
|
||||
content:"<form class='bt-form pd15'>\
|
||||
<div class='divtable mtb10'>\
|
||||
<div class='tablescroll'>\
|
||||
<table class='table table-hover' width='100%' cellspacing='0' cellpadding='0' border='0' style='border: 0 none;'>\
|
||||
<thead><tr>\
|
||||
<th style='width:80px;'>类型</th>\
|
||||
<th>内容</th>\
|
||||
</tr></thead>\
|
||||
<tbody>"+ err_line +"</tbody>\
|
||||
</table>\
|
||||
</div>\
|
||||
</div>\
|
||||
</form>",
|
||||
</form>",
|
||||
success:function(){
|
||||
copyText(v['Error']);
|
||||
$('.class-copy-db-err').click(function(){
|
||||
copyText(v['Error']);
|
||||
});
|
||||
// copyText(v['Error']);
|
||||
// $('.class-copy-db-err').click(function(){
|
||||
// copyText(v['Error']);
|
||||
// });
|
||||
},
|
||||
yes:function(){
|
||||
if (info['Last_IO_Error'] != ''){
|
||||
copyText(info['Last_IO_Error']);
|
||||
return;
|
||||
}
|
||||
|
||||
if (info['Last_SQL_Error'] != ''){
|
||||
copyText(info['Last_SQL_Error']);
|
||||
return;
|
||||
}
|
||||
|
||||
if (info['Slave_SQL_Running_State'] != ''){
|
||||
copyText(info['Slave_SQL_Running_State']);
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -70,7 +70,7 @@ log-slave-updates = 1
|
||||
# Prevent replication from starting automatically with MySQL
|
||||
#skip-slave-start = 1
|
||||
#replicate-do-db
|
||||
slave_skip_errors=1062
|
||||
slave_skip_errors=1062,1396
|
||||
replicate-ignore-db = information_schema
|
||||
replicate-ignore-db = performance_schema
|
||||
replicate-ignore-db = mysql
|
||||
|
||||
@@ -18,6 +18,7 @@ basedir = {$SERVER_APP_PATH}
|
||||
datadir = {$SERVER_APP_PATH}/data
|
||||
log-error = {$SERVER_APP_PATH}/data/error.log
|
||||
server-id = {$SERVER_ID}
|
||||
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
|
||||
|
||||
default_storage_engine = InnoDB
|
||||
|
||||
@@ -72,7 +73,7 @@ log-slave-updates = 1
|
||||
# Prevent replication from starting automatically with MySQL
|
||||
#skip-slave-start = 1
|
||||
#replicate-do-db
|
||||
slave_skip_errors=1062
|
||||
slave_skip_errors=1062,1396
|
||||
replicate-ignore-db = information_schema
|
||||
replicate-ignore-db = performance_schema
|
||||
replicate-ignore-db = mysql
|
||||
|
||||
@@ -16,6 +16,7 @@ basedir = {$SERVER_APP_PATH}
|
||||
datadir = {$SERVER_APP_PATH}/data
|
||||
log-error = {$SERVER_APP_PATH}/data/error.log
|
||||
server-id = {$SERVER_ID}
|
||||
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
|
||||
|
||||
explicit_defaults_for_timestamp=true
|
||||
default_storage_engine = InnoDB
|
||||
@@ -74,12 +75,14 @@ binlog-ignore-db = performance_schema
|
||||
# Prevent replication from starting automatically with MySQL
|
||||
#skip-slave-start = 1
|
||||
#replicate-do-db
|
||||
slave_skip_errors=1062
|
||||
slave_skip_errors=1062,1396
|
||||
replicate-ignore-db = information_schema
|
||||
replicate-ignore-db = performance_schema
|
||||
replicate-ignore-db = mysql
|
||||
replicate-ignore-db = test
|
||||
|
||||
master_info_repository = table
|
||||
relay_log_info_repository = table
|
||||
|
||||
innodb_data_home_dir = {$SERVER_APP_PATH}/data
|
||||
innodb_data_file_path = ibdata1:10M:autoextend
|
||||
|
||||
@@ -20,6 +20,7 @@ basedir = {$SERVER_APP_PATH}
|
||||
datadir = {$SERVER_APP_PATH}/data
|
||||
log-error = {$SERVER_APP_PATH}/data/error.log
|
||||
server-id = {$SERVER_ID}
|
||||
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
|
||||
|
||||
default_storage_engine = InnoDB
|
||||
|
||||
@@ -71,12 +72,14 @@ log_replica_updates = 1
|
||||
# Prevent replication from starting automatically with MySQL
|
||||
#skip_replica_start = 1
|
||||
#replicate-do-db
|
||||
replica_skip_errors=1062
|
||||
replica_skip_errors=1062,1396
|
||||
replicate-ignore-db = information_schema
|
||||
replicate-ignore-db = performance_schema
|
||||
replicate-ignore-db = mysql
|
||||
replicate-ignore-db = test
|
||||
|
||||
master_info_repository = table
|
||||
relay_log_info_repository = table
|
||||
|
||||
innodb_data_home_dir = {$SERVER_APP_PATH}/data
|
||||
innodb_data_file_path = ibdata1:10M:autoextend
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<p onclick="dbList()">管理列表</p>
|
||||
<p onclick="masterOrSlaveConf($('.plugin_version').attr('version'))">主从配置</p>
|
||||
</div>
|
||||
<div class="bt-w-con pd15">
|
||||
<div class="bt-w-con pd15" style="height:555px;overflow: auto;">
|
||||
<div class="soft-man-con"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+223
-179
@@ -36,6 +36,10 @@ def getPluginDir():
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getSPluginDir():
|
||||
return '/www/server/mdserver-web/plugins/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
@@ -85,6 +89,14 @@ def getDbPort():
|
||||
return tmp.groups()[0].strip()
|
||||
|
||||
|
||||
def getDbServerId():
|
||||
file = getConf()
|
||||
content = mw.readFile(file)
|
||||
rep = 'server-id\s*=\s*(.*)'
|
||||
tmp = re.search(rep, content)
|
||||
return tmp.groups()[0].strip()
|
||||
|
||||
|
||||
def getSocketFile():
|
||||
file = getConf()
|
||||
content = mw.readFile(file)
|
||||
@@ -802,15 +814,15 @@ def isSqlError(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:
|
||||
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:
|
||||
if "1133," in mysqlMsg:
|
||||
return mw.returnJson(False, '数据库用户不存在!')
|
||||
if "1007" in mysqlMsg:
|
||||
if "1007," in mysqlMsg:
|
||||
return mw.returnJson(False, '数据库已经存在!')
|
||||
return None
|
||||
|
||||
@@ -1887,13 +1899,14 @@ def getMasterStatus(version=''):
|
||||
data = {}
|
||||
data['mode'] = recognizeDbMode()
|
||||
data['status'] = master_status
|
||||
data['slave_status'] = False
|
||||
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
|
||||
# print(dlist[0])
|
||||
if len(dlist) > 0 and (dlist[0]["Slave_IO_Running"] == 'Yes' or dlist[0]["Slave_SQL_Running"] == 'Yes'):
|
||||
data['slave_status'] = True
|
||||
for v in dlist:
|
||||
if v["Slave_IO_Running"] == 'Yes' or v["Slave_SQL_Running"] == 'Yes':
|
||||
data['slave_status'] = True
|
||||
|
||||
return mw.returnJson(master_status, '设置成功', data)
|
||||
except Exception as e:
|
||||
@@ -2057,27 +2070,34 @@ def getMasterRepSlaveUserCmd(version):
|
||||
|
||||
mode = recognizeDbMode()
|
||||
|
||||
sid = getDbServerId()
|
||||
channel_name = ""
|
||||
if sid != '':
|
||||
channel_name = " for channel 'r{}';".format(sid)
|
||||
|
||||
if mode == "gtid":
|
||||
sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \
|
||||
clist[0]['username'] + "', MASTER_PASSWORD='" + \
|
||||
clist[0]['password'] + "', MASTER_AUTO_POSITION=1"
|
||||
clist[0]['password'] + "', MASTER_AUTO_POSITION=1" + channel_name
|
||||
if version == '8.0':
|
||||
sql = "CHANGE REPLICATION SOURCE TO SOURCE_HOST='" + ip + "', SOURCE_PORT=" + port + ", SOURCE_USER='" + \
|
||||
clist[0]['username'] + "', SOURCE_PASSWORD='" + \
|
||||
clist[0]['password'] + "', MASTER_AUTO_POSITION=1"
|
||||
clist[0]['password'] + \
|
||||
"', MASTER_AUTO_POSITION=1" + channel_name
|
||||
else:
|
||||
sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \
|
||||
clist[0]['username'] + "', MASTER_PASSWORD='" + \
|
||||
clist[0]['password'] + \
|
||||
"', MASTER_LOG_FILE='" + mstatus[0]["File"] + \
|
||||
"',MASTER_LOG_POS=" + str(mstatus[0]["Position"])
|
||||
"',MASTER_LOG_POS=" + str(mstatus[0]["Position"]) + channel_name
|
||||
|
||||
if version == "8.0":
|
||||
sql = "CHANGE REPLICATION SOURCE TO SOURCE_HOST='" + ip + "', SOURCE_PORT=" + port + ", SOURCE_USER='" + \
|
||||
clist[0]['username'] + "', SOURCE_PASSWORD='" + \
|
||||
clist[0]['password'] + \
|
||||
"', SOURCE_LOG_FILE='" + mstatus[0]["File"] + \
|
||||
"',SOURCE_LOG_POS=" + str(mstatus[0]["Position"])
|
||||
"',SOURCE_LOG_POS=" + \
|
||||
str(mstatus[0]["Position"]) + channel_name
|
||||
|
||||
data = {}
|
||||
data['cmd'] = sql
|
||||
@@ -2348,48 +2368,17 @@ def updateSlaveSSH(version=''):
|
||||
|
||||
|
||||
def getSlaveList(version=''):
|
||||
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
ret = []
|
||||
for x in range(0, len(dlist)):
|
||||
tmp = {}
|
||||
tmp['Master_User'] = dlist[x]["Master_User"]
|
||||
tmp['Master_Host'] = dlist[x]["Master_Host"]
|
||||
tmp['Master_Port'] = dlist[x]["Master_Port"]
|
||||
tmp['Master_Log_File'] = dlist[x]["Master_Log_File"]
|
||||
tmp['Slave_IO_Running'] = dlist[x]["Slave_IO_Running"]
|
||||
tmp['Slave_SQL_Running'] = dlist[x]["Slave_SQL_Running"]
|
||||
tmp['Last_Error'] = dlist[x]["Last_Error"]
|
||||
tmp['Last_IO_Error'] = dlist[x]["Last_IO_Error"]
|
||||
tmp['Last_SQL_Error'] = dlist[x]["Last_SQL_Error"]
|
||||
tmp['Slave_SQL_Running_State'] = dlist[x]["Slave_SQL_Running_State"]
|
||||
|
||||
tmp['Error'] = ''
|
||||
if tmp['Last_Error'] != '':
|
||||
tmp['Error'] = tmp['Last_Error']
|
||||
|
||||
if tmp['Last_IO_Error'] != '':
|
||||
tmp['Error'] = tmp['Last_IO_Error']
|
||||
|
||||
if tmp['Last_SQL_Error'] != '':
|
||||
tmp['Error'] = tmp['Last_SQL_Error']
|
||||
|
||||
if tmp['Error'] == '':
|
||||
tmp['Error'] = tmp['Slave_SQL_Running_State']
|
||||
|
||||
ret.append(tmp)
|
||||
data = {}
|
||||
data['data'] = ret
|
||||
|
||||
data['data'] = dlist
|
||||
return mw.getJson(data)
|
||||
|
||||
|
||||
def getSlaveSyncCmd(version=''):
|
||||
|
||||
root = mw.getRunDir()
|
||||
cmd = 'cd ' + root + ' && python3 ' + root + \
|
||||
'/plugins/mysql/index.py do_full_sync {"db":"all"}'
|
||||
'/plugins/mysql/index.py do_full_sync {"db":"all","sign",""}'
|
||||
return mw.returnJson(True, 'ok', cmd)
|
||||
|
||||
|
||||
@@ -2424,111 +2413,152 @@ def makeSyncUsercmd(u, version=''):
|
||||
return sql
|
||||
|
||||
|
||||
def parseSlaveSyncCmd(cmd):
|
||||
a = {}
|
||||
if cmd.lower().find('for') > 0:
|
||||
cmd_tmp = cmd.split('for')
|
||||
cmd = cmd_tmp[0].strip()
|
||||
|
||||
pattern_c = r"channel \'(.*)\';"
|
||||
match_val = re.match(pattern_c, cmd_tmp[1].strip(), re.I)
|
||||
if match_val:
|
||||
m_groups = match_val.groups()
|
||||
a['channel'] = m_groups[0]
|
||||
vlist = cmd.split(',')
|
||||
for i in vlist:
|
||||
tmp = i.strip()
|
||||
tmp_a = tmp.split(" ")
|
||||
real_tmp = tmp_a[len(tmp_a) - 1]
|
||||
kv = real_tmp.split("=")
|
||||
a[kv[0]] = kv[1].replace("'", '').replace("'", '').replace(";", '')
|
||||
return a
|
||||
|
||||
|
||||
def initSlaveStatusSyncUser(version=''):
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
if len(data) < 1:
|
||||
slave_data = conn.field('ip,port,user,pass,mode,cmd').select()
|
||||
if len(slave_data) < 1:
|
||||
return mw.returnJson(False, '需要先添加同步用户配置!')
|
||||
|
||||
# print(data)
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
if len(dlist) > 0:
|
||||
return mw.returnJson(False, '已经初始化好了zz...')
|
||||
|
||||
u = data
|
||||
|
||||
mode_name = 'classic'
|
||||
if u['mode'] == '1':
|
||||
mode_name = 'gtid'
|
||||
pdb = pMysqlDb()
|
||||
if len(slave_data) == 1:
|
||||
dlist = pdb.query('show slave status')
|
||||
if len(dlist) > 0:
|
||||
return mw.returnJson(False, '已经初始化好了zz...')
|
||||
|
||||
msg = ''
|
||||
local_mode = recognizeDbMode()
|
||||
if local_mode != mode_name:
|
||||
return mw.returnJson(False, '同步模式不一致!')
|
||||
for x in range(len(slave_data)):
|
||||
slave_t = slave_data[x]
|
||||
mode_name = 'classic'
|
||||
base_t = 'IP:' + slave_t['ip'] + ",PORT:" + \
|
||||
slave_t['port'] + ",USER:" + slave_t['user']
|
||||
|
||||
if u['cmd'] == '' and local_mode == 'gtid':
|
||||
sql = makeSyncUsercmd(u, version)
|
||||
# print(sql)
|
||||
t = db.query(sql)
|
||||
else:
|
||||
if u['cmd'] == '':
|
||||
return mw.returnJson(False, '经典模式下,必须手写同步命令!')
|
||||
if slave_t['mode'] == '1':
|
||||
mode_name = 'gtid'
|
||||
|
||||
if local_mode != mode_name:
|
||||
msg += base_t + '->同步模式不一致'
|
||||
continue
|
||||
|
||||
cmd_sql = slave_t['cmd']
|
||||
if cmd_sql == '':
|
||||
msg += base_t + '->同步命令不能为空'
|
||||
continue
|
||||
|
||||
try:
|
||||
pinfo = parseSlaveSyncCmd(cmd_sql)
|
||||
except Exception as e:
|
||||
return mw.returnJson(False, base_t + '->CMD同步命令不合规范!')
|
||||
# print(u['cmd'])
|
||||
t = db.query(u['cmd'])
|
||||
isError = isSqlError(t)
|
||||
if isError:
|
||||
return isError
|
||||
t = pdb.query(cmd_sql)
|
||||
isError = isSqlError(t)
|
||||
if isError:
|
||||
return isError
|
||||
|
||||
db.query("start slave user='{}' password='{}';".format(
|
||||
u['user'], u['pass']))
|
||||
return mw.returnJson(True, '初始化成功!')
|
||||
# pdb.query("start slave user='{}' password='{}';".format(
|
||||
# u['user'], u['pass']))
|
||||
|
||||
pdb.query("start slave")
|
||||
pdb.query("start all slaves")
|
||||
|
||||
if msg == '':
|
||||
msg = '初始化成功!'
|
||||
return mw.returnJson(True, msg)
|
||||
|
||||
|
||||
def initSlaveStatusSSH(version=''):
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
if len(dlist) > 0:
|
||||
return mw.returnJson(False, '已经初始化好了zz...')
|
||||
|
||||
conn = pSqliteDb('slave_id_rsa')
|
||||
data = conn.field('ip,port,id_rsa').find()
|
||||
ssh_list = conn.field('ip,port,id_rsa,db_user').select()
|
||||
|
||||
if len(data) < 1:
|
||||
return mw.returnJson(False, '需要先添加SSH配置!')
|
||||
if len(ssh_list) < 1:
|
||||
return mw.returnJson(False, '需要先配置【[主]SSH配置】!')
|
||||
|
||||
SSH_PRIVATE_KEY = "/tmp/t_ssh.txt"
|
||||
ip = data['ip']
|
||||
master_port = data['port']
|
||||
mw.writeFile(SSH_PRIVATE_KEY, data['id_rsa'].replace('\\n', '\n'))
|
||||
local_mode = recognizeDbMode()
|
||||
|
||||
import paramiko
|
||||
paramiko.util.log_to_file('paramiko.log')
|
||||
ssh = paramiko.SSHClient()
|
||||
|
||||
try:
|
||||
|
||||
db.query('stop slave')
|
||||
db.query('reset slave all')
|
||||
for data in ssh_list:
|
||||
ip = data['ip']
|
||||
SSH_PRIVATE_KEY = "/tmp/t_ssh_" + ip + ".txt"
|
||||
master_port = data['port']
|
||||
mw.writeFile(SSH_PRIVATE_KEY, data['id_rsa'].replace('\\n', '\n'))
|
||||
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=int(master_port),
|
||||
username='root', pkey=key)
|
||||
try:
|
||||
key = paramiko.RSAKey.from_private_key_file(SSH_PRIVATE_KEY)
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect(hostname=ip, port=int(master_port),
|
||||
username='root', pkey=key)
|
||||
|
||||
cmd = 'cd /www/server/mdserver-web && source bin/activate && python3 plugins/mysql/index.py get_master_rep_slave_user_cmd {"username":"","db":""}'
|
||||
stdin, stdout, stderr = ssh.exec_command(cmd)
|
||||
result = stdout.read()
|
||||
result = result.decode('utf-8')
|
||||
cmd_data = json.loads(result)
|
||||
db_user = data['db_user']
|
||||
cmd = 'cd /www/server/mdserver-web && source bin/activate && python3 ' + \
|
||||
getSPluginDir() + \
|
||||
'/index.py get_master_rep_slave_user_cmd {"username":"' + \
|
||||
db_user + '","db":""}'
|
||||
stdin, stdout, stderr = ssh.exec_command(cmd)
|
||||
result = stdout.read()
|
||||
result = result.decode('utf-8')
|
||||
if result.strip() == "":
|
||||
return mw.returnJson(False, '[主][' + ip + ']:获取同步命令失败!')
|
||||
|
||||
if not cmd_data['status']:
|
||||
return mw.returnJson(False, '[主]:' + cmd_data['msg'])
|
||||
cmd_data = json.loads(result)
|
||||
if not cmd_data['status']:
|
||||
return mw.returnJson(False, '[主][' + ip + ']:' + cmd_data['msg'])
|
||||
|
||||
local_mode = recognizeDbMode()
|
||||
if local_mode != cmd_data['data']['mode']:
|
||||
return mw.returnJson(False, '主【{}】从【{}】,运行模式不一致!'.format(cmd_data['data']['mode'], local_mode))
|
||||
if local_mode != cmd_data['data']['mode']:
|
||||
return mw.returnJson(False, '[主][' + ip + ']:【{}】从【{}】,运行模式不一致!'.format(cmd_data['data']['mode'], local_mode))
|
||||
|
||||
u = cmd_data['data']['info']
|
||||
ps = u['username'] + "|" + u['password']
|
||||
conn.where('ip=?', (ip,)).setField('ps', ps)
|
||||
db.query('stop slave')
|
||||
u = cmd_data['data']['info']
|
||||
|
||||
# 保证同步IP一致
|
||||
cmd = cmd_data['data']['cmd']
|
||||
if cmd.find('SOURCE_HOST') > -1:
|
||||
cmd = re.sub(r"SOURCE_HOST='(.*?)'",
|
||||
"SOURCE_HOST='" + ip + "'", cmd, 1)
|
||||
ps = u['username'] + "|" + u['password']
|
||||
print(ps)
|
||||
conn.where('ip=?', (ip,)).setField('ps', ps)
|
||||
db.query('stop slave')
|
||||
|
||||
if cmd.find('MASTER_HOST') > -1:
|
||||
cmd = re.sub(r"MASTER_HOST='(.*?)'",
|
||||
"MASTER_HOST='" + ip + "'", cmd, 1)
|
||||
db.query(cmd)
|
||||
db.query("start slave user='{}' password='{}';".format(
|
||||
u['username'], u['password']))
|
||||
except Exception as e:
|
||||
return mw.returnJson(False, 'SSH认证配置连接失败!' + str(e))
|
||||
# 保证同步IP一致
|
||||
cmd = cmd_data['data']['cmd']
|
||||
if cmd.find('SOURCE_HOST') > -1:
|
||||
cmd = re.sub(r"SOURCE_HOST='(.*?)'",
|
||||
"SOURCE_HOST='" + ip + "'", cmd, 1)
|
||||
|
||||
ssh.close()
|
||||
time.sleep(1)
|
||||
os.system("rm -rf " + SSH_PRIVATE_KEY)
|
||||
if cmd.find('MASTER_HOST') > -1:
|
||||
cmd = re.sub(r"MASTER_HOST='(.*?)'",
|
||||
"MASTER_HOST='" + ip + "'", cmd, 1)
|
||||
db.query(cmd)
|
||||
ssh.close()
|
||||
if os.path.exists(SSH_PRIVATE_KEY):
|
||||
os.system("rm -rf " + SSH_PRIVATE_KEY)
|
||||
except Exception as e:
|
||||
return mw.returnJson(False, '[主][' + ip + ']:SSH认证配置连接失败!' + str(e))
|
||||
db.query('start slave')
|
||||
return mw.returnJson(True, '初始化成功!')
|
||||
|
||||
|
||||
@@ -2538,60 +2568,37 @@ def setSlaveStatus(version=''):
|
||||
return mw.returnJson(False, '需要先设置同步配置')
|
||||
|
||||
mode = mw.readFile(mode_file)
|
||||
if mode == 'ssh':
|
||||
return setSlaveStatusSSH(version)
|
||||
if mode == 'sync-user':
|
||||
return setSlaveStatusSyncUser(version)
|
||||
|
||||
|
||||
def setSlaveStatusSyncUser(version=''):
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
pdb = pMysqlDb()
|
||||
dlist = pdb.query('show slave status')
|
||||
if len(dlist) == 0:
|
||||
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:
|
||||
ip = dlist[0]['Master_Host']
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
if len(data) == 0:
|
||||
return mw.returnJson(False, '没有数据无法重启!')
|
||||
user = data['user']
|
||||
apass = data['pass']
|
||||
for v in dlist:
|
||||
connection_name = ''
|
||||
cmd = "slave"
|
||||
if 'Channel_Name' in v:
|
||||
ch_name = v['Channel_Name']
|
||||
cmd = "slave for channel '{}'".format(ch_name)
|
||||
|
||||
db.query("start slave")
|
||||
# db.query("start slave user='{}' password='{}';".format(user, apass))
|
||||
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def setSlaveStatusSSH(version=''):
|
||||
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
if len(dlist) == 0:
|
||||
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:
|
||||
ip = dlist[0]['Master_Host']
|
||||
conn = pSqliteDb('slave_id_rsa')
|
||||
data = conn.field('ip,ps').where("ip=?", (ip,)).find()
|
||||
if len(data) == 0:
|
||||
return mw.returnJson(False, '没有数据无法重启!')
|
||||
u = data['ps'].split("|")
|
||||
db.query("start slave user='{}' password='{}';".format(u[0], u[1]))
|
||||
if (v["Slave_IO_Running"] == 'Yes' or v["Slave_SQL_Running"] == 'Yes'):
|
||||
pdb.query("stop {}".format(cmd))
|
||||
else:
|
||||
pdb.query("start {}".format(cmd))
|
||||
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def deleteSlave(version=''):
|
||||
args = getArgs()
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('stop slave')
|
||||
dlist = db.query('reset slave all')
|
||||
if 'sign' in args:
|
||||
sign = args['sign']
|
||||
db.query("stop slave for channel '{}'".format(sign))
|
||||
db.query("reset slave all for channel '{}'".format(sign))
|
||||
else:
|
||||
db.query('stop slave')
|
||||
db.query('reset slave all')
|
||||
|
||||
return mw.returnJson(True, '删除成功!')
|
||||
|
||||
|
||||
@@ -2628,11 +2635,13 @@ def dumpMysqlData(version=''):
|
||||
|
||||
############### --- 重要 同步---- ###########
|
||||
|
||||
def asyncTmpfile():
|
||||
path = '/tmp/mysql_async_status.txt'
|
||||
return path
|
||||
|
||||
|
||||
def writeDbSyncStatus(data):
|
||||
path = '/tmp/db_async_status.txt'
|
||||
# status_data['code'] = 1
|
||||
# status_data['msg'] = '主服务器备份完成...'
|
||||
# status_data['progress'] = 30
|
||||
path = asyncTmpfile()
|
||||
mw.writeFile(path, json.dumps(data))
|
||||
|
||||
|
||||
@@ -2650,16 +2659,32 @@ def doFullSync(version=''):
|
||||
|
||||
def doFullSyncUser(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['db'])
|
||||
data = checkArgs(args, ['db', 'sign'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
sync_db = args['db']
|
||||
sync_db_import = args['db']
|
||||
|
||||
if sync_db.lower() == 'all':
|
||||
sync_db_import = ''
|
||||
dbs = findBinlogSlaveDoDb()
|
||||
dbs_str = ''
|
||||
for x in dbs:
|
||||
dbs_str += ' ' + x
|
||||
sync_db = "--databases " + dbs_str.strip()
|
||||
|
||||
sync_sign = args['sign']
|
||||
|
||||
db = pMysqlDb()
|
||||
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
if sync_sign != '':
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').where(
|
||||
'ip=?', (sync_sign,)).find()
|
||||
else:
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
|
||||
user = data['user']
|
||||
apass = data['pass']
|
||||
port = data['port']
|
||||
@@ -2687,7 +2712,8 @@ def doFullSyncUser(version=''):
|
||||
pwd = pSqliteDb('config').where('id=?', (1,)).getField('mysql_root')
|
||||
sock = getSocketFile()
|
||||
my_import_cmd = getServerDir() + '/bin/mysql -S ' + sock + ' -uroot -p' + pwd + \
|
||||
' ' + sync_db + ' < ' + bak_file
|
||||
' ' + sync_db_import + ' < ' + bak_file
|
||||
# print(my_import_cmd)
|
||||
mw.execShell(my_import_cmd)
|
||||
|
||||
if version == '8.0':
|
||||
@@ -2696,21 +2722,30 @@ def doFullSyncUser(version=''):
|
||||
db.query("start slave")
|
||||
|
||||
writeDbSyncStatus({'code': 6, 'msg': '从库重启完成...', 'progress': 100})
|
||||
os.system("rm -rf " + bak_file)
|
||||
|
||||
if os.path.exists(bak_file):
|
||||
os.system("rm -rf " + bak_file)
|
||||
return True
|
||||
|
||||
|
||||
def doFullSyncSSH(version=''):
|
||||
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['db'])
|
||||
data = checkArgs(args, ['db', 'sign'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
sync_db = args['db']
|
||||
sync_sign = args['sign']
|
||||
|
||||
db = pMysqlDb()
|
||||
|
||||
id_rsa_conn = pSqliteDb('slave_id_rsa')
|
||||
data = id_rsa_conn.field('ip,port,db_user,id_rsa').find()
|
||||
if sync_sign != '':
|
||||
data = id_rsa_conn.field('ip,port,db_user,id_rsa').where(
|
||||
'ip=?', (sync_sign,)).find()
|
||||
else:
|
||||
data = id_rsa_conn.field('ip,port,db_user,id_rsa').find()
|
||||
|
||||
SSH_PRIVATE_KEY = "/tmp/mysql_sync_id_rsa.txt"
|
||||
id_rsa = data['id_rsa'].replace('\\n', '\n')
|
||||
@@ -2752,7 +2787,8 @@ def doFullSyncSSH(version=''):
|
||||
writeDbSyncStatus({'code': 0, 'msg': '登录Master成功...', 'progress': 5})
|
||||
|
||||
dbname = args['db']
|
||||
cmd = "cd /www/server/mdserver-web && source bin/activate && python3 plugins/mysql/index.py dump_mysql_data {\"db\":'" + dbname + "'}"
|
||||
cmd = "cd /www/server/mdserver-web && source bin/activate && python3 " + \
|
||||
getSPluginDir() + "/index.py dump_mysql_data {\"db\":'" + dbname + "'}"
|
||||
print(cmd)
|
||||
stdin, stdout, stderr = ssh.exec_command(cmd)
|
||||
result = stdout.read()
|
||||
@@ -2775,7 +2811,10 @@ def doFullSyncSSH(version=''):
|
||||
if copy_status == None:
|
||||
writeDbSyncStatus({'code': 2, 'msg': '数据同步本地完成...', 'progress': 40})
|
||||
|
||||
cmd = 'cd /www/server/mdserver-web && source bin/activate && python3 plugins/mysql/index.py get_master_rep_slave_user_cmd {"username":"' + db_user + '","db":""}'
|
||||
cmd = 'cd /www/server/mdserver-web && source bin/activate && python3 ' + \
|
||||
getSPluginDir() + \
|
||||
'/index.py get_master_rep_slave_user_cmd {"username":"' + \
|
||||
db_user + '","db":""}'
|
||||
stdin, stdout, stderr = ssh.exec_command(cmd)
|
||||
result = stdout.read()
|
||||
result = result.decode('utf-8')
|
||||
@@ -2817,8 +2856,9 @@ def doFullSyncSSH(version=''):
|
||||
writeDbSyncStatus({'code': 5, 'msg': '导入数据失败...', 'progress': 100})
|
||||
return 'fail'
|
||||
|
||||
db.query("start slave user='{}' password='{}';".format(
|
||||
uinfo['username'], uinfo['password']))
|
||||
# "start slave user='{}' password='{}';".format(uinfo['username'], uinfo['password'])
|
||||
|
||||
db.query("start slave")
|
||||
writeDbSyncStatus({'code': 6, 'msg': '从库重启完成...', 'progress': 100})
|
||||
|
||||
os.system("rm -rf " + SSH_PRIVATE_KEY)
|
||||
@@ -2832,12 +2872,16 @@ def fullSync(version=''):
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
status_file = '/tmp/db_async_status.txt'
|
||||
sign = ''
|
||||
if 'sign' in args:
|
||||
sign = args['sign']
|
||||
|
||||
status_file = asyncTmpfile()
|
||||
if args['begin'] == '1':
|
||||
cmd = 'cd ' + mw.getRunDir() + ' && python3 ' + \
|
||||
getPluginDir() + \
|
||||
'/index.py do_full_sync {"db":"' + args['db'] + '"} &'
|
||||
print(cmd)
|
||||
cmd = 'cd ' + mw.getRunDir() + ' && python3 ' + getPluginDir() + \
|
||||
'/index.py do_full_sync {"db":"' + \
|
||||
args['db'] + '","sign":"' + sign + '"} &'
|
||||
# print(cmd)
|
||||
mw.execShell(cmd)
|
||||
return json.dumps({'code': 0, 'msg': '同步数据中!', 'progress': 0})
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"path": "server/mysql/VERSION",
|
||||
"todo_versions":["5.6","5.7","8.0"],
|
||||
"versions":["5.5", "5.6", "5.7","8.0"],
|
||||
"updates":["5.5.62","5.6.50", "5.7.32","8.0.30"],
|
||||
"updates":["5.5.62","5.6.50", "5.7.32","8.0.34"],
|
||||
"shell":"install.sh",
|
||||
"checks":"server/mysql",
|
||||
"path":"server/mysql",
|
||||
@@ -19,4 +19,4 @@
|
||||
"home":"https://dev.mysql.com/downloads/mysql",
|
||||
"date":"2017-11-24",
|
||||
"pid": "2"
|
||||
}
|
||||
}
|
||||
|
||||
+164
-80
@@ -162,34 +162,6 @@ function myPort(){
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//数据库存储信置
|
||||
function changeMySQLDataPath(act) {
|
||||
if (act != undefined) {
|
||||
layer.confirm(lan.soft.mysql_to_msg, { closeBtn: 2, icon: 3 }, function() {
|
||||
var datadir = $("#datadir").val();
|
||||
var data = 'datadir=' + datadir;
|
||||
var loadT = layer.msg(lan.soft.mysql_to_msg1, { icon: 16, time: 0, shade: [0.3, '#000'] });
|
||||
$.post('/database?action=SetDataDir', data, function(rdata) {
|
||||
layer.close(loadT)
|
||||
layer.msg(rdata.msg, { icon: rdata.status ? 1 : 5 });
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
$.post('/database?action=GetMySQLInfo', '', function(rdata) {
|
||||
var LimitCon = '<p class="conf_p">\
|
||||
<input id="datadir" class="phpUploadLimit bt-input-text mr5" style="width:350px;" type="text" value="' + rdata.datadir + '" name="datadir">\
|
||||
<span onclick="changePath(\'datadir\')" class="glyphicon glyphicon-folder-open cursor mr20" style="width:auto"></span><button class="btn btn-success btn-sm" onclick="changeMySQLDataPath(1)">' + lan.soft.mysql_to + '</button>\
|
||||
</p>';
|
||||
$(".soft-man-con").html(LimitCon);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//数据库配置状态
|
||||
function myPerfOpt() {
|
||||
//获取MySQL配置
|
||||
@@ -1691,12 +1663,12 @@ function getMasterRepSlaveListPage(){
|
||||
}
|
||||
|
||||
|
||||
function deleteSlave(){
|
||||
myPost('delete_slave', {}, function(data){
|
||||
function deleteSlave(sign){
|
||||
myPost('delete_slave', {sign:sign}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
showMsg(rdata['msg'], function(){
|
||||
masterOrSlaveConf();
|
||||
},{},3000);
|
||||
},{icon:rdata.status?1:2,time:3000},3000);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1704,28 +1676,73 @@ function deleteSlave(){
|
||||
function getFullSyncStatus(db){
|
||||
var timeId = null;
|
||||
|
||||
var btn = '<div class="table_toolbar" style="left:0px;"><span data-status="init" class="sync btn btn-default btn-sm" id="begin_full_sync" title="">开始</span></div>';
|
||||
var loadOpen = layer.open({
|
||||
type: 1,
|
||||
title: '全量同步['+db+']',
|
||||
area: '500px',
|
||||
content:"<div class='bt-form pd20 c6'>\
|
||||
<div class='divtable mtb10'>\
|
||||
<span id='full_msg'></span>\
|
||||
<div class='progress'>\
|
||||
<div class='progress-bar' role='progressbar' aria-valuenow='0' aria-valuemin='0' aria-valuemax='100' style='min-width: 2em;'>0%</div>\
|
||||
</div>\
|
||||
</div>\
|
||||
"+btn+"\
|
||||
</div>",
|
||||
cancel: function(){
|
||||
clearInterval(timeId);
|
||||
myPost('get_slave_list', {page:1,page_size:100}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
var rsource = rdata.data;
|
||||
|
||||
if (db == 'ALL' && rsource.length>1){
|
||||
layer.msg("多主不支持该模式!",{icon:2});
|
||||
return;
|
||||
}
|
||||
|
||||
var dataSource = '';
|
||||
if (rsource.length>1){
|
||||
var sourceList = '';
|
||||
for (var i = 0; i < rsource.length; i++) {
|
||||
if ('Channel_Name' in rsource[i]){
|
||||
sourceList += '<option val="'+rsource[i]['Master_Host']+'">'+rsource[i]['Master_Host']+'</option>';
|
||||
}
|
||||
}
|
||||
|
||||
dataSource = "<p class='line' style='text-align:center;'>\
|
||||
<span>同步数据源:</span>\
|
||||
<select class='bt-input-text' name='data_source' style='width:200px;'>" + sourceList + "</select>\
|
||||
</p>";
|
||||
}
|
||||
|
||||
layer.open({
|
||||
type: 1,
|
||||
title: '全量同步['+db+']',
|
||||
area: '500px',
|
||||
content:"<div class='bt-form pd15'>\
|
||||
<div class='divtable mtb10'>\
|
||||
"+dataSource+"\
|
||||
<span id='full_msg'></span>\
|
||||
<div class='progress'>\
|
||||
<div class='progress-bar' role='progressbar' aria-valuenow='0' aria-valuemin='0' aria-valuemax='100' style='min-width: 2em;'>0%</div>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class='table_toolbar' style='left:0px;'>\
|
||||
<span data-status='init' class='sync btn btn-default btn-sm' id='begin_full_sync'>开始</span>\
|
||||
</div>\
|
||||
</div>",
|
||||
cancel: function(){
|
||||
clearInterval(timeId);
|
||||
},
|
||||
success:function(){
|
||||
$('#begin_full_sync').click(function(){
|
||||
var val = $(this).data('status');
|
||||
var sign = '';
|
||||
if (dataSource !=''){
|
||||
sign = $('select[name="data_source"]').val();
|
||||
}
|
||||
if (val == 'init'){
|
||||
fullSync(db, sign, 1);
|
||||
timeId = setInterval(function(){
|
||||
fullSync(db,sign,0);
|
||||
}, 1000);
|
||||
$(this).data('status','starting');
|
||||
} else {
|
||||
layer.msg("正在同步中..",{icon:0});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function fullSync(db,begin){
|
||||
function fullSync(db,sign,begin){
|
||||
|
||||
myPostN('full_sync', {db:db,begin:begin}, function(data){
|
||||
myPostN('full_sync', {db:db,sign:sign,begin:begin}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
$('#full_msg').text(rdata['msg']);
|
||||
$('.progress-bar').css('width',rdata['progress']+'%');
|
||||
@@ -1738,19 +1755,6 @@ function getFullSyncStatus(db){
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$('#begin_full_sync').click(function(){
|
||||
var val = $(this).attr('data-status');
|
||||
if (val == 'init'){
|
||||
fullSync(db,1);
|
||||
timeId = setInterval(function(){
|
||||
fullSync(db,0);
|
||||
}, 1000);
|
||||
$(this).attr('data-status','starting');
|
||||
} else {
|
||||
layer.msg("正在同步中..");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function addSlaveSSH(ip=''){
|
||||
@@ -1920,18 +1924,29 @@ function addSlaveSyncUser(ip=''){
|
||||
<div class='line'><span class='tname'>同步账户</span><div class='info-r'><input name='user' class='bt-input-text mr5' type='text' style='width:330px;' value='"+user+"'></div></div>\
|
||||
<div class='line'><span class='tname'>同步密码</span><div class='info-r'><input name='pass' class='bt-input-text mr5' type='text' style='width:330px;' value='"+pass+"'></div></div>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>CMD[最好填好]</span>\
|
||||
<span class='tname'>CMD[必须填写]</span>\
|
||||
<div class='info-r'><textarea class='bt-input-text mr5' row='20' cols='30' name='cmd' style='width:330px;height:150px;'></textarea></div>\
|
||||
</div>\
|
||||
<input type='hidden' name='mode' value='"+mode+"' />\
|
||||
</form>",
|
||||
success:function(){
|
||||
$('textarea[name="cmd"]').html(cmd);
|
||||
|
||||
$('textarea[name="cmd"]').change(function(){
|
||||
var val = $(this).val();
|
||||
var vlist = val.split(',');
|
||||
var a = {};
|
||||
if (val.toLowerCase().indexOf('for')>0){
|
||||
cmd_tmp = val.split('for');
|
||||
val = cmd_tmp[0].trim();
|
||||
|
||||
const channel_str = cmd_tmp[1].trim();
|
||||
const ch_reg = /channel \'(.*)\';/;
|
||||
var match_val = channel_str.match(ch_reg);
|
||||
if (match_val.length>1){
|
||||
a['channel'] = match_val[1];
|
||||
}
|
||||
}
|
||||
|
||||
var vlist = val.split(',');
|
||||
for (var i in vlist) {
|
||||
var tmp = toTrim(vlist[i]);
|
||||
var tmp_a = tmp.split(" ");
|
||||
@@ -2098,7 +2113,7 @@ function getSlaveUserList(){
|
||||
layerId = layer.open({
|
||||
type: 1,
|
||||
title: '同步账户列表',
|
||||
area: '500px',
|
||||
area: '600px',
|
||||
content:"<div class='bt-form pd20 c6'>\
|
||||
<div class='divtable mtb10'>\
|
||||
<div><table class='table table-hover get-slave-ssh-list'>\
|
||||
@@ -2122,7 +2137,7 @@ function getSlaveSSHList(page=1){
|
||||
layerId = layer.open({
|
||||
type: 1,
|
||||
title: 'SSH列表',
|
||||
area: '500px',
|
||||
area: '600px',
|
||||
content:"<div class='bt-form pd20 c6'>\
|
||||
<div class='divtable mtb10'>\
|
||||
<div><table class='table table-hover get-slave-ssh-list'>\
|
||||
@@ -2230,10 +2245,16 @@ function masterOrSlaveConf(version=''){
|
||||
myPost('get_slave_list', _data, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
var list = '';
|
||||
|
||||
var isHasSign = false;
|
||||
for(i in rdata.data){
|
||||
|
||||
var v = rdata.data[i];
|
||||
var status = "<a class='btlink db_error'>异常</>";
|
||||
if ('Channel_Name' in v){
|
||||
isHasSign = true;
|
||||
}
|
||||
|
||||
var status = "<a data-id="+i+" class='btlink db_error'>异常</>";
|
||||
if (v['Slave_SQL_Running'] == 'Yes' && v['Slave_IO_Running'] == 'Yes'){
|
||||
status = "正常";
|
||||
}
|
||||
@@ -2245,13 +2266,23 @@ function masterOrSlaveConf(version=''){
|
||||
list += '<td>' + rdata.data[i]['Master_Log_File'] +'</td>';
|
||||
list += '<td>' + rdata.data[i]['Slave_IO_Running'] +'</td>';
|
||||
list += '<td>' + rdata.data[i]['Slave_SQL_Running'] +'</td>';
|
||||
|
||||
if (isHasSign){
|
||||
list += '<td>' + v['Channel_Name'] +'</td>';
|
||||
}
|
||||
|
||||
list += '<td>' + status +'</td>';
|
||||
list += '<td style="text-align:right">' +
|
||||
'<a href="javascript:;" class="btlink" onclick="deleteSlave()" title="删除">删除</a>' +
|
||||
'<a data-id="'+i+'" href="javascript:;" class="btlink btn_delete_slave" title="删除">删除</a>' +
|
||||
'</td>';
|
||||
list += '</tr>';
|
||||
}
|
||||
|
||||
var signThead_th = '';
|
||||
if (isHasSign){
|
||||
var signThead_th = '<th>标识</th>';
|
||||
}
|
||||
|
||||
var con = '<div class="divtable mtb10">\
|
||||
<div class="tablescroll">\
|
||||
<table id="DataBody" class="table table-hover" width="100%" cellspacing="0" cellpadding="0" border="0" style="border: 0 none;">\
|
||||
@@ -2262,6 +2293,7 @@ function masterOrSlaveConf(version=''){
|
||||
<th>日志</th>\
|
||||
<th>IO</th>\
|
||||
<th>SQL</th>\
|
||||
'+signThead_th+'\
|
||||
<th>状态</th>\
|
||||
<th style="text-align:right;">操作</th></tr></thead>\
|
||||
<tbody>\
|
||||
@@ -2276,22 +2308,74 @@ function masterOrSlaveConf(version=''){
|
||||
// </div>
|
||||
$(".table_slave_status_list").html(con);
|
||||
|
||||
$('.db_error').click(function(){
|
||||
$(".btn_delete_slave").click(function(){
|
||||
var id = $(this).data('id');
|
||||
var v = rdata.data[id];
|
||||
if ('Channel_Name' in v){
|
||||
deleteSlave(v['Channel_Name']);
|
||||
} else{
|
||||
deleteSlave();
|
||||
}
|
||||
});
|
||||
|
||||
$('.db_error').click(function(){
|
||||
var id = $(this).data('id');
|
||||
var info = rdata.data[id];
|
||||
|
||||
var err_line = "";
|
||||
err_line +="<tr>\
|
||||
<td>IO错误</td>\
|
||||
<td>"+ (info['Last_IO_Error'] == '' ? '无':info['Last_IO_Error'])+"</td>\
|
||||
</tr>";
|
||||
err_line +="<tr>\
|
||||
<td>SQL错误</td>\
|
||||
<td>"+(info['Last_SQL_Error'] == '' ? '无':info['Last_SQL_Error'])+"</td>\
|
||||
</tr>";
|
||||
|
||||
err_line +="<tr>\
|
||||
<td>状态</td>\
|
||||
<td>"+(info['Slave_SQL_Running_State'] == '' ? '无':info['Slave_SQL_Running_State']) +"</td>\
|
||||
</tr>";
|
||||
|
||||
layer.open({
|
||||
type: 1,
|
||||
title: '同步异常信息',
|
||||
area: '500px',
|
||||
content:"<form class='bt-form pd20 pb70'>\
|
||||
<div class='line'>"+v['Error']+"</div>\
|
||||
<div class='bt-form-submit-btn'>\
|
||||
<button type='button' class='btn btn-success btn-sm btn-title class-copy-db-err'>复制</button>\
|
||||
area: ['600px','300px'],
|
||||
btn:['复制错误',"取消"],
|
||||
content:"<form class='bt-form pd15'>\
|
||||
<div class='divtable mtb10'>\
|
||||
<div class='tablescroll'>\
|
||||
<table class='table table-hover' width='100%' cellspacing='0' cellpadding='0' border='0' style='border: 0 none;'>\
|
||||
<thead><tr>\
|
||||
<th style='width:80px;'>类型</th>\
|
||||
<th>内容</th>\
|
||||
</tr></thead>\
|
||||
<tbody>"+ err_line +"</tbody>\
|
||||
</table>\
|
||||
</div>\
|
||||
</div>\
|
||||
</form>",
|
||||
</form>",
|
||||
success:function(){
|
||||
copyText(v['Error']);
|
||||
$('.class-copy-db-err').click(function(){
|
||||
copyText(v['Error']);
|
||||
});
|
||||
// copyText(v['Error']);
|
||||
// $('.class-copy-db-err').click(function(){
|
||||
// copyText(v['Error']);
|
||||
// });
|
||||
},
|
||||
yes:function(){
|
||||
if (info['Last_IO_Error'] != ''){
|
||||
copyText(info['Last_IO_Error']);
|
||||
return;
|
||||
}
|
||||
|
||||
if (info['Last_SQL_Error'] != ''){
|
||||
copyText(info['Last_SQL_Error']);
|
||||
return;
|
||||
}
|
||||
|
||||
if (info['Slave_SQL_Running_State'] != ''){
|
||||
copyText(info['Slave_SQL_Running_State']);
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -57,7 +57,7 @@ fi
|
||||
VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
|
||||
|
||||
|
||||
VERSION=8.0.30
|
||||
VERSION=8.0.34
|
||||
Install_mysql()
|
||||
{
|
||||
mkdir -p ${mysqlDir}
|
||||
@@ -109,11 +109,12 @@ Install_mysql()
|
||||
fi
|
||||
|
||||
if [ ! -f ${mysqlDir}/mysql-boost-${VERSION}.tar.gz ];then
|
||||
wget --no-check-certificate -O ${mysqlDir}/mysql-boost-${VERSION}.tar.gz --tries=3 https://cdn.mysql.com/archives/mysql-8.0/mysql-boost-${VERSION}.tar.gz
|
||||
#wget --no-check-certificate -O ${mysqlDir}/mysql-boost-${VERSION}.tar.gz --tries=3 https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-${VERSION}.tar.gz
|
||||
wget --no-check-certificate -O ${mysqlDir}/mysql-boost-${VERSION}.tar.gz --tries=3 https://cdn.mysql.com/archives/mysql-8.0/mysql-boost-${VERSION}.tar.gz
|
||||
fi
|
||||
|
||||
#检测文件是否损坏.
|
||||
md5_mysql_ok=313d625fcaa932bd87b48f0cf9b40f1c
|
||||
md5_mysql_ok=c8cfab52fbde1cca55accb3113c235eb
|
||||
if [ -f ${mysqlDir}/mysql-boost-${VERSION}.tar.gz ];then
|
||||
md5_mysql=`md5sum ${mysqlDir}/mysql-boost-${VERSION}.tar.gz | awk '{print $1}'`
|
||||
if [ "${md5_mysql_ok}" == "${md5_mysql}" ]; then
|
||||
@@ -121,7 +122,7 @@ Install_mysql()
|
||||
else
|
||||
# 重新下载
|
||||
rm -rf ${mysqlDir}/mysql-${VERSION}
|
||||
wget --no-check-certificate -O ${mysqlDir}/mysql-boost-${VERSION}.tar.gz --tries=3 https://cdn.mysql.com/archives/mysql-8.0/mysql-boost-${VERSION}.tar.gz
|
||||
wget --no-check-certificate -O ${mysqlDir}/mysql-boost-${VERSION}.tar.gz --tries=3 https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-${VERSION}.tar.gz
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -162,10 +163,10 @@ Install_mysql()
|
||||
add-apt-repository ppa:ubuntu-toolchain-r/test
|
||||
|
||||
LIBTIRPC_VER=`pkg-config libtirpc --modversion`
|
||||
if [ ! -f ${mysqlDir}/libtirpc_1.2.5.orig.tar.bz2 ];then
|
||||
wget --no-check-certificate -O ${mysqlDir}/libtirpc_1.2.5.orig.tar.bz2 https://launchpad.net/ubuntu/+archive/primary/+sourcefiles/libtirpc/1.2.5-1ubuntu0.1/libtirpc_1.2.5.orig.tar.bz2
|
||||
cd ${mysqlDir} && tar -jxvf libtirpc_1.2.5.orig.tar.bz2
|
||||
cd libtirpc-1.2.5 && ./configure
|
||||
if [ ! -f ${mysqlDir}/libtirpc_1.3.3.orig.tar.bz2 ];then
|
||||
wget --no-check-certificate -O ${mysqlDir}/libtirpc_1.3.3.orig.tar.bz2 https://downloads.sourceforge.net/libtirpc/libtirpc-1.3.3.tar.bz2
|
||||
cd ${mysqlDir} && tar -jxvf libtirpc_1.3.3.orig.tar.bz2
|
||||
cd libtirpc-1.3.3 && ./configure
|
||||
fi
|
||||
|
||||
export PKG_CONFIG_PATH=/usr/lib/pkgconfig
|
||||
|
||||
@@ -245,6 +245,7 @@
|
||||
<p onclick="wafScreen();">首页</p>
|
||||
<p onclick="wafGloabl();">全局配置</p>
|
||||
<p onclick="wafSite();">站点配置</p>
|
||||
<p onclick="wafAreaLimit();">地区限制</p>
|
||||
<p onclick="wafLogs();">封锁历史</p>
|
||||
<!-- <p onclick="wafOpLogs();">操作日志</p> -->
|
||||
</div>
|
||||
@@ -255,9 +256,13 @@
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<script src="/plugins/file?name=op_waf&f=js/op_waf.js"></script>
|
||||
<script type="text/javascript">
|
||||
resetPluginWinWidth(800);
|
||||
$.getScript( "/plugins/file?name=op_waf&f=js/op_waf.js", function(){
|
||||
|
||||
$.getScript( "/plugins/file?name=op_waf&f=js/op_waf.js", function(data, textStatus, jqxhr){
|
||||
// console.log(data, textStatus, jqxhr);
|
||||
pluginService('op_waf');
|
||||
});
|
||||
|
||||
</script>
|
||||
+365
-153
@@ -1,5 +1,9 @@
|
||||
# coding:utf-8
|
||||
|
||||
'''
|
||||
cd /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/op_waf && bash install.sh install 0.3.2
|
||||
python3 /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/op_waf/index.py reload
|
||||
'''
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
@@ -73,6 +77,10 @@ def getConf():
|
||||
return path
|
||||
|
||||
|
||||
def dstWafConfPath():
|
||||
return mw.getServerDir() + "/web_conf/nginx/vhost/opwaf.conf"
|
||||
|
||||
|
||||
def pSqliteDb(dbname='logs'):
|
||||
name = "waf"
|
||||
db_dir = getServerDir() + '/logs/'
|
||||
@@ -97,10 +105,9 @@ def pSqliteDb(dbname='logs'):
|
||||
return conn
|
||||
|
||||
|
||||
def initDomainInfo():
|
||||
def initDomainInfo(conf_reload=False):
|
||||
data = []
|
||||
path_domains = getJsonPath('domains')
|
||||
|
||||
_list = mw.M('sites').field('id,name,path').where(
|
||||
'status=?', ('1',)).order('id desc').select()
|
||||
|
||||
@@ -122,11 +129,12 @@ def initDomainInfo():
|
||||
mw.writeFile(path_domains, cjson)
|
||||
|
||||
|
||||
def initSiteInfo():
|
||||
def initSiteInfo(conf_reload=False):
|
||||
data = []
|
||||
|
||||
path_site = getJsonPath('site')
|
||||
path_domains = getJsonPath('domains')
|
||||
path_config = getJsonPath('config')
|
||||
path_site = getJsonPath('site')
|
||||
|
||||
config_contents = mw.readFile(path_config)
|
||||
config_contents = json.loads(config_contents)
|
||||
@@ -136,6 +144,8 @@ def initSiteInfo():
|
||||
|
||||
try:
|
||||
site_contents = mw.readFile(path_site)
|
||||
if not site_contents:
|
||||
site_contents = "{}"
|
||||
except Exception as e:
|
||||
site_contents = "{}"
|
||||
|
||||
@@ -192,10 +202,11 @@ def initSiteInfo():
|
||||
mw.writeFile(path_site, cjson)
|
||||
|
||||
|
||||
def initTotalInfo():
|
||||
def initTotalInfo(conf_reload=False):
|
||||
data = []
|
||||
path_domains = getJsonPath('domains')
|
||||
|
||||
path_total = getJsonPath('total')
|
||||
path_domains = getJsonPath('domains')
|
||||
|
||||
domain_contents = mw.readFile(path_domains)
|
||||
domain_contents = json.loads(domain_contents)
|
||||
@@ -230,10 +241,6 @@ def initTotalInfo():
|
||||
mw.writeFile(path_total, cjson)
|
||||
|
||||
|
||||
def dstWafConf():
|
||||
return mw.getServerDir() + "/web_conf/nginx/vhost/opwaf.conf"
|
||||
|
||||
|
||||
def contentReplace(content):
|
||||
service_path = mw.getServerDir()
|
||||
waf_root = getServerDir()
|
||||
@@ -242,121 +249,245 @@ def contentReplace(content):
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
content = content.replace('{$WAF_PATH}', waf_path)
|
||||
content = content.replace('{$WAF_ROOT}', waf_root)
|
||||
|
||||
if mw.isAppleSystem():
|
||||
content = content.replace('{$MMDB_FILE_SUFFIX}', 'dylib')
|
||||
else:
|
||||
content = content.replace('{$MMDB_FILE_SUFFIX}', 'so')
|
||||
|
||||
return content
|
||||
|
||||
|
||||
def autoMakeLuaConfSingle(file):
|
||||
# path = getPluginDir() + "/waf/rule/" + file + ".json"
|
||||
def autoMakeLuaConfSingle(file, conf_reload=False):
|
||||
path = getServerDir() + "/waf/rule/" + file + ".json"
|
||||
to_path = getServerDir() + "/waf/conf/rule_" + file + ".lua"
|
||||
dst_path = getServerDir() + "/waf/conf/rule_" + file + ".lua"
|
||||
if not os.path.exists(dst_path) or conf_reload:
|
||||
content = mw.readFile(path)
|
||||
# print(content)
|
||||
content = json.loads(content)
|
||||
listToLuaFile(dst_path, content)
|
||||
|
||||
|
||||
def autoCpImport(file):
|
||||
path = getPluginDir() + "/waf/" + file + ".json"
|
||||
dst_path = getServerDir() + "/waf/" + file + ".json"
|
||||
content = mw.readFile(path)
|
||||
# print(content)
|
||||
content = json.loads(content)
|
||||
listToLuaFile(to_path, content)
|
||||
mw.writeFile(dst_path, content)
|
||||
|
||||
|
||||
def autoMakeLuaImportSingle(file):
|
||||
def autoMakeLuaImportSingle(file, conf_reload=False):
|
||||
path = getServerDir() + "/waf/" + file + ".json"
|
||||
to_path = getServerDir() + "/waf/conf/waf_" + file + ".lua"
|
||||
content = mw.readFile(path)
|
||||
# print(content)
|
||||
content = json.loads(content)
|
||||
listToLuaFile(to_path, content)
|
||||
dst_path = getServerDir() + "/waf/conf/waf_" + file + ".lua"
|
||||
if not os.path.exists(dst_path) or conf_reload:
|
||||
content = mw.readFile(path)
|
||||
# print(content)
|
||||
content = json.loads(content)
|
||||
listToLuaFile(dst_path, content)
|
||||
|
||||
|
||||
def autoMakeLuaHtmlSingle(file):
|
||||
def autoMakeLuaHtmlSingle(file, conf_reload=False):
|
||||
path = getServerDir() + "/waf/html/" + file + ".html"
|
||||
to_path = getServerDir() + "/waf/html/html_" + file + ".lua"
|
||||
dst_path = getServerDir() + "/waf/html/html_" + file + ".lua"
|
||||
if not os.path.exists(dst_path) or conf_reload:
|
||||
content = mw.readFile(path)
|
||||
htmlToLuaFile(dst_path, content)
|
||||
|
||||
|
||||
def autoCpHtml(file):
|
||||
path = getPluginDir() + "/waf/html/" + file + ".html"
|
||||
dst_path = getServerDir() + "/waf/html/" + file + ".html"
|
||||
content = mw.readFile(path)
|
||||
htmlToLuaFile(to_path, content)
|
||||
mw.writeFile(dst_path, content)
|
||||
|
||||
|
||||
def autoMakeLuaConf():
|
||||
def autoMakeLuaConf(conf_reload=False, cp_reload=False):
|
||||
conf_list = ['args', 'cookie', 'ip_black', 'ip_white',
|
||||
'ipv6_black', 'post', 'scan_black', 'url',
|
||||
'url_white', 'user_agent']
|
||||
for x in conf_list:
|
||||
autoMakeLuaConfSingle(x)
|
||||
autoMakeLuaConfSingle(x, conf_reload)
|
||||
|
||||
import_list = ['config', 'site', 'domains']
|
||||
import_list = ['config', 'site', 'domains', 'area_limit']
|
||||
for x in import_list:
|
||||
autoMakeLuaImportSingle(x)
|
||||
autoMakeLuaImportSingle(x, conf_reload)
|
||||
|
||||
html_list = ['get', 'post', 'safe_js', 'user_agent', 'cookie', 'other']
|
||||
for x in html_list:
|
||||
autoMakeLuaHtmlSingle(x)
|
||||
if cp_reload:
|
||||
autoCpHtml(x)
|
||||
autoMakeLuaHtmlSingle(x, conf_reload)
|
||||
|
||||
|
||||
def initDefaultInfo():
|
||||
def initDefaultInfo(conf_reload=False):
|
||||
path = getServerDir()
|
||||
djson = path + "/waf/domains.json"
|
||||
default_json = path + "/waf/default.json"
|
||||
if os.path.exists(djson):
|
||||
content = mw.readFile(djson)
|
||||
content = json.loads(content)
|
||||
dst_path = path + "/waf/default.pl"
|
||||
default_site = ''
|
||||
if os.path.exists(dst_path):
|
||||
return True
|
||||
source_path = path + "/waf/domains.json"
|
||||
content = mw.readFile(source_path)
|
||||
content = json.loads(content)
|
||||
|
||||
ddata = {}
|
||||
dlist = []
|
||||
for i in content:
|
||||
dlist.append(i["name"])
|
||||
ddata = {}
|
||||
dlist = []
|
||||
for i in content:
|
||||
dlist.append(i["name"])
|
||||
|
||||
dlist.append('unset')
|
||||
ddata["list"] = dlist
|
||||
if len(ddata["list"]) < 1:
|
||||
ddata["default"] = "unset"
|
||||
else:
|
||||
ddata["default"] = dlist[0]
|
||||
dlist.append('unset')
|
||||
ddata["list"] = dlist
|
||||
if len(ddata["list"]) < 1:
|
||||
default_site = "unset"
|
||||
else:
|
||||
default_site = dlist[0]
|
||||
|
||||
mw.writeFile(default_json, json.dumps(ddata))
|
||||
mw.writeFile(dst_path, default_site)
|
||||
|
||||
|
||||
def autoMakeConfig():
|
||||
def getSiteListData():
|
||||
path = getServerDir()
|
||||
source_path = path + "/waf/domains.json"
|
||||
dst_path = path + "/waf/default.pl"
|
||||
|
||||
initDomainInfo()
|
||||
initSiteInfo()
|
||||
initTotalInfo()
|
||||
autoMakeLuaConf()
|
||||
content = mw.readFile(source_path)
|
||||
content = json.loads(content)
|
||||
dlist = []
|
||||
for i in content:
|
||||
dlist.append(i["name"])
|
||||
dlist.append('unset')
|
||||
|
||||
default_site = mw.readFile(dst_path)
|
||||
|
||||
data = {}
|
||||
data['list'] = dlist
|
||||
data['default'] = default_site
|
||||
return data
|
||||
|
||||
|
||||
def restartWeb():
|
||||
autoMakeConfig()
|
||||
def setDefaultSite(name):
|
||||
path = getServerDir()
|
||||
dst_path = path + "/waf/default.pl"
|
||||
mw.writeFile(dst_path, name)
|
||||
return mw.returnJson(True, 'OK')
|
||||
|
||||
|
||||
def getDefaultSite():
|
||||
data = getSiteListData()
|
||||
return mw.returnJson(True, 'OK', data)
|
||||
|
||||
|
||||
def getCountry():
|
||||
data = ['中国大陆以外的地区(包括[中国特别行政区:港,澳,台])', '中国大陆(不包括[中国特别行政区:港,澳,台])', '中国香港', '中国澳门', '中国台湾',
|
||||
'美国', '日本', '英国', '德国', '韩国', '法国', '巴西', '加拿大', '意大利', '澳大利亚', '荷兰', '俄罗斯', '印度', '瑞典', '西班牙', '墨西哥',
|
||||
'比利时', '南非', '波兰', '瑞士', '阿根廷', '印度尼西亚', '埃及', '哥伦比亚', '土耳其', '越南', '挪威', '芬兰', '丹麦', '乌克兰', '奥地利',
|
||||
'伊朗', '智利', '罗马尼亚', '捷克', '泰国', '沙特阿拉伯', '以色列', '新西兰', '委内瑞拉', '摩洛哥', '马来西亚', '葡萄牙', '爱尔兰', '新加坡',
|
||||
'欧洲联盟', '匈牙利', '希腊', '菲律宾', '巴基斯坦', '保加利亚', '肯尼亚', '阿拉伯联合酋长国', '阿尔及利亚', '塞舌尔', '突尼斯', '秘鲁', '哈萨克斯坦',
|
||||
'斯洛伐克', '斯洛文尼亚', '厄瓜多尔', '哥斯达黎加', '乌拉圭', '立陶宛', '塞尔维亚', '尼日利亚', '克罗地亚', '科威特', '巴拿马', '毛里求斯', '白俄罗斯',
|
||||
'拉脱维亚', '多米尼加', '卢森堡', '爱沙尼亚', '苏丹', '格鲁吉亚', '安哥拉', '玻利维亚', '赞比亚', '孟加拉国', '巴拉圭', '波多黎各', '坦桑尼亚',
|
||||
'塞浦路斯', '摩尔多瓦', '阿曼', '冰岛', '叙利亚', '卡塔尔', '波黑', '加纳', '阿塞拜疆', '马其顿', '约旦', '萨尔瓦多', '伊拉克', '亚美尼亚', '马耳他',
|
||||
'危地马拉', '巴勒斯坦', '斯里兰卡', '特立尼达和多巴哥', '黎巴嫩', '尼泊尔', '纳米比亚', '巴林', '洪都拉斯', '莫桑比克', '尼加拉瓜', '卢旺达', '加蓬',
|
||||
'阿尔巴尼亚', '利比亚', '吉尔吉斯坦', '柬埔寨', '古巴', '喀麦隆', '乌干达', '塞内加尔', '乌兹别克斯坦', '黑山', '关岛', '牙买加', '蒙古', '文莱',
|
||||
'英属维尔京群岛', '留尼旺', '库拉索岛', '科特迪瓦', '开曼群岛', '巴巴多斯', '马达加斯加', '伯利兹', '新喀里多尼亚', '海地', '马拉维', '斐济', '巴哈马',
|
||||
'博茨瓦纳', '扎伊尔', '阿富汗', '莱索托', '百慕大', '埃塞俄比亚', '美属维尔京群岛', '列支敦士登', '津巴布韦', '直布罗陀', '苏里南', '马里', '也门',
|
||||
'老挝', '塔吉克斯坦', '安提瓜和巴布达', '贝宁', '法属玻利尼西亚', '圣基茨和尼维斯', '圭亚那', '布基纳法索', '马尔代夫', '泽西岛', '摩纳哥', '巴布亚新几内亚',
|
||||
'刚果', '塞拉利昂', '吉布提', '斯威士兰', '缅甸', '毛里塔尼亚', '法罗群岛', '尼日尔', '安道尔', '阿鲁巴', '布隆迪', '圣马力诺', '利比里亚',
|
||||
'冈比亚', '不丹', '几内亚', '圣文森特岛', '荷兰加勒比区', '圣马丁', '多哥', '格陵兰', '佛得角', '马恩岛', '索马里', '法属圭亚那', '西萨摩亚',
|
||||
'土库曼斯坦', '瓜德罗普', '马里亚那群岛', '瓦努阿图', '马提尼克', '赤道几内亚', '南苏丹', '梵蒂冈', '格林纳达', '所罗门群岛', '特克斯和凯科斯群岛', '多米尼克',
|
||||
'乍得', '汤加', '瑙鲁', '圣多美和普林西比', '安圭拉岛', '法属圣马丁', '图瓦卢', '库克群岛', '密克罗尼西亚联邦', '根西岛', '东帝汶', '中非',
|
||||
'几内亚比绍', '帕劳', '美属萨摩亚', '厄立特里亚', '科摩罗', '圣皮埃尔和密克隆', '瓦利斯和富图纳', '英属印度洋领地', '托克劳', '马绍尔群岛', '基里巴斯',
|
||||
'纽埃', '诺福克岛', '蒙特塞拉特岛', '朝鲜', '马约特', '圣卢西亚', '圣巴泰勒米岛']
|
||||
return mw.returnJson(True, 'ok', data)
|
||||
|
||||
|
||||
def autoMakeConfig(conf_reload=False, cp_reload=False):
|
||||
initDomainInfo(conf_reload)
|
||||
initSiteInfo(conf_reload)
|
||||
initTotalInfo(conf_reload)
|
||||
autoMakeLuaConf(conf_reload, cp_reload)
|
||||
initDefaultInfo(conf_reload)
|
||||
|
||||
|
||||
def setConfRestartWeb():
|
||||
autoMakeConfig(True, False)
|
||||
mw.opWeb('stop')
|
||||
mw.opWeb('start')
|
||||
|
||||
|
||||
def makeDstLua():
|
||||
def restartWeb():
|
||||
mw.opWeb('stop')
|
||||
mw.opWeb('start')
|
||||
|
||||
|
||||
def makeOpDstRunLua(conf_reload=False):
|
||||
root_init_dir = mw.getServerDir() + '/web_conf/nginx/lua/init_by_lua_file'
|
||||
root_worker_dir = mw.getServerDir() + '/web_conf/nginx/lua/init_worker_by_lua_file'
|
||||
root_access_dir = mw.getServerDir() + '/web_conf/nginx/lua/access_by_lua_file'
|
||||
path = getServerDir()
|
||||
path_tpl = getPluginDir()
|
||||
|
||||
waf_common_tpl = path_tpl + "/waf/lua/waf_common.lua"
|
||||
waf_common_dst = path + "/waf/lua/waf_common.lua"
|
||||
content = mw.readFile(waf_common_tpl)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(waf_common_dst, content)
|
||||
if not os.path.exists(waf_common_dst) or conf_reload:
|
||||
waf_common_tpl = path_tpl + "/waf/lua/waf_common.lua"
|
||||
content = mw.readFile(waf_common_tpl)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(waf_common_dst, content)
|
||||
|
||||
waf_init_tpl = path_tpl + "/waf/lua/init_preload.lua"
|
||||
waf_init_dst = root_init_dir + "/waf_init_preload.lua"
|
||||
content = mw.readFile(waf_init_tpl)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(waf_init_dst, content)
|
||||
if not os.path.exists(waf_init_dst) or conf_reload:
|
||||
waf_init_tpl = path_tpl + "/waf/lua/init_preload.lua"
|
||||
content = mw.readFile(waf_init_tpl)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(waf_init_dst, content)
|
||||
|
||||
init_worker_tpl = path_tpl + "/waf/lua/init_worker.lua"
|
||||
init_worker_dst = root_worker_dir + '/opwaf_init_worker.lua'
|
||||
content = mw.readFile(init_worker_tpl)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(init_worker_dst, content)
|
||||
if not os.path.exists(init_worker_dst) or conf_reload:
|
||||
init_worker_tpl = path_tpl + "/waf/lua/init_worker.lua"
|
||||
content = mw.readFile(init_worker_tpl)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(init_worker_dst, content)
|
||||
|
||||
access_file_tpl = path_tpl + "/waf/lua/init.lua"
|
||||
access_file_dst = root_access_dir + '/opwaf_init.lua'
|
||||
content = mw.readFile(access_file_tpl)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(access_file_dst, content)
|
||||
if not os.path.exists(access_file_dst) or conf_reload:
|
||||
access_file_tpl = path_tpl + "/waf/lua/init.lua"
|
||||
access_file_dst_s = path + "/waf/lua/init.lua"
|
||||
content = mw.readFile(access_file_tpl)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(access_file_dst, content)
|
||||
mw.writeFile(access_file_dst_s, content)
|
||||
|
||||
waf_mmdb_dst = path + "/waf/lua/waf_maxminddb.lua"
|
||||
if not os.path.exists(waf_mmdb_dst) or conf_reload:
|
||||
waf_mmdb_tpl = path_tpl + "/waf/lua/waf_maxminddb.lua"
|
||||
content = mw.readFile(waf_mmdb_tpl)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(waf_mmdb_dst, content)
|
||||
|
||||
mw.opLuaMakeAll()
|
||||
return True
|
||||
|
||||
|
||||
def makeOpDstStopLua():
|
||||
root_init_dir = mw.getServerDir() + '/web_conf/nginx/lua/init_by_lua_file'
|
||||
root_worker_dir = mw.getServerDir() + '/web_conf/nginx/lua/init_worker_by_lua_file'
|
||||
root_access_dir = mw.getServerDir() + '/web_conf/nginx/lua/access_by_lua_file'
|
||||
|
||||
waf_init_dst = root_init_dir + "/waf_init_preload.lua"
|
||||
if os.path.exists(waf_init_dst):
|
||||
os.remove(waf_init_dst)
|
||||
|
||||
init_worker_dst = root_worker_dir + '/opwaf_init_worker.lua'
|
||||
if os.path.exists(init_worker_dst):
|
||||
os.remove(init_worker_dst)
|
||||
|
||||
access_file_dst = root_access_dir + '/opwaf_init.lua'
|
||||
if os.path.exists(access_file_dst):
|
||||
os.remove(access_file_dst)
|
||||
|
||||
wafconf = dstWafConfPath()
|
||||
if os.path.exists(wafconf):
|
||||
os.remove(wafconf)
|
||||
|
||||
mw.opLuaMakeAll()
|
||||
return True
|
||||
|
||||
|
||||
def initDreplace():
|
||||
@@ -377,30 +508,25 @@ def initDreplace():
|
||||
config = path + '/waf/config.json'
|
||||
content = mw.readFile(config)
|
||||
content = json.loads(content)
|
||||
|
||||
wfDir = path + "/waf/html"
|
||||
content['reqfile_path'] = wfDir
|
||||
content['reqfile_path'] = path + "/waf/html"
|
||||
mw.writeFile(config, mw.getJson(content))
|
||||
|
||||
makeDstLua()
|
||||
makeOpDstRunLua()
|
||||
|
||||
waf_conf = dstWafConf()
|
||||
waf_conf = dstWafConfPath()
|
||||
if not os.path.exists(waf_conf):
|
||||
waf_tpl = getPluginDir() + "/conf/luawaf.conf"
|
||||
content = mw.readFile(waf_tpl)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(waf_conf, content)
|
||||
|
||||
initDomainInfo()
|
||||
initSiteInfo()
|
||||
initTotalInfo()
|
||||
autoMakeLuaConf()
|
||||
initDefaultInfo()
|
||||
autoMakeConfig(True, False)
|
||||
|
||||
pSqliteDb()
|
||||
|
||||
if not mw.isAppleSystem():
|
||||
mw.execShell("chown -R www:www " + path)
|
||||
return path
|
||||
|
||||
|
||||
def status():
|
||||
@@ -408,7 +534,7 @@ def status():
|
||||
if not os.path.exists(path):
|
||||
return 'stop'
|
||||
|
||||
waf_conf = dstWafConf()
|
||||
waf_conf = dstWafConfPath()
|
||||
if not os.path.exists(waf_conf):
|
||||
return 'stop'
|
||||
return 'start'
|
||||
@@ -425,31 +551,12 @@ def start():
|
||||
|
||||
|
||||
def stop():
|
||||
root_init_dir = mw.getServerDir() + '/web_conf/nginx/lua/init_by_lua_file'
|
||||
root_worker_dir = mw.getServerDir() + '/web_conf/nginx/lua/init_worker_by_lua_file'
|
||||
root_access_dir = mw.getServerDir() + '/web_conf/nginx/lua/access_by_lua_file'
|
||||
|
||||
waf_init_dst = root_init_dir + "/waf_init_preload.lua"
|
||||
if os.path.exists(waf_init_dst):
|
||||
os.remove(waf_init_dst)
|
||||
|
||||
init_worker_dst = root_worker_dir + '/opwaf_init_worker.lua'
|
||||
if os.path.exists(init_worker_dst):
|
||||
os.remove(init_worker_dst)
|
||||
|
||||
access_file_dst = root_access_dir + '/opwaf_init.lua'
|
||||
if os.path.exists(access_file_dst):
|
||||
os.remove(access_file_dst)
|
||||
|
||||
wafconf = dstWafConf()
|
||||
if os.path.exists(wafconf):
|
||||
os.remove(wafconf)
|
||||
makeOpDstStopLua()
|
||||
|
||||
import tool_task
|
||||
tool_task.removeBgTask()
|
||||
|
||||
mw.opLuaMakeAll()
|
||||
|
||||
restartWeb()
|
||||
return 'ok'
|
||||
|
||||
@@ -460,16 +567,16 @@ def restart():
|
||||
|
||||
|
||||
def reload():
|
||||
stop()
|
||||
mw.opWeb('stop')
|
||||
|
||||
makeDstLua()
|
||||
makeOpDstRunLua(True)
|
||||
autoMakeConfig(True, False)
|
||||
|
||||
errlog = mw.getServerDir() + "/openresty/nginx/logs/error.log"
|
||||
mw.execShell('rm -rf ' + errlog)
|
||||
elog = mw.getServerDir() + "/openresty/nginx/logs/error.log"
|
||||
if os.path.exists(elog):
|
||||
mw.execShell('rm -rf ' + elog)
|
||||
|
||||
start()
|
||||
|
||||
restartWeb()
|
||||
mw.opWeb('start')
|
||||
return 'ok'
|
||||
|
||||
|
||||
@@ -519,7 +626,8 @@ def addRule():
|
||||
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(fpath, cjson)
|
||||
restartWeb()
|
||||
|
||||
setConfRestartWeb()
|
||||
return mw.returnJson(True, '设置成功!', content)
|
||||
|
||||
|
||||
@@ -541,7 +649,8 @@ def removeRule():
|
||||
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(fpath, cjson)
|
||||
restartWeb()
|
||||
|
||||
setConfRestartWeb()
|
||||
return mw.returnJson(True, '设置成功!', content)
|
||||
|
||||
|
||||
@@ -566,7 +675,8 @@ def setRuleState():
|
||||
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(fpath, cjson)
|
||||
restartWeb()
|
||||
|
||||
setConfRestartWeb()
|
||||
return mw.returnJson(True, '设置成功!', content)
|
||||
|
||||
|
||||
@@ -597,7 +707,8 @@ def modifyRule():
|
||||
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(fpath, cjson)
|
||||
restartWeb()
|
||||
|
||||
setConfRestartWeb()
|
||||
return mw.returnJson(True, '设置成功!', content)
|
||||
|
||||
|
||||
@@ -638,7 +749,8 @@ def addSiteRule():
|
||||
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
restartWeb()
|
||||
|
||||
setConfRestartWeb()
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
@@ -674,7 +786,7 @@ def addIpWhite():
|
||||
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
restartWeb()
|
||||
setConfRestartWeb()
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
@@ -696,7 +808,7 @@ def removeIpWhite():
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
|
||||
restartWeb()
|
||||
setConfRestartWeb()
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
@@ -733,7 +845,7 @@ def addIpBlack():
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
|
||||
restartWeb()
|
||||
setConfRestartWeb()
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
@@ -755,7 +867,7 @@ def removeIpBlack():
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
|
||||
restartWeb()
|
||||
setConfRestartWeb()
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
@@ -774,7 +886,7 @@ def setIpv6Black():
|
||||
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
restartWeb()
|
||||
setConfRestartWeb()
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
@@ -794,7 +906,7 @@ def delIpv6Black():
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
|
||||
restartWeb()
|
||||
setConfRestartWeb()
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
@@ -818,7 +930,7 @@ def removeSiteRule():
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
|
||||
restartWeb()
|
||||
setConfRestartWeb()
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
@@ -839,7 +951,7 @@ def setObjStatus():
|
||||
cjson = mw.getJson(cobj)
|
||||
mw.writeFile(conf, cjson)
|
||||
|
||||
restartWeb()
|
||||
setConfRestartWeb()
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
@@ -859,13 +971,13 @@ def setRetry():
|
||||
cjson = mw.getJson(cobj)
|
||||
mw.writeFile(conf, cjson)
|
||||
|
||||
restartWeb()
|
||||
setConfRestartWeb()
|
||||
return mw.returnJson(True, '设置成功!', [])
|
||||
|
||||
|
||||
def setSafeVerify():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['auto', 'time', 'cpu'])
|
||||
data = checkArgs(args, ['auto', 'time', 'cpu', 'mode'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
@@ -875,6 +987,7 @@ def setSafeVerify():
|
||||
|
||||
cobj['safe_verify']['time'] = args['time']
|
||||
cobj['safe_verify']['cpu'] = int(args['cpu'])
|
||||
cobj['safe_verify']['mode'] = args['mode']
|
||||
|
||||
if args['auto'] == '0':
|
||||
cobj['safe_verify']['auto'] = False
|
||||
@@ -884,7 +997,7 @@ def setSafeVerify():
|
||||
cjson = mw.getJson(cobj)
|
||||
mw.writeFile(conf, cjson)
|
||||
|
||||
restartWeb()
|
||||
setConfRestartWeb()
|
||||
return mw.returnJson(True, '设置成功!', [])
|
||||
|
||||
|
||||
@@ -915,7 +1028,7 @@ def setCcConf():
|
||||
cjson = mw.getJson(cobj)
|
||||
mw.writeFile(conf, cjson)
|
||||
|
||||
restartWeb()
|
||||
setConfRestartWeb()
|
||||
return mw.returnJson(True, '设置成功!', [])
|
||||
|
||||
|
||||
@@ -933,7 +1046,7 @@ def saveScanRule():
|
||||
cjson = mw.getJson(args)
|
||||
mw.writeFile(path, cjson)
|
||||
|
||||
restartWeb()
|
||||
setConfRestartWeb()
|
||||
return mw.returnJson(True, '设置成功!', [])
|
||||
|
||||
|
||||
@@ -973,26 +1086,6 @@ def getSiteConfig():
|
||||
return mw.returnJson(True, 'ok!', content)
|
||||
|
||||
|
||||
def getSiteListData():
|
||||
path = getServerDir() + "/waf/default.json"
|
||||
data = mw.readFile(path)
|
||||
return json.loads(data)
|
||||
|
||||
|
||||
def setDefaultSite(name):
|
||||
path = getServerDir() + "/waf/default.json"
|
||||
data = mw.readFile(path)
|
||||
data = json.loads(data)
|
||||
data['default'] = name
|
||||
mw.writeFile(path, json.dumps(data))
|
||||
return mw.returnJson(True, 'OK')
|
||||
|
||||
|
||||
def getDefaultSite():
|
||||
data = getSiteListData()
|
||||
return mw.returnJson(True, 'OK', data)
|
||||
|
||||
|
||||
def getSiteConfigByName():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['siteName'])
|
||||
@@ -1027,7 +1120,7 @@ def addSiteCdnHeader():
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
|
||||
restartWeb()
|
||||
setConfRestartWeb()
|
||||
return mw.returnJson(True, '添加成功!')
|
||||
|
||||
|
||||
@@ -1048,7 +1141,7 @@ def removeSiteCdnHeader():
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
|
||||
restartWeb()
|
||||
setConfRestartWeb()
|
||||
return mw.returnJson(True, '删除成功!')
|
||||
|
||||
|
||||
@@ -1103,6 +1196,8 @@ def getLogsList():
|
||||
domain = args['site']
|
||||
tojs = args['tojs']
|
||||
|
||||
setDefaultSite(domain)
|
||||
|
||||
conn = pSqliteDb('logs')
|
||||
|
||||
field = 'time,ip,domain,server_name,method,uri,user_agent,rule_name,reason'
|
||||
@@ -1172,7 +1267,7 @@ def setObjOpen():
|
||||
|
||||
cjson = mw.getJson(cobj)
|
||||
mw.writeFile(conf, cjson)
|
||||
restartWeb()
|
||||
setConfRestartWeb()
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
@@ -1202,7 +1297,7 @@ def setSiteObjOpen():
|
||||
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
restartWeb()
|
||||
setConfRestartWeb()
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
@@ -1216,6 +1311,117 @@ def getWafConf():
|
||||
return mw.readFile(conf)
|
||||
|
||||
|
||||
def getAreaLimit():
|
||||
conf = getJsonPath('area_limit')
|
||||
if not os.path.exists(conf):
|
||||
mw.writeFile(conf, '[]')
|
||||
|
||||
d = mw.readFile(conf)
|
||||
data = json.loads(d)
|
||||
return mw.returnJson(True, 'ok!', data)
|
||||
|
||||
|
||||
def delAreaLimit():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['site', 'types', 'region'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
type_list = ["refuse", "accept"]
|
||||
if not args['types'] in type_list:
|
||||
return mw.returnJson(False, '输入的类型错误!')
|
||||
|
||||
region_l = args['region'].split(",")
|
||||
site_l = args['site'].split(",")
|
||||
|
||||
paramMode = {}
|
||||
for i in region_l:
|
||||
if not i:
|
||||
continue
|
||||
i = i.strip()
|
||||
if not i in paramMode:
|
||||
paramMode[i] = "1"
|
||||
|
||||
sitesMode = {}
|
||||
for i in site_l:
|
||||
i = i.strip()
|
||||
if not i:
|
||||
continue
|
||||
|
||||
if not i in sitesMode:
|
||||
sitesMode[i] = "1"
|
||||
|
||||
if len(paramMode) == 0:
|
||||
return mw.returnJson(False, '输入的请求类型错误!')
|
||||
if len(sitesMode) == 0:
|
||||
return mw.returnJson(False, '输入的站点错误!')
|
||||
|
||||
conf = getJsonPath('area_limit')
|
||||
t_data = json.loads(mw.readFile(conf))
|
||||
|
||||
data = {"site": sitesMode, "types": args['types'], "region": paramMode}
|
||||
if not data in t_data:
|
||||
return mw.returnJson(False, '不存在!')
|
||||
|
||||
t_data.remove(data)
|
||||
mw.writeFile(conf, json.dumps(t_data))
|
||||
|
||||
setConfRestartWeb()
|
||||
return mw.returnJson(True, '删除成功!')
|
||||
|
||||
|
||||
def addAreaLimit():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['site', 'types', 'region'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
type_list = ["refuse", "accept"]
|
||||
if not args['types'] in type_list:
|
||||
return mw.returnJson(False, '输入的类型错误!')
|
||||
|
||||
region_l = args['region'].split(",")
|
||||
site_l = args['site'].split(",")
|
||||
|
||||
paramMode = {}
|
||||
for i in region_l:
|
||||
if not i:
|
||||
continue
|
||||
i = i.strip()
|
||||
if not i in paramMode:
|
||||
paramMode[i] = "1"
|
||||
|
||||
if '海外' in paramMode and '中国' in paramMode:
|
||||
return mw.returnJson(False, '不允许设置【中国大陆】和【中国大陆以外地区】一同开启地区限制!')
|
||||
|
||||
sitesMode = {}
|
||||
for i in site_l:
|
||||
i = i.strip()
|
||||
if not i:
|
||||
continue
|
||||
|
||||
if not i in sitesMode:
|
||||
sitesMode[i] = "1"
|
||||
|
||||
if len(paramMode) == 0:
|
||||
return mw.returnJson(False, '输入的请求类型错误!')
|
||||
if len(sitesMode) == 0:
|
||||
return mw.returnJson(False, '输入的站点错误!')
|
||||
|
||||
conf = getJsonPath('area_limit')
|
||||
t_data = json.loads(mw.readFile(conf))
|
||||
|
||||
data = {"site": sitesMode, "types": args['types'], "region": paramMode}
|
||||
if data in t_data:
|
||||
return mw.returnJson(False, '已存在!')
|
||||
|
||||
t_data.insert(0, data)
|
||||
mw.writeFile(conf, json.dumps(t_data))
|
||||
|
||||
setConfRestartWeb()
|
||||
return mw.returnJson(True, '添加成功!')
|
||||
|
||||
|
||||
def cleanDropIp():
|
||||
url = "http://127.0.0.1/clean_waf_drop_ip"
|
||||
data = mw.httpGet(url)
|
||||
@@ -1311,6 +1517,8 @@ if __name__ == "__main__":
|
||||
print(getSiteConfig())
|
||||
elif func == 'get_default_site':
|
||||
print(getDefaultSite())
|
||||
elif func == 'get_country':
|
||||
print(getCountry())
|
||||
elif func == 'get_site_config_byname':
|
||||
print(getSiteConfigByName())
|
||||
elif func == 'add_site_cdn_header':
|
||||
@@ -1329,8 +1537,12 @@ if __name__ == "__main__":
|
||||
print(getWafSrceen())
|
||||
elif func == 'waf_conf':
|
||||
print(getWafConf())
|
||||
elif func == 'waf_site':
|
||||
print(getWafSite())
|
||||
elif func == 'get_area_limit':
|
||||
print(getAreaLimit())
|
||||
elif func == 'add_area_limit':
|
||||
print(addAreaLimit())
|
||||
elif func == 'del_area_limit':
|
||||
print(delAreaLimit())
|
||||
elif func == 'clean_drop_ip':
|
||||
print(cleanDropIp())
|
||||
elif func == 'test_run':
|
||||
|
||||
@@ -24,5 +24,5 @@
|
||||
"home":"https://github.com/loveshell/ngx_lua_waf",
|
||||
"date":"2019-04-21",
|
||||
"pid": "1",
|
||||
"versions": ["0.2.6"]
|
||||
"versions": ["0.3.2"]
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
# cd /www/server/mdserver-web/plugins/op_waf && bash install.sh install 0.3.0
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
@@ -36,7 +38,6 @@ Install_App(){
|
||||
fi
|
||||
|
||||
# which luarocks
|
||||
# if [ "$?" != "0" ];then
|
||||
if [ ! -d $serverPath/op_waf/luarocks ];then
|
||||
cd $serverPath/source/op_waf && tar xvf luarocks-3.5.0.tar.gz
|
||||
# cd luarocks-3.9.1 && ./configure && make bootstrap
|
||||
@@ -83,11 +84,42 @@ Install_App(){
|
||||
cp -rf ${DEFAULT_DIR}/lsqlite3.so $serverPath/op_waf/waf/conf/lsqlite3.so
|
||||
fi
|
||||
|
||||
cn=$(curl -fsSL -m 10 http://ipinfo.io/json | grep "\"country\": \"CN\"")
|
||||
HTTP_PREFIX="https://"
|
||||
if [ ! -z "$cn" ];then
|
||||
HTTP_PREFIX="https://ghproxy.com/"
|
||||
fi
|
||||
|
||||
# download GeoLite Data
|
||||
GeoLite2_TAG=2023.08.10
|
||||
if [ ! -f $serverPath/op_waf/GeoLite2-City.mmdb ];then
|
||||
wget --no-check-certificate -O $serverPath/op_waf/GeoLite2-City.mmdb ${HTTP_PREFIX}github.com/P3TERX/GeoLite.mmdb/releases/download/${GeoLite2_TAG}/GeoLite2-City.mmdb
|
||||
fi
|
||||
|
||||
if [ ! -f $serverPath/op_waf/GeoLite2-Country.mmdb ];then
|
||||
wget --no-check-certificate -O $serverPath/op_waf/GeoLite2-Country.mmdb ${HTTP_PREFIX}github.com/P3TERX/GeoLite.mmdb/releases/download/${GeoLite2_TAG}/GeoLite2-Country.mmdb
|
||||
fi
|
||||
|
||||
libmaxminddb_ver='1.7.1'
|
||||
if [ ! -f $serverPath/op_waf/waf/mmdb/lib/libmaxminddb.a ] && [ ! -f $serverPath/op_waf/waf/mmdb/lib/libmaxminddb.so ];then
|
||||
libmaxminddb_local_path=$serverPath/source/op_waf/libmaxminddb-${libmaxminddb_ver}.tar.gz
|
||||
libmaxminddb_url_path=${HTTP_PREFIX}github.com/maxmind/libmaxminddb/releases/download/${libmaxminddb_ver}/libmaxminddb-${libmaxminddb_ver}.tar.gz
|
||||
if [ ! -f ${libmaxminddb_local_path} ]; then
|
||||
wget --no-check-certificate -O ${libmaxminddb_local_path} ${libmaxminddb_url_path}
|
||||
fi
|
||||
|
||||
cd $serverPath/source/op_waf && tar -zxvf ${libmaxminddb_local_path} && \
|
||||
cd $serverPath/source/op_waf/libmaxminddb-${libmaxminddb_ver} && \
|
||||
./configure --prefix=$serverPath/op_waf/waf/mmdb && make && make install
|
||||
fi
|
||||
|
||||
echo "${version}" > $serverPath/op_waf/version.pl
|
||||
echo 'install ok' > $install_tmp
|
||||
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/op_waf/index.py start
|
||||
# cd ${rootPath} && python3 ${rootPath}/plugins/op_waf/index.py restart
|
||||
echo "cd ${rootPath} && python3 ${rootPath}/plugins/op_waf/index.py start"
|
||||
sleep 2
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/op_waf/index.py reload
|
||||
}
|
||||
|
||||
Uninstall_App(){
|
||||
|
||||
+247
-7
@@ -14,6 +14,19 @@ function owPost(method, args, callback){
|
||||
},'json');
|
||||
}
|
||||
|
||||
function owPostN(method, args, callback){
|
||||
$.post('/plugins/run', {name:'op_waf', func:method, args:JSON.stringify(args)}, function(data) {
|
||||
if (!data.status){
|
||||
layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
if(typeof(callback) == 'function'){
|
||||
callback(data);
|
||||
}
|
||||
},'json');
|
||||
}
|
||||
|
||||
|
||||
function getRuleByName(rule_name, callback){
|
||||
owPost('get_rule', {rule_name:rule_name}, function(data){
|
||||
@@ -227,7 +240,7 @@ function setRetry(retry_cycle, retry, retry_time, siteName) {
|
||||
|
||||
|
||||
//设置safe_verify规则
|
||||
function setSafeVerify(auto, cpu, time, siteName) {
|
||||
function setSafeVerify(auto, cpu, time, mode,siteName) {
|
||||
var svlayer = layer.open({
|
||||
type: 1,
|
||||
title: "设置强制安全验证",
|
||||
@@ -241,7 +254,18 @@ function setSafeVerify(auto, cpu, time, siteName) {
|
||||
</div>\
|
||||
<div class="line">\
|
||||
<span class="tname">通行时间</span>\
|
||||
<div class="info-r"><input class="bt-input-text" name="time" type="number" value="'+ time + '" /> 秒</div>\
|
||||
<div class="info-r">\
|
||||
<input class="bt-input-text" name="time" type="number" value="'+ time + '" /> 秒\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class="line">\
|
||||
<span class="tname">验证模式</span>\
|
||||
<div class="info-r">\
|
||||
<select class="bt-input-text mr5" style="width:200px" name="mode">\
|
||||
<option value="url" '+(mode=='url'?"selected=selected":"")+'>URL跳转验证</option>\
|
||||
<option value="local" '+(mode=='local'?"selected=selected":"")+'>本地验证</option>\
|
||||
</select>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class="line">\
|
||||
<span class="tname">开启自动</span>\
|
||||
@@ -249,8 +273,8 @@ function setSafeVerify(auto, cpu, time, siteName) {
|
||||
<select class="bt-input-text mr5" style="width:80px" name="auto">\
|
||||
<option value="0" '+(auto==false?"selected=selected":"")+'>关闭</option>\
|
||||
<option value="1" '+(auto==true?"selected=selected":"")+'>开启</option>\
|
||||
</select>\
|
||||
</div>\
|
||||
</select>\
|
||||
</div>\
|
||||
</div>\
|
||||
<ul class="help-info-text c7 ptb10">\
|
||||
<li><font style="color:red;">全局设置强制安全验证</font></li>\
|
||||
@@ -266,6 +290,7 @@ function setSafeVerify(auto, cpu, time, siteName) {
|
||||
siteName: siteName,
|
||||
cpu: $("input[name='cpu']").val(),
|
||||
auto: $("select[name='auto']").val(),
|
||||
mode: $("select[name='mode']").val(),
|
||||
time: $("input[name='time']").val(),
|
||||
}
|
||||
var act = 'set_safe_verify';
|
||||
@@ -459,7 +484,7 @@ function scanRule() {
|
||||
var tmp = $.parseJSON(data.data);
|
||||
var rdata = $.parseJSON(tmp.data);
|
||||
|
||||
create_l = layer.open({
|
||||
create_l = ({
|
||||
type: 1,
|
||||
title: "常用扫描器过滤规则",
|
||||
area: '650px',
|
||||
@@ -1036,7 +1061,7 @@ function wafGloabl(){
|
||||
<input class="btswitch btswitch-ios" id="close_safe_verify" type="checkbox" '+(rdata.safe_verify.open ? 'checked' : '')+'>\
|
||||
<label class="btswitch-btn" for="close_safe_verify" onclick="setObjOpen(\'safe_verify\')"></label></div>\
|
||||
</td>\
|
||||
<td class="text-right"><a class="btlink" onclick="setSafeVerify('+ rdata.safe_verify.auto + ',' + rdata.safe_verify.cpu + ',' + rdata.safe_verify.time + ')">设置</a> | <a class="btlink" href="javascript:;" onclick="onlineEditFile(0,\''+rdata['reqfile_path']+'/safe_js.html\')">响应内容</a></td>\
|
||||
<td class="text-right"><a class="btlink" onclick="setSafeVerify('+ rdata.safe_verify.auto + ',' + rdata.safe_verify.cpu + ',' + rdata.safe_verify.time + ',\'' + rdata.safe_verify.mode + '\')">设置</a> | <a class="btlink" href="javascript:;" onclick="onlineEditFile(0,\''+rdata['reqfile_path']+'/safe_js.html\')">响应内容</a></td>\
|
||||
</tr>\
|
||||
<tr>\
|
||||
<td>GET-URI过滤</td>\
|
||||
@@ -1622,6 +1647,221 @@ function wafSite(){
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function wafAreaLimitRender(){
|
||||
function keyVal(obj){
|
||||
var str = [];
|
||||
$.each(obj, function (index, item) {
|
||||
if (item == 1) {
|
||||
if (index == 'allsite') index = '所有站点';
|
||||
if (index == '海外') index = '中国大陆以外的地区(包括[港,澳,台])';
|
||||
if (index == '中国') index = '中国大陆(不包括[港,澳,台])';
|
||||
str.push(index);
|
||||
}
|
||||
});
|
||||
return str.toString();
|
||||
}
|
||||
owPost('get_area_limit', {}, function(rdata) {
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
if (!rdata.status) {
|
||||
layer.msg(rdata.msg, { icon: 2, time: 2000 });
|
||||
return;
|
||||
}
|
||||
|
||||
var list = '';
|
||||
var rlist = rdata.data;
|
||||
|
||||
for (var i = 0; i < rlist.length; i++) {
|
||||
var op = '';
|
||||
var type = rlist[i]['types'] === 'refuse' ? '拦截' : '只放行';
|
||||
var region_str = keyVal(rlist[i]['region']);
|
||||
var site_str = keyVal(rlist[i]['site']);
|
||||
|
||||
op += '<a data-id="'+i+'" href="javascript:;" class="area_limit_del btlink">删除</a>';
|
||||
|
||||
list += '<tr>';
|
||||
list += '<td><span class="overflow_hide" style="width: 303px;" title="'+region_str+'"">' + region_str + '</span></td>';
|
||||
list += '<td>' + site_str + '</td>';
|
||||
list += '<td>' + type + '</td>';
|
||||
|
||||
list += '<td class="text-right">' + op + '</td>';
|
||||
list += '</tr>';
|
||||
}
|
||||
|
||||
$('#con_list tbody').html(list);
|
||||
$('.area_limit_del').click(function(){
|
||||
var data_id = $(this).data('id');
|
||||
|
||||
var site = [],region = [];
|
||||
$.each(rlist[data_id]['site'], function (index, item) {
|
||||
site.push(index);
|
||||
});
|
||||
$.each(rlist[data_id]['region'], function (index, item) {
|
||||
region.push(index);
|
||||
});
|
||||
|
||||
var type = rlist[data_id]['types'];
|
||||
|
||||
owPost('del_area_limit', {
|
||||
site:site.toString(),
|
||||
region:region.toString(),
|
||||
types:type,
|
||||
}, function(rdata) {
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
showMsg(rdata.msg, function(){
|
||||
if (rdata.status){
|
||||
wafAreaLimit();
|
||||
}
|
||||
},{ icon: rdata.status ? 1 : 2 });
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 地区限制
|
||||
function wafAreaLimit(){
|
||||
var con = '<div class="safe bgw">\
|
||||
<button id="create_area_limit" class="btn btn-success btn-sm" type="button" style="margin-right: 5px;">添加地区限制</button>\
|
||||
<div class="divtable mtb10">\
|
||||
<div class="tablescroll">\
|
||||
<table id="con_list" class="table table-hover" width="100%" cellspacing="0" cellpadding="0" border="0" style="border: 0 none;">\
|
||||
<thead><tr>\
|
||||
<th>地区</th>\
|
||||
<th>站点</th>\
|
||||
<th>类型</th>\
|
||||
<th style="text-align:right;">操作</th></tr></thead>\
|
||||
<tbody></tbody></table>\
|
||||
</div>\
|
||||
</div>\
|
||||
</div>';
|
||||
$(".soft-man-con").html(con);
|
||||
wafAreaLimitRender();
|
||||
|
||||
$('#create_area_limit').click(function(){
|
||||
var site_list;
|
||||
var area_list;
|
||||
var site_length = 0;
|
||||
layer.open({
|
||||
type: 1,
|
||||
title: '添加地区限制',
|
||||
area: ['450px','280px'],
|
||||
closeBtn: 1,
|
||||
btn: ['添加', '取消'],
|
||||
content: '<div class="waf-form pd20">\
|
||||
<div class="line">\
|
||||
<span class="tname">类型</span>\
|
||||
<div class="info-r c4">\
|
||||
<select name="type" class="bt-input-text" style="width:230px">\
|
||||
<option value="refuse" selected="">拦截</option>\
|
||||
<option value="accept">只放行</option>\
|
||||
</select>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class="line">\
|
||||
<span class="tname">站点</span>\
|
||||
<div class="info-r">\
|
||||
<div id="site_list"></div>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class="line">\
|
||||
<span class="tname">地区</span>\
|
||||
<div class="info-r" id="area_list"></div>\
|
||||
</div>\
|
||||
</div>',
|
||||
success: function (layers, index) {
|
||||
document.getElementById('layui-layer' + index).getElementsByClassName('layui-layer-content')[0].style.overflow = 'unset';
|
||||
|
||||
site_list = xmSelect.render({
|
||||
el: '#site_list',
|
||||
language: 'zn',
|
||||
toolbar: {show: true,},
|
||||
paging: true,
|
||||
pageSize: 10,
|
||||
data: [],
|
||||
});
|
||||
|
||||
owPostN('get_default_site','', function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
var rlist = rdata.data.list;
|
||||
|
||||
|
||||
var pdata = [];
|
||||
for (var i = 0; i < rlist.length; i++) {
|
||||
var tval = rlist[i];
|
||||
if (tval != 'unset'){
|
||||
var t = {name:rlist[i],value:rlist[i]};
|
||||
pdata.push(t);
|
||||
}
|
||||
}
|
||||
site_length = pdata.length;
|
||||
site_list.update({data:pdata});
|
||||
});
|
||||
|
||||
area_list = xmSelect.render({
|
||||
el: '#area_list',
|
||||
language: 'zn',
|
||||
toolbar: {show: true,},
|
||||
filterable: true,
|
||||
data: [],
|
||||
});
|
||||
owPostN('get_country','', function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
var rlist = rdata.data;
|
||||
|
||||
var pdata = [];
|
||||
for (var i = 0; i < rlist.length; i++) {
|
||||
var tval = rlist[i];
|
||||
if (tval != 'unset'){
|
||||
var t = {name:tval,value:tval};
|
||||
pdata.push(t);
|
||||
}
|
||||
}
|
||||
|
||||
area_list.update({data:pdata});
|
||||
});
|
||||
},
|
||||
yes: function (indexs) {
|
||||
|
||||
var reg_type = $('select[name="type"]').val();
|
||||
var site_val = site_list.getValue('value');
|
||||
var area_val = area_list.getValue('value');
|
||||
|
||||
if (area_val.length <1) return layer.msg('地区最少选一个!', { icon: 2 });
|
||||
if (site_val.length <1) return layer.msg('站点最少选一个!', { icon: 2 });
|
||||
|
||||
var site = '';
|
||||
if (site_length === site_val.length) {
|
||||
site = 'allsite';
|
||||
} else {
|
||||
site = site_val.join();
|
||||
}
|
||||
|
||||
var area = area_val.join();
|
||||
var region = area.replace('中国大陆以外的地区(包括[中国特别行政区:港,澳,台])', '海外')
|
||||
.replace('中国大陆(不包括[中国特别行政区:港,澳,台])', '中国')
|
||||
.replace('中国香港', '香港')
|
||||
.replace('中国澳门', '澳门')
|
||||
.replace('中国台湾', '台湾');
|
||||
|
||||
owPost('add_area_limit',{
|
||||
site:site,
|
||||
types:reg_type,
|
||||
region:region,
|
||||
}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
showMsg(rdata.msg, function(){
|
||||
if (rdata.status){
|
||||
layer.close(indexs);
|
||||
wafAreaLimit();
|
||||
}
|
||||
},{ icon: rdata.status ? 1 : 2 });
|
||||
});
|
||||
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function wafLogRequest(page){
|
||||
var args = {};
|
||||
args['page'] = page;
|
||||
@@ -1797,7 +2037,7 @@ function wafLogs(){
|
||||
wafLogRequest(1);
|
||||
});
|
||||
|
||||
owPost('get_default_site',{},function(rdata){
|
||||
owPostN('get_default_site',{},function(rdata){
|
||||
$('select[name="site"]').html('');
|
||||
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
@@ -1 +1,66 @@
|
||||
{"reqfile_path": "{$WAF_PATH}/html", "retry": {"retry_time": 180, "is_open_global": 0, "retry": 6, "retry_cycle": 60}, "log": true, "scan": {"status": 444, "ps": "过滤常见扫描测试工具的渗透测试", "open": true, "reqfile": ""}, "cc": {"status": 444, "ps": "过虑CC攻击", "limit": 120, "endtime": 300, "open": true,"cycle": 60}, "safe_verify":{"status": 200,"ps": "强制安全校验", "reqfile": "safe_js.html","open": false,"cpu":50,"auto":true,"time":86400 },"get": {"status": 200, "ps": "过滤uri、uri参数中常见sql注入、xss等攻击", "open": true, "reqfile": "get.html"}, "log_save": 30, "user-agent": {"status": 200, "ps": "通常用于过滤浏览器、蜘蛛及一些自动扫描器", "open": true, "reqfile": "user_agent.html"}, "other": {"status": 200, "ps": "其它非通用过滤", "reqfile": "other.html"}, "cookie": {"status": 200, "ps": "过滤利用Cookie发起的渗透攻击", "open": true, "reqfile": "cookie.html"}, "logs_path": "/www/wwwlogs/waf", "post": {"status": 200, "ps": "过滤POST参数中常见sql注入、xss等攻击", "open": true, "reqfile": "post.html"}, "open": true}
|
||||
{
|
||||
"reqfile_path": "{$WAF_PATH}/html",
|
||||
"retry": {
|
||||
"retry_time": 180,
|
||||
"is_open_global": 0,
|
||||
"retry": 6,
|
||||
"retry_cycle": 60
|
||||
},
|
||||
"log": true,
|
||||
"scan": {
|
||||
"status": 444,
|
||||
"ps": "过滤常见扫描测试工具的渗透测试",
|
||||
"open": true,
|
||||
"reqfile": ""
|
||||
},
|
||||
"cc": {
|
||||
"status": 444,
|
||||
"ps": "过虑CC攻击",
|
||||
"limit": 120,
|
||||
"endtime": 300,
|
||||
"open": true,
|
||||
"cycle": 60
|
||||
},
|
||||
"safe_verify": {
|
||||
"status": 200,
|
||||
"ps": "强制安全校验",
|
||||
"reqfile": "safe_js.html",
|
||||
"open": false,
|
||||
"mode":"local",
|
||||
"cpu": 50,
|
||||
"auto": true,
|
||||
"time": 86400
|
||||
},
|
||||
"get": {
|
||||
"status": 200,
|
||||
"ps": "过滤uri、uri参数中常见sql注入、xss等攻击",
|
||||
"open": true,
|
||||
"reqfile": "get.html"
|
||||
},
|
||||
"log_save": 30,
|
||||
"user-agent": {
|
||||
"status": 200,
|
||||
"ps": "通常用于过滤浏览器、蜘蛛及一些自动扫描器",
|
||||
"open": true,
|
||||
"reqfile": "user_agent.html"
|
||||
},
|
||||
"other": {
|
||||
"status": 200,
|
||||
"ps": "其它非通用过滤",
|
||||
"reqfile": "other.html"
|
||||
},
|
||||
"cookie": {
|
||||
"status": 200,
|
||||
"ps": "过滤利用Cookie发起的渗透攻击",
|
||||
"open": true,
|
||||
"reqfile": "cookie.html"
|
||||
},
|
||||
"logs_path": "/www/wwwlogs/waf",
|
||||
"post": {
|
||||
"status": 200,
|
||||
"ps": "过滤POST参数中常见sql注入、xss等攻击",
|
||||
"open": true,
|
||||
"reqfile": "post.html"
|
||||
},
|
||||
"open": true
|
||||
}
|
||||
@@ -19,7 +19,7 @@
|
||||
<div class="main">
|
||||
<div class="title">OP网站防火墙|安全校验</div>
|
||||
<div class="content">
|
||||
<p id="change">5</p>
|
||||
<p id="change">3</p>
|
||||
</div>
|
||||
<div id="status" style="display: none;">false</div>
|
||||
</div>
|
||||
@@ -27,6 +27,15 @@
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
function getQueryString(name) {
|
||||
let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
|
||||
let r = window.location.search.substr(1).match(reg);
|
||||
if (r != null) {
|
||||
return decodeURIComponent(r[2]);
|
||||
};
|
||||
return null;
|
||||
}
|
||||
|
||||
function ajax(type,bool){
|
||||
var xhr = {};
|
||||
if(typeof(type)=='undefined'){
|
||||
@@ -125,22 +134,29 @@ function ajax(type,bool){
|
||||
return xhr;
|
||||
}
|
||||
|
||||
ajax('JSON',true).post('{uri}',{'pass':"ok"}, function(data){
|
||||
if (data['status'] == 0){
|
||||
document.getElementById('status').innerHTML = 'ok';
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
|
||||
var ok = setInterval(function(){
|
||||
var id = document.getElementById('change').innerHTML;
|
||||
id = id - 1;
|
||||
if (id == 0){
|
||||
document.getElementById('change').innerHTML = '稍等';
|
||||
clearInterval(ok);
|
||||
if (document.getElementById('status').innerHTML == 'ok'){
|
||||
location.reload();
|
||||
}
|
||||
ajax('JSON',true).post('{uri}',{'pass':"ok"}, function(data){
|
||||
if (data['status'] == 0 && data['msg'] == 'ok'){
|
||||
document.getElementById('status').innerHTML = 'ok';
|
||||
setTimeout(function(){
|
||||
var f = getQueryString('f');
|
||||
// console.log(f,typeof(f));
|
||||
if (f && f!=''){
|
||||
location.href = f;
|
||||
} else {
|
||||
location.reload();
|
||||
}
|
||||
|
||||
},500);
|
||||
} else{
|
||||
document.getElementById('change').innerHTML = '?';
|
||||
}
|
||||
});
|
||||
} else {
|
||||
document.getElementById('change').innerHTML = id;
|
||||
}
|
||||
|
||||
+163
-12
@@ -35,10 +35,10 @@ local cookie_rules = require "rule_cookie"
|
||||
local url_rules = require "rule_url"
|
||||
local url_white_rules = require "rule_url_white"
|
||||
|
||||
local waf_area_limit = require "waf_area_limit"
|
||||
|
||||
-- local server_name = string.gsub(C:get_sn(config_domains),'_','.')
|
||||
local server_name = C:get_sn(config_domains)
|
||||
|
||||
local function initParams()
|
||||
local data = {}
|
||||
data['server_name'] = server_name
|
||||
@@ -53,10 +53,12 @@ local function initParams()
|
||||
data['user_agent'] = data['request_header']['user-agent']
|
||||
data['cookie'] = ngx.var.http_cookie
|
||||
data['time'] = ngx.time()
|
||||
|
||||
return data
|
||||
end
|
||||
|
||||
local params = initParams()
|
||||
-- C:D(C:to_json(params))
|
||||
C:setParams(params)
|
||||
|
||||
local cpu_percent = ngx.shared.waf_limit:get("cpu_usage")
|
||||
@@ -343,6 +345,7 @@ local function waf_cc_increase()
|
||||
local make_uri_str = "?token="..make_token
|
||||
local make_uri = "/"..make_uri_str
|
||||
|
||||
-- C:D("token:"..tostring(params['uri_request_args']['token']))
|
||||
if params['uri_request_args']['token'] then
|
||||
ngx.header.content_type = "application/json"
|
||||
local args_token = params['uri_request_args']['token']
|
||||
@@ -352,18 +355,37 @@ local function waf_cc_increase()
|
||||
ngx.say(json.encode(data))
|
||||
ngx.exit(200)
|
||||
end
|
||||
|
||||
-- C:D("debug[args]:"..tostring(params['uri_request_args']['debug']))
|
||||
-- if params['uri_request_args']['debug'] == 'ok' then
|
||||
-- ngx.header.content_type = "application/json"
|
||||
-- local data = get_return_state(0, "ok")
|
||||
-- ngx.say(json.encode(data))
|
||||
-- ngx.exit(200)
|
||||
-- end
|
||||
local data = get_return_state(0, "unset")
|
||||
ngx.say(json.encode(data))
|
||||
ngx.exit(200)
|
||||
end
|
||||
|
||||
local cc_html = ngx.re.gsub(cc_safe_js_html, "{uri}", make_uri_str)
|
||||
C:return_html(200, cc_html)
|
||||
if not config['safe_verify']['mode'] then return false end
|
||||
|
||||
-- C:D(C:to_json(params['uri_request_args']))
|
||||
if config['safe_verify']['mode'] == 'url' then
|
||||
local page = 'safe_verify_'..cache_token
|
||||
local request_uri = params['request_uri']
|
||||
local to_url = '/?'..page..'&f='..request_uri
|
||||
|
||||
local cache_url_key = cache_token..':url'
|
||||
local cache_url_val = ngx.shared.waf_limit:get(cache_url_key)
|
||||
|
||||
if params['uri_request_args'][page] then
|
||||
local cc_html = ngx.re.gsub(cc_safe_js_html, "{uri}", make_uri_str)
|
||||
return C:return_html(200, cc_html)
|
||||
end
|
||||
|
||||
if not cache_url_val then
|
||||
ngx.shared.waf_limit:set(cache_url_key, request_uri,30)
|
||||
return ngx.redirect(to_url)
|
||||
end
|
||||
end
|
||||
|
||||
if config['safe_verify']['mode'] == 'local' then
|
||||
local cc_html = ngx.re.gsub(cc_safe_js_html, "{uri}", make_uri_str)
|
||||
C:return_html(200, cc_html)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -529,16 +551,125 @@ local function waf_cookie()
|
||||
return false
|
||||
end
|
||||
|
||||
local geo=nil
|
||||
local waf_country=""
|
||||
local geo2=nil
|
||||
|
||||
function waf()
|
||||
|
||||
local function initmaxminddb()
|
||||
if geo==nil then
|
||||
maxminddb ,geo = pcall(function() return require 'waf_maxminddb' end)
|
||||
if not maxminddb then
|
||||
C:D("debug waf error on :"..tostring(geo))
|
||||
return nil
|
||||
end
|
||||
end
|
||||
if type(geo)=='number' then return nil end
|
||||
local ok2,data=pcall(function()
|
||||
if not geo.initted() then
|
||||
geo.init("{$WAF_ROOT}/GeoLite2-City.mmdb")
|
||||
end
|
||||
end )
|
||||
if not ok2 then
|
||||
geo=nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function get_ip_country(ip)
|
||||
initmaxminddb()
|
||||
if type(geo)=='number' then return "2" end
|
||||
if geo==nil then return "2" end
|
||||
if geo.lookup==nil then return "2" end
|
||||
local res,err=geo.lookup(ip or ngx.var.remote_addr)
|
||||
if not res then
|
||||
return "2"
|
||||
else
|
||||
C:D("res:"..tostring(res))
|
||||
return res
|
||||
end
|
||||
end
|
||||
|
||||
local function get_country()
|
||||
local ip = params['ip']
|
||||
if ngx.shared.waf_limit:get("get_country"..ip) then
|
||||
return ngx.shared.waf_limit:get("get_country"..ip)
|
||||
end
|
||||
local ip_postion=get_ip_country(ip)
|
||||
if ip_postion=="2" then return false end
|
||||
if ip_postion["country"]==nil then return false end
|
||||
if ip_postion["country"]["names"]==nil then return false end
|
||||
if ip_postion["country"]["names"]["zh-CN"]==nil then return false end
|
||||
ngx.shared.waf_limit:set("get_country"..ip,ip_postion["country"]["names"]["zh-CN"],3600)
|
||||
return ip_postion["country"]["names"]["zh-CN"]
|
||||
end
|
||||
|
||||
local function area_limit(overall_country, server_name, status)
|
||||
|
||||
if not status then
|
||||
return false
|
||||
end
|
||||
|
||||
if overall_country and overall_country~="" and C:count_size(waf_area_limit)>=1 then
|
||||
for k, val in pairs(waf_area_limit) do
|
||||
-- C:D(tostring(k)..':'..tostring(val['site']['allsite']) ..':'.. tostring(val['site']['allsite'] == '1') ..':'.. tostring(val['site']['allsite']))
|
||||
if val['site']['allsite'] and val['site']['allsite'] == '1' and val['types'] == 'refuse' then
|
||||
for rk, reg_val in pairs(val['region']) do
|
||||
if rk == overall_country then
|
||||
ngx.exit(403)
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if val['site'][server_name] and val['site'][server_name] == '1' and val['types'] == 'refuse' then
|
||||
for rk, reg_val in pairs(val['region']) do
|
||||
if rk == overall_country then
|
||||
ngx.exit(403)
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if val['site']['allsite'] and val['site']['allsite'] == '1' and val['types'] == 'accept' then
|
||||
for rk, reg_val in pairs(val['region']) do
|
||||
if rk == overall_country then
|
||||
return false
|
||||
end
|
||||
end
|
||||
ngx.exit(403)
|
||||
return true
|
||||
end
|
||||
|
||||
if val['site'][server_name] and val['site'][server_name] == '1' and val['types'] == 'accept' then
|
||||
for rk, reg_val in pairs(val['region']) do
|
||||
if rk == overall_country then
|
||||
return false
|
||||
end
|
||||
end
|
||||
ngx.exit(403)
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function run_app_waf()
|
||||
min_route()
|
||||
-- C:D("min_route")
|
||||
-- country limit
|
||||
local waf_country = get_country()
|
||||
if area_limit(waf_country, server_name, site_config[server_name]['open']) then return true end
|
||||
|
||||
if site_config[server_name] and site_config[server_name]['open'] then
|
||||
|
||||
|
||||
-- white ip
|
||||
if waf_ip_white() then return true end
|
||||
-- C:D("waf_ip_white")
|
||||
|
||||
|
||||
-- url white
|
||||
if waf_url_white() then return true end
|
||||
-- C:D("waf_url_white")
|
||||
@@ -589,4 +720,24 @@ function waf()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local waf_run_status = nil
|
||||
function waf()
|
||||
if waf_run_status then
|
||||
run_app_waf()
|
||||
else
|
||||
local ok,waf_err=pcall(function()
|
||||
run_app_waf()
|
||||
end)
|
||||
|
||||
if waf_err ~= nil then
|
||||
C:D("----waf error-----"..tostring(waf_err))
|
||||
end
|
||||
|
||||
if ok then
|
||||
waf_run_status = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
waf()
|
||||
@@ -26,7 +26,7 @@ local function waf_timer_stats_total_log(premature)
|
||||
WAF_C:timer_stats_total()
|
||||
end
|
||||
|
||||
local waf_clean_expire_data = function(premature)
|
||||
local function waf_clean_expire_data(premature)
|
||||
WAF_C:clean_log()
|
||||
end
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ end
|
||||
|
||||
function _M.initDB(self)
|
||||
local path = log_dir .. "/waf.db"
|
||||
db, err = sqlite3.open(path)
|
||||
local db, err = sqlite3.open(path)
|
||||
|
||||
if err then
|
||||
self:D("initDB err:"..tostring(err))
|
||||
@@ -207,7 +207,7 @@ function _M.D(self, msg)
|
||||
local _msg = ''
|
||||
if type(msg) == 'table' then
|
||||
for key, val in pairs(msg) do
|
||||
_msg = tostring( key)..':'.."\n"
|
||||
_msg = tostring(key)..':'.."\n"
|
||||
end
|
||||
elseif type(msg) == 'string' then
|
||||
_msg = msg
|
||||
@@ -277,6 +277,16 @@ function _M.setParams( self, params )
|
||||
self.params = params
|
||||
end
|
||||
|
||||
function _M.count_size(data)
|
||||
local count=0
|
||||
if type(data)~="table" then return count end
|
||||
for k,v in pairs(data)
|
||||
do
|
||||
count=count+1
|
||||
end
|
||||
return count
|
||||
end
|
||||
|
||||
|
||||
function _M.is_min(self, ip1, ip2)
|
||||
n = 0
|
||||
@@ -360,7 +370,9 @@ end
|
||||
|
||||
function _M.return_html(self, status, html)
|
||||
ngx.header.content_type = "text/html"
|
||||
ngx.header.Cache_Control = "no-cache"
|
||||
status = tonumber(status)
|
||||
|
||||
-- self:D("return_html:"..tostring(status))
|
||||
if status == 200 then
|
||||
ngx.say(html)
|
||||
@@ -369,7 +381,7 @@ function _M.return_html(self, status, html)
|
||||
end
|
||||
|
||||
function _M.read_file_body(self, filename)
|
||||
fp = io.open(filename, 'r')
|
||||
local fp = io.open(filename, 'r')
|
||||
if fp == nil then
|
||||
return nil
|
||||
end
|
||||
@@ -821,5 +833,4 @@ function _M.t(self)
|
||||
ngx.say(',,,')
|
||||
end
|
||||
|
||||
|
||||
return _M
|
||||
|
||||
@@ -0,0 +1,362 @@
|
||||
--[[
|
||||
Copyright 2017-now anjia (anjia0532@gmail.com)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
]]
|
||||
|
||||
-- copy from https://github.com/lilien1010/lua-resty-maxminddb/blob/f96633e2428f8f7bcc1e2a7a28b747b33233a8db/resty/maxminddb.lua#L5-L12
|
||||
|
||||
local ffi = require ('ffi')
|
||||
local ffi_new = ffi.new
|
||||
local ffi_str = ffi.string
|
||||
local ffi_cast = ffi.cast
|
||||
local ffi_gc = ffi.gc
|
||||
local C = ffi.C
|
||||
|
||||
local _M ={}
|
||||
_M._VERSION = '1.3.3'
|
||||
local mt = { __index = _M }
|
||||
|
||||
-- copy from https://github.com/lilien1010/lua-resty-maxminddb/blob/f96633e2428f8f7bcc1e2a7a28b747b33233a8db/resty/maxminddb.lua#L36-L126
|
||||
ffi.cdef[[
|
||||
|
||||
typedef long int ssize_t;
|
||||
|
||||
typedef unsigned int mmdb_uint128_t __attribute__ ((__mode__(TI)));
|
||||
|
||||
typedef struct MMDB_entry_s {
|
||||
struct MMDB_s *mmdb;
|
||||
uint32_t offset;
|
||||
} MMDB_entry_s;
|
||||
|
||||
typedef struct MMDB_lookup_result_s {
|
||||
bool found_entry;
|
||||
MMDB_entry_s entry;
|
||||
uint16_t netmask;
|
||||
} MMDB_lookup_result_s;
|
||||
|
||||
typedef struct MMDB_entry_data_s {
|
||||
bool has_data;
|
||||
union {
|
||||
uint32_t pointer;
|
||||
const char *utf8_string;
|
||||
double double_value;
|
||||
const uint8_t *bytes;
|
||||
uint16_t uint16;
|
||||
uint32_t uint32;
|
||||
int32_t int32;
|
||||
uint64_t uint64;
|
||||
mmdb_uint128_t uint128;
|
||||
bool boolean;
|
||||
float float_value;
|
||||
};
|
||||
|
||||
uint32_t offset;
|
||||
uint32_t offset_to_next;
|
||||
uint32_t data_size;
|
||||
uint32_t type;
|
||||
} MMDB_entry_data_s;
|
||||
|
||||
typedef struct MMDB_entry_data_list_s {
|
||||
MMDB_entry_data_s entry_data;
|
||||
struct MMDB_entry_data_list_s *next;
|
||||
} MMDB_entry_data_list_s;
|
||||
|
||||
typedef struct MMDB_description_s {
|
||||
const char *language;
|
||||
const char *description;
|
||||
} MMDB_description_s;
|
||||
|
||||
typedef struct MMDB_metadata_s {
|
||||
uint32_t node_count;
|
||||
uint16_t record_size;
|
||||
uint16_t ip_version;
|
||||
const char *database_type;
|
||||
struct {
|
||||
size_t count;
|
||||
const char **names;
|
||||
} languages;
|
||||
uint16_t binary_format_major_version;
|
||||
uint16_t binary_format_minor_version;
|
||||
uint64_t build_epoch;
|
||||
struct {
|
||||
size_t count;
|
||||
MMDB_description_s **descriptions;
|
||||
} description;
|
||||
} MMDB_metadata_s;
|
||||
|
||||
typedef struct MMDB_ipv4_start_node_s {
|
||||
uint16_t netmask;
|
||||
uint32_t node_value;
|
||||
} MMDB_ipv4_start_node_s;
|
||||
|
||||
typedef struct MMDB_s {
|
||||
uint32_t flags;
|
||||
const char *filename;
|
||||
ssize_t file_size;
|
||||
const uint8_t *file_content;
|
||||
const uint8_t *data_section;
|
||||
uint32_t data_section_size;
|
||||
const uint8_t *metadata_section;
|
||||
uint32_t metadata_section_size;
|
||||
uint16_t full_record_byte_size;
|
||||
uint16_t depth;
|
||||
MMDB_ipv4_start_node_s ipv4_start_node;
|
||||
MMDB_metadata_s metadata;
|
||||
} MMDB_s;
|
||||
|
||||
typedef char * pchar;
|
||||
|
||||
MMDB_lookup_result_s MMDB_lookup_string(MMDB_s *const mmdb, const char *const ipstr, int *const gai_error,int *const mmdb_error);
|
||||
int MMDB_open(const char *const filename, uint32_t flags, MMDB_s *const mmdb);
|
||||
int MMDB_aget_value(MMDB_entry_s *const start, MMDB_entry_data_s *const entry_data, const char *const *const path);
|
||||
char *MMDB_strerror(int error_code);
|
||||
|
||||
int MMDB_get_entry_data_list(MMDB_entry_s *start, MMDB_entry_data_list_s **const entry_data_list);
|
||||
void MMDB_free_entry_data_list(MMDB_entry_data_list_s *const entry_data_list);
|
||||
void MMDB_close(MMDB_s *const mmdb);
|
||||
const char *gai_strerror(int errcode);
|
||||
]]
|
||||
|
||||
-- error codes
|
||||
-- https://github.com/maxmind/libmaxminddb/blob/master/include/maxminddb.h#L66
|
||||
local MMDB_SUCCESS = 0
|
||||
local MMDB_FILE_OPEN_ERROR = 1
|
||||
local MMDB_CORRUPT_SEARCH_TREE_ERROR = 2
|
||||
local MMDB_INVALID_METADATA_ERROR = 3
|
||||
local MMDB_IO_ERROR = 4
|
||||
local MMDB_OUT_OF_MEMORY_ERROR = 5
|
||||
local MMDB_UNKNOWN_DATABASE_FORMAT_ERROR = 6
|
||||
local MMDB_INVALID_DATA_ERROR = 7
|
||||
local MMDB_INVALID_LOOKUP_PATH_ERROR = 8
|
||||
local MMDB_LOOKUP_PATH_DOES_NOT_MATCH_DATA_ERROR = 9
|
||||
local MMDB_INVALID_NODE_NUMBER_ERROR = 10
|
||||
local MMDB_IPV6_LOOKUP_IN_IPV4_DATABASE_ERROR = 11
|
||||
|
||||
-- data type
|
||||
-- https://github.com/maxmind/libmaxminddb/blob/master/include/maxminddb.h#L40
|
||||
local MMDB_DATA_TYPE_EXTENDED = 0
|
||||
local MMDB_DATA_TYPE_POINTER = 1
|
||||
local MMDB_DATA_TYPE_UTF8_STRING = 2
|
||||
local MMDB_DATA_TYPE_DOUBLE = 3
|
||||
local MMDB_DATA_TYPE_BYTES = 4
|
||||
local MMDB_DATA_TYPE_UINT16 = 5
|
||||
local MMDB_DATA_TYPE_UINT32 = 6
|
||||
local MMDB_DATA_TYPE_MAP = 7
|
||||
local MMDB_DATA_TYPE_INT32 = 8
|
||||
local MMDB_DATA_TYPE_UINT64 = 9
|
||||
local MMDB_DATA_TYPE_UINT128 = 10
|
||||
local MMDB_DATA_TYPE_ARRAY = 11
|
||||
local MMDB_DATA_TYPE_CONTAINER = 12
|
||||
local MMDB_DATA_TYPE_END_MARKER = 13
|
||||
local MMDB_DATA_TYPE_BOOLEAN = 14
|
||||
local MMDB_DATA_TYPE_FLOAT = 15
|
||||
|
||||
-- copy from https://github.com/lilien1010/lua-resty-maxminddb/blob/f96633e2428f8f7bcc1e2a7a28b747b33233a8db/resty/maxminddb.lua#L136-L138
|
||||
-- you should install the libmaxminddb to your system
|
||||
local maxm = ffi.load('{$WAF_ROOT}/waf/mmdb/lib/libmaxminddb.{$MMDB_FILE_SUFFIX}')
|
||||
--https://github.com/maxmind/libmaxminddb
|
||||
local mmdb = ffi_new('MMDB_s')
|
||||
local initted = false
|
||||
|
||||
local function mmdb_strerror(rc)
|
||||
return ffi_str(maxm.MMDB_strerror(rc))
|
||||
end
|
||||
|
||||
local function gai_strerror(rc)
|
||||
return ffi_str(C.gai_strerror(rc))
|
||||
end
|
||||
|
||||
function _M.init(dbfile)
|
||||
if not initted then
|
||||
local maxmind_ready = maxm.MMDB_open(dbfile,0,mmdb)
|
||||
|
||||
if maxmind_ready ~= MMDB_SUCCESS then
|
||||
return nil, mmdb_strerror(maxmind_ready)
|
||||
end
|
||||
|
||||
initted = true
|
||||
|
||||
ffi_gc(mmdb, maxm.MMDB_close)
|
||||
end
|
||||
return initted
|
||||
end
|
||||
|
||||
function _M.initted()
|
||||
return initted
|
||||
end
|
||||
|
||||
-- https://github.com/maxmind/libmaxminddb/blob/master/src/maxminddb.c#L1938
|
||||
-- LOCAL MMDB_entry_data_list_s *dump_entry_data_list( FILE *stream, MMDB_entry_data_list_s *entry_data_list, int indent, int *status)
|
||||
local function _dump_entry_data_list(entry_data_list,status)
|
||||
|
||||
if not entry_data_list then
|
||||
return nil,MMDB_INVALID_DATA_ERROR
|
||||
end
|
||||
|
||||
local entry_data_item = entry_data_list[0].entry_data
|
||||
local data_type = entry_data_item.type
|
||||
local data_size = entry_data_item.data_size
|
||||
local result
|
||||
|
||||
if data_type == MMDB_DATA_TYPE_MAP then
|
||||
result = {}
|
||||
|
||||
local size = entry_data_item.data_size
|
||||
|
||||
entry_data_list = entry_data_list[0].next
|
||||
|
||||
while(size > 0 and entry_data_list)
|
||||
do
|
||||
entry_data_item = entry_data_list[0].entry_data
|
||||
data_type = entry_data_item.type
|
||||
data_size = entry_data_item.data_size
|
||||
|
||||
if MMDB_DATA_TYPE_UTF8_STRING ~= data_type then
|
||||
return nil,MMDB_INVALID_DATA_ERROR
|
||||
end
|
||||
|
||||
local key = ffi_str(entry_data_item.utf8_string,data_size)
|
||||
|
||||
if not key then
|
||||
return nil,MMDB_OUT_OF_MEMORY_ERROR
|
||||
end
|
||||
|
||||
local val
|
||||
entry_data_list = entry_data_list[0].next
|
||||
entry_data_list,status,val = _dump_entry_data_list(entry_data_list)
|
||||
|
||||
if status ~= MMDB_SUCCESS then
|
||||
return nil,status
|
||||
end
|
||||
|
||||
result[key] = val
|
||||
|
||||
size = size -1
|
||||
end
|
||||
|
||||
|
||||
elseif entry_data_list[0].entry_data.type == MMDB_DATA_TYPE_ARRAY then
|
||||
local size = entry_data_list[0].entry_data.data_size
|
||||
result = {}
|
||||
|
||||
entry_data_list = entry_data_list[0].next
|
||||
|
||||
local i = 1
|
||||
while(i <= size and entry_data_list)
|
||||
do
|
||||
local val
|
||||
entry_data_list,status,val = _dump_entry_data_list(entry_data_list)
|
||||
|
||||
if status ~= MMDB_SUCCESS then
|
||||
return nil,nil,val
|
||||
end
|
||||
|
||||
result[i] = val
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
|
||||
else
|
||||
entry_data_item = entry_data_list[0].entry_data
|
||||
data_type = entry_data_item.type
|
||||
data_size = entry_data_item.data_size
|
||||
|
||||
local val
|
||||
-- string type "key":"val"
|
||||
-- other type "key":val
|
||||
-- default other type
|
||||
if data_type == MMDB_DATA_TYPE_UTF8_STRING then
|
||||
val = ffi_str(entry_data_item.utf8_string,data_size)
|
||||
if not val then
|
||||
status = MMDB_OUT_OF_MEMORY_ERROR
|
||||
return nil,status
|
||||
end
|
||||
elseif data_type == MMDB_DATA_TYPE_BYTES then
|
||||
val = ffi_str(ffi_cast('char * ',entry_data_item.bytes),data_size)
|
||||
if not val then
|
||||
status = MMDB_OUT_OF_MEMORY_ERROR
|
||||
return nil,status
|
||||
end
|
||||
elseif data_type == MMDB_DATA_TYPE_DOUBLE then
|
||||
val = entry_data_item.double_value
|
||||
elseif data_type == MMDB_DATA_TYPE_FLOAT then
|
||||
val = entry_data_item.float_value
|
||||
elseif data_type == MMDB_DATA_TYPE_UINT16 then
|
||||
val = entry_data_item.uint16
|
||||
elseif data_type == MMDB_DATA_TYPE_UINT32 then
|
||||
val = entry_data_item.uint32
|
||||
elseif data_type == MMDB_DATA_TYPE_BOOLEAN then
|
||||
val = entry_data_item.boolean
|
||||
elseif data_type == MMDB_DATA_TYPE_UINT64 then
|
||||
val = entry_data_item.uint64
|
||||
elseif data_type == MMDB_DATA_TYPE_INT32 then
|
||||
val = entry_data_item.int32
|
||||
else
|
||||
return nil,MMDB_INVALID_DATA_ERROR
|
||||
end
|
||||
|
||||
result = val
|
||||
entry_data_list = entry_data_list[0].next
|
||||
end
|
||||
|
||||
status = MMDB_SUCCESS
|
||||
return entry_data_list,status,result
|
||||
end
|
||||
|
||||
function _M.lookup(ip)
|
||||
|
||||
if not initted then
|
||||
return nil, "not initialized"
|
||||
end
|
||||
|
||||
-- copy from https://github.com/lilien1010/lua-resty-maxminddb/blob/f96633e2428f8f7bcc1e2a7a28b747b33233a8db/resty/maxminddb.lua#L159-L176
|
||||
local gai_error = ffi_new('int[1]')
|
||||
local mmdb_error = ffi_new('int[1]')
|
||||
|
||||
local result = maxm.MMDB_lookup_string(mmdb,ip,gai_error,mmdb_error)
|
||||
|
||||
if mmdb_error[0] ~= MMDB_SUCCESS then
|
||||
return nil,'lookup failed: ' .. mmdb_strerror(mmdb_error[0])
|
||||
end
|
||||
|
||||
if gai_error[0] ~= MMDB_SUCCESS then
|
||||
return nil,'lookup failed: ' .. gai_strerror(gai_error[0])
|
||||
end
|
||||
|
||||
if true ~= result.found_entry then
|
||||
return nil,'not found'
|
||||
end
|
||||
|
||||
local entry_data_list = ffi_cast('MMDB_entry_data_list_s **const',ffi_new("MMDB_entry_data_list_s"))
|
||||
|
||||
local status = maxm.MMDB_get_entry_data_list(result.entry,entry_data_list)
|
||||
|
||||
if status ~= MMDB_SUCCESS then
|
||||
return nil,'get entry data failed: ' .. mmdb_strerror(status)
|
||||
end
|
||||
|
||||
local head = entry_data_list[0] -- Save so this can be passed to free fn.
|
||||
local _,status,result = _dump_entry_data_list(entry_data_list)
|
||||
maxm.MMDB_free_entry_data_list(head)
|
||||
|
||||
if status ~= MMDB_SUCCESS then
|
||||
return nil,'dump entry data failed: ' .. mmdb_strerror(status)
|
||||
end
|
||||
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
-- copy from https://github.com/lilien1010/lua-resty-maxminddb/blob/master/resty/maxminddb.lua#L208
|
||||
-- https://www.maxmind.com/en/geoip2-databases you should download the mmdb file from maxmind
|
||||
|
||||
return _M;
|
||||
@@ -7,19 +7,20 @@ rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
|
||||
opensslVersion="3.0.10"
|
||||
# echo $rootPath
|
||||
|
||||
SERVER_ROOT=$rootPath/lib
|
||||
SOURCE_ROOT=$rootPath/source/lib
|
||||
mkdir -p $SOURCE_ROOT
|
||||
|
||||
if [ ! -d ${SERVER_ROOT}/openssl ];then
|
||||
cd ${SOURCE_ROOT}
|
||||
if [ ! -f ${SOURCE_ROOT}/openssl-1.1.1p.tar.gz ];then
|
||||
wget --no-check-certificate -O ${SOURCE_ROOT}/openssl-1.1.1p.tar.gz https://www.openssl.org/source/openssl-1.1.1p.tar.gz
|
||||
if [ ! -f ${SOURCE_ROOT}/openssl-${opensslVersion}.tar.gz ];then
|
||||
wget --no-check-certificate -O ${SOURCE_ROOT}/openssl-${opensslVersion}.tar.gz https://www.openssl.org/source/openssl-${opensslVersion}.tar.gz
|
||||
fi
|
||||
tar -zxvf openssl-1.1.1p.tar.gz
|
||||
cd openssl-1.1.1p
|
||||
tar -zxvf openssl-${opensslVersion}.tar.gz
|
||||
cd openssl-${opensslVersion}
|
||||
./config --prefix=${SERVER_ROOT}/openssl zlib-dynamic shared
|
||||
make && make install
|
||||
fi
|
||||
|
||||
@@ -9,8 +9,7 @@ serverPath=$(dirname "$rootPath")
|
||||
sourcePath=${serverPath}/source
|
||||
sysName=`uname`
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
|
||||
|
||||
SYS_ARCH=`arch`
|
||||
|
||||
version=5.2.17
|
||||
PHP_VER=52
|
||||
@@ -101,6 +100,10 @@ if [ "$IS_64BIT" == "64" ];then
|
||||
OPTIONS="${OPTIONS} --with-libdir=lib64"
|
||||
fi
|
||||
|
||||
if [ "${SYS_ARCH}" == "aarch64" ];then
|
||||
OPTIONS="$OPTIONS --build=aarch64-unknown-linux-gnu --host=aarch64-unknown-linux-gnu"
|
||||
fi
|
||||
|
||||
|
||||
if [ ! -d $serverPath/php/${PHP_VER} ];then
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ rootPath=$(dirname "$rootPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
sourcePath=${serverPath}/source/php
|
||||
|
||||
SYS_ARCH=`arch`
|
||||
LIBNAME=apc
|
||||
LIBV=3.1.9
|
||||
sysName=`uname`
|
||||
@@ -46,8 +46,13 @@ Install_lib()
|
||||
fi
|
||||
cd $php_lib/${_LIBNAME}-${LIBV}
|
||||
|
||||
OPTIONS=''
|
||||
if [ "${SYS_ARCH}" == "aarch64" ] && [ "$version" -lt "56" ];then
|
||||
OPTIONS="$OPTIONS --build=aarch64-unknown-linux-gnu --host=aarch64-unknown-linux-gnu"
|
||||
fi
|
||||
|
||||
$serverPath/php/$version/bin/phpize
|
||||
./configure --with-php-config=$serverPath/php/$version/bin/php-config && \
|
||||
./configure --with-php-config=$serverPath/php/$version/bin/php-config $OPTIONS && \
|
||||
make && make install && make clean
|
||||
|
||||
fi
|
||||
|
||||
@@ -14,7 +14,7 @@ rootPath=$(dirname "$rootPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
sourcePath=${serverPath}/source/php
|
||||
|
||||
SYS_ARCH=`arch`
|
||||
LIBNAME=eaccelerator
|
||||
LIBV=0.9.6
|
||||
sysName=`uname`
|
||||
@@ -51,8 +51,14 @@ Install_lib()
|
||||
fi
|
||||
cd $php_lib/${LIBNAME}-${LIBV}
|
||||
|
||||
OPTIONS=""
|
||||
if [ "${SYS_ARCH}" == "aarch64" ] && [ "$version" -lt "56" ];then
|
||||
OPTIONS="$OPTIONS --build=aarch64-unknown-linux-gnu --host=aarch64-unknown-linux-gnu"
|
||||
fi
|
||||
|
||||
$serverPath/php/$version/bin/phpize
|
||||
./configure --with-php-config=$serverPath/php/$version/bin/php-config \
|
||||
$OPTIONS \
|
||||
--enable-eaccelerator=shared
|
||||
make && make install && make clean
|
||||
|
||||
|
||||
@@ -9,8 +9,7 @@ serverPath=$(dirname "$rootPath")
|
||||
sourcePath=${serverPath}/source
|
||||
sysName=`uname`
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
|
||||
|
||||
SYS_ARCH=`arch`
|
||||
|
||||
version=5.3.29
|
||||
PHP_VER=53
|
||||
@@ -97,6 +96,10 @@ else
|
||||
fi
|
||||
# ----- cpu end ------
|
||||
|
||||
if [ "${SYS_ARCH}" == "aarch64" ];then
|
||||
OPTIONS="$OPTIONS --build=aarch64-unknown-linux-gnu --host=aarch64-unknown-linux-gnu"
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/php/53/bin ];then
|
||||
cd $sourcePath/php/php${PHP_VER} && ./configure \
|
||||
--prefix=$serverPath/php/53 \
|
||||
|
||||
@@ -10,7 +10,7 @@ rootPath=$(dirname "$rootPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
sourcePath=${serverPath}/source/php
|
||||
|
||||
SYS_ARCH=`arch`
|
||||
LIBNAME=intl
|
||||
LIBV=3.0.0
|
||||
sysName=`uname`
|
||||
@@ -41,13 +41,20 @@ Install_lib()
|
||||
mkdir -p $php_lib
|
||||
|
||||
cd ${rootPath}/plugins/php/lib && /bin/bash icu.sh
|
||||
if [ -d $php_lib/${LIBNAME}-${LIBV} ];then
|
||||
wget -O $php_lib/${LIBNAME}-${LIBV}.tgz http://pecl.php.net/get/${LIBNAME}-${LIBV}.tgz
|
||||
cd $php_lib && tar xvf ${LIBNAME}-${LIBV}.tgz
|
||||
fi
|
||||
cd $php_lib/${LIBNAME}-${LIBV}
|
||||
|
||||
wget -O $php_lib/${LIBNAME}-${LIBV}.tgz http://pecl.php.net/get/${LIBNAME}-${LIBV}.tgz
|
||||
OPTIONS=''
|
||||
if [ "${SYS_ARCH}" == "aarch64" ];then
|
||||
OPTIONS="$OPTIONS --build=aarch64-unknown-linux-gnu --host=aarch64-unknown-linux-gnu"
|
||||
fi
|
||||
|
||||
cd $php_lib && tar xvf ${LIBNAME}-${LIBV}.tgz
|
||||
cd ${LIBNAME}-${LIBV}
|
||||
$serverPath/php/$version/bin/phpize
|
||||
./configure --with-php-config=$serverPath/php/$version/bin/php-config \
|
||||
$OPTIONS \
|
||||
--with-icu-dir=${serverPath}/lib/icu
|
||||
|
||||
make && make install && make clean
|
||||
|
||||
@@ -10,7 +10,7 @@ rootPath=$(dirname "$rootPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
sourcePath=${serverPath}/source/php
|
||||
|
||||
SYS_ARCH=`arch`
|
||||
LIBNAME=opcache
|
||||
LIBV=7.0.5
|
||||
sysName=`uname`
|
||||
@@ -45,8 +45,13 @@ Install_lib()
|
||||
fi
|
||||
cd $php_lib/zendopcache-7.0.5
|
||||
|
||||
OPTIONS=''
|
||||
if [ "${SYS_ARCH}" == "aarch64" ] && [ "$version" -lt "56" ];then
|
||||
OPTIONS="$OPTIONS --build=aarch64-unknown-linux-gnu --host=aarch64-unknown-linux-gnu"
|
||||
fi
|
||||
|
||||
$serverPath/php/$version/bin/phpize
|
||||
./configure --with-php-config=$serverPath/php/$version/bin/php-config
|
||||
./configure --with-php-config=$serverPath/php/$version/bin/php-config $OPTIONS
|
||||
make && make install && make clean
|
||||
fi
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ rootPath=$(dirname "$rootPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
sourcePath=${serverPath}/source/php
|
||||
|
||||
SYS_ARCH=`arch`
|
||||
LIBNAME=apc
|
||||
_LIBNAME=$(echo $LIBNAME | tr '[a-z]' '[A-Z]')
|
||||
LIBV=3.1.9
|
||||
@@ -45,8 +45,13 @@ Install_lib()
|
||||
fi
|
||||
cd $php_lib/${_LIBNAME}-${LIBV}
|
||||
|
||||
OPTIONS=''
|
||||
if [ "${SYS_ARCH}" == "aarch64" ] && [ "$version" -lt "56" ];then
|
||||
OPTIONS="$OPTIONS --build=aarch64-unknown-linux-gnu --host=aarch64-unknown-linux-gnu"
|
||||
fi
|
||||
|
||||
$serverPath/php/$version/bin/phpize
|
||||
./configure --with-php-config=$serverPath/php/$version/bin/php-config
|
||||
./configure --with-php-config=$serverPath/php/$version/bin/php-config $OPTIONS
|
||||
make && make install && make clean
|
||||
fi
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ serverPath=$(dirname "$rootPath")
|
||||
sourcePath=${serverPath}/source
|
||||
sysName=`uname`
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
|
||||
SYS_ARCH=`arch`
|
||||
|
||||
version=5.4.45
|
||||
PHP_VER=54
|
||||
@@ -89,6 +89,9 @@ else
|
||||
fi
|
||||
# ----- cpu end ------
|
||||
|
||||
if [ "${SYS_ARCH}" == "aarch64" ];then
|
||||
OPTIONS="$OPTIONS --build=aarch64-unknown-linux-gnu --host=aarch64-unknown-linux-gnu"
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/php/${PHP_VER} ];then
|
||||
cd $sourcePath/php/php${PHP_VER} && ./configure \
|
||||
|
||||
@@ -10,7 +10,7 @@ rootPath=$(dirname "$rootPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
sourcePath=${serverPath}/source/php
|
||||
|
||||
SYS_ARCH=`arch`
|
||||
LIBNAME=opcache
|
||||
LIBV=7.0.5
|
||||
sysName=`uname`
|
||||
@@ -39,12 +39,19 @@ Install_lib()
|
||||
php_lib=$sourcePath/php_lib
|
||||
mkdir -p $php_lib
|
||||
|
||||
wget -O $php_lib/zendopcache-7.0.5.tgz http://pecl.php.net/get/zendopcache-7.0.5.tgz
|
||||
if [ ! -d $php_lib/zendopcache-7.0.5 ];then
|
||||
wget -O $php_lib/zendopcache-7.0.5.tgz http://pecl.php.net/get/zendopcache-7.0.5.tgz
|
||||
cd $php_lib && tar xvf zendopcache-7.0.5.tgz
|
||||
fi
|
||||
cd $php_lib/zendopcache-7.0.5
|
||||
|
||||
OPTIONS=''
|
||||
if [ "${SYS_ARCH}" == "aarch64" ] && [ "$version" -lt "56" ];then
|
||||
OPTIONS="$OPTIONS --build=aarch64-unknown-linux-gnu --host=aarch64-unknown-linux-gnu"
|
||||
fi
|
||||
|
||||
cd $php_lib && tar xvf zendopcache-7.0.5.tgz
|
||||
cd zendopcache-7.0.5
|
||||
$serverPath/php/$version/bin/phpize
|
||||
./configure --with-php-config=$serverPath/php/$version/bin/php-config
|
||||
./configure --with-php-config=$serverPath/php/$version/bin/php-config $OPTIONS
|
||||
make && make install && make clean
|
||||
|
||||
# cp modules/opcache.la $serverPath/php/${version}/lib/php/extensions/no-debug-non-zts-20100525/
|
||||
|
||||
@@ -9,7 +9,7 @@ serverPath=$(dirname "$rootPath")
|
||||
sourcePath=${serverPath}/source
|
||||
sysName=`uname`
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
|
||||
SYS_ARCH=`arch`
|
||||
version=5.5.38
|
||||
PHP_VER=55
|
||||
Install_php()
|
||||
@@ -88,6 +88,12 @@ else
|
||||
fi
|
||||
# ----- cpu end ------
|
||||
|
||||
if [ "${SYS_ARCH}" == "aarch64" ];then
|
||||
# 修复aarch64架构下安装
|
||||
# /www/server/mdserver-web/plugins/php/versions/56/src/zend_multiply.h > /www/server/source/php/php56/Zend/zend_multiply.h
|
||||
cat ${curPath}/versions/${PHP_VER}/src/zend_multiply.h > $sourcePath/php/php${PHP_VER}/Zend/zend_multiply.h
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/php/55 ];then
|
||||
cd $sourcePath/php/php${PHP_VER} && ./configure \
|
||||
--prefix=$serverPath/php/55 \
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| Zend Engine |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1998-2015 Zend Technologies Ltd. (http://www.zend.com) |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 2.00 of the Zend license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available through the world-wide-web at the following url: |
|
||||
| http://www.zend.com/license/2_00.txt. |
|
||||
| If you did not receive a copy of the Zend license and are unable to |
|
||||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@zend.com so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Authors: Sascha Schumann <sascha@schumann.cx> |
|
||||
| Ard Biesheuvel <ard.biesheuvel@linaro.org> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#if defined(__i386__) && defined(__GNUC__)
|
||||
|
||||
#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \
|
||||
long __tmpvar; \
|
||||
__asm__ ("imul %3,%0\n" \
|
||||
"adc $0,%1" \
|
||||
: "=r"(__tmpvar),"=r"(usedval) \
|
||||
: "0"(a), "r"(b), "1"(0)); \
|
||||
if (usedval) (dval) = (double) (a) * (double) (b); \
|
||||
else (lval) = __tmpvar; \
|
||||
} while (0)
|
||||
|
||||
#elif defined(__x86_64__) && defined(__GNUC__)
|
||||
|
||||
#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \
|
||||
long __tmpvar; \
|
||||
__asm__ ("imul %3,%0\n" \
|
||||
"adc $0,%1" \
|
||||
: "=r"(__tmpvar),"=r"(usedval) \
|
||||
: "0"(a), "r"(b), "1"(0)); \
|
||||
if (usedval) (dval) = (double) (a) * (double) (b); \
|
||||
else (lval) = __tmpvar; \
|
||||
} while (0)
|
||||
|
||||
#elif defined(__arm__) && defined(__GNUC__)
|
||||
|
||||
#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \
|
||||
long __tmpvar; \
|
||||
__asm__("smull %0, %1, %2, %3\n" \
|
||||
"sub %1, %1, %0, asr #31" \
|
||||
: "=r"(__tmpvar), "=r"(usedval) \
|
||||
: "r"(a), "r"(b)); \
|
||||
if (usedval) (dval) = (double) (a) * (double) (b); \
|
||||
else (lval) = __tmpvar; \
|
||||
} while (0)
|
||||
|
||||
#elif defined(__aarch64__) && defined(__GNUC__)
|
||||
|
||||
#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \
|
||||
long __tmpvar; \
|
||||
__asm__("mul %0, %2, %3\n" \
|
||||
"smulh %1, %2, %3\n" \
|
||||
"sub %1, %1, %0, asr #63\n" \
|
||||
: "=&r"(__tmpvar), "=&r"(usedval) \
|
||||
: "r"(a), "r"(b)); \
|
||||
if (usedval) (dval) = (double) (a) * (double) (b); \
|
||||
else (lval) = __tmpvar; \
|
||||
} while (0)
|
||||
|
||||
#elif SIZEOF_LONG == 4 && defined(HAVE_ZEND_LONG64)
|
||||
|
||||
#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \
|
||||
zend_long64 __result = (zend_long64) (a) * (zend_long64) (b); \
|
||||
if (__result > LONG_MAX || __result < LONG_MIN) { \
|
||||
(dval) = (double) __result; \
|
||||
(usedval) = 1; \
|
||||
} else { \
|
||||
(lval) = (long) __result; \
|
||||
(usedval) = 0; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#else
|
||||
|
||||
#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \
|
||||
long __lres = (a) * (b); \
|
||||
long double __dres = (long double)(a) * (long double)(b); \
|
||||
long double __delta = (long double) __lres - __dres; \
|
||||
if ( ((usedval) = (( __dres + __delta ) != __dres))) { \
|
||||
(dval) = __dres; \
|
||||
} else { \
|
||||
(lval) = __lres; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#endif
|
||||
@@ -2,6 +2,8 @@
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
# cd /www/server/mdserver-web/plugins/php && /bin/bash install.sh install 56
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
@@ -9,7 +11,7 @@ serverPath=$(dirname "$rootPath")
|
||||
sourcePath=${serverPath}/source
|
||||
sysName=`uname`
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
|
||||
SYS_ARCH=`arch`
|
||||
version=5.6.40
|
||||
PHP_VER=56
|
||||
Install_php()
|
||||
@@ -89,6 +91,14 @@ fi
|
||||
# ----- cpu end ------
|
||||
|
||||
|
||||
|
||||
if [ "${SYS_ARCH}" == "aarch64" ];then
|
||||
# 修复aarch64架构下安装
|
||||
# /www/server/mdserver-web/plugins/php/versions/56/src/zend_multiply.h > /www/server/source/php/php56/Zend/zend_multiply.h
|
||||
cat ${curPath}/versions/${PHP_VER}/src/zend_multiply.h > $sourcePath/php/php${PHP_VER}/Zend/zend_multiply.h
|
||||
fi
|
||||
|
||||
|
||||
if [ ! -d $serverPath/php/56 ];then
|
||||
cd $sourcePath/php/php${PHP_VER} && ./configure \
|
||||
--prefix=$serverPath/php/56 \
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| Zend Engine |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1998-2016 Zend Technologies Ltd. (http://www.zend.com) |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 2.00 of the Zend license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available through the world-wide-web at the following url: |
|
||||
| http://www.zend.com/license/2_00.txt. |
|
||||
| If you did not receive a copy of the Zend license and are unable to |
|
||||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@zend.com so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Authors: Sascha Schumann <sascha@schumann.cx> |
|
||||
| Ard Biesheuvel <ard.biesheuvel@linaro.org> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#if defined(__i386__) && defined(__GNUC__)
|
||||
|
||||
#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \
|
||||
long __tmpvar; \
|
||||
__asm__ ("imul %3,%0\n" \
|
||||
"adc $0,%1" \
|
||||
: "=r"(__tmpvar),"=r"(usedval) \
|
||||
: "0"(a), "r"(b), "1"(0)); \
|
||||
if (usedval) (dval) = (double) (a) * (double) (b); \
|
||||
else (lval) = __tmpvar; \
|
||||
} while (0)
|
||||
|
||||
#elif defined(__x86_64__) && defined(__GNUC__)
|
||||
|
||||
#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \
|
||||
long __tmpvar; \
|
||||
__asm__ ("imul %3,%0\n" \
|
||||
"adc $0,%1" \
|
||||
: "=r"(__tmpvar),"=r"(usedval) \
|
||||
: "0"(a), "r"(b), "1"(0)); \
|
||||
if (usedval) (dval) = (double) (a) * (double) (b); \
|
||||
else (lval) = __tmpvar; \
|
||||
} while (0)
|
||||
|
||||
#elif defined(__arm__) && defined(__GNUC__)
|
||||
|
||||
#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \
|
||||
long __tmpvar; \
|
||||
__asm__("smull %0, %1, %2, %3\n" \
|
||||
"sub %1, %1, %0, asr #31" \
|
||||
: "=&r"(__tmpvar), "=&r"(usedval) \
|
||||
: "r"(a), "r"(b)); \
|
||||
if (usedval) (dval) = (double) (a) * (double) (b); \
|
||||
else (lval) = __tmpvar; \
|
||||
} while (0)
|
||||
|
||||
#elif defined(__aarch64__) && defined(__GNUC__)
|
||||
|
||||
#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \
|
||||
long __tmpvar; \
|
||||
__asm__("mul %0, %2, %3\n" \
|
||||
"smulh %1, %2, %3\n" \
|
||||
"sub %1, %1, %0, asr #63\n" \
|
||||
: "=&r"(__tmpvar), "=&r"(usedval) \
|
||||
: "r"(a), "r"(b)); \
|
||||
if (usedval) (dval) = (double) (a) * (double) (b); \
|
||||
else (lval) = __tmpvar; \
|
||||
} while (0)
|
||||
|
||||
#elif SIZEOF_LONG == 4 && defined(HAVE_ZEND_LONG64)
|
||||
|
||||
#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \
|
||||
zend_long64 __result = (zend_long64) (a) * (zend_long64) (b); \
|
||||
if (__result > LONG_MAX || __result < LONG_MIN) { \
|
||||
(dval) = (double) __result; \
|
||||
(usedval) = 1; \
|
||||
} else { \
|
||||
(lval) = (long) __result; \
|
||||
(usedval) = 0; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#else
|
||||
|
||||
#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \
|
||||
long __lres = (a) * (b); \
|
||||
long double __dres = (long double)(a) * (long double)(b); \
|
||||
long double __delta = (long double) __lres - __dres; \
|
||||
if ( ((usedval) = (( __dres + __delta ) != __dres))) { \
|
||||
(dval) = __dres; \
|
||||
} else { \
|
||||
(lval) = __lres; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#endif
|
||||
@@ -16,7 +16,7 @@ function version_lt() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)"
|
||||
function version_ge() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1"; }
|
||||
|
||||
|
||||
version=8.2.7
|
||||
version=8.2.8
|
||||
PHP_VER=82
|
||||
Install_php()
|
||||
{
|
||||
|
||||
@@ -39,9 +39,9 @@ done
|
||||
cd $DIR
|
||||
PHP_VER_LIST=(53 54 55 56 70 71 72 73 74 80 81 82)
|
||||
# yar
|
||||
PHP_EXT_LIST=(ioncube ZendGuardLoader pdo mysqlnd sqlite3 openssl pcntl opcache mcrypt fileinfo \
|
||||
exif gd intl memcache memcached redis imagemagick xdebug xhprof \
|
||||
swoole yaf yac apc mongo mongodb solr seaslog mbstring iconv phalcon)
|
||||
PHP_EXT_LIST=(ZendGuardLoader pdo mysqlnd sqlite3 openssl pcntl opcache mcrypt fileinfo \
|
||||
exif gd intl memcache memcached redis imagemagick xdebug \
|
||||
swoole yac apc mongo mongodb solr seaslog mbstring iconv)
|
||||
|
||||
for PHP_VER in ${PHP_VER_LIST[@]}; do
|
||||
echo "php${PHP_VER} -- start"
|
||||
|
||||
@@ -12,7 +12,7 @@ rootPath=$(dirname "$rootPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
sourcePath=${serverPath}/source/php
|
||||
|
||||
SYS_ARCH=`arch`
|
||||
actionType=$1
|
||||
version=$2
|
||||
|
||||
@@ -54,8 +54,13 @@ Install_lib()
|
||||
|
||||
cd $sourcePath/php${version}/ext/${LIBNAME}
|
||||
|
||||
OPTIONS=""
|
||||
if [ "${SYS_ARCH}" == "aarch64" ] && [ "$version" -lt "56" ];then
|
||||
OPTIONS="$OPTIONS --build=aarch64-unknown-linux-gnu --host=aarch64-unknown-linux-gnu"
|
||||
fi
|
||||
|
||||
$serverPath/php/$version/bin/phpize
|
||||
./configure --with-php-config=$serverPath/php/$version/bin/php-config
|
||||
./configure --with-php-config=$serverPath/php/$version/bin/php-config $OPTIONS
|
||||
|
||||
make clean && make && make install && make clean
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ rootPath=$(dirname "$rootPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
sourcePath=${serverPath}/source/php
|
||||
|
||||
SYS_ARCH=`arch`
|
||||
actionType=$1
|
||||
version=$2
|
||||
|
||||
@@ -57,8 +57,13 @@ Install_lib()
|
||||
|
||||
cd $sourcePath/php${version}/ext/${LIBNAME}
|
||||
|
||||
OPTIONS=''
|
||||
if [ "${SYS_ARCH}" == "aarch64" ] && [ "$version" -lt "56" ];then
|
||||
OPTIONS="$OPTIONS --build=aarch64-unknown-linux-gnu --host=aarch64-unknown-linux-gnu"
|
||||
fi
|
||||
|
||||
$serverPath/php/$version/bin/phpize
|
||||
./configure --with-php-config=$serverPath/php/$version/bin/php-config
|
||||
./configure --with-php-config=$serverPath/php/$version/bin/php-config $OPTIONS
|
||||
|
||||
FIND_C99=`cat Makefile|grep c99`
|
||||
if [ "$FIND_C99" == "" ];then
|
||||
|
||||
@@ -10,7 +10,7 @@ rootPath=$(dirname "$rootPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
sourcePath=${serverPath}/source/php
|
||||
|
||||
SYS_ARCH=`arch`
|
||||
actionType=$1
|
||||
version=$2
|
||||
|
||||
@@ -55,8 +55,13 @@ Install_lib()
|
||||
|
||||
cd $sourcePath/php${version}/ext/${LIBNAME}
|
||||
|
||||
OPTIONS=''
|
||||
if [ "${SYS_ARCH}" == "aarch64" ] && [ "$version" -lt "56" ];then
|
||||
OPTIONS="$OPTIONS --build=aarch64-unknown-linux-gnu --host=aarch64-unknown-linux-gnu"
|
||||
fi
|
||||
|
||||
$serverPath/php/$version/bin/phpize
|
||||
./configure --with-php-config=$serverPath/php/$version/bin/php-config
|
||||
./configure --with-php-config=$serverPath/php/$version/bin/php-config $OPTIONS
|
||||
|
||||
|
||||
# It is considered as a temporary bug
|
||||
|
||||
@@ -10,7 +10,7 @@ rootPath=$(dirname "$rootPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
sourcePath=${serverPath}/source/php
|
||||
|
||||
SYS_ARCH=`arch`
|
||||
actionType=$1
|
||||
version=$2
|
||||
|
||||
@@ -18,6 +18,7 @@ LIBNAME=gd
|
||||
LIBV=0
|
||||
|
||||
|
||||
|
||||
# if [ "$version" -lt "74" ];then
|
||||
# echo "not need!"
|
||||
# exit 1
|
||||
@@ -67,10 +68,16 @@ Install_lib()
|
||||
|
||||
$serverPath/php/$version/bin/phpize
|
||||
|
||||
OPTIONS=""
|
||||
if [ "${SYS_ARCH}" == "aarch64" ] && [ "$version" -lt "56" ];then
|
||||
OPTIONS="$OPTIONS --build=aarch64-unknown-linux-gnu --host=aarch64-unknown-linux-gnu"
|
||||
fi
|
||||
|
||||
#--with-xpm
|
||||
# =${serverPath}/lib/freetype_old
|
||||
# =/usr/lib
|
||||
./configure --with-php-config=$serverPath/php/$version/bin/php-config \
|
||||
$OPTIONS \
|
||||
--with-gd \
|
||||
--with-jpeg-dir \
|
||||
--with-freetype-dir=${serverPath}/lib/freetype_old \
|
||||
|
||||
@@ -10,7 +10,7 @@ rootPath=$(dirname "$rootPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
sourcePath=${serverPath}/source/php
|
||||
|
||||
SYS_ARCH=`arch`
|
||||
actionType=$1
|
||||
version=$2
|
||||
|
||||
@@ -48,9 +48,14 @@ Install_lib()
|
||||
fi
|
||||
|
||||
cd $sourcePath/php${version}/ext/${LIBNAME}
|
||||
|
||||
|
||||
OPTIONS=""
|
||||
if [ "${SYS_ARCH}" == "aarch64" ] && [ "$version" -lt "56" ];then
|
||||
OPTIONS="$OPTIONS --build=aarch64-unknown-linux-gnu --host=aarch64-unknown-linux-gnu"
|
||||
fi
|
||||
|
||||
$serverPath/php/$version/bin/phpize
|
||||
./configure --with-php-config=$serverPath/php/$version/bin/php-config
|
||||
./configure --with-php-config=$serverPath/php/$version/bin/php-config $OPTIONS
|
||||
|
||||
# PHP52需要,因为52关闭。所有注释掉
|
||||
# FIND_C99=`cat Makefile|grep c99`
|
||||
|
||||
@@ -12,7 +12,7 @@ rootPath=$(dirname "$rootPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
sourcePath=${serverPath}/source/php
|
||||
|
||||
SYS_ARCH=`arch`
|
||||
actionType=$1
|
||||
version=$2
|
||||
|
||||
@@ -55,8 +55,13 @@ Install_lib()
|
||||
|
||||
cd $sourcePath/php${version}/ext/${LIBNAME}
|
||||
|
||||
OPTIONS=""
|
||||
if [ "${SYS_ARCH}" == "aarch64" ] && [ "$version" -lt "56" ];then
|
||||
OPTIONS="$OPTIONS --build=aarch64-unknown-linux-gnu --host=aarch64-unknown-linux-gnu"
|
||||
fi
|
||||
|
||||
$serverPath/php/$version/bin/phpize
|
||||
./configure --with-php-config=$serverPath/php/$version/bin/php-config
|
||||
./configure --with-php-config=$serverPath/php/$version/bin/php-config $OPTIONS
|
||||
make clean && make && make install && make clean
|
||||
|
||||
fi
|
||||
|
||||
@@ -10,7 +10,7 @@ rootPath=$(dirname "$rootPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
sourcePath=${serverPath}/source/php
|
||||
|
||||
SYS_ARCH=`arch`
|
||||
LIBNAME=imagick
|
||||
LIBV=3.7.0
|
||||
sysName=`uname`
|
||||
@@ -20,7 +20,11 @@ version=$2
|
||||
|
||||
if [ "$version" == "53" ];then
|
||||
echo 'not need'
|
||||
exit 1
|
||||
exit 0
|
||||
elif [ "$version" -lt "70" ];then
|
||||
LIBV=3.6.0
|
||||
else
|
||||
echo 'ok'
|
||||
fi
|
||||
|
||||
|
||||
@@ -57,8 +61,13 @@ Install_lib()
|
||||
fi
|
||||
cd $php_lib/${LIBNAME}-${LIBV}
|
||||
|
||||
OPTIONS=''
|
||||
if [ "${SYS_ARCH}" == "aarch64" ] && [ "$version" -lt "56" ];then
|
||||
OPTIONS="$OPTIONS --build=aarch64-unknown-linux-gnu --host=aarch64-unknown-linux-gnu"
|
||||
fi
|
||||
|
||||
$serverPath/php/$version/bin/phpize
|
||||
./configure --with-php-config=$serverPath/php/$version/bin/php-config
|
||||
./configure --with-php-config=$serverPath/php/$version/bin/php-config $OPTIONS
|
||||
make clean && make && make install && make clean
|
||||
|
||||
fi
|
||||
|
||||
@@ -10,7 +10,7 @@ rootPath=$(dirname "$rootPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
sourcePath=${serverPath}/source/php
|
||||
|
||||
SYS_ARCH=`arch`
|
||||
|
||||
# _os=`uname`
|
||||
|
||||
@@ -85,7 +85,10 @@ Install_lib()
|
||||
fi
|
||||
|
||||
cd $sourcePath/php${version}/ext/${LIBNAME}
|
||||
|
||||
if [ "${SYS_ARCH}" == "aarch64" ] && [ "$version" -lt "56" ];then
|
||||
OPTIONS="$OPTIONS --build=aarch64-unknown-linux-gnu --host=aarch64-unknown-linux-gnu"
|
||||
fi
|
||||
|
||||
$serverPath/php/$version/bin/phpize
|
||||
./configure --with-php-config=$serverPath/php/$version/bin/php-config $OPTIONS
|
||||
make clean && make && make install && make clean
|
||||
|
||||
@@ -11,7 +11,7 @@ rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
sourcePath=${serverPath}/source/php
|
||||
|
||||
# support 52-74
|
||||
# support 55-74
|
||||
|
||||
LIBNAME=ioncube
|
||||
LIBV=0
|
||||
@@ -21,7 +21,7 @@ version=$2
|
||||
IC_VERSION=${version:0:1}.${version:1:2}
|
||||
ARCH=`uname -m`
|
||||
|
||||
if [ "$version" -gt "74" ];then
|
||||
if [ "$version" -gt "55" ];then
|
||||
echo "not need"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user