1. 修改主机名称和添加hosts
bash
#永久修改主机名
hostnamectl set-hostname master && bash #在master01上操作,阿里云服务器
hostnamectl set-hostname worker1 && bash #在node01上操作,阿里腾讯云服务器
hostnamectl set-hostname worker2 && bash #在node02上操作,华为云服务器
bash
cat >> /etc/hosts << EOF
202.168.216.25 master
198.201.73.25 worker1
49.58.173.125 worker2
EOF
2.系统优化
bash
#时间同步:
yum install epel-release -y
yum install ntpdate -y
ntpdate time.windows.com
bash
#修改内核参数
cat > /etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
cat >> /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
modprobe br_netfilter #加载br_netfilter模块
lsmod |grep br_netfilter #验证模块是否加载成功
sysctl -p /etc/sysctl.d/k8s.conf #使刚才修改的内核参数生效
bash
systemctl stop firewalld # 关闭
systemctl disable firewalld # 禁止开机启动防火墙
sed -i 's/enforcing/disabled/' /etc/selinux/config # 永久
setenforce 0 # 临时
bash
yum install -y yum-utils device-mapper-persistent-data lvm2 wget curl
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
#yum list docker-ce --showduplicates | sort -r #查看yum仓库中可以安装的docker版本
#yum -y install docker-ce-18.06.1.ce-3.el7 #安装指定的版本
yum -y install docker-ce docker-ce-cli containerd.io #安装最新docker
systemctl enable docker
systemctl start docker
docker --version
cat > /etc/docker/daemon.json << EOF
{
"registry-mirrors": ["https://qj799ren.mirror.aliyuncs.com","https://4c99aa72f1a643edb02b13b93fec6a17.mirror.swr.myhuaweicloud.com"],
"insecure-registries": ["0.0.0.0/0"],
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
systemctl restart docker
systemctl status docker
3.rancher安装
bash
#在master01上操作,阿里云服务器上安装rancher
docker run -d --name rancher_server --restart=unless-stopped --privileged -p 8080:80 -p 8443:443 -v /rancher/rancher:/var/lib/rancher rancher/rancher:v2.4.17