【ELK】(三)-Logstash的部署和使用+Kibana部署和使用

一 环境准备

  • Logstash 依赖 JDK1.8 ,因此在安装之前请确保机器已经安装和配置好 JDK1.8。

JDK下载官网

下载后解压,并配置环境变量,重新加载后测试

tar -xzvf jdk-8u381-linux-x64.tar.gz -C /usr/local
vim /etc/profile进入编辑模式后,在末尾加入这段
 
export JAVA_HOME=/usr/local/jdk1.8.0_381
export PATH=$PATH:$JAVA_HOME/bin           
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar  
export JRE_HOME=$JAVA_HOME/jre    
source /etc/profile
java -version  #出现版本即为成功
javac

 二 安装Logstash,修改配置文件并测试

  2.1 下载Logstash:要下载与es对应的版本,并解压到/usr/local

Logstash下载官网

wget https://artifacts.elastic.co/downloads/logstash/logstash-7.6.1.tar.gz
tar -xzvf logstash-7.6.1.tar.gz -C /usr/local/

  2.2 修改配置文件

vim /usr/local/logstash/config/logstash.yml

path.config: /etc/logstash/conf.d

  2.3 启动并测试

./bin/logstash -e 'input {stdin {}} output{stdout{}}' 
##ss -nlt 查看9600端口

  2.4  简单应用:收集多个日志到多个索引

   2.41  

input输入文件:flie - type - path     

output:输出到es中创建索引,判断类型 - es地址 - 索引命名       参考优秀文档

vim /etc/logstash/conf.d/morefile_es.conf

input {
  file {
    type => "messages_log"
    path => "/var/log/messages"
  }
  file {
    type => "secure_log"
    path => "/var/log/secure"
  }
}
output {
  if [type] == "messages_log" {
    elasticsearch {
      hosts => ["192.168.10.103:9200"]
      index => "messages_log_%{+YYYY-MM-dd}"
    }
  }
  if [type] == "secure_log" {
    elasticsearch {
      hosts => ["192.168.10.103:9200"]
      index => "secure_log_%{+YYYY-MM-dd}"
    }
  }
}

启动尽量使用绝对路径:否则可能建立不了索引 

##检测语法
/usr/local/logstash/bin/logstash -f /etc/logstash/conf.d/message_file.conf -t
##启动
nohup /usr/local/logstash/bin/logstash -f  /etc/logstash/conf.d/morefile_es.conf &
##查询索引创建与否
curl -XGET 'http://192.168.10.103:9200/_cat/indices?v&pretty'
##日志如果没有更新,是不会创建索引的,新打开一个窗口

  2.42  一个日志文件一个索引,多个日志多个索引,采集Nginx、MySQL、Kafka日志

要采集哪个日志就在那台服务器上配置logstash

本实验环境:一台服务器rpm部署mysql,tar部署nginx

vim /etc/logstash/conf.d/test.conf

input {
  file {
    type => "nginx_log"
    path => "/usr/local/nginx/logs/error.log"
  }
  file {
    type => "mysql_log"
    path => "/var/log/mysqld.log"
  }
  file {
    type => "kafka_log"
    path => "/usr/local/kafka/logs/kafkaServer.out"
  }
}
output {
  if [type] == "nginx_log" {
    elasticsearch {
      hosts => ["192.168.10.103:9200"]
      index => "nginx_log_%{+YYYY-MM-dd}"
    }
  }
  if [type] == "mysql_log" {
    elasticsearch {
      hosts => ["192.168.10.103:9200"]
      index => "mysql_log_%{+YYYY-MM-dd}"
    }
  }
  if [type] == "kafka_log" {
    elasticsearch {
      hosts => ["192.168.10.103:9200"]
      index => "kafka_log_%{+YYYY-MM-dd}"
    }
  }
}
##检测语法
/usr/local/logstash/bin/logstash -f /etc/logstash/conf.d/test.conf -t
##启动
nohup /usr/local/logstash/bin/logstash -f  /etc/logstash/conf.d/test.conf &
##查询创建索引
curl -XGET 'http://192.168.10.103:9200/_cat/indices?v&pretty'

 索引出现即为成功,但是Kafka启动,没有日志产生故没有索引创建3e5b94f3ff40421ebe2938353d07f701.png

三 安装Kibana 

  3.1 下载Kibana:要下载与es对应的版本,并解压到/usr/local

Kibana下载官网

wget https://artifacts.elastic.co/downloads/kibana/kibana-7.6.1-linux-x86_64.tar.gz
tar -xzvf kibana-7.6.1-linux-x86_64.tar.gz -C /usr/local/

   3.2 修改配置文件,并启动

vim /usr/local/kibana-7.6.1-linux-x86_64/config/kibana.yml

server.port: 5601
server.host: "0.0.0.0"
elasticsearch.hosts: ["http://192.168.10.101:9200","http://192.168.10.102:9200","http://192.168.10.103:9200"]
server.name: "elk3" #随意
i18n.locale: "zh-CN" #汉化
nohup ./kibana --allow-root &
/usr/local/kibana-7.6.1-linux-x86_64/bin//kibana --allow-root &
##启动后看5601端口
##http://192.168.10.103:5601/app/kibana  使用浏览器操作

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值