linux Centos7.7 配置k8s系统环境

一、修改系统名字

  hostnamectl set-hostname k8s-master01

  hostnamectl set-hostname k8s-node01

  hostnamectl set-hostname k8s-node02

 

 安装依赖包


  yum install -y conntrack ntpdate ntp ipvsadm ipset jq iptables curl sysstat libseccomp wget vim net-tools git

 设置防火墙ipatbles并设置空规则


systemctl stop firewalld && systemctl disable firewalld && systemctl mask firewalld


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

 

如果开启了 swap 分区,kubelet 会启动失败(可以通过将参数 --fail-swap-on 设置为 false 来忽略 swap on),故需要在每台机器上关闭 swap 分区

swapoff -a && sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

关闭selinux

setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config


 设置系统参数

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
vm.overcommit_memory=1
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
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


设置系统时区
# 调整系统时区为 中国/上海
timedatectl set-timezone Asia/Shanghai

# 将当前的 UTC 时间写入硬件时钟
timedatectl set-local-rtc 0

# 重启依赖于系统时间的服务
systemctl restart rsyslog
systemctl restart crond

关闭系统不需要的服务

systemctl stop psatfix && systemctl disable postfix

设置rsyslogd和systemd journald

mkdir /var/log.journal #持久化保存日志的目录
mkdir /etc/systemd/journald.conf.d
touch /etc/systemd/journald.conf.d/99-prophet.conf
cat /etc/systemd/journald.conf.d/99-prophet.conf <<EOF
[Journal]
# 持久化保存到磁盘
Storage=persistent

# 压缩历史日志
Compress=yes

SyncIntervalSec=5m
RateLimitInterval=30svim
RateLimitBurst=1000

# 最大占用空间 10G

SystemMaxUse=10G

# 单日志文件最大 200M

SystemMaxFileSize=200M

# 日志保存时间 2周

MaxRetentionSec=2week

# 不将日志转发到 syslog

ForwardToSyslog=no

EOF

systemctl restart systemd-journald

升级系统内核为4.44

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

1.获取源
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-4.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.182-1.el7.elrepo.×86_64) 7 (Core)' && reboot

grub2-editenv list #验证是否设置成功

4.重启使配置有效

reboot

5.查看正在使用的内核(系统重启后,一定要查看)

uname -r


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

安装Docker软件

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

  查看最新的Docker版本:
  yum list docker-ce.x86_64 --showduplicates |sort -r

  Kubernetes 1.15当前支持的docker版本列表是1.13.1, 17.03, 17.06, 17.09, 18.06, 18.09。 这里在各节点安装docker的18.09.7版本。
  yum update -y && yum install -y docker-ce-18.09.9-3.el7 docker-ce-cli-18.09.9-3.el7

reboot 重启后使系统自动使用更新后的服务

检查内核版本

uname -r

grub2-editenv list 检查是否修改成功

如果不一致可进入内核启动文件,把旧版本给注释了,以后就只会启动新内核

vim /boot/grub2/grub.cfg

查看/var/log/boot.log系统启动日志是否有报错

tail -100f /var/log/boot.log

以下报错
[FAILED] Failed to start Postfix Mail Transport Agent.
See 'systemctl status postfix.service' for details.

报错处理

修改文件
vim /etc/postfix/main.cf

inet_protocols = ipv4
inet_interfaces = all


reboot重启后查看内核和日志

 

# 创建 /etc/docker 目录

mkdir /etc/docker
cat > /etc/docker/daemon.json << EOF
{
"exec-opts":["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts":{
"max-size": "100m"
}
}
EOF

mkdir -p /etc/systemd/system/docker.service.d

# 重启docker服务

systemctl daemon-reload && systemctl restart docker && systemctl enable docker

posted @ 2020-06-10 16:13  ╰☆ぷ天然ルo槑ご  阅读(762)  评论(0编辑  收藏  举报