首页 > 数据库 >Linux搭建ELK+Filebeat+Nginx+Redis分布式日志管理平台

Linux搭建ELK+Filebeat+Nginx+Redis分布式日志管理平台

时间:2022-12-30 16:37:07浏览次数:38  
标签:ELK Filebeat redis local Redis nginx usr root localhost

ELK介绍

需求背景

业务发展越来越庞大,服务器越来越多

各种访问日志、应用日志、错误日志量越来越多,导致运维人员无法很好的去管理日志

开发人员排查问题,需要到服务器上查日志,不方便

运营人员需要一些数据,需要我们运维到服务器上分析日志

为什么要用到ELK?

一般我们需要进行日志分析场景:直接在日志文件中 grep、awk 就可以获得自己想要的信息。但在规模较大也就是日志量多而复杂的场景中,此方法效率低下,面临问题包括日志量太大如何归档、文本搜索太慢怎么办、如何多维度查询。需要集中化的日志管理,所有服务器上的日志收集汇总。常见解决思路是建立集中式日志收集系统,将所有节点上的日志统一收集,管理,访问。

大型系统通常都是一个分布式部署的架构,不同的服务模块部署在不同的服务器上,问题出现时,大部分情况需要根据问题暴露的关键信息,定位到具体的服务器和服务模块,构建一套集中式日志系统,可以提高定位问题的效率。

一个完整的集中式日志系统,需要包含以下几个主要特点:

1)收集-能够采集多种来源的日志数据;

2)传输-能够稳定的把日志数据传输到中央系统;

3)存储-如何存储日志数据;

4)分析-可以支持 UI 分析;

5)警告-能够提供错误报告,监控机制;

而ELK则提供了一整套解决方案,并且都是开源软件,之间互相配合使用,完美衔接,高效的满足了很多场合的应用。是目前主流的一种日志系统。

ELK简介

ELK是三个开源软件的缩写,分别为:Elasticsearch 、 Logstash以及Kibana , 它们都是开源软件。不过现在还新增了一个Beats,它是一个轻量级的日志收集处理工具(Agent),Beats占用资源少,适合于在各个服务器上搜集日志后传输给Logstash,官方也推荐此工具,目前由于原本的ELK Stack成员中加入了 Beats 工具所以已改名为Elastic Stack。

Elastic Stack包含:

Elasticsearch是个开源分布式搜索引擎,提供搜集、分析、存储数据三大功能。它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等。

详细可参考Elasticsearch权威指南

Logstash主要是用来日志的搜集、分析、过滤日志的工具,支持大量的数据获取方式。一般工作方式为c/s架构,client端安装在需要收集日志的主机上,server端负责将收到的各节点日志进行过滤、修改等操作在一并发往elasticsearch上去。

Kibana也是一个开源和免费的工具,Kibana可以为 Logstash 和 ElasticSearch提供的日志分析友好的 Web 界面,可以帮助汇总、分析和搜索重要数据日志。

Beats在这里是一个轻量级日志采集器,其实Beats家族有6个成员,早期的ELK架构中使用Logstash收集、解析日志,但是Logstash对内存、cpu、io等资源消耗比较高。相比 Logstash,Beats所占系统的CPU和内存几乎可以忽略不计

ELK Stack (5.0版本之后)--> Elastic Stack == (ELK Stack + Beats)。目前Beats包含六种工具:

Packetbeat: 网络数据(收集网络流量数据)

Metricbeat: 指标 (收集系统、进程和文件系统级别的 CPU 和内存使用情况等数据)

Filebeat: 日志文件(收集文件数据)

Winlogbeat: windows事件日志(收集 Windows 事件日志数据)

Auditbeat:审计数据 (收集审计日志)

Heartbeat:运行时间监控 (收集系统运行时的数据)

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

中文指南:https://www.gitbook.com/book/chenryn/elk-stack-guide-cn/details

ELK架构图:

Linux搭建ELK+Filebeat+Nginx+Redis分布式日志管理平台_linux

环境准备

操作系统:CentOS Linux release 7.8.2003 (Core)

服务器IP:172.168.1.157

软件版本

