用unomp自己搭建比特币矿池

in #cn-0076 years ago (edited)

2017年12月初,我在一台VPS主机上搭建成功了一个unomp矿池(https://github.com/UNOMP/unified-node-open-mining-portal),并在测试网络上挖了110个BTC,当时写了一篇文章分享了矿工与矿池之间通讯的stratum通讯协议的技术细节,这次分享出整个搭建过程。

阿里云ECS主机的配置:2核CPU,4GB (I/O优化)内存,1Mbps专有网络,40GB硬盘,还配了一块好贵的200GB数据盘,包月价283元。跑通整个流程后,无力支付高昂的云租金,该主机已被销毁。我在自己机器的VirtualBox中也搭建成功过。

安装前准备

用浏览器登录阿里云也可以进入控制台管理界面,但功能非常弱,最好使用PuTTY软件登录。如果无法驾驭vi编辑器或ftp传输文件,最好使用WinSCP工具,两款工具都是免费的。

我使用的操作系统是64位的Ubuntu 16.04,整个安装过程主要参考了这篇文档:
https://github.com/UNOMP/unified-node-open-mining-portal

用浏览器登录的控制台界面

系统管理员root的权限太强大,为了防止误操作,建立一个新用户shenlb。
adduser shenlb

有些软件是用源代码编译生成,提前安装好git。
apt install git

安装bitcoind

unomp本身可以支持很多种币,我这里以比特币矿池为例,所以得先安装一个全节点的比特币客户端,官方推荐的是bitcoind。

https://launchpad.net/~bitcoin/+archive/ubuntu/bitcoin

用root权限,执行如下命令:

apt-get update
apt-get install software-properties-common 
add-apt-repository ppa:bitcoin/bitcoin
apt-get update
apt-get install bitcoind

启动bitcoind,这里先使用测试网络testnet,区块数据写入文件夹/core-data中。
bitcoind -datadir=/core-data -testnet -daemon

修改/core-data文件夹下的bitcoin.conf,以备后面与矿池软件进行rpc调用。

server=1
rpcuser=user
rpcpassword=pass

安装nodejs、npm等程序

unomp的主体代码是2014、2015年开发完成的,要依赖nodeljs,而且还不能用最新的版本,先一股脑安装上。

sudo apt-get install build-essential libssl-dev npm nodejs nodejs-legacy
curl https://raw.githubusercontent.com/creationix/nvm/v0.16.1/install.sh | sh
source ~/.profile

nvm是nodejs的版本管理器,这里也比较挑剔。

nvm install 0.10.25
nvm use 0.10.25

现在可以下载并安装unomp了。

git clone https://github.com/UNOMP/unified-node-open-mining-portal.git unomp
cd unomp
npm update

安装redis

为了保证矿池的访问效率,unomp内部也使用了redis内存键值数据库,参考文档:
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-redis

apt-get update
apt-get install build-essential
apt-get install tcl8.5
wget http://download.redis.io/releases/redis-stable.tar.gz
tar xzf redis-stable.tar.gz
cd redis-stable
make
make test
make install
cd utils
./install_server.sh

用下面两条命令启动和停止redis服务:

sudo service redis_6379 start
sudo service redis_6379 stop

用下面命令将redis设置为开机自动启动:
sudo update-rc.d redis_6379 defaults

修改config.json

上面就完成了整个安装过程,为了将程序跑起来,需要修改一些配置文件。首先在unomp文件夹下找到config.json.example文件,复制为config.json。
cp config.json.example config.json
config.json里有许多配置选项,不明白的保持默认值,我修改的地方用##标注。

    "logLevel": "debug",
    "logColors": true,

    "cliPort": 17117,

    "clustering": {
        "enabled": true,
        "forks": "auto"
    },

    "defaultPoolConfigs": {
        "blockRefreshInterval": 1000,
        "jobRebroadcastTimeout": 55,
        "connectionTimeout": 600,
        "emitInvalidBlockHashes": false,
        "validateWorkerUsername": true,
        "tcpProxyProtocol": false,
        "banning": {
            "enabled": true,
            "time": 600,
            "invalidPercent": 50,
            "checkThreshold": 500,
            "purgeInterval": 300
        },
        "redis": {
            "host": "127.0.0.1",
            "port": 6379,
            "db": 0,
            "password": ""  ## 正式运行的矿池需要设置redis的密码
        }
    },

    "website": {
        "enabled": true,
        "host": "0.0.0.0",
        "siteTitle": "UNOMP Beta by shenlb", ## 网站的标题
        "port": 8080, ## 改成自己喜欢的端口,阿里云还需要配置安全组,放开相应端口
        "stratumHost": "pool.unomp.org",
        "stats": {
            "updateInterval": 60,
            "historicalRetention": 43200,
            "hashrateWindow": 300,
            "graphColors": ["#058DC7", "#50B432", "#ED561B", "#DDDF00", "#24CBE5", "#64E572",
            "#FF9655", "#FFF263", "#6AF9C4"]
        },
        "adminCenter": {
            "enabled": true,
            "password": "password" ## 修改密码
        }
    },

    "redis": {
        "host": "127.0.0.1",
        "port": 6379,
        "db": 0,
        "password": ""
    },

    "switching": {
        "switch1": {
            "enabled": false,
            "algorithm": "sha256", ## 这是比特币工作量证明的算法
            "ports": {
                "3333": {
                    "diff": 10,  ## 初始难度
                    "varDiff": {
                        "minDiff": 16,
                        "maxDiff": 512,
                        "targetTime": 15,
                        "retargetTime": 90,
                        "variancePercent": 30
                    }
                }
            }
        },
        "switch2": {
            ... ## 其它的挖矿算法,这里略过
        },
        "switch3": {
            ... ## 其它的挖矿算法,这里略过
            }
        }
    },

    "profitSwitch": {
        "enabled": false,
        "updateInterval": 600,
        "depth": 0.90,
        "usePoloniex": true,
        "useBittrex": true
    }

