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

hostnamectl set-hostname k8s-master01

安装依赖包

yum -y install wget net-tools nfs-utils lrzsz gcc gcc-c++ make cmake\
libxml2-devel openssl-devel curl curl-devel unzip sudo ntp libaio-devel\
wget vim ncurses-devel autoconf automake zlib-devel python-devel\
epel-release lrzsz openssh-server socat ipvsadm conntrack bind-utils\
libffi-devel zip ntpdate ipset jq sysstat libseccomp git yum-utils

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

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

关闭 SELINUX,关闭swap

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

放开文件描述符的最大值限制,默认是1024

echo "root soft nofile 65536" >> /etc/security/limits.conf
echo "root hard nofile 65536" >> /etc/security/limits.conf
echo "* soft nofile 65536" >> /etc/security/limits.conf
echo "* hard nofile 65536" >> /etc/security/limits.conf
echo "fs.file-max=655360" >> /etc/sysctl.conf
sysctl -p
echo "ulimit -n 65536" >> /etc/profile
#source /etc/profile

调整内核参数,对于 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 -fr 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

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

升级系统内核为 5.4.98-1

CentOS 7.x 系统自带的 3.10.x 内核存在一些 Bugs,导致运行的 Docker、Kubernetes 不稳定

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
# 设置开机从新内核启动
cat /boot/grub2/grub.cfg | grep '5.4.98-1' || grub2-set-default 'CentOS Linux (5.4.98-1.el7.elrepo.x86_64) 7 (Core)'
grub2-editenv list
#如果内核已经不是5.4.98-1,请根据实际情况做调整

上面的rpm文件下载失败,请从http://download.zhufunin.com/elrepo-release-7.0-3.el7.elrepo.noarch.rpm这里下载

配置docker yum源

yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

配置k8s 的yum源

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
EOF

yum安装18.09版本的docker

yum list docker-ce --showduplicates |sort -r
yum install -y docker-ce-18.09.9-3.el7
systemctl enable docker && systemctl start docker
systemctl status docker

**yum安装k8s 1.16.4版kubeadm kubelet **

yum list kubeadm --showduplicates |sort -r|head -30
yum list kubelet --showduplicates |sort -r|head -30
yum install -y kubeadm-1.16.4-0.x86_64 kubelet-1.16.4-0.x86_64
systemctl enable kubelet

kube-proxy开启ipvs的前置条件

modprobe br_netfilter
cat > /etc/sysconfig/modules/ipvs.modules <<EOF
#!/bin/bash
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack_ipv4
EOF
chmod 755 /etc/sysconfig/modules/ipvs.modules
bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep -e ip_vs -e nf_conntrack_ipv4

最新文章

  1. FZU 2150 Fire Game
  2. git分支管理策略
  3. MySQL数据处理函数
  4. mysql 调用存储过程及例子
  5. C# 枚举的使用
  6. whatwg-fetch源码分析
  7. Linux学习总结(七)—— CentOS软件包管理:脚本安装
  8. 自动化运维工具——ansible详解(一)
  9. SpriteBuilder中如何给精灵添加帧动画
  10. Spring面试问答
  11. BurpSuite使用笔记
  12. 从Win32程序中的主函数中获取命令行参数
  13. Django的内置登录、退出、修改密码方法
  14. Linux内核分析——第三章 进程管理
  15. 个人项目Individual Project:迷宫求解
  16. hdu 3068 最长回文【manacher】(模板题)
  17. 5.Python文件操作之增删改查
  18. CSS中width和height与盒子模型的关系
  19. Spring源码分析(十八)创建bean
  20. Linux美化终端

热门文章

  1. C#测试--内部类测试
  2. 力扣119. 杨辉三角 II
  3. 细说MySQL连接查询:内连、左连和右连
  4. PAT-1119(Pre- and Post-order Traversals)+前序和后序遍历确定二叉树+判断二叉树是否唯一
  5. 基于 vagrant搭建移动端的开发环境
  6. 追洞小组 | 实战CVE-2020-7471漏洞
  7. 对话对话每日互动CEO方毅:数据智能应用的过去、现在和未来每日互动CEO方毅:数据智能应用的过去、现在和未来
  8. IPFS是什么?IPFS与Filecoin有什么关系?
  9. Python图像处理库——PIL
  10. 更改当前目录--cd