Ubuntu 23.04 安装es

在Ubuntu 23.04上安装Elasticsearch的过程可能与之前版本类似,以下是基于最新稳定版Elasticsearch的一般安装步骤:

  1. 准备工作:

    • 确保系统已更新至最新版本:

      bash 复制代码
      sudo apt update && sudo apt upgrade
    • 安装Java Development Kit (JDK)。Elasticsearch至少需要Java 11。可以通过官方apt仓库安装Adoptium OpenJDK(或者其他你喜欢的Java版本):

      bash 复制代码
      sudo apt install openjdk-11-jdk-headless
  2. 下载并解压Elasticsearch:

    访问Elasticsearch官方网站(https://www.elastic.co/cn/downloads/past-releases#elasticsearch)下载适合Ubuntu的tar.gz包。假设你下载了名为`elasticsearch-8.12.0.tar.gz`的压缩包,将其解压到适当的目录,例如 /usr/local

    bash 复制代码
    wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.12.0-linux-x86_64.tar.gz
    sudo mkdir -p /usr/local/elasticsearch
    sudo tar -xzvf elasticsearch-8.12.0-linux-x86_64.tar.gz -C /usr/local/elasticsearch --strip-components=1
  3. 创建Elasticsearch系统用户和组:

    bash 复制代码
    sudo groupadd elastic
    sudo useradd -r -g elastic -s /bin/bash elastic
    sudo chown -R elastic:elastic /usr/local/elasticsearch
  4. 配置Elasticsearch:

    • 编辑 /usr/local/elasticsearch/config/elasticsearch.yml 文件,根据您的环境调整配置。关键配置可能包括:
bash 复制代码
cluster.name: my-application
node.name: node-1
network.host: 0.0.0.0
xpack.security.enabled: false
path.data: /usr/local/elasticsearch/data
path.logs: /usr/local/elasticsearch/logs

xpack.security.enrollment.enabled: false
xpack.security.http.ssl:
  enabled: false
  keystore.path: certs/http.p12
xpack.security.transport.ssl:
  enabled: false
  verification_mode: certificate
  keystore.path: certs/transport.p12
  truststore.path: certs/transport.p12
复制代码
 - `cluster.name`: 设置集群名称。
 - `node.name`: 设置节点名称。
 - `network.host`: 指定节点监听的主机地址(如 `localhost` 或特定IP)。
 - `path.data`: 数据存储路径。
 - `path.logs`: 日志文件存放路径。
 - 可能需要开启或配置安全功能(如X-Pack Security)。

编辑配置文件 /etc/security/limits.conf 或者在目录 /etc/security/limits.d/ 创建配置文件 (e.g., /etc/security/limits.d/elasticsearch.conf) 添加正面的内容

bash 复制代码
elasticsearch soft nofile 65536
elasticsearch hard nofile 65536

执行以下命令

bash 复制代码
sudo systemctl daemon-reload

在目录 /etc/sysctl.d/创建文件/etc/sysctl.d/elasticsearch.conf,添加以下内容:

bash 复制代码
vm.max_map_count=262144

执行以下命令

bash 复制代码
sudo sysctl --system
  1. 启动Elasticsearch:

    bash 复制代码
    sudo su elastic
    cd /usr/local/elasticsearch
    ./bin/elasticsearch

    如果你希望以守护进程方式运行Elasticsearch并设置为开机启动,你需要创建一个systemd服务单元文件,例如 /etc/systemd/system/elasticsearch.service,并定义正确的启动参数。

  2. 创建systemd服务(可选):

    创建一个elasticsearch.service文件,并添加相应的启动脚本。以下是一个基本示例:

    ini 复制代码
    [Unit]
    Description=Elasticsearch Service
    Wants=network-online.target
    After=network-online.target
    
    [Service]
    Type=notify
    User=elastic
    Group=elastic
    ExecStart=/usr/local/elasticsearch/bin/elasticsearch
    Restart=on-failure
    LimitMEMLOCK=infinity
    LimitNOFILE=65536
    
    [Install]
    WantedBy=multi-user.target

    然后启用并启动服务:

    bash 复制代码
    sudo systemctl daemon-reload
    sudo systemctl enable elasticsearch.service
    sudo systemctl start elasticsearch.service

在生产环境中,还应考虑对Elasticsearch进行安全配置,例如设置密码认证、禁用HTTP访问等。

相关推荐
IT菜鸟程6 小时前
Ubuntu 下 apt 版 Nginx 升级为源码编译版本完整操作指南(1.24.0 → 1.30.4 实战)
linux·nginx·ubuntu
Mr-Apple7 小时前
系统找不到指定的文件-CreateInstance/CreateVm/HCS/ERROR_FILE_NOT_FOUND
linux·windows·ubuntu·wsl
Elastic 中国社区官方博客7 小时前
Elasticsearch 向量数据库:几分钟内完成部署,以经济高效的方式扩展至数千亿规模
大数据·运维·数据库·elasticsearch·搜索引擎·ai·全文检索
自律最差的编程狗8 小时前
Ubuntu下Docker部署Ollama 轻量模型
linux·ubuntu·docker
Elasticsearch10 小时前
将 Vercel 数据导入 Elastic:无需安装任何东西的无服务器可观测性
elasticsearch
阿钱真强道11 小时前
04 嵌入式操作系统 | 常用命令Ⅱ:用户权限、进程与网络
linux·ubuntu·进程管理·用户权限·网络排查
阿钱真强道11 小时前
03 嵌入式操作系统 | 常用命令Ⅰ:文件、查找与压缩
linux·ubuntu·文件管理·命令行·压缩解压
Elastic 中国社区官方博客1 天前
Elasticsearch Python DSL 客户端开发
大数据·数据库·python·elasticsearch·搜索引擎·全文检索
飞翔的熊blabla1 天前
# Webpack 5 + Jenkins 持久化缓存实战:前端构建从 288 秒降到 30 秒>
前端·webpack·jenkins