1. 程式人生 > >elasticsearch 使用心得

elasticsearch 使用心得

map 驗證 文件 命令 mit sso pro yml package

安裝所遇到的問題:
http://www.bubuko.com/infodetail-1889252.html

一,先創建用戶和組
groupadd es useradd -g es es passwd es

二,下載對應文件

Download and install the .tar.gz packageedit

The .tar.gz archive for Elasticsearch v5.4.0 can be downloaded and installed as follows:

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.4.0.tar.gz
sha1sum elasticsearch-5.4.0.tar.gz 技術分享

三,切換用戶並解壓文件
su es tar -xzf elasticsearch-5.4.0.tar.gz
然後chmod 777 給文件所在的目錄授權 cd elasticsearch-5.4.0/
四,啟動軟件

[[email protected] ~]# su es
[[email protected] root]$ cd elasticsearch-5.4.0
[[email protected] elasticsearch-5.4.0]$ ./bin/elasticsearch

技術分享

啟動後總是這裏報錯,然後參考下面文章進行修改。
五,排錯的過程
結合tail命令進行排查

[[email protected] ~]# tail -100f /root/elasticsearch-5.4.0/logs/elasticsearch.log



ELK學習系列文章第二章:elasticsearch常見錯誤與配置簡介::

http://m.blog.csdn.net/article/details?id=53577115

在安裝Elasticsearch時候,會出現一些坑,我這裏做個總結,目的是進行一些記錄以及後面使用的童鞋一個參考,同時把其配置做一個簡介。

一、常見錯誤

1.1 root用戶啟動elasticsearch報錯

Elasticsearch為了安全考慮,不讓使用root啟動,解決方法新建一個用戶,用此用戶進行相關的操作。如果你用root啟動,會出現“java.lang.RuntimeException: can not runelasticsearch as root”錯誤,具體如下所示:

技術分享

1.2 JVM虛擬機內存不足

錯誤:“JavaHotSpot(TM) 64-Bit Server VM warning: INFO: error=‘Cannotallocate memory‘ (errno=12)”表示內存不足,其配置文件為config目錄下的jvm.options,默認為2g,可以修改為1g。

1.3 max_map_count過小

錯誤“max virtual memory areas vm.max_map_count [65530]is too low, increase to at least [262144]”,max_map_count文件包含限制一個進程可以擁有的VMA(虛擬內存區域)的數量,系統默認是65530,修改成262144。解決方法是修改/etc/sysctl.conf配置文件,添加vm.max_map_count=262144,記得需要重啟機器才起作用,修改後配置如下圖所示:

技術分享

1.4 max file descriptors過小

錯誤“max file descriptors [65535] for elasticsearchprocess is too low, increase to at least [65536]”,maxfile descriptors為最大文件描述符,設置其大於65536即可。解決方法是修改/etc/security/limits.conf文件,添加“* - nofile65536 * - memlock unlimited”,“*”表示給所有用戶起作用,修改後的配置如下圖所示:

技術分享

一定要重新啟動機器要不死活就是你麻痹的,啟動不了。

1.5外網訪問設置

細心的同學也許發現第一章驗證是用的“localhost:9200”,如果換成“IP:9200”,則瀏覽器與curl都無法進行訪問,那麽如何讓外網訪問呢?網上查了一下,需要修改config目錄下elasticsearch.yml文件,修改network.host為“0.0.0.0”,然後進行啟動成功,外網就可以訪問啦。但是很遺憾,在我的機器還出現了其他錯誤,具體如下所示:

技術分享

通過上面的錯誤信息,想到需要修改config目錄下elasticsearch.yml文件,修改discovery.zen.ping.unicast.hosts為“[“0.0.0.0”]”,然後再次啟動,發現沒有報錯信息(註意防火墻對於端口的限制),同時遠程瀏覽器訪問也正常,如下圖所示:

技術分享

elasticsearch 使用心得