在Ubuntu 20.04 LTS(Focal Fossa)上安装Elasticsearch 7 OSS Only 版

简洁概述

    • Elastic 公式が用意している Elasticsearch 7 OSS Only 版の Debian パッケージを Ubuntu 20.04 LTS (Focal Fossa) にインストールする

 

    • 基本的には公式ドキュメント Install Elasticsearch with Debian Package | Elasticsearch Reference [7.9] | Elastic に従ってインストール作業を進める

 

    今回の環境: Ubuntu 20.04 LTS (Focal Fossa) + Elasticsearch 7.9.0

APT仓库的设置

为了确保apt使用的仓库是可信的,需导入Elasticsearch的PGP认证密钥去进行设置。

$ wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
OK

添加 Elasticsearch 7 OSS Only 版本的 APT 仓库。

$ echo "deb https://artifacts.elastic.co/packages/oss-7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list
deb https://artifacts.elastic.co/packages/oss-7.x/apt stable main

安装elasticsearch-oss包。

$ sudo apt update && sudo apt install elasticsearch-oss
(中略)
以下のパッケージが新たにインストールされます:
  elasticsearch-oss
アップグレード: 0 個、新規インストール: 1 個、削除: 0 個、保留: 0 個。
232 MB のアーカイブを取得する必要があります。
この操作後に追加で 419 MB のディスク容量が消費されます。
取得:1 https://artifacts.elastic.co/packages/oss-7.x/apt stable/main amd64 elasticsearch-oss amd64 7.9.0 [232 MB]
232 MB を 21秒 で取得しました (11.1 MB/s)                                                          

使用systemd进行启动管理

为了使设置内容生效,重新加载systemd的设置。

$ sudo systemctl daemon-reload

用 `systemctl enable` 命令来启用 Elasticsearch 服务。

$ sudo systemctl enable elasticsearch
Synchronizing state of elasticsearch.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable elasticsearch
Created symlink /etc/systemd/system/multi-user.target.wants/elasticsearch.service → /lib/systemd/system/elasticsearch.service.

启动Elasticsearch

使用systemctl start命令启动Elasticsearch服务。

$ sudo systemctl start elasticsearch

使用systemctl status命令可以检查服务的状态。

$ sudo systemctl status elasticsearch
● elasticsearch.service - Elasticsearch
     Loaded: loaded (/lib/systemd/system/elasticsearch.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2020-08-30 14:12:00 JST; 11s ago
       Docs: https://www.elastic.co
   Main PID: 38446 (java)
      Tasks: 52 (limit: 2318)
     Memory: 330.7M
     CGroup: /system.slice/elasticsearch.service
             └─38446 /usr/share/elasticsearch/jdk/bin/java -Xshare:auto -Des.networkaddress.cache.t>

 8月 30 14:11:45 foo-bar-aaaaa systemd[1]: Starting Elasticsearch...
 8月 30 14:12:00 foo-bar-aaaaa systemd[1]: Started Elasticsearch.

确认Elasticsearch是否启动

使用curl访问以确认Elasticsearch已经启动。

$ curl http://localhost:9200/
{
  "name" : "foo-bar-aaaaa",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "XXXXXXXXXXXXXXXXXXXXXX",
  "version" : {
    "number" : "7.9.0",
    "build_flavor" : "oss",
    "build_type" : "deb",
    "build_hash" : "a479a2a7fce0389512d6a9361301708b92dff667",
    "build_date" : "2020-08-11T21:36:48.204330Z",
    "build_snapshot" : false,
    "lucene_version" : "8.6.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

确认基本操作

创建索引。

$ curl --include -XPUT "http://localhost:9200/foo_index?pretty"
HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-length: 85

{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "foo_index"
}

向索引中添加文档。

$ curl --include -XPOST "http://localhost:9200/foo_index/_doc?pretty" \
> -H 'Content-Type: application/json' \
> -d '{
>   "foo_user": "Alice",
>   "foo_message": "The night was young, and so was he. But the night was sweet, and he was sour."
> }'
HTTP/1.1 201 Created
Location: /foo_index/_doc/unbQPXQBOy7T_EM8fvEu
content-type: application/json; charset=UTF-8
content-length: 242

{
  "_index" : "foo_index",
  "_type" : "_doc",
  "_id" : "unbQPXQBOy7T_EM8fvEu",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}

搜索文件。

$ curl --include -XGET "http://localhost:9200/foo_index/_search?pretty" \
> -H 'Content-Type: application/json' \
> -d '
> {
>   "query": {
>     "match": {
>       "foo_message": "night was sweet"
>     }
>   }
> }'
HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-length: 586

{
  "took" : 177,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.1700915,
    "hits" : [
      {
        "_index" : "foo_index",
        "_type" : "_doc",
        "_id" : "unbQPXQBOy7T_EM8fvEu",
        "_score" : 1.1700915,
        "_source" : {
          "foo_user" : "Alice",
          "foo_message" : "The night was young, and so was he. But the night was sweet, and he was sour."
        }
      }
    ]
  }
}

主要配置文件所在位置

/etc/default/elasticsearch → Elasticsearch 的默认配置文件

/etc/elasticsearch/.elasticsearch.keystore.initial_md5sum → Elasticsearch 的密钥文件初始 MD5 校验和

/etc/elasticsearch/elasticsearch.keystore → Elasticsearch 的密钥文件

/etc/elasticsearch/elasticsearch.yml → Elasticsearch 的配置文件

/etc/elasticsearch/jvm.options → Elasticsearch 的 JVM 配置文件

/etc/elasticsearch/log4j2.properties → Elasticsearch 的日志配置文件

/lib/systemd/system/elasticsearch.service → Elasticsearch 的 systemd 服务文件

请查阅相关资料

    • Install Elasticsearch with Debian Package | Elasticsearch Reference [7.9] | Elastic

 

    Download Elasticsearch Free • Get Started Now | Elastic
广告
将在 10 秒后关闭
bannerAds