计算板拆分为4个roles分别部署

This commit is contained in:
lijia
2019-09-18 20:45:30 +08:00
parent 4fc766a1e0
commit 6e25d6bbf0
18 changed files with 366 additions and 7 deletions

59
hosts.astana Normal file
View File

@@ -0,0 +1,59 @@
[all:vars]
ansible_user=root
rpm_file_name=tsg-cli-1.0.6-1.el7.x86_64.rpm
[blade-00]
10.4.39.9
#10.4.39.13
10.4.39.17
10.4.39.21
10.4.39.25
10.4.39.29
10.4.39.33
[blade-01]
10.4.39.10
#10.4.39.14
10.4.39.18
10.4.39.22
10.4.39.26
10.4.39.30
10.4.39.34
[blade-02]
10.4.39.11
#10.4.39.15
10.4.39.19
10.4.39.23
10.4.39.27
10.4.39.31
10.4.39.35
[blade-03]
10.4.39.12
#10.4.39.16
10.4.39.20
10.4.39.24
10.4.39.28
10.4.39.32
10.4.39.36
[astana-adc-3]
10.4.39.9
10.4.39.10
10.4.39.11
10.4.39.12
[astana-adc-9]
10.4.39.33
10.4.39.34
10.4.39.35
10.4.39.36
[control-blade-all:children]
blade-01
blade-02
blade-03
[certstore]
10.4.35.1 ansible_user=tsg

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#mcn1-3
#mcn1
#防止因上一次的命令阻塞或长时间未返回,
#导致10秒内还不结束, 强行杀掉,
@@ -9,7 +9,6 @@ killall_uncompleted_cmd(){
#killall -9 tsg_cluster_register
killall -9 tsg_diagnose_background
killall -9 tsg_update_tags
killall -9 tsg_monit_interface
}

View File

@@ -8,6 +8,5 @@
"dev_type": "marsio",
"flow_type": "mirror"
}
]
}

View File

@@ -0,0 +1,15 @@
[Unit]
Description=tsg monitor service
Requires=network.target
After=network.target
[Service]
#WorkingDirectory=/opt/tsg/tsg-monitor/
ExecStart=/opt/tsg/tsg-monitor/tsg-monitor.sh
#ExecStop=/bin/kill -9 $MAINPID
Type=simple
Restart=always
RestartSec=5s
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,74 @@
#!/bin/sh
#mcn2
#防止因上一次的命令阻塞或长时间未返回,
#导致10秒内还不结束, 强行杀掉,
#否则长时间运行后, 会有大量后台进程运行
killall_uncompleted_cmd(){
#killall -9 tsg_cluster_register
killall -9 tsg_diagnose_background
killall -9 tsg_update_tags
killall -9 tsg_monit_interface
}
start_background_cmd(){
#后台并发运行, 保证所有命令的开始运行时间基本一样,
#且不会因某个命令网络拥塞、执行时间长等问题阻塞while(1)主循环
/opt/tsg/tsg-monitor/tsg_diagnose_background > /dev/null &
/opt/tsg/tsg-monitor/tsg_update_tags > /dev/null &
/opt/tsg/tsg-monitor/tsg_monit_interface > /dev/null &
}
#return value: current time in ms
get_current_time_in_ms(){
time_sec=`date +"%s"`
time_nsec=`date +"%N"`
#echo $time_sec
#echo $time_nsec
time_epoch_ms=`echo | awk -v a=$time_sec -v b=$time_nsec '{printf("%.f"), a*1000+b/1000/1000}'`
echo $time_epoch_ms
}
#args:
#begin from time, in ms
#wait for n ms
sleep_for_time_ms(){
last_time=$1
wait_sec=$2
#break_time=`echo | awk -v a=$last_time -v b=$wait_sec '{printf("%.f"), a+b}'`
break_time=`expr $last_time + $wait_sec`
break_time_int=`expr $break_time`
#echo "start: last_time is:$last_time, expect break timeis:$break_time!"
current_time=0
break_time=0
#break_time=`expr $last_time + 1000*$1`
while [ 1 ]; do
current_time=`get_current_time_in_ms`
current_time_int=`expr $current_time`
if [ $current_time_int -ge $break_time_int ]; then
#echo "current is: $current_time_int, break_time is:$break_time_int, break!"
break
else
#echo "break is: $current_time_int, last_time is:$break_time_int, continue!"
# usleep is us
usleep 1000
fi
done
}
while [ 1 ]; do
start_time=`get_current_time_in_ms`
echo tsg-monitor start at `date +"%Y/%m/%d, %H:%M:%S.%N"` >> /tmp/tsg-monitor.log
start_background_cmd
sleep 10
killall_uncompleted_cmd
sleep_for_time_ms $start_time 15000
done

