zoukankan      html  css  js  c++  java
  • Centos7基础优化操作项

    1.基础优化操作项:更新yum源信息
    第一个:就近使用yum源地址,安装软件更快。
    curl -s -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    第二个:安装RHEL/CentOS官方源不提供的软件包
    curl -s -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

    2.安全优化:关闭SELinux及iptables(在工作场景中,如果有外部IP一般要打开iptables,高并发流量的服务器可能无法开启)

    # 关闭selinux
    sed -i 's#SELINUX=.*#SELINUX=disabled#g' /etc/selinux/config
    sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
    grep SELINUX=disabled /etc/selinux/config 
    setenforce 0
    getenforce

    3.关闭firewalld防火墙服务

    systemctl stop firewalld
    systemctl disable firewalld
    systemctl disable firewalld

    4.基础优化操作项:设置普通用户提权操作(可选优化)
    # 提权smile可以利用sudo

    useradd smile
    echo 123456|passwd --stdin smile
    cp /etc/sudoers /etc/sudoers.ori
    echo "smile ALL=(ALL) NOPASSWD: ALL " >>/etc/sudoers
    tail -1 /etc/sudoers
    visudo -c


    5.设置系统中文UTF8字符集

    [root@smile ~]# cat /etc/locale.conf
    LANG="en_US.UTF-8"
    修改命令如下:
    cp /etc/locale.conf /etc/locale.conf.ori
    echo 'LANG="zh_CN.UTF-8"' >/etc/locale.conf 
    source /etc/locale.conf 
    echo $LANG

    6.基础优化操作项:时间同步设置
    # 定时更新服务器时间,使其和互联网时间同步。

    yum install ntpdate -y
    /usr/sbin/ntpdate ntp3.aliyun.com
    
    echo '#crond-id-001:time sync' >>/var/spool/cron/root
    echo "*/5 * * * * /usr/sbin/ntpdate ntp3.aliyun.com >/dev/null 2>&1">>/var/spool/cron/root
    crontab -l

    7.基础优化操作项:提升命令行操作安全性(可选优化)
    # 超时时间、操作记录数更改(可选配置)

    echo 'export TMOUT=300' >>/etc/profile
    echo 'export HISTSIZE=500' >>/etc/profile
    echo 'export HISTFILESIZE=5' >>/etc/profile
    tail -3 /etc/profile
    . /etc/profile

    8.基础优化操作项:加大文件描述符

    # 实例演示:加大文件描述
    echo '* - nofile 65535 ' >>/etc/security/limits.conf 
    tail -1 /etc/security/limits.conf
    ulimit -SHn 65535 
    ulimit -n    #<==命令方式查看配置结果


    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
    net.core.wmem_default = 8388608
    net.core.rmem_default = 8388608
    net.core.wmem_max = 16777216
    net.core.rmem_max = 16777216
    EOF
    sysctl -p

    11.ssh服务配置优化:
    ####Start by smile#2019-04-26###
    Port 52113 #使用大于10000的端口
    PermitRootLogin no #禁止root远程登录,可以su - root,C7需要改yes为no
    PermitEmptyPasswords no #禁止空密码登录,C7默认就是

    UseDNS no #不使用dns解析,yes改为no
    GSSAPIAuthentication no #禁止连接慢的解决配置
    ListenAddress 172.16.1.61:52113 #只允许内网IP连接SSH(172.16.1.0)
    ####End by smile#2019-04-26###

    最终配置为:
    ####Start by smile#2019-04-26###
    PermitEmptyPasswords no
    UseDNS no
    GSSAPIAuthentication no
    #ListenAddress 172.16.1.7:22
    ####End by smile#2019-04-26###

    12.基础优化操作项:安装系统常用软件
    CentOS6和CentOS7都要安装的企业运维常用基础工具包

    yum install tree nmap dos2unix lrzsz nc lsof wget tcpdump htop iftop iotop sysstat nethogs -y


    CentOS7要安装的企业运维常用基础工具包

    yum install psmisc net-tools bash-completion vim-enhanced -y


    11.打补丁并升级有已知漏洞的软件。

    yum update

    12.锁定关键系统文件,如/etc/passwd,/etc/shadow,/etc/group,/etc/gshadow,/etc/inittab,处理以上内容后吧chattr、lsattr改名为oldboy,转移走,这样就安全多了。

    13.清空/etc/isuue、/etc/issue.net,去除系统及内核版本登录前的屏幕显示。

    1 >/etc/issue
    2 >/etc/issue.net
    3 cat /etc/issue
    4 cat /etc/issue.net
  • 相关阅读:
    C#-WebForm-★★★JQuery-动画★★★
    C#-WebForm-★★★JQuery知识——DOM操作★★★
    C#-WebForm-★★★JQuery知识——基础知识、选择器、事件★★★
    C#-WebForm-组合查询(Queryable延迟查询、Intersect交集)、分页展示基础
    C#-WebForm-★★★LinQ-数据的条件组合查询并进行分页展示(未加各种限定)★★★
    C#-WebForm-光棒效果
    C#-WebForm-LinQ-条件精确查询、高级查询
    C#-WebForm-LinQ(一)-LinQ:语言集成查询(Language Integrated Query)-增删改查、属性扩展
    C#-WebForm JS定时器
    ★★★正则表达式★★★
  • 原文地址:https://www.cnblogs.com/--smile/p/11809991.html
Copyright © 2011-2022 走看看