公司某项目需要使用GPU作图渲染,跟开发人员对接,得到需求,只要服务器上能调用OpenGL即可,剩余的项目依赖包交由开发人员安装部署。
硬件及系统信息:
1.普通台式机一台;
2.NVIDIA GeForce GTX 1050 显卡一块;
3.系统为Ubuntu 18.04.3 LTS 最小化安装;
一:环境准备
1.先替换apt源
这里全面替换为阿里云apt镜像源。
sed -i "s/archive.ubuntu.com/mirrors.aliyun.com/g" /etc/apt/sources.list
阿里云官方帮助文档: Ubuntu 镜像
2.开启root远程
因为是物理机使用官方镜像安装的系统,默认情况下Ubuntu不支持root直接远程登录,为了方便操作,直接开启root登录,不需要的朋友可以跳过。
vim /etc/ssh/sshd_config PermitRootLogin yes
systemctl restart sshd
二:驱动安装
Ubuntu上安装NVIDIA显卡驱动有两种方式:自动安装和官方驱动包安装
1.自动安装方式最简单,建议使用这种方式安装驱动,但是有一定几率因为网络等原因安装失败。
apt-get update -y apt install ubuntu-drivers-common ubuntu-drivers devices #查看是否读取到显卡信息,跟lspci |grep -i vga 信息对比 ubuntu-drivers autoinstall #信息无误,直接自动安装,会自动从apt源下载所需驱动
安装完成后reboot 重启机器
2.官方驱动包手动安装
到NVIDIA下载对应显卡型号的驱动程序,选择Linux 64-bit 类型下载 NVIDIA驱动程序下载
chmod +x ./NVIDIA-Linux-x86_64-xxx.run ./NVIDIA-Linux-x86_64-xxx.run
安装过程不安装32位兼容程序。
如果安装的时候报错nouveau 相关,则禁用nouveau 后再执行驱动程序安装。
vim /etc/modprobe.d/blacklist-nouveau.conf blacklist nouveau blacklist lbm-nouveau options nouveau modeset=0
rmmod nouveau update-initramfs -u reboot
PS: 因为我用自动安装方式安装成功了,所以Ubuntu上没手动安装过驱动。
3.验证驱动
使用NVIDIA提供工具nvidia-smi 出现类似如下信息则代表驱动安装成功:
root@gpu-test:~# nvidia-smi
Fri Jan 17 10:27:36 2020
+—————————————————————————–+
| NVIDIA-SMI 435.21 Driver Version: 435.21 CUDA Version: 10.1 |
|——————————-+———————-+———————-+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 105… Off | 00000000:01:00.0 On | N/A |
| 45% 24C P8 N/A / 75W | 15MiB / 4036MiB | 0% Default |
+——————————-+———————-+———————-+
+—————————————————————————–+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
+—————————————————————————–+
4.安装xorg组件,服务器用GPU,不需要完整的桌面环境,只需要xorg进程,启动桌面服务即可。
apt-get install -y zip freeglut3-dev xserver-xorg xserver-xorg-core x11-xserver-utils libxrender1 libx11-dev mesa-utils supervisor
5.生成xorg配置文件
有两种方式生成配置文件:
通过nvidia-xconfig 命令生成,该方案适合单显卡物理机
nvidia-xconfig
执行该命令后,会生成/etc/X11/xorg.conf 配置文件
6.启动xorg服务
export DISPLAY=:0 /usr/bin/Xorg :0
DISPLAY 变量代表桌面,类似于需要指定xorg服务连接的显示器,可以随意指派,:0 是默认,命令执行成功后,当前终端会类似这样显示(没报错,进程不退出):
root@gpu-test:~# /usr/lib/xorg/Xorg :0
X.Org X Server 1.19.6
Release Date: 2017-12-20
X Protocol Version 11, Revision 0
Build Operating System: Linux 4.4.0-148-generic x86_64 Ubuntu
Current Operating System: Linux gpu-sdk 4.15.0-88-generic #88-Ubuntu SMP Tue Feb 11 20:11:34 UTC 2020 x86_64
Kernel command line: BOOT_IMAGE=/boot/vmlinuz-4.15.0-88-generic root=UUID=cb882c53-1dbf-4f7d-aa76-af58484728f5 ro
Build Date: 03 June 2019 08:10:35AM
xorg-server 2:1.19.6-1ubuntu4.3 (For technical support please see http://www.ubuntu.com/support)
Current version of pixman: 0.34.0
Before reporting problems, check http://wiki.x.org
to make sure that you have the latest version.
Markers: (–) probed, (**) from config file, (==) default setting,
(++) from command line, (!!) notice, (II) informational,
(WW) warning, (EE) error, (NI) not implemented, (??) unknown.
(==) Log file: “/var/log/Xorg.2.log”, Time: Thu Mar 5 15:21:27 2020
(==) Using config file: “/etc/X11/xorg.conf”
(==) Using system config directory “/usr/share/X11/xorg.conf.d”
然后新打开一个终端连接服务器,查看xorg进程信息
root@gpu-test:~# ps -ef | grep X root 5916 1298 0 Mar02 tty2 00:00:00 /usr/lib/xorg/Xorg :0 root 29570 26272 0 15:23 pts/0 00:00:00 grep --color=auto X
7.测试OpenGL
export DISPLAY=:0 glxinfo | grep -i opengl
出现类似下面的信息则代表OpenGL服务调用成功。
OpenGL vendor string: NVIDIA Corporation OpenGL renderer string: GeForce GTX 1050 Ti/PCIe/SSE2 OpenGL core profile version string: 4.6.0 NVIDIA 435.21
上面测试无误后,可以将xorg服务写入到supervisor 程序进行控制开机自启动,DISPLAY 变量写入/etc/profile中
cat /etc/supervisor/conf.d/xorg.conf [program:Xorg0] command=/usr/bin/Xorg :0 autorestart=true
cat /etc/profile export DISPLAY=:0
到此Ubuntu 系统安装OpenGL程序完成。
转载请注明:菜鸟运维网 » GPU服务器环境部署-Ubuntu