filebeat + elasticSearch + kibana 搭建日志收集系统

本文详细介绍如何在CentOS 6.x环境下搭建ELK(Elasticsearch、Logstash、Kibana)日志系统,包括Filebeat日志收集、Elasticsearch日志存储及Kibana日志展示的全过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

注意.

​ filebeat作用为收集日志,所以发布到日志所在的服务器

​ Elasitcsearch + Kibana发布在日志最终传输的目的服务器

​ filebeat ,Elasitcsearch ,Kibana最好使用相同版本,不然很可能会出现不兼容现象

centos 6.x 环境下

1.1 在日志所在服务器上安装Filebeat

sudo rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch

将以下内容

[elastic-5.x]
name=Elastic repository for 5.x packages
baseurl=https://artifacts.elastic.co/packages/5.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

保存为 /etc/yum.repos.d/beat.repo 文件

开始安装

yum -y install filebeat
chkconfig --add filebeat

启动命令

/etc/init.d/filebeat start

1.2 另外安装方式

https://www.elastic.co/downloads/beats/filebeat1

方式一:源码

wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.0.0-linux-x86_64.tar.gz
tar -zxvf filebeat-6.0.0-linux-x86_64.tar.gz

方式二:rpm

#推荐使用
curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.0.0-x86_64.rpm
sudo rpm -ivh filebeat-6.0.0-x86_64.rpm

 

 

2. 在日志服务器安装 Elasticsearch

mkdir -p ~/download && cd ~/download
​
wget -c https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.7.2.zip
unzip elasticsearch-1.7.2.zip 
(或者)
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.0.0.tar.gz
tar -xvf elasticsearch-6.0.0.tar.gz
​
mv elasticsearch-1.7.2 /usr/local/elasticsearch

启动命令

cd /usr/local/elasticsearch/bin
./elasticsearch -d

注意:出于安全考虑,es不能以root用户执行,所以,步骤如下:

groupadd elsearch
useradd elsearch -g elsearch -p elasticsearch
chown -R elsearch:elsearch  elasticsearch目录(此处为/usr/local/elasticsearch)
su elsearch #切换账户
cd /usr/local/elasticsearch/bin #进入你的elasticsearch目录下的bin目录
./elasticsearch -d

 

 

3. 在日志服务器安装 Kibana

#方式一
rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
cat > /etc/yum.repos.d/kibana.repo  
​
[kibana-6.x]
name=Kibana 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=1
autorefresh=1
type=rpm-md
​
yum install kibana
chkconfig --add kibana
​
​
#方式二
wget https://artifacts.elastic.co/downloads/kibana/kibana-6.0.0-x86_64.rpm
rpm -ivh kibana-6.0.0-x86_64.rpm
chkconfig --add kibana

 

 

启动命令

/etc/init.d/kibana start

4.1配置 filebeat

filebeat:
  prospectors:
    -
      document_type: "php-fpm"
      paths:
        - /var/log/php/php-fpm.log
    -
      document_type: "php-fpm.slow"
      paths:
        - /var/log/php/slow.log
      multiline:
          pattern: '^[[:space:]]'
          negate: true
          match: after
output:
  elasticsearch:
    hosts: ["192.168.1.88:9200"]
shipper:
  tags: ["web"]
​

上面的配置表示从 /var/log/server/php/php-fpm.log, /var/log/server/php/cloud.slow.log 这两个位置收集日志,其中由于 slow 日志存在多行的做为一条记录的情况,filebeat 通过三个配置来将多行转为一行, pattern, negate, match, 上面的配置表示,如果不是以空白开头的行将被拼接到上一行的后面,pattern 遵循golang的正则语法

output 指令中指定将日志输出到 elasticsearch,并添加了服务所在ip 和端口,可以添加多台,还能支持负均衡

shipper 中可以指定一些tag,方便后面在 kibana 中筛选数据

好了,重启filebeat就可以了, /etc/init.d/filebeat restart

4.2 配置Elasticsearch

确保 Elasticsearch 已经启动

4.3 配置kibana

安装 filebeat 的示例仪表盘等

mkdir -p ~/download && cd ~/download
curl -L -O http://download.elastic.co/beats/dashboards/beats-dashboards-1.3.1.zip
unzip beats-dashboards-1.3.1.zip
cd beats-dashboards-1.3.1/
./load.sh

默认情况下,脚本假设在127.0.0.1:9200上运行Elasticsearch。 使用-url选项指定其他位置。 例如:./load.sh -url http://192.168.1.88:9200

kibana中需要配置 elasticsearch 的地址和端口,现在两个服务都是在同一台上,配置默认是 localhost:9200,所以也不用改

4.4 打开kibana

kibana 启动后默认 端口是 5601 , 从浏览器打开 http://192.168.1.88:5601

5.添加访问权限

进入elasticsearch目录,下载x-pack

bin/elasticsearch-plugin install x-pack

安装过程中跳出选项现在y即可。

如果你在Elasticsearch已禁用自动索引的创建,在elasticsearch.yml配置action.auto_create_index允许X-pack创造以下指标:

action.auto_create_index: .security,.monitoring*,.watches,.triggered_watches,.watcher-history*

启动ES,很有可能会报错!

Exception in thread "main" org.elasticsearch.bootstrap.BootstrapException: java.nio.file.AccessDeniedException: /usr/local/elasticsearch/config/elasticsearch.keystore

提示权限不够,此时,切换到root用户,执行

chown 用户名(elsearch) /usr/local/elasticsearch -R

另。因为很可能出现初始账号密码不对,所以可以事先设定自己的密码(此方法适用6.x及以上版本版本)

bin/x-pack/setup-passwords interactive

 

进入kibana目录,下载x-pack

bin/kibana-plugin install x-pack
#直到出现Plugin installation complete才算安装完成

修改kibana.yml中的elasticsearch账号密码,默认为 账号:elastic 密码:changme

在进入kibana界面之后,可以进行密码修改,但是修改之后又要重新修改kibana中的账号密码,重启

注:rpm安装默认在/usr/share/kibana;可以find / -name kibana-plugin

 

 

6.添加权限管理用户

 

在登录kibana之后,进入管理页面

在Management里面可以添加新的用户,并分配不同的权限

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

兔八哥的幸福生活

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

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

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

打赏作者

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

抵扣说明:

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

余额充值