一、安装必要rpm包

yum -y install epel-release gcc binutils wget kernel-devel kernel-headers
# 主要安装 kernel-devel,但是此处要保证内核于运行的一致,
# 两种解决思路:
# 1.找到对应版本的kernel-devel包
# 2.更新运行kernel(这里的例子采用此法)
yum -y install kernel
# 更改grub配置使用最新的内核启动
awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (3.10.0-1160.66.1.el7.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)
2 : CentOS Linux (0-rescue-e0830d43d81340eb9b9f97a07371fc82) 7 (Core)
#将CentOS Linux (3.10.0-1160) 设置为默认启动项,对应的序号是0:

grub2-set-default 0
grub2-mkconfig -o /boot/grub2/grub.cfg
#重启机器
reboot
#内核更新了:
# 再次进入系统后
# uname -r
3.10.0-1160.66.1.el7.x86_64

二、安装显卡驱动

查看显卡信息

lspci |grep -i VGA
# -bash: lspci: 未找到命令
# yum install pciutils

禁用Nouveau

# 1. 检查是否开启Nouveau
lsmod | grep nouveau
# 注意:无信息输出表示已被禁用无需在操作以下步骤;

# 2. 修改配置
echo -e "blacklist nouveau\noptions nouveau modeset=0" > /etc/modprobe.d/blacklist.conf

# 3. 备份img
mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak

# 4. 重建
dracut /boot/initramfs-$(uname -r).img $(uname -r)


# 5. 重启系统
reboot

# 6. 查看nouveau是否启动,如果结果为空即为禁用成功
# 同1.

下载驱动

直接去官网下载即可,步骤省略

安装驱动

 ./NVIDIA-Linux-x86_64-470.63.01.run
 # 之后按默认的回车即可
 
 # 查看版本信息
 nvidia-smi
Wed Jun  8 14:20:14 2022       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 470.63.01    Driver Version: 470.63.01    CUDA Version: 11.4     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  Off  | 00000000:01:00.0 Off |                  N/A |
| 34%   41C    P0    28W / 175W |      0MiB /  7981MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

三、安装cuda及cudnn

cuda

./cuda_10.2.89_440.33.01_linux.run
############################################
# Step. 1. 以下回显
--------------------------------------------------------------------------------
x  End User License Agreement                                                  x
x  --------------------------                                                  x
x                                                                              x
x                                                                              x
x  Preface                                                                     x
x  -------                                                                     x
x                                                                              x
x  The Software License Agreement in Chapter 1 and the Supplement              x
x  in Chapter 2 contain license terms and conditions that govern               x
x  the use of NVIDIA software. By accepting this agreement, you                x
x  agree to comply with all the terms and conditions applicable                x
x  to the product(s) included herein.                                          x
x                                                                              x
x                                                                              x
x  NVIDIA Driver                                                               x
x                                                                              x
x                                                                              x
x  Description                                                                 x
x                                                                              x
x  This package contains the operating system driver and                       x
--------------------------------------------------------------------------------
x Do you accept the above EULA? (accept/decline/quit):                         x
x accept                                                                       x
--------------------------------------------------------------------------------
# 输入 accept 回车

############################################
# Step. 2. 以下回显
--------------------------------------------------------------------------------
x CUDA Installer                                                               x
x - [ ] Driver                                                                 x
x      [ ] 440.33.01                                                           x
x + [X] CUDA Toolkit 10.2                                                      x
x   [X] CUDA Samples 10.2                                                      x
x   [X] CUDA Demo Suite 10.2                                                   x
x   [X] CUDA Documentation 10.2                                                x
x   Options                                                                    x
x   Install                                                                    x
x                                                                              x
x Up/Down: Move | Left/Right: Expand | 'Enter': Select | 'A': Advanced options x
--------------------------------------------------------------------------------
# 第二步这里因为我们已经安装了显卡驱动去掉 Driver后上下选择到Install 回车

# 验证
 /usr/local/cuda/bin/nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Oct_23_19:24:38_PDT_2019
Cuda compilation tools, release 10.2, V10.2.89

cudnn

tar xvf cudnn-10.2-linux-x64-v7.6.5.32.tgz -C /usr/local/

(完)