k8s部署之系統初始化(一)


初始化

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,導致運行的 DockerKubernetes 不穩定,例如: 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

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

本文章為我自己的學習筆記,難免有些遺漏,歡迎指正。遇事不慌,大隆來幫,也請大家關注我,支持我,謝謝!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM