CentOS 7 优化脚本

CentOS 7 优化脚本

#!/bin/bash
#this script is only for CentOS 7.x

platform=`uname -i`
if [ $platform != "x86_64" ];then
echo "脚本仅适合64位CentOS 7系统"
exit 1
fi
echo "----------CentOS 7 64位系统,开始优化----------"

#添加公网DNS地址
cat >> /etc/resolv.conf << EOF
nameserver 114.114.114.114
EOF

#修改字符集
sed -i ‘s/LANG="en_US.UTF-8"/LANG="zh_CN.UTF-8"/‘ /etc/locale.conf

#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,可适当添加vim配置
yum -y install vim  tree wget lrzsz net-tools bash-completion

#设置最大打开文件描述符数
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 

#配置 ssh
sed -i ‘s/#UseDNS yes/UseDNS no/‘ /etc/ssh/sshd_config   #禁止DNS反向解析客户端
sed -i ‘s/#Port 22/Port 2223/‘ /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

#系统服务优化,可适当选择下列服务
SERVICES="acpid atd auditd avahi-daemon avahi-dnsconfd bluetooth conman cpuspeed cups dnsmasq dund firstboot hidd httpd ibmasm ip6tables irda kdump lm_sensors mcstrans messagebus microcode_ctl netconsole netfs netplugd nfs nfslock nscd oddjobd pand pcscd portmap psacct rdisc restorecond rpcgssd rpcidmapd rpcsvcgssd saslauthd sendmail setroubleshoot smb vncserver winbind wpa_supplicant ypbind"
for service in $SERVICES
do
#关闭所选服务随系统启动
systemctl disable $SERVICES
#停止所选的服务
systemctl stop $SERVICES
done

echo "------------------优化完成--------------------"

原文地址:http://blog.51cto.com/innocence/2328260

时间: 2024-10-19 12:19:05

CentOS 7 优化脚本的相关文章

centos一键优化脚本

centos一键优化脚本:细节:http://oldboy.blog.51cto.com/2561410/1336488网络状态优化:http://oldboy.blog.51cto.com/2561410/1184228定时任务优化:http://oldboy.blog.51cto.com/2561410/1216730一键脚本:较简单: http://mofansheng.blog.51cto.com/8792265/1710247较健全: http://chocolee.blog.51ct

centos开机优化脚本

CentOS 6.5初始化优化脚本

#!/bin/bash echo "这个是系统初始化脚本,请慎重运行!" input_fun() {     OUTPUT_VAR=$1     INPUT_VAR=""     while [ -z $INPUT_VAR ];do         read -p "$OUTPUT_VAR" INPUT_VAR     done     echo $INPUT_VAR } input_again() { MYHOSTNAME=$(input_fu

刚搭建的linux环境的基本优化以及优化脚本---菜鸟初写

本篇博文主要是参考并借鉴老男孩老师的优秀博文外加自己总结及写的优化脚本!博文地址:http://oldboy.blog.51cto.com/2561410/1336488 虽然我并没有参加过老男孩老师的培训但是看过他的优秀视频和优秀博文,接受过他的熏陶与教育,在这里十分感谢老男孩老师!!! 还有这篇博文之中一些操作与脚本的编写非常感谢京峰老师们的帮助! 主要优化的目录 我使用的linux版本是CentOS6.6 x86_64 1.网络配置优化 2.关闭selinux及清除iptables链 3.

CentOS6.x 优化脚本

这个是CentOS安装常用软件及优化脚本: #! /bin/sh # update yumyum -y updateyum upgrade -y # 1.安装yum优先级插件yum install yum-priorities # 2.epelrpm -Uvh http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpmrpm -Uvh http://rpms.famillecollet.com/enter

centos mysql 优化 第二十三节课

centos mysql  优化  第二十三节课 f

centos mysql 优化 第二十一节课

centos mysql  优化  第二十一节课 f

centos mysql 优化 第十九节课

centos mysql  优化  第十九节课 f

centos mysql 优化 第十八节课

centos mysql  优化  第十八节课 f