やさぐれSEの技術メモ

皆が辛い思いをしないようにハマったポイントなどを書きます

Elasticsearch6.3のインストールと考察

Elasticsearch6.3がリリースされましたので、インストールと検証を行いました。

インストールの流れ

検証した結果、下記の流れが良いと思います。
6.3からX-Packも含まれていますので、そのインストールが減ります。
基本的には6.2と変わらないです。

今回は(1)~(8)について書きます

==== ここから ====
(1)Elasticsearch:インストール及び最低限の設定
(2)Elasticsearch:日本語パッケージのインストール
(3)Elasticsearch:運用支援ツール(Curator)のインストール
(4)Kibana:インストール及び最低限の設定
(5)Kibana:ライセンスの変更(BASIC→Trial or GOLD等)
(6)Elasticsearch:TLS設定
(7)Elasticsearch:Config(yml)の修正及びElasticsearchの起動
(8)Elasticsearch:ビルトインアカウントのパスワード変更
==== ここまで====

(9)Elasticsearch:起動コマンドの整備
(10)Elasticsearch:スナップショットの取得
(11)Elasticsearch:SSL設定(任意)

インストール

(1)Elasticsearch:インストール及び最低限の設定

公式HPに従って簡単にインストールができます。
6.2とほとんど変わりませんので、手順は割愛させていただきます。

www.elastic.co

Configについては最低限の定義で良いです。
下記のようにバインドするIPアドレスの定義のみでOKです。

network.host: 各インスタンスのIPアドレス(19.168.0.1~5)

(2)Elasticsearch:日本語パッケージのインストール

大きく変わらないので割愛します。

(3)Elasticsearch:運用支援ツール(Curator)のインストール

大きく変わらないので割愛します。

(4)Kibana:インストール及び最低限の設定

Elasticsearchをインストールすると同時にX-Packもインストールされるわけですが、その際に「BASIC」ライセンスも適用されます。(6.2では「Trial」)

この状態ですと、ビルトインアカウントのパスワード変更や、セキュリティ設定の有効化が出来ません(厳密には有効になるがパスワード有りでも無しでも動作する)。

ライセンスの変更は以前と同様にCurlで出来るのですが、「Trial」ライセンスへの変更はKibanaから実施しますので、ここでKibanaを設定します。

インストール方法は大きく変わらないので割愛します。

www.elastic.co

Configは管理コンソールとElasticsearchに接続可能な最低限の定義で良いです。

server.host: "192.168.0.0"
elasticsearch.url: "http://192.168.0.3:9200"

(5)Kibana:ライセンスの変更(BASIC→Trial or GOLD等)

Kibanaにアクセスします f:id:gitya107:20180623164946p:plain

[Management]→[License Management]と選択します。 f:id:gitya107:20180623165050p:plain

今回は評価版で実施するので「Start Trial」を選択します。 f:id:gitya107:20180623165142p:plain

「Start my trial」を選択します。 f:id:gitya107:20180623165239p:plain

これで評価版ライセンスになります。評価版は全ての機能が利用できます。 f:id:gitya107:20180623165527p:plain

一応Elasticsearch側からも確認します。

# curl -XGET -u 'http://192.168.0.3:9200/_xpack/license'
{
  "license" : {
    "status" : "active",
    "uid" : "cb332d0c-7475-48a4-89fa-f129ed3a5ac5",
    "type" : "trial",
    "issue_date" : "2018-06-18T05:14:26.334Z",
    "issue_date_in_millis" : 1529298866334,
    "expiry_date" : "2018-07-18T05:14:26.334Z",
    "expiry_date_in_millis" : 1531890866334,
    "max_nodes" : 1000,
    "issued_to" : "elasticsearch",
    "issuer" : "elasticsearch",
    "start_date_in_millis" : -1
  }
}

(6)Elasticsearch:TLS設定

一応公式のセキュリティ設定部分を頑張って読みました。
結果として6.2と変わらないのかなと思います。
公式サイトのドキュメントがより一層解りにくくなりました。

www.elastic.co

使っていたコマンドが地味に変更となります。
6.2(certutil)→6.3(elasticsearch-certutil)

認証局の構築及びCA証明書・プライベートキーの作成

# /usr/share/elasticsearch/bin/elasticsearch-certutil ca
This tool assists you in the generation of X.509 certificates and certificate
signing requests for use with SSL/TLS in the Elastic stack.

The 'ca' mode generates a new 'certificate authority'
This will create a new X.509 certificate and private key that can be used
to sign certificate when running in 'cert' mode.

Use the 'ca-dn' option if you wish to configure the 'distinguished name'
of the certificate authority

By default the 'ca' mode produces a single PKCS#12 output file which holds:
    * The CA certificate
    * The CA's private key

If you elect to generate PEM format certificates (the -pem option), then the output will
be a zip file containing individual files for the CA certificate and private key

Please enter the desired output file [elastic-stack-ca.p12]:Enter
Enter password for elastic-stack-ca.p12 :パスワードを入力

