安裝logstash,elasticsearch,kibana三件套,搜索程序通常由索引鏈及搜索組件組成。html
索引鏈功能的實現須要按照幾個獨立的步驟依次完成:檢索原始內容、根據原始內容來建立對應的文檔、對建立的文檔進行索引。java
搜索組件用於接收用戶的查詢請求並返回相應結果,通常由用戶接口、構建可編程查詢語句的方法、查詢語句執行引擎及結果展現組件組成。node
Elasticsearch是個開源分佈式搜索引擎,它的特色有:分佈式,零配置,自動發現,索引自動分片,索引副本機制, restful 風格接口,多數據源,自動搜索負載等。nginx
Logstash 是一個徹底開源的工具,他能夠對你的日誌進行收集、分析,並將其存儲供之後使用(如,搜索)。git
kibana也是一個開源和免費的工具,他Kibana 能夠爲 Logstash 和 ElasticSearch 提供的日誌分析友好的 Web 界面,能夠幫助您彙總、分析和搜索重要數據日誌github
1、安裝java:web
[root@cml3 elasticsearch-5.6.3]# yum install -y *jdk*
2、配置訪問最大文件數:npm
[root@node2 src]# cat /etc/security/limits.conf * soft nofile 65536 * hard nofile 131072 * soft nproc 2048 * hard nproc 4096 [root@node2 src]# vim /etc/security/limits.d/20-nproc.conf * soft nproc 4096 [root@node2 src]# vim /etc/sysctl.conf vm.max_map_count=655360 並執行命令,使其生效: [root@node2 src]# sysctl -p
2、在解壓目錄下建立,log,data文件目錄:編程
[root@cml3 elasticsearch-5.6.3]# mkdir data [root@cml3 elasticsearch-5.6.3]# mkdir log [root@cml3 elasticsearch-5.6.3]# mkdir logs ##有時候沒有這個目錄就本身手動建立
3、修改elastic.yaml:監聽主機(這裏假如你想使用外網去進行訪問,network.host修改爲0.0.0.0)vim
[root@cml3 elasticsearch-5.6.3]# vim config/elasticsearch.yml node.name: cml3 network.host: 192.168.5.104 discovery.zen.minimum_master_nodes: 1
##由於我這裏演示的是在一臺機器上安裝(因此節點改成1)
4、建立elastic用戶用來開啓elasticsearch(這是出於系統安全考慮設置的條件。因爲ElasticSearch能夠接收用戶輸入的腳本而且執行,爲了系統安全考慮,
建議建立一個單獨的用戶用來運行ElasticSearch)
[root@cml3 elasticsearch-5.6.3]# useradd elastic [root@cml3 elasticsearch-5.6.3]# ls bin config data lib LICENSE.txt log logs modules NOTICE.txt plugins README.textile
##有時候會小了目錄本身手動建立上就能夠了:
[root@cml3 logs]# ll total 4 -rw-rw-r-- 1 elastic elastic 0 Nov 3 19:52 elasticsearch_deprecation.log -rw-rw-r-- 1 elastic elastic 0 Nov 3 19:52 elasticsearch_index_indexing_slowlog.log -rw-rw-r-- 1 elastic elastic 0 Nov 3 19:52 elasticsearch_index_search_slowlog.log
##由於5.0的版本爲了安全不能使用root用戶啓動因此給elasticsearch-5.6.3目錄下elastic(能夠自定義用戶)的用戶權限
##開啓haed:插件:
http.cors.enabled:true http.cors.allow-origin:"*"
##開啓的時候會有如下錯誤:
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should conf...CThreads=N
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot a ...'(errno=12)
##解決方法:
意思是內存不夠,加大內存重啓就能夠了!
##有時候還會出現如下錯誤:
[elastic@cml3 bin]$ ./elasticsearch
Exception in thread "main"2017-11-03 20:38:47,194 main ERROR No log4j2 configuration file found. Usingdefault configuration: logging only errors to the console. Set system property'log4j2.debug' to show Log4j2 internal initialization logging.
2017-11-03 20:38:47,646 main ERROR Couldnot register mbeans java.security.AccessControlException: access denied("javax.management.MBeanTrustPermission" "register")
##解決方法:直接安裝幾個log4j包就ok啦
[root@cml3 elasticsearch-5.6.3]# yum install -y log4j*
5、啓動elastic:直接用curl訪問9200端口成功便可
[root@cml3 elasticsearch-5.6.3]# netstat -ntlp Active Internet connections (only servers) tcp6 0 0 192.168.5.104:9200 :::* LISTEN 3749/java tcp6 0 0 192.168.5.104:9300 :::* LISTEN 3749/java
1、介紹:
在以往的es版本有一個很是好用的插件叫head,能夠方便的查看索引,集羣等相關狀態:
5.0以後head安裝支持目前只是支持插件的方式:
2、建立存放這個插件的目錄:
#mkdir head ##隨意目錄下建立就行 #cd head #git clone git://github.com/mobz/elasticsearch-head.git #cd elasticsearch-head yum install -y npm* ##缺乏npm就直接安裝就ok了 #npm install ##這個步驟下載包都是國外地址因此安裝起來比較慢 #npm install -g grunt-cli #grunt server
3、監聽端口爲localhost,能夠修改配置文件:
[root@controller head]# cd elasticsearch-head/ [root@controller elasticsearch-head]#vim Gruntfile.js 作以下修改: server: { options: { port: 9100, hostname: '0.0.0.0', #####添加這句。 base: '.', keepalive: true } } }
修改es配置文件添加以下:
[root@controller config]# vim elasticsearch.yml http.cors.enabled:true http.cors.allow-origin:"*"
#####而後重啓es服務
4、啓動head插件,而後訪問web的ip與端口便可:
#grunt server
##就能夠看到咱們相關索引的狀態,分片集羣等相關操做均可以在上面完成:
1、下載解壓logstash:
下載地址: https://artifacts.elastic.co/downloads/logstash/logstash-5.6.3.tar.gz
[root@cml3 src]# tar -xf logstash-5.6.3.tar.gz
2、建立conf的目錄
[root@cml3 ~]# mkdir /logstash/ [root@cml3 logstash]# vim input_flter_output.conf input { file{ path=> "/usr/local/nginx/logs/cml.log" ##nginx生成日誌的目錄 type=> "cml" ##索引的類型 start_position=> "beginning" ##一開始就輸入原來的日誌信息 } stdin{} } filter{ grok { match => { "message" =>"(?<remote_IP>\d+.\d+.\d+.\d+)\s-\s-\s\[(?<DATA>\d+/\w+/\d+:\d+:\d+:\d+)[[:space:]](?<time_zone>\+\d+)\]\s\"(?<action>\w+)%{URIPATHPARAM:request} (?<Version>\w+/\d+.\d+)\"\s(?<status>\w+)\s(?<web_size>\w+)\s\"(?<language>\S+)\"\s" ##自定義grok } } } output{ elasticsearch{ action=> "index" hosts=> "192.168.5.104:9200" ##輸出到elasticsearch上面 index=> "log-%{+yyyy.MM.dd}" ##生成一個log-時間的索引 } stdout {codec=>rubydebug} ##在終端上輸出方便檢測 }
3、啓動logstash
[root@cml3 logstash]# /usr/local/src/logstash-5.6.3/bin/logstash -f input_flter_output.conf
1、下載安裝kibana:
[root@cml3 logstash]# cd /usr/local/src/ [root@cml3 src]# wget https://artifacts.elastic.co/downloads/kibana/kibana-5.6.3-x86_64.rpm [root@cml3 src]# rpm -ivh kibana-5.6.3-x86_64.rpm
2、修改kibana配置文件:
[root@controller config]# vim kibana.yml server.host: "192.168.63.246" elasticsearch.url: http://192.168.63.246:9200 elasticsearch.username: "elastic" elasticsearch.password: "pwd"
##x-pack默認超級用戶的登陸密碼(es和kibana兩個的超級管理員帳號密碼都同樣,這裏我就爲了方便不使用密碼用戶登陸了。)
3、啓動kibana
[root@cml3 src]# systemctl start kibana
瀏覽器輸入http://IP:5601配置input_flter_output.conf文件定義的索引。(圖形化配置kibana)
##點擊Discover選擇log*索引就能夠看到日誌的數據出來了。
##點擊儀表板而後建立一個儀表盤:
##接下來就是建立一個圖表
##這裏就能夠定義本身想要的圖表了:
##我比較喜歡看柱形圖,選擇本身的索引:
##最終能夠出來的結果(我添加了request項是訪問的url)也能夠是客戶端的IP