1. 程式人生 > >ElasticSearch單節點模式的搭建

ElasticSearch單節點模式的搭建

環境CentOS7
安裝了JDK1.8
這裡用的elasticsearch5.2.2為例,你也可以用5.6.1或者更高的版本

1.最好以非root使用者解壓ElasticSearch,如果用root使用者,要不然以後還要將檔案的許可權以及組轉移給非foot使用者
1)解壓elasticsearch-5.2.2.tar.gz到/opt/module目錄下
[[email protected] ~]# su asy
[[email protected] root]$ tar -zxvf elasticsearch-5.2.2.tar.gz -C /opt/module
2)在/opt/module/elasticsearch-5.2.2路徑下建立data和logs資料夾
mkdir data
mkdir logs

如果你用root賬號,請先新增一個非root賬號,因為elaticsearch不能用root賬號執行
user add asy
chown -R asy:asy /opt/module/elasticsearch-5.2.2/

3)root賬號修改配置檔案/opt/module/elasticsearch-5.2.2/config/elasticsearch.yml
[[email protected] config]# pwd
/opt/module/elasticsearch-5.2.2/config
[[email protected] config]# vi elasticsearch.yml
修改以下引數

---------------------------------- Cluster -------------------------------------

cluster.name: Asy

------------------------------------ Node --------------------------------------(三個不能一樣)

node.name: node-1

----------------------------------- Paths ---------------------------------------

path.data: /opt/module/elasticsearch-5.2.2/data
path.logs: /opt/module/elasticsearch-5.2.2/logs

----------------------------------- Memory -----------------------------------

bootstrap.memory_lock: false
bootstrap.system_call_filter: false

---------------------------------- Network ------------------------------------

network.host: hdp21
http.port: 9200

--------------------------------- Discovery ------------------------------------

discovery.zen.ping.unicast.hosts: ["hdp21"]

path.data
path.logs data和logs的路徑

network.host ip地址或者host域名地址
http.port埠號

5)配置linux系統環境(參考:
(1)編輯limits.conf 新增類似如下內容
[[email protected] config]# vi /etc/security/limits.conf
新增如下內容:

  • soft nofile 65536
  • hard nofile 131072
  • soft nproc 2048
  • hard nproc 4096
    (2)進入limits.d目錄下修改配置檔案。
    [[email protected] config]# vi /etc/security/limits.d/20-nproc.conf
    修改如下內容:如果超過2048則不用修改
  • soft nproc 1024
    #修改為
  • soft nproc 2048
    (3)修改配置sysctl.conf
    [[email protected] config]# vi /etc/sysctl.conf
    新增下面配置:
    vm.max_map_count=655360

退回到上一級目錄
並執行命令:
[[email protected] config]# cd ..
[[email protected] elasticsearch-5.2.2]# pwd
/opt/module/elasticsearch-5.2.2

[[email protected] elasticsearch-5.2.2]# sysctl -p
然後,重新啟動elasticsearch,即可啟動成功。
6)啟動elasticsearch
[[email protected] elasticsearch-5.2.2]$ bin/elasticsearch
後臺啟動方式
[[email protected] elasticsearch-5.2.2]$ bin/elasticsearch-d
7)測試elasticsearch
[[email protected] ~]# curl http://hdp21:9200
{
"name" : "node1",
"cluster_name" : "Asy",
"cluster_uuid" : "8T7xJ-NLTbmYHOPKa3a4tA",
"version" : {
"number" : "5.2.2",
"build_hash" : "f9d9b74",
"build_date" : "2017-02-24T17:26:45.835Z",
"build_snapshot" : false,
"lucene_version" : "6.4.1"
},
"tagline" : "You Know, for Search"
}

執行bin/elasticsearch的時候
如果有 max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536] 的報錯

這個對應v/etc/security/limits.conf

  • soft nofile 65536
    已經修改了,怎麼不生效呢?
    重新進入該非 root user即可

Google瀏覽器除錯Elastic Search
開啟更多工具,擴充套件程式並且開啟開發者模式
將elasticsearch-head.crx拖入瀏覽器視窗成功完成外掛的安裝
輸入http://192.168.234.21:9200/
其中192.168.234.21為linux主機的IP地址,9200為埠號
ElasticSearch單節點模式的搭建