Centos7安裝Elasticsearch7.2版本

環(huán)境說明

Centos7, jdk1.8已安裝,root用戶登錄

概要

這段時(shí)間一直在研究Elasticsearch環(huán)境搭建,基于目前最新版本Elasticsearch7.2。環(huán)境包括Elasticsearch7.2下載安裝、kibana7.2安裝配置、logstash7.2安裝和配置mysql8.0的數(shù)據(jù)同步、ik分詞器插件的安裝。
本文只說Elasticsearch的安裝,其它會(huì)另寫博客說明。

開始安裝

下載Elasticsearch7.2

1、登錄Elasticsearch官網(wǎng)下載7.2版本
*點(diǎn)擊可以下載各個(gè)版本的es * https://www.elastic.co/cn/
或者直接復(fù)制我的代碼

[root@localhost tar.gz]# pwd
/usr/local/src/tar.gz
[root@localhost tar.gz]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.2.0-linux-x86_64.tar.gz
[root@localhost tar.gz]# ll
total 328760
-rw-r--r--. 1 root root 336647987 Aug  2 11:39 elasticsearch-7.2.0-linux-x86_64.tar.gz

百度云
鏈接:https://pan.baidu.com/s/1QQ2A20yatNnuU99A_-T4FA
提取碼:po9r

解壓

[root@localhost tar.gz]# tar -zxvf elasticsearch-7.2.0-linux-x86_64.tar.gz -C /usr/local/src/

[root@localhost tar.gz]# cd ..
[root@localhost src]# ll
total 0
drwxr-xr-x. 9 root root 154 Jun 20 23:56 elasticsearch-7.2.0
drwxr-xr-x. 2 root root  53 Aug  2 11:39 tar.gz
[root@localhost src]# mv elasticsearch-7.2.0/ elasticsearch
[root@localhost src]# ll
total 0
drwxr-xr-x. 9 root root 154 Jun 20 23:56 elasticsearch
drwxr-xr-x. 2 root root  53 Aug  2 11:39 tar.gz

新建用戶
es不能用root用戶啟動(dòng),需要自己新建用戶,并賦權(quán)
(我輸?shù)拿艽a比較簡單,所以有BAD PASSWORD:這個(gè)提示,不用管它)



## 新建用戶,設(shè)置密碼
[root@localhost src]# adduser esuser
[root@localhost src]# passwd esuser
Changing password for user esuser.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.
## 授權(quán)
[root@localhost src]# chown -R esuser elasticsearch/

新建文件夾
等會(huì)要配置下elasticsearch.yml,這里先建立兩個(gè)文件夾,數(shù)據(jù)文件夾和日志文件夾,并授權(quán)給es用戶,會(huì)在es的配置文件中使用到。

[root@localhost src]# mkdir /opt/elasticsearch-data
[root@localhost src]# mkdir /opt/elasticsearch-log
[root@localhost config]# chown -R esuser /opt/elasticsearch-data/
[root@localhost config]# chown -R esuser /opt/elasticsearch-log/

編輯elasticsearch.yml
注釋的內(nèi)容就不貼出來了,只保留改動(dòng)的部分.
(設(shè)置0.0.0.0可以讓任何人訪問到你的es)

[esuser@localhost config]$ pwd
/usr/local/src/elasticsearch/config
[esuser@localhost config]$ vi elasticsearch.yml
cluster.name: es-application
node.name: node-1
path.data: /opt/elasticsearch-data
path.logs: /opt/elasticsearch-log
network.host: 0.0.0.0
http.port: 9200
# 下面這兩個(gè)是默認(rèn)配置,我先保留等下會(huì)說
#discovery.seed_hosts: ["host1", "host2"]
#cluster.initial_master_nodes: ["node-1", "node-2"]

在es用戶下啟動(dòng)elasticsearch

[root@localhost bin]# su esuser
[esuser@localhost bin]$ cd /usr/local/src/elasticsearch/bin/
[esuser@localhost bin]$ ./elasticsearch

報(bào)錯(cuò)
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max number of threads [3800] for user [esuser] is too low, increase to at least [4096]
[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

解決 問題[1]、問題[2]

# 切換root用戶
[root@localhost config]# vi /etc/security/limits.conf
# 添加如下4行內(nèi)容
*        soft    nofile      65536
*        hard    nofile      65536
*        soft    nproc       4096
*        hard    nproc       4096
image.png

解決 問題[3]

[root@localhost config]# vi /etc/sysctl.conf
# 添加下面這行
vm.max_map_count=655360

重新啟動(dòng)依舊報(bào)錯(cuò)
ERROR: [1] bootstrap checks failed
[1]: 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
解決
需要配置cluster.initial_master_nodes,修改 elasticsearch.yml,
由于暫時(shí)我們的es是單節(jié)點(diǎn)的,所以只要配置一個(gè)node節(jié)點(diǎn)就行了,
這里node-1必須和 node.name: 名稱相同

cluster.initial_master_nodes: ["node-1"]

重新啟動(dòng)===》成功!

image.png

開啟防火墻9200端口

[esuser@localhost bin]$ su root
Password: 
[root@localhost bin]# firewall-cmd --zone=public --add-port=9200/tcp --permanent
[root@localhost bin]# systemctl restart firewalld.service

瀏覽器訪問

image.png

注意

1、es啟動(dòng)不能用root賬戶,需要自己新建賬戶并授權(quán)
2、虛擬機(jī)分配的內(nèi)存不能過小,es7.2默認(rèn)啟動(dòng)內(nèi)存是1G(可以修改配置文件更改內(nèi)存參數(shù)),所以在虛擬機(jī)分配的內(nèi)存可以大一點(diǎn),內(nèi)存過小,啟動(dòng)報(bào)錯(cuò)。

擴(kuò)展

Elasticsearch7.2在啟動(dòng)的時(shí)候會(huì)看到第一行信息是這樣的:
future versions of Elasticsearch will require Java 11; your Java version from [/opt/jdk1.8.0_211/jre] does not meet this requirement

這是由于Elasticsearch依賴于jdk,es和jdk有著對應(yīng)的依賴關(guān)系。如果jdk版本過低,es會(huì)啟動(dòng)不了。
這里由于篇幅的原因,我將重新寫一篇博客說明下這個(gè)問題。

Elasticsearch7.2啟動(dòng)指定JDK11

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

友情鏈接更多精彩內(nèi)容