添加OAM、tsg-cli自动部署部分
This commit is contained in:
93
roles/tsg-cli-mcn3/files/rsyslog.conf
Normal file
93
roles/tsg-cli-mcn3/files/rsyslog.conf
Normal file
@@ -0,0 +1,93 @@
|
||||
# rsyslog configuration file
|
||||
|
||||
# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html
|
||||
# If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html
|
||||
|
||||
#### MODULES ####
|
||||
|
||||
# The imjournal module bellow is now used as a message source instead of imuxsock.
|
||||
$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
|
||||
$ModLoad imjournal # provides access to the systemd journal
|
||||
#$ModLoad imklog # reads kernel messages (the same are read from journald)
|
||||
#$ModLoad immark # provides --MARK-- message capability
|
||||
|
||||
# Provides UDP syslog reception
|
||||
#$ModLoad imudp
|
||||
#$UDPServerRun 514
|
||||
|
||||
# Provides TCP syslog reception
|
||||
#$ModLoad imtcp
|
||||
#$InputTCPServerRun 514
|
||||
|
||||
|
||||
#### GLOBAL DIRECTIVES ####
|
||||
|
||||
# Where to place auxiliary files
|
||||
$WorkDirectory /var/lib/rsyslog
|
||||
|
||||
# Use default timestamp format
|
||||
#$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
|
||||
$template tsgformat,"%$NOW% %TIMESTAMP:8:15% %HOSTNAME:F,45:3%:<%PRI%> [%syslogseverity-text%] %msg%\n"
|
||||
$ActionFileDefaultTemplate tsgformat
|
||||
|
||||
# File syncing capability is disabled by default. This feature is usually not required,
|
||||
# not useful and an extreme performance hit
|
||||
#$ActionFileEnableSync on
|
||||
|
||||
# Include all config files in /etc/rsyslog.d/
|
||||
$IncludeConfig /etc/rsyslog.d/*.conf
|
||||
|
||||
# Turn off message reception via local log socket;
|
||||
# local messages are retrieved through imjournal now.
|
||||
$OmitLocalLogging on
|
||||
|
||||
# File to store the position in the journal
|
||||
$IMJournalStateFile imjournal.state
|
||||
|
||||
|
||||
#### RULES ####
|
||||
|
||||
# Log all kernel messages to the console.
|
||||
# Logging much else clutters up the screen.
|
||||
#kern.* /dev/console
|
||||
|
||||
# Log anything (except mail) of level info or higher.
|
||||
# Don't log private authentication messages!
|
||||
*.notice;mail.none;authpriv.none;cron.none /var/log/messages
|
||||
|
||||
# The authpriv file has restricted access.
|
||||
authpriv.* /var/log/secure
|
||||
|
||||
# Log all the mail messages in one place.
|
||||
mail.* -/var/log/maillog
|
||||
|
||||
|
||||
# Log cron stuff
|
||||
cron.* /var/log/cron
|
||||
|
||||
# Everybody gets emergency messages
|
||||
*.emerg :omusrmsg:*
|
||||
|
||||
# Save news errors of level crit and higher in a special file.
|
||||
uucp,news.crit /var/log/spooler
|
||||
|
||||
# Save boot messages also to boot.log
|
||||
local7.* /var/log/boot.log
|
||||
|
||||
|
||||
# ### begin forwarding rule ###
|
||||
# The statement between the begin ... end define a SINGLE forwarding
|
||||
# rule. They belong together, do NOT split them. If you create multiple
|
||||
# forwarding rules, duplicate the whole block!
|
||||
# Remote Logging (we use TCP for reliable delivery)
|
||||
#
|
||||
# An on-disk queue is created for this action. If the remote host is
|
||||
# down, messages are spooled to disk and sent when it is up again.
|
||||
#$ActionQueueFileName fwdRule1 # unique name prefix for spool files
|
||||
#$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible)
|
||||
#$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
|
||||
#$ActionQueueType LinkedList # run asynchronously
|
||||
#$ActionResumeRetryCount -1 # infinite retries if host is down
|
||||
# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional
|
||||
*.warning @@192.168.100.5:514
|
||||
# ### end of the forwarding rule ###
|
||||
15
roles/tsg-cli-mcn3/files/tsg-monitor.service
Normal file
15
roles/tsg-cli-mcn3/files/tsg-monitor.service
Normal 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
|
||||
75
roles/tsg-cli-mcn3/files/tsg-monitor.sh
Normal file
75
roles/tsg-cli-mcn3/files/tsg-monitor.sh
Normal file
@@ -0,0 +1,75 @@
|
||||
#!/bin/sh
|
||||
|
||||
#mcn3
|
||||
|
||||
#防止因上一次的命令阻塞或长时间未返回,
|
||||
#导致10秒内还不结束, 强行杀掉,
|
||||
#否则长时间运行后, 会有大量后台进程运行
|
||||
killall_uncompleted_cmd(){
|
||||
#killall -9 -q tsg_cluster_register
|
||||
killall -9 -q tsg_diagnose_background
|
||||
killall -9 -q tsg_update_tags
|
||||
killall -9 -q tsg_monit_interface
|
||||
killall -9 -q tsg_monit_intercept
|
||||
}
|
||||
|
||||
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 &
|
||||
/opt/tsg/tsg-monitor/tsg_monit_intercept > /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
|
||||
13
roles/tsg-cli-mcn3/files/tsg_chassis_interface.json
Normal file
13
roles/tsg-cli-mcn3/files/tsg_chassis_interface.json
Normal 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"
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
60
roles/tsg-cli-mcn3/tasks/main.yml
Normal file
60
roles/tsg-cli-mcn3/tasks/main.yml
Normal file
@@ -0,0 +1,60 @@
|
||||
---
|
||||
- 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
|
||||
when: not use_chassis_hardware_sn | bool
|
||||
|
||||
- name: "copy tsg_sn.json to destination server"
|
||||
synchronize:
|
||||
src: "{{ role_path }}/../tsg-common-files/tsg_sn.json"
|
||||
dest: "/opt/tsg/etc/tsg_sn.json"
|
||||
when: use_chassis_hardware_sn | bool
|
||||
|
||||
- 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: "copy rsyslog.conf to destination server"
|
||||
synchronize:
|
||||
src: "{{ role_path }}/files/rsyslog.conf"
|
||||
dest: "/etc/"
|
||||
|
||||
- name: "restart rsyslog service"
|
||||
systemd:
|
||||
name: rsyslog
|
||||
state: restarted
|
||||
|
||||
- name: "enable tsg-monitor service"
|
||||
systemd:
|
||||
name: tsg-monitor
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
||||
state: restarted
|
||||
3
roles/tsg-cli-mcn3/templates/tsg_sn.json.j2
Normal file
3
roles/tsg-cli-mcn3/templates/tsg_sn.json.j2
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"sn": "{{ SN }}"
|
||||
}
|
||||
Reference in New Issue
Block a user