一、环境准备
VM网络配置
- 打开VMware软件 --编辑 --虚拟网络编辑器
二、VM创建虚拟机
三、安装rhel8.9操作系统
1、rhel8.9 镜像下载
- 第一步:进入redhat官网进行注册
- 第二步:下载rhel8.9镜像文件 https://access.redhat.com/downloads/content/rhel
2、操作系统安装
- 第一步:打开虚拟机设置,设置虚拟光驱指定镜像iso文件
- 第二步:安装 :启动虚拟机,选择第一个安装
- 安装语言,English
- 配置四个选项: - 安装目的地:默认- 时区:亚洲 -上海- 软件选择:最小化安装- Root 密码: 123456
3、系统-网络配置
- 第一步:网卡ip地址配置 IP : 10.0.0.2子网: 255.255.255.0网关: 10.0.0.254
编辑网卡配置文件
# vi /etc/sysconfig/network-scripts/网卡文件
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
NAME=网卡名称
DEVICE=网卡名称
ONBOOT=yes
IPADDR=10.0.0.2
NETMASK=255.255.255.0
GATEWAY=10.0.0.254重启网络管理服务
# systemctl restart NetworkManager
- 第二步:系统dns配置
# cat > /etc/resolv.conf << EOF
nameserver 223.5.5.5
nameserver 114.144.114.114
EOF验证
# ping www.baidu.com第三步:使用xshell工具远程连接
- 第三步:使用xshell工具远程连接
四、系统-基本配置
1、禁用防火墙与SELinux
关闭firewalld
# systemctl disable firewalld --now检查确认关闭
# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor
preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)关闭SELinux
# sed -i.bak 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config验证
# grep SELINUX=disabled /etc/selinux/config
SELINUX=disabled命令行更改
# setenforce 0验证
# getenforce
Permissive
2、设置主机名
[root@localhost ~]# hostnamectl set-hostname docker-a
[root@localhost ~]# bash
[root@docker-a ~]#
3、系统语言配置
[root@docker-a ~]# localectl set-locale LANG="en_US.UTF-8"
[root@docker-a ~]# echo 'export LANG=en_US.UTF-8' >> /etc/profile
检查确认
[root@docker-a ~]# echo $LANG
en_US.UTF-8
4、本地yum源仓库配置:
# rm -f /etc/yum.repos.d/*# cat >> /etc/yum.repos.d/local.repo <<EOF
[BaseOS]
name=BaseOS
baseurl=file:///mnt/BaseOS
gpgcheck=0
enabled=1
[AppStream]
name=AppStream
baseurl=file:///mnt/AppStream
gpgcheck=0
enabled=1
EOF# 挂载前,先确保CD/DVD是已连接状态
# mount /dev/cdrom /mnt
mount: /dev/sr0 is write-protected, mounting read-only# yum clean all && yum makecache开机自启
# echo '/dev/cdrom /mnt iso9660 loop 0 0' >> /etc/fstab
5、安装常用软件:
# yum install vim lrzsz tree nc telnet wget lsof chrony bash-completion tcpdump psmisc sysstat net-tools unzip -y
6、配置与阿里时钟服务器同步:
# cat > /etc/chrony.conf << EOF
# 把这一行代码加入即可server ntp.aliyun.com iburststratumweight 0
driftfile /var/lib/chrony/drift
rtcsync
makestep 10 3
bindcmdaddress 127.0.0.1
bindcmdaddress ::1
keyfile /etc/chrony.keys
commandkey 1
generatecommandkey
logchange 0.5
logdir /var/log/chrony
EOF启动chronyd服务
# systemctl enable chronyd --now
验证# chronyc sources
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* 203.107.6.88 2 6 37 8 +79us[ -123ms] +/- 33ms
7、额外添加一块数据盘:10G
第一步:VM中虚拟机添加一块10G硬盘
重启虚拟机
# reboot
查看新添加的硬盘# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 39G 0 part
├─rhel-root 253:0 0 37G 0 lvm /
└─rhel-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 10G 0 disk
sr0 11:0 1 12.6G 0 rom第二步:系统里格式化并挂载至/app
# mkfs.xfs /dev/sdb
# mkdir /app
# echo '/dev/sdb /app xfs defaults 0 0' >> /etc/fstab
# mount -a
# systemctl daemon-reload验证:确保已挂载
# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 848M 0 848M 0% /dev
tmpfs 868M 0 868M 0% /dev/shm
tmpfs 868M 8.7M 859M 1% /run
tmpfs 868M 0 868M 0% /sys/fs/cgroup
/dev/mapper/rhel-root 37G 2.1G 35G 6% /
/dev/sda1 1014M 229M 786M 23% /boot
tmpfs 174M 0 174M 0% /run/user/0
/dev/sdb 10G 104M 9.9G 2% /app
五、安装Docker
阿里镜像站: https://developer.aliyun.com/mirror/
1、关闭swap
命令行关闭
# swapoff -a关闭开机自启
# 注释/etc/fstab中的swap行
# cat /etc/fstab
/dev/mapper/rhel-root / xfs defaults 0 0
UUID=c2d190de-00f5-4c47-bded-7c4e71663caa /boot xfs
defaults 0 0# /dev/mapper/rhel-swap none swap defaults 0 0
/dev/sdb /app
2、 安装
卸载docker
# sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine安装必要的一些系统工具
# sudo yum install -y yum-utils device-mapper-persistent-data lvm2添加阿里软件源信息
# sudo yum-config-manager --add-repo https://mirrors.aliyun.com/dockerce/linux/centos/docker-ce.repo
# sudo sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+'
/etc/yum.repos.d/docker-ce.repo更新并安装Docker-CE
# sudo yum makecache
# sudo yum -y install docker-ce开启Docker服务,并设置自启
# sudo systemctl enable docker --now
3、 Docker验证
# docker version
Client: Docker Engine - Community
Version: 25.0.3
API version: 1.44
Go version: go1.21.6
Git commit: 4debf41
Built: Tue Feb 6 21:15:16 2024
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 25.0.3
API version: 1.44 (minimum version 1.24)
Go version: go1.21.6
Git commit: f417435
Built: Tue Feb 6 21:14:12 2024
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.28
GitCommit: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
runc:
Version: 1.1.12
GitCommit: v1.1.12-0-g51d5e94
docker-init:
Version: 0.19.0
GitCommit: de40ad0
4、验证运行helloworld镜像
# sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:d000bc569937abbe195e20322a0bde6b2922d805332fd6d8a68b19f524b7d21d
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/
5、验证运行一个Ubuntu容器,并打印出当前系统时间
# docker run -it ubuntu bash