Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions docker/Elastic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Tổng quan về việc chạy các thành phần Elasticsearch, Logstash, Kibana trên từng container riêng biệt

## Hướng dẫn chạy Elasticsearch container
+ Build docker image Elasticsearch bằng lệnh

```
docker build -t elasticsearch .
```
   Lưu ý trước khi chạy lệnh trên thì phải trỏ tới thư mục chứa docker file

Ngoài cách build thủ công còn có thể sử dụng image có sẵn trên docker hub: "elasticsearch" (một bản OFFICIAL REPOSITORY)

+ Chạy docker image Elasticsearch
Sau khi build xong Docker image có thể chạy đơn giản bằng lệnh

```
docker run -d -P elasticsearch
```
Có thể sử dụng file cấu hình tùy biến (ví dụ /usr/share/elasticsearch/config) bằng lệnh

```
docker run -d -v "$PWD/config":/usr/share/elasticsearch/config elasticsearch
```

## Hướng dẫn chạy Kibana container
+ Build docker image Kibana bằng lệnh

```
docker build -t kibana .
```
Lưu ý trước khi chạy lệnh trên thì phải trỏ tới thư mục chứa docker file

Ngoài cách build thủ công còn có thể sử dụng image có sẵn trên docker hub: "kibana" (một bản OFFICIAL REPOSITORY)

+ Chay docker image Kibana
Chạy image Kibana bằng cách trỏ tới Docker container chạy Elasticsearch (ví dụ elegant_brahmagupta):

```
sudo docker run --link elegant_brahmagupta:elasticsearch -d -p 5601:5601 kibana
```

Ngoài ra có thể chạy Kibana image bằng cách trỏ tới địa chỉ ip của server chạy Elasticsearch:

```
sudo docker run --name some-kibana -e ELASTICSEARCH_URL=http://some-elasticsearch:9200 -p 5601:5601 -d kibana
```

## Hướng dẫn chạy Logstash container
+ Build docker image Logstash bằng lệnh

```
docker build -t logstash .
```
Lưu ý trước khi chạy lệnh trên thì phải trỏ tới thư mục chứa docker file

Ngoài cách build thủ công còn có thể sử dụng image có sẵn trên docker hub: "logstash" (một bản OFFICIAL REPOSITORY)

+ Chạy docker image Logstash
Test thử xem docker image có hoạt động bình thường không bằng lệnh

```
docker run -it --rm logstash -e 'input { stdin { } } output { stdout { } }'
```

Để kết nối Logstash tới Elasticsearch ta thực hiện lệnh sau

```
sudo docker run -it -v "$PWD":/mount logstash -f /mount/config
```
Trong đó:
- $PWD lấy đường dẫn hiện tại của host,
- "/mount" mount đường dẫn hiện tại vào thư mục /mount của container
- "-f /mount/config" lấy file config trong thư mục mount để làm file cấu hình cho logstash chạy. Trong file này sẽ định nghĩa vị trí của Elasticsearch

Ví dụ file config sẽ có dạng
```
input {
file {
path => "/var/log/nguyenbinh.log"
}
beats {
port => "5044"
}
}
filter {
grok {
match => { "message" => "(idp %{DATA:idp} )([^\"]*)(idkv %{DATA:idkv} )([^\"]*)(idcum %{DATA:idcum} )([^\"]*)(nhietdo %{NUMBER:nhietdo:float})([^\"]*)(doam %{NUMBER:doam:float})([^\"]*)(nguoi |%{NUMBER:nguoi:int})"}
}
}
output {
elasticsearch {
hosts => ["192.168.0.109:9200"]
}
}
```
54 changes: 54 additions & 0 deletions docker/Elastic/elasticsearch_2.3/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
FROM openjdk:8-jre

# grab gosu for easy step-down from root
ENV GOSU_VERSION 1.7
RUN set -x \
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
&& export GNUPGHOME="$(mktemp -d)" \
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
&& rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
&& chmod +x /usr/local/bin/gosu \
&& gosu nobody true

# https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-repositories.html
# https://packages.elasticsearch.org/GPG-KEY-elasticsearch
RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 46095ACC8548582C1A2699A9D27D666CD88E42B4

ENV ELASTICSEARCH_VERSION 2.3.5
ENV ELASTICSEARCH_REPO_BASE http://packages.elasticsearch.org/elasticsearch/2.x/debian

RUN echo "deb $ELASTICSEARCH_REPO_BASE stable main" > /etc/apt/sources.list.d/elasticsearch.list

