初始化安装filebeat

2024-05-16 11:41:59 浏览数 (2)

代码语言:txt复制
#!/bin/bash

###
command(){
cat >> /etc/profile  << 'EOF'
HISTDIR='/var/log/command.log'
# 定义Command日志的格式
export HISTTIMEFORMAT="{"TIME":"%F %T","LI":"$(who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g')","LU":"$(who am i|awk '{print $1}')","CMD":""
# 输出日志到指定的log文件
export PROMPT_COMMAND='history 1|tail -1|sed "s/^[ ] [0-9]  //"|sed "s/$/"}/">> /var/log/command.log'
EOF
    #引用
    source /etc/profile
}
command
#cat /etc/profile | grep HISTTIMEFORMAT | grep -v grep 
#if [[ $? == 0 ]];
#  then
#    echo "command已设置"
#  else
#    command
#fi

ps -ef | grep /usr/local/filebeat | grep -v grep 
if [[ $? == 0 ]];
  then
    echo "filebeat已经安装完毕"
  else
    #下载安装包
    touch /var/log/command.log
    chmod 666 /var/log/command.log
    wget http://yum-server.4paradigm.com/system/files/filebeat-7.17.16-linux-x86_64.tar.gz -O /root/filebeat-7.17.16-linux-x86_64.tar.gz
    tar xf /root/filebeat-7.17.16-linux-x86_64.tar.gz -C /usr/local/
    mv /usr/local/filebeat-7.17.16-linux-x86_64 /usr/local/filebeat
    mv /usr/local/filebeat/filebeat.yml /usr/local/filebeat/filebeat.yml.bak
    wget -P /usr/local/filebeat http://yum-server.4paradigm.com/system/files/filebeat.yml
    chmod 644 /usr/local/filebeat/filebeat.yml
    wget -P /usr/lib/systemd/system/ http://yum-server.4paradigm.com/system/files/filebeat.service
    rm -f /root/filebeat-7.17.16-linux-x86_64.tar.gz
    systemctl daemon-reload
    systemctl start filebeat
    systemctl status filebeat
    systemctl enable filebeat
    source /root/.bashrc
fi
#
if [ -f "tools-filebeat.sh" ]; then
  echo "tools-filebeat.sh存在"
  rm -f tools-filebeat.sh
else
  echo "文件不存在"
fi 

0 人点赞