elk搭建完整搭建【篇1】

參考java

官網:linux

https://www.elastic.co/downloadsnginx

參考:git

http://517sou.net/archives/centos%E4%B8%8B%E4%BD%BF%E7%94%A8elk%E5%A5%97%E4%BB%B6%E6%90%AD%E5%BB%BA%E6%97%A5%E5%BF%97%E5%88%86%E6%9E%90%E5%92%8C%E7%9B%91%E6%8E%A7%E5%B9%B3%E5%8F%B0/github

http://my.oschina.net/itblog/blog/547250web

http://baidu.blog.51cto.com/71938/1676798bootstrap


ELK組成vim

Elasticsearch:centos

Search and analyze data in real time.瀏覽器

Logstash:

Collect, enrich, and transport data.

Kibana:

Explore and visualize your data.


注意:三個組建縮寫ELK


安裝系統環境和軟件包

系統信息:

[root@log_server src]# du -sh elasticsearch-2.2.1.tar.gz logstash-all-plugins-2.2.0.tar.gz kibana-4.4.2-linux-x64.tar.gz 

29M     elasticsearch-2.2.1.tar.gz

72M     logstash-2.2.2.tar.gz

32M     kibana-4.4.2-linux-x64.tar.gz


能夠檢查的校驗碼與官網對比是否包已經下載完整

[root@log_server src]# sha1sum kibana-4.4.2-linux-x64.tar.gz 

6251dbab12722ea1a036d8113963183f077f9fa7  kibana-4.4.2-linux-x64.tar.gz

[root@log_server src]# cat /etc/redhat-release ; uname -m

CentOS release 6.4 (Final)

x86_64

關閉防火牆

[root@log_server src]# /etc/init.d/iptables status

iptables: Firewall is not running.

[root@log_server src]# getenforce 

Disabled

最大文件描述符(默人用戶級別的1024過小咯 要求是65536以上)

[root@master ~]# ulimit -n

102400


修改方式:

打開文件增長兩行 /etc/security/limits.conf 


* soft nofile 102400

* hard nofile 102400


查看 ulimit -n

[root@log_server src]# java -version

java version "1.7.0_99"

OpenJDK Runtime Environment (rhel-2.6.5.0.el6_7-x86_64 u99-b00)

OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)



注意:jdk可自行網上搜索安裝方法

注:因爲Logstash的運行依賴於Java環境, 而Logstash 1.5以上版本不低於java 1.7,所以推薦使用最新版本的Java。由於咱們只須要Java的運行環境,因此能夠只安裝JRE,不過這裏我依然使用JDK,請自行搜索安裝。

(推薦yum安裝yum install -y java-1.7.0-openjdk)

yum install -y java-1.8.0-openjdk.x86_64   (推薦用1.8 不然會有警告)

!!! Please upgrade your java version, the current version '1.7.0_09-icedtea-mockbuild_2013_01_16_18_52-b00' may cause problems. We recommend a minimum version of 1.7.0_51


這是版本建議(推薦1.8)

下載來自官網源和軟件安裝介紹

wKioL1cnQiqyWAMJAACr_DGJnHw790.png


系統環境和版本信息:本文把ELK套件部署在一臺CentOS單機上。

具體的版本要求以下:

wget https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.2.1/elasticsearch-2.2.1.tar.gz
wget https://download.elastic.co/logstash/logstash/logstash-2.2.2.tar.gz
wget https://download.elastic.co/kibana/kibana/kibana-4.4.2-linux-x64.tar.gz

wKiom1cnQfWjIXgDAAD6KIFnyNI326.png

wKioL1cnQsjSDzv1AACz_HEEhNQ969.png

wKioL1cnQsjj_L8MAAEp1HH4NgM563.png




【安裝elasticsearch

解壓、軟鏈接、cd到目錄下

tar xvf elasticsearch-2.2.1.tar.gz -C /usr/local/
ln -s /usr/local/elasticsearch-2.2.1/ /usr/local/elasticsearch
cd /usr/local/elasticsearc

安裝這個重要的插件:

[root@master elasticsearc]# ./bin/plugin install  mobz/elasticsearch-head

-> Installing mobz/elasticsearch-head...

Plugins directory [/usr/local/elasticsearc/plugins] does not exist. Creating...

Trying https://github.com/mobz/elasticsearch-head/archive/master.zip ...

Downloading .................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................DONE

