Bagaimana cara menginstal dan mengkonfigurasi Filebeat? Log Forwarder Ringan untuk Lingkungan Dev/Prod
Diterbitkan: 2020-05-03 Selama beberapa tahun terakhir, saya telah bermain dengan Filebeat
– ini adalah salah satu penerus log/data lightweight
terbaik untuk aplikasi produksi Anda.
Pertimbangkan skenario di mana Anda harus mentransfer log dari satu lokasi klien ke lokasi pusat untuk analisis. Splunk
adalah salah satu alternatif untuk meneruskan log tetapi terlalu mahal. Menurut saya itu terlalu mahal.
Di situlah Filebeat muncul. Ini sangat ringan, sederhana, mudah diatur, menggunakan lebih sedikit memori dan terlalu efisien. Filebeat adalah produk dari Elastic.co
.
Ini Kuat dan Tidak Melewatkan Ketukan. Ini guarantees delivery of logs
.
Ini siap untuk semua jenis wadah:
- Kubernetes
- Buruh pelabuhan
Dengan perintah satu baris sederhana, Filebeat menangani pengumpulan, penguraian, dan visualisasi log dari lingkungan mana pun di bawah ini:
- apache
- NGINX
- Sistem
- MySQL
- Apache2
- auditd
- pencarian elastis
- haproksi
- es
- IIS
- Iptables
- Kafka
- Kibana
- Logstash
- MongoDB
- Osquery
- PostgreSQL
- Redis
- Suricata
- Traefik
- Dan lebih…
Filebeat hadir dengan modul internal (auditd, Apache, NGINX, System, MySQL, dan lainnya) yang menyederhanakan pengumpulan, penguraian, dan visualisasi format log umum menjadi satu perintah.
Bagaimana Cara Menginstal Filebeat di Lingkungan Linux?
Jika Anda memiliki pertanyaan di bawah ini maka Anda berada di tempat yang tepat:
- Memulai Dengan Filebeat
- Tutorial Filebeat: Memulai
- Instal, Konfigurasi, dan Gunakan FileBeat – Elasticsearch
- Contoh pengaturan dan konfigurasi Filebeat
- Bagaimana Cara Menginstal Elasticsearch, Logstash?
- Bagaimana Cara Menginstal Elastis Stack di Ubuntu?
Langkah-1) Instalasi
Unduh dan ekstrak biner Filebeat menggunakan perintah di bawah ini.
lingkungan Linux:
1 2 3 4 5 6 |
root @ localhost : ~ # curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.7.0-linux-x86_64.tar.gz % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 11.1M 100 11.1M 0 0 13.2M 0 -- : -- : -- -- : -- : -- -- : -- : -- 13.2M root @ localhost : ~ # tar xzvf filebeat-6.7.0-linux-x86_64.tar.gz |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
root @ localhost : ~ # cd filebeat-6.7.0-linux-x86_64/ root @ localhost : ~ / filebeat - 6.7.0 - linux - x86_64 # pwd / root / filebeat - 6.7.0 - linux - x86_64 root @ localhost : ~ / filebeat - 6.7.0 - linux - x86_64 # ls -ltra total 36720 - rw - r -- r -- 1 root root 13675 Mar 21 14 : 30 LICENSE . txt - rw - r -- r -- 1 root root 163444 Mar 21 14 : 30 NOTICE . txt drwxr - xr - x 4 root root 4096 Mar 21 14 : 31 kibana drwxr - xr - x 2 root root 4096 Mar 21 14 : 33 modules . d drwxr - xr - x 21 root root 4096 Mar 21 14 : 33 module - rw - r -- r -- 1 root root 146747 Mar 21 14 : 33 fields . yml - rw ------- 1 root root 7714 Mar 21 14 : 33 filebeat . yml - rw - r -- r -- 1 root root 69996 Mar 21 14 : 33 filebeat . reference . yml - rwxr - xr - x 1 root root 37161549 Mar 21 14 : 34 filebeat - rw - r -- r -- 1 root root 802 Mar 21 14 : 35 README . md - rw - r -- r -- 1 root root 41 Mar 21 14 : 35 . build_hash . txt drwx ------ 9 root root 4096 Mar 30 13 : 46 . . drwxr - xr - x 5 root root 4096 Mar 30 13 : 46 . |
Unduh Mac:
1 2 |
curl - L - O https : //artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.7.0-darwin-x86_64.tar.gz tar xzvf filebeat - 6.7.0 - darwin - x86_64 . tar . gz |
Unduh RPM:
1 2 |
curl - L - O https : //artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.7.0-x86_64.rpm sudo rpm - vi filebeat - 6.7.0 - x86_64 . rpm |
Langkah-2) Konfigurasikan file konfigurasi filebeat.yml
Periksa filebeat.yml
file. Ini file konfigurasi filebeat.
Berikut adalah konten file sederhana.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
root @ localhost : ~ / filebeat - 6.7.0 - linux - x86_64 # cat filebeat.yml ###################### Filebeat Configuration Example ######################### # This file is an example configuration file highlighting only the most common # options. The filebeat.reference.yml file from the same directory contains all the # supported options with more comments. You can use it as a reference. # # You can find the full configuration reference here: # https://www.elastic.co/guide/en/beats/filebeat/index.html # For more available modules and options, please see the filebeat.reference.yml sample # configuration file. #=========================== Filebeat inputs ============================= filebeat . inputs : # Each - is an input. Most options can be set at the input level, so # you can use different inputs for various configurations. # Below are the input specific configurations. - type : log # Change to true to enable this input configuration. enabled : false # Paths that should be crawled and fetched. Glob based paths. paths : - / var / log /* . log #- c:\programdata\elasticsearch\logs\* # Exclude lines. A list of regular expressions to match. It drops the lines that are # matching any regular expression from the list. #exclude_lines: ['^DBG'] # Include lines. A list of regular expressions to match. It exports the lines that are # matching any regular expression from the list. #include_lines: ['^ERR', '^WARN'] # Exclude files. A list of regular expressions to match. Filebeat drops the files that # are matching any regular expression from the list. By default, no files are dropped. #exclude_files: ['.gz$'] # Optional additional fields. These fields can be freely picked # to add additional information to the crawled log files for filtering #fields: # level: debug # review: 1 ### Multiline options # Multiline can be used for log messages spanning multiple lines. This is common # for Java Stack Traces or C-Line Continuation # The regexp Pattern that has to be matched. The example pattern matches all lines starting with [ #multiline.pattern: ^\[ # Defines if the pattern set under pattern should be negated or not. Default is false. #multiline.negate: false # Match can be set to "after" or "before". It is used to define if lines should be append to a pattern # that was (not) matched before or after or as long as a pattern is not matched based on negate. # Note: After is the equivalent to previous and before is the equivalent to to next in Logstash #multiline.match: after #============================= Filebeat modules =============================== filebeat . config . modules : # Glob pattern for configuration loading path : $ { path . config } / modules . d /* . yml # Set to true to enable config reloading reload . enabled : false # Period on which files under path should be checked for changes #reload.period: 10s #==================== Elasticsearch template setting ========================== setup . template . settings : index . number_of_shards : 3 #index.codec: best_compression #_source.enabled: false #================================ General ===================================== # The name of the shipper that publishes the network data. It can be used to group # all the transactions sent by a single shipper in the web interface. #name: # The tags of the shipper are included in their own field with each # transaction published. #tags: ["service-X", "web-tier"] # Optional fields that you can specify to add additional information to the # output. #fields: # env: staging #============================== Dashboards ===================================== # These settings control loading the sample dashboards to the Kibana index. Loading # the dashboards is disabled by default and can be enabled either by setting the # options here, or by using the `-setup` CLI flag or the `setup` command. #setup.dashboards.enabled: false # The URL from where to download the dashboards archive. By default this URL # has a value which is computed based on the Beat name and version. For released # versions, this URL points to the dashboard archive on the artifacts.elastic.co # website. #setup.dashboards.url: #============================== Kibana ===================================== # Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API. # This requires a Kibana endpoint configuration. setup . kibana : # Kibana Host # Scheme and port can be left out and will be set to the default (http and 5601) # In case you specify and additional path, the scheme is required: http://localhost:5601/path # IPv6 addresses should always be defined as: https://[2001:db8::1]:5601 #host: "localhost:5601" # Kibana Space ID # ID of the Kibana Space into which the dashboards should be loaded. By default, # the Default Space will be used. #space.id: #============================= Elastic Cloud ================================== # These settings simplify using filebeat with the Elastic Cloud (https://cloud.elastic.co/). # The cloud.id setting overwrites the `output.elasticsearch.hosts` and # `setup.kibana.host` options. # You can find the `cloud.id` in the Elastic Cloud web UI. #cloud.id: # The cloud.auth setting overwrites the `output.elasticsearch.username` and # `output.elasticsearch.password` settings. The format is `<user>:<pass>`. #cloud.auth: #================================ Outputs ===================================== # Configure what output to use when sending the data collected by the beat. #-------------------------- Elasticsearch output ------------------------------ output . elasticsearch : # Array of hosts to connect to. hosts : [ "localhost:9200" ] # Enabled ilm (beta) to use index lifecycle management instead daily indices. #ilm.enabled: false # Optional protocol and basic auth credentials. #protocol: "https" #username: "elastic" #password: "changeme" #----------------------------- Logstash output -------------------------------- #output.logstash: # The Logstash hosts #hosts: ["localhost:5044"] # Optional SSL. By default is off. # List of root certificates for HTTPS server verifications #ssl.certificate_authorities: ["/etc/pki/root/ca.pem"] # Certificate for SSL client authentication #ssl.certificate: "/etc/pki/client/cert.pem" # Client Certificate Key #ssl.key: "/etc/pki/client/cert.key" #================================ Processors ===================================== # Configure processors to enhance or manipulate events generated by the beat. processors : - add_host_metadata : ~ - add_cloud_metadata : ~ #================================ Logging ===================================== # Sets log level. The default log level is info. # Available log levels are: error, warning, info, debug #logging.level: debug # At debug level, you can selectively enable logging only for some components. # To enable all selectors use ["*"]. Examples of other selectors are "beat", # "publish", "service". #logging.selectors: ["*"] #============================== Xpack Monitoring =============================== # filebeat can export internal metrics to a central Elasticsearch monitoring # cluster. This requires xpack monitoring to be enabled in Elasticsearch. The # reporting is disabled by default. # Set to true to enable the monitoring reporter. #xpack.monitoring.enabled: false # Uncomment to send the metrics to Elasticsearch. Most settings from the # Elasticsearch output are accepted here as well. Any setting that is not set is # automatically inherited from the Elasticsearch output configuration, so if you # have the Elasticsearch output configured, you can simply uncomment the # following line. #xpack.monitoring.elasticsearch: |