インスタンス向け証明書及びプライベートキーの作成

# /usr/share/elasticsearch/bin/elasticsearch-certutil cert elastic-stack-ca.p12
This tool assists you in the generation of X.509 certificates and certificate
signing requests for use with SSL/TLS in the Elastic stack.

The 'cert' mode generates X.509 certificate and private keys.
    * By default, this generates a single certificate and key for use
       on a single instance.
    * The '-multiple' option will prompt you to enter details for multiple
       instances and will generate a certificate and key for each one
    * The '-in' option allows for the certificate generation to be automated by describing
       the details of each instance in a YAML file

    * An instance is any piece of the Elastic Stack that requires a SSL certificate.
      Depending on your configuration, Elasticsearch, Logstash, Kibana, and Beats
      may all require a certificate and private key.
    * The minimum required value for each instance is a name. This can simply be the
      hostname, which will be used as the Common Name of the certificate. A full
      distinguished name may also be used.
    * A filename value may be required for each instance. This is necessary when the
      name would result in an invalid file or directory name. The name provided here
      is used as the directory name (within the zip) and the prefix for the key and
      certificate files. The filename is required if you are prompted and the name
      is not displayed in the prompt.
    * IP addresses and DNS names are optional. Multiple values can be specified as a
      comma separated string. If no IP addresses or DNS names are provided, you may
      disable hostname verification in your SSL configuration.

    * All certificates generated by this tool will be signed by a certificate authority (CA).
    * The tool can automatically generate a new CA for you, or you can provide your own with the
         -ca or -ca-cert command line options.

By default the 'cert' mode produces a single PKCS#12 output file which holds:
    * The instance certificate
    * The private key for the instance certificate
    * The CA certificate

If you specify any of the following options:
    * -pem (PEM formatted output)
    * -keep-ca-key (retain generated CA key)
    * -multiple (generate multiple certificates)
    * -in (generate certificates from an input file)
then the output will be be a zip file containing individual certificate/key files

Please enter the desired output file [elastic-certificates.p12]:Enter
Enter password for elastic-certificates.p12 :パスワードを入力

Certificates written to /root/elastic-certificates.p12

This file should be properly secured as it contains the private key for
your instance.

This file is a self contained file and can be copied and used 'as is'
For each Elastic product that you wish to configure, you should copy
this '.p12' file to the relevant configuration directory
and then follow the SSL configuration instructions in the product guide.

・証明書を配置するディレクトリの作成
# mkdir /etc/elasticsearch/certificate

ディレクトリの権限等を修正します。

# chgrp elasticsearch /etc/elasticsearch/certificate
# chmod o-rx /etc/elasticsearch/certificate

・SCP等で全インスタンスに証明書及びプライベートキー(elastic-stack-ca.p12 , elastic-certificates.p12 )を配布します。
 また、作成したディレクトリにファイルを移動します。

・ファイル権限等を修正します。

chgrp elasticsearch /etc/elasticsearch/elastic-stack-ca.p12 /etc/elasticsearch/elastic-certificates.p12
chmod 640 /etc/elasticsearch/elastic-stack-ca.p12 /etc/elasticsearch/elastic-certificates.p12

・キーストアの設定を実施します。
[CA]

# /usr/share/elasticsearch/bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password
Enter value for xpack.security.transport.ssl.keystore.secure_password:   elastic-stack-ca.p12作成時のパスワード

[インスタンス ]

# /usr/share/elasticsearch/bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password
Enter value for xpack.security.transport.ssl.truststore.secure_password:  elastic-certificates.p12 作成時のパスワード

(7)Elasticsearch:Config(yml)の修正及びElasticsearchの起動

6.2のコンフィグを参考に設定をしてください。
X-Packの部分だけ下記に記述します。

xpack.security.enabled: true

# 6.3 から入れておいたほうが良いなと思う定義
# トークンを使わないので要らないような・・・・
xpack.security.authc.token.enabled: false

xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: /etc/elasticsearch/certificates/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: /etc/elasticsearch/certificates/elastic-certificates.p12

6.2と同様に起動します。

(8)Elasticsearch:ビルトインアカウントのパスワード変更

6.2と手順は変わりません。
6.2ではデフォルトパスワードが設定されなかったのに、6.3では「changeme」が設定されているようです。(5.x系に回帰???)

# /usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive
Initiating the setup of passwords for reserved users elastic,kibana,logstash_system,beats_system.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y


Enter password for [elastic]:パスワードを入力
Reenter password for [elastic]:パスワードを入力
Enter password for [kibana]:パスワードを入力
Reenter password for [kibana]:パスワードを入力
Enter password for [logstash_system]:パスワードを入力
Reenter password for [logstash_system]:パスワードを入力
Enter password for [beats_system]:パスワードを入力
Reenter password for [beats_system]:パスワードを入力
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [elastic]

さいごに

残りの手順は6.2と変わりません。 過去の記事を参考に実施していただければと思います。