eugene-lim-260668

Background

最近公司在弄數位貨幣相關的東西. 那我負責建立礦池的部分. 所以紀錄一下這整個建立的過程.

Requirements

  • VPS with at least 2GB of Ram
  • 硬碟空間至少大於50G
  • Ubuntu Ubuntu 16.04 LTS
  • go >= 1.9
  • geth or parity
  • redis-server >= 2.8.0
  • nodejs >= 4 LTS
  • nginx

Installation

我是在AWS上開一台 VPS 滿足前兩點的需求. 接下來就是安裝需要安裝的東西.

1. Update

$ sudo apt-get update
$ sudo apt-get dist-upgrade
$ sudo apt-get install build-essential make
$ sudo reboot

2. Install GoLang

$ wget https://dl.google.com/go/go1.10.2.linux-amd64.tar.gz
$ sudo tar -xvf go1.10.2.linux-amd64.tar.gz
$ sudo mv go /usr/local
$ sudo vim ~/.profile

~/.profile

...
# set PATH so it includes user's private bin directories
PATH="$HOME/bin:$HOME/.local/bin:$PATH"
export PATH=$PATH:/usr/local/go/bin
$ source ~/.profile
$ go version
go version go1.10.2 linux/amd64

3. Installing Redis and Test

Build and Install Redis

$ sudo apt-get update
$ sudo apt-get install build-essential tcl
$ curl -O http://download.redis.io/redis-stable.tar.gz
$ tar xzvf redis-stable.tar.gz
$ cd redis-stable
$ make
$ make test
$ sudo make install

Configure Redis

$ sudo mkdir /etc/redis
$ sudo cp ~/redis-stable/redis.conf /etc/redis
$ sudo vim /etc/redis/redis.conf

/etc/redis/redis.conf

. . .

# Set supervised to systemd
supervised systemd

# Set the dir
dir /var/lib/redis

. . .

Create a Redis systemd Unit File

$ sudo vim /etc/systemd/system/redis.service

/etc/systemd/system/redis.service

[Unit]
Description=Redis In-Memory Data Store
After=network.target

[Service]
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always

[Install]
WantedBy=multi-user.target

Create the Redis User, Group and Directories

$ sudo adduser --system --group --no-create-home redis
$ sudo mkdir /var/lib/redis
$ sudo chown redis:redis /var/lib/redis
$ sudo chmod 770 /var/lib/redis

Start and Test Redis

$ sudo systemctl start redis
$ sudo systemctl status redis

Test the Redis Instance Functionality

$ redis-cli
$ ping
PONG
$ exit

Enable Redis to Start at Boot

$ sudo systemctl enable redis

4. Install Node.js

$ sudo apt-get update
$ sudo apt-get install nodejs
$ sudo apt-get install npm
$ nodejs -v
$ sudo ln -s /usr/bin/nodejs /usr/bin/node

5. User Setup

這邊是用EC2的關係, 我就使用default的user 'ubuntu'. 所以這段我就不介紹了. 反正不要使用root來run相關的程式就對了.

6. Ethereum Daemon Setup (Wallet)

$ cd ~
$ git clone https://github.com/ethereum/go-ethereum
$ cd go-ethereum
$ export GOROOT=/usr/local/go
$ export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
$ export GOPATH=$HOME/go
$ make all

7. Run Eth for First Time

$ cd build/bin/
$ ./geth --rpc --rpcaddr 127.0.0.1 --rpcport 8545 --cache=1024

It will start sync process depend on speed of of your server it may take time to completely sync. Once complete now we need generate wallet address in our pool wallet

大概會花約30分鐘左右的時間來同步資料. 創造一個node.

這部分先跳過改天再補回來.

8. Running Pool

$ sudo mkdir /var/www
$ sudo chown -R ubuntu:root www
$ git clone https://github.com/sammy007/open-ethereum-pool.git
$ cd open-ethereum-pool
$ make
$ cp config.example.json config.json
# edit config.json for your own setting
$ ./build/bin/open-ethereum-pool config.json

9. Building Frontend

$ vim www/config/environment.js
# change ApiUrl: '//example.net/' to your pool api url
$ cd /var/www/open-ethereum-pool
$ sudo npm install -g ember-cli@2.9.1
$ sudo npm install -g bower
$ cd www
$ npm install
$ bower install
$ ./build.sh

10. Set Nginx

$ sudo apt-get install nginx
$ sudo vim /etc/nginx/sites-available/eth

/etc/nginx/sites-available/eth

upstream api {
    server 127.0.0.1:8080;
}

server {
    listen 80;
    server_name IP or DOMAIN_NAME;
    root /var/www/open-ethereum-pool/www/dist;

    location / {
    }

    location /api {
        proxy_pass http://api;
    }
}
$ sudo ln -s /etc/nginx/sites-available/eth /etc/nginx/sites-enabled
$ sudo systemctl restart nginx
$ sudo systemctl status nginx
# see the nginx result

結論

大致上的流程是這樣. 其實不難啦. 但麻煩的是之後整個礦池的架構&進去以太坊節點的部分. 之後有機會在做相關的紀錄.

Reference