elasticsearch:elasticsearch-7.5.1-linux-x86_64.tar.gz

kibana:kibana-7.5.1-linux-x86_64.tar.gz

logstash:logstash-7.5.1.tar.gz

filebeat:filebeat-7.5.1-linux-x86_64.tar.gz

JDK:jdk-11.0.1_linux-x64_bin.tar.gz

Redis:redis-5.0.7.tar.gz

Nginx:nginx-1.18.0.tar.gz

一、基础环境配置

1、关闭防火墙和selinux

[root@localhost ~]# systemctl stop firewalld

[root@localhost ~]# systemctl disable firewalld

[root@localhost ~]# setenforce 0

[root@localhost ~]# sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config

2、内核优化

[root@localhost ~]# vim /etc/security/limits.conf

# 在文件最后添加以下内容


  1. * soft nofile 65537
  2. * hard nofile 65537
  3. * soft nproc 65537
  4. * hard nproc 65537

[root@localhost ~]# vim /etc/security/limits.d/20-nproc.conf

# 配置以下内容


  1. * soft nproc 4096

[root@localhost ~]# vim /etc/sysctl.conf

配置以下内容


  1. net.ipv4.tcp_max_syn_backlog = 65536
  2. net.core.netdev_max_backlog = 32768
  3. net.core.somaxconn = 32768
  4. net.core.wmem_default = 8388608
  5. net.core.rmem_default = 8388608
  6. net.core.rmem_max = 16777216
  7. net.core.wmem_max = 16777216
  8. net.ipv4.tcp_timestamps = 0
  9. net.ipv4.tcp_synack_retries = 2
  10. net.ipv4.tcp_syn_retries = 2
  11. net.ipv4.tcp_tw_recycle = 1
  12. net.ipv4.tcp_tw_reuse = 1
  13. net.ipv4.tcp_mem = 94500000 915000000 927000000
  14. net.ipv4.tcp_max_orphans = 3276800
  15. net.ipv4.tcp_fin_timeout = 120
  16. net.ipv4.tcp_keepalive_time = 120
  17. net.ipv4.ip_local_port_range = 1024 65535
  18. net.ipv4.tcp_max_tw_buckets = 30000
  19. fs.file-max=655350
  20. vm.max_map_count = 262144
  21. net.core.somaxconn= 65535
  22. net.ipv4.ip_forward = 1
  23. net.ipv6.conf.all.disable_ipv6=1

#执行sysctl -p使其生效

[root@localhost ~]# sysctl –p

3、安装JDK环境

[root@localhost ~]# wget https://mirrors.yangxingzhen.com/jdk/jdk-11.0.1_linux-x64_bin.tar.gz

[root@localhost ~]# tar zxf jdk-11.0.1_linux-x64_bin.tar.gz -C /usr/local

#配置/etc/profile,添加以下内容

[root@localhost ~]# vim /etc/profile


  1. export JAVA_HOME=/usr/local/jdk-11.0.1
  2. export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
  3. export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOMR/bin

[root@localhost ~]# source /etc/profile

#看到如下信息,java环境配置成功

[root@localhost ~]# java -version

java version "11.0.1" 2018-10-16 LTS

Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)

Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)

4、创建ELK用户

[root@localhost ~]# useradd elk

二、安装Redis

1、下载Redis包

[root@localhost ]# wget -c http://download.redis.io/releases/redis-5.0.7.tar.gz

2、解压安装配置Redis

[root@localhost ]# tar zxf redis-5.0.7.tar.gz

[root@localhost ]# mv redis-5.0.7 /usr/local/redis

[root@localhost ]# cd /usr/local/redis/

[root@localhost ]# make

3、创建数据存放目录

[root@localhost redis]# mkdir -p /data/redis

4、配置Redis

# 随机生成密码

[root@localhost redis]# openssl rand -hex 12

c710403c3c97ac97a269d7a6

[root@localhost redis]# ln -sf /usr/local/redis/src/redis-* /usr/bin

[root@localhost redis]# sed -i "s/127.0.0.1/0.0.0.0/g" /usr/local/redis/redis.conf

[root@localhost redis]# sed -i "/daemonize/s/no/yes/" /usr/local/redis/redis.conf

