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,进行数据迁移
相关推荐
程序员Android1 分钟前
MTK多帧拍照流程分析
数据库
不剪发的Tony老师3 分钟前
Apache Doris:一款高性能的实时数据仓库
数据库·数据仓库
甜可儿14 分钟前
redis序列化设置
数据库·redis
GGBondlctrl19 分钟前
【SpringBoot】论坛项目中如何进行实现发布文章,以及更新对应数据库的数据更新
数据库·springboot项目·三层设计思想·文章发布项目
jonyleek31 分钟前
「JVS更新日志」低代码、企业会议、智能BI、智能排产2.26更新说明
java·大数据·低代码·数据分析·软件需求
若云止水33 分钟前
Ubuntu 下 nginx-1.24.0 源码分析 - ngx_init_cycle 函数 - 详解(4)
数据库·nginx·ubuntu
jay丿1 小时前
Django模板系统深入
数据库·django·sqlite
kngines1 小时前
【实战 ES】实战 Elasticsearch:快速上手与深度实践-1.3.1单节点安装(Docker与手动部署)
大数据·elasticsearch·docker
小稻草打打打1 小时前
金融项目管理:合规性与风险管理的实战指南
大数据·金融
千层冷面1 小时前
Redis除了做缓存还能做什么?
数据库·redis·缓存