前言,最近在系统学习k8s,考虑到centos已经不维护了,现在选择下载rockylinux进行部署测试,首先在阿里云镜像下载rokylinux,最新版本9.4考虑到解决方案的丰富性,我选择使用前两个版本。
阿里云镜像地址:
https://mirrors.aliyun.com/rockylinux-vault/9.2/isos/x86_64/下载好之后要在本地虚拟机上查看主机地址并且修改rocky Linux的ip为固定ip,具体参数如下:
[connection]
id=ens160
uuid=e2e2663c-1008-33f7-9e34-09502ff2978c
type=ethernet
autoconnect-priority=-999
interface-name=ens160
timestamp=1726128865
[ethernet]
[ipv4]
method=manual
address1=192.168.159.91/24
[ipv6]
addr-gen-mode=eui64
method=auto
[proxy]
一、配置初始系统设置
标准安装步骤:先换源
sed -e 's|^mirrorlist=|#mirrorlist=|g' -e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g' -i.bak /etc/yum.repos.d/[Rr]ocky*.repo
dnf makecache #dnf底层也是调用yum包进行安装
# 防火墙修改 firewalld 为 iptables
systemctl stop firewalld
systemctl disable firewalld
yum -y install iptables-services
#开启iptables的用户态
systemctl start iptables
#查找iptables的默认规则
iptables -L
#清空iptables的默认规则
iptables -F
#保存空规则为持久化文件
service iptables save
#开启开机自启
systemctl enable iptables
#直到出现 Created symlink /etc/systemd/system/multi-user.target.wants/iptables.service → /usr/lib/systemd/system/iptables.service. 至此防火墙设置成功
# 禁用 Selinux
#临时关闭Selinux
setenforce 0
#永久关闭Selinux
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config#此命令意为修改/etc/selinux/config配置文件将当前文件下的SELINUX=enforcing 改成SELINUX=disabled
#此外还要更改内核信息,将selinux=0,这样重启后selinux就是关闭状态。
grubby --update-kernel ALL --args selinux=0
# 查看是否禁用,grubby --info DEFAULT
# 回滚内核层禁用操作,grubby --update-kernel ALL --remove-args selinux
# 设置时区
timedatectl set-timezone Asia/Shanghai
至此一阶段修改后的纯净系统就已经完成,后续其他复制可以基于该快照进行克隆二、安装docker
# 加载 bridge
#epel源是为了给bridge-utils提供源支持
yum install -y epel-release
yum install -y bridge-utils
#modprobe br_netfilter 加载br_netfilter模块,该模块是经过网桥的流量都经过防火墙处理。
modprobe br_netfilter
#将br_netfilter模块添加至开机自启中
echo 'br_netfilter' >> /etc/modules-load.d/bridge.conf
#ipv4下的所有网桥的流量都要被网桥所回调
echo 'net.bridge.bridge-nf-call-iptables=1' >> /etc/sysctl.conf
#ipv6下的所有网桥的流量都要被网桥所回调
echo 'net.bridge.bridge-nf-call-ip6tables=1' >> /etc/sysctl.conf
#开启ipv4的路由转发
echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf
sysctl -p
#出现以下字符即为生效
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
# 添加 docker-ce yum 源 中科大(ustc)
dnf config-manager --add-repo https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo
#如果添加错误:通过dnf repolist 查询repo id 然后通过dnf config-manager --set-disable repository 禁用
dnf config-manager --set-disable mirrors.ustc.edu.cn_dockece_linux_centos_docker-ce.repor
cd /etc/yum.repos.d
# 切换中科大源
sed -e 's|download.docker.com|mirrors.ustc.edu.cn/docker-ce|g' docker-ce.repo
#将结果保存到docker-ce-ustc.repo
sed -e 's|download.docker.com|mirrors.ustc.edu.cn/docker-ce|g' docker-ce.repo > docker-ce-ustc.repo
20240912更
# 添加 docker-ce yum 源 清华(ustc)
dnf config-manager --add-repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
cd /etc/yum.repos.d
#将结果保存到docker-ce-tuna.repo
sed -e 's|download.docker.com|mirrors.tuna.tsinghua.edu.cn/docker-ce|g' docker-ce.repo > docker-ce-tuna.repo
# 安装 docker-ce
yum -y install docker-ce
# 配置 daemon.
cat > /etc/docker/daemon.json <<EOF
{
"data-root": "/data/docker",
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "100"
},
"insecure-registries": ["harbor.xinxainghf.com"],
"registry-mirrors": [
"https://do.nark.eu.org",
"https://dc.j8.work",
"https://docker.m.daocloud.io",
"https://dockerproxy.com",
"https://docker.mirrors.ustc.edu.cn",
"https://docker.nju.edu.cn"
]
}
EOF
mkdir -p /etc/systemd/system/docker.service.d
# 重启docker服务
systemctl daemon-reload && systemctl restart docker && systemctl enable docker
报错
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xeu docker.service" for details.
尝试一:
cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": [
"https://do.nark.eu.org",
"https://dc.j8.work",
"https://docker.m.daocloud.io",
"https://dockerproxy.com",
"https://docker.mirrors.ustc.edu.cn",
"https://docker.nju.edu.cn"
]
}
EOF无效
尝试方法二:
生效
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": [
"https://do.nark.eu.org",
"https://dc.j8.work",
"https://docker.m.daocloud.io",
"https://dockerproxy.com",
"https://docker.mirrors.ustc.edu.cn",
"https://docker.nju.edu.cn"
]
}
EOF更改源文件
sudo mkdir -p /etc/docker
•
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"data-root": "/data/docker",
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "100"
},
"insecure-registries": ["harbor.xinxainghf.com"],
"registry-mirrors": [
"https://do.nark.eu.org",
"https://dc.j8.work",
"https://docker.m.daocloud.io",
"https://dockerproxy.com",
"https://docker.mirrors.ustc.edu.cn",
"https://docker.nju.edu.cn"
]
}
EOF
•
sudo systemctl daemon-reload
sudo systemctl restart dockerps:是缩进问题,只要是一行一行添加就不会有错误
配置解释:
{
指定当前的ipc的模式是允许共享的
"default-ipc-mode": "shareable"
指定当前的docker的根目录在哪,默认在var/lib/docker目录下
"data-root": "/data/docker",
指定当前的一些启动的额外参数,比如cgroup驱动为systemd
"exec-opts": ["native.cgroupdriver=systemd"],
指定当前的日志驱动为json-file 保存为json格式
"log-driver": "json-file",
"log-opts": {
单文件的最大大小
"max-size": "100m",
保存最大文件数量
"max-file": "100"
},
当前信任的仓库地址
"insecure-registries": ["harbor.xinxainghf.com"],
当前的镜像仓库地址
"registry-mirrors": [
"https://do.nark.eu.org",
"https://dc.j8.work",
"https://docker.m.daocloud.io",
"https://dockerproxy.com",
"https://docker.mirrors.ustc.edu.cn",
"https://docker.nju.edu.cn"
]
}
至此docker安装完成,配置快照installdocker
评论区