安装Linux系统
这里以安装龙蜥操作系统AnolisOS8.9为例加以说明。
通过PVE后台上传操作系统ISO镜像。
然后在PVE上【创建虚拟机】,选定上传的龙蜥操作系统镜像进行系统安装。
注意:在安装过程中,要设定语言、时区、超管用户root的密码、普通用户k8s的账号和密码、内存、磁盘大小等参数。超管用户与普通用户的密码尽量保持一致,来回切换懒得匹配不同的密码。
安装好系统后,如果通过命令sudo su无法提升权限,需要把当前用户加入
# 切换root超管用户
su root# 编辑/etc/sudoers
vi /etc/sudoers# 然后在下面%wheel的下面添加一行,如安装操作系统时创建的普通用户为k8s,则添加%k8s这一行内容
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
%k8s ALL=(ALL) ALL
保存配置后退出。
为了加快服务器访问速度,还要配置域名解析文件。
编辑Dns解析配置文件,路径在/etc/resolv.conf。
# vi /etc/resolv.conf
search local
nameserver 211.xx.xx.xx # 域名服务器地址
配置静态IP
编辑网卡配置文件,这里的网卡使用ens18,配置文件在/etc/sysconfig/network-scripts/ifcfg-ens18。注意:不同系统路径可能有差别,根据实际使用的网卡及系统进行配置。
# vi /etc/sysconfig/network-scripts/ifcfg-ens18
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static # 静态IP方式
IPADDR=172.xx.xx.22 # 具体的IP
NETMASK=255.255.255.0
GATEWAY=172.xx.xx.1 # 网关,不一定为.1
DNS1=211.xx.xx.xx # DNS地址解析服务器DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=eui64
NAME=ens18
UUID=xx-xx-xx
DEVICE=ens18
ONBOOT=on # 静态网卡跟随系统一起启动
克隆虚拟机
克隆创建好的虚拟机,只需修改hosts和静态IP即可。
- 修改/etc/hosts中的hostname
- 修改静态IP
在/etc/sysconfig/network-scripts/ifcfg-ens18
安装基础包
安装wget包
[root@localhost soft]# yum install -y wget
Last metadata expiration check: 0:02:09 ago on Thu 09 Jan 2025 04:10:30 PM CST.
Dependencies resolved.
=========================================================================================================================================================================================Package Architecture Version Repository Size
=========================================================================================================================================================================================
Installing:wget x86_64 1.19.5-12.0.1.an8 AppStream 705 k
Installing dependencies:libmetalink x86_64 0.1.3-7.0.1.an8 BaseOS 30 kTransaction Summary
=========================================================================================================================================================================================
Install 2 PackagesTotal download size: 735 k
Installed size: 2.7 M
Downloading Packages:
(1/2): wget-1.19.5-12.0.1.an8.x86_64.rpm 136 kB/s | 705 kB 00:05
(2/2): libmetalink-0.1.3-7.0.1.an8.x86_64.rpm 4.1 kB/s | 30 kB 00:07
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 101 kB/s | 735 kB 00:07
AnolisOS-8 - AppStream 158 kB/s | 3.0 kB 00:00
Importing GPG key 0x4873F7C5:Userid : "Anolis OS <os@openanolis.org>"Fingerprint: F87D B652 2967 855E 986F 840C 6191 4008 4873 F7C5From : /etc/pki/rpm-gpg/RPM-GPG-KEY-ANOLIS
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transactionPreparing : 1/1 Installing : libmetalink-0.1.3-7.0.1.an8.x86_64 1/2 Installing : wget-1.19.5-12.0.1.an8.x86_64 2/2 Running scriptlet: wget-1.19.5-12.0.1.an8.x86_64 2/2 Verifying : wget-1.19.5-12.0.1.an8.x86_64 1/2 Verifying : libmetalink-0.1.3-7.0.1.an8.x86_64 2/2 Installed:libmetalink-0.1.3-7.0.1.an8.x86_64 wget-1.19.5-12.0.1.an8.x86_64 Complete!
[root@localhost soft]#
[root@localhost soft]# rpm -qa|grep "wget"
wget-1.19.5-12.0.1.an8.x86_64
[root@localhost soft]#
[root@localhost soft]# wget https://github.com/goharbor/harbor/releases/download/v2.12.1/harbor-offline-installer-v2.12.1.tgz
--2025-01-09 16:13:00-- https://github.com/goharbor/harbor/releases/download/v2.12.1/harbor-offline-installer-v2.12.1.tgz
Resolving github.com (github.com)...
20.205.243.166
Connecting to github.com (github.com)|20.205.243.166|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://objects.githubusercontent.com/github-production-release-asset-2e65be/50613991/806eb4e2-6da8-42f1-888f-29d44c0d9a96?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduction%2F20250109%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20250109T081305Z&X-Amz-Expires=300&X-Amz-Signature=f82138a7280433879a3ea8c62d5325709a734884ce732cb12f42415b7859eb29&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3B%20filename%3Dharbor-offline-installer-v2.12.1.tgz&response-content-type=application%2Foctet-stream [following]
--2025-01-09 16:13:06-- https://objects.githubusercontent.com/github-production-release-asset-2e65be/50613991/806eb4e2-6da8-42f1-888f-29d44c0d9a96?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduction%2F20250109%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20250109T081305Z&X-Amz-Expires=300&X-Amz-Signature=f82138a7280433879a3ea8c62d5325709a734884ce732cb12f42415b7859eb29&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3B%20filename%3Dharbor-offline-installer-v2.12.1.tgz&response-content-type=application%2Foctet-stream
Resolving objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.108.133, 185.199.111.133, 185.199.110.133, ...
Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.108.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 703617262 (671M) [application/octet-stream]
Saving to: ‘harbor-offline-installer-v2.12.1.tgz’harbor-offline-installer-v2.12.1.tgz 100%[=================================================================================================>] 671.02M 21.9MB/s in 29s 2025-01-09 16:13:35 (23.5 MB/s) - ‘harbor-offline-installer-v2.12.1.tgz’ saved [703617262/703617262][root@localhost soft]#
[root@localhost soft]#
[root@localhost soft]# ls -alh
total 672M
drwxrwxr-x 2 k8s k8s 50 Jan 9 16:13 .
drwx------. 3 k8s k8s 95 Jan 9 15:52 ..
-rw-r--r-- 1 root root 672M Dec 24 15:03 harbor-of
制作快照
对上面创建好的3台虚拟机初始环境创建快照,方便后面回滚使用初始安装的Linux系统重新部署新环境使用。
配置docker环境
更新yum源
更新软件源中的包。
yum update
安装底层工具
yum install -y yum-utils device-mapper-persistent-data lvm2
添加阿里云仓库
# 添加阿里云的docker镜像仓库
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
刷新源信息
yum makecache --timer
下载docker-ce
使用yum -y install docker-ce docker-ce-cli containerd.io
命令安装docker相关资源包,更新龙蜥8.9的软件园后,安装的docker版本呢是26.1.3,还是比较新的。
[root@localhost harbor]# yum -y install docker-ce docker-ce-cli containerd.io
Docker CE Stable - x86_64 6.3 kB/s | 66 kB 00:10
Dependencies resolved.
=========================================================================================================================================================================================Package Architecture Version Repository Size
=========================================================================================================================================================================================
Installing:containerd.io x86_64 1.6.32-3.1.el8 docker-ce-stable 35 Mdocker-ce x86_64 3:26.1.3-1.el8 docker-ce-stable 27 Mdocker-ce-cli x86_64 1:26.1.3-1.el8 docker-ce-stable 7.8 M
Installing dependencies:container-selinux noarch 2:2.229.0-2.module+an8.9.0+11261+8fb088a9 AppStream 70 kfuse-common x86_64 3.3.0-19.an8 BaseOS 21 kfuse-overlayfs x86_64 1.13-1.0.1.module+an8.9.0+11261+8fb088a9 AppStream 69 kfuse3 x86_64 3.3.0-19.an8 BaseOS 54 kfuse3-libs x86_64 3.3.0-19.an8 BaseOS 95 klibcgroup x86_64 2.0-1.0.1.an8 BaseOS 78 klibslirp x86_64 4.4.0-2.module+an8.9.0+11257+d476ec85 AppStream 69 kslirp4netns x86_64 1.2.3-1.module+an8.9.0+11261+8fb088a9 AppStream 55 k
Installing weak dependencies:docker-buildx-plugin x86_64 0.14.0-1.el8 docker-ce-stable 14 Mdocker-ce-rootless-extras x86_64 26.1.3-1.el8 docker-ce-stable 5.0 Mdocker-compose-plugin x86_64 2.27.0-1.el8 docker-ce-stable 13 M
Enabling module streams:container-tools an8
验证docker是否安装成功
[root@localhost harbor]# docker -v
Docker version 26.1.3, build b72abbb
展示出具体的docker版本,即说明docker安装成功。
组建k8s集群
敬请关注后续文章。
参考
龙蜥Linux系统部署docker21.1.3版本
手把手教你搭建Docker私有仓库Harbor
Docker部署私有仓库(registry&Harbor)
内网环境下离线安装Docker
Anolis8.8安装docker-ce
自建Docker镜像加速服务,基于官方 registry 一键部署Docker、K8s、Quay、Ghcr、Mcr、elastic、nvcr等镜像加速/管理服务
Docker/DockerHub 国内镜像源/加速列表(1月6日更新-长期维护)