大数据作业(一)基于docker的hadoop集群环境搭建


主要是根据厦门大学数据库实验室的教程( http://dblab.xmu.edu.cn/blog/1233/)在Ubuntu16.04环境下进行搭建。

一、安装docker(Docker CE)

根据docker官网教程(https://docs.docker.com/install/linux/docker-ce/ubuntu/)教程进行安装。
官方提供三种方式进行安装,一种是从docker仓库安装,还有一种方式是从安装包安装,最后一种就是使用脚本进行安装,我选择的是从docker仓库安装,这样方便以后更新docker。

(一)设置软件仓库

1、首先升级现有软件仓库,更新包

$ sudo apt update

2、然后安装以下所需软件:

$ sudo apt install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

3、添加docker的官方GPG

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

通过以下命令确定key值为9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88

$ sudo apt-key fingerprint 0EBFCD88

pub   4096R/0EBFCD88 2017-02-22
      Key fingerprint = 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid                  Docker Release (CE deb) <docker@docker.com>
sub   4096R/F273FCD8 2017-02-22

4、docker拥有stable、edge、test三个版本,其中stable为稳定版,所以选择安装稳定版

$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

(二)安装Docker CE

1、刷新一下软件源

$ sudo apt update

2、安装最新版本的Docker CE

$ sudo apt-get install docker-ce

3、验证是否安装成功

$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
d1725b59e92d: Pull complete 
Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

4、添加用户权限
由于docker默认只有root才能执行,所以还需要为当前用户添加权限

$ sudo usermod -aG docker zhangsl

然后注销系统之后再次登录,验证权限是否添加成功

$ docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

二、在docker中安装Ubuntu系统

首先是从docker hub上面拉取一个Ubuntu镜像

$ docker pull ubuntu

然后验证是否安装成功

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED          SIZE
hello-world         latest              4ab4c602aa5e        2 weeks ago   1.84kB
ubuntu              latest              cd6d8154f1e1        2 weeks ago   84.1MB

在启动镜像时,需要一个文件夹向镜像内部进行文件传输,所以在家目录下面新建一个文件用于文件传输

$ mkdir docker-ubuntu  

然后在docker上运行Ubuntu

$ docker run -it -v ~/docker-ubuntu:/root/docker-ubuntu --name ubuntu ubuntu
root@b59d716dbb4d:/# 

三、Ubuntu系统初始化

由于刚刚安装好之后的系统是纯净系统,很多软件都没有装,所以需要刷新一下软件源以及安装一些必要的软件。

(一)刷新源

由于在docker 上面运行的Ubuntu默认登录的为root用户,所以运行命令不需要sudo

root@b59d716dbb4d:/# apt update

(二)安装一些必要的软件

1、安装Vim
终端中用到的文本编辑器有vim、emacs、nano等,个人比较习惯vim,所以才选择vim

root@b59d716dbb4d:/# apt  install vim

2、安装sshd
由于分布式需要用ssh连接到docker内的镜像

root@b59d716dbb4d:/# apt  install ssh

然后在~/.bashrc内加入/etc/init.d/ssh start,保证每次启动镜像时都会自动启动ssh服务,也可以使用service或者systemctl设置ssh服务自动启动
然后就是配置ssh免密登录

root@b59d716dbb4d:~# ssh-keygen -t rsa #一直按回车键即可
root@b59d716dbb4d:~# cd .ssh
root@b59d716dbb4d:~/.ssh# cat id_dsa.pub >> authorized_keys

3、安装jdk
由于Hadoop需要Java,因此还需要安装jdk,由于默认的jdk为Java10,所以需要改成java8

root@b59d716dbb4d:~/# apt  install openjdk-8-jdk

接下来设置JAVA_HOMEPATH变量
只需要在~/.bashrc最后加入

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/
export PATH=$PATH:$JAVA_HOME/bin

然后使~/.bashrc生效

root@b59d716dbb4d:~/# source ~/.bashrc

(三)

  • 1
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值