elk

kibana图表:
    登录--左侧面板选择visualize--点击“+”号--选择图表类型--选择索引--Buckets--x-Axis--Aggregation(选择Terms)--
    Field(remote_addr.keyword)--size(5)--点击上方三角标志
kibana监控(x-pack):
    登录--左侧面板选择--Monitoring--启用监控
###################################################################################    
构建filebeat+redis+logstash+es+kibana架构

1.安装redis,并启动
(1)准备安装和数据目录
    mkdir -p /data/soft
    mkdir -p /opt/redis_cluster/redis_6379/{conf,logs,pid}

(2)下载redis安装包
    cd /data/soft
    wget http://download.redis.io/releases/redis-5.0.7.tar.gz

(3)解压redis到/opt/redis_cluster/
    tar xf redis-5.0.7.tar.gz -C /opt/redis_cluster/
    ln -s /opt/redis_cluster/redis-5.0.7  /opt/redis_cluster/redis
    
(4)切换目录安装redis
    cd /opt/redis_cluster/redis
    make && make install 
    
(5)编写配置文件
vim /opt/redis_cluster/redis_6379/conf/6379.conf
添加:
bind 127.0.0.1 192.168.1.108
port 6379
daemonize yes
pidfile /opt/redis_cluster/redis_6379/pid/redis_6379.pid
logfile /opt/redis_cluster/redis_6379/logs/redis_6379.log
databases 16
dbfilename redis.rdb
dir /opt/redis_cluster/redis_6379
保存退出

(6)启动当前redis服务
redis-server /opt/redis_cluster/redis_6379/conf/6379.conf

2.修改filebeat配置文件,output给redis
(参考文档:https://www.elastic.co/guide/en/beats/filebeat/6.6/index.html)
(1)修改filebeat配置output指向redis,重启
vim /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
  enabled: true
  paths:
    - /var/log/nginx/access.log
  json.keys_under_root: true
  json.overwrite_keys: true
  tags: ["access"]

- type: log
  enabled: true
  paths:
    - /var/log/nginx/error.log
  tags: ["error"]

setup.template.settings:
  index.number_of_shards: 3

setup.kibana:

output.redis:
  hosts: ["192.168.1.104"]
  key: "filebeat"
  db: 0
  timeout: 5
保存退出
重启服务:systemctl restart filebeat

(2)测试访问网站,登录redis,查看键值
redis-cli                #登录
keys *                    #列出所有键
type filebeat              #filebeat为键值名
LLEN filebeat            #查看list长度
LRANGE filebeat 0 -1     #查看list所有内容
    
3.安装logstash,收集redis的日志,提交给es
(1)安装logstash(安装包提前放在了/data/soft下)
cd /data/soft/
rpm -ivh logstash-6.6.0.rpm 
(2)修改logstash配置文件,实现access和error日志分离
vim /etc/logstash/conf.d/redis.conf
添加:
input {
  redis {
    host => "192.168.1.104"
    port => "6379"
    db => "0"
    key => "filebeat"
    data_type => "list"
  }
}

filter {
  mutate {
    convert => ["upstream_time","float"]
    convert => ["request_time","float"]
  }
}

output {
  stdout {}
   if "access" in [tags] {
    elasticsearch {
      hosts => ["http://192.168.1.104:9200"]
      index => "nginx_access-%{+YYYY.MM.dd}"
      manage_template => false
    }
   }
   if "error" in [tags] {
    elasticsearch {
      hosts => ["http://192.168.1.104:9200"]
      index => "nginx_error-%{+YYYY.MM.dd}"
      manage_template => false
    }
   }
}
保存退出
重启logstash:/usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/redis.conf

你可能感兴趣的:(redis,elk,nginx)