赞
踩
`简介`
ELK是目前主流的一种日志系统,三个开源软件的缩写,分别表示:Elasticsearch , Logstash, Kibana , 它们都是开源软件。
Elasticsearch是一个分布式、RESTful 风格的搜索和数据分析引擎,能够解决不断涌现出的各种用例。
Logstash 是免费且开放的服务器端数据处理管道,能够从多个来源采集数据,转换数据,然后将数据发送到您最喜欢的“存储库”中。采用jruby语言开发。
Kibana 是一个免费且开放的用户界面,能够对 Elasticsearch 数据进行可视化,并让在 Elastic Stack 中进行导航。可以进行各种操作,从跟踪查询负载,到理解请求如何流经整个应用。
`工作原理`
收集日志-> 存储分析-> 界面展示->
logstash-> elasticsearch-> kibana
1、环境描述
10.1.0.103 安装jdk,elasticsearch7.x,logstash7.x,kibana7.x
2、安装jdk
下载地址:https://download.oracle.com
(1)解压安装包
tar xvf jdk-8u141-linux-x64.tar.gz
(2)配置环境变量(解压路径及下载版本跟需调整)
echo ' export JAVA_HOME=/usr/local/java/jdk1.8.0_141/' >> /etc/profile
echo ' export JAVA_BIN=/usr/local/java/jdk1.8.0_141/bin' >> /etc/profile
echo ' export PATH=$PATH:$JAVA_HOME/bin' >> /etc/profile
echo ' export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar' >> /etc/profile
echo ' export JAVA_HOME JAVA_BIN PATH CLASSPATH' >> /etc/profile
(3)刷新环境变量
source /etc/profile
(4)查看安装情况
java -version
3、安装elasticsearch
(1)配置elasticsearch源
vim /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
(2)安装elasticsearch
yum install elasticsearch -y
(3)配置elasticsearch
vim /etc/elasticsearch/elasticsearch.yml
17 cluster.name: my-application
23 node.name: elk-1
56 network.host: 0.0.0.0
61 http.port: 9200
74 cluster.initial_master_nodes: ["elk-1"]
#head插件连接es
http.cors.enabled: true
http.cors.allow-origin: "*"
说明:启动内存和其他参数跟机器需求调整
(4)启动
/etc/init.d/elasticsearch start
(5)测试
curl 127.0.0.1:9200
4、安装elasticsearch-head插件
(1)安装nodejs
curl -sL https://rpm.nodesource.com/setup_11.x | bash -
yum install nodejs -y
(2)使用git安装elasticsearch-head
yum install git -y
git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install
说明:安装报错,可参考https://blog.csdn.net/weixin_44320761/article/details/121291103?spm=1001.2014.3001.5501
(3)后台启动
nohup npm run start >/dev/null 2>&1 &
(4)浏览器访问测试
http://IP:9100
5、安装logstash
(1)安装
yum install -y logstash
(2)创建一个软连接(默认安装在/usr/share下)
ln -s /usr/share/logstash/bin/logstash /bin/
(3)测试
logstash -e 'input { stdin { } } output { stdout {} }'
(4)标准输出elasticsearch中
logstash -e 'input { stdin { } } output { elasticsearch { hosts => ["10.1.0.103:9200"] } stdout { codec => rubydebug }}'
(5)logstash使用配置文件配置系统日志
vim logstash.conf
input {
file {
path => "/var/log/messages"
type => "system"
start_position => "beginning"
}
}
output {
if [type] == "system" {
elasticsearch {
hosts => ["10.1.0.103:9200"]
index => "test-system-%{+YYYY.MM.dd}"
}
}
}
(6)后台启动
nohup logstash -f logstash.conf >/dev/null 2>&1 &
6、安装kibana
(1)安装
yum install kibana -y
(2)配置kibana
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.hosts: ["http://10.1.0.103:9200"]
kibana.index: ".kibana"
(3)启动
/etc/init.d/kibana start
(4)浏览器访问
http://IP:5601
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。