ELK介紹、安裝es、測試(查看集羣狀態)、總結html
ELK介紹java
需求背景node
業務發展愈來愈龐大,服務器愈來愈多linux
各類訪問日誌、應用日誌、錯誤日誌量愈來愈多git
開發人員排查問題,須要到服務器上查日誌,不方便web
運營人員須要一些數據,須要咱們運維到服務器上分析日誌json
ELK介紹vim
官網https://www.elastic.co/cn/安全
中文指南https://www.gitbook.com/book/chenryn/elk-stack-guide-cn/detailsbash
ELK Stack (5.0版本以後) Elastic Stack == (ELK Stack + Beats)
ELK Stack包含:ElasticSearch、Logstash、Kibana
ElasticSearch是一個搜索引擎,用來搜索、分析、存儲日誌。它是分佈式的,也就是說能夠橫向擴容,能夠自動發現,索引自動分片,總之很強大。文檔https://www.elastic.co/guide/cn/elasticsearch/guide/current/index.html
Logstash用來採集日誌,把日誌解析爲json格式交給ElasticSearch。
Kibana是一個數據可視化組件,把處理後的結果經過web界面展現
Beats在這裏是一個輕量級日誌採集器,其實Beats家族有5個成員
早期的ELK架構中使用Logstash收集、解析日誌,可是Logstash對內存、cpu、io等資源消耗比較高。相比 Logstash,Beats所佔系統的CPU和內存幾乎能夠忽略不計
x-pack對Elastic Stack提供了安全、警報、監控、報表、圖表於一身的擴展包,是收費的
ELK架構
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27.2 ELK安裝準備工做
準備3臺機器128,130,133
角色劃分:
1.3臺所有安裝elasticsearch(後續簡稱es) ,1主節點128,2數據節點130,133
2.es主128上安裝kibana
3.1臺es數據節點130上安裝logstash (beats先不裝)
4.3臺機器所有安裝jdk8(openjdk便可)
yum install -y java-1.8.0-openjdk
實例:
[root@axinlinux-01 ~]# vim /etc/hosts #先寫一個hosts。三臺機器都寫
192.168.208.128 axinlinux-01
192.168.208.130 axinlinux-02
192.168.208.133 axinlinux-03
[root@axinlinux-02 ~]# vim /etc/hosts
[root@axinlinux-03 ~]# vim /etc/hosts
[root@axinlinux-02 ~]# yum install -y java-1.8.0-openjdk #三個機器分別安裝opebjdk。其餘兩臺都手動安裝過啦,就不須要了
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ELK安裝 – 安裝es
官方文檔 https://www.elastic.co/guide/en/elastic-stack/current/installing-elastic-stack.html
如下操做3臺機器上都要執行
1.rpm - -import https://artifacts.elastic.co/GPG-KEY-elasticsearch
#就是搞一個yum源
簡單說就是要導入密鑰。 涉及到一個安全驗證。
https://www.cnblogs.com/musang/p/5856259.html
2.vim /etc/yum.repos.d/elastic.repo //加入以下內容
[elasticsearch-6.x]
name=Elasticsearch repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
3.yum install -y elasticsearch //而後安裝
若是,yum速度太慢。也能夠直接下載rpm文件,而後安裝
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.0.0.rpm
rpm -ivh elasticsearch-6.0.0.rpm
實例:
[root@axinlinux-01 ~]# rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch #三臺機器都要執行
[root@axinlinux-01 ~]# vim /etc/yum.repos.d/elastic.repo #三臺機器都要執行。文件名寫什麼均可以,關鍵是後綴名要爲.repo
[elasticsearch-6.x] name=Elasticsearch repository for 6.x packages baseurl=https://artifacts.elastic.co/packages/6.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md
[root@axinlinux-01 ~]# yum list |grep elastic
apm-server.i686 6.8.0-1 elasticsearch-6.x apm-server.x86_64 6.8.0-1 elasticsearch-6.x auditbeat.i686 6.8.0-1 elasticsearch-6.x auditbeat.x86_64 6.8.0-1 elasticsearch-6.x elasticsearch.noarch 6.8.0-1 elasticsearch-6.x filebeat.i686 6.8.0-1 elasticsearch-6.x filebeat.x86_64 6.8.0-1 elasticsearch-6.x heartbeat-elastic.i686 6.8.0-1 elasticsearch-6.x heartbeat-elastic.x86_64 6.8.0-1 elasticsearch-6.x journalbeat.i686 6.8.0-1 elasticsearch-6.x journalbeat.x86_64 6.8.0-1 elasticsearch-6.x kibana.x86_64 6.8.0-1 elasticsearch-6.x kibana-oss.x86_64 6.3.0-1 elasticsearch-6.x logstash.noarch 1:6.8.0-1 elasticsearch-6.x metricbeat.i686 6.8.0-1 elasticsearch-6.x metricbeat.x86_64 6.8.0-1 elasticsearch-6.x packetbeat.i686 6.8.0-1 elasticsearch-6.x packetbeat.x86_64 6.8.0-1 elasticsearch-6.x pcp-pmda-elasticsearch.x86_64 4.1.0-5.el7_6 updates rsyslog-elasticsearch.x86_64 8.24.0-34.el7 base
elasticsearch.noarch 6.5.4-1 elasticsearch-6.x #就是這個直接yum。可是速度太慢了,能夠去官網下載的rpm包,而後再rpm -ivh的
yum install -y elasticsearch //也能夠直接下載rpm文件,而後安裝
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.0.0.rpm
rpm -ivh elasticsearch-6.0.0.rpm
yum install -y elasticsearch.noarch 6.5.4-1 elasticsearch-6.x
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
配置es
elasticsearch配置文件/etc/elasticsearch和/etc/sysconfig/elasticsearch
參考https://www.elastic.co/guide/en/elasticsearch/reference/6.0/rpm.html
1.在128上(主節點)編輯配置文件vi /etc/elasticsearch/elasticsearch.yml//增長或更改
cluster.name: aminglinux #集羣的名字
node.master: true//意思是該節點爲主節點
node.data: false 意思是否是data節點。以上這兩行是要加進去的
network.host: 192.168.208.128 #在哪一個ip上監聽端口。只監聽一個內網ip就好了
discovery.zen.ping.unicast.hosts: ["192.168.133.130", "192.168.133.132", "192.168.133.133"] #定義有哪些機器。能夠寫ip。也能夠寫主機名(需定義hosts)
2.在132和133上一樣編輯配置文件vi /etc/elasticsearch/elasticsearch.yml//增長或更改
cluster.name: aminglinux
node.master: false
node.data: true
network.host: 192.168.208.130(所在機器的ip)
discovery.zen.ping.unicast.hosts: ["192.168.133.130", "192.168.133.132", "192.168.133.133"]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ELK安裝 – 安裝x-pack(可省略、收費!)
3臺機器上都要執行
cd /usr/share/elasticsearch/bin/ (可省略)
./elasticsearch-plugin install x-pack //若是速度慢,就下載x-pack壓縮包(可省略)
cd /tmp/; wget https://artifacts.elastic.co/downloads/packs/x-pack/x-pack-6.0.0.zip (可省略)
./elasticsearch-plugin install file:///tmp/x-pack-6.0.0.zip (可省略)
啓動elasticsearch服務
systemctl enable elasticsearch.service
systemctl start elasticsearch.service
如下操做只須要在130上執行
安裝x-pack後就能夠爲內置用戶設置密碼了,以下
/usr/share/elasticsearch/bin/x-pack/setup-passwords interactive (可省略)
Sets the passwords for reserved users Commands -------- auto - Uses randomly generated passwords interactive - Uses passwords entered by a user Non-option arguments: command Option Description ------ ----------- -h, --help show help -s, --silent show minimal output -v, --verbose show verbose output ERROR: Missing command
curl localhost:9200 -u elastic //輸入密碼,能夠查看到輸出信息(可省略)
Enter host password for user 'elastic': { "name" : "axinlinux-01", "cluster_name" : "aminglinux", "cluster_uuid" : "_na_", "version" : { "number" : "6.8.0", "build_flavor" : "default", "build_type" : "rpm", "build_hash" : "65b6179", "build_date" : "2019-05-15T20:06:13.172855Z", "build_snapshot" : false, "lucene_version" : "7.7.0", "minimum_wire_compatibility_version" : "5.6.0", "minimum_index_compatibility_version" : "5.0.0" }, "tagline" : "You Know, for Search" }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ELK安裝 – curl查看es(查看集羣是否成功)
128(主節點)上執行
curl 'localhost:9200/_cluster/health?pretty' 健康檢查(狀態)
#咱們綁定的ip是內網(192.168.208.128),因此這裏localhost要寫成192.168.208.128.若是綁定的是0.0.0.0,就能夠寫localhost
curl 'localhost:9200/_cluster/state?pretty' 集羣詳細信息
{ "error" : { "root_cause" : [ { "type" : "master_not_discovered_exception", "reason" : null } ], "type" : "master_not_discovered_exception", "reason" : null }, "status" : 503 }
參考 http://zhaoyanblog.com/archives/732.html
9200端口是cluster本身自己要通訊的
9300端口是他們數據傳輸的時候用到的
總結:
首先要安裝rpm包(能夠yum,但比較慢),而後rpm -ivh安裝
主節點機器上配置配置文件vim /etc/elasticsearch/elasticsearch.yml
啓動不了,能夠查看日誌: 1. /var/log/masssges
2. /var/log/elasticsearch/aminglinux.log