虚拟化及容器_课上实验
实验1
下载使用虚拟机
然后快照回溯到init
网络:
推荐改为NAT模式:
开机就好啦
实验1 安装和使用Docker
登录名:
root
openstack
步骤1、2 关闭防火墙和SELinux
systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld
# 关闭SELinux
setenforce 0
# i 进入输入模式,ESC+:wq 退出编辑模式
vi /etc/selinux/config
把SELINUX 改为:SELINUX=disabled
步骤3 修改网卡配置信息
可能更简单方法
nmtui
改信息:
改成自动然后删掉IP
【俩ESC】
reboot
登录后输入
ip addr
这个就是IP地址啦
修改DNS
vi /etc/sysconfig/network-scripts/ifcfg-ens33
加入DNS1=114.114.114.114
重启下网络
测试与外网的连通性。
[root@node-a ~]# ping -c 4 www.sina.com.cn
PING ww1.sinaimg.cn.w.alikunlun.com (27.221.120.196) 56(84) bytes of data.
64 bytes from 27.221.120.196 (27.221.120.196): icmp_seq=1 ttl=128 time=1.07 ms
64 bytes from 27.221.120.196 (27.221.120.196): icmp_seq=2 ttl=128 time=0.348 ms
64 bytes from 27.221.120.196 (27.221.120.196): icmp_seq=3 ttl=128 time=0.553 ms
64 bytes from 27.221.120.196 (27.221.120.196): icmp_seq=4 ttl=128 time=0.449 ms
--- ww1.sinaimg.cn.w.alikunlun.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 4015ms
rtt min/avg/max/mdev = 0.348/0.606/1.074/0.279 ms
[root@node-a ~]#
SSH连接
在cmd里
ssh root@192.168.59.128 (这里是你的ip)
输入yes
4.更新yum仓库信息
yum -y update
5. 配置时间同步
yum –y install ntpdate
ntpdate ntp.aliyun.com
6 7 8. 安装docker
yum remove docker docker-common docker-selinux docker-engine
yum install -y yum-utils device-mapper-persistent-data lvm2
# 中科大镜像源
yum-config-manager --add-repo http://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
选择并且安装
yum list docker-ce --showduplicates | sort -r
``
安装
yum install –y docker-ce.x86_64 3:24.0.6-1.el7
![](https://cmd.dayi.ink/uploads/upload_a654c8e4ce819f4d5d481ee944fe23fb.png)
![](https://cmd.dayi.ink/uploads/upload_3dca66f686398038d50b9bf533f008c7.png)
### 11.开机自启、开机启动
systemctl start docker
systemctl enable docker
![](https://cmd.dayi.ink/uploads/upload_374bc6ff87835c737c063161c599b027.png)
### 12. 查看docker进程
ps -ef | grep docker
docker version
![](https://cmd.dayi.ink/uploads/upload_5b36fbc33e369422a852b053eedab946.png)
[root@node-a ~]# ps -ef | grep docker
root 2024 1 0 15:29 ? 00:00:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root 2171 1452 0 15:30 pts/0 00:00:00 grep --color=auto docker
[root@node-a ~]# docker version
Client: Docker Engine - Community
Version: 24.0.6
API version: 1.43
Go version: go1.20.7
Git commit: ed223bc
Built: Mon Sep 4 12:35:25 2023
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 24.0.6
API version: 1.43 (minimum version 1.12)
Go version: go1.20.7
Git commit: 1a79695
Built: Mon Sep 4 12:34:28 2023
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.24
GitCommit: 61f9fd88f79f081d64d6fa3bb1a0dc71ec870523
runc:
Version: 1.1.9
GitCommit: v1.1.9-0-gccaecfc
docker-init:
Version: 0.19.0
GitCommit: de40ad0
[root@node-a ~]#
### 12.镜像加速器
vi /etc/docker/daemon.json
i 输入
ESC -> :wq 保存
{
"registry-mirrors": ["https://x3n9jrcg.mirror.aliyuncs.com"]
}
![](https://cmd.dayi.ink/uploads/upload_83185599d7289864d5da05dc792fe0bb.png)
### 13. 重启docker
[root@node-a ~]# systemctl daemon-reload
[root@node-a ~]#
[root@node-a ~]# systemctl restart docker
[root@node-a ~]#
![](https://cmd.dayi.ink/uploads/upload_6c5bc74d6a968102224245487a28d5d8.png)
### 14. 下载镜像以便于测试
docker run -dit -p 80:80 nginx:latest
![](https://cmd.dayi.ink/uploads/upload_5a55d20f185bce2cb0d635832eb351f5.png)
打开网页测试:
![](https://cmd.dayi.ink/uploads/upload_d487078c811d28840d7c12c5a7a53ac6.png)