Lotus编译安装

Lotus 安装配置

一.Ubuntu 20.04.2初始设置

1.配置阿里源

http://mirrors.aliyun.com/

2.卸载snapd

1
2
3
4
5
6
$ snap list
$ snap remove lxd
$ snap remove core18
$ snap remove snapd
$ sudo apt-get remove snapd --purge	# 卸载snapd
$ sudo apt-get autoremove --purge  	# 卸载无用的squashfs-tools

二.编译环境安装

1.基础编译环境

1
2
$ sudo apt install mesa-opencl-icd ocl-icd-opencl-dev gcc git bzr jq pkg-config curl clang build-essential hwloc libhwloc-dev wget -y
$ sudo apt-get upgrade -y

2.环境变量配置

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# rustup 环境
source "$HOME/.cargo/env"

# Go 环境变量
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin

# Go 中国区加速
export GOPROXY=https://goproxy.cn

# 证明参数-中国区加快首次启动时的下载IPFS加速
export IPFS_GATEWAY=https://proof-parameters.s3.cn-south-1.jdcloud-oss.com/ipfs/
export FIL_PROOFS_PARAMETER_CACHE=/srv/FIL_PROOFS_PARAMETER_CACHE
export FIL_PROOFS_PARENT_CACHE=/srv/FIL_PROOFS_PARENT_CACHE

# 打开的文件限制并确保它至少设置为10000000
ulimit -n 1000000

# 其他配置
export BELLMAN_CPU_UTILIZATION=0.95 # CPU使用率
export FIL_PROOFS_MAXIMIZE_CACHING=1
export FIL_PROOFS_USE_GPU_COLUMN_BUILDER=1 # When having GPU.
export FIL_PROOFS_USE_GPU_TREE_BUILDER=1   # When having GPU.

3.Rust 安装及软件包镜像配置

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# 开始安装
# 安装包加速镜像
$ export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
$ export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup

# 其他
# 清华大学
RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup

# 中国科学技术大学
RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup

# 上海交通大学
RUSTUP_DIST_SERVER=https://mirrors.sjtug.sjtu.edu.cn/rust-static/

$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
$ source $HOME/.cargo/env
$ rustup default nightly
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 软件包国内镜像源
$ mkdir -p $HOME/.cargo
$ vim $HOME/.cargo/config


[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'rustcc'

# rustcc社区
[source.rustcc]
registry="git://crates.rustcc.com/crates.io-index"

[source.rustcc2]
registry="git://crates.rustcc.cn/crates.io-index"

# 清华大学
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"

# 中国科学技术大学
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"

# 上海交通大学
[source.sjtu]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"
####

如果编译源码的时候报错Updating crates.io index,是因为无法加载crate.io源,是并发下载的问题,可以重新编译下载。

4.Golang编译环境安装

官方一键安装命令

wget -c https://golang.org/dl/go1.16.linux-amd64.tar.gz -O - | sudo tar -xz -C /usr/local

wget -c https://golang.google.cn/dl/go1.16.linux-amd64.tar.gz -O - | sudo tar -xz -C /usr/local

a). 下载Golang安装包
1
2
3
4
5
# 下载golang安装包			
$ wget -c https://golang.org/dl/go1.16.linux-amd64.tar.gz
  # 国内加速
$ wget -c https://golang.google.cn/dl/go1.16.linux-amd64.tar.gz
$ tar -xvf go1.16.linux-amd64.tar.gz
b). 安装
1
2
3
$ sudo chown -R root:root ./go
$ sudo rm -rfv /usr/local/go
$ sudo mv go /usr/local/
c). Go环境变量
1
2
3
4
5
6
7
$ echo "GOPATH=$HOME/go" >> $HOME/.profile
$ echo "export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin" >> $HOME/.profile

# 配置国内goproxy代理
$ echo "export GOPROXY=https://goproxy.cn" >> $HOME/.profile
# 使环境变量生效
$ source $HOME/.profile
d). 查看验证golang版本
1
$ go version

三.开始编译安装

1.下载源码

1
2
3
# 以下任意皆可,第二个国内镜像能快点
$ git clone https://github.com/filecoin-project/lotus.git
$ git clone https://github.com.cnpmjs.org/filecoin-project/lotus.git

配置子模块镜像加速

1
2
3
4
5
# 手动修改.gitmodules为镜像地址https://hub.fastgit.org/或者https://github.com.cnpmjs.org
cd lotus
vim .gitmodules
# 运行git submodule sync 同步新配置到.git/config
git submodule update --init --recursive
1
2
3
4
5
6
# 根据情况切换分支
git checkout <branch_or_tag>
# 例如:
git checkout master # 主网
git checkout ntwk-calibration # calibration-net
git checkout ntwk-nerpa # nerpa-net

git分支中有脏状态,编译报错请尝试

git checkout <desired_branch>
git reset origin/<desired_branch> –hard
make clean

2.查看扩展指令集支持

1
$ grep  "adx\|sha" /proc/cpuinfo
  • 启用SHA扩展-如果您具有AMD Zen或Intel Ice Lake CPU(或更高版本),请通过添加以下两个环境变量:
1
2
3
4
5
export RUSTFLAGS="-C target-cpu=native -g"
export FFI_BUILD_FROM_SOURCE=1

## 启用 cuda 支持
export FFI_USE_CUDA=1
  • 没有ADX指令支持的较旧的Intel和AMD处理器可能会因非法指令错误而感到恐慌。要解决此问题,请添加CGO_CFLAGS环境变量:
1
2
export CGO_CFLAGS_ALLOW="-D__BLST_PORTABLE__"
export CGO_CFLAGS="-D__BLST_PORTABLE__"

3.编译安装

1
2
make clean all
sudo make install # 安装lotus,lotus-miner,lotus-worker到/usr/local/bin

默认情况下将使用$HOME/.lotus 文件夹进行存储(配置,链数据,钱包等)

4.安装为System系统服务文件

Lotus提供了通用的Systemd服务文件。它们可以通过以下方式安装:

1
2
sudo make install-daemon-service
sudo make install-miner-service

四.初始配置(CPU性能模式/关闭显卡驱动升级/sudoer)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# CPU performance
sudo apt-get install cpufrequtils
cpufreq-set -g performance
# close upgrade
sed -i  's/1/0' /etc/apt/apt.conf.d/10periodic
# recreate kernel initramfs
update-initramfs -u

# disable nvidia update
cat >> /etc/modprobe.d/blacklist-nouveau.conf <<EOF
blacklist nouveau
options nouveau modeset=0
EOF

# sudoers config
cat >>/etc/sudoers <<EOF
fil ALL=(ALL:ALL) ALL
EOF