使用root用户
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache fast
vim /etc/yum.repos.d/kubernetes.repo
内容
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
yum clean all
yum makecache fast
yum -y update
yum -y install yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum clean all
yum makecache fast
yum -y install wget net-tools nfs-utils lrzsz gcc gcc-c++ make cmake libxml2-devel openssl-devel curl curl-devel unzip sudo ntp libaio-devel wget vim ncurses-devel autoconf automake zlib-devel python-devel epel-release openssh-server socat ipvsadm conntrack ntpdate
centos7系统默认使用的是firewalld防火墙,停止firewalld防火墙,并禁用这个服务.
# 停止防火墙
systemctl stop firewalld
# 禁用防火墙
systemctl disable firewalld
如果你用firewalld不是很习惯,可以安装iptables
yum install iptables-services -y
# 停止
service iptables stop
# 禁用
systemctl disable iptables
ntpdate cn.pool.ntp.org
[root@zhoufei ~]# crontab -e
内容
* */1 * * * /usr/sbin/ntpdate cn.pool.ntp.org
service crond restart
关闭selinux,设置永久关闭,这样重启机器selinux也处于关闭状态
# 将 selinux 文件中的 SELINUX=enforcing 替换为 SELINUX=disabled
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux
# 将 config 文件中的 SELINUX=enforcing 替换为 SELINUX=disabled
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
reboot -f
# 临时禁用
swapoff -a
# 永久禁用,/etc/fstab中注释掉swap那一行。
sed -i 's/.*swap.*/#&/' /etc/fstab

打开文件
vim /etc/sysctl.d/k8s.conf
内容
# 开启 iptables 对bridge的数据进行处理
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
让配置文件生效
sysctl --system
hostnamectl set-hostname k8s01
vim /etc/hosts
新增
# 本机IP
192.168.187.154 k8s01
sudo yum list docker-ce --showduplicates |sort -r

# 安装
yum -y install docker-ce-19.03.7-3.el7
# 开启docker服务
systemctl enable docker
systemctl start docker
如果状态是active(running),说明docker是正常运行状态
systemctl status docker

cat > /etc/docker/daemon.json <
# 镜像仓库
registry-mirrors:
#存储方式
storage-driver": "overlay2"
systemctl daemon-reload
systemctl restart docker
echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
echo 1 >/proc/sys/net/bridge/bridge-nf-call-ip6tables
echo """
vm.swappiness = 0
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
""" > /etc/sysctl.conf
# 让配置文件失效
sysctl -p

不开启ipvs将会使用iptables,但是效率低,所以官网推荐需要开通ipvs内核
cat > /etc/sysconfig/modules/ipvs.modules < /dev/null 2>&1
if [ $? -eq 0 ]; then
/sbin/modprobe \${kernel_module}
fi
done
EOF
chmod 755 /etc/sysconfig/modules/ipvs.modules
bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep ip_vs
