ELK6.6搭建
ELK简介:ELK主要有elasticsearch、logstash、kibana组成。elasticsearch主要功能为存储日志,logstash为收集日志,kibana提供页面展现。最为重要的是elasticsearch,存储日志组件一旦丢失,日志数据就会丢失。logstash和kibana可以重复部署,不影响数据存储。
ELK工作模式:
环境介绍:
192.168.0.9 elasticsearch kibana logstash
elasticsearch、logstash 需要java环境的支持,所以需要先安装jdk
一、elasticsearch安装
1、解压缩
tar zxf /opt/elk/elasticsearch-6.6.1.tar.gz -C /usr/local/
mv elasticsearch-6.6.1 elasticsearch
2、修改elasticserach配置文件
[root@localhost config]# egrep "^[^#]" elasticsearch.yml
cluster.name: es-cluster
bootstrap.memory_lock: true
node.name: node-1
network.host: 0.0.0.0
http.port: 9200
cluster.routing.allocation.disk.threshold_enabled: true
cluster.routing.allocation.disk.watermark.low: 94%
cluster.routing.allocation.disk.watermark.high: 96%
cluster.routing.allocation.disk.watermark.flood_stage: 98%
discovery.zen.minimum_master_nodes: 1
3、修改系统参数
vim /etc/security/limits.conf
#@student - maxlogins 4
* soft nofile 65536
* hard nofile 65536
* - nproc 10240
* soft memlock unlimited
* hard memlock unlimited
vim /etc/sysctl.conf
vm.max_map_count=655360
fs.file-max=655360
4、创建elsearch用户
groupadd elsearch
useradd elsearch -g elsearch -p elasticsearch
5、切换es用户启动
su - elsearch
/usr/local/elas/bin/elasticsearch -d
6、web界面查看
二、logstash安装
1、解压logstash
tar zxf logstash-6.6.1.tar.gz -C /usr/local/
mv logstash-6.6.1 logstash
2、修改配置文件
vim /usr/local/logstash/config/logstash.yml
# 数据及日志存储目录
path.data: /usr/local/logstash/data
path.logs: /usr/local/logstash/log
# 每次发送的事件数
pipeline.batch.size: 200
3、编写logstash配置文件,收集nginx日志(nginx部署在本机)
[root@localhost config]# cat logstash.conf
input {
file {
path => "/usr/local/nginx/logs/access.log"
}
}
output {
elasticsearch {
#发送日志给elasticserach
hosts => ["http://192.168.0.9:9200"]
}
}
4、启动logstash
/usr/local/logstash/bin/logstash -f /usr/local/logstash/config/logstash.conf &>>/tmp/logstash.log &
三、kibana安装
1、解压
tar /opt/elk/kibana-6.6.1-linux-x86_64.tar.gz -C /usr/local/
mv kibana-6.6.1 kibana
2、修改配置文件
[root@localhost config]# egrep "^[^#]" /usr/local/kibana/config/kibana.yml
server.port: 5601 #开启访问端口为5601
server.host: "0.0.0.0" #监听全网
3、启动kibana
/usr/local/kibana-6.6.0/bin/kibana >/tmp/kibana.log &>>/tmp/kibana.log &
四、访问kibana
192.168.0.9:5601