Skip to content

Commit a231872

Browse files
author
maqian6
committedApr 20, 2018
1. 监控检测版本 添加bindto, 否则在多网卡环境中 keepalived healthchecker无法发出探活包
2. 修改相关html页面信息 3. 修改config.ymal, 添加lvsLocalIp配置, 以后可以在页面中CRUD这些信息
1 parent 16703a2 commit a231872

File tree

7 files changed

+94
-82
lines changed

7 files changed

+94
-82
lines changed
 

‎MonitorWeb/control.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ def get(self):
551551
lb_list = []
552552
for lb in cluster['agent']:
553553
lb_info = search_agent(lb)
554-
lb_list.append({"id":lb_info['id'],"ipadd":lb_info['ipadd']})
554+
lb_list.append({"id":lb_info['id'],"adminIp":lb_info['adminIp'], "lvsLocalIp":lb_info['lvsLocalIp']})
555555
cluster['lb'] = lb_list
556556
self.render2('lvsmanager.html',cluster_list=cluster_list)
557557

@@ -718,15 +718,15 @@ def get(self):
718718
# 2).对于不同的vrrp实例, tag[0]第一个vrrp实例为主, 则其第二个vrrp实例为备
719719

720720
#keepalive for master
721-
keepalived_config_master = self.template('keepalived.tpl',vip_instance_list = vipinstancelist, router_id = tgt[0], master = 0)
721+
keepalived_config_master = self.template('keepalived.tpl',vip_instance_list = vipinstancelist, router_id = tgt[0], master = 0, localip = search_agent(tgt[0])['lvsLocalIp'])
722722
publishdir = options.publishdir
723723
keepalived_config_file_master = os.path.join(publishdir,new_publish_id) + "master"
724724
f = codecs.open(keepalived_config_file_master,'w+','utf-8')
725725
f.write(keepalived_config_master)
726726
f.close()
727727

728728
#keepalive for slave
729-
keepalived_config_slave = self.template('keepalived.tpl',vip_instance_list = vipinstancelist, router_id = tgt[1], master = 1)
729+
keepalived_config_slave = self.template('keepalived.tpl',vip_instance_list = vipinstancelist, router_id = tgt[1], master = 1, localip = search_agent(tgt[1])['lvsLocalIp'])
730730
keepalived_config_file_slave = os.path.join(publishdir,new_publish_id) + "slave"
731731
f = codecs.open(keepalived_config_file_slave,'w+','utf-8')
732732
f.write(keepalived_config_slave)

‎MonitorWeb/setting.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
cur_dir = os.path.dirname(os.path.abspath(__file__))
88

9-
define("port", default=8888, help="run on the given port", type=int)
9+
define("port", default=8080, help="run on the given port", type=int)
1010
define("mongodb", default="localhost", help="mongodb host")
1111
define("mongodb_port", default=27017, help="mongodb port")
1212
define("db", default="LvsMonitor", help="default Lvs Monitor Db Name")

‎MonitorWeb/templates/keepalived.tpl

+69-57
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
global_defs {
2-
router_id {{ router_id }}
2+
router_id {{ router_id }}
33
}
44

55
{% set rvid = 1 %}
66

7-
include ./local_address.conf
7+
local_address_group laddr_g1 {
8+
{{ localip }}
9+
}
810