[root@localhost redis]# sed -i "s/dir .*/dir \/data\/redis/" /usr/local/redis/redis.conf

[root@localhost redis]# sed -i "s/logfile .*/logfile \/usr\/local\/redis\/redis.log/" /usr/local/redis/redis.conf

[root@localhost redis]# sed -i '/appendonly/s/no/yes/' /usr/local/redis/redis.conf

[root@localhost redis]# sed -i "s/# requirepass foobared/requirepass c710403c3c97ac97a269d7a6/" /usr/local/redis/redis.conf

[root@localhost redis]# echo never > /sys/kernel/mm/transparent_hugepage/enabled

[root@localhost redis]# sysctl vm.overcommit_memory=1

5、创建systemctl管理配置文件

[root@localhost redis]# vim /usr/lib/systemd/system/redis.service

# 配置内容如下


  1. [Unit]
  2. Description=Redis Server
  3. After=network-online.target remote-fs.target nss-lookup.target
  4. Wants=network-online.target

  5. [Service]
  6. Type=forking
  7. ExecStart=/usr/bin/redis-server /usr/local/redis/redis.conf
  8. ExecStop=/usr/bin/redis-cli -h 127.0.0.1 -p 6379 shutdown
  9. User=root
  10. Group=root

  11. [Install]
  12. WantedBy=multi-user.target

6)启动Redis服务

[root@localhost redis]# systemctl daemon-reload

[root@localhost redis]# systemctl enable redis

[root@localhost redis]# systemctl start redis

7)查询端口及进程

[root@localhost redis]# netstat -lntup |grep 6379

[root@localhost redis]# systemctl status redis

三、安装elasticsearch

1、创建持久化目录及Logs日志目录

[root@localhost ~]# mkdir -p /data/elasticsearch/{data,logs}

2、下载elasticsearch软件包

[root@localhost ~]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.5.1-linux-x86_64.tar.gz

3、解压并重命名

[root@localhost ~]# tar xf elasticsearch-7.5.1-linux-x86_64.tar.gz

[root@localhost ~]# mv elasticsearch-7.5.1 /usr/local/elasticsearch

4、修改elasticsearch.yml配置文件,文件内容如下

[root@localhost ~]# vim /usr/local/elasticsearch/config/elasticsearch.yml


  1. # 集群名称
  2. cluster.name: es
  3. # 节点名称
  4. node.name: es-master
  5. # 存放数据目录,先创建该目录
  6. path.data: /data/elasticsearch/data
  7. # 存放日志目录,先创建该目录
  8. path.logs: /data/elasticsearch/logs
  9. # 节点IP
  10. network.host: 0.0.0.0
  11. # tcp端口
  12. transport.tcp.port: 9300
  13. # http端口
  14. http.port: 9200
  15. # 主合格节点列表,若有多个主节点,则主节点进行对应的配置
  16. cluster.initial_master_nodes: ["172.168.1.157:9300"]
  17. # 是否允许作为主节点
  18. node.master: true
  19. # 是否保存数据
  20. node.data: true
  21. node.ingest: false
  22. node.ml: false
  23. cluster.remote.connect: false
  24. # 跨域
  25. http.cors.enabled: true
  26. http.cors.allow-origin: "*"
  27. # 配置X-Pack
  28. http.cors.allow-headers: Authorization
  29. xpack.security.enabled: true
  30. xpack.security.transport.ssl.enabled: true

5、ELK用户授权

[root@localhost ~]# chown -R elk.elk /usr/local/elasticsearch/

[root@localhost ~]# chown -R elk.elk /data/elasticsearch/*

6、启动elasticsearch服务(第一次先测试好然后再加-d后台启动)

[root@localhost ~]# su - elk

[elk@localhost ~]$ /usr/local/elasticsearch/bin/elasticsearch

7、后台启动elasticsearch服务

[elk@localhost ~]$ /usr/local/elasticsearch/bin/elasticsearch -d

8、查询ES的集群状态

[elk@localhost ~]$ curl -X GET 'http://172.168.1.157:9200/_cluster/health?pretty'

