From ecbc3e758053b25070adeff9079feb2cea4d0110 Mon Sep 17 00:00:00 2001 From: wiz Date: Mon, 25 May 2020 20:58:46 +0900 Subject: [PATCH] Add production site setup guide and related install scripts --- production/README.md | 161 ++++++++++++++++++++++++++++++- production/electrs-start-liquid | 22 +++++ production/electrs-start-mainnet | 19 ++++ production/electrs-start-testnet | 19 ++++ production/mempool-install-all | 2 + 5 files changed, 222 insertions(+), 1 deletion(-) create mode 100755 production/electrs-start-liquid create mode 100755 production/electrs-start-mainnet create mode 100755 production/electrs-start-testnet diff --git a/production/README.md b/production/README.md index 5e9f55969..5529ad766 100644 --- a/production/README.md +++ b/production/README.md @@ -1 +1,160 @@ -### misc scripts for running mempool.space production site +# mempool.space v2 production website hosting + +These instructions are for setting up a serious production mempool website for Mainnet, Testnet, and Liquid. For home users, follow the main instructions instead. + +### Server Hardware + +Mempool V2 is powered by electrs, which is a beast. I recommend a beefy server: + +* 16C CPU (more is better) +* 64G RAM (more is better) +* 2TB SSD (NVMe is better) + +### HDD vs SSD vs NVMe + +If you don't have a fast SSD or NVMe backed disk, that's fine. What you do is, go online and buy some fast new NVMe drives and wait for them to arrive. After you install them, throw away your old HDDs and then proceed with the rest of this guide. + +## FreeBSD 12 + +The mempool.space site is powered by FreeBSD with ZFS root and ARC cache for maximum performance. Linux probably works fine too, but why settle? + +### Build Dependencies + +You'll probably need these: +``` +pkg install -y zsh sudo git screen vim-console curl wget calc neovim rsync +pkg install -y openssl openssh-portable open-vm-tools-nox11 py27-pip py37-pip +pkg install -y boost-libs autoconf automake gmake gcc libevent libtool pkgconf +pkg install -y mariadb55-server mariadb55-client nginx py37-certbot-nginx +``` + +### Rust + +I recommend to build rust from latest source: +``` +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh +``` + +### Bitcoin + +Build [Bitcoin Core](https://github.com/bitcoin/bitcoin) from source. Alternatively, install the OS packages: +``` +pkg install -y bitcoin-daemon bitcoin-utils +``` + +Configure your bitcoin.conf like this: +``` +server=1 +daemon=1 +listen=1 +discover=1 +txindex=1 +par=16 +dbcache=3700 +maxconnections=1337 +timeout=30000 +onion=127.0.0.1:9050 +rpcallowip=127.0.0.1 +rpcuser=0cd862dce678b830bd2aa36f10b9b6b2 +rpcpassword=2d89d36cac4a13c87b5d19ef8f577e37 +rpcworkqueue=128 +rpcthreads=32 +rpctimeout=60 +uacomment=@wiz + +[main] +bind=127.0.0.1:8333 +rpcbind=127.0.0.1:8332 + +[test] +bind=127.0.0.1:18333 +rpcbind=127.0.0.1:18332 +``` + +### Elements + +Build [Elements Core](https://github.com/ElementsProject/elements) from source: +``` +./autogen.sh +MAKE=gmake CC=cc CXX=c++ CPPFLAGS=-I/usr/local/include \ +./configure --with-gui=no --disable-wallet +gmake -j19 +gmake install +``` + +Configure your elements.conf like this: +``` +server=1 +daemon=1 +listen=1 +chain=liquidv1 +rpcuser=liquiduser +rpcpassword=liquidpass +validatepegin=1 +mainchainrpchost=127.0.0.1 +mainchainrpcport=8332 +mainchainrpcuser=user +mainchainrpcpassword=pass +txindex=1 +``` + +Start elementsd and wait for it to sync the Liquid blockchain. + +### Electrs + +Install [Electrs](https://github.com/Blockstream/electrs) from source: +``` +git clone https://github.com/Blockstream/electrs +cd electrs +git checkout new-index +``` + +You'll need 3 instances, one for each network. Build one at a time: +``` +./electrs-start-mainnet +./electrs-start-testnet +./electrs-start-liquid +``` + +### MariaDB + +Import historical mempool fee database snapshot, or the blank mariadb structure if none: +``` +mysql -u mempool -p mempool < /mempool/mempool/mariadb-structure.sql +``` + +### Mempool + +After all 3 electrs instances are fully indexed, install your 3 mempool nodes: +``` +./mempool-install-all +./mempool-upgrade-all +``` + +Finally, start your 3 mempool backends: +``` +./mempool-start-all +``` + +### Nginx + +Get SSL certificate using certbot: +``` +certbot --nginx -d mempool.space +``` + +Install nginx.conf from this repo, edit as necessary: +``` +cp nginx.conf /usr/local/etc/nginx/nginx.conf +vi /usr/local/etc/nginx/nginx.conf +``` + +Restart nginx +``` +service nginx restart +``` + +### Done + +Your site should look like https://mempool.space/ +If it doesn't ask wiz on Keybase DM or Twitter for help. diff --git a/production/electrs-start-liquid b/production/electrs-start-liquid new file mode 100755 index 000000000..35ad7f713 --- /dev/null +++ b/production/electrs-start-liquid @@ -0,0 +1,22 @@ +#!/usr/local/bin/zsh +cd /electrs +source $HOME/.cargo/env +export PATH=$HOME/.cargo/bin:$PATH + +until false +do + cargo run \ + --release \ + --features liquid \ + --bin electrs \ + -- \ + -vvv \ + --address-search \ + --network liquid \ + --daemon-dir /elements \ + --http-addr '[::]:3001' \ + --monitoring-addr '127.0.0.1:4225' \ + --cookie 'user:pass' \ + --precache-scripts $HOME/electrs/contrib/popular-scripts.txt + sleep 1 +done diff --git a/production/electrs-start-mainnet b/production/electrs-start-mainnet new file mode 100755 index 000000000..75172bf33 --- /dev/null +++ b/production/electrs-start-mainnet @@ -0,0 +1,19 @@ +#!/usr/local/bin/zsh +cd /electrs +source $HOME/.cargo/env +export PATH=$HOME/.cargo/bin:$PATH + +until false +do + cargo run \ + --release \ + --bin electrs \ + -- \ + -vvvv \ + --address-search \ + --daemon-dir /bitcoin \ + --http-addr '[::]:3000' \ + --cookie 'user:pass' \ + --precache-scripts /electrs/contrib/popular-scripts.txt + sleep 1 +done diff --git a/production/electrs-start-testnet b/production/electrs-start-testnet new file mode 100755 index 000000000..b6a66263a --- /dev/null +++ b/production/electrs-start-testnet @@ -0,0 +1,19 @@ +#!/usr/local/bin/zsh +cd /electrs +source $HOME/.cargo/env +export PATH=$HOME/.cargo/bin:$PATH + +until false +do + cargo run \ + --release \ + --bin electrs \ + -- \ + -vv \ + --network testnet \ + --daemon-dir /bitcoin \ + --http-addr '[::]:3002' \ + --cookie 'user:pass' \ + --precache-scripts /electrs/contrib/popular-scripts.txt + sleep 1 +done diff --git a/production/mempool-install-all b/production/mempool-install-all index 0f9a17717..d238d88ba 100755 --- a/production/mempool-install-all +++ b/production/mempool-install-all @@ -2,8 +2,10 @@ for site in mainnet liquid testnet do git clone https://github.com/mempool/mempool "${HOME}/${site}" + mkdir -p "${HOME}/public_html/${site}/" cd "${HOME}/${site}/backend/" cp "../production/mempool-config.${site}.json" "mempool-config.json" + touch cache.json npm install npm run build cd "${HOME}/${site}/frontend/"