RUN set -x \
&& apt-get update \
&& apt-get install -y --no-install-recommends elasticsearch=$ELASTICSEARCH_VERSION \
&& rm -rf /var/lib/apt/lists/*

ENV PATH /usr/share/elasticsearch/bin:$PATH

WORKDIR /usr/share/elasticsearch

RUN set -ex \
&& for path in \
./data \
./logs \
./config \
./config/scripts \
; do \
mkdir -p "$path"; \
chown -R elasticsearch:elasticsearch "$path"; \
done

COPY config ./config

VOLUME /usr/share/elasticsearch/data

COPY docker-entrypoint.sh /

RUN chmod 777 /docker-entrypoint.sh

EXPOSE 9200 9300
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["elasticsearch"]
1 change: 1 addition & 0 deletions docker/Elastic/elasticsearch_2.3/config/elasticsearch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
network.host: 0.0.0.0
15 changes: 15 additions & 0 deletions docker/Elastic/elasticsearch_2.3/config/logging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# you can override this using by setting a system property, for example -Des.logger.level=DEBUG
es.logger.level: INFO
rootLogger: ${es.logger.level}, console
logger:
# log action execution errors for easier debugging
action: DEBUG
# reduce the logging for aws, too much is logged under the default INFO
com.amazonaws: WARN

appender:
console:
type: console
layout:
type: consolePattern
conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n"
23 changes: 23 additions & 0 deletions docker/Elastic/elasticsearch_2.3/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

set -e

# Add elasticsearch as command if needed
if [ "${1:0:1}" = '-' ]; then
set -- elasticsearch "$@"
fi

# Drop root privileges if we are running elasticsearch
# allow the container to be started with `--user`
if [ "$1" = 'elasticsearch' -a "$(id -u)" = '0' ]; then
# Change the ownership of /usr/share/elasticsearch/data to elasticsearch
chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/data

set -- gosu elasticsearch "$@"
#exec gosu elasticsearch "$BASH_SOURCE" "$@"
fi

# As argument is not related to elasticsearch,
# then assume that user wants to run his own process,
# for example a `bash` shell to explore this image
exec "$@"
62 changes: 62 additions & 0 deletions docker/Elastic/kibana_4.5/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
FROM debian:jessie

# add our user and group first to make sure their IDs get assigned consistently
RUN groupadd -r kibana && useradd -r -m -g kibana kibana

RUN apt-get update && apt-get install -y \
ca-certificates \
wget \
--no-install-recommends && rm -rf /var/lib/apt/lists/*

# grab gosu for easy step-down from root
ENV GOSU_VERSION 1.7
RUN set -x \
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
&& export GNUPGHOME="$(mktemp -d)" \
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
&& rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
&& chmod +x /usr/local/bin/gosu \
&& gosu nobody true

# grab tini for signal processing and zombie killing
ENV TINI_VERSION v0.9.0
RUN set -x \
&& wget -O /usr/local/bin/tini "https://github.com/krallin/tini/releases/download/$TINI_VERSION/tini" \
&& wget -O /usr/local/bin/tini.asc "https://github.com/krallin/tini/releases/download/$TINI_VERSION/tini.asc" \
&& export GNUPGHOME="$(mktemp -d)" \
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys 6380DC428747F6C393FEACA59A84159D7001A4E5 \
&& gpg --batch --verify /usr/local/bin/tini.asc /usr/local/bin/tini \
&& rm -r "$GNUPGHOME" /usr/local/bin/tini.asc \
&& chmod +x /usr/local/bin/tini \
&& tini -h

# https://www.elastic.co/guide/en/kibana/4.4/setup.html#kibana-apt
# https://packages.elasticsearch.org/GPG-KEY-elasticsearch
RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 46095ACC8548582C1A2699A9D27D666CD88E42B4

ENV KIBANA_MAJOR 4.5
ENV KIBANA_VERSION 4.5.4

RUN echo "deb http://packages.elastic.co/kibana/${KIBANA_MAJOR}/debian stable main" > /etc/apt/sources.list.d/kibana.list

RUN set -x \
&& apt-get update \
&& apt-get install -y --no-install-recommends kibana=$KIBANA_VERSION \
&& chown -R kibana:kibana /opt/kibana \
&& rm -rf /var/lib/apt/lists/* \
\
# ensure the default configuration is useful when using --link
&& sed -ri "s!^(\#\s*)?(elasticsearch\.url:).*!\2 'http://elasticsearch:9200'!" /opt/kibana/config/kibana.yml \
&& grep -q 'elasticsearch:9200' /opt/kibana/config/kibana.yml

ENV PATH /opt/kibana/bin:$PATH

COPY docker-entrypoint.sh /

RUN chmod 777 /docker-entrypoint.sh

EXPOSE 5601
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["kibana"]
18 changes: 18 additions & 0 deletions docker/Elastic/kibana_4.5/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -e

# Add kibana as command if needed
if [[ "$1" == -* ]]; then
set -- kibana "$@"
fi

# Run as user "kibana" if the command is "kibana"
if [ "$1" = 'kibana' ]; then
if [ "$ELASTICSEARCH_URL" ]; then
sed -ri "s!^(\#\s*)?(elasticsearch\.url:).*!\2 '$ELASTICSEARCH_URL'!" /opt/kibana/config/kibana.yml
fi

set -- gosu kibana tini -- "$@"
fi

exec "$@"
55 changes: 55 additions & 0 deletions docker/Elastic/logstash_2.3/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
FROM openjdk:8-jre

# install plugin dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
libzmq3 \
&& rm -rf /var/lib/apt/lists/*

# the "ffi-rzmq-core" gem is very picky about where it looks for libzmq.so
RUN mkdir -p /usr/local/lib \
&& ln -s /usr/lib/*/libzmq.so.3 /usr/local/lib/libzmq.so

