elk搭建實戰(zhàn)

elk搭建實戰(zhàn)

1 安裝elasticsearch

1.1安裝elasticsearch

ES中文文檔地址:https://es.xiaoleilu.com

ES下載地址:https://www.elastic.co/downloads/elasticsearch

解壓:tar -zxvf elasticsearch-5.6.2.tar.gz

cd elasticsearch-5.6.2/ ? ?

運行

./bin/elasticsearch

./bin/elasticsearch -d????????? #后臺運行

tail -f logs/elasticsearch.log?????????? #查看日志

注意:

elasticsearch5.0啟動失敗,出現(xiàn)如下提示:

1、Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot allocate memory' (errno=12)

由于elasticsearch5.0默認分配jvm空間大小為2g,修改jvm空間分配

#?vim?config/jvm.options

-Xms2g

-Xmx2g

修改為

-Xms512m

-Xmx512m

驗證:elasticsearch --version

注:ES有執(zhí)行腳本的能力,因安全因素,不能在root用戶下運行,強行運行會報如下錯誤:

org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root

解決方案:

groupadd es????????? #增加es組

useradd es -g es -p es123456 ? ? ? ? ?#增加es用戶并附加到es組

chown -R es:es elasticsearch-5.6.2 ? #給目錄權(quán)限

su es????????? #使用es用戶

./bin/elasticsearch -d ???????? #后臺運行es

外網(wǎng)訪問

vi conf/elasticsearch.yml

修改network.host: 0.0.0.0

再次啟動linux可能出現(xiàn)如下類似錯誤

bootstrap checks failed

max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]

解決方案

1、vi /etc/sysctl.conf

設(shè)置fs.file-max=655350

保存之后sysctl -p使設(shè)置生效

2、vi /etc/security/limits.conf 新增

* soft nofile 655350

* hard nofile 655350

3、重新使用SSH登錄,再次啟動elasticsearch即可。

外網(wǎng)訪問:serverip:9200/


2、max number of threads [1024] for user [elasticsearch] is too low, increase to at least [2048]

修改?/etc/security/limits.d/90-nproc.conf

* ? ? ? ? ?soft ? ?nproc ? ? 1024

* ? ? ? ? ?soft ? ?nproc ? ? 2048


3、max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

修改/etc/sysctl.conf配置文件,

cat /etc/sysctl.conf | grep vm.max_map_count

vm.max_map_count=262144

如果不存在則添加

echo "vm.max_map_count=262144" >>/etc/sysctl.conf


默認端口:9200

配置elasticsearch:

打開config/elasticsearch.yml

修改以下配置:

path.data: /Users/chenshunyang/tools/elasticsearch/data

path.logs: /Users/chenshunyang/tools/elasticsearch/logs

cluster.name: elktest //更改默認的名稱為我們想要的名稱

node.name: node-elktest? //更改節(jié)點默認的名稱

network.host: localhost

1.2 安裝插件:elasticsearch-head

elasticsearch 2.x 版本

elasticsearch 2.x版本中,直接使用/bin/plugin install mobz/elasticsearch-head安裝即可

驗證:通過訪問http://localhost:9200/_plugin/head/

elasticsearch 5.1 版本

安裝:elasticsearch 5.1中,elasticsearch-head插件不能放在elasticsearch的 plugins、modules 目錄下,不能使用 elasticsearch-plugin install,直接啟動elasticsearch即可

git clone https://github.com/mobz/elasticsearch-head.git

cd elasticsearch-head/

npm install grunt

配置:修改elasticsearch/config/elasticsearch.yml

添加

http.cors.enabled: true

http.cors.allow-origin: "*"

打開elasticsearch-head-master/Gruntfile.js,找到下面connect屬性,新增hostname: ‘0.0.0.0’:

connect: {

server: {

options: {

hostname: '0.0.0.0',

port: 9100,

base: '.',

keepalive: true

}

}

}

啟動插件:

elasticsearch-head/ && ./node_modules/grunt/bin/grunt server

查看

http://localhost:9100

2 安裝kibana