{

"cluster_name" : "elasticsearch",

"status" : "green",

"timed_out" : false,

"number_of_nodes" : 1,

"number_of_data_nodes" : 1,

"active_primary_shards" : 1,

"active_shards" : 1,

"relocating_shards" : 0,

"initializing_shards" : 0,

"unassigned_shards" : 0,

"delayed_unassigned_shards" : 0,

"number_of_pending_tasks" : 0,

"number_of_in_flight_fetch" : 0,

"task_max_waiting_in_queue_millis" : 0,

"active_shards_percent_as_number" : 100.0

}

# status=green表示服务正常

9、ElasticSearch配置用户名密码

[elk@localhost ~]$ /usr/local/elasticsearch/bin/elasticsearch-setup-passwords interactive

注:这里为了方便演示,密码统一设置为www.yangxingzhen.com

Linux搭建ELK+Filebeat+Nginx+Redis分布式日志管理平台_elasticsearch_02

注:配置了密码之后获取集群状态命令如下

[elk@localhost ~]$ curl --user elastic:www.yangxingzhen.com -X GET 'http://172.168.1.157:9200/_cluster/health?pretty'

Linux搭建ELK+Filebeat+Nginx+Redis分布式日志管理平台_redis_03

10、Elasticsearch常用命令

curl -XDELETE 'http://172.168.1.157:9200/logstash-*' 删除索引(后面为索引名称)

curl -XGET '172.168.1.157:9200/_cat/health?v&pretty' 查看集群状态

curl -XGET '172.168.1.157:9200/_cat/indices?v&pretty' 查看索引

四、安装Kibana

1、下载Kibana软件包

[root@localhost ~]$ wget https://artifacts.elastic.co/downloads/kibana/kibana-7.5.1-linux-x86_64.tar.gz

2、解压Kibana软件包并重命名

[root@localhost ~]$ tar xf kibana-7.5.1-linux-x86_64.tar.gz

[root@localhost ~]$ mv kibana-7.5.1-linux-x86_64 /usr/local/kibana

3、配置Kibana配置文件

[root@localhost ~]$ vim /usr/local/kibana/config/kibana.yml

#配置内容如下


  1. # 配置kibana的端口
  2. server.port: 5601
  3. # 配置监听ip
  4. server.host: "172.168.1.157"
  5. # 配置es服务器的ip,如果是集群则配置该集群中主节点的ip
  6. elasticsearch.hosts: ["http://172.168.1.157:9200"]
  7. elasticsearch.username: "elastic"
  8. elasticsearch.password: "www.yangxingzhen.com"
  9. # 配置kibana的日志文件路径,不然默认是messages里记录日志
  10. logging.dest: /usr/local/kibana/logs/kibana.log
  11. # 配置为中文
  12. i18n.locale: "zh-CN"

4、创建日志目录并授权

[root@localhost ~]# mkdir /usr/local/kibana/logs

[root@localhost ~]# chown -R elk.elk /usr/local/kibana/

5、启动Kibana服务

[root@localhost ~]# su - elk

# 前台启动

[elk@localhost ~]$ /usr/local/kibana/bin/kibana

# 后台启动

[elk@localhost ~]$ /usr/local/kibana/bin/kibana &

温馨提示:可以先前台启动查看日志,正常之后在后台启动。

五、安装Nginx

1)安装依赖软件

[root@localhost ~]# yum -y install make zlib zlib-devel gcc-c++ libtool pcre pcre-devel openssl openssl-devel wget

2)下载Nginx源码包

[root@localhost ~]# wget -c http://nginx.org/download/nginx-1.18.0.tar.gz

3)解压Nginx源码包

[root@localhost ~]# tar zxf nginx-1.18.0.tar.gz

4)进入解压目录,预编译Nginx

[root@localhost ~]# cd nginx-1.18.0

[root@localhost ~]# useradd -s /sbin/nologin www

[root@localhost ~]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-stream

5)编译和安装Nginx

[root@localhost ~]# make && make install

6)检测配置或安装是否成功:

[root@localhost nginx-1.18.0]# /usr/local/nginx/sbin/nginx -t

如果出现下列信息,则表示安装或配置成功。

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

