硬件说明
Dell R730服务器 ,配备两块Tesla K40m显示卡,64GB内存,英特尔至强32核心处理器,安装时显示器采用KVM方案。
安装系统
系统下载
官网下载地址https://www.centos.org/download/
参考https://wiki.centos.org/TipsAndTricks/sha256sum 验证你下载的iso镜像是否完整
在地址http://mirrors.163.com/centos/7/isos/x86_64/sha256sum.txt 中可以找到CentOS-7-x86_64-DVD-1611.iso 对应的sha1sum值
mac上如下图所示
请务必校验下载的镜像文件
系统启动盘制作
- 1、插入U盘并打开软碟通(UltraISO Premium Edition 9.6.0.3000,版本至少9.6)
- 2、文件—>>打开—>>CentOS-7-x86_64-DVD-1611.iso
- 3、启动—>>写入硬盘映像
-
4、硬盘驱动器千万别选错了,一定要确定是你的U盘再开始点击写入
- 5、右键—>>对U盘重命名为CENTOS7(名字不要紧,但一定要改,否则安装会出错)
系统安装
服务器原本需要创建RAID5磁盘阵列的,但由于现在已经是创建好的磁盘阵列,暂时不需要再次创建,只要在系统安装时清除整个磁盘就可以了。
开机时按F11 进入系统设置,选择One-shot....启动,选择你的U盘即可
- 1、当出现下面的画面时,按F11
-
2、稍等进入系统后选择One-Shot BIOS Menu
- 3、选择你的U盘并等待启动
-
4、出现如下画面时,上下键选择Install Centos …
5、按TAB键,修改启动选项,将LABLE修改为CENTOS7(或者你自己定义的名称)
- 6、语言选择English,在SOFTWARE选项,选择Server with GUI ,并勾选如下选项
- 7、设置硬盘
点击DONE,下一步清空所有磁盘空间
-
8、设置网络,设置IPV4即可,最后别忘了勾选自动连接
- 9、设置超级用户和普通用户
配置网络
如果你的网络不正常,就需要配置网络了
检查网络是否工作正常
ping 192.168.69.254 #192.168.69.254 为网关地址,无错误即可```
**如果不通,则设置网络**
cd /etc/sysconfig/network-scripts
vi ifcfg-em3 #按要求配置ip地址```
TYPE="Ethernet"
BOOTPROTO="none"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="em3"
UUID="a4a96c2a-0efc-4442-bb52-024ba11aed90"
DEVICE="em3"
ONBOOT="yes"
IPADDR="192.168.69.64"
PREFIX="24"
GATEWAY="192.168.69.254"
DNS1="211.82.112.120"
IPV6_PEERDNS="yes"
IPV6_PEERROUTES="yes"
IPV6_PRIVACY="no"
sudo ifdown em3
sudo ifup em3
再次使用ping 命令连接网关验证
配置代理
代理服务器搭建
- Mac上
安装SquidMan这个软件并设置好端口号与允许访问的客户端地址 - windows
安装ccproxy并设置好相关参数
登录服务器
ssh [email protected]
vi ~/.bashrc
#添加如下内容
export http_proxy=http://192.168.69.165:8066
export https_proxy=http://192.168.69.165:8066
export ftp_proxy=http://192.168.69.165:8066
切换到root环境,并修改 .bashrc
测试网络是否通畅
注意不要使用ping www.baidu.com 因为代理服务器不支持 ICMP协议的代理
wget www.baidu.com
切换到到root用户下重复上述操作,以便切换到root后依然能上网
root账户使用vim
默认vi编辑时,使用的是vi,没有语法高亮功能,而vim可以
sudo mv /bin/vi /bin/vi_bak
sudo ln -s /bin/vim /bin/vi
使sudo继承用户当前代理变量
参考:
https://www.chenyudong.com/archives/sudo-keep-env.html
配置完代理后发现sudo 执行的命令无法上网,原因是每次执行时都会进行变量重置,为了解决这个问题可以进行如下设置
sudo visudo #不要直接使用sudo vi /etc/sudoers修改,会被覆盖
#添加如下内容
Defaults env_keep += "http_proxy https_proxy ftp_proxy no_proxy DISPLAY XAUTHORITY"
这样sudo 执行的命令就可以使用用户的代理变量了
设置国内镜像源
这一步操作非必须,但强烈推荐,这会大大加快你的网络访问速度,节省时间。具体操作请移步本人博客 CentOS 7 禁用fastestmirror插件并配置清华镜像源
安装epel源
yum install -y epel-release
更新系统(非常重要,请务必执行)
yum update -y
reboot
配置pip镜像源
pip安装第三方软件包时总是很慢,如果你还不知道镜像源的妙用,那就OUT啦~~,配置镜像源后,速度快得飞起!
这一步非必须,但强烈建议安装
参考 http://www.jianshu.com/p/5002e4aea6d7
mkdir ~/.pip
vi ~/.pip/pip.conf
添加如下内容
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
在root用户下重复上述操作,以便切换到root后依然能使用pip镜像源
关闭SELinux
vi /etc/sysconfig/selinux
修改#SELINUX=enforcing 为 SELINUX=disable
#立即生效
setenforce 0
# 查看SELinux状态
getenforce
升级Python为2.7.13
请移步本人博客CentOS 7.3 升级Python 2.7.13
至此,Python的升级工作终于完成
安装Python3.6.1 多版本共存
请移步本人博客 CentOS 7 安装Python3.6.1 多版本共存
配置Xmanager
请移步本人博客 Centos 7 配置Xmanager XDMCP
安装Nvidia显卡驱动
请到Nvidia驱动官网查询并下载与显卡对应的驱动程序、cuda包及cudnn库
使用winscp或其他软件上传相关文件到服务器
[zhangxinming@localhost Nvidia]$ ll
总用量 1595180
-rw-rw-r--. 1 zhangxinming zhangxinming 1457082926 11月 16 02:05 cuda_8.0.44_linux.run
-rw-rw-r--. 1 zhangxinming zhangxinming 100504805 11月 16 01:57 cudnn-8.0-linux-x64-v5.1.tgz
-rw-rw-r--. 1 zhangxinming zhangxinming 75866380 4月 24 03:26 NVIDIA-Linux-x86_64-375.51.run
- 禁用nouveau
vi /etc/modprobe.d/blacklist-nouveau.conf
添加如下内容
blacklist nouveau
options nouveau modeset=0
#退出后
sudo dracut --force
sudo reboot
#检验是否禁用成功
lsmod | grep nouveau #如果没有输出就表示成功
- 安装相应的软件包
yum install gcc make kernel-devel-$(uname -r)
- 安装
sudo init 3
chmod +x NVIDIA-Linux-x86_64-375.51.run
sudo ./NVIDIA-Linux-x86_64-375.51.run #按照提示操作就可以了
# 与windows不同的是,显卡的驱动安装完毕后不需要重新启动系统,为了保险起见,重启一下也无妨
- 验证
nvidia-smi #如果出现相应的信息就说明成功了
- 问题
你可能会遇到nvidia-smi
命令特别慢的情况,而且GPU-Util
利用率非常高。
参考https://devtalk.nvidia.com/default/topic/539632/k20-with-high-utilization-but-no-compute-processes-/
我们执行以下命令为GPU打开persistence mode
sudo nvidia-smi -pm 1
可以看到如下信息:
Enabled persistence mode for GPU 0000:03:00.0.
Enabled persistence mode for GPU 0000:82:00.0.
All done.
再次执行nvidia-smi
就很快了,而且GPU-Util
利用率为0.
安装CUDA
注意:安装cuda的同时就不要安装安装cuda自带的显卡驱动。如果你使用的是GNOME桌面,不要安装OPENGL,GNOME桌面在很多情况下会崩溃!当然如果你水平够高的话,也可以尝试着解决以下这个问题。服务器环境请使用别的桌面环境和图形管理器
- 安装依赖
首先把依赖安装完毕,否则会出现如下错误:
Installing the NVIDIA display driver...
Installing the CUDA Toolkit in /usr/local/cuda-8.0 ...
Missing recommended library: libGLU.so
Missing recommended library: libXmu.so
Installing the CUDA Samples in /usr/local/cuda-8.0-samples ...
Copying samples to
/usr/local/cuda-8.0-samples/NVIDIA_CUDA-8.0_Samples now...
Finished copying samples.
解决方案:参考 Cuda on CentOS 7
yum install mesa-libGLES.x86_64 mesa-libGL-devel.x86_64 mesa-libGLU-devel.x86_64 mesa-libGLw.x86_64 mesa-libGLw-devel.x86_64 libXi-devel.x86_64 freeglut-devel.x86_64 freeglut.x86_64
- 安装
安装很简单,只要注意驱动不要选yes就可以了,其他的选择yes及默认路径
sudo ./cuda_8.0.44_linux.run
- 修改环境变量
vi /etc/profile
#添加如下内容
#Base LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/lib:/lib64:/usr/lib:/usr/lib64:/usr/local/lib:/usr/local/lib64
#CUDA
export PATH=/usr/local/cuda-8.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH
设置LD_LIBRARY_PATH
基本变量能避免很多类似于找不到share library的错误,推荐
- 更新运行库缓存
source /etc/profile
sudo ldconfig
安装CUDNN
cudnn是比cuda更高级的GPU加速库,安装也十分简单,只要将文件移动到相应的位置就可以了
tar -zxvf cudnn-8.0-linux-x64-v5.1.tgz
sudo mv include/cudnn.h /usr/local/cuda/include/
sudo mv lib64/* /usr/local/cuda/lib64/
至此,基础环境搭建完毕,下一步,配置caffe平台
配置Git协议结合SquidMan走HTTP代理
参考:
http://www.vpsee.com/2011/07/how-to-use-git-through-a-http-proxy/
https://gist.github.com/sit/49288
https://www.emilsit.net/blog/archives/how-to-use-the-git-protocol-through-a-http-connect-proxy/
https://www.digglife.net/articles/squid-for-git-proxy.html
- 配置SquidMan的配置文件,在合适的位置添加
acl SSL_ports port 9418
acl Safe_ports port 9418
重启SquidMan
配置服务器
yum install socat
vi /usr/local/bin/gitproxy-socat-simon
添加如下内容
#!/bin/sh
#!/bin/sh
# Use socat to proxy git through an HTTP CONNECT firewall.
# Useful if you are trying to clone git:// from inside a company.
# Requires that the proxy allows CONNECT to port 9418.
#
# Save this file as gitproxy somewhere in your path (e.g., ~/bin) and then run
# chmod +x gitproxy
# git config --global core.gitproxy gitproxy
#
# More details at http://tinyurl.com/8xvpny
# Configuration. Common proxy ports are 3128, 8123, 8000.
_proxy=192.168.69.165 #搭建的http代理地址
_proxyport=8066 #自己搭建的http代理端口
exec socat STDIO PROXY:$_proxy:$1:$2,proxyport=$_proxyport
配置git客户端代理
参见初次运行 Git 前的配置
git config --global core.gitproxy /usr/local/bin/gitproxy-socat-simon
安装mercurial并为为HG Clone设置http代理
参考:
http://www.it610.com/article/1672477.htm
http://chenzaichun.github.io/2010-05-16-mercurial_hg_proxy.html
http://blog.csdn.net/xiaoaiwhc/article/details/33015971
- 安装mercurial
yum install mercurial
- 执行
vi ~/.hgrc
添加如下内容
[http_proxy]
host=192.168.69.165:8066
- 由于之前升级了python需要修改hg命令,执行
vi /usr/bin/hg
修改#!/usr/bin/python
为#!/usr/bin/python2.7.5
安装FFMPEG(新版)
rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm
yum -y install ffmpeg ffmpeg-devel
安装Java
参考:https://argcv.com/articles/3155.c
- 下载JDK
- 安装
yum localinstall jdk-8u20-linux-x64.rpm -y
- 更改默认java
alternatives --config java 选择2
- 验证
java -version
- 配置一下环境变量
vi /etc/profile
# 添加如下内容
export JAVA_HOME=/usr/java/default
export JRE_HOME=/usr/java/default/jre
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
安装Matlab R2016b
下载破解版文件
链接: https://pan.baidu.com/s/1i5HXTPV 密码: 4mma挂载文件
用root权限安装
在用户根目录以绝对路径运行安装脚本
其余参看readme.txt
另外两个版本的Matlab安装,请移步
Linux Matlab2014b安装及下载
Linux Matlab2012b安装及下载
编译安装OpenCV 3.3.0(新版)
安装依赖
yum -y install cmake git pkgconfig libpng-devel libjpeg-turbo-devel jasper-devel openexr-devel libtiff-devel libwebp-devel libdc1394-devel libv4l-devel gstreamer-plugins-base-devel gtk2-devel tbb-devel eigen3-devel
pip install numpy
yum install python-devel libgphoto2
修复头文件
查看jasper
版本
rpm -qa | grep jasper
jasper-libs-1.900.1-30.el7_3.x86_64
jasper-devel-1.900.1-30.el7_3.x86_64
如果你得到以上信息,请务必修改头文件,修复错误
2017年5月15日,centos更新了jaspe-devel包为jasper-devel.x86_64 0:1.900.1-30.el7_3
(旧版本为jasper-devel-1.900.1-29.el7.x86_64
),这将导致如下问题:
In file included from /usr/include/jasper/jasper.h:77:0,
from /home/zhangxinming/Desktop/OpenCV/opencv-3.2.0/modules/imgcodecs/src/grfmt_jpeg2000.cpp:59:
/usr/include/jasper/jas_math.h: 在函数‘bool jas_safe_size_mul(std::size_t, std::size_t, std::size_t*)’中:
/usr/include/jasper/jas_math.h:143:15: 错误:‘SIZE_MAX’在此作用域中尚未声明
if (x && y > SIZE_MAX / x) {
^
/usr/include/jasper/jas_math.h: 在函数‘bool jas_safe_size_add(std::size_t, std::size_t, std::size_t*)’中:
/usr/include/jasper/jas_math.h:170:10: 错误:‘SIZE_MAX’在此作用域中尚未声明
if (y > SIZE_MAX - x) {
^
[ 38%] Building CXX object modules/reg/CMakeFiles/opencv_reg.dir/src/mapperpyramid.cpp.o
在全局域:
cc1plus: 警告:无法识别的命令行选项“-Wno-unnamed-type-template-args” [默认启用]
make[2]: *** [modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/src/grfmt_jpeg2000.cpp.o] 错误 1
make[1]: *** [modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/all] 错误 2
make[1]: *** 正在等待未完成的任务....
[ 38%] Building CXX object modules/reg/CMakeFiles/opencv_reg.dir/src/mapprojec.cpp.o
[ 38%] Building CXX object modules/video/CMakeFiles/opencv_video.dir/src/optflowgf.cpp.o
[ 38%] Building CXX object modules/reg/CMakeFiles/opencv_reg.dir/src/mapshift.cpp.o
[ 38%] Building CXX object modules/video/CMakeFiles/opencv_video.dir/src/tvl1flow.cpp.o
[ 38%] Building CXX object modules/reg/CMakeFiles/opencv_reg.dir/src/precomp.cpp.o
[ 38%] [ 38%] Building CXX object modules/video/CMakeFiles/opencv_video.dir/opencl_kernels_video.cpp.o
Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/misc/tensorflow/versions.pb.cc.o
[ 38%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/misc/caffe/caffe.pb.cc.o
[ 38%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/blob.cpp.o
Linking CXX shared library ../../lib/libopencv_reg.so
[ 38%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/caffe/caffe_importer.cpp.o
[ 38%] Built target opencv_reg
[ 38%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/caffe/caffe_io.cpp.o
[ 38%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/caffe/layer_loaders.cpp.o
[ 38%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/dnn.cpp.o
[ 38%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/init.cpp.o
[ 38%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/concat_layer.cpp.o
[ 38%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/convolution_layer.cpp.o
[ 38%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/crop_layer.cpp.o
[ 39%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/detection_output_layer.cpp.o
[ 39%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/elementwise_layers.cpp.o
[ 39%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/eltwise_layer.cpp.o
[ 39%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/flatten_layer.cpp.o
[ 39%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/fully_connected_layer.cpp.o
[ 39%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/layers_common.cpp.o
[ 39%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/lrn_layer.cpp.o
[ 39%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/mvn_layer.cpp.o
Linking CXX shared library ../../lib/libopencv_video.so
[ 39%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/normalize_bbox_layer.cpp.o
[ 39%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/op_blas.cpp.o
[ 39%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/op_im2col.cpp.o
[ 39%] Built target opencv_video
[ 39%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/permute_layer.cpp.o
[ 39%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/pooling_layer.cpp.o
[ 39%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/prior_box_layer.cpp.o
[ 39%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/recurrent_layers.cpp.o
[ 39%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/reshape_layer.cpp.o
[ 39%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/shift_layer.cpp.o
[ 40%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/slice_layer.cpp.o
[ 40%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/softmax_layer.cpp.o
[ 40%] [ 40%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/split_layer.cpp.o
Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/tensorflow/tf_importer.cpp.o
[ 40%] [ 40%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/tensorflow/tf_io.cpp.o
Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/torch/THDiskFile.cpp.o
[ 40%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/torch/THFile.cpp.o
[ 40%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/torch/THGeneral.cpp.o
[ 40%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/torch/torch_importer.cpp.o
[ 40%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/opencl_kernels_dnn.cpp.o
Linking CXX shared library ../../lib/libopencv_dnn.so
[ 40%] Built target opencv_dnn
Scanning dependencies of target opencv_cudaarithm
[ 40%] [ 40%] [ 40%] [ 40%] Building CXX object modules/cudaarithm/CMakeFiles/opencv_cudaarithm.dir/src/core.cpp.o
Building CXX object modules/cudaarithm/CMakeFiles/opencv_cudaarithm.dir/src/element_operations.cpp.o
Building CXX object modules/cudaarithm/CMakeFiles/opencv_cudaarithm.dir/src/arithm.cpp.o
Building CXX object modules/cudaarithm/CMakeFiles/opencv_cudaarithm.dir/src/reductions.cpp.o
Linking CXX shared library ../../lib/libopencv_cudaarithm.so
[ 40%] Built target opencv_cudaarithm
Scanning dependencies of target opencv_cudawarping
[ 40%] [ 40%] [ 41%] [ 41%] Building CXX object modules/cudawarping/CMakeFiles/opencv_cudawarping.dir/src/remap.cpp.o
Building CXX object modules/cudawarping/CMakeFiles/opencv_cudawarping.dir/src/resize.cpp.o
Building CXX object modules/cudawarping/CMakeFiles/opencv_cudawarping.dir/src/pyramids.cpp.o
Building CXX object modules/cudawarping/CMakeFiles/opencv_cudawarping.dir/src/warp.cpp.o
Linking CXX shared library ../../lib/libopencv_cudawarping.so
[ 41%] Built target opencv_cudawarping
make: *** [all] 错误 2
解决方案:
参考:
https://stackoverflow.com/questions/44038198/opencv-3-0-0-install-error-on-centos7
https://www.cpume.com/question/ffzhgong-opencv-3-0-0-install-error-on-centos7.html
vi /usr/include/jasper/jas_math.h
#在 #include 后添加
#if ! defined SIZE_MAX
#define SIZE_MAX (4294967295U)
#endif
编译安装
请一定要指定可以帆樯的代理,因为cmake过程中需要下载依赖文件,而且下载的比较多,不可能一个个的下载再放到正确的位置上。
#使用帆樯代理,请更换成自己的代理
export http_proxy=127.0.0.1:8118
export https_proxy=127.0.0.1:8118
编译
#下载相应的包
git clone -b 3.3.0 --depth 1 https://github.com/opencv/opencv.git
git clone -b 3.3.0 --depth 1 https://github.com/opencv/opencv_contrib.git
cd opencv
mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_OPENCV_PYTHON2=ON ..
#使用24核并行编译,这里更改为自己电脑的核心数
make -j24
sudo make install
检查是否安装成功
#python
>>>import cv2
>>>cv2.__version__
3.3.0
Caffe搭建
参考:
http://caffe.berkeleyvision.org/install_yum.html
安装依赖
- General dependencies
sudo yum -y install protobuf-devel leveldb-devel snappy-devel opencv-devel hdf5-devel openblas-devel
- Remaining dependencies, recent OS
sudo yum -y install gflags-devel glog-devel lmdb-devel
- BLAS
#atlas 有问题,不要使用atlas
sudo yum -y install openblas-devel
- Python (optional)
sudo yum -y install python-devel
- 安装python依赖
for req in $(cat requirements.txt); do pip install $req; done
- Boost库
epel源自带的boost库版本太低,需要源码安装boost
官网下载boost-1.55.0 http://www.boost.org/users/history/
下载后解压
tar -jxf boost_1_55_0.tar.bz2
cd boost_1_55_0
./bootstrap.sh --with-libraries=all
./b2
大约20分钟左右,出现如下信息
The Boost C++ Libraries were successfully built!
The following directory should be added to compiler include paths:
/home/zhangxinming/Desktop/boost_1_55_0
The following directory should be added to linker library paths:
/home/zhangxinming/Desktop/boost_1_55_0/stage/lib
开始安装
sudo ./b2 install
修改Makefile.config 文件
## Refer to http://caffe.berkeleyvision.org/installation.html
# Contributions simplifying and improving our build system are welcome!
# cuDNN acceleration switch (uncomment to build with cuDNN).
USE_CUDNN := 1
# CPU-only switch (uncomment to build without GPU support).
# CPU_ONLY := 1
# uncomment to disable IO dependencies and corresponding data layers
# USE_OPENCV := 0
# USE_LEVELDB := 0
# USE_LMDB := 0
# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
# You should not set this flag if you will be reading LMDBs with any
# possibility of simultaneous read and write
# ALLOW_LMDB_NOLOCK := 1
# Uncomment if you're using OpenCV 3
OPENCV_VERSION := 3
# To customize your choice of compiler, uncomment and set the following.
# N.B. the default for Linux is g++ and the default for OSX is clang++
# CUSTOM_CXX := g++
# CUDA directory contains bin/ and lib/ directories that we need.
CUDA_DIR := /usr/local/cuda
# On Ubuntu 14.04, if cuda tools are installed via
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
# CUDA_DIR := /usr
# CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.
# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
CUDA_ARCH := -gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_50,code=sm_50 \
-gencode arch=compute_52,code=sm_52 \
-gencode arch=compute_60,code=sm_60 \
-gencode arch=compute_61,code=sm_61 \
-gencode arch=compute_61,code=compute_61
# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := open
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
BLAS_INCLUDE := /usr/include/openblas
#BLAS_LIB := /usr/lib64/atlas
# Homebrew puts openblas in a directory that is not on the standard search path
# BLAS_INCLUDE := $(shell brew --prefix openblas)/include
# BLAS_LIB := $(shell brew --prefix openblas)/lib
# This is required only if you will compile the matlab interface.
# MATLAB directory should contain the mex binary in /bin.
MATLAB_DIR := /usr/local/MATLAB/R2016b
# MATLAB_DIR := /Applications/MATLAB_R2012b.app
# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
PYTHON_INCLUDE := /usr/local/include/python2.7 /usr/local/lib/python2.7/site-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
# ANACONDA_HOME := $(HOME)/anaconda
# PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
# $(ANACONDA_HOME)/include/python2.7 \
# $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include
# Uncomment to use Python 3 (default is Python 2)
# PYTHON_LIBRARIES := boost_python3 python3.5m
# PYTHON_INCLUDE := /usr/include/python3.5m \
# /usr/lib/python3.5/dist-packages/numpy/core/include
# We need to be able to find libpythonX.X.so or .dylib.
PYTHON_LIB := /usr/lib
# PYTHON_LIB := $(ANACONDA_HOME)/lib
# Homebrew installs numpy in a non standard path (keg only)
# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include
# PYTHON_LIB += $(shell brew --prefix numpy)/lib
# Uncomment to support layers written in Python (will link against Python libs)
WITH_PYTHON_LAYER := 1
# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
# INCLUDE_DIRS += $(shell brew --prefix)/include
# LIBRARY_DIRS += $(shell brew --prefix)/lib
# NCCL acceleration switch (uncomment to build with NCCL)
# https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0)
# USE_NCCL := 1
# Uncomment to use `pkg-config` to specify OpenCV library paths.
# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
# USE_PKG_CONFIG := 1
# N.B. both build and distribute dirs are cleared on `make clean`
BUILD_DIR := build
DISTRIBUTE_DIR := distribute
# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
# DEBUG := 1
# The ID of the GPU that 'make runtest' will use to run unit tests.
TEST_GPUID := 0
# enable pretty build (comment to see full commands)
Q ?= @
编译
make -j32
make pycaffe
make matcaffe
make test -j24
make runtest -j24
或者使用CMake编译
mkdir build
cd build
cmake -DBLAS=open ..
make -j32
make install
验证
cd ~/caffe-master/python
ipython
输入
import caffe
caffe.__version__
同时make runtest
也必须能通过才算成功
错误及解决方法
- 错误一:
In file included from ./include/caffe/util/device_alternate.hpp:40:0,
from ./include/caffe/common.hpp:19,
from ./include/caffe/blob.hpp:8,
from ./include/caffe/layers/batch_norm_layer.hpp:6,
from src/caffe/layers/batch_norm_layer.cpp:4:
./include/caffe/util/cudnn.hpp:8:34: 致命错误:caffe/proto/caffe.pb.h:没有那个文件或目录
#include "caffe/proto/caffe.pb.h"
^
编译中断。
The bug is not reproducible, so it is likely a hardware or OS problem.
make: *** [.build_release/src/caffe/layers/batch_norm_layer.o] 错误 1
make: *** 正在等待未完成的任务....
解决方法:
https://github.com/NVIDIA/DIGITS/issues/105
protoc src/caffe/proto/caffe.proto --cpp_out=.
mkdir include/caffe/proto
mv src/caffe/proto/caffe.pb.h include/caffe/proto
- 错误二
[zhangxinming@localhost caffe-master]$ make pycaffe
CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
**python/caffe/_caffe.cpp:10:31:** **致命错误:**numpy/arrayobject.h:没有那个文件或目录
#include
** ^**
编译中断。
make: *** [python/caffe/_caffe.so] 错误 1
提示arrayobject.h没找到,于是使用find / -name arrayobject.h
是存在的,
[root@localhost caffe-master]# find / -name arrayobject.h
/usr/local/lib/python2.7/site-packages/numpy/core/include/numpy/arrayobject.h
判断是Makefile.config 的python的include路径出问题了
修改路径如下:
PYTHON_INCLUDE := /usr/local/include/python2.7 /usr/local/lib/python2.7/site-packages/numpy/core/include
再次进行编译即可
- 错误三:
在make runtest 时出现如下错误
[zhangxinming@localhost caffe-master]$ make runtest -j8
.build_release/tools/caffe
.build_release/tools/caffe: error while loading shared libraries: libboost_system.so.1.55.0: cannot open shared object file: No such file or directory
make: *** [runtest] 错误 127
解决办法:
运行find 发现是有这个库的,只是没有加入到运行库的path里面去而已
vi /etc/profile
#添加如下内容
#Base LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/lib:/lib64:/usr/lib:/usr/lib64:/usr/local/lib:/usr/local/lib64
#CUDA
export PATH=/usr/local/cuda-8.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH
重建缓存
source /etc/profile
sudo ldconfig
再次运行make runtest -j8
即可
至此,caffe的编译工作完成
其他用户使用时,请一定要使用pyhotn虚拟环境,避免干扰其他用户和项目,请移步本人博客开始你的envpython之旅——传送门==Python Virtual Environments虚拟环境导引
另外你可以移步CentOS 7 搭建Tensorflow环境,快速搭建起自己的TensorFlow环境,记得要的虚拟环境下进行哟~