View File

@@ -0,0 +1,12 @@
{
"interface_list": [{
"dev_name": "ens8f1",
"dev_type": "pcap",
"flow_type": "intercomm"
},{
"dev_name": "ens8f2",
"dev_type": "marsio",
"flow_type": "mirror"
}
]
}

View File

@@ -0,0 +1,45 @@
---
- name: "copy tsg-cli rmp to destination server"
synchronize:
src: "{{ role_path }}/../tsg-common-files/{{ rpm_file_name }}"
dest: "/tmp/tsg-cli-deploy/"
- name: "install tsg-cli"
yum:
name: "{{ packages }}"
state: present
vars:
packages:
- /tmp/tsg-cli-deploy/{{ rpm_file_name }}
- name: Template the tsg_sn.json
template:
src: "{{ role_path }}/templates/tsg_sn.json.j2"
dest: /opt/tsg/etc/tsg_sn.json
tags: template
- name: "copy tsg-monitor.service to destination server"
synchronize:
src: "{{ role_path }}/files/tsg-monitor.service"
dest: "/usr/lib/systemd/system"
- name: "copy tsg_chassis_interface.json to destination server"
synchronize:
src: "{{ role_path }}/files/tsg_chassis_interface.json"
dest: "/opt/tsg/etc/"
- name: "copy tsg-monitor.sh to destination server"
#synchronize:
copy:
src: "{{ role_path }}/files/tsg-monitor.sh"
dest: "/opt/tsg/tsg-monitor/"
mode: 0755
- name: "reload systemd config"
command: systemctl daemon-reload
- name: "enable tsg-monitor service"
command: systemctl enable tsg-monitor.service
#- name: "start tsg-monitor service"
# command: systemctl start tsg-monitor.service

View File

@@ -0,0 +1,3 @@
{
"sn": "{{ SN }}"
}

View File

@@ -0,0 +1,15 @@
[Unit]
Description=tsg monitor service
Requires=network.target
After=network.target
[Service]
#WorkingDirectory=/opt/tsg/tsg-monitor/
ExecStart=/opt/tsg/tsg-monitor/tsg-monitor.sh
#ExecStop=/bin/kill -9 $MAINPID
Type=simple
Restart=always
RestartSec=5s
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,74 @@
#!/bin/sh
#mcn3
#防止因上一次的命令阻塞或长时间未返回,
#导致10秒内还不结束, 强行杀掉,
#否则长时间运行后, 会有大量后台进程运行
killall_uncompleted_cmd(){
#killall -9 tsg_cluster_register
killall -9 tsg_diagnose_background
killall -9 tsg_update_tags
killall -9 tsg_monit_interface
}
start_background_cmd(){
#后台并发运行, 保证所有命令的开始运行时间基本一样,
#且不会因某个命令网络拥塞、执行时间长等问题阻塞while(1)主循环
/opt/tsg/tsg-monitor/tsg_diagnose_background > /dev/null &
/opt/tsg/tsg-monitor/tsg_update_tags > /dev/null &
/opt/tsg/tsg-monitor/tsg_monit_interface > /dev/null &
}
#return value: current time in ms
get_current_time_in_ms(){
time_sec=`date +"%s"`
time_nsec=`date +"%N"`
#echo $time_sec
#echo $time_nsec
time_epoch_ms=`echo | awk -v a=$time_sec -v b=$time_nsec '{printf("%.f"), a*1000+b/1000/1000}'`
echo $time_epoch_ms
}
#args:
#begin from time, in ms
#wait for n ms
sleep_for_time_ms(){
last_time=$1
wait_sec=$2
#break_time=`echo | awk -v a=$last_time -v b=$wait_sec '{printf("%.f"), a+b}'`
break_time=`expr $last_time + $wait_sec`
break_time_int=`expr $break_time`
#echo "start: last_time is:$last_time, expect break timeis:$break_time!"
current_time=0
break_time=0
#break_time=`expr $last_time + 1000*$1`
while [ 1 ]; do
current_time=`get_current_time_in_ms`
current_time_int=`expr $current_time`
if [ $current_time_int -ge $break_time_int ]; then
#echo "current is: $current_time_int, break_time is:$break_time_int, break!"
break
else
#echo "break is: $current_time_int, last_time is:$break_time_int, continue!"
# usleep is us
usleep 1000
fi
done
}
while [ 1 ]; do
start_time=`get_current_time_in_ms`
echo tsg-monitor start at `date +"%Y/%m/%d, %H:%M:%S.%N"` >> /tmp/tsg-monitor.log
start_background_cmd
sleep 10
killall_uncompleted_cmd
sleep_for_time_ms $start_time 15000
done

