Linux日志對接Kibana如何進(jìn)行配置與部署

本篇內(nèi)容主要講解“Linux日志對接Kibana如何進(jìn)行配置與部署”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“Linux日志對接Kibana如何進(jìn)行配置與部署”吧!

本篇內(nèi)容主要講解“Linux日志對接Kibana如何進(jìn)行配置與部署”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“Linux日志對接Kibana如何進(jìn)行配置與部署”吧!一,準(zhǔn)備工作

1,CVM及ElasticSearch

五通橋ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書合作)期待與您的合作!

在騰訊云帳號下,申請一臺CVM(Linux操作系統(tǒng))、一個ElasticSearch集群(后面簡稱ES),使用最簡配置即可;申請的CVM和ES,必須在同一個VPC的同一個子網(wǎng)下。

CVM詳情信息

ElasticSearch詳情信息

2,F(xiàn)ilebeat工具

為了將Linux日志提取到ES中,我們需要使用Filebeat工具。Filebeat是一個日志文件托運(yùn)工具,在你的上安裝客戶端后,F(xiàn)ilebeat會監(jiān)控日志目錄或者指定的日志文件,追蹤讀取這些文件(追蹤文件的變化,不停的讀),并且轉(zhuǎn)發(fā)這些信息到ElasticSearch或者logstarsh中存放。當(dāng)你開啟Filebeat程序的時候,它會啟動一個或多個探測器(prospectors)去檢測你指定的日志目錄或文件,對于探測器找出的每一個日志文件,F(xiàn)ilebeat啟動收割進(jìn)程(harvester),每一個收割進(jìn)程讀取一個日志文件的新內(nèi)容,并發(fā)送這些新的日志數(shù)據(jù)到處理程序(spooler),處理程序會集合這些事件,最后Filebeat會發(fā)送集合的數(shù)據(jù)到你指定的地點(diǎn)。

官網(wǎng)簡介:https://www.elastic.co/products/beats/filebeat二,操作步驟

1,F(xiàn)ilebeat下載與安裝

首先,登錄待接管日志的CVM,在CVM上下載Filebeat工具:

[root@VM_3_7_centos ~]# cd /opt/[root@VM_3_7_centos opt]# lltotal 4drwxr-xr-x. 2 root root 4096 Sep  7  2017 rh[root@VM_3_7_centos opt]# wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.2.2-x86_64.rpm--2018-12-10 20:24:26--  https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.2.2-x86_64.rpmResolving artifacts.elastic.co (artifacts.elastic.co)... 107.21.202.15, 107.21.127.184, 54.225.214.74, ...Connecting to artifacts.elastic.co (artifacts.elastic.co)|107.21.202.15|:443... connected.HTTP request sent, awaiting response... 200 OKLength: 12697788 (12M) [binary/octet-stream]Saving to: ‘filebeat-6.2.2-x86_64.rpm’100%[=================================================================================================>] 12,697,788   160KB/s   in 1m 41s 2018-12-10 20:26:08 (123 KB/s) - ‘filebeat-6.2.2-x86_64.rpm’ saved [12697788/12697788]

然后,進(jìn)行安裝filebeat:

[root@VM_3_7_centos opt]# rpm -vi filebeat-6.2.2-x86_64.rpmwarning: filebeat-6.2.2-x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID d88e42b4: NOKEYPreparing packages...filebeat-6.2.2-1.x86_64[root@VM_3_7_centos opt]#

至此,F(xiàn)ilebeat安裝完成。

2,F(xiàn)ilebeat配置

進(jìn)入Filebeat配置文件目錄:/etc/filebeat/

[root@VM_3_7_centos opt]# cd /etc/filebeat/[root@VM_3_7_centos filebeat]# lltotal 108-rw-r--r-- 1 root root 44384 Feb 17  2018 fields.yml-rw-r----- 1 root root 52193 Feb 17  2018 filebeat.reference.yml-rw------- 1 root root  7264 Feb 17  2018 filebeat.ymldrwxr-xr-x 2 root root  4096 Dec 10 20:35 modules.d[root@VM_3_7_centos filebeat]#

其中,filebeat.yml就是我們需要修改的配置文件。建議修改配置前,先備份此文件。然后,確認(rèn)需要對接ElasticSearch的Linux的日志目錄,我們以下圖(/var/log/secure

)為例。

/var/log/secure日志文件

使用vim打開/etc/filebeat/filebeat.yml文件,修改其中的:1)Filebeat prospectors類目中,enable默認(rèn)為false,我們要改為

true2)paths,默認(rèn)為/var/log/*.log,我們要改為待接管的日志路徑:

/var/log/secure

3)Outputs類目中,有ElasticSearchoutput配置,其中hosts默認(rèn)為"localhost:9200",需要我們手工修改為上面申請的ES子網(wǎng)地址和端口,即**"10.0.3.8:9200"**。

修改好上述內(nèi)容后,保存退出。

修改好的配置文件全文如下:

[root@VM_3_7_centos /]# vim /etc/filebeat/filebeat.yml[root@VM_3_7_centos /]# cat /etc/filebeat/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 prospectors =============================filebeat.prospectors:# Each - is a prospector. Most options can be set at the prospector level, so# you can use different prospectors for various configurations.# Below are the prospector specific configurations.- type: log  # Change to true to enable this prospector configuration.  enabled: true  # Paths that should be crawled and fetched. Glob based paths.  paths:    - /var/log/secure    #- 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  # Mutiline 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"#============================= 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: ["10.0.3.8:9200"]  # 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"#================================ 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:[root@VM_3_7_centos /]#

執(zhí)行下列命令啟動filebeat[root@VM_3_7_centos /]# sudo /etc/init.d/filebeat startStarting filebeat (via systemctl):                         [  OK  ][root@VM_3_7_centos /]#

3,Kibana配置

進(jìn)入ElasticSearch對應(yīng)的Kibana管理頁,如下圖。

首次訪問Kibana默認(rèn)會顯示管理頁

首次登陸,會默認(rèn)進(jìn)入Management頁面,我們需要將Index pattern內(nèi)容修改為:filebeat-*,然后頁面會自動填充**Time Filter field name,**不需手動設(shè)置,直接點(diǎn)擊Create即可。點(diǎn)擊Create后,頁面需要一定時間來加載配置和數(shù)據(jù),請稍等。如下圖:

將Index pattern內(nèi)容修改為:filebeat-*,然后點(diǎn)擊Create

至此,CVM上,/var/log/secure日志文件,已對接到ElasticSearch中,歷史日志可以通過Kibana進(jìn)行查詢,最新產(chǎn)生的日志也會實(shí)時同步到Kibana中。

三,實(shí)戰(zhàn)效果

日志接管已完成配置,如何使用呢?

如下圖:

在Index Patterns中可以看到我們配置過的filebeat-*

點(diǎn)擊Discover,即可看到secure中的所有日志,頁面上方的搜索框中輸入關(guān)鍵字,即可完成日志的檢索。如下圖(點(diǎn)擊圖片,可查看高清大圖):

使用Kibana進(jìn)行日志檢索

實(shí)際上,檢索只是Kibana提供的諸多功能之一,還有其他功能如可視化、分詞檢索等,還有待后續(xù)研究。

網(wǎng)站標(biāo)題:Linux日志對接Kibana如何進(jìn)行配置與部署
網(wǎng)站網(wǎng)址:http://muchs.cn/article44/dejgee.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動網(wǎng)站建設(shè)、服務(wù)器托管、外貿(mào)網(wǎng)站建設(shè)、關(guān)鍵詞優(yōu)化、網(wǎng)站維護(hù)品牌網(wǎng)站設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化