k8s部署之系統初始化(一)
阿新 • • 發佈:2020-07-29
初始化
1.安裝依賴包
yum -y install tree lrzsz nmap nc telnet vim wget lsof network-tools bash-completion bash-completion-extras net-tools epel-release createrepo conntrack ntpdate ntp ipvsadm ipset jq iptables curl sysstat libseccomp wget vim net-tools git net-tools
2.更新yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
3.設定系統主機名以及 Host 檔案的相互解析
vim /etc/hosts 192.168.0.156 k8s-master01 192.168.0.45 k8s-node01 192.168.0.44 k8s-node02
4.設定防火牆為 Iptables 並設定空規則
systemctl stop firewalld && systemctl disable firewalld yum-y install iptables-services && systemctl start iptables && systemctl enable iptables && iptables -F && service iptables save
5.關閉SELINUX
#關閉swap分割槽虛擬記憶體 swapoff -a && sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
6.調整核心引數,對於 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 cp kubernetes.conf /etc/sysctl.d/kubernetes.conf sysctl -p /etc/sysctl.d/kubernetes.conf
7.關閉系統不需要服務
systemctl stop postfix && systemctl disable postfix
8.設定 rsyslogd 和 systemd journald(日誌方案改為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 systemctl restart systemd-journald
9.升級系統核心為4.44
核心軟體包地址備用:
https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/linux-4.4.189.tar.gz
CentOS 7.x 系統自帶的 3.10.x 核心存在一些 Bugs,導致執行的 Docker、Kubernetes 不穩定,例如: rpm -Uvhhttp://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 yum --enablerepo=elrepo-kernel install -y kernel-lt #檢視都有哪些核心 awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg grub2-set-default 'CentOS Linux (4.4.217-1.el7.elrepo.x86_64) 7 (Core)' #重啟主機 reboot #檢視核心 uname -r
本文章為我自己的學習筆記,難免有些遺漏,歡迎指正。遇事不慌,大隆來幫,也請大家關注我,支援我,謝謝!