btcpool 编译安装,以及ETH私池搭建
部署条件
部署系统: ubuntu 18.04
矿池交互图
编译源代码
git clone https://github.com/btccom/btcpool.git
安装依赖
sudo apt-get update
sudo apt-get install -y git build-essential autotools-dev libtool autoconf automake pkg-config cmake \
openssl libssl-dev libcurl4-openssl-dev libconfig++-dev \
libboost-all-dev libgmp-dev libmysqlclient-dev libzookeeper-mt-dev \
libzmq3-dev libgoogle-glog-dev libhiredis-dev zlib1g zlib1g-dev \
libsodium-dev libprotobuf-dev protobuf-compiler
注意:不再建议libevent-dev
从软件源安装。 libevent
的发行版和稳定版本将在sserver中导致死锁错误(问题#75)。建议您使用下面的命令从它的master
分支手动构建libevent
。
有时一个或两个软件包由于依赖关系问题而失败,您可以尝试aptitude
sudo apt-get update
sudo apt-get install -y aptitude
sudo aptitude install git build-essential autotools-dev libtool autoconf automake pkg-config cmake \
openssl libssl-dev libcurl4-openssl-dev libconfig++-dev \
libboost-all-dev libgmp-dev libmysqlclient-dev libzookeeper-mt-dev \
libzmq3-dev libgoogle-glog-dev libhiredis-dev zlib1g zlib1g-dev \
libsodium-dev libprotobuf-dev protobuf-compiler
# Input `n` if the solution is `NOT INSTALL` some package.
# Eventually aptitude will give a solution that downgrade some packages to allow all packages to be installed.
安装ZooKeeper
安装依赖
sudo apt-get install -y zookeeper zookeeper-bin zookeeperd
创建所需目录
mkdir -p /data/work/zookeeper
mkdir /data/work/zookeeper/version-2
touch /data/work/zookeeper/myid
sudo chown -R zookeeper:zookeeper /data/work/zookeeper
设置机器id
sudo echo 1 > /data/work/zookeeper/myid
修改配置
sudo vim /etc/zookeeper/conf/zoo.cfg
initLimit=5
syncLimit=2
clientPort=2181
clientPortAddress=127.0.0.1
dataDir=/data/work/zookeeper
#伪分布式
server.1=127.0.0.1:2888:3888
启动服务
#start/stop service
sudo service zookeeper restart
#service zookeeper start/stop/restart/status
安装Kafka
安装依赖
sudo apt-get install -y default-jre
安装java 1.8
sudo apt-get update
sudo apt-get install openjdk-8-jdk
update-alternatives --display java
sudo update-alternatives --config java
java -version
安装kafka
mkdir -p /data/work/kafka
cd /data/work/kafka
wget https://archive.apache.org/dist/kafka/0.11.0.2/kafka_2.11-0.11.0.2.tgz
tar -zxf ./kafka_2.11-0.11.0.2.tgz --strip 1
编辑配置
vim /data/work/kafka/config/server.properties
broker.id=1
offsets.topic.replication.factor=1
message.max.bytes=20000000
replica.fetch.max.bytes=30000000
log.dirs=/data/work/kafka-logs
listeners=PLAINTEXT://127.0.0.1:9092
#伪分布式
zookeeper.connect=127.0.0.1:2181
#start server
cd /data/work/kafka
nohup /data/work/kafka/bin/kafka-server-start.sh /data/work/kafka/config/server.properties > /dev/null 2>&1 &
遇到问题
yw_manager@web204_234:/data/work/kafka$ /data/work/kafka/bin/kafka-server-start.sh /data/work/kafka/config/server.properties
[0.000s][warning][gc] -Xloggc is deprecated. Will use -Xlog:gc:/data/work/kafka/bin/../logs/kafkaServer-gc.log instead.
Unrecognized VM option 'PrintGCDateStamps'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
解决方案
降级java 1.8
从其master分支构建libevent
注意:版本2.1.9-beta之前的libevent将在sserver中导致死锁错误(问题#75)。请使用release-2.1.9-beta和更高版本。
wget https://github.com/libevent/libevent/releases/download/release-2.1.10-stable/libevent-2.1.10-stable.tar.gz
tar zxf libevent-2.1.10-stable.tar.gz
cd libevent-2.1.10-stable
./autogen.sh
./configure --disable-shared
make -j$(nproc) && sudo make install
编译librdkafka-v0.9.1
wget https://github.com/edenhill/librdkafka/archive/0.9.1.tar.gz
tar zxvf 0.9.1.tar.gz
cd librdkafka-0.9.1
./configure && make -j$(nproc) && sudo make install
# if you want to keep static libraries only
sudo rm -v /usr/local/lib/librdkafka*.so /usr/local/lib/librdkafka*.so.*
下载Bitcoin源码,并建立链接到BTCPool
支持ETH的矿池用BTC选项
mkdir work
sudo mv work/ /data/
cd /data/work
wget -O bitcoin-0.16.0.tar.gz https://github.com/bitcoin/bitcoin/archive/v0.16.0.tar.gz
tar zxf bitcoin-0.16.0.tar.gz
git clone https://github.com/btccom/btcpool.git
cd btcpool
mkdir build
cd build
# Release build:
cmake -DJOBS=4 -DCHAIN_TYPE=BTC -DCHAIN_SRC_ROOT=/data/work/bitcoin-0.16.0 ..
make -j$(nproc)
# Debug build:
cmake -DCMAKE_BUILD_TYPE=Debug -DCHAIN_TYPE=BTC -DCHAIN_SRC_ROOT=/data/work/bitcoin-0.16.0 ..
make -j$(nproc)
常见问题
使用当前最新版本bitcoin v0.21.0提示如下错误,暂时未跟进该问题,先用v0.16.0版本测试
CMake Error at CMakeLists.txt:267 (message):
/data/work/bitcoin-0.21.0/src/crypto/libbitcoin_crypto.a not exists!
估计是本地已安装boost版本问题,本项目依赖boost v1.65,删除本地已安装boost,重新运行第一步,安装依赖
/usr/local/include/boost/thread/pthread/condition_variable.hpp:131: undefined reference to `boost::this_thread::interruption_point()'
collect2: error: ld returned 1 exit status
CMakeFiles/jobmaker.dir/build.make:114: recipe for target 'jobmaker' failed
make[2]: *** [jobmaker] Error 1
CMakeFiles/Makefile2:125: recipe for target 'CMakeFiles/jobmaker.dir/all' failed
make[1]: *** [CMakeFiles/jobmaker.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
运行测试
./unittest
I0125 16:19:24.673416 7530 TestMain.cc:73] BTC unittest version 2020.06.09-11-fix-jobmaker-kafka-17-g0127a750
[==========] Running 91 tests from 24 test cases.
[----------] Global test environment set-up.
[----------] 1 test from BitcoinUtils
[ RUN ] BitcoinUtils.GetBlockRewardBitcoin
[ OK ] BitcoinUtils.GetBlockRewardBitcoin (1 ms)
[----------] 1 test from BitcoinUtils (1 ms total)
...
[----------] Global test environment tear-down
[==========] 91 tests from 24 test cases ran. (4711 ms total)
[ PASSED ] 91 tests.
初始化btcpool
初始化目录
cd /data/work/btcpool/build
bash ../install/init_folders.sh
设置全节点
docker for Parity
https://github.com/btccom/btcpool/tree/master/docker/eth-parity/latest
docker for Geth
https://github.com/btccom/btcpool/tree/master/docker/eth-geth/v1.8.23-btcpool-patched
安装mysql
sudo apt-get update
sudo apt-get install mysql-server
systemctl status mysql.service
初始化mysql数据库以及表
cd /data/work/btcpool/install
sudo mysql -uroot -p
CREATE DATABASE bpool_local_db;
USE bpool_local_db;
SOURCE bpool_local_db_ETH.sql;
CREATE DATABASE bpool_local_stats_db;
USE bpool_local_stats_db;
SOURCE bpool_local_stats_db.sql;
参考文档
https://github.com/btccom/btcpool-ABANDONED/blob/master/docs/INSTALL-ZooKeeper.md
https://github.com/btccom/btcpool-ABANDONED/blob/master/docs/INSTALL-Kafka.md
https://github.com/btccom/btcpool/blob/master/docs/INSTALL-BTCPool.md
https://www.pianshen.com/article/5122807736/
https://en.bitcoin.it/wiki/Merged_mining_specification
https://github.com/btccom/btcpool-go-modules/tree/master/mergedMiningProxy
https://blog.csdn.net/a1291985595/article/details/108799549