ELK環境搭建及配置
ElasticSearch在5.x后的安裝和插件的官方執行更好了,head插件官方默認集成在kibana的dev tools里,支持rpm包方式安裝,x-pack安裝后支持權限及各種報表功能。
一、安裝ES
1. 安裝JAVA SDK
類似阿里雲和aws一般默認的操作系統都自帶了java環境,檢查java安裝環境使用java -version查看。
目前安裝的ELK版本是5.6.4版本,需要java8以上(java有兩個版本,sdk版本和外部版本,sdk版本是1.8.x)就滿足要求了。
# yum install java-1.8.0-openjdk
2. 安裝elasticsearch
下載地址: https://www.elastic.co/downloads/elasticsearch
下載對應的版本,下載后解壓到想安裝的文件夾中,因為es是綠色版本所以解壓后就可以使用
./bin/elasticsearch其實是一個shell腳本,最終還是啟動在java的虛擬機環境中,並加入了一定參數。
# rpm -ivh elasticsearch-5.6.4.rpm
# chkconfig --add elasticsearch
# chkconfig elasticsearch on
# vim etc/elasticsearch/elasticsearch.yml
# /etc/init.d/elasticsearch.rpmnew start
可執行文件目錄:/usr/share/elasticsearch/
配置文件目錄: /etc/elasticsearch/
日志文件目錄:/var/log/elasticsearch/
data文件目錄:/var/lib/elasticsearch/
pid文件路徑:/var/run/elasticsearch/
日志文件:/var/log/elasticsearch/
3. 啟動elasticsearch
守護進程 ./bin/elasticsearch -d
前台運行 ./bin/elasticsearch
配合elasticsearch-servicewrapper
插件將腳本服務化更易管理 (2.x加不再支持,棄用)
運行日志在../log/下,每一個索引一個文件,每日一個文件,包括運行的慢日志和服務日志。
4. 測試elasticsearch
curl -XGET http://xxx:9200/?pretty
5. 集群配置
discovery.zen.ping.unicast.hosts : ["17.16.0.1:9300", "172.16.2.1:9300"]
默認通信的TCP端口是9300,也可以自定義修改,如果集群連接失敗可查看是否啟動成功,並在elasticsearch/kibana的日志中查看具體原因並排查,配置定義在加入的新服務器里,使用_cat/nodes?v可查看節點信息。
6. 常用api
_cat/health?v
查看集群監控情況
_cat/nodes?v
集群節點情況
_cat/indices
索引情況
二、安裝Kibana
下載頁面:https://www.elastic.co/cn/downloads/kibana
安裝rpm包,我的電腦是x64的所以下載64位的安裝包,rpm包安裝完畢后會自動在/etc/init.d/下生成執行腳本,提供給service/chkconfig,更方便我們使用
# wget https://artifacts.elastic.co/downloads/kibana/kibana-5.6.4-x86_64.rpm
# rpm -ivh kibana-5.6.4-x86_64.rpm
# vim /etc/kibana/kibana.yml
三、安裝Beats
Beats與Logstash的主要區別是Beats是輕量級的數據采集器,Beats包含Filebeat(普通文件采集)、
Metricbeat(系統和服務指標收集)、Packetbeat(網絡相關數據采集)、Winlogbeat(windows日志)、
Heartbeat(運行時間監控、ping檢測)、Auditbeat 、Topbeat等。
1. 安裝Heartbeat客戶端
安裝Heartbeat並將數據寫入到ES中,並結合Kibana平台進行數據展示報表和檢索功能
下載地址:https://www.elastic.co/downloads/beats/heartbeat
項目介紹:https://www.elastic.co/cn/products/beats/heartbeat
啟動 /etc/init.d/heartbeat start
四、安裝x-pack插件
官方下載地址:https://www.elastic.co/downloads/x-pack
官方文檔地址:https://www.elastic.co/guide/en/x-pack/current/xpack-introduction.html
https://www.elastic.co/gu ide/en/x-pack/6.0/setting-up-authentication.html#set-built-in-user-passwords
1. elasticsearch安裝x-pack插件
- 如果是集群架構,則每一台新機器都需要安裝插件
- kibana安裝了x-pack,elasticsearch也必須要安裝
# /usr/share/elasticsea rch/bin/elasticsearch-plugin install x-pack
# /usr/share/kibana/bin/kibana-plugin install x-pack
2. 編輯配置文件
# vim /etc/elasticsearch/x-pack/
3. 用戶管理
# /usr/share/elasticsearch/bin/x-pack/users useradd test -p 123456 -r superuser
如果設置的密碼不能登錄,則可以創建內置用戶,登錄成功后再修改密碼。
官方說明:https://www.elastic.co/guide/en/x-pack/current/security-getting-started.html
/usr/share/elasticsearch/bin/x-pack/users useradd test -p 123456 -r superuser
vim /etc/kibana/kibana.yml
x-pack有很多內置角色,具體可以看官方說明superuser是最高權限,詳見:
https://www.elastic.co/guide/en/x-pack/current/built-in-roles.html
Kibana支持在elasticsearch、kibana、logstath都安裝,但是各個支持的功能點不一樣,設置也不太一樣,
比如es的x-pack就不支持Graph,具體參考以下鏈接:
https://www.elastic.co/guide/en/elasticsearch/reference/6.0/settings-xpack.html
常見問題及注意
-
Elasticsearch is still initializing the Monitoring indices
解決:刪除相關索引
-
transport.tcp.port
自定義discovery集群發行端口 -
如果安裝了x-pack,則集群每台機器都需要安裝
-
如果shell執行則需要注意目錄的每個文件的所屬者都要是執行用戶的,否則java會拋出AccessDenied錯誤