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 { vrrp_script chk_mysql_port {
script "{$PLUGIN_PATH}/scripts/chk_mysql.sh" script "{$PLUGIN_PATH}/scripts/chk.sh mysql"
interval 2 interval 2
weight –5 weight –5
fall 2 fall 2
rise 1 rise 1
} }
vrrp_instance VI_1 { vrrp_instance VI_MYSQL {
state MASTER state MASTER
interface {$ETH_XX} interface {$ETH_XX}
virtual_router_id 51 virtual_router_id 51

@ -6,8 +6,7 @@
<p onclick="pluginInitD('keepalived');">自启动</p> <p onclick="pluginInitD('keepalived');">自启动</p>
<!-- <p onclick="pluginConfig('keepalived');">配置修改</p> --> <!-- <p onclick="pluginConfig('keepalived');">配置修改</p> -->
<p onclick="pluginConfigTpl('keepalived',$('.plugin_version').attr('version'));">配置修改</p> <p onclick="pluginConfigTpl('keepalived',$('.plugin_version').attr('version'));">配置修改</p>
<!-- <p onclick="getRedisConfig($('.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="redisStatus($('.plugin_version').attr('version'));">负载状态</p> -->
<!-- <p onclick="pluginLogs('keepalived','','run_log');">日志</p> --> <!-- <p onclick="pluginLogs('keepalived','','run_log');">日志</p> -->
</div> </div>
<div class="bt-w-con pd15"> <div class="bt-w-con pd15">

@ -97,6 +97,21 @@ def readConfigTpl():
content = contentReplace(content) content = contentReplace(content)
return mw.returnJson(True, 'ok', 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(): def status():
data = mw.execShell( data = mw.execShell(
"ps aux|grep keepalived |grep -v grep | grep -v python | grep -v mdserver-web | awk '{print $2}'") "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') content = content.replace('{$ETH_XX}', 'eth1')
else: else:
# # 已找到
content = content.replace('{$ETH_XX}', ethx[0]) content = content.replace('{$ETH_XX}', ethx[0])
return content 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(): def initDreplace():
file_tpl = getInitDTpl() file_tpl = getInitDTpl()
@ -150,13 +179,13 @@ def initDreplace():
dst_conf = getServerDir() + '/etc/keepalived/keepalived.conf' dst_conf = getServerDir() + '/etc/keepalived/keepalived.conf'
dst_conf_init = getServerDir() + '/init.pl' dst_conf_init = getServerDir() + '/init.pl'
if not os.path.exists(dst_conf_init): if not os.path.exists(dst_conf_init):
conf_content = mw.readFile(getConfTpl()) content = mw.readFile(getConfTpl())
content = contentReplace(content)
conf_content = contentReplace(conf_content) mw.writeFile(dst_conf, content)
mw.writeFile(dst_conf, conf_content)
mw.writeFile(dst_conf_init, 'ok') mw.writeFile(dst_conf_init, 'ok')
# route -n | grep ^0.0.0.0 | awk '{print $8}' # 复制检查脚本
copyScripts()
# systemd # systemd
systemDir = mw.systemdCfgDir() systemDir = mw.systemdCfgDir()
@ -164,9 +193,9 @@ def initDreplace():
if os.path.exists(systemDir) and not os.path.exists(systemService): if os.path.exists(systemDir) and not os.path.exists(systemService):
systemServiceTpl = getPluginDir() + '/init.d/' + getPluginName() + '.service.tpl' systemServiceTpl = getPluginDir() + '/init.d/' + getPluginName() + '.service.tpl'
service_path = mw.getServerDir() service_path = mw.getServerDir()
se_content = mw.readFile(systemServiceTpl) content = mw.readFile(systemServiceTpl)
se_content = contentReplace(se_content) content = contentReplace(content)
mw.writeFile(systemService, se_content) mw.writeFile(systemService, content)
mw.execShell('systemctl daemon-reload') mw.execShell('systemctl daemon-reload')
return file_bin return file_bin
@ -308,6 +337,10 @@ if __name__ == "__main__":
print(runLog()) print(runLog())
elif func == 'config_tpl': elif func == 'config_tpl':
print(configTpl()) print(configTpl())
elif func == 'default_scripts_tpl':
print(defaultScriptsTpl())
elif func == 'config_scripts_tpl':
print(configScriptsTpl())
elif func == 'read_config_tpl': elif func == 'read_config_tpl':
print(readConfigTpl()) print(readConfigTpl())
else: else:

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

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

Loading…
Cancel
Save