ELKF (Elasticsearch+Logstash+Kibana+Filebeat) は複数のマシンに Filebeat をデプロイします

ELKF 展開構造
ここに画像の説明を挿入

1. Elasticsearchをインストールして設定する

1.1. インストール パッケージをインストール パスに解凍します。

たとえば、/usr/local/elkの下にあります。

tar -zxvf elasticsearch-6.3.0-linux-x86_64.tar.gz -C /usr/local/elk/
或者直接解压
tar -zxvf elasticsearch-6.3.0-linux-x86_64.tar.gz 

1.2 設定ファイルを変更する

vi  /usr/local/elk/elasticsearch-6.3.0/config/elasticsearch.yml
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /data/elasticsearch/data
#
# Path to log files:
#
path.logs: /data/elasticsearch/logs
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0           ##服务器ip 本机
#
# Set a custom port for HTTP:
#
http.port: 9200                 ##服务端口
#
# For more information, consult the network module documentation.

ディレクトリ/data/elasticsearch/dataおよび/data/elasticsearch/logs は独自に作成する必要があります

1.3 システム制限設定ファイルの変更

1.3.1 sysctl.conf ファイルを変更する

vim /etc/sysctl.conf
在文件后面加入   vm.max_map_count = 655360

ここに画像の説明を挿入
設定をリロードする

sysctl -p /etc/sysctl.conf

1.3.2limits.confファイルを変更する

vim /etc/security/limits.conf

ファイルの最後に以下を追加します

#<domain>      <type>  <item>         <value>
#

#*               soft    core            0
#*               hard    rss             10000
#@student        hard    nproc           20
#@faculty        soft    nproc           20
#@faculty        hard    nproc           50
#ftp             hard    nproc           0
#@student        -       maxlogins       4

# End of file

* soft nofile 65536
* hard nofile 131072
* soft nproc  65536
* hard nproc  131072

1.3.3 ユーザーリソースパラメータの設定

vim /etc/security/limits.d/20-nproc.conf

次の内容を追加します

es_user  soft  nproc   65536

1.3 エラスティックサーチを開始する

/data/elasticsearch/ このディレクトリは、構成ファイル elasticsearch.yml で構成されます。

Elastic Searchの起動に注意 ESの起動はrootアカウントでは直接起動できないため、新規ユーザーを作成し、新規ユーザーに切り替えて起動する必要があります 実行コマンドは以下の通りです。

-- 创建新用户及授权
 useradd  es_user
 groupadd esgroup
 chown -R es_user:esgroup elasticsearch-6.3.0
 chown -R es_user:esgroup /data/elasticsearch/
-- 切换用户,启动
 su es_user
 cd elasticsearch-6.3.0/bin
=======================================================
-- 两种方式启动
/usr/local/elk/elasticsearch-6.3.0/bin/elasticsearch   #命令窗运行
/usr/local/elk/elasticsearch-6.3.0/bin/elasticsearch  -d  #后台线程运行
=======================================================================
-- 对应关闭命令
ctrl+c              #命令窗关闭                     

ps -ef | grep elastic                    #后台线程关闭
kill -9 [pid]                             ##pid为查处线程的pid

一般的な問題の解決elasticsearch 起動時の一般的な問題

2. Logstash をインストールして設定する

2.1 ファイルを解凍する

tar -zvxf /usr/local/elk/logstash-7.2.0.tar.gz -C /usr/local/elk/
或者
tar -zvxf /usr/local/elk/logstash-7.2.0.tar.gz

2.2 新しいログ ファイルを作成する

mkdir   /usr/local/elk/logstash/logs

2.3 logstash.conf ファイルを変更する

cd config
--新建 flexcc-logstash.conf 文件
touch flexcc-logstash.conf

次のコンテンツを追加します

PS: localhsot は、Elasticsearch がインストールされているサーバー アドレスに変更する必要があります。

input {
    
    
    beats {
    
    
        port => 18401 #filebeat端口
    }
}