911
{% for vipinstance in vip_instance_list %}
1012
{% if vipinstance.status != 'offline' %}
@@ -14,83 +16,93 @@ vrrp_instance {{ vipinstance.vip_instance }} {
1416
interface {{ vipinstance.vip_nic}}
1517
virtual_router_id {% set rvid = rvid%256 %}{{ rvid }}{% set rvid = rvid + 1 %} #VRID可用值0-255,即lvs设备上最多可以定义256个vrrp实例
1618

17-
#多个vrrp实例时, 主备直接轮流切换, 最大化资源利用率
1819
{% set master = master%2 %}
19-
{% if master == 0 %}
20+
{% if master == 0 %} #多个vrrp实例时, 主备直接轮流切换, 最大化资源利用率
2021
priority 100 #主机上设置成100
2122
{% else %}
2223
priority 90 #备机上设置成90
2324
{% endif %}
2425
{% set master = master + 1 %}
2526

2627
advert_int 1
27-
nopreempt #设置成切换不抢占
28-
authentication {
29-
auth_type PASS
30-
auth_pass zsd@2018
31-
}
28+
nopreempt #设置成切换不抢占
29+
authentication {
30+
auth_type PASS
31+
auth_pass zsD@2018
32+
}
33+
34+
notify_master "/etc/keepalived/lvs_to_master.sh {% for vip in vipinstance.vip_group %} {{ vip.vip }}{% endfor %}"
35+
notify_backup "/etc/keepalived/lvs_to_backup.sh {% for vip in vipinstance.vip_group %} {{ vip.vip }}{% endfor %}"
36+
notify_fault "/etc/keepalived/lvs_to_fault.sh {% for vip in vipinstance.vip_group %} {{ vip.vip }}{% endfor %}"
37+
3238
virtual_ipaddress {
3339
{% for vip in vipinstance.vip_group %}
34-
{{ vip.vip }} {{ vip.port }} #{{ vipinstance.descript }}
40+
{{ vip.vip }}
3541
{% endfor %}
3642
}
3743
}
3844

3945

4046
virtual_server_group {{ vipinstance.vip_instance }} {
4147
{% for vip in vipinstance.vip_group %}
42-
{{ vip.vip }} {{ vip.port }} #{{ vipinstance.descript }}
48+
{{ vip.vip }} {{ vip.port }} #{{ vipinstance.descript }}
4349
{% endfor %}
4450
}
4551

