CLOVER🍀

That was when it all began.

Apache 2.0 LicenseのElasticsearch、KibanaをUbuntu Linux 18.04 LTSにインストールする

これは、なにをしたくて書いたもの?

ElasticsearchやKibanaをインストールする際に、Elastic LicenseのものとApache 2 Licenseのものでインストール方法が異なることに
気づいていなかったので、メモとして。

よくよく見ると、ダウンロードページから異なるんですね。

Download Elasticsearch

Download Elasticsearch - OSS Only

Kibana、Logstash、Beatsも同様です。

6.3.0から、こういう形態になっているんでしょうかね?

f:id:Kazuhira:20191130011429p:plain

f:id:Kazuhira:20191130011452p:plain

今回、ElasticsearchとKibanaの2つをApache 2 Licenseのもので、かつaptでインストールしてみたいと思います。

環境

今回の環境は、こちらです。

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.3 LTS
Release:    18.04
Codename:   bionic


$ java --version
openjdk 11.0.4 2019-07-16
OpenJDK Runtime Environment (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3)
OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3, mixed mode, sharing)

ElasticsearchおよびKibanaは、7.4.2をインストールします。

ドキュメントは、以下を参照。

Install Elasticsearch with Debian Package | Elasticsearch Reference [7.4] | Elastic

Install Kibana with Debian Package | Kibana Guide [7.4] | Elastic

aptリポジトリの追加

まず、aptリポジトリを追加します。

$ wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
$ echo "deb https://artifacts.elastic.co/packages/oss-7.x/apt stable main" | sudo tee -a /etc/

これは、Elasticsearch、Kibanaで(BeatsやLogstashも)同じです。

ポイントは、追加するリポジトリ

https://artifacts.elastic.co/packages/oss-7.x/apt

となっていることで、Elastic Licenseの場合はこちらになります。

https://artifacts.elastic.co/packages/7.x/apt

そして、update。

sudo apt -y update

Elasticsearchのインストール

では、Elasticsearchをインストールします。

$ sudo apt -y install elasticsearch-oss

パッケージ名が、「elasticsearch-oss」と「-oss」が付くところがポイントです。

Elastic Licenseの場合は「elasticsearch」になります。

起動。

$ sudo systemctl daemon-reload
$ sudo systemctl enable elasticsearch
$ sudo systemctl start elasticsearch

停止はこちら。

$ sudo systemctl stop elasticsearch

設定は、こんな感じにしておきました。

$ sudo grep -v '^#' /etc/elasticsearch/elasticsearch.yml
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
network.host: 0.0.0.0
discovery.type: "single-node"

Kibanaのインストール

続いて、Kibanaをインストールします。

$ sudo apt -y install kibana-oss

こちらも、「kibana-oss」になります。

起動。

$ sudo systemctl daemon-reload
$ sudo systemctl enable kibana
$ sudo systemctl start kibana

停止はこちら。

$ sudo systemctl stop kibana

設定は、こんな感じに。

$ sudo grep -v '^#' /etc/kibana/kibana.yml 

server.host: "0.0.0.0"

起動した後のKibanaの画面も、一応貼っておきます。

f:id:Kazuhira:20191130002820p:plain

LogstashやBeatsのインストールパッケージは?

参考までに。

LogstashのApache 2 License版のインストールパッケージは、「logstash-oss」でした。

Beatsは、「-oss」prefixのものは見当たらず…?

$ sudo apt search filebeat
Sorting... Done
Full Text Search... Done
filebeat/stable 7.4.2 amd64
  Filebeat sends log files to Logstash or directly to Elasticsearch.

ドキュメントにはApache 2 License向けのリポジトリのことは書いてあったり

Repositories for APT and YUM | Filebeat Reference [7.4] | Elastic

バイナリのダウンロード先は別々だったりするんですけどね。

Download Filebeat

Download Filebeat - OSS Only

と思ってとりあえず「filebeat」でインストールしたら、Apache 2 Licenseのものが入ったようです。

$ grep Apache /usr/share/filebeat/LICENSE.txt 
                                 Apache License
   APPENDIX: How to apply the Apache License to your work.
      To apply the Apache License to your work, attach the following
   Licensed under the Apache License, Version 2.0 (the "License");

AnsibleをUbuntu Linux 18.04 LTSにインストールする

これは、なにをしたくて書いたもの?