filter {
    
    

    if [fields][log-source] == "callin-server" {
    
    
                json {
    
    
            source => "message"
            #target => "doc"
            #remove_field => ["message"]
                }
        }

        if [fields][log-source] == "callout-server" {
    
    
                json {
    
    
            source => "message"
            #target => "doc"
            #remove_field => ["message"]
                }
        }

        if [fields][log-source] == "sysmanager-server" {
    
    
                json {
    
    
            source => "message"
            #target => "doc"
            #remove_field => ["message"]
                }
        }

        if [fields][log-source] == "report-server" {
    
    
                json {
    
    
            source => "message"
            #target => "doc"
            #remove_field => ["message"]
                }
        }
 
output {
    
    

        if [fields][log-source] == "callin-server" {
    
    
          elasticsearch {
    
    
               hosts => ["localhsot:18200"]
               index => "rpc-callin-%{+YYYY.MM.dd}"
               user => admin
               password => admin
          }
    }

        if [fields][log-source] == "callout-server" {
    
    
          elasticsearch {
    
    
               hosts => ["localhost:18200"]
               index => "rpc-callout-%{+YYYY.MM.dd}"
               user => admin
               password => admin
          }
    }

        if [fields][log-source] == "sysmanager-server" {
    
    
          elasticsearch {
    
    
               hosts => ["localhost:18200"]
               index => "rpc-sys-%{+YYYY.MM.dd}"
               user => admin
               password => admin
          }
    }


        if [fields][log-source] == "report-server" {
    
    
          elasticsearch {
    
    
               hosts => ["localhost:18200"]
               index => "rpc-report-%{+YYYY.MM.dd}"
               user => admin
               password => admin
          }
    }
}
}

2.4 logstash.sh ファイルを変更する

cd  /usr/local/elk/logstash-6.3.1/bin
touch flexcc-logstash.sh

次のコンテンツを追加します
自分の状況に応じて道を決めなければなりません。

nohup ./logstash -f /usr/local/elk/logstash-6.3.1/config/flexcc-logstash.conf > /usr/local/elk/logstash/logs/flexcc-logstash.log 2>&1 &

実行し続ける

sh flexcc-logstash.sh

3 Kibana のインストールと設定

3.1 減圧

tar -zxvf kibana-6.3.1-linux-x86_64.tar.gz

3.2 構成の変更

vim /usr/local/elk/kibana-6.3.1-linux-x86_64/config/kibana.yml
server.port: 5601       ##服务端口
server.host: "0.0.0.0"  ##服务器ip  本机
 
elasticsearch.url: "http://localhost:9200" ##elasticsearch服务地址 与elasticsearch对应

3.3 キバナを開始する

/usr/local/elk/kibana-6.3.1-linux-x86_64/bin/kibana       #命令窗启动
或者
nohup ./kibana-6.3.1-linux-x86_64/bin/kibana &   #后台线程启动

3.4 キバナを閉じる

ctrl+c                                   #命令窗关闭
或者
netstat -tunlp|grep 5601                    #后台线程关闭   5601为kibana的启动端口
kill -9 pid                             ##pid 为查处线程的pid 

ここに画像の説明を挿入

3.5 kibana の起動を確認する

http://localhost:5601/

4 Filebeatのインストールと設定

複数のマシンの場合、Filebeat を繰り返しデプロイできます。ただし、filebeat.yml ファイル内の Logstash のサーバーとポートを変更するには

4.1 減圧

tar -zxvf filebeat -6.3.0-linux-x86_64.tar.gz

4.2 ファイルbeat.yml を編集する

cd /usr/local/elk/filebeat-6.3.1-linux-x86_64

vim filebeat.yml

次の内容を変更します。

paths: サービス ログが配置されているパス
host: [“localhost:18401”]: Logstash が配置されているサーバーとポート

#=========================== 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: true

  # Paths that should be crawled and fetched. Glob based paths.
  paths:
    - /home/xiandai/callin/nohup.out
    - /home/xiandai/callout/nohup.out
    - /home/xiandai/sysmanager/nohup.out
    - /home/xiandai/report/nohup.out
    - /home/xiandai/knowledge/nohup.out
    #- 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']
  
  # The regexp Pattern that has to be matched. The example pattern matches all lines starting with [
  #multiline.pattern: ^\[
  multiline.pattern: '^\{\"level\":'
  multiline.negate: true
  multiline.match: after
  # Defines if the pattern set under pattern should be negated or not. Default is false.
  #multiline.negate: false




#============================= 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


#================================ Outputs =====================================

#----------------------------- Logstash output --------------------------------
output.logstash:
  # The Logstash hosts
  hosts: ["localhost:18401"]

  # Optional SSL. By default is off.
  # List of root certificates for HTTPS server verifications
  #ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]

4.3 テスト

filebeat-6.3.1-linux-x86_64 パスの下

./filebeat -e -c filebeat.yml -d "Publish"

大量の出力が表示される場合は、ログが elasticsearch または logstash に送信されていることを意味します。
テストが正常に完了したら、Ctrl+C で終了します

4.4スタート

nohup ./filebeat -e -c filebeat.yml >/dev/null 2>&1 &

おすすめ

転載: blog.csdn.net/weixin_38746118/article/details/118087579