2步安装1个hive docker运行环境[centos7]

1 构建基础容器

基于centos环境docker环境快速搭建,执行步骤

docker build -t cenosbase7 .

执行此步骤就可以构建1个基础的centos基础运行环境

相关的文件如下具体内容如下,其中有详细注释

 

Dockerfile

#Build image 包含了JDK mariadb sshd

#  docker build -t cenosbase7 .

#Run

#-v /sys/fs/cgroup:/sys/fs/cgroup:ro 必须加

# https://hub.docker.com/_/centos/ systemd enabled

# 带提示的启动

# docker run -ti -v /sys/fs/cgroup:/sys/fs/cgroup:ro --privileged=true --name csx cenosbase7

# 守护方式启动

# docker run -tid -v /sys/fs/cgroup:/sys/fs/cgroup:ro --privileged=true --name csx cenosbase7

#1503 not have systemd

#cat /etc/redhat_rlease 7.3

FROM centos:7

MAINTAINER cenosbase

USER root

#https://hub.docker.com/_/centos/

#systemd

# 7.1.1503, RUN yum clean all && yum swap fakesystemd systemd systemd没有安装

ENV container docker

RUN [ -d /lib/systemd/system/sysinit.target.wants ] && (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \

rm -f /lib/systemd/system/multi-user.target.wants/*;\

rm -f /etc/systemd/system/*.wants/*;\

rm -f /lib/systemd/system/local-fs.target.wants/*; \

rm -f /lib/systemd/system/sockets.target.wants/*udev*; \

rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \

rm -f /lib/systemd/system/basic.target.wants/*;\

rm -f /lib/systemd/system/anaconda.target.wants/*;

RUN yum install -y net-tools iproute lsof && \

 yum install -y vim-enhanced && \

 yum install -y sudo passwd && \

 yum install -y iptables && \

 yum install -y openssh.x86_64 openssh-server.x86_64 openssh-clients.x86_64 && \

 yum install -y java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-devel.x86_64 && \

 yum install -y mariadb-server.x86_64 mariadb.x86_64 && \

 yum install -y mysql-connector-java.noarch

#sshd and root

RUN ssh-keygen -q -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N ''  && \

 ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ''  && \

 ssh-keygen -t dsa -f /etc/ssh/ssh_host_ed25519_key  -N '' && \

 sed -i "s/#UsePrivilegeSeparation.*/UsePrivilegeSeparation no/g" /etc/ssh/sshd_config  && \

 sed -i "s/UsePAM.*/UsePAM no/g" /etc/ssh/sshd_config  && \

 sed -i "s/#Port.*/Port 23/g" /etc/ssh/sshd_config  && \

 echo "root:root" | chpasswd && systemctl enable mariadb.service && systemctl enable sshd.service

RUN /bin/echo -e "LANG=\"en_US.UTF-8\"" > /etc/default/local

#jdk

RUN ln -s /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141-1.b16.el7_3.x86_64 /usr/lib/jvm/jdk8

ENV JAVA_HOME /usr/lib/jvm/jdk8

ENV CLASSPATH .:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

ENV PATH $PATH:$JAVA_HOME/bin

RUN rm /usr/bin/java && ln -s $JAVA_HOME/bin/java /usr/bin/java

#supervisor

RUN rpm -Uvh  http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-10.noarch.rpm

RUN yum install -y supervisor

RUN mkdir -p /etc/supervisor/

COPY supervisord.conf /etc/supervisor/

#should use systemd

VOLUME [ "/sys/fs/cgroup" ]

#CMD /usr/sbin/init

COPY run.sh /

RUN chown root:root /run.sh && \

 chmod 700 /run.sh && yum clean all

#CMD supervisord -c /etc/supervisor/supervisord.conf

CMD /run.sh

EXPOSE 23

 

supervisord.conf

[unix_http_server]

file=/var/run/supervisor/supervisor.sock   ; (the path to the socket file)

[supervisord]

logfile=/var/run/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)

logfile_maxbytes=50MB        ; (max main logfile bytes b4 rotation;default 50MB)

logfile_backups=10           ; (num of main logfile rotation backups;default 10)

loglevel=info                ; (log level;default info; others: debug,warn,trace)

pidfile=/var/run/supervisor/supervisord.pid ; (supervisord pidfile;default supervisord.pid)

nodaemon=true               ; (start in foreground if true;default false)

minfds=1024                  ; (min. avail startup file descriptors;default 1024)

minprocs=200                 ; (min. avail process descriptors;default 200)

[rpcinterface:supervisor]

supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]

serverurl=unix:///var/run/supervisor/supervisor.sock ; use a unix:// URL  for a unix socket

[program:sshd]

command=/usr/sbin/sshd –D

 

run.sh

#!/bin/bash

echo "supervisord start..."

supervisord -c /etc/supervisor/supervisord.conf &

echo "init start..."

exec /usr/sbin/init

 

2 构建hive

基于上一个的镜像,可以构建hive的镜像

docker build -t centoshive .

 

Dockerfile

#docker build -t centoshive .

#参考了 https://github.com/sequenceiq/hadoop-docker

FROM cenosbase7

MAINTAINER centoshive

USER root

#.tar.gz会自动解压

