一、修改主机名及解析(三台节点)
1、节点规划
hostname | IP | 内核版本 |
k8s-master | 192.168.80.14 | 5.0以上 |
k8s-node1 | 192.168.80.15 | 5.0以上 |
k8s-node2 |
192.168.80.16 | 5.0以上 |
2、修改主机名
hostnamectl set-hostname k8s-master
hostnamectl set-hostname k8s-node1
hostnamectl set-hostname k8s-node2
3、添加host解析
cat /etc/hosts
192.168.80.14 k8s-master
192.168.80.15 k8s-node1
192.168.80.16 k8s-node2
4、添加DNS解析
vim /etc/resolv.conf
# Generated by NetworkManager
nameserver 223.5.5.5
nameserver 114.114.114.114
二、系统优化(三个节点全做)
1、关闭selinux
#永久关闭
sed -i 's#enforcing#disabled#g' /etc/selinux/config
#临时关闭
setenforce 0
2、关闭防火墙
systemctl disable --now firewalld
3、关闭swap分区
# 关闭swap分区
swapoff -a
# 注释swap分区
vim /etc/fstab
sed -i.bak 's/^.*centos-swap/#&/g' /etc/fstab
# kubelet忽略swap
echo 'KUBELET_EXTRA_ARGS="--fail-swap-on=false"' > /etc/sysconfig/kubelet
4、做免密登录(主节点做)
[root@k8s-master-01 ~]# rm -rf /root/.ssh
[root@k8s-master-01 ~]# ssh-keygen #交互式直接全部回车
[root@k8s-master-01 ~]# cd /root/.ssh/
[root@k8s-master-01 ~/.ssh]# mv id_rsa.pub authorized_keys
[root@k8s-master-01 ~/.ssh]# scp -r /root/.ssh 192.168.15.32:/root
[root@k8s-master-01 ~/.ssh]# scp -r /root/.ssh 192.168.15.33:/root
5、同步集群时间
yum install ntp -y
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
echo 'Asia/Shanghai' > /etc/timezone
ntpdate time2.aliyun.com
echo '#Timing synchronization time' >>/var/spool/cron/root #给定时任务加上注释
echo '0 */1 * * * /usr/sbin/ntpdate ntp1.aliyun.com &>/dev/null' >>/var/spool/cron/root #设置定时任务
crontab -l #检查结果
6、配置国内yum源
rm -rf /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
# 刷新缓存
yum makecache
# 更新系统
yum update -y --exclud=kernel*
7、升级内核版本
搜索Index of /linux/kernel/el7/x86_64/RPMS
wget 下载rpm包
FOR example:
wget https://elrepo.org/linux/kernel/el7/x86_64/RPMS/kernel-lt-4.4.245-1.el7.elrepo.x
86_64.rpm
wget https://elrepo.org/linux/kernel/el7/x86_64/RPMS/kernel-lt-devel-4.4.245-1.el7.el
repo.x86_64.rpm
#安装
yum localinstall -y kernel-lt*
#调到默认启动
grub2-set-default 0 && grub2-mkconfig -o /etc/grub2.cfg
#查看当前默认启动的内核
grubby --default-kernel
# 重启系统
reboot
8、删除多余内核
yum remove $(rpm -qa | grep kernel | grep -v $(uname -r))
为了保险起见这个命令里,yum remove没有带-y参数,你可以根据输出再一次判断需要删除的内核版本是否正确。
一定要确认无误后再按y并回车!
9、安装IPVS
ipvs 是系统内核中的一个模块,其网络转发性能很高。一般情况下,我们首选 ipvs
# 安装 IPVS
yum install -y conntrack-tools ipvsadm ipset conntrack libseccomp
# 加载 IPVS 模块
cat > /etc/sysconfig/modules/ipvs.modules <<EOF
#!/bin/bash
ipvs_modules="ip_vs ip_vs_lc ip_vs_wlc ip_vs_rr ip_vs_wrr ip_vs_lblc ip_vs_lblcr
ip_vs_dh ip_vs_sh ip_vs_fo ip_vs_nq ip_vs_sed ip_vs_ftp nf_conntrack"
for kernel_module in \${ipvs_modules}; do
/sbin/modinfo -F filename \${kernel_module} > /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
10、内核参数优化
内核参数优化的主要目的是使其更适合 kubernetes 的正常运行。
cat > /etc/sysctl.d/k8s.conf << EOF
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
fs.may_detach_mounts = 1
vm.overcommit_memory=1
vm.panic_on_oom=0
fs.inotify.max_user_watches=89100
fs.file-max=52706963
fs.nr_open=52706963
net.ipv4.tcp_keepalive_time = 600
net.ipv4.tcp.keepaliv.probes = 3
net.ipv4.tcp_keepalive_intvl = 15
net.ipv4.tcp.max_tw_buckets = 36000
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp.max_orphans = 327680
net.ipv4.tcp_orphan_retries = 3
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.ip_conntrack_max = 65536
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.top_timestamps = 0
net.core.somaxconn = 16384
EOF
# 立即生效
sysctl --system
11、安装基础软件
yum install wget expect vim net-tools ntp bash-completion ipvsadm ipset jq iptables
conntrack sysstat libseccomp -y
三、安装Docker(三台节点都要做)
CentOS7版
#卸载之前的docker
y