ELK搭建

本次ELK安装版本均为7.17.21,8.0版本容易出软件如兼容的问题,故选择7的最后一个版本进行安装

前期准备:

  elastic官网:https://www.elastic.co/

  elasticsearch下载地址:https://www.elastic.co/cn/downloads/past-releases/elasticsearch-7-17-21

  logstash下载地址:https://www.elastic.co/cn/downloads/past-releases/logstash-7-17-21

  kibana下载地址:https://www.elastic.co/cn/downloads/past-releases/kibana-7-17-21

elasticsearch

  tar -xvf elasticsearch-7.17.21-linux-x86_64.tar.gz

  cd elasticsearch-7.17.21

  vim config/elasticsearch.yml

    xpack.security.enabled: true    #开启https安全校验,未开启的情况下kibana无法使用

    xpack.security.authc.api_key.enabled: true     #开启api接口访问

      ./bin/elasticsearch-setup-passwords interactive      #重置es密码,执行后会在控制台打印出用户名和密码

  useradd esuser  #创建esuser用户

  su esuser        #root用户不能启动elasticsearch  需要切换到esuser用户启动

  后台启动:nohup ./bin/elasticsearch  > /dev/null 2>&1 &     

kibana

  tar -xvf kibana-7.17.21-linux-x86_64.tar.gz

  cd kibana-7.17.21-linux-x86_64/

      elasticsearch开启htts安全设置时需要生成加密字符串   ./bin/kibana-encryption-keys generate  并配置到kibana.yml中

  vim config/kibana.yml

    elasticsearch.username: "es user name"

    elasticsearch.password: "es password"

  后台启动:nohup ./bin/kibana --allow-root > /dev/null 2>&1 &       #root用户启动需要加--allow-root   非root用户可不加

  kibana访问:http://ip:5601

logstash  

tar -xvf logstash-7.17.21-linux-x86_64.tar.gz

  cd logstash-7.17.21

  mkdir conf.d

  创建配置文件,多个配置文件ipput需加type字段,在output中对type进行判断,否则会出现同一来源的日志进入所有配置的output中

      

# Sample Logstash configuration for creating a simple
# Beats -> Logstash -> Elasticsearch pipeline.
input {
  file {
    path => "/home/www/jzwl/api/resource/log/sql/*.log"
    #start_position => "beginning"
    type=>"api"
  }
}

output {
  if [type] == "api"{
    elasticsearch {
      hosts => ["http://localhost:9200"]
      index => "jzwl-api-%{+YYYY.MM.dd}"
      user => "es username"
      password => "es password"
    }
  }
}

  

  后台启动:

nohup ./bin/logstash -f ./conf.d/ > /dev/null 2>&1 & 

ELK 的工作原理是在所有需要收集日志的服务器上部署 Logstash;或者先将日志进行集中化管理在日志服务器上,在日志服务器上部署 Logstash。Logstash 收集日志,将日志格式化并输出到 Elasticsearch 中。Elasticsearch 对格式化后的数据进行索引和存储。Kibana 从 ES 群集中查询数据生成图表,并进行前端数据的展示。搭建 ELK 可以参考以下步骤: #### 安装 Elasticsearch 解压到相应目录: ```bash tar -zxvfelasticsearch-8.14.3-linux-x86_64.tar.gz -C /opt/elk/ ``` 修改配置: ```bash vim /opt/elk/elasticsearch-8.14.3/config/elasticsearch.yml ``` 配置示例: ```yaml node.name: node-1 path.data: /opt/elk/elasticsearch-8.14.3/data path.logs: /opt/elk/elasticsearch-8.14.3/logs network.host: 127.0.0.1 http.host: 0.0.0.0 http.port: 9200 discovery.seed_hosts: ["127.0.0.1"] cluster.initial_master_nodes: ["node-1"] ``` #### 安装 Logstash 安装 Logstash 通常也是下载对应版本的压缩包并解压。解压后需要配置 `logstash.conf` 文件,示例配置如下: ```conf input { file { path => "/var/log/*.log" start_position => "beginning" } } filter { grok { match => { "message" => "%{COMBINEDAPACHELOG}" } } } output { elasticsearch { hosts => ["localhost:9200"] index => "logstash-%{+YYYY.MM.dd}" } } ``` #### 安装 Kibana 同样是下载压缩包并解压,解压后修改 `kibana.yml` 配置文件: ```bash vim /path/to/kibana/config/kibana.yml ``` 配置示例: ```yaml server.port: 5601 server.host: "0.0.0.0" elasticsearch.hosts: ["http://localhost:9200"] ``` #### 启动服务 分别启动 Elasticsearch、Logstash 和 Kibana: ```bash /opt/elk/elasticsearch-8.14.3/bin/elasticsearch /path/to/logstash/bin/logstash -f /path/to/logstash.conf /path/to/kibana/bin/kibana ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小斌0810

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值