架构
elk比较常见的架构:
本文用的架构:
ELK是Elasticsearch、Logstash、Kibana的简称,这三者是中心套件,但并非悉数。
Elasticsearch是实时全文查找和剖析引擎,提供收集、剖析、存1 + O z储数据三大功用;是一套开放REST和JAVA API等结构提供高效查找功用,可扩展的分布式系统。它构建于Apache Lucene查找引擎库之上。
Logstash是一个用来收集、剖析、过滤日志的东西。它支持几乎任何类型的日志,包含系统日志、过错日志和自定义应用程序日志。它能够从许多来历接纳日志F X U 7 C v o l,这些来D o n & 7 ; H历包含 syslog、消息传递(例如 RabbitMQ)和JMX,它能够以多种方法输出数据,包含电子邮件、websock@ ) @ets和| a 5 d n m b , BElasticsearch。(能够重视下/ B ] B =beats,有代替logstash shia 7 h &pper的趋势)
Kibana是一个根据Web的图形界面,用于查找、剖析和可视化存储在 Elasticsearch目标中的日志数据。它利用Elasti) h c s Ccsearch的REST接口来检索数据,不只答应用户` E W o ? p i P创立他们自己的数据的定制仪表板视图,还答应他们以特别的方法C & B @ ! l V查询和过滤数据。
装置
网上许多关于elk介绍的例子都2 * M h 2 K & P是根据老版别介绍的,最新版别的elk的装置和老版别有些区别,下面的装置过程都是根据最新版别的es、logstash、kibana根据centos6.3装置。, o M 8 u
网上装置jdk的介绍许多,这里不做介绍(装置jdo q q s j M ] gk1.8,否则后续发动最新的eL @ s a | *s、kibana会报错)
装置装备lo1 A ? l Zgstash
mkdir -p /home/disk2/log/elk
cd8 q o A O n K E Y /home/disk2/log/elk
wget https://artifacts.elastic.co/downloads/logstash/logstash-5.4.0.zip (如机器没外网拜访权限可先下载到本地再传到服务[ b K ]器,下同)
unzip logstash-5.4.0.zip
#修正logstash装备
cd logstash-5.4.0/config
vi$ 8 G Qm logh j 9 zstash.yml
修正pipeline.workers为当时cpu数量
装置装备es
cd /home/m { h F h Adisk2/log/elk
wget https:/: t t/artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.46 % F X u.0.zip
unzipV $ d j Y : 5 & x elasticsearch-5.4.0.zip
#装备
cd elasF _ J G p sticsearch-5.4.w w 50/config
vim elasticsearch.M G 4 k q 4yml
#修正如下内f q r容
cluster.name: log
node.name: na @ q & { t @ $ode-1
path.data: /home/disk2/log/elk/elasticsearch-5.4.0/data
path.logs: /home/disk2/log/ei ^ ulk/elasticsearc% n F 9 th-5.4.0/logs
ne{ g o 3 d / m V Jtwork.host: you.website.com
http.port: 8000# 默许9200端口
http.cors.enabled: true
http.cors.allow-origin: "*"
bootstrap.system_call_filter: false#重要,centos6需添加此行装备
#修正系统装备
vim /etc/security/limits.X m t (conf
添加装备:
work soft nofile 65536
work hard noa X _ B H #file 65536
work soft memlock unliz p 7 q 1mited
work hard meml{ ^ 1 ~ Yock unlimited
vim /etc/sysctl.v W % p K D J ] yconf
添加装备
vm.l P Q f imax_map_count = 262144
履行sysctl -p
vim /etc/security/limits.d/90-nproc.conf
添加装O z z备
wr p o [ R q york soX e h u bft nproc 65535
装置装备elasticsearch-head插件
#装置nodejs、xz
yum install xz
yum install nodejs
#此刻0 j m d 2 S J ( 履行npm -v检查npm是否装置,B s o 2 T不出意外现已装置好了
#下载elasticsearch-head
#下载地址:htz m y U G Stps://gi* h T ` V g S ithub.com/mobz/elasticsearch-head,下载后解压缩。
#进入elasticsearch-head目录履行
运用npm装置grunt:
npm install grunt
npm install –g grunt–cli
npm装置依靠:
到elasticsearch-head-master目R f X = e录下,运行命令:
npm install
假如速度较慢或者装置失利,能够运用国内镜像:
npm install -g cnpm --registry=https://registry.npm.taobao.org
#修正Gruntfile.js(通过8100端口拜访; F { 3 0 ( @ v &es heaW C { ~d)
connect: {
serverB _ G H D G # n: {
options: {
hostname: 'you.website.com',
port:} n 8 K : 8 8100,
base: '.',
keepac / : 8 { Ylive: true
}
}
}
#修正_site/app.js,修正衔接es的地址
thiw # H _ . { 1 ` ys.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://you.website.com:8000";
发动:
node_modules/grunt/bin/grunt serveh M H ~ Wr &
#浏览器拜访http://you.website.com:8100/
#可参考Q i : Q P b - c ehttp://blog.csdn.net/napoay/article/details/53896348
装置装备kibana
cK G e Z Xd /home/disk2/log/elk
wget https://artifacts.elastic.co/downloads/kibana/x = D kkibana-5.4.0-linux-x86_64.tar.gz
tar -zvxf kibana-5.4.0-w N [ X D D B 5linux-x86_64.tar.gz
mv kibana-5.4.0-linux-x86_64 kibana-5.4.0
#修正装备
cd kibana-5.4.0/config
vim kibana.yml
修正如下装备:
server.port: 8100
server.hb ^ X * 6 : 1 `ost: "yoQ t % qu.webs8 v W ~ % C R Lite.com"
elasticsearch.url: "c Y 1 + ,http://you.website.com:8000"
运用
装备logstash
假p ~ T c . Y W i如日志现已汇总到了一台机器,而且通过shell脚本进行了指定格局切分(能够运用logstash gork正则匹配字段,但网上说功率很低,待承认),这里采用dissect过滤,关于logstash的filter能够进一步研讨下
在logstash下创立K z t M v 1conf.d目录
vimh 8 G % k J t bpslog.conf
添加如下装备(本装备包] Z x k ! ^ G ^含了filter:dessect,输出到es,es装备自定义模板):
input
{
file {
path => ["/home/disk2/log/orp/formatedlog/bpslU l c xog/*w h F/*.log"]
type => "bpsloU @ g j ` R - f Kg"
sU Y 1 + E U g y }tart_position => "beginning"
}
file {
path => ["/home/disk2/log/orp/formatedlog/manhatta| L X ; z J wn/*/*.log"]
type => "manhattanlog"
star. | 3 7 lt_position => "beginning"
}
}
filter {
if ([messag~ f ~ - 9 }e] == "") {
drop {}
}
if [type] == "bpslog" {d ) ~ I J K ~
dissect {
mapping => {
"message" => w [; "%{app}mysplit%{bid}mysplit%{opcode}mysplit%{uri}mysplit%{logId}mysplitL A ] & R%{logtime}mysplit%{bps}"
}
}
}
else if [type] == "manhattanlog" {
di| G S w F i y 4ssect {
mapping => {
"messs a %age") U B u T # k M =&; z e i W (gt; "%{app}mysplit%{bid}mysplit%{uri}mysplit%{logId}mysplit%{logtime}mysplit%{raldata}"
}
}
}
}
output{
if [typeE ^ , . F] == "bpslog" {
elasticsearch {
host~ } Ts => ["you.website.com:82: X d s a ^ U 801"]
index => "B Q T O ~ 0 R%{type}-%{+YYYY.MM.dd}"
template_overwrite => true
template =/ B ? 9> "/home/disk2/log/elk/logstash-5.4.0/template/bps.json"
}
}
else if [type] == "manhattanlog" {
elasticsearch {
hosts => [2 = g { C"you.websiteo * 4.com:8000"]
index => "%{type}-%{+YYYY.MM.dd}i ? O"
template_overwrite => true
template => "/home/dX G 2 G 7 ) pisk2/log/elk/logstash-5.4.0/template/manhattan.j& [ M f 8 A e |son"
}
}
stdout{codec=>rubydebug}
}
自定义 % r d Z R O模板装备
{
"bps" : {
"template": "bpslog-*",
"settings": {
},
"mappings" : {
"log_ ( x / ` i @ Hs" : {
"propert{ Q x Aies" : {
"@timestamp" : {
"type" : "date",
"format" : "datA Q OeOptionalTime",
"doc_values" : true
},e | ( , [ ; ;
"@version" : {
"type" : "string",
W 5 R c / J + o f"index" : "not1 v v = V n e_analyzed", #不分词
},
"app" : {
"type" : "string",
"index" :H K j Z $ ; [ [ V "not_analyzed",
},
"bid" : {
"type" : "integer",
"indexa Q 7 + D B 8" : "not_analyzed",
},
"opcode" : {
"type" : "integer",
"index" : "not_analyzed",
},
"uri" : {
"type" : "stY V W i 6 Z 8 Yring",
"index" : "no",
}
"logId" : {
"type" : "integer",
"index" : "not_analyzed",
},
"logtime" : {
"type" : "string",
"index" : "noi M E ( v & S W 2t_an@ ~ Galyzed",
},
"bps" : {
"type" :f = M C p ! "string",
"index" : "no",
}& m J y - m,
}
}
}
}
}
发动logstash
cd /home/disk2/log/elk/logstash-5.4.0/bin
./logstash -f ../conf.d &
发动es
cd /home/disk2/log/elk/elasticsearch-5.4.0/bin
./elasticsearch -d
运用kibana
kibana.logstash( l 1 g H Y.es/content/kib…
装置X-pack插件
实践拓宽
场景
1) datasource->logstash->ela) s !sticsearch->kibana
2) datasou` u a Crce->filp . j u R Q k K Jebeat->logstash-> elast{ b + O C _ & T ticsearT B Lch->kibana
3) datasource->filebeat->logstash->redis/kafka->logstash-> elasticsearch->kib+ = n : w Y Kana
4) kafka->logstash-> elasticsearch->kiban7 N w z i &a
5) datasource->filebeat->kafka->logstash->elasticsearch->kibana(最常用)
6) filebeatSSL加密传输
7) datasource->logstash->redis/kafka->logstash->elasticsearch->kibana
8) mysql->logstash->elasticsearch->kibana
www.cnblogs.com/qingqing746…
发表回复
要发表评论,您必须先登录。