環(huán)境說(shuō)明
Centos7, jdk1.8已安裝捣辆,root用戶(hù)登錄
概要
這段時(shí)間一直在研究Elasticsearch環(huán)境搭建元暴,基于目前最新版本Elasticsearch7.2矾踱。環(huán)境包括Elasticsearch7.2下載安裝览绿、kibana7.2安裝配置、logstash7.2安裝和配置mysql8.0的數(shù)據(jù)同步轩端、ik分詞器插件的安裝党涕。
本文只說(shuō)Elasticsearch的安裝烦感,其它會(huì)另寫(xiě)博客說(shuō)明。
開(kāi)始安裝
下載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
新建用戶(hù)
es不能用root用戶(hù)啟動(dòng)手趣,需要自己新建用戶(hù),并賦權(quán)
(我輸?shù)拿艽a比較簡(jiǎn)單骑祟,所以有BAD PASSWORD:這個(gè)提示回懦,不用管它)
## 新建用戶(hù),設(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用戶(hù)缸棵,會(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)容就不貼出來(lái)了谭期,只保留改動(dòng)的部分.
(設(shè)置0.0.0.0可以讓任何人訪問(wèn)到你的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ì)說(shuō)
#discovery.seed_hosts: ["host1", "host2"]
#cluster.initial_master_nodes: ["node-1", "node-2"]
在es用戶(hù)下啟動(dòng)elasticsearch
[root@localhost bin]# su esuser
[esuser@localhost bin]$ cd /usr/local/src/elasticsearch/bin/
[esuser@localhost bin]$ ./elasticsearch
[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]
# 切換root用戶(hù)
[root@localhost config]# vi /etc/security/limits.conf
# 添加如下4行內(nèi)容
* soft nofile 65536
* hard nofile 65536
* soft nproc 4096
* hard nproc 4096
[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: 名稱(chēng)相同
cluster.initial_master_nodes: ["node-1"]
重新啟動(dòng)===》成功!
開(kāi)啟防火墻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
瀏覽器訪問(wèn)
注意
1胀瞪、es啟動(dòng)不能用root賬戶(hù)针余,需要自己新建賬戶(hù)并授權(quán)
2、虛擬機(jī)分配的內(nèi)存不能過(guò)小凄诞,es7.2默認(rèn)啟動(dòng)內(nèi)存是1G(可以修改配置文件更改內(nèi)存參數(shù))圆雁,所以在虛擬機(jī)分配的內(nèi)存可以大一點(diǎn),內(nèi)存過(guò)小帆谍,啟動(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依賴(lài)于jdk,es和jdk有著對(duì)應(yīng)的依賴(lài)關(guān)系汛蝙。如果jdk版本過(guò)低烈涮,es會(huì)啟動(dòng)不了朴肺。
這里由于篇幅的原因,我將重新寫(xiě)一篇博客說(shuō)明下這個(gè)問(wèn)題坚洽。