tensorflow 在centos7上的环境配置流程

Table of Contents

系统安装

切换国内镜像站

安装Anaconda

安装显卡驱动

安装cuda 10

安装tensorflow-gpu

激活环境并运行python


系统配置

  • CPU: Intel Xeon4114 *2
  • GPU: Nvidia Tesla V100 * 2
  • 操作系统: Centos 7
  • Anaconda版本: 2019.10
  • 显卡驱动版本: 410.129
  • tensorflow: tensorflow-gpu:2.0

系统安装

切换国内镜像站

参见:CentOS 镜像

su
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache

安装Anaconda

cd <Directory of Anaconda3 Installer> #Anaconda3安装包所在路径
chmod +x Anaconda3-2019.10-Linux-x86_64.sh
./Anaconda3-2019.10-Linux-x86_64.sh # 安装过程中全部选yes

cd
conda config --set show_channel_urls yes
gedit .condarc
  • 向文件中复制如下内容:
channels:
  - defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  •  清除索引缓存
conda clean -i

安装显卡驱动

参考:CentOS 7中以runfile形式安装CUDA 9.0

  • 切至root用户
su
  • 确保电脑上安装了nvidia显卡
lspci | grep -i nvidia
  • 安装需要的软件
yum install -y gcc gcc-c++
  • 安装kernel header
yum install -y kernel-devel-$(uname -r) kernel-headers-$(uname -r)
  • 列出Nouveau驱动
lsmod | grep nouveau
  •  新建blacklist-nouveau.conf,禁用Nouveau驱动
gedit /usr/lib/modprobe.d/blacklist-nouveau.conf
  •  在配置文件中输入如下内容:
blacklist nouveau
options nouveau modeset=0
  •  重新生成kernel inittramfs:
sudo dracut --force
  • 设置默认启动方式为“text mode”
systemctl set-default multi-user.target
init 3
  • 重启计算机

计算机重启后进入命令行界面,输入用户名和密码进行登陆,登陆后安装驱动即可。

  • 驱动安装完成后,运行以下命令,切换会图形界面。
systemctl set-default graphical.target
init 5

安装cuda & cudnn

  • 切换至cuda安装包所在目录,运行:
chmod +x cuda_10.0.130_410.48_linux.run
sudo ./cuda_10.0.130_410.48_linux.run
  • 请勿安装cuda默认的驱动程序!!
  • 在".bashrc"中添加:
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
  •  下载并安装cudnn7.6.5
rpm -ivh libcudnn7-*.x86_64.rpm
rpm -ivh libcudnn7-devel-*.x86_64.rpm
rpm -ivh libcudnn7-doc-*.x86_64.rpm
  • 验证安装是否成功
cp -r /usr/src/cudnn_samples_v7/ $HOME
cd  $HOME/cudnn_samples_v7/mnistCUDNN
make clean && make
./mnistCUDNN
  • 下载并安装nccl2.5
rpm -ivh nccl-repo-rhel7-2.5.6-ga-cuda10.0-1-1.x86_64.rpm

安装tensorflow-gpu

conda create -n tf tensorflow-gpu=2.0

激活环境并运行python

conda activate tf
python

在python命令提示符后输入:

import tensorflow as tf
tf.test.is_gpu_available()

返回‘True’,表示tensorflow-gpu可用。

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

falwat

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值