Linux 服务器装机后优化 参考

https://blog.csdn.net/u010133338/article/details/81055475

优化初始化脚本

vim init_optimization.sh

#!/bin/bash
#author by cc
#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
nameserver 223.5.5.5
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 wget net-tools screen lsof tcpdump nc mtr openssl-devel vim bash-completion lrzsz nmap telnet tree ntpdate bash-completion chrony
#同步时间
yum -y install ntp
sed -i 's/server 0.centos.pool.ntp.org iburst/server ntp1.aliyun.com iburst/' /etc/ntp.conf
sed -i 's/server 1.centos.pool.ntp.org iburst/server ntp2.aliyun.com iburst/' /etc/ntp.conf
sed -i 's/server 2.centos.pool.ntp.org iburst/server ntp3.aliyun.com iburst/' /etc/ntp.conf
systemctl restart ntpd.service
#设置最大打开文件描述符数
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
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
net.ipv4.ip_forward = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 30
net.ipv4.ip_local_port_range = 1024 65000
fs.file-max = 655350
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.default.secure_redirects = 0
vm.swappiness = 10
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
 
#

最新文章

  1. 项目游戏开发日记 No.0x00000
  2. [数据库]cakephp操作ENUM、tinyint等类型的一点说明
  3. TransparentBlt、StretchBlt与BitBlt三个函数的区别
  4. [置顶] HTML语义和前端架构
  5. TCP连接的建立与关闭
  6. delphi 提取字符中的数字
  7. Spring学习笔记--依赖注入
  8. string,stringbuilder和stringbuffer的区别
  9. Druid的简介及功能
  10. 【jdbc访问数据库获取执行sql转换json】
  11. Python下关于RSA解密模块的使用
  12. IDEA2017 免费激活方法
  13. gflags 学习
  14. Python的随机数模块
  15. [算法专题] BST&amp;AVL&amp;RB-Tree
  16. ElasticSearch 之 dis_max tie_break的应用
  17. JFinal上传文件时用getFile()方法报错
  18. C语言字节对齐问题详解
  19. Rufus 制作 USB 启动盘简单教程
  20. Windows自动执行java脚本

热门文章

  1. Array(数组)对象--&gt;pop() 方法
  2. Python设计模式(3)-工厂方法模式
  3. 登陆ECP后,无法正常现实OU
  4. Odoo 查看 模块app 对应的 源码 相关依赖模块信息
  5. 多线程高并发编程(4) -- ReentrantReadWriteLock读写锁源码分析
  6. 爬虫的新手使用教程(python代理IP)
  7. stand up meeting 1/7/2016
  8. 包、mode模式、if-else语句、switch语句
  9. Oracle计算数值型的幂次方——POWER()
  10. Spring5:控制反转