Elasticsearch安装和数据迁移

Elasticsearch安装和数据迁移

Elasticsearch安装
  1. 下载并解压Elasticsearch
    首先下载Elasticsearch的tar.gz文件,并将其解压:
bash 复制代码
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.8.2-linux-x86_64.tar.gz
tar -xzf elasticsearch-8.8.2-linux-x86_64.tar.gz
cd elasticsearch-8.8.2
  1. 创建新用户(推荐)
    由于Elasticsearch不推荐以root用户运行,建议创建一个普通用户来运行它:
bash 复制代码
sudo adduser elastic
sudo passwd elastic
设置密码:自己创建一个能记住的密码
  1. 修改目录权限
    将Elasticsearch安装目录的所有权更改为新用户:
bash 复制代码
sudo chown -R elastic:elastic /home/elasticsearch-8.8.2
sudo chown -R 777 elasticsearch-8.8.2

配置 elasticsearch.yml

如果需要绑定特定网络接口或修改端口,可以编辑 elasticsearch.yml 配置文件:

bash 复制代码
sudo nano /home/elasticsearch-8.8.2/config/elasticsearch.yml

修改以下配置项:

bash 复制代码
  yaml
	network.host: 0.0.0.0
	http.port: 9200
   【重要】然后data logs文件夹的位置 和/home统一
  1. 修改系统JVM
bash 复制代码
vim /etc/security/limits.conf  
追加
elastic hard nofile 65536
elastic soft nofile 65536
vim /etc/sysctl.conf
vm.max_map_count=655360
sysctl -p
ulimit -HSn 65535

新用户添加至 sudoerslist,也可以不添加

bash 复制代码
sudo cd elasticsearch-8.8.2
 visudo
 添加 elastic ALL=(ALL) ALL
  1. 以新用户身份运行Elasticsearch
    切换到新用户,并运行Elasticsearch:
bash 复制代码
bash
su - elastic
cd /home/elasticsearch-8.8.2
./bin/elasticsearch -d -p 19999
  1. 检查Elasticsearch是否启动
    打开浏览器,访问 http://localhost:9200,您应该看到一个JSON响应,表明Elasticsearch正在运行。
    使用 curl 命令验证
    使用 curl 命令从命令行验证 Elasticsearch 是否正常运行:
bash 复制代码
curl -X GET "localhost:9200"
  1. 节点配置成systemd服务
bash 复制代码
su root 
 cd /lib/systemd/system/      ###配置服务的目录
 vim /lib/systemd/system/elasticsearch.service     ###写入如下内容
xml 复制代码
[Unit]
 Description=elasticsearch
 After=network.target
 
 [Service]
 Type=simple
 User=elastic
 # elasticsearch安装目录
 ExecStart=/home/elasticsearch-8.8.2/bin/elasticsearch
 PrivateTmp=true
 # 指定此进程可以打开的最大文件数
 LimitNOFILE=65535
 # 指定此进程可以打开的最大进程数
 LimitNPROC=65535
 # 最大虚拟内存
 LimitAS=infinity
 # 最大文件大小
 LimitFSIZE=infinity
 Restart=on-failure
 
 [Install]
 WantedBy=multi-user.target
  • 更新systemd配置文件
    systemctl daemon-reload
  • 使服务生效
    systemctl enable elasticsearch
  • 启动服务
    systemctl start elasticsearch
  • 查看服务状态
    systemctl status elasticsearch
    常见问题处理
    1. fatal exception while booting Elasticsearchjava.lang.IllegalArgumentException: node settings must not contain any index level settings
    删掉

2. 如果服务连接不上ElsticSearch,则检查下安全连接机制,都要关闭

Elasticsearch数据迁移
物理迁移方式
  1. 将源数据elasticsearch-8.8.2 下
    data目录 所有数据打包 成data.tar
  2. 文件传输
bash 复制代码
scp -P 22 -r  data.tar root@ip:/home/

输入密码

  1. 处理数据

新的elasticsearch-8.8.2中

bash 复制代码
tar -zvf tar.data
bash 复制代码
cd  elasticsearch-8.8.2

将原来的备份成 data_bak

bash 复制代码
mv  data data_bak

将源数据的data 移到新的elasticsearch-8.8.2下

bash 复制代码
mv data   elasticsearch-8.8.2/
  1. 给予新的权限(不给予权限的话,启动将会报错)
    maybe these locations are not writable or multiple nodes were started on the same data path?
    解决权限问题:
bash 复制代码
  chown -R 1000:1000 data
  chmod -R 777 data
如果新的Elasticsearch中已有数据,防止物理迁移造成新的Elasticsearch数据丢失,可用官方提供的logstash,进行数据迁移
相关推荐
zzb15801 小时前
RAG from Scratch-优化-query
java·数据库·人工智能·后端·spring·mybatis
V搜xhliang02462 小时前
机器人建模(URDF)与仿真配置
大数据·人工智能·深度学习·机器学习·自然语言处理·机器人
一只鹿鹿鹿2 小时前
信息安全等级保护安全建设防护解决方案(总体资料)
运维·开发语言·数据库·面试·职场和发展
房产中介行业研习社2 小时前
2026年3月哪些房源管理系统功能全
大数据·运维·人工智能
堕2742 小时前
MySQL数据库《基础篇--数据库索引(2)》
数据库·mysql
wei_shuo2 小时前
数据库优化器进化论:金仓如何用智能下推把查询时间从秒级打到毫秒级
数据库·kingbase·金仓
雷工笔记2 小时前
Navicat Premium 17 软件安装记录
数据库
wenlonglanying3 小时前
Ubuntu 系统下安装 Nginx
数据库·nginx·ubuntu
数据库小组3 小时前
10 分钟搞定!Docker 一键部署 NineData 社区版
数据库·docker·容器·database·数据库管理工具·ninedata·迁移工具
爬山算法3 小时前
MongoDB(38)如何使用聚合进行投影?
数据库·mongodb