欢迎光临
我们一直在努力

Kubernetes自动化运维平台--Rancher(离线安装)

Rancher安装

官网:架构推荐 | Rancher。 服务器最低配置要求:4核4G 

安装 Docker-CE

1:查看操作系统

cat /etc/redhat-release

2:关闭防火墙及Seliunx、swap分区

swapoff -a && sysctl -w vm.swappiness=0 && sed -ri '/^[^#]*swap/s@^@#@' /etc/fstab
systemctl disable –now firewalld && setenforce 0
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/sysconfig/selinux

sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config

3:更换yum源

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/rocky*.repo

4: 安装docker源

yum install -y yum-utils jq psmisc net-tools telnet device-mapper-persistent-data lvm2 -y
yum-config-manager –add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
dnf makecache

5:安装基础工具

yum install wget jq psmisc vim net-tools telnet yum-utils device-mapper-persistent-data lvm2 git iptables -y

6:内核调优

modprobe overlay
modprobe br_netfilter
modprobe iptable_filter
modprobe ip_tables
modprobe iptable_nat

这一整套是搭建 containerd + K8s 节点前的前置环境初始化

vim /etc/modules-load.d/container-modules.conf
overlay
br_netfilter
iptable_filter
ip_tables
iptable_nat

systemctl enable –now systemd-modules-load.service rsyslog
lsmod | grep -E "overlay|br_netfilter|iptable_filter|ip_tables"

底层存储就绪:加载 overlay,支持容器镜像分层读写

底层网络就绪:加载网桥、iptables 模块,支撑 K8s Pod 通信、Service 转发、网络策略

持久化生效:配置开机自动加载,重启机器不用重复手动加载模块

事后校验:确认模块加载成功,避免后续安装 containerd/kubelet 报网络 / 存储底层错误

cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
EOF
sysctl –system
sysctl -p

7: 安装docker

yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y

配置镜像加速器  

vim /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"registry-mirrors": [ "http://hub-mirror.c.163.com",
"https://docker.m.daocloud.io",
"https://dockerproxy.com",
"https://vu1ajswo.mirror.aliyuncs.com",
"https://docker.mirrors.ustc.edu.cn",
"https://docker.nju.edu.cn" ]
}

8:启动Docker

systemctl daemon-reload && systemctl enable –now docker

测试docker

docker info


离线安装 Rancher

版本选择:GitHub – rancher/rancher: Complete container management platform

k3s 容器镜像修改方法:https://docs.rancher.cn/docs/rancher2/best-practices/use-in-china/_index/

先创建目录 —  存放我的个人主页中的rancher10个镜像 (提前下载好)

mkdir -p /data/rancher-data && chmod 777 -R /data && cd /data/rancher-data

通过xshell放到当前目录下! 

1:创建数据目录

cd /opt && mkdir rancher && cd rancher

2:启动Rancher :  (拉取走的是阿里云)

vim docker-compose.yaml
services:
rancher:
image: registry.cn-hangzhou.aliyuncs.com/hujiaming/rancher:v2.14.2
container_name: rancher
restart: unless-stopped
privileged: true
networks:
– rancher-net
ports:
– "80:80"
– "443:443"
dns:
– 223.5.5.5
– 114.114.114.114
volumes:
– /data/rancher-data:/var/lib/rancher
environment:
– TZ=Asia/Shanghai
– CATTLE_BOOTSTRAP_PASSWORD=Mashangyouqian666666!@
– CATTLE_TELEMETRY=off
– CATTLE_AGENT_IMAGE=registry.cn-hangzhou.aliyuncs.com/hujiaming/rancher-agent:v2.14.2
ulimits:
nofile:
soft: 65536
hard: 65536
nproc: 65536
healthcheck:
test: ["CMD", "curl", "-f", "-k", "https://localhost/ping"]
interval: 30s
timeout: 10s
retries: 3
start_period: 90s
logging:
driver: json-file
options:
max-size: "100m"
max-file: "5"
networks:
rancher-net:
driver: bridge
ipam:
config:
– subnet: 172.20.0.0/16
gateway: 172.20.0.1
docker compose up -d

3:查看容器日志

docker logs -f rancher
tail -f /data/rancher-data/k3s.log

如果rancher的组件镜像无法拉取,请参考此链接如何在国内使用 Rancher | Rancher文档

新开终端!

进入到rancher容器

docker exec -it rancher bash
cd /var/lib/rancher

加载我们放在目录里面的镜像文件

ctr -n k8s.io image import /var/lib/rancher/mirrored-coredns-coredns-1.14.2.tar
ctr -n k8s.io image import /var/lib/rancher/mirrored-pause-3.6.tar
ctr -n k8s.io image import /var/lib/rancher/shell-v0.7.0.tar
ctr -n k8s.io image import /var/lib/rancher/fleet-v0.15.2.tar
ctr -n k8s.io image import /var/lib/rancher/turtles-v0.26.2.tar
ctr -n k8s.io image import /var/lib/rancher/system-upgrade-controller-v0.19.1.tar
ctr -n k8s.io image import /var/lib/rancher/rancher-webhook-v0.10.6.tar
ctr -n k8s.io image import /var/lib/rancher/remotedialer-proxy-v0.7.3.tar
ctr -n k8s.io image import /var/lib/rancher/fleet-agent-v0.15.2.tar
ctr -n k8s.io image import /var/lib/rancher/cluster-api-controller-v1.12.7.tar

登录 : 网页

更换镜像

registry.cn-hangzhou.aliyuncs.com

赞(0)
未经允许不得转载:171主机测评 » Kubernetes自动化运维平台--Rancher(离线安装)
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址