elasticsearch6.3.2 安裝

環(huán)境

  • CentOS7
  • 請確保已經(jīng)安裝了jdk1.8或更高的版本

下載

選擇要下載的,我下載的是TAR。按需要下載。

image.png

解壓

我已經(jīng)將安裝包放在了usr/local/software目錄下。

[root@localhost software]# pwd
/usr/local/software
[root@localhost software]# ls
elasticsearch-6.3.2.tar.gz

解壓安裝包,得到 elasticsearch-6.3.2。

tar -zxvf elasticsearch-6.3.2.tar.gz 

我將elasticsearch-6.3.2移動到了usr/local/dev-env目錄下。

[root@localhost dev-env]# pwd
/usr/local/dev-env
[root@localhost dev-env]# mv /usr/local/software/elasticsearch-6.3.2  elasticsearch-6.3.2
[root@localhost dev-env]# ls
elasticsearch-6.3.2  jdk1.8.0_181

啟動異常

當我在elastic下執(zhí)行./bin/elasticsearch,啟動elastic的時候,報了一下錯誤:

[2018-08-09T18:11:32,675][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:140) ~[elasticsearch-6.3.2.jar:6.3.2]
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.3.2.jar:6.3.2]
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.3.2.jar:6.3.2]
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.3.2.jar:6.3.2]
        at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.3.2.jar:6.3.2]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.3.2.jar:6.3.2]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.3.2.jar:6.3.2]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
        at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:104) ~[elasticsearch-6.3.2.jar:6.3.2]
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:171) ~[elasticsearch-6.3.2.jar:6.3.2]
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:326) ~[elasticsearch-6.3.2.jar:6.3.2]
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.3.2.jar:6.3.2]
        ... 6 more

創(chuàng)建用戶

從上面可以看出,我們不能用root來啟動es,那么我們就新建一個用戶

# 添加用戶 elastic
adduser elastic

# 給用戶elastic設置密碼,按照提示輸入自己的密碼
passwd elastic

# 設置權限
chown -R elastic /usr/local/dev-env/elasticsearch-6.3.2

# 切換用戶
su elastic

# 查看權限
ll

啟動elasticsearch

./bin/elasticsearch

## 以守護進程在后臺運行
./bin/elasticsearch -d 

測試啟動結果

執(zhí)行以下操作,查看輸出

curl 'http://localhost:9200'

當然在執(zhí)行時,可能會碰到下面問題

curl: (7) Failed connect to localhost:9200; Connection refused

我們只需要關閉防火墻

service firewalld stop

然后再運行,我們可以看到輸出如下內容:

{
  "name" : "7KfHH2X",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "XihaCbM2Q9Sk3w6yJRhHEw",
  "version" : {
    "number" : "6.3.2",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "053779d",
    "build_date" : "2018-07-20T05:20:23.451332Z",
    "build_snapshot" : false,
    "lucene_version" : "7.3.1",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

外部訪問

上面的設置只能在本地上能訪問。我的linux是按照在虛擬機上的,現(xiàn)在我要在電腦的瀏覽器上訪問。我們發(fā)現(xiàn)是不行的。那么我們需要新的設置

修改elasticsearch目錄下的config/elasticsearch.yml文件

# 設置所有ip都能訪問
network.host: 0.0.0.0

http.port: 9200

其他問題

當我們設置好上面的配置是,又出現(xiàn)了其他的問題,下面一個個的處理

ERROR: [2] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

上面出現(xiàn)了兩個問題,我們一個個的處理。我們先切回到root用戶。

  • 問題 [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

修改文件/etc/security/limits.conf,在其后面追加如下內容:

* soft nofile 65536
* hard nofile 65536
  • 問題 [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

修改文件 /etc/sysctl.conf, 在其后面追加如下內容:

vm.max_map_count=655360

使用命令 sysctl -p 使剛才的設置生效。

最后,我們切換到elastic用戶,并啟動服務./bin/elasticsearch,我們發(fā)現(xiàn)啟動成功,并且能在其他的機器上訪問到es了。

?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容