码迷,mamicode.com
首页 > Web开发 > 详细

Kubernetes实战总结 - 系统初始化

时间:2020-03-25 21:12:23      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:nic   tools   dir   install   cat   tables   句柄   ntpdate   target   

 

设置系统主机名以及Host文件的相互解析

hostnamectl set-hostname k8s-master01 
cat >> /etc/hosts <<EOF
192.168.17.101 k8s-master01
192.168.17.102 k8s-node01
192.168.17.103 k8s-node02
EOF

安装依赖包以及常用软件

yum install -y ipvsadm ipset iptablesvim curl wget net-tools sysstat conntrack libseccomp ntpdate

设置防火墙为 Iptables 并设置空规则

systemctl stop firewalld && systemctl disable firewalld
yum -y install iptables-services && systemctl start iptables && systemctl enable iptables && iptables -F && service iptables save

注意:生产环境要根据实际需要配置防火墙规则。

技术图片

关闭交换空间以及禁用SELINUX

注意: k8s要求关闭swap分区,以防容器运行在虚拟内存,导致性能大大降低。

swapoff -a && sed -i ‘/ swap / s/^\(.*\)$/#\1/g‘ /etc/fstab
setenforce 0 && sed -i ‘s/^SELINUX=.*/SELINUX=disabled/‘ /etc/selinux/config

针对K8S调整内核参数

注意:红色为必要调整,其余为可选优化方案。

cat > kubernetes.conf <<EOF
# 开启ipv4网桥模式
net.bridge.bridge-nf-call-iptables=1
# 开启ipv4网桥模式
net.bridge.bridge-nf-call-ip6tables=1
# 关闭ipv6协议
net.ipv6.conf.all.disable_ipv6=1

# 启用IP路由转发功能
net.ipv4.ip_forward=1
# 关闭TIME-WAIT状态sockets的快速回收
net.ipv4.tcp_tw_recycle=0
# 禁止使用swap空间,只有当系统 OOM 时才允许使用它
vm.swappiness=0
# 开启OOM     
vm.panic_on_oom=0
# 不检查物理内存是否够用
vm.overcommit_memory=1
# 设置文件最大句柄数目
fs.file-max=52706963
# 设置文件最大打开数目
fs.nr_open=52706963
# 指定每一个real user ID可创建的inotify instatnces的数量上限
fs.inotify.max_user_instances=8192
# 指定每个inotify instance相关联的watches的上限 
fs.inotify.max_user_watches=1048576
# 设置系统最大连接数
net.netfilter.nf_conntrack_max=2310720
EOF

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 rsyslog
systemctl 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
systemctl restart systemd-journald

 

参考:https://www.bilibili.com/video/BV1w4411y7Go?p=12

 

作者:Leozhanggg

出处:https:////www.cnblogs.com/leozhanggg/p/12568456.html

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

 

Kubernetes实战总结 - 系统初始化

标签:nic   tools   dir   install   cat   tables   句柄   ntpdate   target   

原文地址:https://www.cnblogs.com/leozhanggg/p/12568456.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!