#http://archive.apache.org/dist/hive/hive-1.1.0/apache-hive-1.1.0-bin.tar.gz

#http://archive.cloudera.com/cdh5/cdh/5/hadoop-2.6.0-cdh5.10.1.tar.gz

ADD pkg/apache-hive-1.1.0-bin.tar.gz /usr/local/

ADD pkg/hadoop-2.6.0-cdh5.10.1.tar.gz /usr/local/

#RUN ls -l /usr/local/

RUN cd /usr/local && ln -s ./hadoop-2.6.0-cdh5.10.1 hadoop && ln -s ./apache-hive-1.1.0-bin hive

ENV HADOOP_PREFIX=/usr/local/hadoop HADOOP_COMMON_HOME=/usr/local/hadoop HADOOP_HDFS_HOME=/usr/local/hadoop

ENV HADOOP_MAPRED_HOME /usr/local/hadoop

ENV HADOOP_YARN_HOME /usr/local/hadoop

ENV HADOOP_CONF_DIR /usr/local/hadoop/etc/hadoop

ENV YARN_CONF_DIR $HADOOP_PREFIX/etc/hadoop

RUN sed -i '/^export JAVA_HOME/ s:.*:export JAVA_HOME=/usr/lib/jvm/jdk8\nexport HADOOP_PREFIX=/usr/local/hadoop\nexport HADOOP_HOME=/usr/local/hadoop\n:' $HADOOP_PREFIX/etc/hadoop/hadoop-env.sh && \

 sed -i '/^export HADOOP_CONF_DIR/ s:.*:export HADOOP_CONF_DIR=/usr/local/hadoop/etc/hadoop/:' $HADOOP_PREFIX/etc/hadoop/hadoop-env.sh

#RUN . $HADOOP_PREFIX/etc/hadoop/hadoop-env.sh

RUN mkdir $HADOOP_PREFIX/input && \

 cp $HADOOP_PREFIX/etc/hadoop/*.xml $HADOOP_PREFIX/input

# pseudo distributed

ADD hadoop-cfg/core-site.xml.template $HADOOP_PREFIX/etc/hadoop/core-site.xml.template

RUN sed s/HOSTNAME/localhost/ /usr/local/hadoop/etc/hadoop/core-site.xml.template > /usr/local/hadoop/etc/hadoop/core-site.xml

ADD hadoop-cfg/hdfs-site.xml $HADOOP_PREFIX/etc/hadoop/hdfs-site.xml

ADD hadoop-cfg/mapred-site.xml $HADOOP_PREFIX/etc/hadoop/mapred-site.xml

ADD hadoop-cfg/yarn-site.xml $HADOOP_PREFIX/etc/hadoop/yarn-site.xml

RUN $HADOOP_PREFIX/bin/hdfs namenode -format

# fixing the libhadoop.so like a boss

ADD pkg/hadoop-native-64-2.7.1.tar.gz /usr/local/hadoop/lib/native

# workingaround docker.io build error

RUN chmod +x /usr/local/hadoop/etc/hadoop/*-env.sh

#ssh

ADD ssh_config /root/.ssh/config

RUN chmod 600 /root/.ssh/config

RUN chown root:root /root/.ssh/config

#ssh localhost不用登录

# passwordless ssh

RUN ssh-keygen -q -N "" -t dsa -f /etc/ssh/ssh_host_dsa_key

#RUN ssh-keygen -q -N "" -t rsa -f /etc/ssh/ssh_host_rsa_key

RUN ssh-keygen -q -N "" -t rsa -f /root/.ssh/id_rsa

RUN cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys

#hive

ENV HIVE_HOME /usr/local/hive

COPY hive/hive-site.xml /usr/local/hive/conf/.

COPY pkg/mysql-connector-java-5.1.38.jar /usr/local/hive/lib/.

ENV PATH $PATH:/usr/local/hive/bin

#daemon service

RUN mkdir -p /opt/daemon/ && rm -f /run.sh && rm -rf /etc/supervisor/

ADD svc/*.sh /opt/daemon/

COPY svc/*.ini /etc/supervisord.d/

RUN mkdir -p /opt/log && chown root:root /opt/daemon/*.sh && \

 chmod 700 /opt/daemon/*.sh

#

COPY svc/locale.conf /etc/

#RUN yum install -y kde-l10n-Chinese

#

CMD /opt/daemon/run.sh

# Hdfs ports

EXPOSE 50010 50020 50070 50075 50090 8020 9000

# Mapred ports

EXPOSE 10020 19888

#Yarn ports

EXPOSE 8030 8031 8032 8033 8040 8042 8088

#hive ports

EXPOSE 10000

 

其他依赖文件

https://gitee.com/wushifeng/hivedocker/attach_files/download?i=114939&u=http%3A%2F%2Ffiles.git.oschina.net%2Fgroup1%2FM00%2F02%2FC6%2FPaAvDFpfFtOASF8RABMYaUNwYdI5212.gz%3Ftoken%3D08896e8c3e9a49eed5c33d921bd52836%26ts%3D1516181203%26attname%3Dhive-docker.tar.gz  

上一篇:Json转换利器Gson之实例一-简单对象转化和带泛型的List转化 (转)


下一篇:Swift语法专题五——集合类型