Skip to content

Commit

Permalink
fix : filebeat 재설치 및 재실행 스크립트 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
java-saeng committed Jul 18, 2023
1 parent ce295d7 commit 6e19570
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions backend/.ebextensions/02-set-filebeat.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
"content": "#!/bin/bash\nPASSWORD=$(sudo /opt/elasticbeanstalk/bin/get-config environment -k ELASTICSEARCH_PASSWORD)\nHOST=$(sudo /opt/elasticbeanstalk/bin/get-config environment -k ELASTICSEARCH_HOST)\nPORT=$(sudo /opt/elasticbeanstalk/bin/get-config environment -k ELASTICSEARCH_PORT)\nUSER=$(sudo /opt/elasticbeanstalk/bin/get-config environment -k ELASTICSEARCH_USER)\ncat > /home/ec2-user/filebeat-7.14.1-linux-x86_64/filebeat.yml <<EOF\nfilebeat.inputs:\n- type: log\n enabled: true\n paths:\n - /var/app/current/logs/info/info.log\n - /var/app/current/logs/error/error.log\n - /var/app/current/logs/warn/*.log\n fields:\n log_type: legacy-log\n- type: log\n enabled: true\n paths:\n - /var/log/nginx/access.log\n fields:\n log_type: access-log\noutput.elasticsearch:\n hosts: [\"$HOST:$PORT\"]\n username: \"$USER\"\n password: \"$PASSWORD\"\n indices:\n - index: \"filebeat-%{[agent.version]}-access-log\"\n when.equals:\n fields.log_type: \"access-log\"\n - index: \"filebeat-%{[agent.version]}-legacy-log\"\n when.equals:\n fields.log_type: \"legacy-log\"\nEOF"
},
"/tmp/install_filebeat.sh": {
"mode": "000755",
"content": "#!/bin/bash\nFILEBEAT_DIRECTORY=\"/home/ec2-user/filebeat-7.14.1-linux-x86_64\"\nif [ ! -d \"$FILEBEAT_DIRECTORY\" ]; then\n wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.14.1-linux-x86_64.tar.gz\n tar xzvf filebeat-7.14.1-linux-x86_64.tar.gz\nelse\n echo \"Filebeat already installed.\"\nfi"
},
"/tmp/restart_filebeat.sh": {
"mode": "000755",
"content": "wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.14.1-linux-x86_64.tar.gz\ntar xzvf filebeat-7.14.1-linux-x86_64.tar.gz"
"content": "#!/bin/bash\n\nPID=$(ps -ef | grep filebeat | grep -v grep | awk '{print $2}')\n\nif [[ -n \"$PID\" ]]; then\n echo \"Filebeat PID : $PID\"\n kill -9 $PID\nelse\n echo \"Filebeat is not running.\"\nfi\n\necho \"Restarting Filebeat\"\ncd filebeat-7.14.1-linux-x86_64 && nohup ./filebeat -e &\n\necho \"Filebeat restarted\""
}
},
"commands": {
Expand All @@ -17,7 +21,7 @@
"command": "bash /tmp/make_filebeat_yml.sh"
},
"03_run_filebeat": {
"command": "cd filebeat-7.14.1-linux-x86_64 && ./filebeat -e"
"command": "bash /tmp/restart_filebeat.sh"
}
}
}

0 comments on commit 6e19570

Please sign in to comment.