pull/504/head
Mr Chen 2 years ago
parent 135b307a98
commit e676790250
  1. 4
      plugins/keepalived/config/keepalived.conf
  2. 3
      plugins/keepalived/index.html
  3. 51
      plugins/keepalived/index.py
  4. 2
      plugins/keepalived/scripts/chk.sh
  5. 3
      plugins/keepalived/scripts/chk_mysql.sh

@ -5,14 +5,14 @@ global_defs {
}
vrrp_script chk_mysql_port {
script "{$PLUGIN_PATH}/scripts/chk_mysql.sh"
script "{$PLUGIN_PATH}/scripts/chk.sh mysql"
interval 2
weight –5
fall 2
rise 1
}
vrrp_instance VI_1 {
vrrp_instance VI_MYSQL {
state MASTER
interface {$ETH_XX}
virtual_router_id 51

@ -6,8 +6,7 @@
<p onclick="pluginInitD('keepalived');">自启动</p>
<!-- <p onclick="pluginConfig('keepalived');">配置修改</p> -->
<p onclick="pluginConfigTpl('keepalived',$('.plugin_version').attr('version'));">配置修改</p>
<!-- <p onclick="getRedisConfig($('.plugin_version').attr('version'));">性能调整</p> -->
<!-- <p onclick="redisStatus($('.plugin_version').attr('version'));">负载状态</p> -->
<p onclick="pluginConfigTpl('keepalived',$('.plugin_version').attr('version'), 'default_scripts_tpl','config_scripts_tpl','read_config_tpl');">脚本模板</p>
<!-- <p onclick="pluginLogs('keepalived','','run_log');">日志</p> -->
</div>
<div class="bt-w-con pd15">

@ -97,6 +97,21 @@ def readConfigTpl():
content = contentReplace(content)
return mw.returnJson(True, 'ok', content)
def defaultScriptsTpl():
path = getServerDir() + "/scripts/chk.sh"
return path
def configScriptsTpl():
path = getServerDir() + '/scripts'
pathFile = os.listdir(path)
tmp = []
for one in pathFile:
file = path + '/' + one
tmp.append(file)
return mw.getJson(tmp)
def status():
data = mw.execShell(
"ps aux|grep keepalived |grep -v grep | grep -v python | grep -v mdserver-web | awk '{print $2}'")
@ -117,13 +132,27 @@ def contentReplace(content):
# 未找到
content = content.replace('{$ETH_XX}', 'eth1')
else:
#
# 已找到
content = content.replace('{$ETH_XX}', ethx[0])
return content
def copyScripts():
# 复制检查脚本
src_scripts_path = getPluginDir() + '/scripts'
dst_scripts_path = getServerDir() + '/scripts'
if not os.path.exists(dst_scripts_path):
cmd = 'cp -rf ' +src_scripts_path+' '+dst_scripts_path
t = mw.execShell(cmd)
acl_cmd = 'chmod +x '+dst_scripts_path+'/*.sh'
# print(acl_cmd)
mw.execShell(acl_cmd)
# print(t)
return True
return False
def initDreplace():
file_tpl = getInitDTpl()
@ -150,13 +179,13 @@ def initDreplace():
dst_conf = getServerDir() + '/etc/keepalived/keepalived.conf'
dst_conf_init = getServerDir() + '/init.pl'
if not os.path.exists(dst_conf_init):
conf_content = mw.readFile(getConfTpl())
conf_content = contentReplace(conf_content)
mw.writeFile(dst_conf, conf_content)
content = mw.readFile(getConfTpl())
content = contentReplace(content)
mw.writeFile(dst_conf, content)
mw.writeFile(dst_conf_init, 'ok')
# route -n | grep ^0.0.0.0 | awk '{print $8}'
# 复制检查脚本
copyScripts()
# systemd
systemDir = mw.systemdCfgDir()
@ -164,9 +193,9 @@ def initDreplace():
if os.path.exists(systemDir) and not os.path.exists(systemService):
systemServiceTpl = getPluginDir() + '/init.d/' + getPluginName() + '.service.tpl'
service_path = mw.getServerDir()
se_content = mw.readFile(systemServiceTpl)
se_content = contentReplace(se_content)
mw.writeFile(systemService, se_content)
content = mw.readFile(systemServiceTpl)
content = contentReplace(content)
mw.writeFile(systemService, content)
mw.execShell('systemctl daemon-reload')
return file_bin
@ -308,6 +337,10 @@ if __name__ == "__main__":
print(runLog())
elif func == 'config_tpl':
print(configTpl())
elif func == 'default_scripts_tpl':
print(defaultScriptsTpl())
elif func == 'config_scripts_tpl':
print(configScriptsTpl())
elif func == 'read_config_tpl':
print(readConfigTpl())
else:

@ -1,6 +1,8 @@
#!/bin/bash
# 计划任务,恢复后,可自动拉起keepalived
# {$SERVER_PATH}/keepalived/scripts/chk.sh mysql
# check script bash
curPath=`pwd`

@ -1,5 +1,8 @@
#!/bin/bash
# 计划任务,恢复后,可自动拉起keepalived
# {$SERVER_PATH}/keepalived/scripts/chk_mysql.sh
date +'%Y-%m-%d %H:%M:%S'
echo "start check mysql status ..."
counter=$(netstat -na|grep "LISTEN"|grep "3306"|wc -l)

Loading…
Cancel
Save