• CentOS安装操作系统级初始优化


    .作者:邓聪聪

    一.SSH 连接速度慢优化

    同步时间:timedatectl list-timezones

    1>.关闭DNS PTR反向查询

      UseDNS 选项打开状态下,当客户端试图登录SSH服务器时,服务器端先根据客户端的IP地址进行DNS PTR反向查询出客户端的主机名,然后根据查询出的客户端主机名进行DNS正向A记录查询,验证与其原始IP地址是否一致,这是防止客户端欺骗的一种措施,但一般我们的是动态IP不会有PTR记录,打开这个选项不过是在白白浪费时间而已,不如将其关闭。

    [root@node101 ~]# 
    [root@node101 ~]# grep UseDNS /etc/ssh/sshd_config 
    #UseDNS yes
    [root@node101 ~]# 
    [root@node101 ~]# sed -i 's@#UseDNS yes@UseDNS no@g' /etc/ssh/sshd_config
    [root@node101 ~]# 
    [root@node101 ~]# grep UseDNS /etc/ssh/sshd_config 
    UseDNS no
    [root@node101 ~]#

    2>.关闭GSSAPI身份验证

      GSSAPIAuthentication  当这个参数开启( GSSAPIAuthentication  yes )的时候,通过SSH登陆服务器时候会有些会很慢!这是由于服务器端启用了GSSAPI。登陆的时候客户端需要对服务器端的IP地址进行反解析,如果服务器的IP地址没有配置PTR记录,那么就容易在这里卡住了。

    [root@node101 ~]# grep GSSAPIAuthentication /etc/ssh/sshd_config 
    GSSAPIAuthentication yes
    [root@node101 ~]# 
    [root@node101 ~]# sed -i 's@^GSSAPIAuthentication yes@GSSAPIAuthentication no@g' /etc/ssh/sshd_config
    [root@node101 ~]# 
    [root@node101 ~]# grep GSSAPIAuthentication /etc/ssh/sshd_config 
    GSSAPIAuthentication no
    [root@node101 ~]# 
    [root@node101 ~]# systemctl restart sshd
    [root@node101 ~]#

    二.更换yum源

    1>.创建备份目录

    [root@node101 ~]# ll /etc/yum.repos.d/
    total 28
    -rw-r--r--. 1 root root 1664 Dec  9  2015 CentOS-Base.repo
    -rw-r--r--. 1 root root 1309 Dec  9  2015 CentOS-CR.repo
    -rw-r--r--. 1 root root  649 Dec  9  2015 CentOS-Debuginfo.repo
    -rw-r--r--. 1 root root  290 Dec  9  2015 CentOS-fasttrack.repo
    -rw-r--r--. 1 root root  630 Dec  9  2015 CentOS-Media.repo
    -rw-r--r--. 1 root root 1331 Dec  9  2015 CentOS-Sources.repo
    [root@node101 ~]# mkdir -p /etc/yum.repos.d/{default,back}
    [root@node101 ~]# ll /etc/yum.repos.d/
    total 28
    drwxr-xr-x. 2 root root    6 Mar  3 05:34 back
    -rw-r--r--. 1 root root 1664 Dec  9  2015 CentOS-Base.repo
    -rw-r--r--. 1 root root 1309 Dec  9  2015 CentOS-CR.repo
    -rw-r--r--. 1 root root  649 Dec  9  2015 CentOS-Debuginfo.repo
    -rw-r--r--. 1 root root  290 Dec  9  2015 CentOS-fasttrack.repo
    -rw-r--r--. 1 root root  630 Dec  9  2015 CentOS-Media.repo
    -rw-r--r--. 1 root root 1331 Dec  9  2015 CentOS-Sources.repo
    -rw-r--r--. 1 root root 1952 Dec  9  2015 CentOS-Vault.repo
    drwxr-xr-x. 2 root root    6 Mar  3 05:34 default
    [root@node101 ~]# mkdir -p /etc/yum.repos.d/{default,back}
    View Code

    2>.备份所有默认的配置文件

    [root@node101 ~]# ll /etc/yum.repos.d/
    total 28
    drwxr-xr-x. 2 root root    6 Mar  3 05:34 back
    -rw-r--r--. 1 root root 1664 Dec  9  2015 CentOS-Base.repo
    -rw-r--r--. 1 root root 1309 Dec  9  2015 CentOS-CR.repo
    -rw-r--r--. 1 root root  649 Dec  9  2015 CentOS-Debuginfo.repo
    -rw-r--r--. 1 root root  290 Dec  9  2015 CentOS-fasttrack.repo
    -rw-r--r--. 1 root root  630 Dec  9  2015 CentOS-Media.repo
    -rw-r--r--. 1 root root 1331 Dec  9  2015 CentOS-Sources.repo
    -rw-r--r--. 1 root root 1952 Dec  9  2015 CentOS-Vault.repo
    drwxr-xr-x. 2 root root    6 Mar  3 05:34 default
    [root@node101 ~]# mv /etc/yum.repos.d/*repo /etc/yum.repos.d/default/
    [root@node101 ~]# 
    [root@node102 ~]# ll /etc/yum.repos.d/
    total 4
    drwxr-xr-x. 2 root root    6 Mar  3 05:34 back
    drwxr-xr-x. 2 root root 4096 Mar  3 05:34 default
    [root@node101 ~]# mv /etc/yum.repos.d/*repo /etc/yum.repos.d/default/
    View Code

    3>.获取yum 源

    [root@node101 ~]# ll /etc/yum.repos.d/
    total 4
    drwxr-xr-x. 2 root root    6 Mar  3 05:34 back
    drwxr-xr-x. 2 root root 4096 Mar  3 05:34 default
    [root@node101 ~]# 
    [root@node101 ~]# 
    [root@node101 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
     2523  100  2523    0     0  15349      0 --:--:-- --:--:-- --:--:-- 15478
    
    [root@node101 ~]# ll /etc/yum.repos.d/
    total 8
    drwxr-xr-x. 2 root root    6 Mar  3 05:34 back
    -rw-r--r--. 1 root root 2523 Mar  3 05:35 CentOS-Base.repo
    drwxr-xr-x. 2 root root 4096 Mar  3 05:34 default
    
    [root@node101 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    View Code

    4>.生成缓存

    [root@node101 ~]# yum makecache
    Loaded plugins: fastestmirror
    base                                                                                                                                                                                               | 3.6 kB  00:00:00     
    extras                                                                                                                                                                                             | 3.4 kB  00:00:00     
    updates                                                                                                                                                                                            | 3.4 kB  00:00:00     
    (1/8): extras/7/x86_64/filelists_db                                                                                                                                                                | 231 kB  00:00:00     
    extras/7/x86_64/other_db       FAILED                                          
    http://mirrors.cloud.aliyuncs.com/centos/7/extras/x86_64/repodata/d072100fade170a6b781b00657e1a6c116f84b59b35c21b98a280e598512508c-other.sqlite.bz2: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Name or service not known"
    Trying other mirror.
    (2/8): updates/7/x86_64/filelists_db                                                                                                                                                               | 1.9 MB  00:00:00     
    (3/8): updates/7/x86_64/other_db                                                                                                                                                                   | 344 kB  00:00:00     
    (4/8): extras/7/x86_64/other_db                                                                                                                                                                    | 118 kB  00:00:00     
    (5/8): base/7/x86_64/filelists_db                                                                                                                                                                  | 7.1 MB  00:00:01     
    base/7/x86_64/other_db         FAILED                                          
    http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/fbebcd3de05e22bd1cd526e594f235968401471d4a9aef3c1ad356b6d1965365-other.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
    Trying other mirror.
    extras/7/x86_64/prestodelta    FAILED                                          
    http://mirrors.aliyuncs.com/centos/7/extras/x86_64/repodata/ea35765e72afae3e1539686da06393ce09fe26a04dbf576e218f994e4b7a706a-prestodelta.xml.gz: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
    Trying other mirror.
    (6/8): extras/7/x86_64/prestodelta                                                                                                                                                                 |  47 kB  00:00:00     
    (7/8): base/7/x86_64/other_db                                                                                                                                                                      | 2.6 MB  00:00:00     
    updates/7/x86_64/prestodelta   FAILED                                          
    http://mirrors.aliyuncs.com/centos/7/updates/x86_64/repodata/fd2186bbf3d231d441dc73bc0d0a3f2b79d5c212d14ceadf9a878fb2a5808de3-prestodelta.xml.gz: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
    Trying other mirror.
    (8/8): updates/7/x86_64/prestodelta                                                                                                                                                                | 343 kB  00:00:00     
    Loading mirror speeds from cached hostfile
     * base: mirrors.aliyun.com
     * extras: mirrors.aliyun.com
     * updates: mirrors.aliyun.com
    Metadata Cache Created
    [root@node101 ~]# yum makecache
    View Code

    5>.备份yum 源

    [root@node101 ~]# cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/back/
    [root@node101 ~]# 
    [root@node101 ~]# ll /etc/yum.repos.d/back/
    total 4
    -rw-r--r--. 1 root root 2523 Mar  3 05:37 CentOS-Base.repo
    [root@node101 ~]# 
    [root@node101 ~]# ll /etc/yum.repos.d/default/
    total 28
    -rw-r--r--. 1 root root 1664 Dec  9  2015 CentOS-Base.repo
    -rw-r--r--. 1 root root 1309 Dec  9  2015 CentOS-CR.repo
    -rw-r--r--. 1 root root  649 Dec  9  2015 CentOS-Debuginfo.repo
    -rw-r--r--. 1 root root  290 Dec  9  2015 CentOS-fasttrack.repo
    -rw-r--r--. 1 root root  630 Dec  9  2015 CentOS-Media.repo
    -rw-r--r--. 1 root root 1331 Dec  9  2015 CentOS-Sources.repo
    -rw-r--r--. 1 root root 1952 Dec  9  2015 CentOS-Vault.repo
    [root@node101 ~]# 
    [root@node101 ~]# ll /etc/yum.repos.d/
    total 8
    drwxr-xr-x. 2 root root   29 Mar  3 05:37 back
    -rw-r--r--. 1 root root 2523 Mar  3 05:35 CentOS-Base.repo
    drwxr-xr-x. 2 root root 4096 Mar  3 05:34 default
    
    [root@node101 ~]# cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/back/
    View Code

    三、修改网卡名称

    1.修改网卡配置文件的名字

    [root@node101 ~]# cd /etc/sysconfig/network-scripts/
    [root@node101 network-scripts]# 
    [root@node101 network-scripts]# mv ifcfg-eno16777736 ifcfg-eth0
    [root@node101 network-scripts]# 
    View Code

    2.修改网卡配置文件里面的内容

    [root@node101 network-scripts]# pwd
    /etc/sysconfig/network-scripts
    [root@node101 network-scripts]# 
    [root@node101 network-scripts]# cat ifcfg-eth0 
    TYPE=Ethernet
    DEVICE=eth0
    ONBOOT=yes
    BOOTPROTO=static
    IPADDR=172.30.1.102
    NETMASK=255.255.255.0
    GATEWAY=172.30.1.254
    DNS1=172.30.1.254
    [root@node101 network-scripts]# 
    View Code

    3.GRUB 添加kernel 参数

    [root@node101 ~]# cat /etc/sysconfig/grub 
    GRUB_TIMEOUT=5
    GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
    GRUB_DEFAULT=saved
    GRUB_DISABLE_SUBMENU=true
    GRUB_TERMINAL_OUTPUT="console"
    GRUB_CMDLINE_LINUX="crashkernel=auto rhgb net.ifnames=0 biosdevname=0 quiet"
    GRUB_DISABLE_RECOVERY="true"
    [root@node101 ~]# 
    View Code

    4.使配置生效

    [root@node101 ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
    Generating grub configuration file ...
    Found linux image: /boot/vmlinuz-3.10.0-327.el7.x86_64
    Found initrd image: /boot/initramfs-3.10.0-327.el7.x86_64.img
    Found linux image: /boot/vmlinuz-0-rescue-d1667a8e7e71407d8b380ec3588d6c19
    Found initrd image: /boot/initramfs-0-rescue-d1667a8e7e71407d8b380ec3588d6c19.img
    done
    [root@node101 ~]# 
    View Code

    5.系统重启

  • 相关阅读:
    statefulSet 原理理解
    kubernetes 集群机器重启后磁盘盘符变化
    去掉数据库外键约束
    kubernetes集群中对多个pod操作命令
    (转)怎么实时查看mysql当前连接数
    Got fatal error 1236 from master when reading data from binary log: 'Client requested master to start replication from impossible position
    phpfpm和nginx设置开机自动启动
    jquery ajax超时设置
    lumen中间件中设置响应header
    php支持多个地址跨域访问
  • 原文地址:https://www.cnblogs.com/dengcongcong/p/11172411.html
Copyright © 2020-2023  润新知