Advertisement
thanh_thu

Install_ELK_Beats

Jul 21st, 2019
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Đọc 1 lượt
  2. - Cài theo các bước: https://blog.cloud365.vn/logging/ELK-part2-Cai-dat-ELK-stack/
  3. * Lưu ý thay đổi nội dung của filebeat.yml
  4. - Cấu hình logstash input, output theo hướng dẫn trong https://blog.cloud365.vn/logging/ELK-part-5-Tim-hieu-ve-filebeats/
  5. * lưu ý cấu hình filebeat đang bị sai
  6. Cấu hình filebeat cho log tại : https://pastebin.com/wLUpjUwB
  7.  
  8.  
  9. - Sau khi kiểm tra các service status OK --> vào kibana tạo index pattern: Index pattern là gì?
  10. Có thể để ý thấy khi logstash forward sang cho elasticsearch sẽ có index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"
  11. Đây chính là pattern chung "[@metadata][beat]" -> vào kibana tạo index pattern là giá trị của [@metadata][beat], trường hợp này là "filebeat", tham số thời gian có thể thay đổi --> index pattern là : "filebeat-*" -> next step
  12. - Khi này đã có thể discover các event
  13.  
  14.  
  15. - Tuy nhiên để visualize được thì cần có các trường giá trị phù hợp -> cần parse đúng cách:
  16. Đối với cách nhận toàn bộ các field giá trị như /var/log/*.log chỉ phù hợp cho nhận log Ubuntu, centos thì system log ở vị trí khác. Theo dõi blog này : https://burnhamforensics.com/2019/03/12/monitoring-centos-endpoints-with-filebeat-elk/
  17. Để bật system log cho hệ điều hành: khôi phục filebeat.yml mặc định
  18. filebeat modules enable system
  19.  
  20. Sau đó cấu hình lại logstash để filter ra các field mong muốn như trong: https://burnhamforensics.com/2019/03/12/monitoring-centos-endpoints-with-filebeat-elk/
  21.  
  22. Muốn tạo dashboard -> vào client có filebeat agent: gõ lệnh "filebeat setup --dashboards". DONE
  23.  
  24.  
  25. Ví dụ đã setup: http://139.180.137.217:5601/app/kibana#/dashboard/5517a150-f9ce-11e6-8115-a7c18106d86a
  26.  
  27.  
  28.  
  29. ---- /etc/logstash/conf.d/02-logstash.conf
  30. filter {
  31. if [fileset][module] == "system" {
  32. if [fileset][name] == "secure" {
  33. grok {
  34. match => { "message" => ["%{SYSLOGTIMESTAMP:[system][auth][timestamp]} %{SYSLOGHOST:[system][auth][hostname]} sshd(?:\[%{POSINT:[system][auth][pid]}\])?: %{DATA:[system][auth][ssh][event]} %{DATA:[system][auth][ssh][method]} for (invalid user )?%{DATA:[system][auth][user]} from %{IPORHOST:[system][auth][ssh][ip]} port %{NUMBER:[system][auth][ssh][port]} ssh2(: %{GREEDYDATA:[system][auth][ssh][signature]})?",
  35. "%{SYSLOGTIMESTAMP:[system][auth][timestamp]} %{SYSLOGHOST:[system][auth][hostname]} sshd(?:\[%{POSINT:[system][auth][pid]}\])?: %{DATA:[system][auth][ssh][event]} user %{DATA:[system][auth][user]} from %{IPORHOST:[system][auth][ssh][ip]}",
  36. "%{SYSLOGTIMESTAMP:[system][auth][timestamp]} %{SYSLOGHOST:[system][auth][hostname]} sshd(?:\[%{POSINT:[system][auth][pid]}\])?: Did not receive identification string from %{IPORHOST:[system][auth][ssh][dropped_ip]}",
  37. "%{SYSLOGTIMESTAMP:[system][auth][timestamp]} %{SYSLOGHOST:[system][auth][hostname]} sudo(?:\[%{POSINT:[system][auth][pid]}\])?: \s*%{DATA:[system][auth][user]} <img draggable="false" class="emoji" alt="~_~X" src="https://s0.wp.com/wp-content/mm
  38. u-plugins/wpcom-smileys/twemoji/2/svg/1f626.svg"> %{DATA:[system][auth][sudo][error]} ;)? TTY=%{DATA:[system][auth][sudo][tty]} ; PWD=%{DATA:[system][auth][sudo][pwd]} ; USER=%{DATA:[system][auth][sudo][user]} ; COMMAND=%{GREEDYDATA:[system][auth][sudo][command]}",
  39. "%{SYSLOGTIMESTAMP:[system][auth][timestamp]} %{SYSLOGHOST:[system][auth][hostname]} groupadd(?:\[%{POSINT:[system][auth][pid]}\])?: new group: name=%{DATA:system.auth.groupadd.name}, GID=%{NUMBER:system.auth.groupadd.gid}",
  40. "%{SYSLOGTIMESTAMP:[system][auth][timestamp]} %{SYSLOGHOST:[system][auth][hostname]} useradd(?:\[%{POSINT:[system][auth][pid]}\])?: new user: name=%{DATA:[system][auth][user][add][name]}, UID=%{NUMBER:[system][auth][user][add][uid]}, GID=%{NUMBER:[system][auth][user][add][gid]}, home=%{DATA:[system][auth][user][add][home]}, shell=%{DATA:[system][auth][user][add][shell]}$",
  41. "%{SYSLOGTIMESTAMP:[system][auth][timestamp]} %{SYSLOGHOST:[system][auth][hostname]} %{DATA:[system][auth][program]}(?:\[%{POSINT:[system][auth][pid]}\])?: %{GREEDYMULTILINE:[system][auth][message]}"] }
  42. pattern_definitions => {
  43. "GREEDYMULTILINE"=> "(.|\n)*"
  44. }
  45. remove_field => "message"
  46. }
  47. date {
  48. match => [ "[system][auth][timestamp]", "MMM d HH:mm:ss", "MMM dd HH:mm:ss" ]
  49. }
  50. geoip {
  51. source => "[system][auth][ssh][ip]"
  52. target => "[system][auth][ssh][geoip]"
  53. }
  54. }
  55. else if [fileset][name] == "syslog" {
  56. grok {
  57. match => { "message" => ["%{SYSLOGTIMESTAMP:[system][syslog][timestamp]} %{SYSLOGHOST:[system][syslog][hostname]} %{DATA:[system][syslog][program]}(?:\[%{POSINT:[system][syslog][pid]}\])?: %{GREEDYMULTILINE:[system][syslog][message]}"] }
  58. pattern_definitions => { "GREEDYMULTILINE" => "(.|\n)*" }
  59. remove_field => "message"
  60. }
  61. date {
  62. match => [ "[system][syslog][timestamp]", "MMM d HH:mm:ss", "MMM dd HH:mm:ss" ]
  63. }
  64. }
  65. }
  66. }
  67.  
  68.  
  69. input {
  70. beats {
  71. port => 5044
  72. ssl => false
  73. }
  74. }
  75.  
  76. output {
  77. elasticsearch {
  78. hosts => ["localhost:9200"]
  79. sniffing => true
  80. index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement