centos下ELK5.4.1搭建部署详解
ELK5.4.1搭建部署大纲:
一、简介
二、Elasticsearch
三、Logstash
四、Kinaba
一、简介
1、核心组成
ELK由Elasticsearch、Logstash和Kibana三部分组件组成;
Elasticsearch是个开源分布式搜索引擎,它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等。
Logstash是一个完全开源的工具,它可以对你的日志进行收集、分析,并将其存储供以后使用
kibana 是一个开源和免费的工具,它可以为 Logstash 和 ElasticSearch 提供的日志分析友好的 Web 界面,可以帮助您汇总、分析和搜索重要数据日志。
2、四大组件
Logstash: logstash server端用来搜集日志;
Elasticsearch: 存储各类日志;
Kibana: web化接口用作查寻和可视化日志;
Logstash Forwarder: logstash client端用来通过lumberjack 网络协议发送日志到logstash server;
3、ELK工作流程
在需要收集日志的所有服务上部署logstash,作为logstash agent(logstash shipper)用于监控并过滤收集日志,将过滤后的内容发送到Redis,然后logstash indexer将日志收集在一起交给全文搜索服务ElasticSearch,可以用ElasticSearch进行自定义搜索通过Kibana 来结合自定义搜索进行页面展示。
https://s2.运维网.com/wyfs02/M00/98/1E/wKioL1k3psfQOlrzAAG5FVmSTyk026.png
4、ELK的帮助手册
ELK官网下载:https://www.elastic.co/downloads/
ELK官网文档:https://www.elastic.co/guide/index.html
ELK中文手册:http://kibana.logstash.es/content/elasticsearch/monitor/logging.html
注释
ELK有两种安装方式
(1)集成环境:Logstash有一个集成包,里面包括了其全套的三个组件;也就是安装一个集成包。
(2)独立环境:三个组件分别单独安装、运行、各司其职。(比较常用)
本实验也以第二种方式独立环境来进行演示;单机版主机地址为:10.254.21.18
二、Elasticsearch
1.安装java运行环境
ELK 5.4.1版本对JDK的最低要求是1.8,安装java_1.8版本
解压jdk-8u131-linux-x64.tar.gz
tar zxvf jdk-8u131-linux-x64.tar.gz 添加配置,在/etc/profile里面添加如下:
export JAVA_HOME="/usr/local/jdk1.8.0_131"
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$HADOOP_HOME/bin:$PATH
保存退出,在命令行输入./etc/profile并回车使其生效。
2.关闭防火墙
service iptables stop
chkconfig iptables off
4.新建用户
默认情况elasticsearch是不允许root用户直接启动的
groupadd elk
useradd elk -g elk
至此,前期准备工作结束。
5.安装elasticsearch
从官网下载的elasticsearch-5.4.1.tar.gz
新建/usr/local/elk/目录,在该路目下解压:
tar zxvf elasticsearch-5.4.1.tar.gz
mv elasticsearch-5.4.1 elasticsearch
配置
cd elasticsearch
vim config/elasticsearch.yml
network.host: 192.168.1.104 # 主机IP
http.port: 9200 # api接口url
# 以下两个为允许跨域,主要是5.1版本的head插件和以往安装的不一样
http.cors.enabled: true
http.cors.allow-origin: "*"
启动(elasticsearch目录下)
su elk
./bin/elasticsearch
若是没有启动成功,可以到/var/log/elasticsearch/elasticsearch.log里看到这两条错误日志
max file descriptors for elasticsearch process likely too low, increase to at least
max number of threads for user likely too low, increase to at least 解决第一个,编辑limits.conf
vi /etc/security/limits.conf
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
解决第二个,进入limits.d目录下修改配置文件
vi /etc/security/limits.d/90-nproc.conf
修改如下内容:
* soft nproc 1024
#修改为
* soft nproc 2048
如果虚拟机内存小,也是启动不起来的,需加大内存。
elasticsearch安装使用常见问题及解决:http://xiumin.blog.运维网.com/6205237/1933174
6.安装elasticsearch-head插件
5.4版本的elasticsearch没有提供直接插件安装方法,但在该github上该插件作者给出了方法。
git clone git://github.com/mobz/elasticsearch-head.git
如果虚拟机上没有安装node,则要安装node、npm、grunt。
wget https://nodejs.org/dist/v6.11.0/node-v6.11.0-linux-x64.tar.xz解压node-v6.11.0-linux-x64.tar.xz
tar.xz文件分两步解压
xz -d node-v6.10.3-linux-x64.tar.xz
tar xvf node-v6.10.3-linux-x64.tar
#设置软连接
ln -s /usr/local/elk/node-v6.10.3-linux-x64/bin/node /usr/sbin/
ln -s /usr/local/elk/node-v6.10.3-linux-x64/lib/node_modules/grunt/bin/grunt /usr/sbin/
# 设置npm代理镜像
npm config set registry https://registry.npm.taobao.org # 安装、配置grunt
npm install -g grunt
ln -s /usr/local/elk/node-v6.10.3-linux-x64/lib/node_modules/grunt/bin/grunt /usr/sbin/grunt安装head
npm install修改_site/app.js
// 把localhost改为ip
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://10.254.21.18:9200";
修改Gruntfile.js
connect: {
server: {
options: {
hostname: "0.0.0.0", #这里
port: 9100,
base: '.',
keepalive: true
}
}
}
启动(后台运行)
nohup grunt server & https://s2.运维网.com/wyfs02/M00/98/1F/wKiom1k3rpegVQvuAADRsYXqyqo862.png-wh_500x0-wm_3-wmp_4-s_1887301650.png
三、Logstash
1.安装logstash-5.4.1.tar.gz
在/usr/local/elk/目录下:
tar zxvf logstash-5.4.1.tar.gz
mv logstash-5.4.1 logstash2.写入elasticsearch
cd logstash
vim conf/elastic.conf
input {
file {
path => "/usr/local/openresty/nginx/logs/access.log"#要收集的日志文件
}
}
output {
elasticsearch {
hosts => "10.254.21.18"
index => "nginx-access-%{+YYYY.MM.dd}"
}
stdout {
codec => rubydebug
}
}
3.文件方式启动
/usr/local/elk/logstash/bin/logstash -f /usr/local/elk/logstash/config/elastic.conf
4.在elasticsearch中查看
https://s3.运维网.com/wyfs02/M00/98/20/wKioL1k3r7yj1nX_AAHbvth19BU871.png
四、Kinaba
1.解压kibana-5.4.1-linux-x86_64.tar.gz
在/usr/local/elk/目录下,
tar zxvf kibana-5.4.1-linux-x86_64.tar.gz
mv kibana-5.4.1-linux-x86_64 kibana
2.配置
cd /usr/local/elk/kibana/config
vim kibana.yml
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.url: "http://10.254.21.18:9200"
3.启动(后台运行)
cd /usr/local/elk/kibana/bin/
nohup ./kibana &
4.kibana索引模式配置
Kibana在网页打开后会自动跳转管理页面,配置索引模式
https://s2.运维网.com/wyfs02/M01/98/1F/wKiom1k3sL6hEvCFAAGRoTfJ828031.png
图1
https://s1.运维网.com/wyfs02/M02/98/20/wKioL1k3sL_AQ80fAAAqM4DRrEE303.png
图2
上面两图中红框中index索引必须一致,图一中的create按钮才会出现。然后点击create后大功告成。
如有不明白之处,参见:kibana创建新的index patterns
5.效果图
https://s5.运维网.com/wyfs02/M00/98/1F/wKiom1k3sQXC4NYBAAI4rNayor0771.png-wh_500x0-wm_3-wmp_4-s_177006685.png
至此ELK搭建已大功告成。
页:
[1]