AWS ES,Kibana,Grafana的汇总

我比较了可视化工具(AWS ES、Kibana和Grafana)。

情景

假设想要将存储在数据库中的数据可视化,但是不想使用商业智能工具(因为设置不直观且复杂)。
可以考虑的选择是ElasticSearch和Kibana,但是困扰于是使用AWS的ElasticSearch Service,还是在EC2上部署ElasticSearch和Kibana,抑或是使用Grafana。因此,我大致进行了比较。

所有优点表

我冒出的好处如下所示。

AWS ES

他のAWSサービスとの連携が容易
サーバの運用、管理をしなくて良い
バックアップが自動
グラフやダッシュボードの設定がシンプルで直感的
リソースモニターが付いている
IAMによる権限管理が可能

EC2 grafana

画像データが取得できるので定期レポーティング実装が容易
golangなので、リソースが削減できそう
グラフの作り込みができる
PrometheusやCloudwatchなどの情報を取り込める
比較的細かな権限管理ができる
特定の時間だけ起動することによって、コスト削減可能

EC2 ELK

kibanaのバージョンアップがしやすい(v5リリース予定)
kibanaUIプラグインが利用可能
グラフやダッシュボードの設定がシンプルで直感的
特定の時間だけ起動することによって、コスト削減可能

以下是中文的原生表述方式,仅提供一种选择:
对比

比較項目

認証機能がつけられるか
グラフのカスタマイズのがしやすいか
レポーティング機能がついているか
累積グラフが使えるか
バックアップが容易にとれるか
構築や設定が容易か
お金が安いか

前提条件

サービスは停止しない
データ容量は10G
メモリはkibanaが2G必要で、Elasticsearchは4G必要とする。
データ転送量は無視

#サービス認証グラフ作成累積グラフレポーティングバックアップ構築コスト1AWS ESIAM◯××自動で月に1度◯$196.02/月(※1)2EC2 ELKSG◯Plugin×××$116.4/月(※2)3EC2 Grafana◯△◯△××$116.4/月(※3)4ES and EC2 kibanaSG◯Plugin×自動で月に1度◯$112.26/月(※4)

※1 每月196.02美元 = 弹性搜索(每小时0.27美元 * 24 * 30小时) + 弹性块存储(每GB 0.162美元 * 10)
※2 每月116.4美元 = 弹性计算云(每小时0.16美元 * 24 * 30小时) + 弹性块存储(每GB 0.12美元 * 10)
※3 每月116.4美元 = 弹性计算云(每小时0.16美元 * 24 * 30小时) + 弹性块存储(每GB 0.12美元 * 10)
※4 每月112.26美元 = 弹性搜索(每小时0.112美元 * 24 * 30小时) + 弹性计算云(每小时0.04美元 * 24 * 30小时) + 弹性搜索弹性块存储(每GB 0.162美元 * 10) + 弹性计算云弹性块存储(每GB 0.12美元 * 10)

※参考
参考
AWS估价表
AWS EC2费用表
AWS EBS费用表

結論 – 我們不得不下結論

如果没有想要尽快升级到新版本或使用插件的需求,我认为在AWS ES上建立Elasticsearch,并在EC2上搭建Kibana是个不错的选择。

任务日志

Oracle的安装设置

我们假设数据库是像企业级的Oracle一样进行操作。

    Dockerを使ってOracleを起動する
$ docker run -d --shm-size=2g -p 1521:1521 -p 8080:8080 alexeiled/docker-oracle-xe-11g

※ 参考
https://hub.docker.com/r/alexeiled/docker-oracle-xe-11g/

请参考上述链接。

    tableを作成して適当なデータを入れる。(今回は説明の便宜上ここで、 MATSUNO_TABLE というテーブルを作成したこととする)

logstash的安装配置

创建并切换至适用于Logstash的目录。

$ mkdir logstash && cd logstash
    Oracleのドライバー(ojdbc6.jar)をダウンロードページからダウンロードしてlogstash用ディレクトリに配置する。

1. 亚马逊的Elasticsearch服务

搭建环境

※参考
请参考亚马逊云服务上的Elasticsearch服务。

スクリーンショット 2016-08-31 14.30.22.png
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "",
      "Effect": "Allow",
      "Principal": {
        "AWS": "*"
      },
      "Action": "es:*",
      "Condition": {
        "IpAddress": {
          "aws:SourceIp": [
            "YOUR_IP"
          ]
        }
      },
      "Resource": "arn:aws:es:ap-northeast-1:YOUR_AWS_ACCOUNT:domain/matsuno-test/*"
    }
  ]
}

