Linux上安装Elasticsearch

Linux上安装Elasticsearch

1. 下载安装包

官网下载地址: https://www.elastic.co/cn/downloads/elasticsearch

2. 上传到linux服务器

3. 解压

tar -zxvf elasticsearch-8.7.1-linux-x86_64.tar.gz -C /www/wwwroot

4. 修改配置文件

位置:相对位置/elasticsearch-8.7.1/config/elasticsearch.yml,添加如下

# 数据目录位置
path.data: /www/wwwroot/es/dataES
# 日志目录位置
path.logs: /www/wwwroot/es/logsES
# 默认只允许本机访问,修改为0.0.0.0后则可以远程访问
# 绑定到0.0.0.0,允许任何ip来访问
network.host: 0.0.0.0
# 在添加下面参数让elasticsearch-head插件可以访问es
http.cors.enabled: true
http.cors.allow-origin: "*"
# 修改端口号(非必须)
http.port: 19200

cluster.initial_master_nodes: ["VM-4-7-centos"]

5. 扩大内存权限

位置:绝对位置:/etc/sysctl.conf,添加一行

vm.max_map_count=262144

然后控制台运行:sysctl -p

6. 启动ES(注意:root用户无法启动)

创建用户

useradd yizhi

创建所属组,赋予es文件操作权限:

chown yizhi:yizhi -R 相对位置/elasticsearch-8.7.1

切换到yizhi用户

su yizhi

进入bin目录

cd 相对位置/elasticsearch-8.7.1/bin

启动elasticsearch,注意:第一次启动一定要前台启动

前台运行, Ctrl + C 终止

./elasticsearch

后台运行

elasticsearch -d

启动成功后会返回一段信息,其中包含了初始用户名、密码等信息
✅ Elasticsearch security features have been automatically configured!
✅ Authentication is enabled and cluster connections are encrypted.

ℹ️  Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):
  XXXXXXXXXXXX

ℹ️  HTTP CA certificate SHA-256 fingerprint:
  XXXXXXXXXXXXXXXXX

ℹ️  Configure Kibana to use this cluster:
• Run Kibana and click the configuration link in the terminal when Kibana starts.
• Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes):
  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=

ℹ️ Configure other nodes to join this cluster:
• Copy the following enrollment token and start new Elasticsearch nodes with `bin/elasticsearch --enrollment-token <token>` (valid for the next 30 minutes):
  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=

  If you're running in Docker, copy the enrollment token and run:
  `docker run -e "ENROLLMENT_TOKEN=<token>" docker.elastic.co/elasticsearch/elasticsearch:8.7.1`

用户名为elastic,密码为XXXXXXXXXXXX

开放防火墙,没修改是9200 , 照上面修改后的是19200

访问:https://00.00.00.00:19200,注意:一定是https,http访问不到

原因:是因为ES8默认开启了 SSL 认证。
解决方式:
a. 使用https访问
b. 重新打开elasticsearch.yml
位置:相对位置/elasticsearch-8.7.1/config/elasticsearch.yml

可以看到这两行

xpack.security.enabled: true
xpack.security.enrollment.enabled: true

xpack.security.enabled设置为 false

重新启动,如果访问成功,之后都可以在后台启动了,但是第一次一定要在前台启动
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yizhi-w

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值