月度归档:2022年07月

CentOS 离线安装 docker

一、引言

生产环境中,很多时候都无法访问互联网,如何安装 docker 服务,官方推荐使用编译好的二进制包方案。本文以 CentOS 7 为例

二、先决条件

  • 64 位安装
  • 版本 3.10 或更高版本的 Linux 内核, 建议使用适用于您的平台的最新版本的内核
  • iptables 1.4 或更高版本
  • git 版本 1.7 或更高版本
  • ps 可执行文件,通常由 procps 或类似包提供
  • XZ Utils 4.9 或更高版本
  • 正确安装的 cgroupfs 层次结构

三、让我们开始吧

1.下载(官方安装包在这里
$ curl -LO https://download.docker.com/linux/static/stable/x86_64/docker-20.10.17.tgz
2.解压
$ tar -zxvf docker-20.10.17.tgz
3.移动二进制可执行文件至 /usr/bin 【官方推荐的 executable path, 一定要在这里,否则可能在 systemd 执行中有些问题】
$ sudo cp docker/* /usr/bin
4.编辑守护进程启动文件 /etc/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
  
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/docker/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
  
[Install]
WantedBy=multi-user.target
5.重载守护进程文件
$ systemctl daemon-reload
6.加入开机自启
$ systemctl enable docker.service

PVE 开启硬件直通功能

敲黑板:一定要结合自己的实际硬件配置,再进行操作。

一、环境介绍

  • 主板:ASUS PRIME B250M-PLUS
  • CPU:Intel Pentium G4600

二、让我们开始吧

1.主板开启 VT-X

  • 重启电脑,进入 BIOS(Dell 或者 F2)
  • 按 F7,进入“Advanced Mode”——“Advanced(高级)”——“CPU Configuration(CPU设置)”——拉到最底部找到“Intel Virtual Technology(虚拟化技术)”选项,把“Disabled(禁用)”修改为“Enabled(启用)”
  • 按 F10 保存并退出

2.开启 iommu

# 编辑grub
vi /etc/default/grub

# 注释并修改 GRUB_CMDLINE_LINUX_DEFAULT
GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on iommu=pt"

# 退出保存(按下 ESC,打开大写键,输入 ZZ)

# 更新 grub
update-grub

3.加载相应内核模块

# 加载模块
echo vfio >> /etc/modules
echo vfio_iommu_type1 >> /etc/modules
echo vfio_pci >> /etc/modules
echo vfio_virqfd >> /etc/modules

# 更新内核参数
update-initramfs -k all -u

# 重启服务器
reboot

4.验证是否开启 iommu

# 验证是否开启 iommu
dmesg | grep iommu

# 出现以下,则表示成功
[ 0.329978] iommu: Default domain type: Translated 
[ 1.341100] pci 0000:00:00.0: Adding to iommu group 0
[ 1.341116] pci 0000:00:01.0: Adding to iommu group 1
[ 1.341126] pci 0000:00:02.0: Adding to iommu group 2
[ 1.341137] pci 0000:00:14.0: Adding to iommu group 3
[ 1.341146] pci 0000:00:17.0: Adding to iommu group 4