系统时最小化安装的,这里要安装系统的软件库 1 2 3 4 5 6 yum install -y net-tools vim iotop bc zip \ unzip lrzsz tree ntpdate telnet lsof iostat \ tcpdump wget traceroute bc net-tools \ bash-completion apt install build-essential
1 yum groupinstall -y "development tools"
修改网卡名称以 eth 开头 增加内核参数:
1 net.ifnames =0 biosdevname =0
创建工作目录* 1 2 3 4 5 6 [ ! -d /server/ tools ] && mkdir -p /server/ tools [ ! -d /application ] && mkdir -p / application [ ! -d /data ] && mkdir -p / data [ ! -d /app/ logs ] && mkdir -p /app/ logs [ ! -d /server/ backup ] && mkdir -p /server/ backup [ ! -d /delete ] && mkdir -p / delete
每周六凌晨1点0分更新服务器系统时间 1 2 3 echo "############### auto update time ###############" >> /var/ spool/cron/ root echo "00 01 * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1" >> /var/ spool/cron/ root [ `grep ntpdate /var/ spool/cron/ root |wc -l` -ne 0 ] && action "uptime set" /bin/ true || action "uptime set" /bin/ false
配置国内yum源 centos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backupcurl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo CentOS 7 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo yum clean all yum makecache yum repolist enabled yum repolist all
ubuntu
1 2 3 4 5 6 7 8 9 10 11 12 13 cat > /etc/apt/sources.list << EOF deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse EOF sudo apt update
如果出现NO_PUBKEY
1 apt-key adv --recv-keys --keyserver keyserver.ubuntu .com F42ED6FBAB17C654
关闭SELINUX及iptables和firewalld 1 2 3 4 /bin/ cp /etc/ selinux/config / etc/selinux/ config.baksed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/ selinux/config 2 >&1 systemctl stop firewalld.service systemctl disable firewalld.service
调整文件描述符数量 1 2 /bin/ cp /etc/ security/limits.conf / etc/security/ limits.conf.bakecho '* - nofile 65535' >>/etc/ security/limits.conf
内核升级 CentOS 7.x 系统自带的 3.10.x 内核存在一些 Bugs,导致运行的 Docker、Kubernetes不稳定,例如:
高版本的 docker(1.13 以后) 启用了 3.10 kernel 实验支持的 kernel memoryaccount 功能(无法关闭),当节点压力大如频繁启动和停止容器时会导致 cgroupmemory leak;
网络设备引用计数泄漏,会导致类似于报错:”kernel:unregister_netdevice: waitingfor eth0 to become free. Usage count = 1”;
解决方案如下:
这里采用升级内核的解决办法 :
centos7.7 当前版本
1 2 3 4 5 6 7 8 9 10 11 12 $ uname -a Linux k8s-01 3.10.0-1062.el7.x86_64 $ rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm $ yum --enablerepo=elrepo-kernel install -y kernel-lt $ sudo awk -F\' ' $1 =="menuentry " {print i++ " : " $2 }' /etc/grub2.cfg 0 : CentOS Linux (4.4.216-1.el7.elrepo.x86_64) 7 (Core) 1 : CentOS Linux (3.10.0-1062.el7.x86_64) 7 (Core) 2 : CentOS Linux (0-rescue-a695b6c8dd0e412daaa39cdecc50dd60) 7 (Core) # 设置开机从新内核启动 $ grub2-set-default 0
安装 ml版本 5版本的内核名字叫ml
1 $ yum --enablerepo="elrepo-kernel" -y install kernel-ml.x86_64
重启机器:
查看版本
1 2 [11 :36 :26 root@k8s-01 ~]$uname -a Linux k8 s-01 4.4 .216 -1 .el7 .elrepo.x 86 _64 #1 SMP Wed Mar 11 09 :13 :43 EDT 2020 x 86 _64 x 86 _64 x 86 _64 GNU/Linux
内核参数优化 [ -f /etc/sysctl.conf.bak ] && /bin/cp /etc/sysctl.conf.bak /etc/sysctl.conf.bak.$(date +%F-%H%M%S) ||/bin/cp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 cat >> /etc/sysctl.conf <<EOF net.ipv4 .tcp_fin_timeout = 2 net.ipv4 .tcp_tw_reuse = 1 net.ipv4 .tcp_tw_recycle = 1 net.ipv4 .tcp_syncookies = 1 net.ipv4 .tcp_keepalive_time = 600 net.ipv4 .ip_local_port_range = 4000 65000 net.ipv4 .tcp_max_syn_backlog = 16384 net.ipv4 .tcp_max_tw_buckets = 36000 net.ipv4 .route .gc_timeout = 100 net.ipv4 .tcp_syn_retries = 1 net.ipv4 .tcp_synack_retries = 1 net.core .somaxconn = 16384 net.core .netdev_max_backlog = 16384 net.ipv4 .tcp_max_orphans = 16384 net.ipv6 .conf .all .disable_ipv6 = 1 net.ipv6 .conf .default .disable_ipv6 = 1 EOF sysctl -p
bash调整 1 2 3 4 5 6 7 8 cat > /etc/profile.d/env.sh << EOF export HISTTIMEFORMAT ="[%Y.%m.%d %H:%M:%S] " export HISTSIZE =50000export HISTIGNORE ="ls:ls -lrt:ls -al:clear:pwd" export PS1 ='\[\e[1;32m\][\t \[\e[1;33m\]\u\[\e[36m\]@\h\[\e[1;31m\] \w\[\e[1;32m\]]\[\e[0m\] \\$' EOF source /etc/profile.d/env.sh
vim调整 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 cat >> /etc/vimrc << EOF set tabstop =2set expandtabset numberset rulerset showcmdset autoindentset hlsearchset ignorecaseset backspace =indent,eol,startset pasteset listchars =trail:.set listset tabstop =2EOF