#!/bin/bash#author junxi by #this script is only for CentOS 7.x#check the OSplatform=`uname -i`if [ $platform != "x86_64" ];then echo "this script is only for 64bit Operating System !"exit 1fiecho "the platform is ok"cat << EOF+---------------------------------------+| your system is CentOS 7 x86_64 || start optimizing....... |+---------------------------------------EOF#添加公网DNS地址cat >> /etc/resolv.conf << EOFnameserver 114.114.114.114EOF#Yum源更换为国内阿里源yum install wget telnet -ymv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backupwget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo#添加阿里的epel源#add the epelwget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo# rpm -ivh http://dl.Fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm#yum重新建立缓存yum clean allyum makecache#同步时间yum -y install ntp/usr/sbin/ntpdate cn.pool.ntp.orgecho "* 4 * * * /usr/sbin/ntpdate cn.pool.ntp.org > /dev/null 2>&1" >> /var/spool/cron/rootsystemctl restart crond.service#安装vim#yum -y install vim#设置最大打开文件描述符数echo "ulimit -SHn 102400" >> /etc/rc.localcat >> /etc/security/limits.conf << EOF* soft nofile 655350* hard nofile 655350EOF### * 表示对所有用户有限,soft指的是当前系统生效的设置,hard表明系统中所能设定的最大值,nofile表示所限制的资源是打开文件的最大数目,65535就是限制的数量#禁用selinuxsed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/configsetenforce 0#关闭防火墙systemctl disable firewalld.service systemctl stop firewalld.service #set sshsed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_configsed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_configsystemctl restart sshd.service#内核参数优化cat >> /etc/sysctl.conf << EOFvm.overcommit_memory = 1net.ipv4.ip_local_port_range = 1024 65536net.ipv4.tcp_fin_timeout = 1net.ipv4.tcp_mem = 94500000 915000000 927000000#tcp连接重用net.ipv4.tcp_tw_reuse = 1#tcp连接快速回收net.ipv4.tcp_tw_recycle = 1#262144允许等待中的监听net.core.somaxconn = 262144#这个参数应该设置足够大,以便能在一个共享内存段下容纳下整个的Innodb缓冲池的大小kernel.shmmax = 4294967295#告诉linux内核除非虚拟内存完全满了,否则不要使用交换区#vm.swappiness = 0net.ipv4.tcp_timestamps = 0net.ipv4.tcp_synack_retries = 1net.ipv4.tcp_syn_retries = 1net.ipv4.tcp_abort_on_overflow = 0#TCP接收和发送缓冲区默认大小和最大值net.core.wmem_default = 8388608net.core.rmem_default = 8388608net.core.rmem_max = 16777216net.core.wmem_max = 16777216#用于减少失效tcp所占用资源的时间net.ipv4.tcp_keepalive_time = 1200net.ipv4.tcp_keepalive_probes = 3net.ipv4.tcp_keepalive_intvl = 30net.core.netdev_max_backlog = 262144net.ipv4.tcp_max_orphans = 3276800net.ipv4.tcp_max_syn_backlog = 262144net.ipv4.netfilter.ip_conntrack_max = 2097152net.nf_conntrack_max = 655360net.netfilter.nf_conntrack_tcp_timeout_established = 1200ulimit -n 30000EOF/sbin/sysctl -p#vim定义退格键可删除最后一个字符类型echo 'alias vi=vim' >> /etc/profileecho 'stty erase ^H' >> /etc/profilecat >> /root/.vimrc << EOFset tabstop=4set shiftwidth=4set expandtabsyntax on"set numberEOF#update softyum -y update yum -y install vim tree net-tools lrzsz gcc*cat << EOF+-------------------------------------------------+| optimizer is done || it's recommond to restart this server ! |+-------------------------------------------------+EOF