#! /bin/sh# 更新系统yum -y update# 安装基础软件yum -y install net-tools lrzsz wget vim# 关闭防火墙systemctl stop firewalldsystemctl disable firewalldsystemctl status firewalld# 关闭selinux,把selinux状态改为disabledgetenforcesetenforce 0 sed -i 's/^SELINUX=.*$/SELINUX=disabled/g' /etc/selinux/configgetenforce# 把服务器的时间改成统一的时区timedatectl set-timezone Asia/Shanghai# 配置docker源cd /etc/yum.repos.dif [ ! -f docker-ce.repo ];thenwget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repofi# 配置kubernetes源cat > /etc/yum.repos.d/kubernetes.repo << EOF [kubernetes]name=Kubernetes Repobaseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/gpgcheck=0gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpgenabled=1EOF#配置epel源#设置centos7的YUM源为国内阿里云源epel源cd /etc/yum.repos.d/if [ ! -f epel-7.repo ];thenwget http://mirrors.aliyun.com/repo/epel-7.repofi# 配置nginx源#rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm cat > /etc/yum.repos.d/nginx.repo << EOF [nginx-stable]name=nginx stable repobaseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/gpgcheck=1enabled=1gpgkey=https://nginx.org/keys/nginx_signing.keymodule_hotfixes=true[nginx-mainline]name=nginx mainline repobaseurl=http://nginx.org/packages/mainline/centos/\$releasever/\$basearch/gpgcheck=1enabled=0gpgkey=https://nginx.org/keys/nginx_signing.keymodule_hotfixes=trueEOF#set the file limit#步骤一#echo "ulimit -SHn 102400" >> /etc/rc.localSTR_NAME="ulimit -SHn 102400"if grep -Fxq "$STR_NAME" /etc/rc.localthen echo "setting is exist"else echo "$STR_NAME" >> /etc/rc.localfigrep "$STR_NAME" /etc/rc.local#步骤二#cat >> /etc/security/limits.conf << EOF#* hard nproc 10240#* soft nproc 10240#* soft nofile 65535#* hard nofile 65535#EOFSTR_NAME1="* hard nproc 10240"STR_NAME2="* soft nproc 10240"STR_NAME3="* soft nofile 65535"STR_NAME4="* hard nofile 65535"for STR_NAME in "$STR_NAME1" "$STR_NAME2" "$STR_NAME3" "$STR_NAME4"doif grep -Fxq "$STR_NAME" /etc/security/limits.confthen echo "setting is exist"else echo "$STR_NAME" >> /etc/security/limits.conffidonegrep "$STR_NAME1" /etc/security/limits.confgrep "$STR_NAME2" /etc/security/limits.confgrep "$STR_NAME3" /etc/security/limits.confgrep "$STR_NAME4" /etc/security/limits.conf#tune kernel parametrescat > /etc/sysctl.d/99-sysctl.conf << EOFnet.ipv4.ip_forward = 0net.ipv4.conf.default.rp_filter = 1net.ipv4.conf.default.accept_source_route = 0kernel.sysrq = 0kernel.core_uses_pid = 1net.ipv4.tcp_syncookies = 1kernel.msgmnb = 65536kernel.msgmax = 65536kernel.shmmax = 68719476736kernel.shmall = 4294967296net.ipv4.tcp_max_tw_buckets = 6000net.ipv4.tcp_sack = 1net.ipv4.tcp_window_scaling = 1net.ipv4.tcp_rmem = 4096 87380 4194304net.ipv4.tcp_wmem = 4096 16384 4194304net.core.wmem_default = 8388608net.core.rmem_default = 8388608net.core.rmem_max = 16777216net.core.wmem_max = 16777216net.core.netdev_max_backlog = 262144net.core.somaxconn = 262144net.ipv4.tcp_max_orphans = 3276800net.ipv4.tcp_max_syn_backlog = 262144net.ipv4.tcp_timestamps = 0net.ipv4.tcp_synack_retries = 1net.ipv4.tcp_syn_retries = 1net.ipv4.tcp_tw_recycle = 1net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_syncookies = 1net.ipv4.tcp_mem = 94500000 915000000 927000000net.ipv4.tcp_fin_timeout = 10net.ipv4.tcp_keepalive_time = 1200net.ipv4.ip_local_port_range = 5000 65000fs.file-max=65535net.ipv4.tcp_orphan_retries = 3net.ipv4.tcp_keepalive_intvl = 15kernel.sem = 250 32000 100 128EOF/sbin/sysctl -p#lock system userpasswd -l xfspasswd -l newspasswd -l nscdpasswd -l dbuspasswd -l vcsapasswd -l gamespasswd -l haldaemonpasswd -l gopherpasswd -l ftppasswd -l mailnullpasswd -l pcappasswd -l mailpasswd -l shutdownpasswd -l haltpasswd -l uucppasswd -l operatorpasswd -l syncpasswd -l admpasswd -l lp# 加载源配置yum clean allyum makecacheuseradd adminecho "W123" | passwd admin --stdin > /dev/null 2>&1# 给admin设置管理员权限STR_NAME="admin ALL=(ALL) NOPASSWD: ALL"if grep -Fxq "$STR_NAME" /etc/sudoers;then echo "admin had has the administrator right"else echo "admin ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoersfigrep "$STR_NAME" /etc/sudoers# 禁止root账户直接登录,关闭UseDNS,加速ssh连接sed -i 's/#UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config#sed -i 's/#PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_configgrep PermitRootLogin /etc/ssh/sshd_configgrep UseDNS /etc/ssh/sshd_configsystemctl restart sshd