一、修改主機名
hostnamectl set-hostname xxx
二、修改hosts文件vim /etc/hosts
三、將寫好的hosts文件拷貝到其他節點
scp /etc/hosts root@k8s-node01:/etc/hosts
四、安裝依賴包
yum install -y conntrack ntpdate ntp ipvsadm ipset jq iptables curl sysstat libseccomp wgetvimnet-tools git
五、設置防火牆為 Iptables 並設置空規則(都執行)
//關閉防火牆&&防火牆自啟
systemctl stop firewalld && systemctl disable firewalld //安裝Iptables管理工具&&啟動Iptables&&設為Iptables開機自啟&&清空Iptables規則&&保存Iptables默認規則
yum -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/fstab //關閉swap分區,永久關閉虛擬內存。K8s初始化init時,會檢測swap分區有沒有關閉,如果虛擬內存開啟,容器pod就可能會放置在虛擬內存中運行,會大大降低運行效率
setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
七、調整內核參數,對於k8s
cat > kubernetes.conf <<EOF net.bridge.bridge-nf-call-iptables=1 net.bridge.bridge-nf-call-ip6tables=1 net.ipv4.ip_forward=1 net.ipv4.tcp_tw_recycle=0 vm.swappiness=0 # 禁止使用 swap 空間,只有當系統 OOM 時才允許使用它 vm.overcommit_memory=1 # 不檢查物理內存是否夠用 vm.panic_on_oom=0 # 開啟 OOM fs.inotify.max_user_instances=8192 fs.inotify.max_user_watches=1048576 fs.file-max=52706963 fs.nr_open=52706963 net.ipv6.conf.all.disable_ipv6=1 net.netfilter.nf_conntrack_max=2310720 EOF 其中必備參數 net.bridge.bridge-nf-call-iptables=1 net.bridge.bridge-nf-call-ip6tables=1 //開啟網橋模式 net.ipv6.conf.all.disable_ipv6=1//關閉ipv6的協議 其余為優化參數,可不設置
cp kubernetes.conf /etc/sysctl.d/kubernetes.conf //拷貝,開機能調用
sysctl -p /etc/sysctl.d/kubernetes.conf //手動刷新
八、調整系統時區
//設置系統時區為中國/上海
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
原因:centos7以后,引導方式改為了systemd,所以會有兩個日志系統同時工作只保留一個日志(journald)的方法
mkdir /var/log/journal # 持久化保存日志的目錄 mkdir /etc/systemd/journald.conf.d cat > /etc/systemd/journald.conf.d/99-prophet.conf <<EOF [Journal] #持久化保存到磁盤 Storage=persistent # 壓縮歷史日志 Compress=yes SyncIntervalSec=5m RateLimitInterval=30s RateLimitBurst=1000 # 最大占用空間10G SystemMaxUse=10G # 單日志文件最大200M SystemMaxFileSize=200M # 日志保存時間 2 周 MaxRetentionSec=2week # 不將日志轉發到 syslog ForwardToSyslog=no EOF
#重啟journald配置 systemctl restart systemd-journald
十一、升級內核為4.4版本
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 # 設置開機從新內核啟動 grub2-set-default "CentOS Linux (4.4.182-1.el7.elrepo.x86_64) 7 (Core)"
以上筆記根據尚硅谷官方k8s視頻內容總結