前言

以下内容为个人最小化安装后的初始化配置记录,不一定适用于所有场景。

更换yum源为阿里云

替换 yum 源,安装 epel 源。yum-axelget用于加速 yum 下载

  1. yum install -y epel-release lrzsz wget yum-axelget
  2. mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
  3. wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  4. wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
  5. yum clean all
  6. yum makecache

安装一些基本工具

  1. yum install -y vim gcc gcc-c++ python3 python3-pip curl net-tools unzip sysstat tcpdump rsync supervisor iptables iotop yum-utils yum-axelget tree dos2unix ntp fio mlocate lsof

关闭 NetworkManager

如果要做 kvm 虚拟化的话,NetworkManager一定要关

  1. systemctl stop NetworkManager && systemctl disable NetworkManager

关闭selinux

  1. setenforce 0
  2. sed -i 's/^SELINUX=.*$/SELINUX=disabled/' /etc/selinux/config

增加可打开的最大文件描述符数

  1. cat >> /etc/security/limits.conf <<EOF
  2. * soft nofile 65535
  3. * hard nofile 65535
  4. EOF

调整系统参数

  1. cat >> /etc/sysctl.conf << EOF
  2. net.ipv4.ip_forward = 1
  3. net.ipv6.conf.all.disable_ipv6 = 1
  4. net.ipv6.conf.default.disable_ipv6 = 1
  5. net.core.somaxconn = 2048
  6. net.ipv4.ip_local_port_range= 1024 65535
  7. net.core.rmem_default = 262144
  8. net.core.wmem_default = 262144
  9. fs.file-max = 104857
  10. net.core.rmem_max = 16777216
  11. net.core.wmem_max = 16777216
  12. net.ipv4.tcp_rmem = 4096 4096 16777216
  13. net.ipv4.tcp_wmem = 4096 4096 16777216
  14. net.ipv4.tcp_mem = 786432 3145728 4194304
  15. net.ipv4.tcp_max_syn_backlog = 16384
  16. net.core.netdev_max_backlog = 20000
  17. net.ipv4.tcp_fin_timeout = 15
  18. net.ipv4.tcp_max_syn_backlog = 16384
  19. net.ipv4.tcp_tw_reuse = 1
  20. net.ipv4.tcp_tw_recycle = 1
  21. net.ipv4.tcp_max_orphans= 131072
  22. vm.swappiness=1
  23. EOF
  24. sysctl -p

关闭swap

  1. swapoff -a
  2. sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

关闭firewalld

  1. systemctl stop firewalld.service && systemctl disable firewalld.service

设定ntp时间同步

  1. yum install ntp -y
  2. # 设置时区
  3. timedatectl set-timezone Asia/Shanghai
  4. # 或
  5. mv /etc/localtime /etc/localtime_bak
  6. cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  7. # 手动同步时间
  8. ntpdate asia.pool.ntp.org
  9. # 修改/etc/ntp.conf,将原有的几个server注释,改为
  10. server time1.cloud.tencent.com
  11. server time2.cloud.tencent.com
  12. server time3.cloud.tencent.com
  13. server time4.cloud.tencent.com
  14. server time5.cloud.tencent.com
  15. # 启动ntpd
  16. systemctl start ntpd
  17. systemctl enable ntpd

设置history时间戳

  1. echo 'export HISTTIMEFORMAT="%F %T `whoami` "' >> /etc/profile && source /etc/profile

配置vimrc

  1. set smarttab
  2. set tabstop=4
  3. set expandtab
  4. set softtabstop=4
  5. set shiftwidth=4
  6. set nobackup
  7. set noswapfile
  8. set encoding=utf-8
  9. syntax on
  10. set hlsearch

配置pip源为阿里云

  1. mkdir -p ~/.pip
  2. vim ~/.pip/pip.conf
  1. [global]
  2. index-url = https://mirrors.aliyun.com/pypi/simple/
  3. [install]
  4. trusted-host=mirrors.aliyun.com