create new project.

This commit is contained in:
lijia
2019-09-17 18:18:25 +08:00
commit 0064af7061
28 changed files with 742 additions and 0 deletions

28
hosts.huayan Normal file
View File

@@ -0,0 +1,28 @@
[all:vars]
ansible_user=root
rpm_file_name=tsg-cli-1.0.6-1.el7.x86_64.rpm
[sled-mxn]
192.168.10.45 SN=CBT2201925000001
[sled-mcn0]
192.168.10.41 SN=CBT2201925000001
[sled-mcn1]
192.168.10.42 SN=CBT2201925000001
[sled-mcn2]
192.168.10.43 SN=CBT2201925000001
[sled-mcn3]
192.168.10.44 SN=CBT2201925000001
[tsg-all:children]
sled-mxn
sled-mcn0
sled-mcn1
sled-mcn2
sled-mcn3

View File

@@ -0,0 +1,16 @@
[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=/home/tsg/kni/kni_service_scipt stop
#ExecStop=/bin/kill -9 $MAINPID
Type=simple
Restart=always
RestartSec=5s
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,87 @@
#!/bin/sh
#mcn0
#防止因上一次的命令阻塞或长时间未返回,
#导致10秒内还不结束, 强行杀掉,
#否则长时间运行后, 会有大量后台进程运行
killall_uncompleted_cmd(){
#killall -9 tsg_cluster_register
killall -9 tsg_diagnose_background
killall -9 tsg_update_tags
killall -9 tsg_monit_app
killall -9 tsg_monit_intercept
killall -9 tsg_monit_interface
killall -9 tsg_monit_protocol_v3
killall -9 tsg_monit_protocol_v4
killall -9 tsg_monit_stream_v3
killall -9 tsg_monit_stream_v4
}
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_app > /dev/null &
/opt/tsg/tsg-monitor/tsg_monit_intercept > /dev/null &
/opt/tsg/tsg-monitor/tsg_monit_interface > /dev/null &
/opt/tsg/tsg-monitor/tsg_monit_protocol_v3 > /dev/null &
/opt/tsg/tsg-monitor/tsg_monit_protocol_v4 > /dev/null &
/opt/tsg/tsg-monitor/tsg_monit_stream_v3 > /dev/null &
/opt/tsg/tsg-monitor/tsg_monit_stream_v4 > /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,16 @@
{
"local_chassis_node": "mcn0",
"interface_list": [
{
"dev_name": "ens1f4",
"dev_type": "marsio",
"flow_type": "inline"
},
{
"dev_name": "ens1f5",
"dev_type": "marsio",
"flow_type": "inline"
}
]
}

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 main.conf
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,75 @@
#!/bin/sh
#mcn1-3
#防止因上一次的命令阻塞或长时间未返回,
#导致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": "ens1f1",
"dev_type": "pcap",
"flow_type": "intercomm"
},{
"dev_name": "ens1f2",
"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 $MAINPID
Type=simple
Restart=always
RestartSec=5s
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,72 @@
#!/bin/sh
#mxn
#防止因上一次的命令阻塞或长时间未返回,
#导致10秒内还不结束, 要强行杀掉,
#否则长时间运行后, 会有大量后台进程运行!
killall_uncompleted_cmd(){
killall -9 tsg_cluster_register
#killall -9 tsg_diagnose_background
killall -9 tsg_update_tags
}
start_background_cmd(){
#后台并发运行, 保证所有命令的开始运行时间基本一样,
#且不会因某个命令网络拥塞、执行时间长等问题阻塞while(1)主循环
/opt/tsg/tsg-monitor/tsg_cluster_register > /dev/null &
#nohup /opt/tsg/tsg-monitor/tsg_diagnose_background &
/opt/tsg/tsg-monitor/tsg_update_tags > /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,40 @@
---
- 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-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,28 @@
#!/bin/bash
ifconfig ens1 up
modprobe 8021q
vconfig add ens1 100
vconfig set_flag ens1.100 1 1
ifconfig ens1.100 192.168.100.1 netmask 255.255.255.0 up
echo 0 > /sys/class/net/ens1/device/sriov_numvfs
sleep 1
echo 8 > /sys/class/net/ens1/device/sriov_numvfs
sleep 1
ifconfig ens1f3 up
ip link set ens1 vf 2 vlan 200
ifconfig ens1f3 192.168.200.1 netmask 255.255.255.0
ifconfig enp7s0 up
ifconfig enp8s0 up
ifconfig ens1f1 up
ifconfig ens1f2 up
ifconfig ens1f3 up
ifconfig ens1f4 up
ifconfig ens1f5 up
ifconfig ens1f6 up
ifconfig ens1f7 up
ifconfig enp1s1 up

View File

@@ -0,0 +1,18 @@
[Unit]
Description=tsg env init
Requires=network.target
After=network.target
Before=mrenv.service
[Service]
#WorkingDirectory=/opt/tsg/env
ExecStart=/opt/tsg/env/setup
#ExecStop=/home/tsg/kni/kni_service_scipt stop
#ExecStop=/bin/kill -9 $MAINPID
Type=oneshot
RemainAfterExit=yes
#Restart=always
#RestartSec=5s
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,19 @@
---
- name: "copy setup.sh"
copy:
src: "{{ role_path }}/files/setup"
dest: "/opt/tsg/env/"
mode: 0755
- name: "copy tsg-env.service"
copy:
src: "{{ role_path }}/files/tsg-env.service"
dest: "/usr/lib/systemd/system/"
mode: 0644
- name: "enable tsg-env"
systemd:
name: tsg-env
enabled: yes
daemon_reload: yes

View File

@@ -0,0 +1,25 @@
#!/bin/bash
ifconfig ens1 up
modprobe 8021q
vconfig add ens1 100
vconfig set_flag ens1.100 1 1
ifconfig ens1.100 192.168.100.2 netmask 255.255.255.0 up
echo 0 > /sys/class/net/ens1/device/sriov_numvfs
sleep 1
echo 3 > /sys/class/net/ens1/device/sriov_numvfs
sleep 1
ifconfig ens1f3 up
ip link set ens1 vf 2 vlan 200
ifconfig ens1f3 192.168.200.2 netmask 255.255.255.0
ifconfig enp7s0 up
ifconfig enp8s0 up
ifconfig ens1f1 up
ifconfig ens1f2 up
ifconfig ens1f3 up

View File

@@ -0,0 +1,18 @@
[Unit]
Description=tsg env init
Requires=network.target
After=network.target
Before=mrenv.service
[Service]
#WorkingDirectory=/opt/tsg/env
ExecStart=/opt/tsg/env/setup
#ExecStop=/home/tsg/kni/kni_service_scipt stop
#ExecStop=/bin/kill -9 $MAINPID
Type=oneshot
RemainAfterExit=yes
#Restart=always
#RestartSec=5s
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,18 @@
---
- name: "copy setup.sh"
copy:
src: "{{ role_path }}/files/setup"
dest: "/opt/tsg/env/"
mode: 0755
- name: "copy tsg-env.service"
copy:
src: "{{ role_path }}/files/tsg-env.service"
dest: "/usr/lib/systemd/system/"
mode: 0644
- name: "enable tsg-env"
systemd:
name: tsg-env
enabled: yes
daemon_reload: yes

View File

@@ -0,0 +1,23 @@
#!/bin/bash
ifconfig ens8 up
modprobe 8021q
vconfig add ens8 100
vconfig set_flag ens8.100 1 1
ifconfig ens8.100 192.168.100.3 netmask 255.255.255.0 up
echo 0 > /sys/class/net/ens8/device/sriov_numvfs
sleep 1
echo 3 > /sys/class/net/ens8/device/sriov_numvfs
sleep 1
ifconfig ens8f3 up
ip link set ens8 vf 2 vlan 200
ifconfig ens8f3 192.168.200.3 netmask 255.255.255.0
ifconfig enp7s0 up
ifconfig enp8s0 up
ifconfig ens8f1 up
ifconfig ens8f2 up
ifconfig ens8f3 up
ifconfig ens8f4 up

View File

@@ -0,0 +1,18 @@
[Unit]
Description=tsg env init
Requires=network.target
After=network.target
Before=mrenv.service
[Service]
#WorkingDirectory=/opt/tsg/env
ExecStart=/opt/tsg/env/setup
#ExecStop=/home/tsg/kni/kni_service_scipt stop
#ExecStop=/bin/kill -9 $MAINPID
Type=oneshot
RemainAfterExit=yes
#Restart=always
#RestartSec=5s
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,18 @@
---
- name: "copy setup.sh"
copy:
src: "{{ role_path }}/files/setup"
dest: "/opt/tsg/env/"
mode: 0755
- name: "copy tsg-env.service"
copy:
src: "{{ role_path }}/files/tsg-env.service"
dest: "/usr/lib/systemd/system/"
mode: 0644
- name: "enable tsg-env"
systemd:
name: tsg-env
enabled: yes
daemon_reload: yes

View File

@@ -0,0 +1,21 @@
#!/bin/bash
ifconfig ens8 up
modprobe 8021q
vconfig add ens8 100
vconfig set_flag ens8.100 1 1
ifconfig ens8.100 192.168.100.4 netmask 255.255.255.0 up
echo 0 > /sys/class/net/ens8/device/sriov_numvfs
sleep 1
echo 3 > /sys/class/net/ens8/device/sriov_numvfs
sleep 1
ifconfig ens8f3 up
ip link set ens8 vf 2 vlan 200
ifconfig ens8f3 192.168.200.4 netmask 255.255.255.0
ifconfig enp7s0 up
ifconfig enp8s0 up
ifconfig ens8f1 up
ifconfig ens8f2 up
ifconfig ens8f3 up

View File

@@ -0,0 +1,18 @@
[Unit]
Description=tsg env init
Requires=network.target
After=network.target
Before=mrenv.service
[Service]
#WorkingDirectory=/opt/tsg/env
ExecStart=/opt/tsg/env/setup
#ExecStop=/home/tsg/kni/kni_service_scipt stop
#ExecStop=/bin/kill -9 $MAINPID
Type=oneshot
RemainAfterExit=yes
#Restart=always
#RestartSec=5s
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,18 @@
---
- name: "copy setup.sh"
copy:
src: "{{ role_path }}/files/setup"
dest: "/opt/tsg/env/"
mode: 0755
- name: "copy tsg-env.service"
copy:
src: "{{ role_path }}/files/tsg-env.service"
dest: "/usr/lib/systemd/system/"
mode: 0644
- name: "enable tsg-env"
systemd:
name: tsg-env
enabled: yes
daemon_reload: yes

24
tsg-cli-playbook.yml Normal file
View File

@@ -0,0 +1,24 @@
---
- hosts: sled-mxn
roles:
- tsg-cli-mxn
- hosts: sled-mcn0
roles:
- tsg-cli-mcn0
- tsg-env-mcn0
- hosts: sled-mcn1
roles:
- tsg-cli-mcn1-3
- tsg-env-mcn1
- hosts: sled-mcn2
roles:
- tsg-cli-mcn1-3
- tsg-env-mcn2
- hosts: sled-mcn3
roles:
- tsg-cli-mcn1-3
- tsg-env-mcn3