- 设置静态IP
[root@k8s-master01 ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33
BOOTPROTO=staticONBOOT=yesIPADDR=192.168.5.95NETMASK=255.255.255.0GATEWAY=192.168.5.241DNS1=192.168.5.241DNS2=114.114.114.114DNS3=8.8.8.8
- 设置系统主机名以及 Host 文件的相互解析
[root@k8s-master01 ~]# hostnamectl set-hostname k8s-master01[root@k8s-node01 ~]# hostnamectl set-hostname k8s-node01[root@k8s-node02 ~]# hostnamectl set-hostname k8s-node02
修改 /etc/hosts
192.168.5.80 k8s-master01192.168.5.81 k8s-node01192.168.5.82 k8s-node02
scp /etc/hosts root@k8s-node01:/etc/hostsscp /etc/hosts root@k8s-node02:/etc/hosts
- 安装依赖包
yum install -y conntrack ntpdate ntp ipvsadm ipset jq \iptables curl sysstat libseccomp wget vim \net-tools git
- 设置防火墙为 Iptables 并设置空规则
systemctl stop firewalld && systemctl disable firewalldyum -y install iptables-services && systemctl start iptables && systemctl enable iptables \&& iptables -F && service iptables save
- 关闭 SELINUX
swapoff -a && sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstabsetenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
- 调整内核参数,对于 K8S
cat > kubernetes.conf <<EOFnet.bridge.bridge-nf-call-iptables=1net.bridge.bridge-nf-call-ip6tables=1net.ipv4.ip_forward=1net.ipv4.tcp_tw_recycle=0vm.swappiness=0 # 禁止使用 swap 空间,只有当系统 OOM 时才允许使用它vm.overcommit_memory=1 # 不检查物理内存是否够用vm.panic_on_oom=0 # 开启 OOMfs.inotify.max_user_instances=8192fs.inotify.max_user_watches=1048576fs.file-max=52706963fs.nr_open=52706963net.ipv6.conf .all.disable_ipv6=1net.netfilter.nf_conntrack_max=2310720EOF
PS:必备参数 net.bridge.bridge-nf-call-iptables=1 net.bridge.bridge-nf-call-ip6tables=1 net.ipv6.conf .all.disable_ipv6=1
cp kubernetes.conf /etc/sysctl.d/kubernetes.confsysctl -p /etc/sysctl.d/kubernetes.conf
- 调整系统时区
# 查看时区timedatectl# 设置系统时区为 中国/上海timedatectl set-timezone Asia/Shanghai# 将当前的 UTC 时间写入硬件时钟timedatectl set-local-rtc 0# 重启依赖于系统时间的服务systemctl restart rsyslogsystemctl restart crond
- 关闭系统不需要服务(邮件服务)
systemctl stop postfix && systemctl disable postfix
- 设置 rsyslogd 和 systemd journald
mkdir /var/log/journal # 持久化保存日志的目录mkdir /etc/systemd/journald.conf.dcat > /etc/systemd/journald.conf.d/99-prophet.conf <<EOF[Journal]# 持久化保存到磁盘Storage=persistent# 压缩历史日志Compress=yesSyncIntervalSec=5mRateLimitInterval=30sRateLimitBurst=1000# 最大占用空间 10GSystemMaxUse=10G# 单日志文件最大 200MSystemMaxFileSize=200M# 日志保存时间 2 周MaxRetentionSec=2week# 不将日志转发到 syslogForwardToSyslog=noEOFsystemctl restart systemd-journald
- 升级系统内核为 4.44
CentOS 7.x 系统自带的 3.10.x 内核存在一些 Bugs ,导致运行的 Docker、Kubernetes 不稳定,例如: rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm# 安装完成后检查 /boot/grub2/grub.cfg 中对应内核 menuentry 中是否包含 initrd16 配置,如果没有,再安装一次!yum --enablerepo=elrepo-kernel install -y kernel-lt# 查看当前内核列表awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg# 设置开机从新内核启动grub2-set-default 'CentOS Linux (4.4.206-1.el7.elrepo.x86_64) 7 (Core)'
PS:由于系统会优先选择系统默认内核,所以在
reboot后内核又使用之前的了。 grub2-set-default “CentOS Linux (4.4.206-1.el7.elrepo.x86_64) 7 (Core)” && reboot