4652
virtual_server group {{ vipinstance.vip_instance }} {
47-
delay_loop {{ vipinstance.delay_loop }}
48-
lb_algo {{ vipinstance.lb_algo }}
49-
lb_kind {{ vipinstance.lb_kind }}
50-
protocol {{ vipinstance.protocol }}
51-
persistence_timeout {{ vipinstance.persistence_timeout }}
52-
{% if vipinstance.sync_proxy %}syn_proxy{% endif %}
53-
laddr_group_name laddr_g1
54-
{% if vipinstance.alpha %}alpha{% endif %}
55-
{% if vipinstance.omega %}omega{% endif %}
56-
quorum {{ vipinstance.quorum }}
57-
hysteresis {{ vipinstance.hysteresis }}
58-
quorum_up "{% for vip in vipinstance.vip_group %}ip addr add {{ vip.vip }}/32 dev {{ vipinstance.vip_nic}} ;{% endfor %}"
59-
{% if vipinstance.omega %}
60-
quorum_down "{% for vip in vipinstance.vip_group %}ip addr del {{ vip.vip }}/32 dev {{ vipinstance.vip_nic}} ;{% endfor %}"
61-
{% endif %}
62-
63-
{% for rs in vipinstance.rs %}
64-
{% for rs_port in rs.port %}
65-
real_server {{ rs.server_ip }} {{ rs_port }} {
66-
weight {{ rs.weight }}
67-
inhibit_on_failure
68-
{% if rs.monitor.type == 'HTTP_GET' %}
69-
HTTP_GET {
70-
url {
71-
path {{ rs.monitor.path }}
72-
digest {{ rs.monitor.digest }}
73-
}
74-
connect_timeout {{ rs.monitor.connect_timeout }}
75-
nb_get_retry {{ rs.monitor.nb_get_retry }}
76-
delay_before_retry {{ rs.monitor.delay_before_retry }}
77-
connect_port {{ rs_port }}
78-
}
79-
{% elif rs.monitor.type == 'TCP_CHECK' %}
80-
TCP_CHECK {
81-
connect_timeout {{ rs.monitor.connect_timeout }}
82-
connect_port {{ rs_port }}
83-
}
84-
{% elif rs.monitor.type == 'MISC_CHECK' %}
85-
MISC_CHECK {
86-
misc_path "{{ rs.monitor.misc_path }}"
87-
misc_timeout {{ rs.monitor.misc_timeout }}
88-
}
89-
{% endif %}
53+
delay_loop {{ vipinstance.delay_loop }}
54+
lb_algo {{ vipinstance.lb_algo }}
55+
lb_kind {{ vipinstance.lb_kind }}
56+
protocol {{ vipinstance.protocol }}
57+
persistence_timeout {{ vipinstance.persistence_timeout }}
58+
{% if vipinstance.sync_proxy %}syn_proxy{% endif %}
59+
laddr_group_name laddr_g1
60+
{% if vipinstance.alpha %}alpha{% endif %}
61+
{% if vipinstance.omega %}omega{% endif %}
62+
quorum {{ vipinstance.quorum }}
63+
hysteresis {{ vipinstance.hysteresis }}
64+
quorum_up "{% for vip in vipinstance.vip_group %}ip addr add {{ vip.vip }}/32 dev {{ vipinstance.vip_nic}};{% endfor %}"
65+
{% if vipinstance.omega %}
66+
quorum_down "{% for vip in vipinstance.vip_group %}ip addr del {{ vip.vip }}/32 dev {{ vipinstance.vip_nic}};{% endfor %}"
67+
{% endif %}
68+
69+
{% for rs in vipinstance.rs %}
70+
{% for rs_port in rs.port %}
71+
real_server {{ rs.server_ip }} {{ rs_port }} {
72+
weight {{ rs.weight }}
73+
inhibit_on_failure
74+
75+
notify_up "/etc/keepalived/rs_up.sh {{ rs.server_ip }} {{ rs_port }}"
76+
notify_down "/etc/keepalived/rs_down.sh {{ rs.server_ip }} {{ rs_port }}"
77+
78+
79+
{% if rs.monitor.type == 'HTTP_GET' %}
80+
HTTP_GET {
81+
bindto {{ localip }}
82+
url {
83+
path {{ rs.monitor.path }}
84+
digest {{ rs.monitor.digest }}
85+
}
86+
connect_timeout {{ rs.monitor.connect_timeout }}
87+
nb_get_retry {{ rs.monitor.nb_get_retry }}
88+
delay_before_retry {{ rs.monitor.delay_before_retry }}
89+
connect_port {{ rs_port }}
90+
}
91+
{% elif rs.monitor.type == 'TCP_CHECK' %}
92+
TCP_CHECK {
93+
bindto {{ localip }}
94+
connect_timeout {{ rs.monitor.connect_timeout }}
95+
connect_port {{ rs_port }}
96+
}
97+
{% elif rs.monitor.type == 'MISC_CHECK' %}
98+
MISC_CHECK {
99+
misc_path "{{ rs.monitor.misc_path }}"
100+
misc_timeout {{ rs.monitor.misc_timeout }}
101+
}
102+
{% endif %}
90103
}
91-
{% endfor %}
92-
{% endfor %}
104+
{% endfor %}
105+
{% endfor %}
93106
}
94107
{% endif %}
95-
96108
{% endfor %}

‎MonitorWeb/templates/lvsmanager.html

+13-14
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
<table id="lvsmanager_table" class="table table-bordered table-hover">
2727
<thead>
2828
<tr>
29-
<th style="width: 15%">集群</th>
30-
<th style="width: 15%">描述</th>
31-
<th style="width: 10%">机房</th>
32-
<th style="width: 10%">LB</th>
33-
<th>操作</th>
29+
<th style="width: 10%">集群</th>
30+
<th style="width: 12%">描述</th>
31+
<th style="width: 8%">机房</th>
32+
<th style="width: 20%">LB</th>
33+
<th style="width: 100%">操作</th>
3434
</tr>
3535
</thead>
3636
<tbody id='publish_table_body'>
@@ -39,12 +39,13 @@
3939
<td>{{ cluster.id }}</td>
4040
<td>{{ cluster.descript }}</td>
4141
<td>{{ cluster.area }}</td>
42-
<td>{% for lb in cluster.lb %}
43-
{{ lb.ipadd }}{% endfor %}</td
44-
<td><a href="/lvsmanager_deploy/?id={{ cluster.id }}" class='btn btn-success'><span class="fui-gear"></span></span>配置</a><a href="/lvsmanager_rollback/?id={{ cluster.id }}" class='btn btn-primary' style="position: relative;
45-
left: 5px;"><span class="fui-arrow-left"></span>回滚</a><a href="#" onCLick="lvsmanagerpublish('{{ cluster.id }}')" class='btn btn-warning' style="position: relative;
46-
left: 10px;"><span class="fui-check-inverted-2"></span>发布</a><a href="/lvsmanager_keepalived_reload/?id={{ cluster.id }}" class='btn btn-danger' style="position: relative;
47-
left: 15px;"><span class="fui-calendar-solid"></span>Keepalived操作</a></td>
42+
<td>{% for lb in cluster.lb %} {{ lb.adminIp }}:{{ lb.lvsLocalIp }} {% endfor %}</td>
43+
<td>
44+
<a href="/lvsmanager_deploy/?id={{ cluster.id }}" class='btn btn-success'><span class="fui-gear"></span></span>配置</a>
45+
<a href="/lvsmanager_rollback/?id={{ cluster.id }}" class='btn btn-primary' style="position: relative;left: 5px;"><span class="fui-arrow-left"></span>回滚</a>
46+
<a href="#" onCLick="lvsmanagerpublish('{{ cluster.id }}')" class='btn btn-warning' style="position: relative;left: 10px;"><span class="fui-check-inverted-2"></span>发布</a>
47+
<a href="/lvsmanager_keepalived_reload/?id={{ cluster.id }}" class='btn btn-danger' style="position: relative;left: 15px;"><span class="fui-calendar-solid"></span>Keepalived操作</a>
48+
</td>
4849
</tr>
4950
{% endfor %}
5051
</tbody>
@@ -55,7 +56,6 @@
5556
</div>
5657

5758
<script type="text/javascript">
58-
5959
function lvsmanagerpublish(id) {
6060
bootbox.prompt("请输入本次发布的说明",function(result){
6161
if ( result ) {
@@ -68,7 +68,6 @@
6868
bootbox.alert(_data,function() {
6969
window.location.href="/lvsmanager_keepalived_reload/?id=" + id ;
7070
})
71-
7271
},
7372
error: function(XMLHttpRequest) {
7473
bootbox.alert('发布失败')
@@ -90,4 +89,4 @@
9089
return false ;
9190
})
9291
</script>
93-
{% endblock %}
92+
{% endblock %}

‎MonitorWeb/templates/lvsmanager_deploy.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ <h4>集群:{{ cluster }}</h4>
2222
<table id="lvsmanager_table" class="table table-bordered table-hover">
2323
<thead>
2424
<tr>
25-
<th style="width: 10%">VIP实例</th>
26-
<th style="width: 10%">业务</th>
25+
<th style="width: 10%">VIP实例标识</th>
26+
<th style="width: 10%">业务信息描述</th>
2727
<th style="width: 10%">负责人</th>
2828
<th style="width: 10%">VIP地址组</th>
2929
<th style="width: 10%">协议</th>
@@ -104,4 +104,4 @@ <h4>集群:{{ cluster }}</h4>
104104
});
105105
}
106106
</script>
107-
{% endblock %}
107+
{% endblock %}

‎config-mac.yaml

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ base:
33

44
agent:
55
- id: lvs_master
6-
ipadd: 192.168.43.144
6+
adminIp: 192.168.43.144
7+
lvsLocalIp: 192.168.43.144
78
cluster: bj_lvs_cluster
89
area: beijing
910
port: 60090
1011
state: master
11-
1212
- id: lvs_slave
13-
ipadd: 192.168.43.145
13+
adminIp: 192.168.43.145
14+
lvsLocalIp: 192.168.43.145
1415
cluster: bj_lvs_cluster
1516
area: beijing
1617
port: 60090

‎config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
config-win7.yaml
1+
config-mac.yaml

0 commit comments

Comments
 (0)
Please sign in to comment.