1. 系统初始化

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

hostnamectl set-hostname k8s-master01

安装依赖包

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

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


//关闭防火墙&&防火墙自启
systemctl stop firewalld && systemctl disable firewalld
//安装Iptables管理工具&&启动Iptables&&设为Iptables开机自启&&清空Iptables规则&&保存Iptables默认规则
yum -y install iptables-services && systemctl start iptables && systemctl enable iptables&& iptables -F && service iptables save

关闭SELINUX

//关闭虚拟内存并永久关闭

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

调整内核参数,对于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  #必选 关闭ipv6协议

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 rsyslogsystemctl 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



#重启journald配置

systemctl restart systemd-journald

升级内核为4.4版本

# 可配置yum国内镜像源后运行
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 # 设置开机从新内核启动 grub2-set-default "CentOS Linux (4.4.182-1.el7.elrepo.x86_64) 7 (Core)"

#重启后检测

uname -r

配置yum源

1. 备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

  2. 下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all # 清除系统所有的yum缓存 yum makecache # 生成yum缓存 yum update

3. 查看可用的epel源

yum list | grep epel-release

4.安装 epel
yum install -y epel-release

5.配置阿里镜像提供的epel源
wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all    # 清除系统所有的yum缓存
yum makecache    # 生成yum缓存
yum update

6. 查看yum源和可用yum源

yum repolist all
yum repolist enabled
参考:
https://www.cnblogs.com/LiuQizhong/p/11508059.html
https://developer.aliyun.com/mirror/centos

https://blog.csdn.net/xiaojin21cen/article/details/84726193

posted on 2019-12-19 18:46  luffy_lcc  阅读(38)  评论(0)    收藏  举报

导航