请在YOUR_IP的位置填写您想要允许连接的IP地址。

スクリーンショット 2016-08-31 14.35.19.png

启动大约需要10分钟。

スクリーンショット 2016-08-31 15.35.12.png

状态为绿色即表示一切正常。

数据输入(在装有数据库的服务器上进行)

    logstash.conf作成(logstashのディレクトリにて)
input {
    jdbc {
        jdbc_connection_string => "jdbc:oracle:thin:@oracle:1521/xe"
        jdbc_user => "system"
        jdbc_password => "oracle"
        jdbc_driver_library =>"/config-dir/ojdbc6.jar"
        jdbc_driver_class => "Java::oracle.jdbc.driver.OracleDriver"
        statement => "
SELECT
    *
FROM
    MATSUNO_TABLE
"
    }
}
output {
    elasticsearch {
        ssl => true
        hosts => ["search-matsuno-test-7brub6nxbn352qchitarrjncdu.ap-northeast-1.es.amazonaws.com:443"]
        index => "matsuno"
    }
}

※ 参考链接:https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html

AWS的Elasticsearch Service要注意的是它的端点是使用HTTPS(443)。

$ docker run -it --rm --link 821c58da87eb:oracle -v "$PWD":/config-dir logstash -f /config-dir/logstash.conf

Settings: Default pipeline workers: 2
Pipeline main started
Pipeline main has been shutdown
stopping pipeline {:id=>"main"}
スクリーンショット 2016-08-31 15.39.33.png

我确认了数据已经存在。

插件 (Chā-

亚马逊 ES支持 ICU Analysis 插件和 Kuromoji 插件。您可通过 Elasticsearch Mapping API 进行正常配置。亚马逊 ES目前不支持像 Shield 或 Marvel 这样的商业插件。AWS 中对应这些插件的是 AWS 访问管理 (IAM) 和 CloudWatch。

似乎无法在AWS上安装插件。
然而,可以使用IAM等方法来控制终端点。

以下是参考链接中提到的内容的中文释义:

Amazon Elasticsearch Service 一个通过亚马逊云服务提供的托管式Elasticsearch服务。在此服务上,您可以轻松地部署、扩展和管理Elasticsearch集群,以便用于搜索、日志和实时分析等各种用例。通过使用Amazon Elasticsearch Service,您可以快速、无缝地在亚马逊云上构建和运行强大的搜索应用程序。

2. 在EC2上使用Elasticsearch和Kibana v4。

环境构建

    • EC2を作成(AmazonLinux)

 

    • SecurityGroupで9200,5601を許可

 

    ElasticSearchインストール
$ sudo rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
[elasticsearch-2.x]
name=Elasticsearch repository for 2.x packages
baseurl=https://packages.elastic.co/elasticsearch/2.x/centos
gpgcheck=1
gpgkey=https://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1
$ sudo yum update
$ sudo yum install elasticsearch

※参考
https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-repositories.html

请参考上述网址获取有关设置仓库的信息。

    elasticsearchの外部アクセス設定
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
# network.host: 192.168.0.1
 network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
# http.port: 9200
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html>
#
# --------------------------------- Discovery ----------------------------------
#
    elasticsearch起動
$ sudo chkconfig --add elasticsearch
$ sudo /etc/init.d/elasticsearch start
    kibanaをダウンロード
$ wget https://download.elastic.co/kibana/kibana/kibana-4.5.4-linux-x64.tar.gz
$ tar xfvz kibana-4.5.4-linux-x64.tar.gz
    kibana設定(コメントアウトを外す)
# Kibana is served by a back end server. This controls which port to use.
 server.port: 5601

# The host to bind the server to.
 server.host: "0.0.0.0"

# If you are running kibana behind a proxy, and want to mount it at a path,
# specify that path here. The basePath can't end in a slash.
# server.basePath: ""

# The maximum payload size in bytes on incoming server requests.
 server.maxPayloadBytes: 1048576

# The Elasticsearch instance to use for all your queries.
 elasticsearch.url: "http://localhost:9200"

# preserve_elasticsearch_host true will send the hostname specified in `elasticsearch`. If you set it to false,
# then the host you use to connect to *this* Kibana instance will be sent.
# elasticsearch.preserveHost: true

..............
..............
..............


# Time in milliseconds for Elasticsearch to wait for responses from shards.
# Set to 0 to disable.
# elasticsearch.shardTimeout: 0

# Time in milliseconds to wait for Elasticsearch at Kibana startup before retrying
# elasticsearch.startupTimeout: 5000

# Set the path to where you would like the process id file to be created.
 pid.file: /var/run/kibana.pid

# If you would like to send the log output to a file you can set the path below.
# logging.dest: stdout

#!/bin/sh
#
#
# chkconfig:   2345 80 20
# description: Starts and stops a single kibana instance on this system

### BEGIN INIT INFO
# Provides:          kibana
# Required-Start:    $local_fs $remote_fs $network
# Should-Start:      $time
# Required-Stop:     $local_fs $remote_fs $network
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: Kibana 4
# Description:       Service controller for Kibana 4
### END INIT INFO"

INSTALLED_DIR=/home/ec2-user/kibana-4.5.4-linux-x64
EXEC_SCRIPT="$INSTALLED_DIR/bin/kibana"
LOG_DIR=/var/log/kibana
PID_DIR=/var/run
PID_FILE="$PID_DIR"/kibana.pid
LOG_FILE="$LOG_DIR"/kibana.log

test -d $LOG_DIR || mkdir $LOG_DIR

# Source function library.
. /etc/init.d/functions

RETVAL=0

case "$1" in
    start)
        if [ ! -f "$PID_FILE" ]; then
          echo -n "Starting Kibana"
          nohup $EXEC_SCRIPT 0<&- &> $LOG_FILE &
          echo $! > $PID_FILE
          success
        else
          echo -n "Kibana is already running"
          RETVAL=1
          failure
        fi
        echo
        ;;
    stop)
        if [ -f "$PID_FILE" ]; then
          echo -n "Stopping Kibana"
          test -f $PID_FILE && cat $PID_FILE | xargs kill -s SIGKILL && rm -f $PID_FILE
          success
        else
          echo -n "Kibana is not running"
          RETVAL=1
          failure
        fi
        echo
        ;;
    restart)
        $0 stop
        $0 start
        ;;
    reload)
        $0 restart
        ;;
    status)
        status kibana
        RETVAL=$?
        ;;