7)配置nginx.conf

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf


  1. user www www;
  2. worker_processes auto;
  3. pid /usr/local/nginx/logs/nginx.pid;
  4. events {
  5. use epoll;
  6. worker_connections 10240;
  7. multi_accept on;
  8. }
  9. http {
  10. include mime.types;
  11. default_type application/octet-stream;
  12. log_format json '{"@timestamp":"$time_iso8601",'
  13. '"host":"$server_addr",'
  14. '"clientip":"$remote_addr",'
  15. '"remote_user":"$remote_user",'
  16. '"request":"$request",'
  17. '"http_user_agent":"$http_user_agent",'
  18. '"size":$body_bytes_sent,'
  19. '"responsetime":$request_time,'
  20. '"upstreamtime":"$upstream_response_time",'
  21. '"upstreamhost":"$upstream_addr",'
  22. '"http_host":"$host",'
  23. '"requesturi":"$request_uri",'
  24. '"url":"$uri",'
  25. '"domain":"$host",'
  26. '"xff":"$http_x_forwarded_for",'
  27. '"referer":"$http_referer",'
  28. '"status":"$status"}';
  29. access_log logs/access.log json;
  30. error_log logs/error.log warn;
  31. sendfile on;
  32. tcp_nopush on;
  33. keepalive_timeout 120;
  34. tcp_nodelay on;
  35. server_tokens off;
  36. gzip on;
  37. gzip_min_length 1k;
  38. gzip_buffers 4 64k;
  39. gzip_http_version 1.1;
  40. gzip_comp_level 4;
  41. gzip_types text/plain application/x-javascript text/css application/xml;
  42. gzip_vary on;
  43. client_max_body_size 10m;
  44. client_body_buffer_size 128k;
  45. proxy_connect_timeout 90;
  46. proxy_send_timeout 90;
  47. proxy_buffer_size 4k;
  48. proxy_buffers 4 32k;
  49. proxy_busy_buffers_size 64k;
  50. large_client_header_buffers 4 4k;
  51. client_header_buffer_size 4k;
  52. open_file_cache_valid 30s;
  53. open_file_cache_min_uses 1;
  54. server {
  55. listen 80;
  56. server_name localhost;
  57. location / {
  58. proxy_pass http://172.168.1.157:5601;
  59. proxy_set_header Host $host;
  60. proxy_set_header X-Real-IP $remote_addr;
  61. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  62. }
  63. }
  64. }

8)创建systemctl管理配置文件

[root@localhost ~]# vim /usr/lib/systemd/system/nginx.service


  1. [Unit]
  2. Description=Nginx Server
  3. Documentation=http://nginx.org/en/docs/
  4. After=network-online.target remote-fs.target nss-lookup.target
  5. Wants=network-online.target

  6. [Service]
  7. Type=forking
  8. PIDFile=/usr/local/nginx/logs/nginx.pid
  9. ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  10. ExecReload=/bin/kill -s HUP $MAINPID
  11. ExecStop=/bin/kill -s TERM $MAINPID

  12. [Install]
  13. WantedBy=multi-user.target

9)启动Nginx服务

[root@localhost ~]# systemctl daemon-reload

[root@localhost ~]# systemctl enable nginx

[root@localhost ~]# systemctl start nginx

六、安装filebeat

1、下载filebeat软件包

[root@localhost ~]# wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.5.1-linux-x86_64.tar.gz

2、解压并重命名

[root@localhost ~]# tar xf filebeat-7.5.1-linux-x86_64.tar.gz

[root@localhost ~]# mv filebeat-7.5.1-linux-x86_64 /usr/local/filebeat

3、编辑filebeat.yml配置文件,配置内容如下

