搭建大数据技能竞赛比赛环境容器docker模块A
搭建大数据平台docker
Docker指定版本安装,docker 20.10
搭建大数据技能竞赛比赛环境容器docker模块A
IP规划
宿主机(centos7.9 min) | master(容器) | slave1(容器) | slave2(容器) |
---|---|---|---|
192.168.100.100 | 192.168.100.101 | 192.168.100.102 | 192.168.100.103 |
VM 2C_2G_50G |
系统配置
配置yum源
更换国内阿里云yum源
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
安装需要的依赖软件包
yum install -y yum-utils device-mapper-persistent-data lvm2 wget perl
下载阿里云docker-ce仓库
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
查看选择docker-ce各版本
yum list docker-ce --showduplicates
安装docker
安装指定版本的docker-ce-20.10.20
yum install -y docker-ce-20.10.20 docker-ce-cli-20.10.20 containerd.io
查看版本
docker -v
配置镜像加速
创建docker目录
mkdir /etc/docker
配置文件
cat >/etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["https://docker.udayun.com"]
}
EOF
重载配置
systemctl daemon-reload
重启docker
systemctl restart docker
设置开机自启
systemctl enable docker
构建镜像bigdata
拉取镜像
docker pull centos:7.9.2009
查看镜像
docker image list
编写Dockerfile
vi Dockerfile
FROM centos:7.9.2009
RUN mkdir -p /opt/software && mkdir -p /opt/module
#更换国内阿里云yum源
RUN curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
RUN sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
RUN yum makecache
#安装语言包
RUN yum -y install kde-l10n-Chinese glibc-common vim
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
RUN echo "LANG=zh_CN.UTF-8" >> /etc/locale.conf
#安装sshd
RUN yum install -y openssh-server openssh-clients vim net-tools lrzsz
RUN sed -i '/^HostKey/'d /etc/ssh/sshd_config
RUN echo 'HostKey /etc/ssh/ssh_host_rsa_key' >> /etc/ssh/sshd_config
#生成ssh-key
RUN ssh-keygen -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key
#更改root用户登录密码
RUN echo 'root:123456' | chpasswd
#声明22端口
EXPOSE 22
CMD [ "/usr/sbin/init"]
构建镜像
docker build -t bigdata:1.0 ./
创建网络
docker network create -d ipvlan --subnet 192.168.100.0/24 --gateway 192.168.100.2 -o ipvlan_mode=l2 -o parent=ens33 ipvlan
ens33是你的系统网卡
显示报错
Error response from daemon: kernel version failed to meet the minimum ipvlan kernel requirement of 4.2, found 3.10.0
解决报错:升级内核
下载文件
wget http://mirrors.coreix.net/elrepo-archive-archive/kernel/el7/x86_64/RPMS/kernel-lt-5.4.226-1.el7.elrepo.x86_64.rpm
安装内核
rpm -ivh kernel-lt-5.4.226-1.el7.elrepo.x86_64.rpm
查看启动内核
rpm -qa | grep kernel
回显
kernel-3.10.0-1160.el7.x86_64
kernel-tools-3.10.0-1160.el7.x86_64
kernel-tools-libs-3.10.0-1160.el7.x86_64
kernel-lt-5.4.226-1.el7.elrepo.x86_64
kernel-lt-headers-5.4.226-1.el7.elrepo.x86_64
kernel-lt-devel-5.4.226-1.el7.elrepo.x86_64
设置启动内核
查看启动顺序
cat /etc/grub2.cfg | grep menuentry|awk -F "\'" '$1=="menuentry " {print i++ " : " $2}'
0 : CentOS Linux (5.4.226-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-1160.119.1.el7.x86_64) 7 (Core)
2 : CentOS Linux (3.10.0-1160.el7.x86_64) 7 (Core)
3 : CentOS Linux (0-rescue-89ca0c0544ae4eabb7417e2850f8025d) 7 (Core)
设置启动顺序
grub2-set-default 0
重启生效
reboot
创建ipvlan网络
docker network create -d ipvlan --subnet 192.168.100.0/24 --gateway 192.168.100.2 -o ipvlan_mode=l2 -o parent=ens33 ipvlan
创建容器master、slave1、slave2
docker create -it --name master --privileged=true --network ipvlan --ip 192.168.100.101 -h master bigdata:1.0 /usr/sbin/init
docker create -it --name slave1 --privileged=true --network ipvlan --ip 192.168.100.102 -h slave1 bigdata:1.0 /usr/sbin/init
docker create -it --name slave2 --privileged=true --network ipvlan --ip 192.168.100.103 -h slave2 bigdata:1.0 /usr/sbin/init
查看容器
[root@Bigdata ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ecf92ac8a10c bigdata:1.0 "/usr/sbin/init" 8 seconds ago Created slave2
742f93c9c67a bigdata:1.0 "/usr/sbin/init" 10 seconds ago Created slave1
c93a42a85908 bigdata:1.0 "/usr/sbin/init" 14 seconds ago Created master
启动容器
[root@Bigdata ~]# docker start master
master
[root@Bigdata ~]# docker start slave1
slave1
[root@Bigdata ~]# docker start slave2
slave2
测试
[root@Bigdata ~]# docker exec -it master /bin/bash
[root@master /]# cd
[root@master ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.101 netmask 255.255.255.0 broadcast 192.168.100.255
ether 00:0c:29:8e:f3:76 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
测试网络连通性
[root@master ~]# ping www.baidu.com
PING www.a.shifen.com (157.148.69.74) 56(84) bytes of data.
64 bytes from 157.148.69.74 (157.148.69.74): icmp_seq=1 ttl=128 time=22.9 ms
^C
--- www.a.shifen.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 22.934/22.934/22.934/0.000 ms
[root@master ~]# ping 192.168.100.102
PING 192.168.100.102 (192.168.100.102) 56(84) bytes of data.
64 bytes from 192.168.100.102: icmp_seq=1 ttl=64 time=0.154 ms
64 bytes from 192.168.100.102: icmp_seq=2 ttl=64 time=0.125 ms
^C
--- 192.168.100.102 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1029ms
rtt min/avg/max/mdev = 0.125/0.139/0.154/0.018 ms
[root@master ~]# ping 192.168.100.103
PING 192.168.100.103 (192.168.100.103) 56(84) bytes of data.
64 bytes from 192.168.100.103: icmp_seq=1 ttl=64 time=0.169 ms
^C
--- 192.168.100.103 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.169/0.169/0.169/0.000 ms
原文地址:https://blog.csdn.net/weixin_62687791/article/details/143862797
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!