網上關於ELk的搭建有不少,下面是我搭建的過程,記錄下來。html
# vim /etc/sysconfig/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 9200 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 9292 -j ACCEPT # service iptables restart
http.cors.enabled: true #233行
wget https://github.com/elasticsearch/elasticsearch-servicewrapper/archive/master.tar.gz
mv elasticsearch-servicewrapper-master/service/ /usr/local/elasticsearch/bin/
/usr/local/elasticsearch/bin/service/elasticsearch start
3、搭建logstash
3.1 下載地址:
wget https://download.elasticsearch.org/logstash/logstash/logstash-1.4.2.tar.gz
3.2 tar xfz logstash-1.4.2.tar.gz
3.3 ln -s logstash-1.4.2 logstash
3.4 測試
/usr/local/logstash/bin/logstash -e 'input { stdin { } } output { stdout {} }'
3.5 mkdir /usr/local/logstash/etc
3.6 建立配置文件
vim /usr/local/logstash/etc/logstash_agent.conf
input { file { type => "http.access" path => ["/var/log/httpd/access_log"] } file { type => "http.error" path => ["/var/log/httpd/error_log"] } file { type => "messages" path => ["/var/log/messages"] } } output { elasticsearch { host => "192.168.241.144" port => 9300 } }
3.7 啓動服務
集羣存放路徑:/export/search/elasticsearch-clusternode
6.1. 解壓tar包,建立集羣節點nginx
#進入到集羣路徑 [root@localhost elasticsearch-cluster]# pwd /export/search/elasticsearch-cluster #重命名解壓包 [root@localhost elasticsearch-cluster]# ls elasticsearch-1.4.1 [root@localhost elasticsearch-cluster]# mv elasticsearch-1.4.1 elasticsearch-node1#進入到節點配置路徑 [root@localhost elasticsearch-cluster]# cd elasticsearch-node1/config/ [root@localhost config]# ls elasticsearch.yml logging.yml
6.2.建立集羣配置信息:git
# elasticsearch-node1配置# 配置集羣名稱 cluster.name: elasticsearch-cluster-centos # 配置節點名稱 node.name: "es-node1"# 爲節點之間的通訊設置一個自定義端口(默認爲9300) transport.tcp.port: 9300 # 設置監聽HTTP傳輸的自定義端(默認爲9200) http.port: 9200
elasticsearch配置文件說明見: http://blog.csdn.net/an74520/article/details/10175603github
3.安裝head插件redis
#進入到節點bin路徑 [root@localhost bin]# pwd /export/search/elasticsearch-cluster/elasticsearch-node1/bin 安裝插件 [root@localhost bin]# ./plugin -install mobz/elasticsearch-head
安裝完插件以後會在es節點bin路徑同級建立一個plugins目錄,存放安裝的插件vim
4.複製一份配置好的節點爲elasticsearch-node2centos
[root@localhost elasticsearch-cluster]# ls elasticsearch-node1 elasticsearch-node2
5.修改節點2中的集羣配置信息app
# elasticsearch-node2配置# 配置集羣名稱 cluster.name: elasticsearch-cluster-centos # 配置節點名稱 node.name: "es-node2"# 爲節點之間的通訊設置一個自定義端口(默認爲9300) transport.tcp.port: 9301 # 設置監聽HTTP傳輸的自定義端(默認爲9200) http.port: 9201
說明:cors
上面配置表示集羣中有2個節點,節點名爲別爲,"es-node1"和 "es-node2",同屬於集羣"elasticsearch-cluster-centos"
節點二中端口能夠不用配置,es在啓動時會去檢測,若是目標端口被佔用,會檢測下一個端口.由於兩節點部署在同一天虛擬機上爲了更好的說明問題,這裏手動配置了對應的端口.
咱們能夠從es對應日誌中()查看對應的啓動信息,以及端口綁定信息。
6.分別啓動節點
[root@localhost bin]# pwd /export/search/elasticsearch-cluster/elasticsearch-node1/bin [root@localhost bin]# ./elasticsearch -d -Xms2048m -Xmx2048m
如上,爲啓動節點1的命令,es啓動配置相關日誌查看elasticsearch-cluster- centos.log便可.
[root@localhost logs]# pwd /export/search/elasticsearch-cluster/elasticsearch-node2/logs [root@localhost logs]# ls elasticsearch-cluster-centos_index_indexing_slowlog.log elasticsearch-cluster-centos.log elasticsearch-cluster-centos_index_search_slowlog.log
7. 至此咱們的簡易集羣配置完成.查看集羣
由於咱們安裝了head插件,因此能夠經過該插件查看,虛擬機ip爲192.168.19.56.
http://192.168.19.56:9200/_plugin/head/ (對應節點1) http://192.168.19.56:9201/_plugin/head/ (對應節點2)