更新 APT 包索引:sudo apt-get update
安装用于验证包的包:sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
添加 Docker 的官方 GPG 公钥:curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add –
验证公钥的指纹是否匹配:sudo apt-key fingerprint 0EBFCD88
添加 Docker 的稳定版本仓库:sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable”
添加阿里云的Docker仓库地址:sudo add-apt-repository “deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable”
再次更新 APT 包索引:sudo apt-get update
尝试重新安装 Docker:sudo apt-get install docker-ce
安装docker-compose: apt install docker-compose
挂载数据盘:
- fdisk -l 查看磁盘状态
- df -h 查询服务器硬盘使用情况
- 将dev/vdb 数据盘分区并挂载 :进入主目录上 cd 回车 执行 fdisk /dev/vdb 进行分区 操作分别为 n、p、1、回车、回车、wq
- 格式化分区:mkfs.ext4 /dev/vdb1
- 根目录 cd /
- 创建文件夹 mkdir -p mesdata
- 挂载mount /dev/vdb1 /mesdata
- 重启自动挂载设置 1,获取新分区的UUID :blkid (找到
/dev/vdb1
的行,记下UUID) 2,编辑/etc/fstab
以添加自动挂载:sudo nano /etc/fstab 在文件末尾添加一行UUID=your-uuid /mesdata ext4 defaults 0 2
docker 设置:vim /etc/docker/daemon.json
{
“registry-mirrors”:[“https://registry.docker-cn.com”,”https://q59d4unt.mirror.aliyuncs.com”],
“insecure-registries”: [“0.0.0.0”],
“log-driver”:”json-file”,
“log-opts”:{
“max-size”:”500m”,
“max-file”:”3″
}
}
启用daemon:systemctl daemon-reload
重启docker:systemctl restart docker
docker run –privileged -d –name rancher –restart=unless-stopped -p 8080:80 -p 8443:443 -v /mesdata/rancher:/var/lib/rancher rancher/rancher:stable
rancher 无法启动排查:
以下处理是遇到[FATAL] k3s exited with: exit status 1的错误,
查看日志 rancher下k3s-cluster-reset.log k3s.log 另外docker logs -f rancher
Ubuntu默认启用cgroup v2,修改支持v1
/etc/default/grub 增加GRUB_CMDLINE_LINUX="cgroup_memory=1 cgroup_enable=memory swapaccount=1 systemd.unified_cgroup_hierarchy=0"
update-grub
reboot
另外根据日志time="2022-06-20T10:34:16.530473756Z" level=fatal msg="starting kubernetes: preparing server: start managed
database: cluster-reset was successfully performed, please remove the cluster-reset flag and start k3s normally, if you need to perform another cluster reset, you must first manually delete the /var/lib/rancher/k3s/server/db/reset-flag file" 删除reset-flag文件
在/etc/sysctl.conf中添加:
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
执行sysctl -p 时刷新
docker run --privileged -d --name rancher --restart=unless-stopped -p 8080:80 -p 8443:443 -v /mesdata/rancher:/var/lib/rancher -e CATTLE_SYSTEM_DEFAULT_REGISTRY=https://q59d4unt.mirror.aliyuncs.com -e CATTLE_BOOTSTRAP_PASSWORD=SmarteeMes2021 -e CATTLE_SYSTEM_CATALOG=bundled mes/rancher:latest
docker run -d --privileged --name rancher --restart=unless-stopped -p 8080:80 -p 8443:443 -v /mesdata/rancher:/var/lib/rancher -e CATTLE_BOOTSTRAP_PASSWORD=SmarteeMes2021
-e CATTLE_AGENT_IMAGE="registry.cn-hangzhou.aliyuncs.com/rancher/rancher-agent:v2.6.8" \
registry.cn-hangzhou.aliyuncs.com/rancher/rancher:v2.6.8
sudo docker run -d --name rancher --restart=unless-stopped --privileged -p 8080:80 -p 8443:443 -v /var/rancher:/var/lib/rancher -v /var/rancher/registries.yaml:/etc/rancher/k3s/registries.yaml -e CATTLE_SYSTEM_DEFAULT_REGISTRY=registry.cn-hangzhou.aliyuncs.com -e CATTLE_BOOTSTRAP_PASSWORD=SmarteeMes2021 registry.cn-hangzhou.aliyuncs.com/rancher/rancher:v2.9.1
mirrors:
# 私有仓库域名
crpi-2ooy6l2xyewfpj4y.cn-shanghai.personal.cr.aliyuncs.com:
endpoint:
- "https://crpi-2ooy6l2xyewfpj4y.cn-shanghai.personal.cr.aliyuncs.com"
configs:
"crpi-2ooy6l2xyewfpj4y.cn-shanghai.personal.cr.aliyuncs.com":
auth:
username: hi34841966@aliyun.com # 这是私有镜像仓库的用户名
password: xxx # 这是私有镜像仓库的密码
~
docker run --privileged -d --name rancher --restart=unless-stopped -p 8080:80 -p 8443:443 -v /mesdata/rancher:/var/lib/rancher -e CATTLE_BOOTSTRAP_PASSWORD=SmarteeMes2021 -e CATTLE_SYSTEM_CATALOG=bundled -v /mesdata/registries.yaml:/etc/rancher/k3s/registries.yaml mes/rancher:latest
cat > /etc/rancher/k3s/registries.yaml <<EOF
mirrors:
docker.io:
endpoint:
- "https://registry.cn-hangzhou.aliyuncs.com/"
quay.io:
endpoint:
- "https://quay.tencentcloudcr.com/"
registry.k8s.io:
endpoint:
- "https://registry.aliyuncs.com/v2/google_containers"
gcr.io:
endpoint:
- "https://gcr.m.daocloud.io/"
k8s.gcr.io:
endpoint:
- "https://registry.aliyuncs.com/google_containers"
ghcr.io:
endpoint:
- "https://ghcr.m.daocloud.io/"
https://forums.rancher.cn/t/failed-to-pull-image-rancher-mirrored-pause-3-6/1659/4
https://forums.rancher.cn/t/rancher2-x-rancher-shell-v0-1-19/2013/2
https://www.jianshu.com/p/c71b5a1918e1
http://docs.rancher.cn/docs/rancher2.5/installation/other-installation-methods/single-node-docker/_index
journalctl -xef -u rancher-system-agent.service
journalctl -xeu rke2-server.service
/etc/rancher/rke2/config.yaml.d/50-rancher.yaml 增加 system-default-registry":"registry.cn-hangzhou.aliyuncs.com",
systemctl list-units --type=service
systemctl restart rke2-server.service
systemctl restart rancher-system-agent
清理环境(参考命令,需要时使用)
rke清理脚本
rke2清理脚本
清理脚本清理命令都执行,没脚本下载脚本后再执行
sh clear-k8s.sh
/usr/local/bin/rke2-uninstall.sh
1
2
rke2集群搭建时,人工再度确认/var/lib、/etc、/opt等目录下,是否还要rancher、docker、k3s、kubernetes、containerd等rancher与k3s、k8s等残留信息