You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu服务器Magento 2.4.6中如何安全降级Elasticsearch至7.9.3?

可以安全执行卸载重装操作,以下是零失误的分步操作指南

一、提前备份核心数据(必做)

  • 备份Elasticsearch索引:
    # 创建备份仓库
    curl -X PUT "localhost:9200/_snapshot/my_backup" -H 'Content-Type: application/json' -d'
    {
      "type": "fs",
      "settings": {
        "location": "/var/backups/elasticsearch",
        "compress": true
      }
    }'
    # 执行索引备份
    curl -X POST "localhost:9200/_snapshot/my_backup/snapshot_1?wait_for_completion=true"
    
  • 备份Magento配置与数据库:
    # 导出Elasticsearch相关配置到本地文件
    bin/magento config:show catalog/search > magento_es_config.txt
    # 备份Magento数据库
    mysqldump -u [你的数据库用户名] -p [Magento数据库名] > magento_db_backup.sql
    
  • 停止当前Elasticsearch服务:
    sudo systemctl stop elasticsearch
    

二、彻底卸载Elasticsearch 8.11.4

  • 卸载软件包并清除配置:
    sudo apt-get remove --purge elasticsearch -y
    
  • 删除残留文件与目录:
    sudo rm -rf /var/lib/elasticsearch
    sudo rm -rf /etc/elasticsearch
    sudo rm -rf /usr/share/elasticsearch
    
  • 移除8.x版本的APT源:
    sudo rm /etc/apt/sources.list.d/elastic.list
    
  • 更新APT缓存:
    sudo apt-get update
    

三、安装Elasticsearch 7.9.3

  • 添加7.x版本的APT源:
    wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
    echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list
    
  • 更新缓存并安装指定版本:
    sudo apt-get update
    sudo apt-get install elasticsearch=7.9.3 -y
    
  • 配置Elasticsearch(适配Magento):
    编辑/etc/elasticsearch/elasticsearch.yml,确保以下配置项正确:
    cluster.name: magento
    node.name: node-1
    network.host: localhost
    http.port: 9200
    discovery.seed_hosts: ["127.0.0.1"]
    cluster.initial_master_nodes: ["node-1"]
    
  • 启动并设置开机自启:
    sudo systemctl start elasticsearch
    sudo systemctl enable elasticsearch
    
  • 验证安装成功:
    curl http://localhost:9200
    
    输出内容中应显示"number": "7.9.3"

四、重新配置Magento并同步索引

  • 调整Magento的Elasticsearch配置:
    bin/magento config:set catalog/search/engine elasticsearch7
    bin/magento config:set catalog/search/elasticsearch7_server_hostname localhost
    bin/magento config:set catalog/search/elasticsearch7_server_port 9200
    
  • 重建搜索索引:
    bin/magento indexer:reindex catalogsearch_fulltext
    
  • 清理缓存:
    bin/magento cache:clean && bin/magento cache:flush
    
  • 验证连接:
    bin/magento catalog:search:test
    
    输出显示Success! Elasticsearch is reachable即为配置完成

内容的提问来源于stack exchange,提问作者Alexglvr

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 19:52:13