## ELK 官网:
https://www.elastic.co/cn/what-is/elk-stack
## ELK是什么:
“ELK”是三个开源项目的首字母缩写,这三个项目分别是:Elasticsearch、Logstash 和 Kibana。Elasticsearch 是一个搜索和分析引擎。Logstash 是服务器端数据处理管道,能够同时从多个来源采集数据,转换数据,然后将数据发送到诸如 Elasticsearch 等“存储库”中。Kibana 则可以让用户在 Elasticsearch 中使用图形和图表对数据进行可视化。
实验环境:两台虚拟机(最小化安装,内核2G)
130: elasticsearch+ logstash
132: kibana
准备工作
关闭防火墙和selinux(最好第一步就做,方便)
systemctl stop firewalld
setenforce 0
同步时间
yum -y install ntp
ntpdate pool.ntp.org
安装所需软件
yum -y install vim vi net-tools unzip
开始安装
1、安装elasticsearch(先安装java环境)
上传ELK压缩包并解压
unzip ELK
进入压缩包
cd ELK
[root@localhost ELK]# ll
总用量 624860
-rw-r--r--. 1 root root 114065764 3月 12 2019 elasticsearch-6.6.2.rpm
-rw-r--r--. 1 root root 169983496 11月 19 2017 jdk-8u131-linux-x64_.rpm
-rw-r--r--. 1 root root 185096267 3月 12 2019 kibana-6.6.2-x86_64.rpm
-rw-r--r--. 1 root root 170703770 11月 13 2019 logstash-6.6.0.rpm
安装javaj环境
[root@localhost ELK]# rpm -ivh jdk-8u131-linux-x64_.rpm
安装配置elasticsearch
[root@localhost ELK]# yum -y install elasticsearch-6.6.2.rpm
[root@localhost ELK]# systemctl daemon-reload
[root@localhost ELK]# systemctl enable elasticsearch
[root@localhost ELK]# systemctl start elasticsearch
检测是否启动
[root@localhost ELK]# netstat -anpt |grep java
tcp6 0 0 192.168.159.130:9200 :::* LISTEN 11327/java
tcp6 0 0 192.168.159.130:9300 :::* LISTEN 11327/java
#这里的俩个端口:
#一个为内部访问
#一个为客户访问
[root@localhost ELK]# vim /etc/elasticsearch/elasticsearch.yml
[root@localhost ELK]# cat /etc/elasticsearch/elasticsearch.yml |grep -v "^#"
cluster.name: rjc
node.name: node-1
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
network.host: 192.168.159.130
http.port: 9200
[root@localhost ELK]# systemctl start elasticsearch
[root@localhost ELK]# netstat -anpt | grep java
[root@localhost ELK]# tailf /var/log/elasticsearch/rjc.log
2、安装配置logstash(测试检测messages+secure)
[root@localhost ELK]# yum -y install logstash-6.6.0.rpm
[root@localhost ELK]# cd /etc/logstash/conf.d/
[root@localhost conf.d]# vim messages.conf
#input日志输入模块:日志的获取方式和路径input
input {
file {
path => "/var/log/messages"
type => "messages-log"
start_position => "beginning"
}
}
#output日志的输出模块:导出你的数据
output {
elasticsearch{
hosts => "192.168.159.130:9200"
index => "messages_log-%{+YYYY.MM.dd}"
}
}
[root@localhost conf.d]# vim secure.conf
input {
file {
path => "/var/log/secure"
type => "secure-log"
start_position => "beginning"
}
}
output {
elasticsearch{
hosts => "192.168.159.130:9200"
index => "secure_log-%{+YYYY.MM.dd}"
}
}
[root@localhost conf.d]# cd /etc/logstash/
[root@localhost logstash]# vim pipelines.yml
- pipeline.id: message
path.config: "/etc/logstash/conf.d/message.conf"
- pipeline.id: secure
path.config: "/etc/logstash/conf.d/secure.conf"
[root@localhost logstash]# chmod -R 777 /var/log/
[root@localhost logstash]# systemctl start logstash
[root@localhost logstash]# tailf /var/log/logstash/logstash-plain.log
#全部为info则视为成功进行下一步。
#如果logstash 无法启动报错:
3、安装kibana
[root@localhost logstash]# cd
[root@localhost ~]# cd ELK
[root@localhost ELK]# scp kibana-6.6.2-x86_64.rpm root@服务端ip:/root/
切换到服务端
[root@localhost ~]# yum -y install kibana-6.6.2-x86_64.rpm
[root@localhost ~]# vim /etc/kibana/kibana.yml
[root@localhost ~]# cat /etc/kibana/kibana.yml | grep -v "^#" | sed '/^$/d'
server.port: 5601
server.host: "192.168.159.132"
elasticsearch.hosts: ["http://192.168.159.130:9200"]
[root@localhost ~]# systemctl enable kibana
[root@localhost ~]# systemctl start kibana
[root@localhost ~]# yum -y install net-tools
[root@localhost ~]# netstat -anpt |grep 5601
tcp 0 0 192.168.159.132:5601 0.0.0.0:* LISTEN 9740/node
[root@localhost ~]#
效果