centos7安装后的优化

涉及内容:
1.DNS
2.网络yum源
3.epel源
4.同步时间
5.安装vim
6.设置最大打开文件描述符数
7.禁用selinux
8.关闭防火墙
9.优化ssh连接速度
10.内核参数优化
11.设置vim退格键删除最后一个字符类型
12.更新内核
脚本如下:

#!/bin/bash
#author yundd 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
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
#同步时间
 ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
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
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#安装lrzsz实现win与linux之间的文件互相下载上传
yum -y install lrzsz

#设置最大打开文件描述符数
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_syncookies=1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout=120
net.ipv4.tcp_keepalive_time = 2400
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_max_tw_buckets = 5000
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

原文地址:https://www.cnblogs.com/yundd/p/11518030.html

时间: 2024-08-30 09:44:08

centos7安装后的优化的相关文章

CentOS最小安装后的优化

CentOS最小安装后的优化 添加了新服务器之后,下一步就是安装系统了.这里推荐使用CentOS系列,大家在用服务器时抱着一个原则:系统安装的应用程序包越少,服务器会越稳定,所以我们安装系统时尽量选择最小安装.至于服务器的单机性能优化,本周稳定安全的原则,尽量不要改动系统的原有的配置(CentOS自身的文件和内存机制就很优秀). 1.关闭不需要的服务 众所周知服务越少,系统占用的资源就会越少,所以应关闭不需要的服务. 建议关闭不需要的服务,这样做的好处是减少内存和CPU事件的占用.命令如下所示:

Centos 6.4 x86_64 最小化安装后的优化

Centos 6.4 x86_64 最小化安装后的优化 购买了服务器以后要做的第一件事就是安装操作系统了,这里推荐安装 Centos 6.4 x86_64,安装系统时要选择最小化安装(不需要图形),在使用服务器时要记住一个原则,系统安装的应用程序包越少,服务器就会越稳定.至于服务器单机性能调优,应本着稳定安全的原则,尽量不要改动系统原有的配置(Cetnos系统自身的文件和内存机制就很优秀),以下配置优化部分也适合Amazon Linux系统,大家可以对比参考. 系统的基础优化 1.更新yum官方

centos7 安装后,意外出现Please make your choice from above [&#39;q&#39; to quit | &#39;c&#39; to continue | &#39;r&#39; to refresh]

安装完成centos7后出现如下提示: Initial setup of CentOS Linux 7 (core) 1) [x] Creat user 2) [!] License information (no user will be created) (license not accepted) Please make your choice from above ['q' to quit | 'c' to continue | 'r' to refresh]: 解决方案: 输入[1],

CentOS7安装后系统配置及优化

配置国内源和epel源 cd /etc/yum.repos.d/mkdir repo_bakmv *.repo repo_bak/#基础源文件wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/Centos-7.repo#epel源文件 wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo#重新生成yum缓存yum clean a

Linux安装后基本优化思路

查看系统环境 [[email protected] ~]# cat /etc/redhat-release CentOS release 6.6 (Final) [[email protected] ~]# uname –a Linux xuliangwei.com 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux 1.精简开机系统 保留5个必须:sshd|rsyslo

centos7安装后恢复windows系统入口

现象描述: ================================================================================ 安装centos7后,原来的win7或win8没有进入系统的菜单 出错原因: ================================================================================ 一般我们都会先安装windows,在windows下分出硬盘空间来安装centos7:

CentOS7安装后无法使用鼠标选中

运行命令:yum install gpm*  安装gpm 启动gpm服务:service gpm start 运行systemctl enable gpm.servicere 添加到后台服务. 备注:CentOS7服务使用方法 服务使用方法systemctl start [服务文件名]systemctl restart [服务文件名]systemctl stop [服务文件名]systemctl status [服务文件名]设置开机启动systemctl enable [服务文件名]system

CentOS 5.8最小化安装后的优化

添置了新服务器以后,下一步就要安装系统了.这里推荐用CentOS 5.8 x86_64,大家在用服务器时抱着一个原则:系统安装的应用程序包越少,服务器会越稳定,所以我们安装系统时尽量选择最小化安装.至于服务器的单机性能调优,本着稳定安全的原则,尽量不要改动系统原有的配置(CentOS自身的文件和内存机制就很优秀). 关闭不需要的服务众所周知服务越少,系统占用的资源就会越少,所以应关闭不需要的服务.建议关闭不需要的服务,这样做的好处是减少内存和CPU时间的占用.命令如下所示:# ntsysv 下面

CentOS7安装后无法使用鼠标选中,复制问题解决

出现这种情况,一般是没有安装linux的鼠标服务器gpm gpm命令 是Linux的虚拟控制台下的鼠标服务器,用于在虚拟控制台下实现鼠标复制和粘贴文本的功能. 具体操作: 运行命令:yum install gpm*  安装gpm 启动gpm服务:service gpm start 运行systemctl enable gpm.servicere 添加到后台服务. 备注:CentOS7服务使用方法 服务使用方法systemctl start [服务文件名]systemctl restart [服务