[root@localhost ~]# vim /usr/local/filebeat/filebeat.yml


  1. #========= Filebeat inputs ==========
  2. filebeat.inputs:
  3. - type: log
  4. enabled: true
  5. paths:
  6. - /usr/local/nginx/logs/access.log
  7. multiline:
  8. pattern: '^\d{4}-\d{1,2}-\d{1,2}\s\d{1,2}:\d{1,2}:\d{1,2}'
  9. negate: true
  10. match: after
  11. fields:
  12. logtype: nginx_access
  13. - type: log
  14. enabled: true
  15. paths:
  16. - /usr/local/nginx/logs/error.log
  17. multiline:
  18. pattern: '^\d{4}-\d{1,2}-\d{1,2}\s\d{1,2}:\d{1,2}:\d{1,2}'
  19. negate: true
  20. match: after
  21. fields:
  22. logtype: nginx_error
  23. output.redis:
  24. enabled: true
  25. hosts: ["172.168.1.157:6379"]
  26. password: "c710403c3c97ac97a269d7a6"
  27. key: "all-access-log"
  28. db: 0
  29. timeout: 10

4、创建Filebeat日志目录

[root@localhost ~]# mkdir /usr/local/filebeat/logs

[root@localhost ~]# chown -R elk.elk /usr/local/filebeat

5、启动filebeat服务

[root@localhost ~]# su - elk

[elk@localhost ~]# cd /usr/local/filebeat

# 前台启动

[elk@localhost filebeat]$ ./filebeat -e -c filebeat.yml >>logs/filebeat.log

# 后台启动

[elk@localhost filebeat]$ nohup ./filebeat -e -c filebeat.yml >>logs/filebeat.log >/dev/null 2>&1 &

七、安装logstash

1、下载软件包

[root@localhost ~]# wget https://artifacts.elastic.co/downloads/logstash/logstash-7.5.1.tar.gz

2、解压并重命名

[root@localhost ~]# tar zxf logstash-7.5.1.tar.gz

[root@localhost ~]# mv logstash-7.5.1 /usr/local/logstash

3、创建nginx.conf文件,添加以下内容

[root@localhost ~]# vim /usr/local/logstash/config/nginx.conf


  1. input {
  2. redis {
  3. host => "172.168.1.157"
  4. port => "6379"
  5. db => "0"
  6. password => "c710403c3c97ac97a269d7a6"
  7. data_type => "list"
  8. key => "all-access-log"
  9. codec => json
  10. }
  11. }

  12. filter {
  13. if [fields][logtype] == "nginx_access" {
  14. json {
  15. source => "message"
  16. }

  17. grok {
  18. match => { "message" => "%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:level}" }
  19. }

  20. date {
  21. match => ["timestamp", "yyyy-MM-dd HH:mm:ss,SSS"]
  22. target => "@timestamp"
  23. }
  24. }
  25. if [fields][logtype] == "nginx_error" {
  26. json {
  27. source => "message"
  28. }

  29. grok {
  30. match => { "message" => "%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:level}" }
  31. }

  32. date {
  33. match => ["timestamp", "yyyy-MM-dd HH:mm:ss,SSS"]
  34. target => "@timestamp"
  35. }
  36. }
  37. }

  38. output {
  39. if [fields][logtype] == "nginx_access" {
  40. elasticsearch {
  41. hosts => ["172.168.1.157:9200"]
  42. user => "elastic"
  43. password => "www.yangxingzhen.com"
  44. action => "index"
  45. index => "nginx_access.log-%{+YYYY.MM.dd}"
  46. }
  47. }
  48. if [fields][logtype] == "nginx_error" {
  49. elasticsearch {
  50. hosts => ["172.168.1.157:9200"]
  51. user => "elastic"
  52. password => "www.yangxingzhen.com"
  53. action => "index"
  54. index => "nginx_error.log-%{+YYYY.MM.dd}"
  55. }
  56. }
  57. }

4、启动logstash服务

[root@localhost ~]# chown -R elk.elk /usr/local/logstash

[root@localhost ~]# su - elk

# 前台启动

[elk@localhost ~]$ /usr/local/logstash/bin/logstash -f /usr/local/logstash/conf/nginx.conf

# 后台启动

[elk@localhost ~]$ cd /usr/local/logstash/bin && nohup ./logstash -f /usr/local/logstash/config/nginx.conf >/dev/null 2>&1 &

八、访问Kibana

# 浏览器访问:http://172.168.1.157,出现如下界面

Linux搭建ELK+Filebeat+Nginx+Redis分布式日志管理平台_linux_04

# 输入前面设置的用户名和密码,出现如下界面

