脚本如下,后续继续优化

#!/bin/bash
#author junxi by
#this script is only for CentOS 7.x
#check the OS platform=`uname -i`
if [ $platform != "x86_64" ];then
echo "this script is only for 64bit Operating System !"
exit 1
fi
echo "the platform is ok"
cat << EOF
+---------------------------------------+
| your system is CentOS 7 x86_64 |
| start optimizing....... |
+---------------------------------------
EOF #添加公网DNS地址
cat >> /etc/resolv.conf << EOF
nameserver 114.114.114.114
EOF
#Yum源更换为国内阿里源
yum install wget telnet -y
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo #添加阿里的epel源
#add the epel
wget -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 all
yum makecache
#同步时间
yum -y install ntp
/usr/sbin/ntpdate cn.pool.ntp.org
echo "* 4 * * * /usr/sbin/ntpdate cn.pool.ntp.org > /dev/null 2>&1" >> /var/spool/cron/root
systemctl restart crond.service #安装vim
yum -y install vim #设置最大打开文件描述符数
echo "ulimit -SHn 102400" >> /etc/rc.local
cat >> /etc/security/limits.conf << EOF
* soft nofile 655350
* hard nofile 655350
EOF #禁用selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce 0 #关闭防火墙
systemctl disable firewalld.service
systemctl stop firewalld.service #set ssh
sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_config
sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
systemctl restart sshd.service #内核参数优化
cat >> /etc/sysctl.conf << EOF
vm.overcommit_memory = 1
net.ipv4.ip_local_port_range = 1024 65536
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_abort_on_overflow = 0
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.ipv4.netfilter.ip_conntrack_max = 2097152
net.nf_conntrack_max = 655360
net.netfilter.nf_conntrack_tcp_timeout_established = 1200
EOF
/sbin/sysctl -p #vim定义退格键可删除最后一个字符类型
echo 'alias vi=vim' >> /etc/profile
echo 'stty erase ^H' >> /etc/profile
cat >> /root/.vimrc << EOF
set tabstop=4
set shiftwidth=4
set expandtab
syntax on
"set number
EOF #update soft
yum -y update cat << EOF
+-------------------------------------------------+
| optimizer is done |
| it's recommond to restart this server ! |
+-------------------------------------------------+
EOF

作者:君惜丶
链接:https://www.jianshu.com/p/f9ea135af86a
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

Centos 7系统优化脚本的更多相关文章

  1. linux centos6 系统优化脚本-经典

    转载一篇Ricky的系统优化脚本,这个脚本只能针对centos6x 其他还没有测试,但centos7肯定不行的 #!/bin/bash # ID 201510192126 # Author Ricky ...

  2. centos一键优化脚本

    centos一键优化脚本:细节:http://oldboy.blog.51cto.com/2561410/1336488网络状态优化:http://oldboy.blog.51cto.com/2561 ...

  3. [转]CentOS开机启动脚本

    转载自http://www.2cto.com/os/201306/220559.html   我的一个Centos开机自启动脚本的制作   一.切换到/etc/init.d/   二.制作sh脚本 v ...

  4. Centos开机自启动脚本的制作

    原文地址:http://www.2cto.com/os/201306/220559.html 我的一个Centos开机自启动脚本的制作   一.切换到/etc/init.d/   二.制作sh脚本 v ...

  5. centos 7 初始化脚本

    #!/bin/bash # 时间: 2018-11-21 # 作者: HuYuan # 描述: CentOS 7 初始化脚本 # 加载配置文件 if [ -n "${1}" ];t ...

  6. centos7 系统优化脚本

    脚本一: #!/usr/bin/env bash #设置环境变量 export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sb ...

  7. centos6 系统优化脚本

    #!/bin/bash # 检查是否为root用户,脚本必须在root权限下运行 # if [[ "$(whoami)" != "root" ]]; then ...

  8. 解决方案:centos运行shell脚本时报“$'\r': 未找到命令”

    =============================================== 2018/9/12_第1次修改                       ccb_warlock == ...

  9. 四、Centos linux系统优化

    1.     无论是哪个版本的linux,都会提供32位和64位的两个版本的镜像. i386为32位 x86_64为64位 两者的区别: 1)目标:需要大量的内存需求的行业为64位,普通用户的需求为3 ...

随机推荐

  1. Redis能干啥?细看11种Web应用场景

    下面列出11种Web应用场景,在这些场景下可以充分的利用Redis的特性,大大提高效率. 1.在主页中显示最新的项目列表. Redis使用的是常驻内存的缓存,速度非常快.LPUSH用来插入一个内容ID ...

  2. mysql中OPTIMIZE TABLE的作用

    转载▼ 1.先来看看多次删除插入操作后的表索引情况 mysql> SHOW INDEX FROM `tbl_name`; +----------+------------+----------- ...

  3. 用IDEA/WebStrom 提交本地项目到Git/码云等

    以码云为例: 在码云上创建新的项目. webstrom/idea 打开本地项目

  4. js计算元素距离顶部的高度及元素是否在可视区判断

    前言: 在业务当中,我们经常要计算元素的大小和元素在页面的位置信息.比如说,在一个滚动区域内,我要知道元素A是在可视区内,还是在隐藏内容区(滚动到外边看不到了).有时还要进一步知道,元素是全部都显示在 ...

  5. python_18_反射

    什么是反射? -- 通过输入字符串来获取和修改 类(属性+方法),用字符串来映射内存对象,用于人机交互 反射有哪几种方法? -- getattr()                   --获取字符串 ...

  6. jdbc与java.sql

    JDBC连接操作数据库流程:1.将数据库驱动jar包放在lib文件夹下. 2.定义驱动名(driver),数据库url,username,password字符串常量 3.注册数据库驱动Class.fo ...

  7. Curl是什么,原文地址:http://www.phpchina.com/portal.php?mod=view&aid=40161

    Curl是什么PHP supports libcurl, a library created by Daniel Stenberg, that allows you to connect and co ...

  8. PHP中文网上的分页代码

    page.php <html> <head> <meta http-equiv="CONTENT-TYPE" content="text/h ...

  9. kickstart无人值守

    笔者Q:972581034 交流群:605799367.有任何疑问可与笔者或加群交流 高逼格装系统的方法 Kickstar Cobbler 注意,kickstart并不是一个服务的名称,只是装系统的方 ...

  10. SQL查询系列1---

    1.查询关系为夫妻,年龄相加大于60的信息 表1 信息表 info id 编号   sex 性别 0-女,1-男 age 年龄   表2 关系表 rel id1 编号1 外键 id2 编号2 外键 r ...