环境说明
Centos7, jdk1.8已安装,root用户登录
概要
这段时间一直在研究Elasticsearch环境搭建,基于目前最新版本Elasticsearch7.2。环境包括Elasticsearch7.2下载安装、kibana7.2安装配置、logstash7.2安装和配置mysql8.0的数据同步、ik分词器插件的安装。
本文只说Elasticsearch的安装,其它会另写博客说明。
开始安装
下载Elasticsearch7.2
1、登录Elasticsearch官网下载7.2版本
*点击可以下载各个版本的es * https://www.elastic.co/cn/
或者直接复制我的代码
[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用户启动,需要自己新建用户,并赋权
(我输的密码比较简单,所以有BAD PASSWORD:这个提示,不用管它)
## 新建用户,设置密码
[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.
## 授权
[root@localhost src]# chown -R esuser elasticsearch/
新建文件夹
等会要配置下elasticsearch.yml,这里先建立两个文件夹,数据文件夹和日志文件夹,并授权给es用户,会在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
注释的内容就不贴出来了,只保留改动的部分.
(设置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
# 下面这两个是默认配置,我先保留等下会说
#discovery.seed_hosts: ["host1", "host2"]
#cluster.initial_master_nodes: ["node-1", "node-2"]
在es用户下启动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用户
[root@localhost config]# vi /etc/security/limits.conf
# 添加如下4行内容
* soft nofile 65536
* hard nofile 65536
* soft nproc 4096
* hard nproc 4096
image.png
[root@localhost config]# vi /etc/sysctl.conf
# 添加下面这行
vm.max_map_count=655360
重新启动依旧报错
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,
由于暂时我们的es是单节点的,所以只要配置一个node节点就行了,
这里node-1必须和 node.name: 名称相同
cluster.initial_master_nodes: ["node-1"]
重新启动===》成功!
开启防火墙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启动不能用root账户,需要自己新建账户并授权
2、虚拟机分配的内存不能过小,es7.2默认启动内存是1G(可以修改配置文件更改内存参数),所以在虚拟机分配的内存可以大一点,内存过小,启动报错。
扩展
Elasticsearch7.2在启动的时候会看到第一行信息是这样的:
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有着对应的依赖关系。如果jdk版本过低,es会启动不了。
这里由于篇幅的原因,我将重新写一篇博客说明下这个问题。
网友评论