CentOS 7 使用 Clang 编译安装 qBittorrent
CentOS 7 使用 Clang 编译安装 qBittorrent
Clang的编译速度相较GCC能提速20%左右,且能带来较低的编译期内存占用
准备工作
- 脑子,眼睛,手
- CentOS 7 系统
- 如果人在国内,请改为国内镜像,推荐清华TUNA源
- 一个通畅的网络,至少需要能够从github流畅下载源代码
- 如果不具有此条件,可以使用fastgit镜像站或者本人自建的镜像站
- 最低要求1GiB及以上内存
- 更低的内存我没有试过,如果你内存较少,可以尝试加点swap
- 如果内存太小很有可能在编译
libtorrent
的时候编译器暴毙
开始安装
- 为了防止污染其他目录,建议全程在/tmp目录下进行操作
- 本教程默认你是root用户进行的操作,如果不是root用户请通过
sudo su
切换为root用户 - 建议参考qBitorrent提供的官方编译教程
安装Clang工具链以及相关依赖
因为这个教程是安装好以后写的,所以我也不记得安装了什么包,缺包的话自己装(逃)
yum -y install centos-release-scl #安装scl仓库
yum -y install llvm-toolset-7 #安装llvm工具链
yum -y install qt-devel openssl-devel qt5-qtbase-devel qt5-linguist #安装其他依赖
进入工具链环境
scl enable llvm-toolset-7 bash #也可以换成其他的什么shell
export CC=clang CXX=clang++ #通过环境变量设置编译器
编译安装boost
目前笔者最新的boost
版本是1.74.0
,可以去官网获取下载最新版本
先下载源码,进入源码目录
curl -L https://dl.bintray.com/boostorg/release/1.74.0/source/boost_1_74_0.tar.gz | tar -xz #使用管道可以直接解压到源码而免去中间文件
cd boost_1_74_0
开始编译
这两步可能需要较长的时间,你可以恰个饭再回来
./bootstrap.sh --prefix=/usr --with-toolset=clang #使用clang配置boost编译,安装到/usr
./b2 toolset=clang --prefix=/usr --without-python -j$(nproc) #使用与核心数相当的进程数用clang编译安装boost到/usr
编译安装libtorrent
本教程安装libtorrent 1.2
,其他版本请自己举一反三
在本人沟通(libtorrent#5120)后,已经可以在clang下完美编译
安装完毕后退回到母目录,下载源码
cd /tmp #也可以是你自己的工作目录
git clone --depth 1 -b RC_1_2 https://github.com/arvidn/libtorrent.git #也或者是其他github镜像
cd libtorrent
开始编译
# 请确保你的环境变量中有CC=clang CXX=clang++
./configure --prefix=/usr --disable-debug --enable-encryption --with-boost=/usr #配置编译
make -j$(nproc) #使用和核心数相同的进程数编译,最大利用CPU资源
make install #安装
ln -s /usr/lib/pkgconfig/libtorrent-rasterbar.pc /usr/lib64/pkgconfig/libtorrent-rasterbar.pc #解决运行库问题
编译安装qBittorrent
终于要安装本体了
下载源码
#和上面libtorrent的步骤类似,就不单独说明了
cd /tmp
git clone --depth 1 -b v4_2_x https://github.com/qbittorrent/qBittorrent
cd qBittorrent
开始编译
#和上面libtorrent的步骤类似,就不单独说明了
./configure --prefix=/usr --disable-gui CPPFLAGS=-I/usr/include/qt5 --with-boost=/usr
make -j$(nproc)
make install
配置qBittorrent
为系统服务
在配置服务器之前,先手动运行一次qbittorrent-nox
查看是否能正常运行,并同意法律许可
使用随便你喜欢的什么文本编辑器(推荐nano
)
写入文件到/etc/systemd/system/qbittorrent.service
,内容如下:
[Unit]
Description=qBittorrent-nox service
Documentation=man:qbittorrent-nox(1)
Wants=network-online.target
After=network-online.target nss-lookup.target
[Service]
# if you have systemd < 240 (Ubuntu 18.10 and earlier, for example), you probably want to use Type=simple instead
Type=exec
# change user as needed
User=qbtuser
# notice that no -d flag needed
ExecStart=/usr/bin/qbittorrent-nox
# uncomment this for versions of qBittorrent < 4.2.0 to set the maximum number of open files to unlimited
#LimitNOFILE=infinity
[Install]
WantedBy=multi-user.target
之后启动该服务并将其设置为开机自启
systemctl enable --now qbittorrent.service
访问<服务器IP>:8080
部署完成!
- 用户名:
admin
- 密码:
adminadmin
本文链接:https://blog.mnixry.cn/Technology/centos-7-compile-install-qbittorrent-with-clang.html
该博客遵守 CC BY-NC-SA 4.0 协议