下載:從https://www.elastic.co/downloads/kibana下載對應(yīng)操作系統(tǒng)版本的kibana

解壓: tar -xzvf kibana-5.2.0-darwin-x86_64.tar.gz

配置kibana:進入kibana/config

打開kibana.yml,設(shè)置elasticsearch.url? ? 為es實例的地址

eg:elasticsearch.url: "http://localhost:9200"

啟動:./bin/kibana.sh

默認端口:5601

訪問:http://localhost:5601

3 安裝logstash

下載:從https://www.elastic.co/downloads/logstash下載對應(yīng)操作系統(tǒng)版本的logstash

解壓:tar -zxvf logstash-5.2.0.tar.gz

啟動:./bin/logstash -f /home/push/logstash/conf/logstash.conf (logstash.conf為logstash的配置文件)

驗證:logstah --version

配置logstash:

生成一個logstash.conf文件,配置示例內(nèi)容如下

input {

kafka {

zk_connect => "192.168.248.230:2181,192.168.248.175:2181,192.168.249.238:2181/kafka"

group_id => "sms-service3"

topic_id => "sms-service"

codec => "json"

reset_beginning => false

consumer_threads => 5

decorate_events => true

auto_offset_reset => "smallest"

}

}

output {

elasticsearch {

hosts => ["localhost:9200"]

index => "logstash-smsservice-%{+YYYY.MM.dd}"

document_type => "sms-service"

workers => 1

flush_size => 20000

idle_flush_time => 10

template_overwrite => true

}

}

關(guān)鍵配置詞語解釋:

Input 解釋

作為 Consumer 端,插件使用的是 High-level-consumer API,請結(jié)合上述 kafka 基本概念進行設(shè)置:

group_id

消費者分組,可以通過組 ID 去指定,不同的組之間消費是相互不受影響的,相互隔離。

topic_id

指定消費話題,也是必填項目,指定消費某個 topic ,這個其實就是訂閱某個主題,然后去消費。

reset_beginning

logstash 啟動后從什么位置開始讀取數(shù)據(jù),默認是結(jié)束位置,也就是說 logstash 進程會以從上次讀取結(jié)束時的偏移量開始繼續(xù)讀取,如果之前沒有消費過,那么就開始從頭讀取.如果你是要導(dǎo)入原有數(shù)據(jù),把這個設(shè)定改成 "true", logstash 進程就從頭開始讀取.有點類似 cat ,但是讀到最后一行不會終止,而是變成 tail -F ,繼續(xù)監(jiān)聽相應(yīng)數(shù)據(jù)。

decorate_events

在輸出消息的時候會輸出自身的信息包括:消費消息的大小, topic 來源以及 consumer 的 group 信息。

rebalance_max_retries

當有新的 consumer(logstash) 加入到同一 group 時,將會 reblance ,此后將會有 partitions 的消費端遷移到新的 consumer 上,如果一個 consumer 獲得了某個 partition 的消費權(quán)限,那么它將會向 zookeeper 注冊, Partition Owner registry 節(jié)點信息,但是有可能此時舊的 consumer 尚沒有釋放此節(jié)點,此值用于控制,注冊節(jié)點的重試次數(shù)。

consumer_timeout_ms

指定時間內(nèi)沒有消息到達就拋出異常,一般不需要改。

以上是相對重要參數(shù)的使用示例,更多參數(shù)可以選項可以跟據(jù)https://github.com/joekiller/logstash-kafka/blob/master/README.md查看 input 默認參數(shù)。

output解釋:

Logstash 會努力攢到 20000 條數(shù)據(jù)一次性發(fā)送出去,但是如果 10 秒鐘內(nèi)也沒攢夠 20000 條,Logstash 還是會以當前攢到的數(shù)據(jù)量發(fā)一次。

作者:shunyang

鏈接:http://www.itdecent.cn/p/6b7f0488ddff

來源:簡書

著作權(quán)歸作者所有。商業(yè)轉(zhuǎn)載請聯(lián)系作者獲得授權(quán),非商業(yè)轉(zhuǎn)載請注明出處。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容