Verifying https://github.com/mobz/elasticsearch-head/archive/master.zip checksums if available ...

NOTE: Unable to verify checksum for downloaded plugin (unable to find .sha1 or .md5 file to verify)

Installed head into /usr/local/elasticsearc/plugins/head


建立用戶和目錄(由於elasticsearch 2.0.0 以上版本不能用root用戶運行)

[root@master elasticsearc]# groupadd -g 1000  elasticsearch  
[root@master elasticsearc]# useradd -g 1000 -u 1000 elasticsearch                           
[root@master elasticsearc]# sudo -u elasticsearch mkdir /tmp/elasticsearch
[root@master elasticsearc]# ls /tmp/elasticsearch
[root@master elasticsearc]# sudo -u elasticsearch mkdir /tmp/elasticsearch/{data,logs}

mkdir /usr/local/elasticsearch/config/scripts   

 

編輯配置文件vim config/elasticsearch.yml  加如如下四行(注意冒號後面有空格):

path.data: /tmp/elasticsearch/data

path.logs: /tmp/elasticsearch/logs

network.host: 192.168.100.10

network.port: 9200


啓動配置默認,啓動elasticsearch

sudo -u elastsearch /usr/local/elasticsearch/bin/elasticsearch


wKioL1cnUT-TvKKMAAC9iLaHDXQ785.png



注意:若是正式應用須要在後臺運行 

sudo -u elastsearch /usr/local/elasticsearch/bin/elasticsearch -d

查看進程和端口

[root@master ~]# ps -ef | grep java

