Skip to content

hive에서의 docker 적용 사례

Yongho Choi edited this page Feb 13, 2017 · 1 revision

Docker 설정

docker-compose.yml

version: '2'
services:
  mongodb_1:
    # image: registry.hive.com/mongodb
    build: mongodb/
    volumes:
     - ~/service/log/mongodb-1:/var/log/mongodb
    ports:
     - "27017:27017"
     - "9122:22"
  redis_1:
    # image: registry.hive.com/redis
    build: redis/
    volumes:
     - ~/service/log/redis-1:/data
    ports:
     - "6379:6379"
     - "9222:22"
  mariadb_1:
    # image: registry.hive.com/mariadb
    build: mariadb/
    volumes:
     - ~/service/log/mariadb-1:/var/log/mysql
    ports:
     - "3306:3306"
     - "9322:22"
  apache2_1:
    # image: regisdtry.hive.com/apache2
    build: apache2-host/
    volumes:
     - ~/service/log/apache2-1:/var/log/apache2
    network_mode: "host"

Dockerfile

apache2

Dockerfile

FROM ubuntu:16.04

MAINTAINER Server Team <yongho1037@vinusent.com>

# Environment Variable
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

RUN locale-gen en_GB.UTF-8
ENV LANG en_GB.UTF-8
ENV LC_CTYPE en_GB.UTF-8

# Environment Variable
ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
ENV CATALINA_HOME /usr/share/tomcat/tomcat8
ENV CLASSPATH .:${JAVA_HOME}/jre/lib/ext:$JAVA_HOME/lib/tools.jar:${CATALINA_HOME}/lib/jsp-api.jar:${CATALINA_HOME}/lib/servlet-api.jar
ENV PATH ${PATH}:${JAVA_HOME}/bin:${CATALINA_HOME}/bin
ENV TOMCAT_VERSION 8.0.39
ENV TOMCAT_URL http://mirror.navercorp.com/apache/tomcat/tomcat-8/v8.0.39/bin/apache-tomcat-8.0.39.tar.gz

# Configure Apache2
ENV APACHE_RUN_USER     www-data
ENV APACHE_RUN_GROUP    www-data
ENV APACHE_LOG_DIR      /var/log/apache2
ENV APACHE_PID_FILE     /var/run/apache2.pid
ENV APACHE_RUN_DIR      /var/run/apache2
ENV APACHE_LOCK_DIR     /var/lock/apache2
ENV APACHE_LOG_DIR      /var/log/apache2

# Fix sh
RUN rm /bin/sh && ln -s /bin/bash /bin/sh

# Install dependencies
RUN apt-get update -y && apt-get upgrade -y && \
    apt-get install -y git build-essential curl wget software-properties-common openssh-server vim iputils-ping

# Install JDK 8
RUN \
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \
add-apt-repository -y ppa:webupd8team/java && \
apt-get -y update && \
apt-get install -y oracle-java8-installer wget unzip tar && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /var/cache/oracle-jdk8-installer

# Tomcat
RUN wget ${TOMCAT_URL}
RUN tar -xvf apache-tomcat-${TOMCAT_VERSION}.tar.gz
RUN rm apache-tomcat-${TOMCAT_VERSION}.tar.gz
RUN mkdir /usr/share/tomcat
RUN mv apache-tomcat-${TOMCAT_VERSION} /usr/share/tomcat
RUN ln -s /usr/share/tomcat/apache-tomcat-${TOMCAT_VERSION}/ /usr/share/tomcat/tomcat8

# Important! : You should change password.
RUN adduser --disabled-password --gecos "" hive  \
    && echo 'hive:gkdlqm' | chpasswd \
    && mkdir /var/run/sshd

RUN apt-get update -y && apt-get install -y apache2 libapache2-mod-jk

COPY conf/workers.properties /etc/libapache2-mod-jk/workers.properties
COPY conf/000-default.conf /etc/apache2/sites-available/000-default.conf
COPY script/init.sh /opt/init.sh

VOLUME /var/log/apache2

EXPOSE 80
EXPOSE 22

CMD ["/usr/sbin/sshd", "-D"]

000-defailt.conf

