美文网首页
CentOS 7系统基础优化

CentOS 7系统基础优化

作者: 万越天 | 来源:发表于2017-09-15 14:42 被阅读0次

    1.时间设置

    检查是否为+0800时区:

    # date -R
    Tue, 22 Nov 2016 18:46:14 +0800
    
    

    如果不是+0800时区,处理方法:

    cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
    timedatectl set-timezone Asia/Shanghai
    

    2.yum仓库

    mv /etc/yum.repos.d/* /tmp
    vi /etc/yum.repos.d/guoxin.repo
    

    编辑/etc/yum.repos.d/guoxin.repo如下:

    [guoxin-base]
    name=Guoxin-$releasever - Base - http://repo.91guoxin.bj
    baseurl=http://10.10.10.70:8080/7/base/
    enable=1
    gpgcheck=0
    [guoxin-epel]
    name=Guoxin-$releasever - Base - http://repo.91guoxin.bj 
    baseurl=http://10.10.10.70:8080/7/epel/
    enable=1
    gpgcheck=0
    [guoxin-extras]
    name=Guoxin-$releasever - Base - http://repo.91guoxin.bj 
    baseurl=http://10.10.10.70:8080/7/extras/
    enable=1
    gpgcheck=0
    [guoxin-updates]
    name=Guoxin-$releasever - Base - http://repo.91guoxin.bj 
    baseurl=http://10.10.10.70:8080/7/updates/
    enable=1
    gpgcheck=0
    [guoxin-zabbix]
    name=Guoxin-$releasever - Base - http://repo.91guoxin.bj
    baseurl=http://10.10.10.70:8080/7/zabbix/
    enable=1
    gpgcheck=0
    

    3.时间同步

    检查ntpdate命令是否存在:

    # which ntpdate
    /usr/sbin/ntpdate
    

    如果没有ntpdate命令,则:

    yum install ntpdate -y
    

    手动同步时间:

    /sbin/ntpdate 10.10.10.70 ; /sbin/clock -w
    

    添加时间同步定时任务:

    crontab -e
    
    # Time sync
    5 0 * * * /sbin/ntpdate 10.10.10.70 ; /sbin/clock -w 1>/dev/null 2>&1
    

    检查定时任务是否添加成功:

    crontab -l
    

    4.安装常用命令包

    yum install lrzsz tree vim net-tools -y
    
    

    5.安装bash shell

    cd /usr/local/src/
    rz -y
    rpm -ivh bash-4.3.30-1.el7.centos.x86_64.rpm --force
    mv /bin/bash /bin/bash.bak && cp /usr/local/bin/bash /bin
    

    6.配置rsyslog

    修改配置文件:

    vim /etc/rsyslog.conf 
    

    最后一行增加如下配置:

    *.* @10.10.10.71
    

    检查配置:

    tail -1 /etc/rsyslog.conf 
    
    *.* @10.10.10.71
    

    重启rsyslog服务

    systemctl restart rsyslog
    

    7.内核参数

    修改配置文件:

    \vi /etc/sysctl.conf 
    
    
    vm.overcommit_memory = 1
    net.ipv4.ip_forward = 0
    net.ipv4.conf.default.rp_filter = 1
    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_rmem = 32768 436600 16777216
    net.ipv4.tcp_wmem = 32768 436600 16777216
    net.ipv4.tcp_max_orphans = 3276800
    net.core.wmem_default = 8388608
    net.core.rmem_default = 8388608
    net.core.rmem_max = 16777216
    net.core.wmem_max = 16777216
    net.ipv4.tcp_synack_retries = 1
    net.ipv4.tcp_syn_retries = 2
    net.ipv4.ip_local_port_range = 1024 65000
    net.ipv4.tcp_tw_recycle = 1
    net.ipv4.tcp_tw_reuse = 1
    net.ipv4.tcp_max_tw_buckets = 10000
    net.ipv4.tcp_fin_timeout = 30
    net.ipv4.tcp_keepalive_time = 1200
    net.ipv4.tcp_timestamps = 0
    net.ipv4.tcp_max_syn_backlog = 65536
    net.core.netdev_max_backlog = 262144
    fs.file-max = 102400 
    vm.swappiness = 5
    

    执行sysctl -p使配置生效:

    sysctl -p
    

    8.rm命令替换为mv

    mkdir /data/dustbin -p
    chmod 777 /data/dustbin
    vim /etc/profile
    

    结尾增加:

    saferm ()
    {
            if [ ! -d /data/dustbin ]
            then
                    mkdir -p /data/dustbin
                    chmod 777 /data/dustbin
                    if [ $? -ne 0 ]
                    then
                            echo "Error: failed to create /export/dustbin"
                    fi
            fi
            local dst=`mktemp -d -p /data/dustbin`
            local arg=`echo $* | sed "s/\(^-\w\+\)\|\(\s-\w\+\)/ /g"`
            mv ${arg} ${dst}
    }
    
    alias rm='saferm'
    
    

    使配置生效:

    . /etc/profile
    

    9.ssh优化

    运维专用账户 opsuser

    # useradd opsuser -d /data/opsuser
    # visudo
    

    sudo授权

    opsuser ALL=(ALL)       NOPASSWD: ALL
    

    切换到opsuser用户

    su - opsuser
    id opsuser
    

    检查UID是否为1000

    uid=1000(opsuser) gid=1000(opsuser) groups=1000(opsuser)
    

    配置key认证登陆(密钥文件夹700权限):

    mkdir .ssh
    chmod 700 .ssh
    vim .ssh/authorized_keys
    

    添加运维人员的公钥

    .... xxx@91guoxin.com
    .... xxx@91guoxin.com
    

    密钥文件600权限:

    chmod 600 .ssh/authorized_keys
    

    注:需检查key认证是否成功

    改变监听地址

    监听本机内网IP地址:

    获取本机内网IP地址:

    ifconfig eth0|awk -F "[ :]+" 'NR==2{print $3}'
    
    10.10.10.136
    

    修改ssh配置文件

    vim /etc/ssh/sshd_config
    
    ListenAddress 10.10.10.136
    

    禁用root ssh登陆

    vim /etc/ssh/sshd_config
    
    PermitRootLogin no
    

    重启sshd

    systemctl restart sshd
    

    检查监听地址是否生效:

    netstat -lntup|grep sshd
    
    tcp        0      0 10.10.10.136:22         0.0.0.0:*               LISTEN      9997/sshd
    

    注:还需检查root是否可以通过ssh登录

    10.ulimit

    echo '* soft nofile 102400' >> /etc/security/limits.conf
    echo '* hard nofile 102400' >> /etc/security/limits.conf
    echo '* soft nproc 102400' >> /etc/security/limits.conf
    echo '* hard nproc 102400' >> /etc/security/limits.conf
    ulimit -SHn 102400
    ulimit -n
    

    11.zabbix监控

    yum install zabbix-agent -y
    

    通过ansible同步72配置文件和脚本到本地(在/data/opsuser/ansible/config/hosts增加本机的组)

    ansible -s 10.10.10.136 -m copy -a "src=/etc/zabbix/ dest=/etc/zabbix/ owner=root group=root"
    

    重启zabbix-agent

    systemctl restart zabbix-agent
    
    

    登录 http://10.10.10.70/zabbix/ 增加该主机并添加模板

    • guoxin base
    • Template OS Linux
    • Template_Linux_Disk_IO_Stats

    注:其他模板根据业务需求添加

    12.加入跳板机

    登陆10.10.10.71进行配置:

    [root@idc01-cloud-manage-node-02 proxyd]# pwd
    /usr/local/proxyd
    [root@idc01-cloud-manage-node-02 proxyd]# ls
    log  proxyd.sh  server.cfg  user.cfg
    

    注:在server.cfg添加新的服务器 并在user.cfg进行授权

    13.目录规范

    运维工具安装包:/usr/local/src

    运维工具安装目录:/application

    脚本目录:/server/scripts

    日志目录:/data/logs

    相关文章

      网友评论

          本文标题:CentOS 7系统基础优化

          本文链接:https://www.haomeiwen.com/subject/zhwssxtx.html