天天看點

最新版elasticsearch的安裝踩坑

elasticearch是目前最流行的實時的分布式搜尋和分析引擎,水準擴充能力非常強,提供restful接口簡化使用難度。

文檔

學習一個技術最好的方式就是閱讀官方文檔,英語沒有那麼好的最好方式就是看中文版

elasticsearch權威指南中文翻譯,這是我找到的最好一個線上版本。

離線文檔下載下傳點選這裡

最新版elasticsearch的安裝踩坑

工欲善其事必先利其器,下面介紹安裝過程中遇到的坑:

下載下傳

可以到elasticsearch中文社群下載下傳,但是速度很慢。這裡是國内鏡像位址,速度還可以,就是版本不是最新的。

安裝

elasticsearch的安裝需要依賴jdk8或openJDK11,最新版本據說内置了jdk?

不管是通過下載下傳tar包,還是npm,debian包的方式,都注意不要放在root目錄下,要放在非root使用者目錄下,不然權限問題會搞得你頭大。

解壓

tar -zxvf elasticsearch-7.6.2.tar.gz

,切換非root使用者

su - jun

進入bin下面

./elasticsearch

即可啟動,如果不報錯且

curl http://localhost:9200

傳回json資訊表示啟動成功,但事情一般沒有這麼順利。

  1. 如果提示權限不對

    賦予非root使用者權限,

    chown -R jun:jun /home/jun/elasticsearch

  2. 隻有本機能通路

    在安裝目錄下修改

    vim config/elasticsearch.yml

    增加

    network.host: 0.0.0.0

    或者特定的ip

    另外記得防火牆放開端口

    /sbin/iptables -I INPUT -p tcp --dport 9200 -j ACCEPT

  3. max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]

    原因:無法建立本地檔案問題,使用者最大可建立檔案數太小

    解決方案:切換到root使用者

    vi /etc/security/limits.conf

    , 添加類似如下内容:
    * soft nofile 65536
    * hard nofile 131072
    * soft nproc 2048
    * hard nproc 4096
               
    備注:* 代表Linux所有使用者名稱(比如 hadoop)
  4. max number of threads [3798] for user [jun] is too low, increase to at least [4096]

    原因:無法建立本地線程問題,使用者最大可建立線程數太小

    解決方案:切換到root使用者,

    vi /etc/security/limits.d/20-nproc.conf

    找到如下内容:
    • soft nproc 3978

      #修改為

    • soft nproc 4096
  5. max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]

    原因:最大虛拟記憶體太小

    root使用者執行指令:

    [[email protected] ~]# sysctl -w vm.max_map_count=262144

  6. the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured

    修改elasticsearch.yml

    取消注釋保留一個節點

    cluster.initial_master_nodes: ["node-1"]

    ,這裡的node-1是預設的

另外head(nodejs)、分詞器的安裝網上都是,這裡就不多說了

繼續閱讀