ELK 远程日志服务器安装

Linux localhost.localdomain 3.10.0-1160.6.1.el7.x86_64 #1 SMP Tue Nov 17 13:59:11 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

安装 Logstash


  • 安装 Java 环境
yum install -y java-1.8.0-openjdk
  • 添加 repo:/etc/yum.repos.d/elastic.repo
[elasticsearch]
name=Elasticsearch repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md
  • 安装 Logstash
yum --enablerepo=elasticsearch  install logstash
  • 验证安装
[root@localhost ~]# /usr/share/logstash/bin/logstash -e'input {stdin {}} output {stdout {}}'
WARNING: Could not find logstash.yml which is typically located in $LS_HOME/config or /etc/logstash. You can specify the path using --path.settings. Continuing using the defaults
Could not find log4j2 configuration at path /usr/share/logstash/config/log4j2.properties. Using default config which logs errors to the console
[INFO ] 2020-11-26 11:28:49.727 [main] writabledirectory - Creating directory {:setting=>"path.queue", :path=>"/usr/share/logstash/data/queue"}
[INFO ] 2020-11-26 11:28:49.748 [main] writabledirectory - Creating directory {:setting=>"path.dead_letter_queue", :path=>"/usr/share/logstash/data/dead_letter_queue"}
[WARN ] 2020-11-26 11:28:50.266 [LogStash::Runner] multilocal - Ignoring the 'pipelines.yml' file because modules or command line options are specified
[INFO ] 2020-11-26 11:28:50.287 [LogStash::Runner] runner - Starting Logstash {"logstash.version"=>"6.8.13"}
[INFO ] 2020-11-26 11:28:50.324 [LogStash::Runner] agent - No persistent UUID file found. Generating new UUID {:uuid=>"db92df99-88f9-4134-9f91-14743bdb5d83", :path=>"/usr/share/logstash/data/uuid"}
[INFO ] 2020-11-26 11:28:58.501 [Converge PipelineAction::Create<main>] pipeline - Starting pipeline {:pipeline_id=>"main", "pipeline.workers"=>2, "pipeline.batch.size"=>125, "pipeline.batch.delay"=>50}
[INFO ] 2020-11-26 11:28:58.634 [Converge PipelineAction::Create<main>] pipeline - Pipeline started successfully {:pipeline_id=>"main", :thread=>"#<Thread:0x6eecb906 run>"}
The stdin plugin is now waiting for input:
[INFO ] 2020-11-26 11:28:58.710 [Ruby-0-Thread-2: /usr/share/logstash/lib/bootstrap/environment.rb:6] agent - Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]}
[INFO ] 2020-11-26 11:28:59.016 [Api Webserver] agent - Successfully started Logstash API endpoint {:port=>9600}
hello world
/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/awesome_print-1.7.0/lib/awesome_print/formatters/base_formatter.rb:31: warning: constant ::Fixnum is deprecated
{
       "message" => "hello world",
    "@timestamp" => 2020-11-26T03:29:13.910Z,
      "@version" => "1",
          "host" => "localhost.localdomain"
}
^C[WARN ] 2020-11-26 11:29:20.040 [SIGINT handler] runner - SIGINT received. Shutting down.
[INFO ] 2020-11-26 11:29:20.369 [[main]-pipeline-manager] pipeline - Pipeline has terminated {:pipeline_id=>"main", :thread=>"#<Thread:0x6eecb906 run>"}
[INFO ] 2020-11-26 11:29:20.417 [LogStash::Runner] runner - Logstash shut down.
  • 配置 Logstash:在 /etc/logstash/conf.d 目录下创建远程日志配置文件remote_syslog.conf
input {
    syslog {
        port => "514"
        type => "syslog"
    }
}
filter {}
output {
    elasticsearch {
        hosts => "localhost:9200"
        index => "syslog-%{+YYYY.MM.dd}"  
        }
}

安装 Elasticsearch


  • 安装 Elasticsearch
yum --enablerepo=elasticsearch  install elasticsearch
  • 扩大系统最大文件数:/etc/security/limits.d/20-nproc.conf
*   soft    nofile  65536
*   hard    nofile  131072
*   soft    nproc   4096
*   hard    nproc   4096

root        soft    nproc   unlimited
elasticsearch   soft    memlock unlimited
elasticsearch   hard    memlock unlimited
  • Daemon reload
systemctl daemon-reload
  • 配置 MEMLOCK:/usr/lib/systemd/system/elasticsearch.service
[Service]
LimitMEMLOCK=infinity
  • 修改 elasticsearch 配置:/etc/elasticsearch/elasticsearch.yml
bootstrap.memory_lock: true
http.port: 9200
  • 根据系统资源情况修改 heap size:/etc/elasticsearch/ jvm.options
-Xms4g
-Xmx4g
  • 解决虚拟内存太低,增加最大字节处理长度:/etc/sysctl.conf
vm.max_map_count=655360

# 查看激活
[root@localhost ~]# sysctl -p
vm.overcommit_memory = 1
vm.max_map_count = 655360
  • 启动 elasticsearch
systemctl start Elasticsearch
  • 访问
[root@localhost ~]# curl http://localhost:9200/
{
  "name" : "l1_orbv",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "2K5T_E63Raqt0lGX8xls_A",
  "version" : {
    "number" : "6.8.13",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "be13c69",
    "build_date" : "2020-10-16T09:09:46.555371Z",
    "build_snapshot" : false,
    "lucene_version" : "7.7.3",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}
  • 查看 index 状态
[root@localhost ~]# curl  'localhost:9200/_cat/indices?v'
health status index                           uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green  open   .kibana_task_manager            sp7Yi1R6Qj22xj_WGkEgbg   1   0          2            0     13.2kb         13.2kb
green  open   .monitoring-es-6-2020.11.26     _-coeXyrQQShTuIYYcwqLQ   1   0       6035           30        5mb            5mb
green  open   .monitoring-kibana-6-2020.11.26 94IU5EWpRhOakdHGNxLBGQ   1   0        594            0    492.9kb        492.9kb
yellow open   syslog-2020.11.26               TiFIWTwzSwmC6E7zGKAtfQ   5   1          1            0      9.7kb          9.7kb
green  open   .kibana_1                       RQ95lJkuRb-EYMoeU__g8A   1   0         20            2     93.2kb         93.2kb
green  open   kibana_sample_data_logs         wZf5Vsj2QnKB_lfOiJy44Q   1   0      14005            0     11.6mb         11.6mb

安装 kibana


  • 安装 kibana
yum --enablerepo=elasticsearch  install kibana
  • 配置 /etc/kibana/kibana.yml
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.hosts: ["http://localhost:9200"]
  • 启动 kibana & logstash
systemctl start Kibana
systemctl start logstash
  • 访问 kibana 并添加 index:http://x.x.x.x:5601/

    添加 index

  • 查看收到的日志


    查看日志

References


https://gryzli.info/2019/02/15/installing-and-configuring-filebeat-on-centos-rhel/
https://www.cnblogs.com/xiaobaozi-95/p/9214307.html
https://blog.csdn.net/weixin_42385705/article/details/103342947?utm_medium=distribute.pc_relevant.none-task-blog-baidulandingword-2&spm=1001.2101.3001.4242

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 220,367评论 6 512
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,959评论 3 396
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 166,750评论 0 357
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 59,226评论 1 295
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 68,252评论 6 397
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,975评论 1 308
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,592评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,497评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 46,027评论 1 319
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,147评论 3 340
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,274评论 1 352
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,953评论 5 347
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,623评论 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,143评论 0 23
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,260评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,607评论 3 375
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,271评论 2 358

推荐阅读更多精彩内容