<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/html

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined

	JkMount /Hive/* loadbalancer
</VirtualHost>

workers.properties

workers.tomcat_home=/usr/share/tomcat/tomcat8
workers.java_home=/usr/lib/jvm/java-8-oracle
ps=/

worker.list=loadbalancer
worker.instance1.port=18009
worker.instance1.host=192.168.0.201
worker.instance1.type=ajp13
worker.instance1.lbfactor=1
#worker.instance1.cachesize

worker.instance2.port=28009
worker.instance2.host=192.168.0.201
worker.instance2.type=ajp13
worker.instance2.lbfactor=1
#worker.instance1.cachesize

worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=instance1,instance2

init script

#!bin/bash
chown -R hive:hive /opt
chown -R hive:hive /var/log/apache2
service apache2 start

mariadb

Dockerfile

FROM ubuntu:16.04

MAINTAINER Server Team <yongho1037@vinusent.com>

# Set locales
RUN locale-gen en_GB.UTF-8
ENV LANG en_GB.UTF-8
ENV LC_CTYPE en_GB.UTF-8

# Fix sh
RUN rm /bin/sh && ln -s /bin/bash /bin/sh

# Install dependencies
RUN apt-get update -y && apt-get upgrade -y && \
    apt-get install -y git build-essential curl wget software-properties-common openssh-server vim iputils-ping

# ubuntu 14.04
#RUN apt-get install -y python-software-properties
#RUN apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
#RUN add-apt-repository 'deb http://ftp.kaist.ac.kr/mariadb/repo/10.0/ubuntu trusty main'
#RUN apt-get update -y && apt-get install -y mariadb-server

# ubuntu 16.04
RUN apt-get install -y mariadb-server mariadb-client

# Important! : You should change passwd. (default xhazot)
RUN adduser --disabled-password --gecos "" hive  \
    && echo 'hive:gkdlqm' | chpasswd \
    && mkdir /var/run/sshd

COPY conf/50-server.cnf /etc/mysql/mariadb.conf.d/50-server.cnf
COPY conf/my.cnf /etc/mysql/my.cnf
COPY sql/init.sql /opt/init.sql
COPY script/init.sh /opt/init.sh

EXPOSE 3306
EXPOSE 22

CMD ["/usr/sbin/sshd", "-D"]

50-server.cnf

[server]

[mysqld]
user		= mysql
pid-file	= /var/run/mysqld/mysqld.pid
socket		= /var/run/mysqld/mysqld.sock
port		= 3306
basedir		= /usr
datadir		= /var/lib/mysql
tmpdir		= /tmp
lc-messages-dir	= /usr/share/mysql
skip-external-locking

bind-address = 0.0.0.0

key_buffer_size		= 16M
max_allowed_packet	= 16M
thread_stack		= 192K
thread_cache_size       = 8

myisam-recover         = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10

query_cache_limit	= 1M
query_cache_size        = 16M

log_error = /var/log/mysql/error.log

#server-id		= 1
#log_bin			= /var/log/mysql/mysql-bin.log
expire_logs_days	= 10
max_binlog_size   = 100M
#binlog_do_db		= include_database_name
#binlog_ignore_db	= include_database_name

character-set-server  = utf8mb4
collation-server      = utf8mb4_general_ci

[embedded]
[mariadb]
[mariadb-10.0]

my.cnf

[client-server]


[client]
default-character-set = utf8
[mysqld]
init_connect = SET collation_connection = utf8_general_ci
init_connect = SET NAMES utf8
character-set-server = utf8
collation-server = utf8_general_ci
[mysqldump]
default-character-set = utf8
[mysql]
default-character-set = utf8

# Import all .cnf files from configuration directory
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/

init script

#!bin/bash
usermod -aG mysql hive
chown -R hive:hive /opt
chown -R mysql:mysql /var/log/mysql
service mysql start
mysql -u root < /opt/init.sql

mongodb

Dockerfile

FROM ubuntu:16.04

MAINTAINER Server Team <yongho1037@vinusent.com>

# Set locales
RUN locale-gen en_GB.UTF-8
ENV LANG en_GB.UTF-8
ENV LC_CTYPE en_GB.UTF-8

# Environment Variable
ENV CATALINA_HOME=/usr/share/tomcat/tomcat8
ENV CLASSPATH=.:$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar:$CATALINA_HOME/lib/jsp-api.jar:$CATALINA_HOME/lib/servlet-api.jar
ENV PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin:$CATALINA_HOME/bin

# Fix sh
RUN rm /bin/sh && ln -s /bin/bash /bin/sh

# Install dependencies
RUN apt-get update -y && apt-get upgrade -y && \
    apt-get install -y git build-essential curl wget software-properties-common openssh-server vim iputils-ping

RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
RUN echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.2.list
RUN apt-get update -y && apt-get install -y mongodb-org

# Important! : You should change passwd. (default gkdlqm)
RUN adduser --disabled-password --gecos "" hive  \
    && echo 'hive:gkdlqm' | chpasswd \
    && mkdir /var/run/sshd

COPY conf/mongodb.service /etc/systemd/system/mongodb.service
COPY conf/mongod.conf /etc/mongod.conf
COPY conf/disable-transparent-hugepages /etc/init.d/disable-transparent-hugepages
COPY script/init.sh /opt/init.sh

RUN chmod 755 /etc/init.d/disable-transparent-hugepages
RUN update-rc.d disable-transparent-hugepages defaults

EXPOSE 27017
EXPOSE 22

# Launch sshd
CMD ["/usr/sbin/sshd", "-D"]

disable-transparent-hugepages

#!/bin/bash
### BEGIN INIT INFO
# Provides:          disable-transparent-hugepages
# Required-Start:    $local_fs
# Required-Stop:
# X-Start-Before:    mongod mongodb-mms-automation-agent
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Disable Linux transparent huge pages
# Description:       Disable Linux transparent huge pages, to improve
#                    database performance.
### END INIT INFO

case $1 in
  start)
    if [ -d /sys/kernel/mm/transparent_hugepage ]; then
      thp_path=/sys/kernel/mm/transparent_hugepage
    elif [ -d /sys/kernel/mm/redhat_transparent_hugepage ]; then
      thp_path=/sys/kernel/mm/redhat_transparent_hugepage
    else
      return 0
    fi

    echo 'never' > ${thp_path}/enabled
    echo 'never' > ${thp_path}/defrag

    re='^[0-1]+$'
    if [[ $(cat ${thp_path}/khugepaged/defrag) =~ $re ]]
    then
      # RHEL 7
      echo 0  > ${thp_path}/khugepaged/defrag
    else
      # RHEL 6
      echo 'no' > ${thp_path}/khugepaged/defrag
    fi

    unset re
    unset thp_path
    ;;
esac

mongod.conf

# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1


#processManagement:

#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options:

#auditLog:

#snmp:

mongodb.service

[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target

[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf

[Install]
WantedBy=multi-user.target

init script

#!bin/bash
mkdir /data
mkdir /data/db
usermod -aG mongodb hive
chown -R hive:hive /opt
chown -R mongodb:mongodb /var/log/mongodb
chown -R mongodb:mongodb /var/lib/mongodb
chown -R hive:hive /data
/usr/bin/mongod --fork --logpath /var/log/mongodb/mongodb.log

redis

Dockerfile

FROM redis
MAINTAINER Server Team <yongho1037@vinusent.com>

RUN mkdir /var/log/redis

COPY conf/redis.conf /usr/local/etc/redis/redis.conf
CMD [ "redis-server", "/usr/local/etc/redis/redis.conf" ]

redis.conf

bind 0.0.0.0

protected-mode yes

port 6379

tcp-backlog 511

timeout 0

tcp-keepalive 300

daemonize no

supervised no

pidfile /var/run/redis_6379.pid

loglevel notice

logfile redis.log

databases 16

save 900 1
save 300 10
save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

dbfilename dump.rdb

dir ./

slave-serve-stale-data yes

dangerous commands.
slave-read-only yes


repl-diskless-sync no


repl-diskless-sync-delay 5

repl-disable-tcp-nodelay no

slave-priority 100

appendonly no

appendfilename "appendonly.aof"

appendfsync everysec

no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb

aof-load-truncated yes

lua-time-limit 5000

slowlog-log-slower-than 10000

slowlog-max-len 128

latency-monitor-threshold 0

notify-keyspace-events ""

hash-max-ziplist-entries 512
hash-max-ziplist-value 64

list-max-ziplist-size -2

list-compress-depth 0

set-max-intset-entries 512

zset-max-ziplist-entries 128
zset-max-ziplist-value 64

hll-sparse-max-bytes 3000

activerehashing yes

client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60

hz 10

aof-rewrite-incremental-fsync yes

tomcat server

Dockerfile

FROM ubuntu:16.04

MAINTAINER Server Team <yongho1037@vinusent.com>

# Set locales
ENV LANG en_GB.UTF-8
ENV LC_CTYPE en_GB.UTF-8

# Environment Variable
ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
ENV CATALINA_HOME /opt/tomcat
ENV PATH $PATH:$CATALINA_HOME/bin
ENV TOMCAT_VERSION 8.0.39
ENV TOMCAT_URL http://mirror.navercorp.com/apache/tomcat/tomcat-8/v8.0.39/bin/apache-tomcat-8.0.39.tar.gz

# Set locales
RUN locale-gen en_GB.UTF-8

# Fix sh
RUN rm /bin/sh && ln -s /bin/bash /bin/sh

# Install dependencies
RUN apt-get update -y && apt-get upgrade -y && \
    apt-get install -y git build-essential curl wget software-properties-common openssh-server vim iputils-ping

# Important! : You should change passwd.
RUN adduser --disabled-password --gecos "" hive  \
    && echo 'hive:gkdlqm' | chpasswd \
    && mkdir /opt/tmp \
    && mkdir /var/run/sshd

# Install JDK 8
RUN \
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \
add-apt-repository -y ppa:webupd8team/java && \
apt-get -y update && \
apt-get install -y oracle-java8-installer wget unzip tar && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /var/cache/oracle-jdk8-installer

# add user and working directory make
RUN chown -R hive:hive /opt

# Tomcat
RUN wget ${TOMCAT_URL}
RUN tar -xvf apache-tomcat-${TOMCAT_VERSION}.tar.gz -C /opt
RUN mv /opt/apache-tomcat-${TOMCAT_VERSION} /opt/tomcat
RUN rm apache-tomcat-${TOMCAT_VERSION}.tar.gz
RUN rm -rf /opt/tomcat/webapps/examples && \
rm -rf /opt/tomcat/webapps/docs && \
rm -rf /opt/tomcat/webapps/ROOT

RUN mkdir /opt/exec
COPY script/init.sh /opt/init.sh
COPY script/startup.sh /opt/exec/startup.sh
COPY script/delete_log.sh /opt/exec/delete_log.sh
COPY script/shutdown.sh /opt/exec/shutdown.sh
COPY conf/config_Hive.ini /opt/exec/config_Hive.ini

WORKDIR /opt/tomcat

EXPOSE 8080
EXPOSE 8009
EXPOSE 22

# Launch sshd
CMD ["/usr/sbin/sshd", "-D"]

config_Hive.ini

# db
db1_name = data1
db1_user = hive
db1_password = gkdlqm
db1_url = jdbc:mysql://hive_mariadb_1_1:3306/hive?autoReconnect=true&useSSL=false

# redis
redis1_host=hive_redis_1_1
redis1_port=6379

# log
log_level = Hive_Debug

# logdb
logdb1_host=hive_mongodb_1_1
logdb1_port=27017

init script

#!bin/bash
chown -R hive:hive /opt
/opt/tomcat/bin/startup.sh

delete log

#!bin/bash
find ./Log -mtime +14 -name debug\* -exec rm {} \;
find ./Log -mtime +14 -name error\* -exec rm {} \;
find ./Log -mtime +14 -name info\* -exec rm {} \;
find ../tomcat/logs -mtime +14 -name instance\* -exec rm {} \;
find ../tomcat/logs -mtime +14 -name manager\* -exec rm {} \;
find ../tomcat/logs -mtime +14 -name catalina\* -exec rm {} \;
find ../tomcat/logs -mtime +14 -name host-manager\* -exec rm {} \;
find ../tomcat/logs -mtime +14 -name localhost.\* -exec rm {} \;
find ../tomcat/logs -mtime +14 -name localhost_access_log\* -exec rm {} \;