1.准备
-- 系统更新
sudo apt update
sudo apt upgrade
-- 安装vim 文本编辑器
sudo apt install vim-- jdk 版本确认
java -version
jdk 安装可以参照:https://blog.csdn.net/CsethCRM/article/details/140768670
2.官方下载Elasticsearch
官方地址:https://www.elastic.co/downloads/elasticsearch
3.下载的压缩包放在Ubuntu机器/home/env 目录
4.创建用户
注:从5.0开始,ElasticSearch 安全级别提高了,不允许采用root帐号启动,所以我们要添加一个用户
4.1 创建elasticsearch用户-esuser
-- 创建ES用户
sudo useradd -m esuser -d /home/esuser -s /bin/bash
-- 设置密码
sudo passwd esuser-- 设置sudo权限
sudo adduser esuser sudo
chmod +w /etc/sudoers
vim /etc/sudoers# 在文件末尾添加下边内容:esuser ALL=(ALL:ALL) ALL
4.2 切换成esuser用户解压缩
-- 切换到 esuser
sudo su esuser
-- 切换到压缩包所在目录
cd /home/env
-- 创建elasticsearch8目录
sudo mkdir /usr/lib/elasticsearch8
-- 解压缩elasticsearch 到 新建的elasticsearch8目录
sudo tar -zxvf elasticsearch-8.14.3-linux-x86_64.tar.gz -C /usr/lib/elasticsearch8
4.3 修改elasticsearch配置文件
配置文件路径:/usr/lib/elasticsearch8/elasticsearch-8.14.3/config/elasticsearch.yml
修改后如下:
cluster.name: my-application
node.name: node-1
path.data: /usr/lib/elasticsearch8/elasticsearch-8.14.3/data/
path.logs: /usr/lib/elasticsearch8/elasticsearch-8.14.3/logs
network.host: 0.0.0.0http.port: 9200
cluster.initial_master_nodes: ["node-1", "node-2"]xpack.security.enabled: falsexpack.security.enrollment.enabled: truexpack.security.http.ssl:enabled: falsekeystore.path: certs/http.p12xpack.security.transport.ssl:enabled: trueverification_mode: certificatekeystore.path: certs/transport.p12truststore.path: certs/transport.p12http.host: 0.0.0.0http.cors.enabled: true
http.cors.allow-origin: "*"
4.4 修改目录权限
-- 修改目录权限(777表示所有者、所属组和其他用户都有读、写和执行权限)
sudo chmod 777 /usr/lib/elasticsearch8/
sudo chmod 777 /usr/lib/elasticsearch8/elasticsearch-8.14.3/
sudo chmod 777 /usr/lib/elasticsearch8/elasticsearch-8.14.3/config/
-- 改变elasticsearch8 的拥有者账号为 esuser
sudo chown -R esuser /usr/lib/elasticsearch8/
sudo chown -R esuser /usr/lib/elasticsearch8/elasticsearch-8.14.3/
sudo chown -R esuser /usr/lib/elasticsearch8/elasticsearch-8.14.3/config/
4.5 配置elasticsearch并启动
-- 配置Elasticsearch的最低内存要求,切换到root用户,在 /etc/sysctl.conf文件最后添加一行
sudo su root
vim /etc/sysctl.conf--> 添加如下一行:vm.max_map_count=655360
-- 执行sysctl -p 让其生效
sysctl -p-- 启动elasticsearch,切换到 esuser 用户
sudo su esuser
-- 切换到elasticsearch安装目录
cd /usr/lib/elasticsearch8/elasticsearch-8.14.3/
-- 启动elasticsearch
bin/elasticsearch -d-- 打开查看 es
http://机器IP:9200/
4.6 访问网址如下,恭喜,Success.
附录
其它常用命令
-- ubuntu 删除用户
sudo userdel -r esuser--------重新运行 es
1.查找ES进程
ps -ef | grep elastic2.杀掉ES进程
kill -9 4114962(进程号)3.重启ES
sudo su esuser
-- 切换到es目录
cd /usr/lib/elasticsearch8/elasticsearch-8.14.3/
-- 窗口启动
bin/elasticsearch # 窗口
-- 后台启动
bin/elasticsearch -d
遇到的问题
问题1:
报错:fatal exception while booting Elasticsearchjava.lang.IllegalStateException: failed to obtain node locks,tried [xxx];maybe these locations are not wirtable or multiple nodes were started on the same data path?
原因:启动了 不止一次 elasticsearch
解决方案:
1.查找ES进程
ps -ef | grep elastic2.杀掉ES进程
kill -9 4114962(进程号)