1. 如何找到安装包
- 官方下载安装地址:www.elastic.co/cn/download…
- 找到你想要安装的版本
2. 开始下载并安装
- 下载
cd /usr/local/
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.8.0-linux-x86_64.tar.gz
- 解压安装
tar -xvf elasticsearch-7.8.0-linux-x86_64.tar.gz
- elasticsearch 目录结构
cd elasticsearch-7.8.0/
ls -l
目录 | 作用 |
---|---|
bin | 可执行的脚本文件,包括启动 es、运行统计数据等 |
config | 配置文件目录 |
jdk | 内置的Java运行环境 |
lib | Java类库 |
logs | 日志文件 |
modules | 包含所有的es模块 |
plugins | 包含所有已安装的插件 |
3. 启动 elasticsearch
cd /usr/local/elasticsearch-7.8.0/bin
./elasticsearch
3.1 启动报错问题一
[root@vhpuccrv4yxgkqwq-0530595 bin]# ./elasticsearch
future versions of Elasticsearch will require Java 11; your Java version from [/software/jdk1.8.0_231/jre] does not meet this requirement
future versions of Elasticsearch will require Java 11; your Java version from [/software/jdk1.8.0_231/jre] does not meet this requirement
已杀死
(1) 报错原因
- elasticsearch7.x 开始 JDK默认使用的是 JDK11,而我本地安装的是 JDK8
(2) 解决方案
修改 /usr/local/elasticsearch-7.8.0/bin/elasticsearch-env
脚本文件
vim elasticsearch-env
- 在 36 行下面新增如下代码,并修改 40~42 行代码
# use elasticsearch jdk
ES_JAVA_HOME="/usr/local/elasticsearch-7.8.0/jdk"
3.2 启动报错问题二 can not run elasticsearch as root
uncaught exception in thread [main]
java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:111)
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:178)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:393)
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170)
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:161)
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:127)
at org.elasticsearch.cli.Command.main(Command.java:90)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:126)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92)
For complete error details, refer to the log at /usr/local/elasticsearch-7.8.0/logs/elasticsearch.log
2022-10-04 03:58:48,747087 UTC [20824] ERROR CNamedPipeFactory.cc@226 Unable to open named pipe /tmp/elasticsearch-2714581713060259516/controller_log_20671 for writing: Interrupted system call
2022-10-04 03:58:48,747907 UTC [20824] ERROR CLogger.cc@298 Cannot log to named pipe /tmp/elasticsearch-2714581713060259516/controller_log_20671 as it could not be opened for writing
2022-10-04 03:58:48,747935 UTC [20824] FATAL Main.cc@102 Could not reconfigure logging
- 这个异常信息的意思就是 elasticsearch 7.x 的版本中安装成功之后不能以root用户来直接启动
(1) 添加一个普通用户
用这个普通用户来启动 elasticsearch 服务
adduser es
passwd es
cd /usr/local
chown -R es elasticsearch-7.8.0 #赋权限,让 es 用户可以执行该目录下的文件
3.3 正常启动后问题
(1) 此时能够正常启动es ,但是无法访问云主机 9200 端口
- 云主机要开放安全组,即对外开放 9200 端口,并且关闭防火墙
vim elasticsearch.yml
#配置 network.host: 0.0.0.0
(2) 再次启动时又报错bootstrap checks failed
[es@vhpuccrv4yxgkqwq-0530595 bin]$ ./elasticsearch
[2022-10-04T12:20:48,149][INFO ][o.e.n.Node ] [vhpuccrv4yxgkqwq-0530595.novalocal] initialized
[2022-10-04T12:20:48,149][INFO ][o.e.n.Node ] [vhpuccrv4yxgkqwq-0530595.novalocal] starting ...
[2022-10-04T12:20:48,351][INFO ][o.e.t.TransportService ] [vhpuccrv4yxgkqwq-0530595.novalocal] publish_address {192.168.1.52:9300}, bound_addresses {[::]:9300}
[2022-10-04T12:20:48,912][INFO ][o.e.b.BootstrapChecks ] [vhpuccrv4yxgkqwq-0530595.novalocal] bound or publishing to a non-loopback address, enforcing bootstrap checks
ERROR: [3] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[3]: 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
ERROR: Elasticsearch did not exit normally - check the logs at /usr/local/elasticsearch-7.8.0/logs/elasticsearch.log
[2022-10-04T12:20:48,993][INFO ][o.e.n.Node ] [vhpuccrv4yxgkqwq-0530595.novalocal] stopping ...
[2022-10-04T12:20:49,036][INFO ][o.e.n.Node ] [vhpuccrv4yxgkqwq-0530595.novalocal] stopped
[2022-10-04T12:20:49,036][INFO ][o.e.n.Node ] [vhpuccrv4yxgkqwq-0530595.novalocal] closing ...
[2022-10-04T12:20:49,062][INFO ][o.e.n.Node ] [vhpuccrv4yxgkqwq-0530595.novalocal] closed
[2022-10-04T12:20:49,065][INFO ][o.e.x.m.p.NativeController] [vhpuccrv4yxgkqwq-0530595.novalocal] Native controller process has stopped - no new native processes can be started
解决办法,切换到 root 用户,依次执行如下操作:
- 第一步
配置 elasticsearch.yml
discovery.seed_hosts: ["0.0.0.0"]
- 第二步
sysctl -w vm.max_map_count=262144 (临时解决方案) <br/>
在 /etc/sysctl.conf 文件最后添加一行 vm.max_map_count=262144 (永久解决方案)
vim /etc/security/limits.conf
# 配置
* hard nofile 65536
* soft nofile 65536
# 这个es表示你创建的用户名
es hard nofile 65536
es soft nofile 65536
cd /etc/systemd/system
# 创建目录
mkdir elasticsearch.service.d
cd elasticsearch.service.d
vim override.conf
[Service]
LimitMEMLOCK=infinity
LimitNOFILE=65536
systemctl daemon-reload
修改完成后重启 linux 服务器
3.4 后台启动服务
./elasticsearch -d -p pid
到这里 elasticsearch 的安装并启动算是正式完成!!!