View File

@@ -0,0 +1,13 @@
{
"interface_list": [{
"dev_name": "ens8f1",
"dev_type": "pcap",
"flow_type": "intercomm"
},{
"dev_name": "ens8f2",
"dev_type": "marsio",
"flow_type": "mirror"
}
]
}

View File

@@ -0,0 +1,45 @@
---
- name: "copy tsg-cli rmp to destination server"
synchronize:
src: "{{ role_path }}/../tsg-common-files/{{ rpm_file_name }}"
dest: "/tmp/tsg-cli-deploy/"
- name: "install tsg-cli"
yum:
name: "{{ packages }}"
state: present
vars:
packages:
- /tmp/tsg-cli-deploy/{{ rpm_file_name }}
- name: Template the tsg_sn.json
template:
src: "{{ role_path }}/templates/tsg_sn.json.j2"
dest: /opt/tsg/etc/tsg_sn.json
tags: template
- name: "copy tsg-monitor.service to destination server"
synchronize:
src: "{{ role_path }}/files/tsg-monitor.service"
dest: "/usr/lib/systemd/system"
- name: "copy tsg_chassis_interface.json to destination server"
synchronize:
src: "{{ role_path }}/files/tsg_chassis_interface.json"
dest: "/opt/tsg/etc/"
- name: "copy tsg-monitor.sh to destination server"
#synchronize:
copy:
src: "{{ role_path }}/files/tsg-monitor.sh"
dest: "/opt/tsg/tsg-monitor/"
mode: 0755
- name: "reload systemd config"
command: systemctl daemon-reload
- name: "enable tsg-monitor service"
command: systemctl enable tsg-monitor.service
#- name: "start tsg-monitor service"
# command: systemctl start tsg-monitor.service

View File

@@ -0,0 +1,3 @@
{
"sn": "{{ SN }}"
}

View File

@@ -15,7 +15,10 @@ start_background_cmd(){
#后台并发运行, 保证所有命令的开始运行时间基本一样,
#且不会因某个命令网络拥塞、执行时间长等问题阻塞while(1)主循环
/opt/tsg/tsg-monitor/tsg_cluster_register > /dev/null &
#nohup /opt/tsg/tsg-monitor/tsg_diagnose_background &
#mxn板只检测cpu, mem, disk等, 前台cli命令启用diagnose,
#后台服务依靠oam snmp模块, 无需运行tsg_diagnose_background
#/opt/tsg/tsg-monitor/tsg_diagnose_background &
/opt/tsg/tsg-monitor/tsg_update_tags > /dev/null &
}

View File

@@ -10,14 +10,14 @@
- hosts: sled-mcn1
roles:
- tsg-cli-mcn1-3
- tsg-cli-mcn1
- hosts: sled-mcn2
roles:
- tsg-cli-mcn1-3
- tsg-cli-mcn2
- hosts: sled-mcn3
roles:
- tsg-cli-mcn1-3
- tsg-cli-mcn3