Linux搭建ELK+Filebeat+Nginx+Redis分布式日志管理平台_linux_05

# 选择自己浏览,出现以下界面

Linux搭建ELK+Filebeat+Nginx+Redis分布式日志管理平台_linux_06

Linux搭建ELK+Filebeat+Nginx+Redis分布式日志管理平台_elasticsearch_07

分别点击管理--》索引管理,这时候就能看到Nginx的索引信息

Linux搭建ELK+Filebeat+Nginx+Redis分布式日志管理平台_linux_08

1)创建Nginx访问日志索引

索引模式--->>创建索引模式,输入索引模式名称,点击下一步

Linux搭建ELK+Filebeat+Nginx+Redis分布式日志管理平台_redis_09

Linux搭建ELK+Filebeat+Nginx+Redis分布式日志管理平台_redis_10

Linux搭建ELK+Filebeat+Nginx+Redis分布式日志管理平台_elasticsearch_11

2)创建Nginx错误日志索引

索引模式--->>创建索引模式,输入索引模式名称,点击下一步

Linux搭建ELK+Filebeat+Nginx+Redis分布式日志管理平台_redis_12

Linux搭建ELK+Filebeat+Nginx+Redis分布式日志管理平台_elasticsearch_13

Linux搭建ELK+Filebeat+Nginx+Redis分布式日志管理平台_linux_14

点击Discover,就能看到日志数据了,如下图

Linux搭建ELK+Filebeat+Nginx+Redis分布式日志管理平台_redis_15

至此,ELK日志平台收集Nginx日志搭建完成。

  • 输入编号:7649,直达文章
  • 输入m|M,直达目录列表

标签:ELK,Filebeat,redis,local,Redis,nginx,usr,root,localhost
From: https://blog.51cto.com/u_12018693/5980614

相关文章

  • Linux搭建ELK-7.5.1分布式集群并且配置X-Pack
    ELK介绍需求背景业务发展越来越庞大,服务器越来越多各种访问日志、应用日志、错误日志量越来越多,导致运维人员无法很好的去管理日志开发人员排查问题,需要到服务器上查日志,不......
  • Zabbix监控Redis性能状态
    Zabbix监控Redis性能状态监控原理示意图:监控原理Zabbix-server通过agent监控中配置文件调用shell脚本。Redis中提供redis-cli命令使用info可以获得redis大部分信息。在使用......
  • Tomcat 8.x基于Redis Session会话保持
    什么是Redis?Redis是一个开源的使用ANSIC语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。一、与其他用户状态保存方案比较一般开......
  • Docker 安装 Redis
    Docker安装RedisRedis是一个开源的使用ANSIC语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value的NoSQL数据库,并提供多种语言的API。Redis是一个开源(BSD许......
  • 使用redisTemplate时,Lists和Sets报错
    在使用RedisUtils工具类的时候,Lists和Sets报错,原因是由于缺少谷歌的依赖,只需要添加对应的依赖即可1<dependency>2<groupId>com.google.guava</groupId>3......
  • Redis源码剖析系列博文开篇&大纲
    今年我启动了好几个比较有挑战的个人项目,比如写一门编程语言、成为一名视频UP主、写科幻小说……这些项目目前进度都很堪忧,一方面这些项目挑战都比较大,另一方面业余时间还......
  • redis 批量删除key
    以14号库为例,8号库照猫画虎即可1.首先先尝试连接redis,-h指定地址-p指定端口-n指定第几个库切记不要先执行keys*,可以先执行dbsize查看一下key的数量再决定是否执行......
  • Redis数据清理
    Windows服务器1、打开cmd命令窗口,切换至Redis安装目录下的bin文件夹2、在cmd命令窗口,输入连接Redis指令:./redis-cli.exe-h127.0.0.1-p63893、连接成功后,如果Redis......
  • SpringDataRedis:第一章:简介
    SpringDataRedis简介项目常见问题思考我们目前的系统已经实现了广告后台管理和广告前台展示,但是对于首页每天有大量的人访问,对数据库造成很大的访问压力,甚至是瘫痪。那如......
  • Redis 学习记录
    下载与安装Redisredis......