Buka file filebeat.yml dan atur lokasi file log Anda:
Langkah-3) Kirim log ke ElasticSearch
Pastikan Anda telah memulai ElasticSearch
secara lokal sebelum menjalankan Filebeat. Saya akan menerbitkan artikel hari ini tentang how to install and run ElasticSearch
secara lokal dengan langkah-langkah sederhana.
Berikut adalah konfigurasi file filebeat.yml untuk ElasticSearch.
ElasticSearch berjalan pada port 9200.
1 2 3 |
output . elasticsearch : # Array of hosts to connect to. hosts : [ "localhost:9200" ] |
Dan Anda sudah siap.
Langkah-4) Jalankan Filebeat
1 2 |
bash - 3.2 $ sudo chown root filebeat . yml bash - 3.2 $ sudo . / filebeat - e |
Jalankan dua perintah di atas dari direktori root filebeat dan Anda akan melihat log startup filebeat seperti di bawah ini.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
root @ localhost : / user / crunchify / filebeat - 6.6.2 - linux - x86_64 # sudo chown root filebeat.yml root @ localhost : / user / crunchify / filebeat - 6.6.2 - linux - x86_64 # sudo ./filebeat -e 2019 - 03 - 30T14 : 52 : 02.608Z INFO instance / beat . go : 616 Home path : [ / user / crunchify / filebeat - 6.6.2 - linux - x86_64 ] Config path : [ / user / crunchify / filebeat - 6.6.2 - linux - x86_64 ] Data path : [ / user / crunchify / filebeat - 6.6.2 - linux - x86_64 / data ] Logs path : [ / user / crunchify / filebeat - 6.6.2 - linux - x86_64 / logs ] 2019 - 03 - 30T14 : 52 : 02.608Z INFO instance / beat . go : 623 Beat UUID : da7e202d - d480 - 42df - 907a - 1073b19c8e2d 2019 - 03 - 30T14 : 52 : 02.609Z INFO [ seccomp ] seccomp / seccomp . go : 116 Syscall filter successfully installed 2019 - 03 - 30T14 : 52 : 02.609Z INFO [ beat ] instance / beat . go : 936 Beat info { "system_info" : { "beat" : { "path" : { "config" : "/user/crunchify/filebeat-6.6.2-linux-x86_64" , "data" : "/user/crunchify/filebeat-6.6.2-linux-x86_64/data" , "home" : "/user/crunchify/filebeat-6.6.2-linux-x86_64" , "logs" : "/user/crunchify/filebeat-6.6.2-linux-x86_64/logs" } , "type" : "filebeat" , "uuid" : "da7e202d-d480-42df-907a-1073b19c8e2d" } } } 2019 - 03 - 30T14 : 52 : 02.609Z INFO [ beat ] instance / beat . go : 945 Build info { "system_info" : { "build" : { "commit" : "1eea934ce81be553337f2828bd12131896fea8e4" , "libbeat" : "6.6.2" , "time" : "2019-03-06T14:17:59.000Z" , "version" : "6.6.2" } } } 2019 - 03 - 30T14 : 52 : 02.609Z INFO [ beat ] instance / beat . go : 948 Go runtime info { "system_info" : { "go" : { "os" : "linux" , "arch" : "amd64" , "max_procs" : 2 , "version" : "go1.10.8" } } } 2019 - 03 - 30T14 : 52 : 02.611Z INFO [ beat ] instance / beat . go : 952 Host info { "system_info" : { "host" : { "architecture" : "x86_64" , "boot_time" : "2019-01-15T18:44:58Z" , "containerized" : false , "name" : "localhost" , "ip" : [ "127.0.0.1/8" , "::1/128" , "50.116.13.161/24" , "192.168.177.126/17" , "2600:3c01::f03c:91ff:fe17:4534/64" , "fe80::f03c:91ff:fe17:4534/64" ] , "kernel_version" : "4.18.0-13-generic" , "mac" : [ "f2:3c:91:17:45:34" ] , "os" : { "family" : "debian" , "platform" : "ubuntu" , "name" : "Ubuntu" , "version" : "18.10 (Cosmic Cuttlefish)" , "major" : 18 , "minor" : 10 , "patch" : 0 , "codename" : "cosmic" } , "timezone" : "UTC" , "timezone_offset_sec" : 0 , "id" : "1182104d1089460dbcc0c94ff1954c8c" } } } 2019 - 03 - 30T14 : 52 : 02.611Z INFO [ beat ] instance / beat . go : 981 Process info { "system_info" : { "process" : { "capabilities" : { "inheritable" : null , "permitted" : [ "chown" , "dac_override" , "dac_read_search" , "fowner" , "fsetid" , "kill" , "setgid" , "setuid" , "setpcap" , "linux_immutable" , "net_bind_service" , "net_broadcast" , "net_admin" , "net_raw" , "ipc_lock" , "ipc_owner" , "sys_module" , "sys_rawio" , "sys_chroot" , "sys_ptrace" , "sys_pacct" , "sys_admin" , "sys_boot" , "sys_nice" , "sys_resource" , "sys_time" , "sys_tty_config" , "mknod" , "lease" , "audit_write" , "audit_control" , "setfcap" , "mac_override" , "mac_admin" , "syslog" , "wake_alarm" , "block_suspend" , "audit_read" ] , "effective" : [ "chown" , "dac_override" , "dac_read_search" , "fowner" , "fsetid" , "kill" , "setgid" , "setuid" , "setpcap" , "linux_immutable" , "net_bind_service" , "net_broadcast" , "net_admin" , "net_raw" , "ipc_lock" , "ipc_owner" , "sys_module" , "sys_rawio" , "sys_chroot" , "sys_ptrace" , "sys_pacct" , "sys_admin" , "sys_boot" , "sys_nice" , "sys_resource" , "sys_time" , "sys_tty_config" , "mknod" , "lease" , "audit_write" , "audit_control" , "setfcap" , "mac_override" , "mac_admin" , "syslog" , "wake_alarm" , "block_suspend" , "audit_read" ] , "bounding" : [ "chown" , "dac_override" , "dac_read_search" , "fowner" , "fsetid" , "kill" , "setgid" , "setuid" , "setpcap" , "linux_immutable" , "net_bind_service" , "net_broadcast" , "net_admin" , "net_raw" , "ipc_lock" , "ipc_owner" , "sys_module" , "sys_rawio" , "sys_chroot" , "sys_ptrace" , "sys_pacct" , "sys_admin" , "sys_boot" , "sys_nice" , "sys_resource" , "sys_time" , "sys_tty_config" , "mknod" , "lease" , "audit_write" , "audit_control" , "setfcap" , "mac_override" , "mac_admin" , "syslog" , "wake_alarm" , "block_suspend" , "audit_read" ] , "ambient" : null } , "cwd" : "/user/crunchify/filebeat-6.6.2-linux-x86_64" , "exe" : "/user/crunchify/filebeat-6.6.2-linux-x86_64/filebeat" , "name" : "filebeat" , "pid" : 20394 , "ppid" : 20393 , "seccomp" : { "mode" : "filter" , "no_new_privs" : true } , "start_time" : "2019-03-30T14:52:01.740Z" } } } 2019 - 03 - 30T14 : 52 : 02.611Z INFO instance / beat . go : 281 Setup Beat : filebeat ; Version : 6.6.2 2019 - 03 - 30T14 : 52 : 05.613Z INFO add_cloud_metadata / add_cloud_metadata . go : 319 add_cloud_metadata : hosting provider type not detected . 2019 - 03 - 30T14 : 52 : 05.614Z INFO elasticsearch / client . go : 165 Elasticsearch url : http : //localhost:9200 2019 - 03 - 30T14 : 52 : 05.615Z INFO [ publisher ] pipeline / module . go : 110 Beat name : localhost 2019 - 03 - 30T14 : 52 : 05.615Z INFO instance / beat . go : 403 filebeat start running . 2019 - 03 - 30T14 : 52 : 05.615Z INFO registrar / registrar . go : 134 Loading registrar data from / user / crunchify / filebeat - 6.6.2 - linux - x86_64 / data / registry 2019 - 03 - 30T14 : 52 : 05.615Z INFO [ monitoring ] log / log . go : 117 Starting metrics logging every 30s 2019 - 03 - 30T14 : 52 : 05.616Z INFO registrar / registrar . go : 141 States Loaded from registrar : 0 2019 - 03 - 30T14 : 52 : 05.616Z INFO crawler / crawler . go : 72 Loading Inputs : 1 2019 - 03 - 30T14 : 52 : 05.616Z INFO log / input . go : 138 Configured paths : [ / crunchify / tutorials / log / crunchify - filebeat - test . log ] 2019 - 03 - 30T14 : 52 : 05.616Z INFO input / input . go : 114 Starting input of type : log ; ID : 7740765267175828127 2019 - 03 - 30T14 : 52 : 05.617Z INFO crawler / crawler . go : 106 Loading and starting Inputs completed . Enabled inputs : 1 2019 - 03 - 30T14 : 52 : 05.617Z INFO cfgfile / reload . go : 150 Config reloader started 2019 - 03 - 30T14 : 52 : 05.617Z INFO cfgfile / reload . go : 205 Loading of config files completed . |
Langkah-5) Hasil
Langkah selanjutnya adalah Anda memeriksa siapa yang masuk ke Pencarian Elastis dan bagaimana Anda memvisualisasikannya. Kami akan membahas tutorial terperinci tentang itu segera. Pantau terus.
Apa berikutnya? Siapkan Pencarian Elastis
Bagaimana Cara Menginstal dan Mengonfigurasi Elasticsearch di lingkungan Dev/Produksi Anda?