⒈配置Linux的IP地址node
vim /etc/sysconfig/network-scripts/ifcfg-ens33v
ifcfg-ens33是網卡的最新命名規範,它會從BIOS => PCIE通道里獲取它的網卡文件名,若是都沒有的話,再降級到eth0或者eth1的命名方式,若是須要關閉的話,ifnames=0就能夠關閉了。和之前的配置文件修改方式相似。linux
⒉設置主機名git
hostnamectl set-hostname {hostName}
在大型集羣環境中建議你們經過DNS的方式,讓主機名和IP之間可以相互解析,固然也能夠經過修改host文件進行配置。vim
小環境中不建議你們經過DNS的方式,若是DNS掛掉的話那麼集羣環境也就掛掉了。app
⒊修改host文件【非集羣環境可省略】curl
vim /etc/hosts
**在Linux之間相互拷貝文件tcp
#輸入完此命令後輸入yes,並輸入node01的root密碼便可複製成功 scp /etc/hosts root@k8s-node01:/etc/hosts
⒋將yum雲修改成163【暫略】post
⒌安裝依賴包優化
yum install -y conntrack ntpdate ntp ipvsadm ipset jq iptables curl sysstat libseccomp wget vim net-tools git
⒍設置防火牆爲lptables 並設置空規則url
#關閉firewalld並取消自啓動 systemctl stop firewalld && systemctl disable firewalld #安裝iptables,啓動iptables,設置開機自啓,清空iptables規則,保存當前規則到默認規則 yum -y install iptables-services && systemctl start iptables && systemctl enable iptables && iptables-F && service iptables save
⒎關閉SELINUX
1.關閉swap分區
#關閉swap分區【虛擬內存】而且永久關閉虛擬內存。 swapoff -a && sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
**kubeadm初始化Kubernetes時的過程當中會檢測swap分區到底有沒有關閉,由於若是開啓虛擬內存的話,kubernetes的容器【pod】就有可能會運行在虛擬內存上,會大大的下降容器的工做效率,所以Kubernetes會要求強制關閉,能夠經過kubelet的啓動參數--fail-swap-on=false
更改這個限制。推薦關閉以防止容器運行在虛擬內存的狀況出現。
2.關閉SELinux
setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
⒏相對於Kubernetes調整內核參數
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 #禁止使用swap空間,只有當系統OOM時才容許使用它 vm.swappiness=0 #不檢查物理內存是否夠用 vm.overcommit_memory=1 #開啓OOM vm.panic_on_oom=0 fs.inotify.max_user_instances=8192 fs.inotify.max_user_watches=1048576 fs.file-max=52706963 fs.nr_open=52706963 #關閉ipv6【重要】 net.ipv6.conf.all.disable_ipv6=1 net.netfilter.nf_conntrack_max=2310720 EOF
#將優化內核文件拷貝到/etc/sysctl.d/文件夾下,這樣優化文件開機的時候可以被調用 cp kubernetes.conf /etc/sysctl.d/kubernetes.conf
#手動刷新,讓優化文件當即生效
sysctl -p /etc/sysctl.d/kubernetes.conf
***非Linux4的內核下,將會彈出「sysctl:cannot stat /proc/sys/net/netfilter/nf_conntrack_max:沒有那個文件或目錄」,無視便可。
⒐調整系統時區
#設置系統時區爲中國/上海 timedatectl set-timezone Asia/Shanghai #將當前的 UTC 時間寫入硬件時鐘 timedatectl set-local-rtc 0 #重啓依賴於系統時間的服務 systemctl restart rsyslog systemctl restart crond
⒑關閉系統不須要的服務
#關閉及禁用郵件服務
systemctl stop postfix && systemctl disable postfix
⒒設置日誌的保存方式
在Centos7之後,由於引導方式改成了system.d,因此有兩個日誌系統同時在工做,默認的是rsyslogd,以及systemd journald
使用systemd journald更好一些,所以咱們更改默認爲systemd journald,只保留一個日誌的保存方式。
1.建立保存日誌的目錄
mkdir /var/log/journal
2.建立配置文件存放目錄
mkdir /etc/systemd/journald.conf.d
3.建立配置文件
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
4.重啓systemd journald的配置
systemctl restart systemd-journald
⒓升級Linux內核爲4.44版本
CentOS 7.x 系統自帶的3.10.x內核存在一些Bugs.致使運行的Docker.Kubernetes不穩定。
1.獲取源
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
2.開始安裝,安裝完成後檢查 /boot/grub2/grub.cfg中對應內核menuentry中是否包含 initrd16 配置,若是沒有,再安裝一次!
yum --enablerepo=elrepo-kernel install -y kernel-lt
3.設置開機重新內核啓動
grub2-set-default 'CentoS Linux(4.4.189-1.el7.elrepo.×86_64) 7 (Core)'
⒔重啓啓動使配置生效
reboot