CentOS 7

下载 CentOS 7 镜像

https://www.centos.org/download/

http://mirrors.aliyun.com/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-Minimal-2009.iso

配置 yum 国内源

替换国内源

1
2
3
4
5
# CentOS 7 清华源
sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org/centos|baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos|g' \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo

注意其中的*通配符,如果只需要替换一些文件中的源,请自行增删。
注意,如果需要启用其中一些 repo,需要将其中的 enabled=0 改为 enabled=1

更新软件包缓存

1
sudo yum makecache

升级内核

在线升级

3.10内核在大规模集群具有不稳定性,所以需要升级内核 。(所有机器都要升级到一样)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#查看内核版本
$ uname -r

#系统更新
$ yum update

#载入公钥
$ rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

#安装 ELRepo 最新版本
$ yum install -y https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm

#列出可以使用的 kernel 包版本
$ yum list available --disablerepo=* --enablerepo=elrepo-kernel

#安装指定的 kernel 版本:(已查看版本为准,采用lt长期支持版本)
$ yum install -y kernel-lt-5.4.234-1.el7.elrepo --enablerepo=elrepo-kernel

离线升级

在本地浏览中打开以下URL,将列出可供下载的内核

https://elrepo.org/linux/kernel/el7/x86_64/RPMS/

下载当前最新长期支持版本,即以 kernel-lt 开头的文件

https://elrepo.org/linux/kernel/el7/x86_64/RPMS/kernel-lt-5.4.234-1.el7.elrepo.x86_64.rpm

使用 sftp 工具把下载好的文件传输到 centos 主机 /root 目录

1
2
# 使用 rpm 命令安装新版内核
$ rpm -ivh kernel-lt-5.4.234-1.el7.elrepo.x86_64.rpm

修改启动项使内核生效

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#查看系统可用内核
$ awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg

#设置开机从新内核启动
$ grub2-set-default "CentOS Linux (5.4.234-1.el7.elrepo.x86_64) 7 (Core)"

#查看内核启动项
$ grub2-editenv list
saved_entry=CentOS Linux (5.4.234-1.el7.elrepo.x86_64) 7 (Core)

#重启系统使内核生效:
$ reboot

#启动完成查看内核版本是否更新:
$ uname -r
5.4.234-1.el7.elrepo.x86_64

删除旧内核

1
2
# 查看系统中全部的内核
$ rpm -qa | grep kernel
1
2
3
4
# 方法1:使用 rpm 删除内核
$ rpm -e kernel-3.10.0-1160.83.1.el7.x86_64
# 方法2:使用 yum remove 删除内核
$ yum remove kernel-3.10.0-1160.83.1.el7.x86_64

开启 BBR(可选)

1
2
3
4
5
6
7
8
9
10
$ echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf && echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
$ sysctl -p && sysctl net.ipv4.tcp_available_congestion_control
# 如果成功,上面这行命令会输出如下结果
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
net.ipv4.tcp_available_congestion_control = reno cubic bbr

$ lsmod | grep bbr
# 这句输出类似下面的信息,说明成功了
tcp_bbr 16384 11

离线安装常用软件

在线安装请使用 yum install lrzsz vim 命令安装,此处不再赘述

安装 lrzsz

lrzsz 是一款程序,在linux中可以代替ftp的上传和下载

下载 rpm 安装包:

https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/lrzsz-0.12.20-36.el7.x86_64.rpm

通过 sftp 将 rpm 包传输到 centos 主机 /root目录

1
2
3
4
# 执行以下命令安装 lrzsz
$ rpm -ivh lrzsz-0.12.20-36.el7.x86_64.rpm

$ yum install lrzsz-0.12.20-36.el7.x86_64.rpm

安装 vim

Vim是从 vi 发展出来的一个文本编辑器。代码补全、编译及错误跳转等方便编程的功能特别丰富,在程序员中被广泛使用,和Emacs并列成为类Unix系统用户最喜欢的文本编辑器。

下载 vim 安装包:

https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/vim-common-7.4.629-7.el7.x86_64.rpm

https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/vim-filesystem-7.4.629-7.el7.x86_64.rpm

https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/vim-enhanced-7.4.629-7.el7.x86_64.rpm

下载 vim 依赖项 gpm-libs 包:

https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/gpm-libs-1.20.7-6.el7.x86_64.rpm

下载 vim 依赖项 perl 包以及perl的依赖项(大概要下载下面那么多):

https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-5.16.3-297.el7.x86_64.rpm
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-libs-5.16.3-297.el7.x86_64.rpm
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-Carp-1.26-244.el7.noarch.rpm
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-constant-1.27-2.el7.noarch.rpm
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-Encode-2.51-7.el7.x86_64.rpm
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-Exporter-5.68-3.el7.noarch.rpm
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-File-Path-2.09-2.el7.noarch.rpm
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-File-Temp-0.23.01-3.el7.noarch.rpm
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-Filter-1.49-3.el7.x86_64.rpm
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-Getopt-Long-2.40-3.el7.noarch.rpm
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-HTTP-Tiny-0.033-3.el7.noarch.rpm
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-macros-5.16.3-297.el7.x86_64.rpm
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-parent-0.225-244.el7.noarch.rpm
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-PathTools-3.40-5.el7.x86_64.rpm
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-Pod-Escapes-1.04-297.el7.noarch.rpm
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-podlators-2.5.1-3.el7.noarch.rpm
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-Pod-Perldoc-3.20-4.el7.noarch.rpm
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-Pod-Simple-3.28-4.el7.noarch.rpm
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-Pod-Usage-1.63-3.el7.noarch.rpm
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-Scalar-List-Utils-1.27-248.el7.x86_64.rpm
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-Socket-2.010-5.el7.x86_64.rpm
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-Storable-2.45-3.el7.x86_64.rpm
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-Text-ParseWords-3.29-4.el7.noarch.rpm
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-threads-1.87-4.el7.x86_64.rpm
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-threads-shared-1.43-6.el7.x86_64.rpm
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-Time-HiRes-1.9725-3.el7.x86_64.rpm
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/perl-Time-Local-1.2300-2.el7.noarch.rpm

将上面这些文件通过 sftp 或 rz 命令传输到 centos 主机的 同一个文件夹下,例:/root/vim/

1
2
3
4
# 执行以下命令进行安装,会自动解析依赖项进行安装
$ rpm -ivh *.rpm

$ yum install *.rpm

问题

Q:当完全内网使用时,在使用三方工具 ssh 连接时会比较慢,这是为什么?

A:这是由于ssh的服务端在连接时会自动检测dns环境是否一致,所以会发现Xshell连接虚拟机速度变慢了好多。

  1. 修改sshd_config
1
2
3
4
5
6
$ vi /etc/ssh/sshd_config


#UseDNS yes
修改为
UseDNS no
  1. 重启服务
1
$ systemctl restart sshd