CentOS7.5搭建ELK6.2.4集群及插件安装
一 簡介
Elasticsearch是一個高度可擴(kuò)展的開源全文搜索和分析引擎。它允許您快速,近實時地存儲,搜索和分析大量數(shù)據(jù)。它通常用作支持具有復(fù)雜搜索功能和需求的應(yīng)用程序的底層引擎/技術(shù)。
下載地址:https://www.elastic.co/cn/downloads? ? ? ?版本:elasticsearch-6.2.4.tar.gz??? ?logstash-6.2.4.tar.gz? ??kibana-6.2.4-x86_64.rpm? ?filebeat-6.2.4-x86_64.rpm
1 基本概念
接近實時(NRT)
- Elasticsearch 是一個接近實時的搜索平臺。這意味著,從索引一個文檔直到這個文檔能夠被搜索到有一個很小的延遲(通常是 1 秒)。
集群(cluster)
- 代表一個集群,集群中有多個節(jié)點(node),其中有一個為主節(jié)點,這個主節(jié)點是可以通過選舉產(chǎn)生的,主從節(jié)點是對于集群內(nèi)部來說的。es的一個概念就是去中心化,字面上理解就是無中心節(jié)點,這是對于集群外部來說的,因為從外部來看es集群,在邏輯上是個整體,你與任何一個節(jié)點的通信和與整個es集群通信是等價的。
索引(index)
- ElasticSearch將它的數(shù)據(jù)存儲在一個或多個索引(index)中。用SQL領(lǐng)域的術(shù)語來類比,索引就像數(shù)據(jù)庫,可以向索引寫入文檔或者從索引中讀取文檔,并通過ElasticSearch內(nèi)部使用Lucene將數(shù)據(jù)寫入索引或從索引中檢索數(shù)據(jù)。
文檔(document)
- 文檔(document)是ElasticSearch中的主要實體。對所有使用ElasticSearch的案例來說,他們最終都可以歸結(jié)為對文檔的搜索。文檔由字段構(gòu)成。
映射(mapping)
- 所有文檔寫進(jìn)索引之前都會先進(jìn)行分析,如何將輸入的文本分割為詞條、哪些詞條又會被過濾,這種行為叫做映射(mapping)。一般由用戶自己定義規(guī)則。
類型(type)
- 每個文檔都有與之對應(yīng)的類型(type)定義。這允許用戶在一個索引中存儲多種文檔類型,并為不同文檔提供類型提供不同的映射。
分片(shards)
- 代表索引分片,es可以把一個完整的索引分成多個分片,這樣的好處是可以把一個大的索引拆分成多個,分布到不同的節(jié)點上。構(gòu)成分布式搜索。分片的數(shù)量只能在索引創(chuàng)建前指定,并且索引創(chuàng)建后不能更改。5.X默認(rèn)不能通過配置文件定義分片
副本(replicas)
- 代表索引副本,es可以設(shè)置多個索引的副本,副本的作用一是提高系統(tǒng)的容錯性,當(dāng)個某個節(jié)點某個分片損壞或丟失時可以從副本中恢復(fù)。二是提高es的查詢效率,es會自動對搜索請求進(jìn)行負(fù)載均衡。
數(shù)據(jù)恢復(fù)(recovery)
- 代表數(shù)據(jù)恢復(fù)或叫數(shù)據(jù)重新分布,es在有節(jié)點加入或退出時會根據(jù)機(jī)器的負(fù)載對索引分片進(jìn)行重新分配,掛掉的節(jié)點重新啟動時也會進(jìn)行數(shù)據(jù)恢復(fù)。
- GET /_cat/health?v?? #可以看到集群狀態(tài)
數(shù)據(jù)源(River)
- 代表es的一個數(shù)據(jù)源,也是其它存儲方式(如:數(shù)據(jù)庫)同步數(shù)據(jù)到es的一個方法。它是以插件方式存在的一個es服務(wù),通過讀取river中的數(shù)據(jù)并把它索引到es中,官方的river有couchDB的,RabbitMQ的,Twitter的,Wikipedia的,river這個功能將會在后面的文件中重點說到。
網(wǎng)關(guān)(gateway)
- 代表es索引的持久化存儲方式,es默認(rèn)是先把索引存放到內(nèi)存中,當(dāng)內(nèi)存滿了時再持久化到硬盤。當(dāng)這個es集群關(guān)閉再重新啟動時就會從gateway中讀取索引數(shù)據(jù)。es支持多種類型的gateway,有本地文件系統(tǒng)(默認(rèn)),分布式文件系統(tǒng),Hadoop的HDFS和amazon的s3云存儲服務(wù)。
自動發(fā)現(xiàn)(discovery.zen)
- 代表es的自動發(fā)現(xiàn)節(jié)點機(jī)制,es是一個基于p2p的系統(tǒng),它先通過廣播尋找存在的節(jié)點,再通過多播協(xié)議來進(jìn)行節(jié)點之間的通信,同時也支持點對點的交互。
- 5.X關(guān)閉廣播,需要自定義
通信(Transport)
- 代表es內(nèi)部節(jié)點或集群與客戶端的交互方式,默認(rèn)內(nèi)部是使用tcp協(xié)議進(jìn)行交互,同時它支持http協(xié)議(json格式)、thrift、servlet、memcached、zeroMQ等的傳輸協(xié)議(通過插件方式集成)。
- 節(jié)點間通信端口默認(rèn):9300-9400
分片和復(fù)制(shards and replicas)
一個索引可以存儲超出單個結(jié)點硬件限制的大量數(shù)據(jù)。比如,一個具有10億文檔的索引占據(jù)1TB的磁盤空間,而任一節(jié)點可能沒有這樣大的磁盤空間來存儲或者單個節(jié)點處理搜索請求,響應(yīng)會太慢。
為了解決這個問題,Elasticsearch提供了將索引劃分成多片的能力,這些片叫做分片。當(dāng)你創(chuàng)建一個索引的時候,你可以指定你想要的分片的數(shù)量。每個分片本身也是一個功能完善并且獨(dú)立的“索引”,這個“索引” 可以被放置到集群中的任何節(jié)點上。
分片之所以重要,主要有兩方面的原因:
- 允許你水平分割/擴(kuò)展你的內(nèi)容容量
- 允許你在分片(位于多個節(jié)點上)之上進(jìn)行分布式的、并行的操作,進(jìn)而提高性能/吞吐量?
至于一個分片怎樣分布,它的文檔怎樣聚合回搜索請求,是完全由Elasticsearch管理的,對于作為用戶的你來說,這些都是透明的。
在一個網(wǎng)絡(luò)/云的環(huán)境里,失敗隨時都可能發(fā)生。在某個分片/節(jié)點因為某些原因處于離線狀態(tài)或者消失的情況下,故障轉(zhuǎn)移機(jī)制是非常有用且強(qiáng)烈推薦的。為此, Elasticsearch允許你創(chuàng)建分片的一份或多份拷貝,這些拷貝叫做復(fù)制分片,或者直接叫復(fù)制。
復(fù)制之所以重要,有兩個主要原因:
- 在分片/節(jié)點失敗的情況下,復(fù)制提供了高可用性。復(fù)制分片不與原/主要分片置于同一節(jié)點上是非常重要的。因為搜索可以在所有的復(fù)制上并行運(yùn)行,復(fù)制可以擴(kuò)展你的搜索量/吞吐量
- 總之,每個索引可以被分成多個分片。一個索引也可以被復(fù)制0次(即沒有復(fù)制) 或多次。一旦復(fù)制了,每個索引就有了主分片(作為復(fù)制源的分片)和復(fù)制分片(主分片的拷貝)。
- 分片和復(fù)制的數(shù)量可以在索引創(chuàng)建的時候指定。在索引創(chuàng)建之后,你可以在任何時候動態(tài)地改變復(fù)制的數(shù)量,但是你不能再改變分片的數(shù)量。
- 5.X默認(rèn)5:1?? 5個主分片,1個復(fù)制分片
默認(rèn)情況下,Elasticsearch中的每個索引分配5個主分片和1個復(fù)制。這意味著,如果你的集群中至少有兩個節(jié)點,你的索引將會有5個主分片和另外5個復(fù)制分片(1個完全拷貝),這樣每個索引總共就有10個分片。
2elasticsearch . yml 明細(xì)
# ======================== Elasticsearch Configuration ========================= # NOTE: Elasticsearch comes with reasonable defaults for most settings. # Before you set out to tweak and tune the configuration, make sure you # understand what are you trying to accomplish and the consequences. # # The primary way of configuring a node is via this file. This template lists # the most important settings you may want to configure for a production cluster. # # Please consult the documentation for further information on configuration options: # https://www.elastic.co/guide/en/elasticsearch/reference/index.html # # ---------------------------------- Cluster ----------------------------------- # # Use a descriptive name for your cluster: #cluster.name: my-application # # ------------------------------------ Node ------------------------------------ # # Use a descriptive name for the node: # #node.name: node-1 # # Add custom attributes to the node: # #node.attr.rack: r1 # # ----------------------------------- Paths ------------------------------------ # # Path to directory where to store the data (separate multiple locations by comma): # #path.data: /path/to/data # # Path to log files: # #path.logs: /path/to/logs # # ----------------------------------- Memory ----------------------------------- # # Lock the memory on startup: # #bootstrap.memory_lock: true # # Make sure that the heap size is set to about half the memory available # on the system and that the owner of the process is allowed to use this # limit. # # Elasticsearch performs poorly when the system is swapping the memory. # # ---------------------------------- Network ----------------------------------- # # Set the bind address to a specific IP (IPv4 or IPv6): # #network.host: 192.168.0.1 # # Set a custom port for HTTP: # #http.port: 9200 # # For more information, consult the network module documentation. # # --------------------------------- Discovery ---------------------------------- # # Pass an initial list of hosts to perform discovery when new node is started: # The default list of hosts is ["127.0.0.1", "[::1]"] # #discovery.zen.ping.unicast.hosts: ["host1", "host2"] # # Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1): # #discovery.zen.minimum_master_nodes: # # For more information, consult the zen discovery module documentation. # # ---------------------------------- Gateway ----------------------------------- # # Block initial recovery after a full cluster restart until N nodes are started: # #gateway.recover_after_nodes: 3 # # For more information, consult the gateway module documentation. # # ---------------------------------- Various ----------------------------------- # # Require explicit names when deleting indices: # #action.destructive_requires_name: true二 安裝
1 集群部署
| CentOS7.5 | node21 | 192.168.100.21 | √ | ?√ | √ | ?√ |
| CentOS7.5 | node22 | 192.168.100.22 | √ | ? | √ | ? |
| CentOS7.5 | node23 | 192.168.100.23 | ? | ? | √ | ? |
Elasticsearch的目錄結(jié)構(gòu)
| 文件夾 | 作用 |
| bin | 運(yùn)行ElasticSearch實例和管理插件的一些腳本 |
| config | 放的是配置文件:elasticsearch.yml,jvm.options,log4j2.properties |
| lib | ElasticSearch使用的庫 |
| logs | 日志的文件夾 |
| modules | ? |
| plugins | ? |
config/elasticsearch.yml 主配置文件
config/jvm.options jvm參數(shù)配置文件
cofnig/log4j2.properties 日志配置文件
2?elasticsearch安裝
2.1? 準(zhǔn)備環(huán)境
1)jdk安裝:官方建議java -version 1.8_131以上,我這里安裝的jdk1.8_171
2)出于系統(tǒng)安全考慮,ElasticSearch不允許以root用戶模式運(yùn)行,我這里已創(chuàng)建用戶admin
2.2? 解壓安裝
創(chuàng)建文件夾elk,解壓到elk文件
[admin@node21 software]$ tar zxvf elasticsearch-6.2.4.tar.gz -C /opt/module/elk2.3?集群配置
cluster.name: myescluster #自定義修改一個集群名稱 node.name: node21 #節(jié)點名稱 network.host: 192.168.100.21 #節(jié)點IP(或者解析的主機(jī)名) bootstrap.memory_lock: true #設(shè)置elasticsearch的進(jìn)程鎖住內(nèi)存 discovery.zen.ping.unicast.hosts: ["192.168.100.21", "192.168.100.22","192.168.100.23"] #集群個節(jié)點IP地址 discovery.zen.minimum_master_nodes: 2 #為了避免腦裂,集群節(jié)點數(shù)最少為 半數(shù)+12.4? JVM配置
vi elasticsearch/config/jvm.options -Xms1g # JVM最大、最小使用內(nèi)存-Xmx1g2.5? 分發(fā)es安裝包
[admin@node21 elk]$ scp -r elasticsearch-6.2.4 admin@node22:/opt/module/elk [admin@node21 elk]$ scp -r elasticsearch-6.2.4 admin@node23:/opt/module/elk 修改node22,node23節(jié)點配置文件elasticsearch.yml中的主機(jī)名和ip2.6? 啟動集群
前臺啟動:進(jìn)入到elasticsearch-6.2.4安裝目錄的bin目錄下
[admin@node21 bin]$?./elasticsearch
此時會有一個初始化的過程,內(nèi)容如下
[2018-06-07T04:43:02,506][INFO ][o.e.n.Node ] [node21] initializing ... [2018-06-07T04:43:02,830][INFO ][o.e.e.NodeEnvironment ] [node21] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [91.2gb], net total_space [97.6gb], types [rootfs][2018-06-07T04:43:02,831][INFO ][o.e.e.NodeEnvironment ] [node21] heap size [1015.6mb], compressed ordinary object pointers [true] [2018-06-07T04:43:02,869][INFO ][o.e.n.Node ] [node21] node name [node21], node ID [z14A4EeXSOqvqdp4J1htzQ] [2018-06-07T04:43:02,870][INFO ][o.e.n.Node ] [node21] version[6.2.4], pid[2265], build[ccec39f/2018-04-12T20:37:28.497551Z], OS[Linux/3.10.0-862.el7.x86 _64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_171/25.171-b11][2018-06-07T04:43:02,870][INFO ][o.e.n.Node ] [node21] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX :+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.io.tmpdir=/tmp/elasticsearch.56PUO1hY, -XX:+HeapDumpOnOutOfMemoryError, -XX:+PrintGCDetails, -XX:+PrintGCDateStamps, -XX:+PrintTenuringDistribution, -XX:+PrintGCApplicationStoppedTime, -Xloggc:logs/gc.log, -XX:+UseGCLogFileRotation, -XX:NumberOfGCLogFiles=32, -XX:GCLogFileSize=64m, -Des.path.home=/opt/module/elk/elasticsearch-6.2.4, -Des.path.conf=/opt/module/elk/elasticsearch-6.2.4/config][2018-06-07T04:43:06,699][INFO ][o.e.p.PluginsService ] [node21] loaded module [aggs-matrix-stats] [2018-06-07T04:43:06,699][INFO ][o.e.p.PluginsService ] [node21] loaded module [analysis-common] [2018-06-07T04:43:06,699][INFO ][o.e.p.PluginsService ] [node21] loaded module [ingest-common] [2018-06-07T04:43:06,699][INFO ][o.e.p.PluginsService ] [node21] loaded module [lang-expression] [2018-06-07T04:43:06,700][INFO ][o.e.p.PluginsService ] [node21] loaded module [lang-mustache] [2018-06-07T04:43:06,700][INFO ][o.e.p.PluginsService ] [node21] loaded module [lang-painless] [2018-06-07T04:43:06,700][INFO ][o.e.p.PluginsService ] [node21] loaded module [mapper-extras] [2018-06-07T04:43:06,700][INFO ][o.e.p.PluginsService ] [node21] loaded module [parent-join] [2018-06-07T04:43:06,700][INFO ][o.e.p.PluginsService ] [node21] loaded module [percolator] [2018-06-07T04:43:06,700][INFO ][o.e.p.PluginsService ] [node21] loaded module [rank-eval] [2018-06-07T04:43:06,701][INFO ][o.e.p.PluginsService ] [node21] loaded module [reindex] [2018-06-07T04:43:06,701][INFO ][o.e.p.PluginsService ] [node21] loaded module [repository-url] [2018-06-07T04:43:06,701][INFO ][o.e.p.PluginsService ] [node21] loaded module [transport-netty4] [2018-06-07T04:43:06,701][INFO ][o.e.p.PluginsService ] [node21] loaded module [tribe] [2018-06-07T04:43:06,702][INFO ][o.e.p.PluginsService ] [node21] no plugins loaded [2018-06-07T04:43:18,463][INFO ][o.e.d.DiscoveryModule ] [node21] using discovery type [zen] [2018-06-07T04:43:21,505][INFO ][o.e.n.Node ] [node21] initialized [2018-06-07T04:43:21,505][INFO ][o.e.n.Node ] [node21] starting ... View Code后臺啟動?
nohup./bin/elasticsearch& 或者 /bin/elasticsearch -d?頁面查看,默認(rèn)端口 9200
http://node21:9200/3? 插件安裝
1?head插件
下載地址:https://github.com/mobz/elasticsearch-head?
介紹:head插件是ES的一個可視化插件,類似于navicat和mysql的關(guān)系。head插件是一個用來瀏覽、與ES數(shù)據(jù)進(jìn)行交互的web前端展示插件,是一個用來監(jiān)視ES狀態(tài)的客戶端插件。
由于head插件本質(zhì)上還是一個nodejs的工程,因此需要安裝node,使用npm來安裝依賴的包。(npm其實是Node.js的包管理工具,可以理解為maven)
(1)下載NodeJS
1 下載地址:https://nodejs.org/en/download/
2 安裝nodejs
由于下載下來的是xz文件,node-v8.11.2-linux-x64.tar.xz,Linux上大部分情況下不能直接解壓tar.xz的文件。需要用xz -d xxx.tar.xz 將 xxx.tar.xz解壓成 xxx.tar 然后,再用 tar xvf xxx.tar來解包(報錯先安裝xz,執(zhí)行yum -y install?xz)
[admin@node21 software]$ xz -d node-v8.11.2-linux-x64.tar.xz [admin@node21 software]$ tar xvf node-v8.11.2-linux-x64.tar -C /opt/module/elk配置環(huán)境變量 vi? /etc/profile
export NODE_HOME=/opt/module/elk/node-v8.11.2-linux-x64 export PATH=$NODE_HOME/bin:$PATHsource /etc/profile 環(huán)境變量生效
3?下載head插件頭
[admin@node21 elk]$ wget https://github.com/mobz/elasticsearch-head/archive/master.zip
解壓,會出現(xiàn)一個elasticsearch-head-master文件
[admin@node21 elk]$ unzip master.zip4?使用npm安裝grunt
設(shè)置npm的代理鏡像,由于國外的下載較慢,所以設(shè)置為國內(nèi)的,進(jìn)入到elasticsearch-head-master內(nèi)執(zhí)行以下命令
?[admin@node21 elasticsearch-head-master]$ npm config set registry https://registry.npm.taobao.org
執(zhí)行npm install,grunt是基于Node.js的項目構(gòu)建工具,可以進(jìn)行打包壓縮,測試,執(zhí)行等等的工作,head插件就是通過grunt啟動。?
[admin@node21 elasticsearch-head-master]$ npm install -g grunt [admin@node21 elasticsearch-head-master]$ npm install版本確認(rèn):
[admin@node21 software]$ node -v v8.11.2 [admin@node21 software]$ npm -v 6.1.0 [admin@node21 software]$ grunt -version grunt-cli v1.2.0grunt v1.0.1
5 修改Head源碼
由于head的代碼直接執(zhí)行有很多限制,比如無法跨機(jī)器訪問。因此需要用戶修改兩個地方:
?1)修改 elasticsearch-head-master/Gruntfile.js 文件,紅色部分為添加的,原來沒有,設(shè)置hostname屬性,設(shè)置為0.0.0.0
[admin@node21 elasticsearch-head-master]$ vi Gruntfile.js connect: {server: {options: { hostname: '0.0.0.0',port: 9100,base: '.',keepalive: true}}}2)修改跨域請求配置
不修改連接的狀態(tài)如下,修改之后才能連上,這樣head插件才可以訪問elasticsearch。
修改文件為elasticsearch-6.2.4/config/elasticsearch.yml,添加如下兩行
http.cors.enabled: true http.cors.allow-origin: "*"?上述連接需要手動更改http://localhost:9200/中的localhost為自己的ip才能連接得上。這里修改配置文件,改為自己的ip。修改head的連接地址,進(jìn)入到elasticsearch-head-master/_site里,修改app.js(提示:指定內(nèi)容查找? 如果是用vi打開文件后,在命令行下輸入“/關(guān)鍵字”;?如果是在沒有打開文件的前提就用"cat 文件名 | grep "關(guān)鍵字""。)
[admin@node21 _site]$ vi app.js this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200"; 把localhost修改成你es的服務(wù)器地址,如: this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://192.168.100.21:9200";6 啟動elasticsearch
1、啟動ES(因為上述配置修改了elasticsearch-yml,重啟才能生效。)
如果已經(jīng)啟動,先停止(/elasticsearch-6.2.4/bin)
[admin@node21 bin]$?./elasticsearch2、啟動head
[admin@node21 elasticsearch-head-master]$ grunt server &?頁面訪問,默認(rèn)端口9100,綠色為健康,黃色為警告
?http://192.168.100.21:9100/
3、如果出現(xiàn)端口被占用,可以用如下命令查找被占用端口,然后在kill掉。 netstat -nap | grep 9100
2?bigdesk插件
1. 下載解壓,出現(xiàn)一個bigdesk-master的文件
[admin@node21 elk]$ wget https://github.com/hlstudio/bigdesk/archive/master.zip[admin@node21 elk]$ unzip master.zip?
2. 配置elasticsearch.yml
因為es5.x后不支持內(nèi)嵌plugin,所以把下面參數(shù)打開,安裝head插件也類似
添加:
http.cors.enabled: true
http.cors.allow-origin: "*"
3. 安裝httpd服務(wù)
我這里直接通過httpd服務(wù)跑bigdesk插件
yum install -y httpd
systemctl start httpd
systemctl status httpd
4. 把bigdesk放到httpd服務(wù)目錄里
httpd服務(wù)目錄默認(rèn)為:/var/www/html
我們把下載好的bigdesk-master.zip 解壓,然后放到/var/www/html即可
[admin@node21 elk]$ sudo mv bigdesk-master/ /var/www/html/5. 訪問bigdesk
瀏覽器打開 http://192.168.100.21/bigdesk-master/_site/#nodes?,點擊右側(cè)連接即可訪問!
3? IK分詞器插件
安裝文檔參考:https://github.com/medcl/elasticsearch-analysis-ik/blob/master/README.md
1.下載ik分詞器
[admin@node21 elasticsearch-6.2.4]$ ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.2.4/elasticsearch-analysis-ik-6.2.4.zip2. 重啟elasticsearch
3. 測試IK分詞器
創(chuàng)建索引
[admin@node21 bin]$ curl -XPUT http://192.168.100.21:9200/index創(chuàng)建映射
curl -XPOST http://192.168.100.21:9200/index/fulltext/_mapping -H 'Content-Type:application/json' -d' {"properties": {"content": {"type": "text","analyzer": "ik_max_word","search_analyzer": "ik_max_word"}}}'索引文檔
curl -XPOST http://192.168.100.21:9200/index/fulltext/1 -H 'Content-Type:application/json' -d' {"content":"美國留給伊拉克的是個爛攤子嗎"}'curl -XPOST http://192.168.100.21:9200/index/fulltext/2 -H 'Content-Type:application/json' -d' {"content":"公安部:各地校車將享最高路權(quán)"}' curl -XPOST http://192.168.100.21:9200/index/fulltext/3 -H 'Content-Type:application/json' -d' {"content":"中韓漁警沖突調(diào)查:韓警平均每天扣1艘中國漁船"}' curl -XPOST http://192.168.100.21:9200/index/fulltext/4 -H 'Content-Type:application/json' -d' {"content":"中國駐洛杉磯領(lǐng)事館遭亞裔男子槍擊 嫌犯已自首"}'
?高亮查詢
curl -XPOST http://192.168.100.21:9200/index/fulltext/_search -H 'Content-Type:application/json' -d' {"query" : { "match" : { "content" : "中國" }},"highlight" : {"pre_tags" : ["<tag1>", "<tag2>"],"post_tags" : ["</tag1>", "</tag2>"],"fields" : {"content" : {}}} }'此時會顯示兩條數(shù)據(jù),或者頁面查詢context帶有中國
Dictionary Configuration
IKAnalyzer.cfg.xml?can be located at?{conf}/analysis-ik/config/IKAnalyzer.cfg.xml?or?{plugins}/elasticsearch-analysis-ik-*/config/IKAnalyzer.cfg.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> <comment>IK Analyzer 擴(kuò)展配置</comment> <!--用戶可以在這里配置自己的擴(kuò)展字典 --> <entry key="ext_dict">custom/mydict.dic;custom/single_word_low_freq.dic</entry> <!--用戶可以在這里配置自己的擴(kuò)展停止詞字典--> <entry key="ext_stopwords">custom/ext_stopword.dic</entry> <!--用戶可以在這里配置遠(yuǎn)程擴(kuò)展字典 --> <entry key="remote_ext_dict">location</entry> <!--用戶可以在這里配置遠(yuǎn)程擴(kuò)展停止詞字典--> <entry key="remote_ext_stopwords">http://xxx.com/xxx.dic</entry> </properties>熱更新 IK 分詞使用方法
目前該插件支持熱更新 IK 分詞,通過上文在 IK 配置文件中提到的如下配置
<!--用戶可以在這里配置遠(yuǎn)程擴(kuò)展字典 --><entry key="remote_ext_dict">location</entry> <!--用戶可以在這里配置遠(yuǎn)程擴(kuò)展停止詞字典--> <entry key="remote_ext_stopwords">location</entry>其中?location?是指一個 url,比如?http://yoursite.com/getCustomDict,該請求只需滿足以下兩點即可完成分詞熱更新。
該 http 請求需要返回兩個頭部(header),一個是?Last-Modified,一個是?ETag,這兩者都是字符串類型,只要有一個發(fā)生變化,該插件就會去抓取新的分詞進(jìn)而更新詞庫。
該 http 請求返回的內(nèi)容格式是一行一個分詞,換行符用?\n?即可。
滿足上面兩點要求就可以實現(xiàn)熱更新分詞了,不需要重啟 ES 實例。
可以將需自動更新的熱詞放在一個 UTF-8 編碼的 .txt 文件里,放在 nginx 或其他簡易 http server 下,當(dāng) .txt 文件修改時,http server 會在客戶端請求該文件時自動返回相應(yīng)的 Last-Modified 和 ETag。可以另外做一個工具來從業(yè)務(wù)系統(tǒng)提取相關(guān)詞匯,并更新這個 .txt 文件。
4? marvel插件
Marvel能夠讓你通過Kibana非常容易的監(jiān)視ES。你能實時的觀察集群(your cluster)的健康和表現(xiàn)也能分析過去的集群、索引和節(jié)點指標(biāo)。
Marvel由兩部分組成:Marvel代理:在你的集群中安裝在每一個節(jié)點上;Marvel應(yīng)用:安裝在Kibana。
?
三? filebeat安裝
官方文檔:https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-getting-started.html
Filebeat入門
- 第1步:安裝Filebeat
- 第2步:配置Filebeat
- 步驟3:配置Filebeat以使用Logstash
- 第4步:在Elasticsearch中加載索引模板
- 第5步:設(shè)置Kibana儀表板
- 第6步:啟動Filebeat
- 第7步:查看示例Kibana儀表板
3.1 下載安裝
[admin@node21 elk]$ curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.2.4-x86_64.rpm [admin@node21 elk]$ sudo rpm -vi filebeat-6.2.4-x86_64.rpm3.2?編輯filebeat.yml
rpm安裝的filebeat,配置文件在/etc/filebeat/filebeat.yml,這里做默認(rèn)日志的測試,簡單的修改如下
filebeat.prospectors: - type: logenabled: truepaths:- /var/log/*.log3.3?運(yùn)行啟動守護(hù)進(jìn)程?
sudo ./filebeat -e -c filebeat.yml四? logstash安裝
Logstash參考
- Logstash參考:?主6.x的6.36.2(??當(dāng)前)6.165.65.55.45.35.25.152.42.32.22.12.01.5
- Logstash介紹
- Logstash入門
- Logstash如何工作
- 設(shè)置并運(yùn)行Logstash
- 設(shè)置X-Pack
- 打破變化
- X-Pack突破性改變
- 升級Logstash
- 配置Logstash
- 管理Logstash
- 使用Logstash模塊
- 使用Filebeat模塊
- 數(shù)據(jù)彈性
- 轉(zhuǎn)換數(shù)據(jù)
- 部署和擴(kuò)展Logstash
- 性能調(diào)整
- 監(jiān)視Logstash
- 監(jiān)視API
- 使用插件
- 輸入插件
- 輸出插件
- 過濾插件
- 編解碼器插件
- 為Logstash做出貢獻(xiàn)
- 專業(yè)術(shù)語
- 發(fā)行說明
- X-Pack發(fā)行說明
4.1 下載解壓縮
[admin@node21 elk]$ wget https://artifacts.elastic.co/downloads/logstash/logstash-6.2.4.tar.gz [admin@node21 elk]$ tar zxvf logstash-6.2.4.tar.gz4.2 創(chuàng)建配置文件
一個Logstash的pipeline由3部分組成:input, filter, output。
[admin@node21 datas]$ pwd /opt/datas [admin@node21 datas]$ vi logstash-simple.conflogstash-simple.conf內(nèi)容如下
input { stdin { } } output {elasticsearch { hosts => ["192.168.100.21:9200"] }stdout { codec => rubydebug } }4.3 運(yùn)行l(wèi)ogstash
[admin@node21 bin]$ pwd /opt/module/elk/logstash-6.2.4/bin [admin@node21 bin]$ ./logstash -f /opt/datas/logstash-simple.conf這個pipeline例子從標(biāo)準(zhǔn)輸入獲取數(shù)據(jù)?stdin,并把結(jié)構(gòu)化數(shù)據(jù)輸出到標(biāo)準(zhǔn)輸出stdout。在啟動后,看到日志Pipeline main started后,在終端中輸入hello world,可以在終端中看到對應(yīng)輸出:
View Code在企業(yè)架構(gòu)中,一般Logstash的input是beat,output是ES,需要對應(yīng)的插件。
安裝beat input插件:
構(gòu)建離線插件包:?bin/logstash-plugin prepare-offline-pack logstash-input-beats
安裝離線插件包:?bin/logstash-plugin install file:///path/to/logstash-offline-plugins-6.2.4.zip
[admin@node21 bin]$ ./logstash-plugin prepare-offline-pack logstash-input-beats Offline package created at: /opt/module/elk/logstash-6.2.4/logstash-offline-plugins-6.2.4.zip You can install it with this command `bin/logstash-plugin install file:///opt/module/elk/logstash-6.2.4/logstash-offline-plugins-6.2.4.zip` [admin@node21 bin]$ ./logstash-plugin install file:///opt/module/elk/logstash-6.2.4/logstash-offline-plugins-6.2.4.zip配置 5044 端口作為 Filebeat 的連接和創(chuàng)建 ES 索引。新建?logstash.conf 配置文件,
input {beats {port => 5044} }output {elasticsearch {hosts => "192.168.100.21:9200"manage_template => falseindex => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"document_type => "%{[@metadata][type]}"} }Logstash 使用該配置使用 ES 的索引,和 Filebeat 做的事情是一樣的,不過擁有了額外的緩存以及強(qiáng)大豐富的插件庫。
啟動 logstash :
./bin/logstash -f config/logstash.conf &五? kibana安裝
Kibana用戶指南
- Kibana參考:?主6.x的6.36.2(??當(dāng)前)6.165.65.55.45.35.25.154.64.54.44.34.24.143.0
- 介紹
- 設(shè)置Kibana
- 設(shè)置X-Pack
- 打破變化
- X-Pack突破性改變
- 入門
- 發(fā)現(xiàn)
- 想象
- 儀表板
- 天聯(lián)
- 機(jī)器學(xué)習(xí)
- APM
- 圖形
- 開發(fā)工具
- 監(jiān)控
- 管理
- 來自Kibana的報道
- Kibana插件
- 貢獻(xiàn)Kibana
- 限制
- Kibana發(fā)行說明
- X-Pack發(fā)行說明
Kibana是一個開源的分析和可視化平臺,旨在與 Elasticsearch 合作。Kibana 提供搜索、查看和與存儲在 Elasticsearch 索引中的數(shù)據(jù)進(jìn)行交互的功能。開發(fā)者或運(yùn)維人員可以輕松地執(zhí)行高級數(shù)據(jù)分析,并在各種圖表、表格和地圖中可視化數(shù)據(jù)
5.1 下載解壓縮
[admin@node21 elk]$ wget https://artifacts.elastic.co/downloads/kibana/kibana-6.2.4-linux-x86_64.tar.gz[admin@node21 elk]$ tar -xzf kibana-6.2.4-linux-x86_64.tar.gz
5.2 修改config/kibana.yml
[admin@node21 elk]$ vi kibana-6.2.4-linux-x86_64/config/kibana.yml #server.host: "localhost" server.host: "192.168.100.21" #設(shè)置自己機(jī)器的IP #elasticsearch.url: "http://localhost:9200" elasticsearch.url: "http://192.168.100.21:9200"5.3 啟動Kibana
進(jìn)入kibana/bin/目錄
[admin@node21 bin]$ ./kibana &頁面訪問:192.168.100.21:5601
六? 安裝故障問題
1?bootstrap? checks? failed
ERROR: bootstrap checks failed max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]max number of threads [3812] for user [admin] is too low, increase to at least [4096]
解決辦法:
1)針對?max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
切換root用戶,修改/etc/security/limits.conf文件,配置系統(tǒng)搜索最大文件數(shù),添加如下兩行,此文件修改后需要重新登錄用戶,才會生效,驗證是否設(shè)置成功???ulimit -Hn
* hard nofile 65536 * soft nofile 655362)針對??max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
切換root用戶,修改/etc/sysctl.conf 文件,添加如下信息,設(shè)置后保存退出,執(zhí)行右邊命令? sysctl -p
vm.max_map_count=2621443)針對?max number of threads [3812] for user [admin] is too low, increase to at least [4096]
修改 vi /etc/security/limits.d/20-nproc.conf,修改用戶最大線程數(shù),
* soft nproc 4096 root soft nproc unlimited同時修改/etc/security/limits.conf,添加如下兩行,修改完了驗證?ulimit -u
* soft nproc 4096 * hard nproc 40962? head頭安裝警告問題
npm WARN elasticsearch-head@0.0.0 license should be a valid SPDX license expression npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! phantomjs-prebuilt@2.1.16 install: `node install.js` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the phantomjs-prebuilt@2.1.16 install script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /home/admin/.npm/_logs/2018-06-06T11_41_22_784Z-debug.log第一個警告:解決方式:打開elasticsearch-head目錄下的package.json文件,找到license位置,修改為上面這個網(wǎng)站上存在Identifier,我的修改如下,將Apache內(nèi)容修改為Apache-2.0。
{"name": "elasticsearch-head","version": "0.0.0","description": "Front end for an elasticsearch cluster","main": "_site/index.html","directories": {"test": "test"},"scripts": {"start": "grunt server","test": "grunt jasmine","proxy": "node proxy/index.js"},"repository": {"type": "git","url": "https://github.com/mobz/elasticsearch-head.git"},"author": "","license": "Apache-2.0","gitHead": "0c2ac0b5723b493e4454baa7398f386ecb829412","readmeFilename": "README.textile","devDependencies": {"grunt": "1.0.1","grunt-contrib-concat": "1.0.1","grunt-contrib-watch": "1.0.0","grunt-contrib-connect": "1.0.2","grunt-contrib-copy": "1.0.0","grunt-contrib-clean": "1.0.0","grunt-contrib-jasmine": "1.0.3","karma": "1.3.0","grunt-karma": "2.0.0","http-proxy": "1.16.x"}然后重新執(zhí)行npm install ,該提示已消除。
3?head安裝后啟動問題
[2018-06-06T08:24:28,869][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [node21] uncaught exception in thread [main] org.elasticsearch.bootstrap.StartupException: java.lang.IllegalArgumentException: property [elasticsearch.version] is missing for plugin [head]at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:125) ~[elasticsearch-6.2.4.jar:6.2.4]at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-6.2.4.jar:6.2.4]at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.2.4.jar:6.2.4]at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.2.4.jar:6.2.4]at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.2.4.jar:6.2.4]at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-6.2.4.jar:6.2.4]at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:85) ~[elasticsearch-6.2.4.jar:6.2.4] Caused by: java.lang.IllegalArgumentException: property [elasticsearch.version] is missing for plugin [head]at org.elasticsearch.plugins.PluginInfo.readFromProperties(PluginInfo.java:226) ~[elasticsearch-6.2.4.jar:6.2.4]at org.elasticsearch.plugins.PluginInfo.readFromProperties(PluginInfo.java:184) ~[elasticsearch-6.2.4.jar:6.2.4]at org.elasticsearch.bootstrap.Spawner.spawnNativePluginControllers(Spawner.java:75) ~[elasticsearch-6.2.4.jar:6.2.4]at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:167) ~[elasticsearch-6.2.4.jar:6.2.4]at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:323) ~[elasticsearch-6.2.4.jar:6.2.4]at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-6.2.4.jar:6.2.4]... 6 more解決分析:elasticsearch-head自5.1之后不支持直接放在elasticsearch的 plugins、modules 目錄下,也不能使用 elasticsearch-plugin install。
安裝 elasticsearch-head
修改 elasticsearch/config/elasticsearch.yml,添加如下內(nèi)容
-
下載 elasticsearch-head 或者 git clone 到隨便一個文件夾
-
安裝nodejs
-
cd /path/to/elasticsearch-head
-
npm install -g grunt-cli
-
npm install
-
grunt server
-
http://localhost:9100/
4? 設(shè)置鎖內(nèi)存故障
1)elasticsearch官網(wǎng)建議生產(chǎn)環(huán)境需要設(shè)置bootstrap.memory_lock: true,導(dǎo)致Elasticsearch啟動失敗問題
[admin@node21 bin]$ ./elasticsearch [2018-06-07T23:50:12,370][WARN ][o.e.b.JNANatives ] Unable to lock JVM Memory: error=12, reason=Cannot allocate memory [2018-06-07T23:50:12,374][WARN ][o.e.b.JNANatives ] This can result in part of the JVM being swapped out. [2018-06-07T23:50:12,374][WARN ][o.e.b.JNANatives ] Increase RLIMIT_MEMLOCK, soft limit: 65536, hard limit: 65536 [2018-06-07T23:50:12,374][WARN ][o.e.b.JNANatives ] These can be adjusted by modifying /etc/security/limits.conf, for example: # allow user 'admin' mlockalladmin soft memlock unlimitedadmin hard memlock unlimited [2018-06-07T23:50:12,375][WARN ][o.e.b.JNANatives ] If you are logged in interactively, you will have to re-login for the new limits to take effect. [2018-06-07T23:50:12,875][INFO ][o.e.n.Node ] [node21] initializing ... [2018-06-07T23:50:13,033][INFO ][o.e.e.NodeEnvironment ] [node21] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [90.7gb], net total_space [97.6gb], types [rootfs][2018-06-07T23:50:13,034][INFO ][o.e.e.NodeEnvironment ] [node21] heap size [1015.6mb], compressed ordinary object pointers [true] [2018-06-07T23:50:13,036][INFO ][o.e.n.Node ] [node21] node name [node21], node ID [sM6bNfHmT7CknreP2b9RHw] [2018-06-07T23:50:13,037][INFO ][o.e.n.Node ] [node21] version[6.2.4], pid[2164], build[ccec39f/2018-04-12T20:37:28.497551Z], OS[Linux/3.10.0-862.el7.x86 _64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_171/25.171-b11][2018-06-07T23:50:13,037][INFO ][o.e.n.Node ] [node21] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX :+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.io.tmpdir=/tmp/elasticsearch.OUkgncgb, -XX:+HeapDumpOnOutOfMemoryError, -XX:+PrintGCDetails, -XX:+PrintGCDateStamps, -XX:+PrintTenuringDistribution, -XX:+PrintGCApplicationStoppedTime, -Xloggc:logs/gc.log, -XX:+UseGCLogFileRotation, -XX:NumberOfGCLogFiles=32, -XX:GCLogFileSize=64m, -Des.path.home=/opt/module/elk/elasticsearch-6.2.4, -Des.path.conf=/opt/module/elk/elasticsearch-6.2.4/config][2018-06-07T23:50:15,004][INFO ][o.e.p.PluginsService ] [node21] loaded module [aggs-matrix-stats] [2018-06-07T23:50:15,004][INFO ][o.e.p.PluginsService ] [node21] loaded module [analysis-common] [2018-06-07T23:50:15,004][INFO ][o.e.p.PluginsService ] [node21] loaded module [ingest-common] [2018-06-07T23:50:15,005][INFO ][o.e.p.PluginsService ] [node21] loaded module [lang-expression] [2018-06-07T23:50:15,005][INFO ][o.e.p.PluginsService ] [node21] loaded module [lang-mustache] [2018-06-07T23:50:15,005][INFO ][o.e.p.PluginsService ] [node21] loaded module [lang-painless] [2018-06-07T23:50:15,005][INFO ][o.e.p.PluginsService ] [node21] loaded module [mapper-extras] [2018-06-07T23:50:15,005][INFO ][o.e.p.PluginsService ] [node21] loaded module [parent-join] [2018-06-07T23:50:15,005][INFO ][o.e.p.PluginsService ] [node21] loaded module [percolator] [2018-06-07T23:50:15,005][INFO ][o.e.p.PluginsService ] [node21] loaded module [rank-eval] [2018-06-07T23:50:15,006][INFO ][o.e.p.PluginsService ] [node21] loaded module [reindex] [2018-06-07T23:50:15,006][INFO ][o.e.p.PluginsService ] [node21] loaded module [repository-url] [2018-06-07T23:50:15,006][INFO ][o.e.p.PluginsService ] [node21] loaded module [transport-netty4] [2018-06-07T23:50:15,006][INFO ][o.e.p.PluginsService ] [node21] loaded module [tribe] [2018-06-07T23:50:15,007][INFO ][o.e.p.PluginsService ] [node21] no plugins loaded [2018-06-07T23:50:22,618][INFO ][o.e.d.DiscoveryModule ] [node21] using discovery type [zen] [2018-06-07T23:50:24,023][INFO ][o.e.n.Node ] [node21] initialized [2018-06-07T23:50:24,024][INFO ][o.e.n.Node ] [node21] starting ... [2018-06-07T23:50:24,561][INFO ][o.e.t.TransportService ] [node21] publish_address {192.168.100.21:9300}, bound_addresses {192.168.100.21:9300} [2018-06-07T23:50:24,609][INFO ][o.e.b.BootstrapChecks ] [node21] bound or publishing to a non-loopback address, enforcing bootstrap checks ERROR: [1] bootstrap checks failed [1]: memory locking requested for elasticsearch process but memory is not locked [2018-06-07T23:50:24,684][INFO ][o.e.n.Node ] [node21] stopping ... [2018-06-07T23:50:24,811][INFO ][o.e.n.Node ] [node21] stopped [2018-06-07T23:50:24,812][INFO ][o.e.n.Node ] [node21] closing ... [2018-06-07T23:50:24,851][INFO ][o.e.n.Node ] [node21] closed修改/etc/sysctl.conf和/etc/security/limits.conf?
vi /etc/sysctl.conf vm.swappiness=0 vi /etc/security/limits.conf admin soft memlock unlimited admin hard memlock unlimited 修改完重新登錄生效2)改完之后有可能啟動失敗
[admin@node22 bin]$ ./elasticsearch Killed這里一般是由于內(nèi)存不足導(dǎo)致的,需要設(shè)置es的虛擬機(jī)參數(shù)。修改es_home/bin/elasticsearch。如下所示:ES_JAVA_OPTS="-Xms1g -Xmx1g"
5? IK分詞器問題
{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"analyzer [ik_max_word] not found for field [content]"}],"type":"mapper_parsing_exception","reason" :"analyzer [ik_max_word] not found for field [content]"},"status":400}解決:如果出現(xiàn)上述報錯,可能是單節(jié)點安裝了ik分詞器造成的,如果集群是多節(jié)點的,需要集群中每個節(jié)點上都要安裝Ik。
6? Kibana問題
log [16:11:15.912] [error][timelion] Error: in cell #1: Elasticsearch index not found: _all: Error: in cell #1: Elasticsearch index not found: _all?
轉(zhuǎn)載于:https://www.cnblogs.com/frankdeng/p/9139035.html
總結(jié)
以上是生活随笔為你收集整理的CentOS7.5搭建ELK6.2.4集群及插件安装的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: hbuilder版本更新失败_HBuil
- 下一篇: 新建第一个HBuilder项目