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,进行数据迁移
相关推荐
大熊猫今天吃什么5 分钟前
【一天一坑】空数组,使用 allMatch 默认返回true
前端·数据库
chat2tomorrow15 分钟前
数据仓库 vs 数据湖:架构、应用场景与技术差异全解析
大数据·数据仓库·低代码·架构·数据湖·sql2api
双叶83618 分钟前
(51单片机)LCD显示数据存储(DS1302时钟模块教学)(LCD1602教程)(独立按键教程)(延时函数教程)(I2C总线认识)(AT24C02认识)
c语言·数据库·单片机·嵌入式硬件·mongodb·51单片机·nosql
XY.散人23 分钟前
初识Redis · C++客户端list和hash
数据库·redis·缓存
塔能物联运维25 分钟前
双轮驱动能源革命:能源互联网与分布式能源赋能工厂能效跃迁
大数据·运维
码上飞扬1 小时前
深入 MySQL 高级查询:JOIN、子查询与窗口函数的实用指南
数据库·mysql
-曾牛1 小时前
Git Flow
大数据·git·学习·elasticsearch·个人开发
海洋与大气科学2 小时前
【matlab】地图上的小图
开发语言·数据库·matlab
461K.2 小时前
spark与hadoop的区别
大数据·运维·hadoop·分布式·spark·intellij-idea
Zfox_2 小时前
Git 进阶之路:高效协作之分支管理
大数据·linux·运维·c++·git·elasticsearch