*)
echo "Usage: $0 {start|stop|status|restart|reload}"
exit 1
;;
esac
exit $RETVAL
    kibana起動
$ chmod +x /etc/init.d/kibana
$ chkconfig --add kibana
$ /etc/init.d/kibana start
    ブラウザでアクセス

请提供您的实例IP地址:YOUR_INSTANCE_IP:5601。

在存有数据库的服务器上进行数据投入。

    logstash.conf作成(logstashのディレクトリにて)
input {
    jdbc {
        jdbc_connection_string => "jdbc:oracle:thin:@oracle:1521/xe"
        jdbc_user => "system"
        jdbc_password => "oracle"
        jdbc_driver_library =>"/config-dir/ojdbc6.jar"
        jdbc_driver_class => "Java::oracle.jdbc.driver.OracleDriver"
        statement => "
SELECT
    *
FROM
    MATSUNO_TABLE
"
    }
}
output {
    elasticsearch {
        hosts => ["YOUR_ELASTICSEARCH_IP:9200"]
        index => "matsuno"
    }
}
$ docker run -it --rm --link 821c58da87eb:oracle -v "$PWD":/config-dir logstash -f /config-dir/logstash.conf

Settings: Default pipeline workers: 2
Pipeline main started
Pipeline main has been shutdown
stopping pipeline {:id=>"main"}

插件 jì)

    git install
$ sudo yum install -y git
    install plugin
$ cd /home/ec2-user/kibana-4.5.4-linux-x64/installedPlugins
$ git clone https://github.com/sbeyn/kibana-plugin-line-sg.git
    • 確認

 

    http://54.199.223.185:5601/status にアクセスしてプラグンが ready になっていること

3. 在EC2上部署Elasticsearch和Grafana。

建立环境

    • EC2を作成(AmazonLinux)

 

    • SecurityGroupで9200,3000を許可

 

    ElasticSearchインストール

只要不是ElasticSearch,DB可以是其他的。由于我们要重复使用之前的logstash配置,所以将使用ElasticSearch。

$ sudo rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
[elasticsearch-2.x]
name=Elasticsearch repository for 2.x packages
baseurl=https://packages.elastic.co/elasticsearch/2.x/centos
gpgcheck=1
gpgkey=https://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1
$ sudo yum update
$ sudo yum install elasticsearch
    grafanaインストール
$ sudo yum install https://grafanarel.s3.amazonaws.com/builds/grafana-3.1.1-1470047149.x86_64.rpm

※参考:http://docs.grafana.org/installation/rpm/

请参考上述链接了解有关Grafana在RPM下的安装步骤。

    起動
$ /etc/init.d/grafana-server start
    確認

通过 http://YOUR_IP:3000 admin/admin 访问

bannerAds