1000      9477  9338  2 21:02 pts/4    00:00:07 /usr/bin/java -Xms256m -Xmx1g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:+DisableExplicitGC -Dfile.encoding=UTF-8 -Djna.nosys=true -Des.path.home=/usr/local/elasticsearch -cp /usr/local/elasticsearch/lib/elasticsearch-2.2.1.jar:/usr/local/elasticsearch/lib/* org.elasticsearch.bootstrap.Elasticsearch start

root      9620  9576  0 21:07 pts/0    00:00:00 grep --color=auto java

[root@master ~]# netstat -tulnp |grep java

tcp        0      0 ::ffff:192.168.100.10:9200  :::*                        LISTEN      9477/java           

tcp        0      0 ::ffff:192.168.100.10:9300  :::*                        LISTEN      9477/java      

注意:

能夠看到,它跟其餘的節點的傳輸端口爲9300,接受HTTP請求的端口爲9200。


# curl 192.168.100.10:9200  

{

  "name" : "Wilson Fisk",

  "cluster_name" : "elasticsearch",

  "version" : {

    "number" : "2.2.1",

    "build_hash" : "d045fc29d1932bce18b2e65ab8b297fbf6cd41a1",

    "build_timestamp" : "2016-03-09T09:38:54Z",

    "build_snapshot" : false,

    "lucene_version" : "5.4.1"

  },

  "tagline" : "You Know, for Search"

}

返回展現了配置的cluster_name和name,以及安裝的ES的版本等信息。

剛剛安裝的head插件,它是一個用瀏覽器跟ES集×××互的插件,能夠查看集羣狀態、集羣的doc內容、執行搜索和普通的Rest請求等。如今也能夠使用它打開http://192.168.100.10:9200/_plugin/head/頁面來查看ES集羣狀態:

上面的功能仍是不錯的!

wKiom1cnUbnivnHSAACHck6M0T8351.png




安裝Logstash---數據日誌存儲和傳輸

Logstash的功能以下:



wKiom1cnUk2TZAxfAAFbN_7tYLc036.png


其實它就是一個收集器而已,收集(input)和傳輸(output),咱們須要爲它指定Input和Output(固然Input和Output能夠爲多個)。能夠指定input的日誌和output到elasticsearch中


解壓、軟鏈接

tar xvf logstash-2.2.2.tar.gz -C /usr/local/
ln -s /usr/local/logstash-2.2.2/ /usr/local/logstash



測試logstash

(1) 屏幕輸入輸出方式測試

/usr/local/logstash/bin/logstash -e 'input { stdin { } } output { stdout {} }'


wKiom1cnU8mxO4KmAAA-81Be9KY249.png


咱們能夠看到,咱們輸入什麼內容logstash按照某種格式輸出,其中-e參數參數容許Logstash直接經過命令行接受設置。這點尤爲快速的幫助咱們反覆的測試配置是否正確而不用寫配置文件。使用CTRL-C命令能夠退出以前運行的Logstash。

使用-e參數在命令行中指定配置是很經常使用的方式


不過若是須要配置更多設置則須要很長的內容。這種狀況,咱們首先建立一個簡單的配置文件,而且指定logstash使用這個配置文件。例如:在logstash安裝目錄下建立


配置logstash

建立配置文件目錄:
mkdir -p /usr/local/logstash/etc
vim /usr/local/logstash/etc/hello_search.conf

輸入下面:

# cat /usr/local/logstash/etc/hello_search.conf

input {

  stdin {

    type => "human"

  }

}


output {

  stdout {

    codec => rubydebug

  }


  elasticsearch {

        hosts => "192.168.100.10:9200"

  }

}

啓動: /usr/local/logstash/bin/logstash -f /usr/local/logstash/etc/hello_search.conf

(以頻幕上輸入的方式輸入,以rubydebug格式輸出到屏幕,而且傳遞到elasticsearch)


wKiom1cnXGej5p0GAABBechG03g483.png



測試logstash日誌是否傳輸到了elasticsearch 

經過如下接口:

curl 'http://192.168.100.10:9200/_search?pretty'


wKioL1cnXUuhvgCrAABQEikbuGw657.png


代表已經接收到了日誌

至此,你已經成功利用ElasticsearchLogstash來收集日誌數據了。



安裝kibana---展現數據


注:如今kibanna能夠自帶了web服務,bin/kibana就能夠直接啓動了,建議不用nginx進行配合啓動了。

使用自帶的web

5.1 安裝Kibana

下載kibana後,解壓到對應的目錄就完成kibana的安裝

解壓、軟鏈接

tar -xzvf kibana-4.4.2-linux-x64.tar.gz -C /usr/local/
ln -s /usr/local/kibana-4.4.2-linux-x64/ /usr/local/kibana

啓動kibanna

/usr/local/kibana-4.4.2-linux-x64/bin/kibana

或者

/usr/local/kibana/bin/kibana


此時是沒有鏈接上elasticsearch



配置kibanna

vim /usr/local/kibana/config/kibana.yml 

修改

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

elasticsearch.url: "http://192.168.100.10:9200"

重啓

/usr/local/kibana/bin/kibana 


wKioL1cnX5PTBCAmAACSn-zs2sA400.png


web訪問:

監聽了5601做爲web端口

使用http://kibanaServerIP5601訪問Kibana,登陸後,首先,配置一個索引,默認,Kibana的數據被指向Elasticsearch,使用默認的logstash-*的索引名稱,而且是基於時間的,點擊「Create」便可。

In order to use Kibana you must configure at least one index pattern. Index patterns are used to identify the Elasticsearch index to run search and analytics against. They are also used to configure fields.

爲了後續使用Kibana,須要配置至少一個Index名字或者Pattern,它用於在分析時肯定ES中的Index


wKiom1cnX77AKXkUAAD96BFyc_8652.png



點擊「Discover」,能夠搜索和瀏覽Elasticsearch中的數據,默認搜索的是最近15分鐘的數據。能夠自定義選擇時間。


wKiom1cnYOHx8u_SAADpwrc2l5g183.png


 到此,說明你的ELK平臺安裝部署完成。




補充:


[配置logstash做爲Indexer]

logstash配置爲索引器,並將logstash的日誌數據存儲到Elasticsearch,本範例主要是索引本地系統日誌



cat /usr/local/logstash/etc/logstash-indexer.conf 

input {

  file {

    type =>"syslog"

     path => ["/var/log/messages", "/var/log/secure" ]

  }

  syslog {

    type =>"syslog"

    port =>"5544"

  }

}

output {

  stdout { codec=> rubydebug }

  elasticsearch {hosts => "192.168.100.10:9200" }

}


執行:

/usr/local/logstash/bin/logstash -f /usr/local/logstash/etc/logstash-indexer.conf 


執行:

echo "谷歌alphago和李世石圍棋大戰"  >> /var/log/messages


wKioL1cnY2TSvlHlAABK7XNFBBg494.png


刷新kibana

wKiom1cnYvbgBCkvAACsJEfDtPk910.png


每一個收集日誌的啓動,都是一個獨立的進程


wKiom1cnY-vyufajAAC0fDQ5_u4295.png

相關文章
相關標籤/搜索