ちょっとAnsibleを勉強しようかなと思いまして。

まずは、Ubuntu Linuxにインストールして簡単に確認してみようかな、と。

Ansible

サーバーに対して、ソフトウェアのインストールを自動化するためのツールです。

Ansible is Simple IT Automation

いわゆる、IaCの文脈で語られるツールの一種ですね。

  • 設定がYAMLファイル
  • エージェントレス

というところが特徴かと。

環境

今回の環境は、こちらです。

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.3 LTS
Release:    18.04
Codename:   bionic


$ python -V
Python 2.7.15+


$ python3 -V
Python 3.6.9

Pythonは2系と3系が入っています。インストール要件としては、Python 2.7またはPython 3.5以上なので、どちらでもOKです。

Control Node Requirements

ドキュメントに従うと、aptかpipでインストールするのが良さそうなので、この2つを試してみたいと思います。

Installing Ansible — Ansible Documentation

PPAからインストールする

まずは、PPAでインストールする方法から。

Latest Releases via Apt (Ubuntu)

ansible : Ansible, Inc.

インストール。

$ sudo apt-add-repository --yes --update ppa:ansible/ansible
$ sudo apt install ansible

バージョンを確認。

$ ansible --version
ansible 2.9.1
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'$HOME/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.15+ (default, Oct  7 2019, 17:39:04) [GCC 7.4.0]

Python 2系で動作するAnsibleがインストールされましたね。現時点でのバージョンは、2.9.1です。

pipでインストールする

続いて、pipでインストールしてみます。

Latest Releases via Pip

Python 3系のpipでインストール。

$ pip3 install --user ansible

確認。

$ ansible --version
ansible 2.9.1
  config file = None
  configured module search path = ['$HOME/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = $HOME/.local/lib/python3.6/site-packages/ansible
  executable location = $HOME/.local/bin/ansible
  python version = 3.6.9 (default, Nov  7 2019, 10:44:02) [GCC 8.3.0]

pip3でインストールしたので、Python 3系で動くAnsibleがインストールされました。

今回は、pip版で動かしてみようかなと思います。

ちょっと動かしてみる

それでは、インストールしたAnsibleを動かしてみましょう。

今回は、Vagrantで立ち上げたUbuntu Linux 18.04の仮想マシンに、Apacheをインストールしてみたいと思います。

$ vagrant init generic/ubuntu1804
$ vagrant up

SSHの接続情報を確認。

$ vagrant ssh-config
Host default
  HostName 192.168.121.114
  User vagrant
  Port 22
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /path/to/.vagrant/machines/default/libvirt/private_key
  IdentitiesOnly yes
  LogLevel FATAL

AnsibleのInventryファイルを用意。

How to build your inventory — Ansible Documentation

hosts

[vagrant]
192.168.121.114

簡単なPlaybookを用意。

Intro to Playbooks — Ansible Documentation

playbook.yml

---
- hosts: vagrant
  remote_user: vagrant
  tasks:
    - name: install apache2
      apt:
        name: apache2
      become: true
    - name: apache2 is running
      systemd:
        state: started
        name: apache2

作成したInventry、Playbookと、VagrantSSH Private Keyを指定して、ansible-playbookを実行。

$ ansible-playbook -i hosts playbook.yml --private-key /path/to/.vagrant/machines/default/libvirt/private_key

PLAY [vagrant] *****************************************************************************************************************************************************************************

TASK [Gathering Facts] *********************************************************************************************************************************************************************
The authenticity of host '192.168.121.114 (192.168.121.114)' can't be established.
ECDSA key fingerprint is SHA256:cjlFesPErwQsFNkaywCIl2Tk0AM9eDJzqRcKi0DZhAg.
Are you sure you want to continue connecting (yes/no)? yes
ok: [192.168.121.114]

TASK [install apache2] *********************************************************************************************************************************************************************
changed: [192.168.121.114]

TASK [apache2 is running] ******************************************************************************************************************************************************************
ok: [192.168.121.114]

PLAY RECAP *********************************************************************************************************************************************************************************
192.168.121.114            : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

完了。

Apacheの確認。

$ curl -s 192.168.121.114 | grep 'Apache2 Ubuntu'
    <title>Apache2 Ubuntu Default Page: It works</title>
          Apache2 Ubuntu Default Page

OKですね。

最初は、こんなところで。