feat: NEZ-3158 nz-agent 内置组件增加 rsyslog&logrotate 配置

This commit is contained in:
shizhendong
2023-09-04 14:52:58 +08:00
parent e34c963aae
commit 968406eedc
2 changed files with 104 additions and 0 deletions

View File

@@ -137,6 +137,99 @@ OPTION=" -config.file=/opt/nezha/nz-agent/loki/loki.yml"
EOF
}
# 初始化 rsyslog & logrotate 配置
fn_init_syslog_logrotate_config(){
# cortex
cat > /etc/rsyslog.d/cortex.conf << "EOF"
if $programname == 'cortex-linux-amd64' then {
/var/log/nezha/cortex/cortex.log
stop
}
EOF
cat > /etc/logrotate.d/cortex << "EOF"
/var/log/nezha/cortex/*.log {
daily
missingok
maxsize 100M
rotate 7
copytruncate
compress
}
EOF
# loki
cat > /etc/rsyslog.d/loki.conf << "EOF"
if $programname == 'loki-linux-amd64' then {
/var/log/nezha/loki/loki.log
stop
}
EOF
cat > /etc/logrotate.d/loki << "EOF"
/var/log/nezha/loki/*.log {
daily
missingok
maxsize 100M
rotate 7
copytruncate
compress
}
EOF
# prometheus
cat > /etc/rsyslog.d/prometheus.conf << "EOF"
if $programname == 'prometheus' then {
/var/log/nezha/prometheus/prometheus.log
stop
}
EOF
cat > /etc/logrotate.d/prometheus << "EOF"
/var/log/nezha/prometheus/*.log {
daily
missingok
maxsize 100M
rotate 7
copytruncate
compress
}
EOF
# snmp_exporter
cat > /etc/rsyslog.d/snmp_exporter.conf << "EOF"
if $programname == 'snmp_exporter' then {
/var/log/nezha/snmp_exporter/snmp_exporter.log
stop
}
EOF
cat > /etc/logrotate.d/snmp_exporter << "EOF"
/var/log/nezha/snmp_exporter/*.log {
daily
missingok
maxsize 100M
rotate 7
copytruncate
compress
}
EOF
# blackbox_exporter
cat > /etc/rsyslog.d/blackbox_exporter.conf << "EOF"
if $programname == 'blackbox_exporter' then {
/var/log/nezha/blackbox_exporter/blackbox_exporter.log
stop
}
EOF
cat > /etc/logrotate.d/blackbox_exporter << "EOF"
/var/log/nezha/blackbox_exporter/*.log {
daily
missingok
maxsize 100M
rotate 7
copytruncate
compress
}
EOF
}
compareMD5(){
if [ ! -f $1 ] || [ ! -f $2 ];then
echo 1
@@ -196,6 +289,8 @@ if [ 1 -eq $1 ];then
fn_init_blackbox_exporter_service
fn_init_cortex_service
fn_init_loki_service
fn_init_syslog_logrotate_config
systemctl daemon-reload
systemctl enable nz-agent && systemctl restart nz-agent
@@ -204,6 +299,8 @@ if [ 1 -eq $1 ];then
systemctl enable blackbox-exporter && systemctl restart blackbox-exporter
systemctl enable cortex && systemctl restart cortex
systemctl enable loki && systemctl restart loki
systemctl enable crond && systemctl restart crond
systemctl enable rsyslog && systemctl restart rsyslog
echo 'install nz-agent success !'
fi
@@ -216,6 +313,8 @@ if [ 2 -eq $1 ];then
fn_init_blackbox_exporter_service
fn_init_cortex_service
fn_init_loki_service
fn_init_syslog_logrotate_config
# restore nz-agent config
AGENT_PATH=/opt/nezha/nz-agent
@@ -253,6 +352,8 @@ if [ 2 -eq $1 ];then
systemctl enable blackbox-exporter && systemctl restart blackbox-exporter
systemctl enable cortex && systemctl restart cortex
systemctl enable loki && systemctl restart loki
systemctl enable crond && systemctl restart crond
systemctl enable rsyslog && systemctl restart rsyslog
echo 'update nz-agent success !'
fi

View File

@@ -19,8 +19,11 @@ if [ 0 -eq $1 ];then
systemctl disable cortex.service
systemctl disable loki.service
rm -rf /usr/lib/systemd/system/{nz-agent.service,prometheus.service,snmp-exporter.service,blackbox-exporter.service,cortex.service,loki.service}
rm -rf /etc/rsyslog.d/{cortex.conf,loki.conf,prometheus.conf,snmp_exporter.conf,blackbox_exporter.conf}
rm -rf /etc/logrotate.d/{cortex,loki,prometheus,snmp_exporter,blackbox_exporter}
systemctl daemon-reload
systemctl restart rsyslog
echo 'uninstall success!'
fi