ELK-Kibana 部署

目录

[一、在 node1 节点上操作](#一、在 node1 节点上操作)

[1.1.安装 Kibana](#1.1.安装 Kibana)

[1.2.设置 Kibana 的主配置文件](#1.2.设置 Kibana 的主配置文件)

[1.3.启动 Kibana 服务](#1.3.启动 Kibana 服务)

[1.4.验证 Kibana](#1.4.验证 Kibana)

[1.5.将 Apache 服务器的日志(访问的、错误的)添加到 ES 并通过 Kibana 显示](#1.5.将 Apache 服务器的日志(访问的、错误的)添加到 ES 并通过 Kibana 显示)

[1.6. 浏览器访问](#1.6. 浏览器访问)

二、部署Filebeat+ELK(ELFK)

[2.1.安装 Filebeat](#2.1.安装 Filebeat)

[2.2.设置 Kibana 的主配置文件](#2.2.设置 Kibana 的主配置文件)


一、在 node1 节点上操作

1.1.安装 Kibana

css 复制代码
[root@node1 elasticsearch-head]# cd /opt
[root@node1 opt]# rz -E		#上传软件包 kibana-5.5.1-x86_64.rpm
[root@node1 opt]# rpm -ivh kibana-5.5.1-x86_64.rpm

1.2.设置 Kibana 的主配置文件

css 复制代码
[root@node1 opt]# vim /etc/kibana/kibana.yml
##2行,取消注释,kibana服务的默认监听端口为5601
server.port: 5601
##7行,取消注释,设置kibana的监听地址,0.0.0.0代表所有地址
server.host: "0.0.0.0"
##21行,取消注释,设置和ES建立连接的地址和端口
elasticsearch.url: "http://192.168.190.101:9200"
##30行,取消注释,设置在ES中添加.kibana索引
kibana.index: ".kibana"

1.3.启动 Kibana 服务

css 复制代码
[root@node1 opt]# systemctl start kibana.service 
[root@node1 opt]# systemctl enable kibana.service 
[root@node1 opt]# netstat -natp | grep 5601
tcp        0      0 0.0.0.0:5601            0.0.0.0:*               LISTEN      82765/node     

1.4.验证 Kibana

浏览器访问 http://192.168.190.101:5601

第一次登录需要添加一个 ES 索引

点击 create 创建

索引添加完成后,点击 Discover 按钮可查看图表信息及日志信息

1.5.将 Apache 服务器的日志(访问的、错误的)添加到 ES 并通过 Kibana 显示

apache 服务器

css 复制代码
 
[root@apache opt]# vim /etc/logstash/conf.d/apache_log.conf
 
input {
    file{
        path => "/etc/httpd/logs/access_log"
        type => "access"
        start_position => "beginning"
    }
    file{
        path => "/etc/httpd/logs/error_log"
        type => "error"
        start_position => "beginning"
    }
}
output {
    if [type] == "access" {
        elasticsearch {
            hosts => ["192.168.190.101:9200"]
            index => "apache_access-%{+YYYY.MM.dd}"
        }
    }
	if [type] == "error" {
        elasticsearch {
            hosts => ["192.168.190.101:9200"]
            index => "apache_error-%{+YYYY.MM.dd}"
        }
    }
}
[root@apache opt]# cd /etc/logstash/conf.d
[root@apache conf.d]# /usr/share/logstash/bin/logstash -f apache_log.conf
······
23:42:13.199 [Api Webserver] INFO  logstash.agent - Successfully started Logstash API endpoint {:port=>9601}

1.6. 浏览器访问

浏览器访问 http://192.168.190.101:9100 查看索引是否创建

可能你只看到了 apache-error,那是因为 access 需要访问 httpd 页面才能生成

浏览器访问 http://192.168.190.101:5601 登录 kibana,添加 apache_access-* 和 apache_error-* 索引,查看日志信息

二、部署Filebeat+ELK(ELFK)

2.1.安装 Filebeat

css 复制代码
#上传软件包 filebeat-6.2.4-linux-x86_64.tar.gz 到/opt目录
cd /opt
rz -E
tar zxvf filebeat-6.6.0-linux-x86_64.tar.gz
mv filebeat-6.6.0-linux-x86_64 /usr/local/filebeat
 

2.2.设置 Kibana 的主配置文件

css 复制代码
[root@filebeat opt]# cd /usr/local/filebeat/
[root@filebeat filebeat]# cp filebeat.yml filebeat.yml.bak
[root@filebeat filebeat]# vim filebeat.yml
 
filebeat.prospectors:
##21行,指定log类型,从日志文件中读取消息
- type: log
##24行,开启日志收集功能,默认为false
  enabled: true
##28行,指定监控的日志文件
    - /var/log/*.log
##29行,添加收集/var/log/messages
    - /var/log/messages
##31行,添加以下内容,注意格式
  fields: 
    service_name: filebeat
    log_type: log
    service_id: 192.168.190.105
#-------------------------- Elasticsearch output ------------------------------
该区域内容全部注释
#----------------------------- Logstash output --------------------------------
##157行,取消注释
output.logstash:
##159行,取消注释,指定logstash的IP和端口号
  hosts: ["192.168.190.101:5044"]
 
[root@filebeat filebeat]# ./filebeat -e -c filebeat.yml
#启动filebeat,-e记录到stderr并禁用syslog /文件输出,-c指定配置文件

css 复制代码
[root@apache ~]# cd /etc/logstash/conf.d/
[root@apache conf.d]# vim logstash.conf
 
input {
    beats {
        port => "5044"
    }
}
output {
    elasticsearch {
        hosts => ["192.168.190.101:9200"]
        index => "%{[fields][service_name]}-%{+YYYY.MM.dd}"
    }
    stdout {
        codec => rubydebug
    }
}
 
[root@apache conf.d]# /usr/share/logstash/bin/logstash -f apache_log.conf 

浏览器验证

css 复制代码
浏览器访问,登录 Kibana 测试,
浏览器访问 http://192.168.190.101:5601 登录 Kibana

单击"Create Index Pattern"按钮添加索引"filebeat-*"

单击 "create" 按钮创建,单击 "Discover" 按钮可查看图表信息及日志信息。

相关推荐
Fu20672115 小时前
第一阶段项目
linux·服务器·网络
吴建旭 智宅焕16 小时前
智能家居全国交付的确定性架构设计与实现:从不确定转化到交付基础设施
运维·智能家居·devops
女神下凡1 天前
芯参谋(119):凌阳(Sunplus)_开发指南
linux·arm开发·stm32·单片机·嵌入式硬件
可涵不会debug1 天前
dufs轻量文件服务器教程:中文界面、WebDAV、上传分享与远程访问
运维·服务器
数据库急诊室_阿哲1 天前
一周慢查询日志审计:1200 条里有多少真问题
运维·数据库·dba
新*1 天前
ES 7.17 三节点 Docker 集群的自动备份:从 NFS 被拦住到用 ACL 根治权限
运维·elasticsearch·docker·slm·快照备份
Decay__1 天前
PostgreSQL DBA 日常运维手册 —— 会话、锁阻塞、慢查询、膨胀与每日巡检
运维·数据库·sql·postgresql
落羽的落羽1 天前
【C++】现代容器: tuple、optional、variant、any、string_view
linux·开发语言·数据结构·c++·人工智能·计算机网络·算法
木子欢儿1 天前
Ubuntu 26.04 LTS 安装Python 3.12
linux·运维·服务器·python·ubuntu
时间的拾荒人1 天前
Linux 库的制作与使用(下):链接、加载与动态链接原理
linux·运维·动态库·静态库