Kashibuchi’s blog

勉強のこと、日々のこと

Vagrantで作成した環境 + Elasticsearch + Kibanaのインストールと実行

作業環境について

インストール済のbox

>vagrant box list
bento/centos-7.2 (virtualbox, 2.3.1)
bento/centos-7.8 (virtualbox, 202010.22.0)
centos/7         (virtualbox, 2004.01)

プラグインのリスト

>vagrant plugin list
vagrant-hostmanager (1.8.9, global)
  - Version Constraint: > 0
vagrant-omnibus (1.5.0, global)
  - Version Constraint: > 0
vagrant-vbguest (0.30.0, global)
  - Version Constraint: > 0

Vagrantfileの作成

>vagrant init centos/7
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
  
  
>fc /n Vagrantfile_org Vagrantfile
ファイル Vagrantfile_org と VAGRANTFILE を比較しています
***** Vagrantfile_org
    8:  Vagrant.configure("2") do |config|
    9:    # The most common configuration options are documented and commented below.
***** VAGRANTFILE
    8:  Vagrant.configure("2") do |config|
    9:    if Vagrant.has_plugin?("vagrant-vbguest")
   10:      config.vbguest.auto_update = false
   11:    end
   12:    # The most common configuration options are documented and commented below.
*****

***** Vagrantfile_org
   26:    # config.vm.network "forwarded_port", guest: 80, host: 8080
   27:
***** VAGRANTFILE
   29:    # config.vm.network "forwarded_port", guest: 80, host: 8080
   30:    config.vm.network "forwarded_port", guest: 22, host: 2222, id: "ssh"
   31:
*****

***** Vagrantfile_org
   31:    # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
   32:
***** VAGRANTFILE
   35:    # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
   36:    config.vm.network "forwarded_port", guest: 9200, host: 19200, host_ip: "127.0.0.1"
   37:    config.vm.network "forwarded_port", guest: 5601, host: 15601, host_ip: "127.0.0.1"
   38:
*****

vagrant upの実行

>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos/7'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'centos/7' version '2004.01' is up to date...
==> default: Setting the name of the VM: elasticsearch_default_1634821269779_88784
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
    default: 9200 (guest) => 19200 (host) (adapter 1)
    default: 5601 (guest) => 15601 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: No guest additions were detected on the base box for this VM! Guest
    default: additions are required for forwarded ports, shared folders, host only
    default: networking, and more. If SSH fails on this machine, please install
    default: the guest additions and repackage the box to continue.
    default:
    default: This is not an error message; everything may continue to work properly,
    default: in which case you may ignore this message.
==> default: Rsyncing folder: /cygdrive/c/Users/kamin/work/VagrantBase/elasticsearch/ => /vagrant

Tera Termマクロ

; Vagrant macro
; 「vagrant ssh-config」で確認

; this file path
getdir dir

; port
port=2222

; private keyを指定します。上で取得したIdentityFileの値に書き換えます。
keyfile='C:/Users/kashibuchi/work/VagrantBase/elasticsearch/.vagrant/machines/default/virtualbox/private_key'

sprintf2 constr 'localhost:%d /ssh /2 /auth=publickey /user=vagrant /keyfile=%s' port keyfile

connect constr

vagrantユーザでログイン後、諸々のインストール

参考

Elasticsearch + Kibana + LogstashをCentOS7にインストールしてみた - Qiita

コマンド

[vagrant@localhost ~]$ sudo yum install -y https://corretto.aws/downloads/latest/amazon-corretto-11-x64-linux-jdk.rpm
・・・略・・・
Complete!
[vagrant@localhost ~]$ 
[vagrant@localhost ~]$ 
[vagrant@localhost ~]$ sudo yum install -y vim
Loaded plugins: fastestmirror
Determining fastest mirrors
・・・略・・・
Complete!
[vagrant@localhost ~]$ 
[vagrant@localhost ~]$ sudo yum install -y curl 
Loaded plugins: fastestmirror
・・・略・・・
Complete!
[vagrant@localhost ~]$ 
[vagrant@localhost ~]$ 
[vagrant@localhost ~]$ sudo vim /etc/yum.repos.d/elasticsearch.repo
[vagrant@localhost ~]$ cat /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-6.x]
name=Elasticsearch repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

[vagrant@localhost ~]$ sudo yum install -y elasticsearch-6.8.3
Loaded plugins: fastestmirror
・・・略・・・
Complete!
[vagrant@localhost ~]$ 
[vagrant@localhost ~]$ 
[vagrant@localhost ~]$ sudo yum install -y kibana
Loaded plugins: fastestmirror
・・・略・・・
Complete!
[vagrant@localhost ~]$ 
[vagrant@localhost ~]$ sudo vi /etc/elasticsearch/elasticsearch.yml # network.host: 0.0.0.0 ← 追加
[vagrant@localhost ~]$ sudo vi /etc/kibana/kibana.yml # server.host: "0.0.0.0" ← 追加
[vagrant@localhost ~]$ sudo systemctl start firewalld
[vagrant@localhost ~]$ sudo firewall-cmd --add-port=5601/tcp --zone=public --permanent
success
[vagrant@localhost ~]$ sudo firewall-cmd --add-port=9200/tcp --zone=public --permanent
success
[vagrant@localhost ~]$ sudo firewall-cmd --add-service=ssh --zone=public --permanent
Warning: ALREADY_ENABLED: ssh
success
[vagrant@localhost ~]$ sudo firewall-cmd --reload
success
[vagrant@localhost ~]$ 
[vagrant@localhost ~]$ systemctl daemon-reload # 正直うっかりsudoでやらなかった
==== AUTHENTICATING FOR org.freedesktop.systemd1.reload-daemon ===
Authentication is required to reload the systemd state.
Authenticating as: root
Password: 
==== AUTHENTICATION COMPLETE ===
[vagrant@localhost ~]$ 
[vagrant@localhost ~]$ sudo systemctl restart elasticsearch kibana 
[vagrant@localhost ~]$ 
[vagrant@localhost ~]$ sudo systemctl enable elasticsearch kibana
Created symlink from /etc/systemd/system/multi-user.target.wants/elasticsearch.service to /usr/lib/systemd/system/elasticsearch.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/kibana.service to /etc/systemd/system/kibana.service.
[vagrant@localhost ~]$ 
[vagrant@localhost ~]$ curl http://localhost:9200
{
  "name" : "iNfHYdH",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "vuyKU4CfQgOZoIFPgbexCA",
  "version" : {
    "number" : "6.8.3",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "0c48c0e",
    "build_date" : "2019-08-29T19:05:24.312154Z",
    "build_snapshot" : false,
    "lucene_version" : "7.7.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}
[vagrant@localhost ~]$ curl http://localhost:5601 # ブラウザからリダイレクト?されてちゃんとしたページが参照できる\(なお、日本語化は7.0以降の為、できなかった\)
[vagrant@localhost ~]$ 

ブラウザでの確認

f:id:KashibuchiKyamin:20211021232210p:plainf:id:KashibuchiKyamin:20211021232335p:plain

まとめ

とりあえずできた。 Firewalldを設定しないと接続できないのはちょっと辛いなと。 過去にそこそこがっつり調べたんだけどなー。覚えていないなFirewalldは。

業務で作業するならたぶんプロキシ環境なので、 - Vagrantのplugin - Vagrantfile - yumの設定ファイル ↑この辺のプロキシ設定をすればいいのかな。