# grab gosu for easy step-down from root
ENV GOSU_VERSION 1.7
RUN set -x \
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
&& export GNUPGHOME="$(mktemp -d)" \
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
&& rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
&& chmod +x /usr/local/bin/gosu \
&& gosu nobody true

# https://www.elastic.co/guide/en/logstash/2.3/package-repositories.html
# https://packages.elastic.co/GPG-KEY-elasticsearch
RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 46095ACC8548582C1A2699A9D27D666CD88E42B4

ENV LOGSTASH_MAJOR 2.3
ENV LOGSTASH_VERSION 1:2.3.4-1

RUN echo "deb http://packages.elastic.co/logstash/${LOGSTASH_MAJOR}/debian stable main" > /etc/apt/sources.list.d/logstash.list

RUN set -x \
&& apt-get update \
&& apt-get install -y --no-install-recommends logstash=$LOGSTASH_VERSION \
&& rm -rf /var/lib/apt/lists/*

ENV PATH /opt/logstash/bin:$PATH

# necessary for 5.0+ (overriden via "--path.settings", ignored by < 5.0)
ENV LS_SETTINGS_DIR /etc/logstash
# comment out some troublesome configuration parameters
# path.log: logs should go to stdout
# path.config: No config files found: /etc/logstash/conf.d/*
RUN set -ex \
&& if [ -f "$LS_SETTINGS_DIR/logstash.yml" ]; then \
sed -ri 's!^(path.log|path.config):!#&!g' "$LS_SETTINGS_DIR/logstash.yml"; \
fi

COPY docker-entrypoint.sh /

RUN chmod 777 /docker-entrypoint.sh

ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["-e", ""]
15 changes: 15 additions & 0 deletions docker/Elastic/logstash_2.3/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -e

# Add logstash as command if needed
if [ "${1:0:1}" = '-' ]; then
set -- logstash "$@"
fi

# Run as user "logstash" if the command is "logstash"
if [ "$1" = 'logstash' ]; then
set -- gosu logstash "$@"
fi

exec "$@"
42 changes: 42 additions & 0 deletions docker/Kura/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
FROM debian

## to build it
## sudo docker build -t kura .
## to run it
## sudo docker run -it -p 80:80 -p 5002:5002 -p 1450:1450 --name kura kura

##Them nguon jdk-8 Do mac dinh chua co

RUN echo "deb http://ftp.de.debian.org/debian jessie-backports main" >> /etc/apt/sources.list

## Cai dat cac goi phan mem can thiet
RUN apt-get update && \
apt-get install -y apt-utils unzip ethtool dos2unix telnet bind9 hostapd isc-dhcp-server iw monit wget openjdk-8-jdk wireless-tools cron && \
rm -rf /var/lib/apt/lists/*
#Tao crontab khi khoi dong may
COPY onboot-cron /etc/cron.d/onboot-cron
RUN crontab /etc/cron.d/onboot-cron

## Cai dat kura
RUN wget http://ftp.daumkakao.com/eclipse/kura/releases/2.0.0/kura_2.0.0_raspberry-pi-2_installer.deb
RUN dpkg -i kura_2.0.0_raspberry-pi-2_installer.deb

## Nap san bundle fog_to_cloud
COPY fog_to_cloud.dp /opt/eclipse/kura/kura/packages/
RUN echo "package_name=file\:/opt/eclipse/kura/kura/packages/fog_to_cloud.dp" >> /opt/eclipse/kura/kura/dpa.properties

## Trick java serverlet
RUN [ -f /lib/$(arch)-linux-gnu/libudev.so.0 ] || ln -sf /lib/$(arch)-linux-gnu/libudev.so.1 /lib/$(arch)-linux-gnu/libudev.so.0

COPY entrypoint.sh /

RUN chmod 777 /entrypoint.sh

## Bind cong 80 để kết nối kura web
EXPOSE 80
## Bind cong 5002 để telnet osgi
EXPOSE 5002
## Bind cong 1450 để kết nối iagent
EXPOSE 1450

ENTRYPOINT ["/entrypoint.sh"]
Loading