Elasticsearch + Kibana 構築手順

# Elasticsearch 構築手順

```python:Elasticsearch構築


# JAVA環境を構築
apt-get install openjdk-8-jdk

# version確認 1.8_131 以上であること
java -version 

# elasticseach インストール
# オフィシャルを参照
# https://www.elastic.co/guide/en/elasticsearch/reference/current/deb.html

# ディレクトリ移動
$ cd /usr/src/

# 暗号化のKeyを取得
$ wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

# リポジトリ登録
$ echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a　/etc/apt/sources.list.d/elastic-7.x.list

# インストール
$ apt-get update && sudo apt-get install elasticsearch
$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.2.0-amd64.deb

# パッケージを展開
$ dpkg -i elasticsearch-7.2.0-amd64.deb
  
# 設定ファイルの変更
# 設定関係はここ参照
# https://wisdom-gate.jp/blog/2019/04/18/elastic-search-7-0-%E3%83%AA%E3%83%AA%E3%83%BC%E3%82%B9/

vi /etc/elasticseach/elasticseach.yml
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
network.host: 0.0.0.0
http.port: 9200
discovery.seed_hosts: ["192.168.112.141"]
cluster.initial_master_nodes: ["192.168.112.141"]


# 起動
systemctl start elasticsearch
systemctl enable elasticsearch
systemctl status elasticsearch



# ウェブアクセスにて以下が表示されること

http://192.168.112.141:9200/

{
  "name" : "fulentd",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "knd6kpYsR86vSHNZA33xTA",
  "version" : {
    "number" : "7.2.0",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "508c38a",
    "build_date" : "2019-06-20T15:54:18.811730Z",
    "build_snapshot" : false,
    "lucene_version" : "8.0.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}


# JVMの設定
# メモリリソースの設定
# https://www.karakaram.com/elasticsearch-memory-usage-reduce   
  
 root@fulentd:/bin# cat /etc/elasticsearch/jvm.options  | grep -v "#"

-Xms1g
-Xmx1g


-XX:+UseConcMarkSweepGC
-XX:CMSInitiatingOccupancyFraction=75
-XX:+UseCMSInitiatingOccupancyOnly


-Des.networkaddress.cache.ttl=60
-Des.networkaddress.cache.negative.ttl=10


-XX:+AlwaysPreTouch


-Xss1m

-Djava.awt.headless=true

-Dfile.encoding=UTF-8

-Djna.nosys=true

-XX:-OmitStackTraceInFastThrow

-Dio.netty.noUnsafe=true
-Dio.netty.noKeySetOptimization=true
-Dio.netty.recycler.maxCapacityPerThread=0

-Dlog4j.shutdownHookEnabled=false
-Dlog4j2.disable.jmx=true

-Djava.io.tmpdir=${ES_TMPDIR}


-XX:+HeapDumpOnOutOfMemoryError

-XX:HeapDumpPath=/var/lib/elasticsearch

-XX:ErrorFile=/var/log/elasticsearch/hs_err_pid%p.log


8:-XX:+PrintGCDetails
8:-XX:+PrintGCDateStamps
8:-XX:+PrintTenuringDistribution
8:-XX:+PrintGCApplicationStoppedTime
8:-Xloggc:/var/log/elasticsearch/gc.log
8:-XX:+UseGCLogFileRotation
8:-XX:NumberOfGCLogFiles=32
8:-XX:GCLogFileSize=64m

9-:-Xlog:gc*,gc+age=trace,safepoint:file=/var/log/elasticsearch/gc.log:utctime,pid,tags:filecount=32,filesize=64m
9-:-Djava.locale.providers=COMPAT
 
 



```







# Kibana 構築手順


```python:kibana構築

# 以下参照
# https://www.elastic.co/guide/en/kibana/7.2/deb.html#deb-repo
# https://qiita.com/gitya107/items/9ca1793f95149e81130e

# kibana の設定ファイルを編集
vi etc/kibana/kibana.yml 

server.port: 5601
server.host: "0.0.0.0"
elasticsearch.hosts: ["http://192.168.112.141:9200"]
i18n.locale: "ja-JP"

# 起動
systemctl start kibana
systemctl enable kibana
systemctl status kibana



# 最終的なFW

ufw status
Status: active

To                         Action      From
--                         ------      ----
22/tcp                     ALLOW       Anywhere
24224                      ALLOW       Anywhere
9200                       ALLOW       Anywhere
5601/tcp                   ALLOW       Anywhere
22/tcp (v6)                ALLOW       Anywhere (v6)
24224 (v6)                 ALLOW       Anywhere (v6)
9200 (v6)                  ALLOW       Anywhere (v6)
5601/tcp (v6)              ALLOW       Anywhere (v6)

```