本篇文章是基于Docker搭建大数据集群系列的开篇之作
yum install -y yum-utils #安装工具包,缺少这些依赖将无法完成
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce
systemctl start docker
docker version
docker run hello-world
docker pull centos
docker imsages
docker network create --subnet=172.15.0.0/16 netgroup
--name 容器名称
-h 容器主机名
--net 设置网桥
--ip 指定容器IP
master
docker run -d --privileged -ti -v /sys/fs/cgroup:/sys/fs/cgroup --name cluster-master -h cluster-master --net netgroup --ip 172.15.0.2 centos /usr/sbin/init
slave1
docker run -d --privileged -ti -v /sys/fs/cgroup:/sys/fs/cgroup --name cluster-slave1-h cluster-slave1--net netgroup --ip 172.15.0.3 centos /usr/sbin/init
slave2
docker run -d --privileged -ti -v /sys/fs/cgroup:/sys/fs/cgroup --name cluster-slave2-h cluster-slave2--net netgroup --ip 172.15.0.4 centos /usr/sbin/init
slave3
docker run -d --privileged -ti -v /sys/fs/cgroup:/sys/fs/cgroup --name cluster-slave3-h cluster-slave3--net netgroup --ip 172.15.0.5 centos /usr/sbin/init
docker ps
docker pa -a
docker run 容器名或容器ID
docker run exec -ti 容器名或容器ID bash
#安装VIM编辑工具
yum install vim
vim /etc/hosts
#追加以下内容
172.15.0.2 cluster-master
172.15.0.3 cluster-slave1
172.15.0.4 cluster-slave2
172.15.0.5 cluster-slave3
#将配置文件发送到其它节点
scp /etc/hosts cluster-slave1:/etc/
scp /etc/hosts cluster-slave2:/etc/
scp /etc/hosts cluster-slave3:/etc/
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum -y install openssh openssh-server openssh-clients
systemctl start sshd
敲出下面命令后连续回车三次
ssh-keygen -t rsa
passwd root
在所有结点都生成密钥之后再进行这步
master
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-master
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-slave1
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-slave2
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-slave3
slave1
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-master
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-slave1
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-slave2
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-slave3
slave2
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-master
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-slave1
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-slave2
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-slave3
slave3
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-master
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-slave1
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-slave2
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-slave3
第一次敲下面命令时,会向你询问,直接打
yes
,然后输入对应主机的访问密码第二次敲
ssh
命令时,应当直接能够访问,无需输入密码退出当前用户使用命令
exit
master
ssh cluster-master
ssh cluster-slave1
ssh cluster-slave1
ssh cluster-slave1
slave1
ssh cluster-master
ssh cluster-slave1
ssh cluster-slave1
ssh cluster-slave1
slave2
ssh cluster-master
ssh cluster-slave1
ssh cluster-slave1
ssh cluster-slave1
slave3
ssh cluster-master
ssh cluster-slave1
ssh cluster-slave1
ssh cluster-slave1
docker commit -m '提交文字说明' -a '作者' 容器名 提交后的镜像名:提交后的镜像tag名
https://hub.docker.com/
docker tag 镜像id 要推入的仓库的用户名/要推入的仓库名:新定义的tag
docker push 要推入的仓库的用户名/要推入的仓库名:镜像标签