zoukankan      html  css  js  c++  java
  • 所有服务器模版机的基本优化

    1、关闭selinux

    sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
    grep SELINUX=disabled /etc/selinux/config 
    setenforce 0
    getenforce
     
    2、关闭iptables 
    /etc/init.d/iptables stop
    /etc/init.d/iptables stop
    chkconfig iptables off
     
    3、精简开机自启动服务
    chkconfig|egrep -v "crond|sshd|network|rsyslog|sysstat"|awk '{print "chkconfig",$1,"off"}'|bash
    export LANG=en
    chkconfig --list|grep 3:on
     
    4、提权oldboy可以sudo
    useradd oldboy
    echo 123456|passwd --stdin oldboy
    cp /etc/sudoers /etc/sudoers.ori
    echo "oldboy  ALL=(ALL) NOPASSWD: ALL " >>/etc/sudoers
    tail -1 /etc/sudoers
    visudo -c
     
    5、中文字符集
    cp /etc/sysconfig/i18n /etc/sysconfig/i18n.ori
    echo 'LANG="zh_CN.UTF-8"'  >/etc/sysconfig/i18n 
    source /etc/sysconfig/i18n
    echo $LANG
     
    6、时间同步
    echo '#time sync by oldboy at 2010-2-1' >>/var/spool/cron/root
    echo '*/5 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1' >>/var/spool/cron/root
    crontab -l
     
    7、命令行安全
    echo 'export TMOUT=3000' >>/etc/profile
    echo 'export HISTSIZE=100' >>/etc/profile
    echo 'export HISTFILESIZE=100' >>/etc/profile
    tail -3 /etc/profile
    . /etc/profile
     
    8、加大文件描述
    echo '*               -       nofile          65535 ' >>/etc/security/limits.conf 
    tail -1 /etc/security/limits.conf 
     
    9、内核优化
    cat >>/etc/sysctl.conf<<EOF
    net.ipv4.tcp_fin_timeout = 2
    net.ipv4.tcp_tw_reuse = 1
    net.ipv4.tcp_tw_recycle = 1
    net.ipv4.tcp_syncookies = 1
    net.ipv4.tcp_keepalive_time = 600
    net.ipv4.ip_local_port_range = 4000    65000
    net.ipv4.tcp_max_syn_backlog = 16384
    net.ipv4.tcp_max_tw_buckets = 36000
    net.ipv4.route.gc_timeout = 100
    net.ipv4.tcp_syn_retries = 1
    net.ipv4.tcp_synack_retries = 1
    net.core.somaxconn = 16384
    net.core.netdev_max_backlog = 16384
    net.ipv4.tcp_max_orphans = 16384
    #以下参数是对iptables防火墙的优化,防火墙不开会提示,可以忽略不理。
    net.nf_conntrack_max = 25000000
    net.netfilter.nf_conntrack_max = 25000000
    net.netfilter.nf_conntrack_tcp_timeout_established = 180
    net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120
    net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60
    net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120
    EOF
     
    yum install lrzsz nmap tree dos2unix nc -y
    yum update或yum upgrade
    yum -y update
    升级所有包,改变软件设置和系统设置,系统版本内核都升级
    yum -y upgrade
    升级所有包,不改变软件设置和系统设置,系统版本升级,内核不改变
     
     Linux基础优化与安全重点小结
    1)不用root登录管理系统,而以普通用户登录通过sudo授权管理。
    2)更改默认的远程连接SSH服务端口,禁止root用户远程连接,甚至要更改SSH服务只监听内网IP。
    3)定时自动更新服务器的时间,使其和互联网时间同步。
    4)配置yum更新源,从国内更新源下载安装软件包。
    5)关闭SELinux及iptables(在工作场景中,如果有外部IP一般要打开iptables,高并发高流量的服务器可能无法开启)。
    6)调整文件描述符的数量,进程及文件的打开都会消耗文件描述符数量。
    7)定时自动清理邮件临时目录垃圾文件,防止磁盘的inodes数被小文件占满(注意Centos6和Centos5要清除的目录不同)。
    8)精简并保留必要的开机自启动服务(如crond、sshd、network、rsyslog、sysstat)。
    9)Linux内核参数优化/etc/sysctl.conf,执行sysctl -p生效。
    10)更改系统字符集为“zh_CN.UTF-8”,使其支持中文,防止出现乱码问题。
    11)锁定关键系统文件如/etc/passwd、/etc/shadow、/etc/group、/etc/gshadow、/etc/inittab, 处理以上内容后把chattr、lsattr改名为oldboy,转移走,这样就安全多了。
    12)清空/etc/issue、/etc/issue.net,去除系统及内核版本登录前的屏幕显示。
    13)清除多余的系统虚拟用户账号。
    14)为grub引导菜单加密码。
    15)禁止主机被ping。
    16)打补丁并升级有已知漏洞的软件。
  • 相关阅读:
    聊聊、最新 IDEA 2019.3.3 版本 注册码 有效期 2089
    聊聊、Spring自动扫描器
    聊聊、JVM 第一篇
    聊聊、AES 和 DES
    聊聊、Spring WebApplicationInitializer
    聊聊、Java SPI
    聊聊、Spring ServletContainerInitializer
    《Redis
    《Redis
    《Redis
  • 原文地址:https://www.cnblogs.com/liuqiang0/p/8528216.html
Copyright © 2011-2022 走看看