配置bitcoin.json文件

在pool_configs文件夹下还需要编辑好一个相应币种的json,对于比特币就是bitcoin.json。

    "enabled": true,
    "coin": "bitcoin.json",

    "auxes": [ ], ## 留空
    "address": "12rP8udMb5ueJ4uzx8V7YHM9RMvcUKdrFa", ## 最后的币发到这里

    "rewardRecipients": {
         "12rP8udMb5ueJ4uzx8V7YHM9RMvcUKdrFa" : 1.0 ## 将1%的币发给这个地址
    },

    "paymentProcessing": {
        "enabled": true,
        "paymentInterval": 600,
        "minimumPayment": 0.01,
        "daemon": {
            "host": "127.0.0.1",
            "port": 8332,
            "user": "slb", ## 与bitcoind的rpcuser和rpcpassword相对应
            "password": "your-password" ## 你的密码
        }
    },

    "ports": {
        "3032": {
            "diff": 8
        },
        "3008": {
            "diff": 64, ## 可以调整初始难度值
            "varDiff": {
                "minDiff": 8,
                "maxDiff": 512,
                "targetTime": 15,
                "retargetTime": 90,
                "variancePercent": 30
            }
        },
        "3256": {
            "diff": 256
        }
    },

    "daemons": [
        {
            "host": "127.0.0.1",
            "port": 8332,
            "user": "slb", ## 与bitcoind的rpcuser和rpcpassword相对应
            "password": "your-password" ## 你的密码
        }
    ],

    "p2p": {
        "enabled": false,
        "host": "127.0.0.1",
        "port": 19333,
        "disableTransactions": false
    },

    "mposMode": { ## mpos我没有配置
        "enabled": false,
        "host": "127.0.0.1",
        "port": 3306,
        "user": "me",
        "password": "mypass",
        "database": "ltc",
        "checkPassword": false,
        "autoCreateWorker": false
    }

启动矿池

如果配置无误,现在可以正常启动了。

nvm use 0.10.25
node init.js

然后在浏览器 访问服务器的8080端口,一个矿池就搭建完成了。

unomp.jpg

如何测试?肯定不舍得直接拿ASIC矿机做测试,可以用pooler cpuminer,自行google就可以找到,我用的是windows下的2.5.0版本,里面有详细的命令行选项,可以用来排查故障原因。当然,一次跑通矿池,肯定是不可能的,还需要搞明白矿工与矿池之间通讯的stratum通讯协议

按比特币的当前总算力估计,得有1万台矿机才能自己搭个矿池玩玩,当然你也可以用这种办法搭个其它币的矿池,坐收5%的矿池服务费。

本文由币乎(bihu.com)内容支持计划奖励

Sort:  

这要是真实网络,你挖得120个BTC,那就不得了啊。

用神马矿机在真实网络跑了一个小时,什么也没挖出来,据说得连续运行2年能挖出1BTC。

貌似 unomp 和 bitcoind 之间还是走的 getblocktemplate 协议?

技术强大!可以发行自己的币种了!

原来是技术大咖啊!幸会幸会,被你110个BTC吓住了,还以为真实是网络,哈哈

标题党很有效

請問這個方法也可以用來搭建以太礦池嗎??

Congratulations @speeding! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.28
TRX 0.13
JST 0.032
BTC 61143.11
ETH 2928.78
USDT 1.00
SBD 3.56