2022-05-08 00:25:57 +02:00
# Deploying an Enterprise Production Instance
2020-05-25 13:58:46 +02:00
2022-05-08 00:25:57 +02:00
These instructions are for setting up a serious production Mempool website for Bitcoin (mainnet, testnet, signet), Liquid (mainnet, testnet), and Bisq.
Again, this setup is no joke—home users should use [one of the other installation methods ](../#installation-methods ).
2020-05-25 13:58:46 +02:00
### Server Hardware
2022-05-08 00:25:57 +02:00
Mempool v2 is powered by [blockstream/electrs ](https://github.com/Blockstream/electrs ), which is a beast.
I recommend a beefy server:
2020-05-25 13:58:46 +02:00
2022-05-08 00:25:57 +02:00
* 20-core CPU (more is better)
* 64GB RAM (more is better)
2022-01-04 07:28:17 +01:00
* 4TB SSD (NVMe is better)
2020-05-25 13:58:46 +02:00
### HDD vs SSD vs NVMe
2022-05-08 00:25:57 +02:00
If you don't have a fast SSD or NVMe-backed disk, that's fine—go online and buy some fast new NVMe drives. When they arrive, install them, throw away your old HDDs, and then proceed with the rest of this guide.
2020-05-25 13:58:46 +02:00
2022-01-04 07:28:17 +01:00
## FreeBSD 13
2020-05-25 13:58:46 +02:00
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?
2020-07-22 17:47:18 +02:00
### Filesystem
2022-01-04 07:28:17 +01:00
For maximum performance, I use 2x 2TB NVMe SSDs in a RAID 0 using ZFS with lots of RAM for the ARC L2 cache.
2020-07-22 17:47:18 +02:00
```
2022-01-04 07:28:17 +01:00
% zpool list -v
NAME SIZE ALLOC FREE CKPOINT EXPANDSZ FRAG CAP DEDUP HEALTH ALTROOT
nvm 3.62T 1.25T 2.38T - - 2% 34% 1.00x ONLINE -
nvd0p3 1.81T 629G 1.20T - - 2% 33.9% - ONLINE
nvd1p3 1.81T 646G 1.18T - - 2% 34.8% - ONLINE
2020-07-22 17:47:18 +02:00
```
2022-05-08 00:25:57 +02:00
For maximum flexibility of configuration, I recommend separate partitions for each data folder:
2020-07-22 17:47:18 +02:00
```
Filesystem Size Used Avail Capacity Mounted on
2022-01-04 07:28:17 +01:00
nvm/bisq 766G 1.1G 765G 0% /bisq
nvm/bitcoin 766G 648M 765G 0% /bitcoin
nvm/bitcoin/blocks 1.1T 375G 765G 33% /bitcoin/blocks
nvm/bitcoin/chainstate 770G 4.5G 765G 1% /bitcoin/chainstate
nvm/bitcoin/electrs 772G 7.3G 765G 1% /bitcoin/electrs
nvm/bitcoin/indexes 799G 34G 765G 4% /bitcoin/indexes
nvm/bitcoin/testnet3 765G 5.0M 765G 0% /bitcoin/testnet3
nvm/bitcoin/testnet3/blocks 786G 21G 765G 3% /bitcoin/testnet3/blocks
nvm/bitcoin/testnet3/chainstate 766G 1.1G 765G 0% /bitcoin/testnet3/chainstate
nvm/bitcoin/testnet3/indexes 768G 2.9G 765G 0% /bitcoin/testnet3/indexes
nvm/electrs 765G 128K 765G 0% /electrs
nvm/electrs/liquid 765G 104K 765G 0% /electrs/liquid
nvm/electrs/liquid/cache 765G 7.8M 765G 0% /electrs/liquid/newindex/cache
nvm/electrs/liquid/history 766G 886M 765G 0% /electrs/liquid/newindex/history
nvm/electrs/liquid/txstore 775G 10G 765G 1% /electrs/liquid/newindex/txstore
nvm/electrs/liquidtestnet 765G 112K 765G 0% /electrs/liquidtestnet
nvm/electrs/liquidtestnet/cache 765G 96K 765G 0% /electrs/liquidtestnet/newindex/cache
nvm/electrs/liquidtestnet/history 765G 96K 765G 0% /electrs/liquidtestnet/newindex/history
nvm/electrs/liquidtestnet/txstore 765G 96K 765G 0% /electrs/liquidtestnet/newindex/txstore
nvm/electrs/mainnet 765G 112K 765G 0% /electrs/mainnet
nvm/electrs/mainnet/cache 765G 4.4M 765G 0% /electrs/mainnet/newindex/cache
nvm/electrs/mainnet/history 1.0T 300G 765G 28% /electrs/mainnet/newindex/history
nvm/electrs/mainnet/txstore 1.3T 530G 765G 41% /electrs/mainnet/newindex/txstore
nvm/electrs/signet 766G 522M 765G 0% /electrs/signet
nvm/electrs/testnet 765G 104K 765G 0% /electrs/testnet
nvm/electrs/testnet/cache 765G 1.6M 765G 0% /electrs/testnet/newindex/cache
nvm/electrs/testnet/history 784G 19G 765G 2% /electrs/testnet/newindex/history
nvm/electrs/testnet/txstore 803G 38G 765G 5% /electrs/testnet/newindex/txstore
nvm/elements 766G 927M 765G 0% /elements
nvm/elements/electrs 766G 716M 765G 0% /elements/electrs
nvm/elements/liquidv1 777G 11G 765G 1% /elements/liquidv1
nvm/mempool 789G 24G 765G 3% /mempool
nvm/mysql 766G 648M 765G 0% /mysql
tmpfs 1.0G 1.3M 1.0G 0% /var/cache/nginx
tmpfs 3.0G 1.9G 1.1G 63% /bisq/statsnode-data/btc_mainnet/db/json
2020-07-22 17:47:18 +02:00
```
2020-05-25 13:58:46 +02:00
### Build Dependencies
You'll probably need these:
```
2022-05-09 06:57:48 +02:00
pkg install -y zsh sudo git screen curl wget neovim rsync nginx openssl openssh-portable py38-pip py38-certbot-nginx boost-libs autoconf automake gmake gcc libevent libtool pkgconf mariadb105-server mariadb105-client
2020-05-25 13:58:46 +02:00
```
2022-05-08 00:25:57 +02:00
### Node.js + npm
2020-09-18 14:53:58 +02:00
2022-05-10 06:59:09 +02:00
Build Node.js v16.15 and npm v8 from source using `nvm` :
2020-09-18 14:53:58 +02:00
```
2022-05-09 06:57:48 +02:00
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | zsh
source $HOME/.zshrc
2022-05-10 06:59:09 +02:00
nvm install v16.15.0
2022-05-09 06:57:48 +02:00
nvm alias default node
2020-09-18 14:53:58 +02:00
```
2020-05-25 13:58:46 +02:00
### Rust
2022-05-08 00:25:57 +02:00
Build Rust from latest source:
2020-05-25 13:58:46 +02:00
```
2022-05-09 06:57:48 +02:00
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
2020-05-25 13:58:46 +02:00
```
2020-05-26 16:13:57 +02:00
### Tor
2022-05-08 00:25:57 +02:00
Install Tor add Bitcoin to the `_tor` group:
2020-05-26 16:13:57 +02:00
```
2022-05-09 06:57:48 +02:00
pkg install -y tor
pw user mod bitcoin -G _tor
2020-05-26 16:13:57 +02:00
```
Then configure `/usr/local/etc/tor/torrc` as follows:
```
RunAsDaemon 1
SOCKSPort 9050
ControlPort 9051
Log notice syslog
CookieAuthentication 1
CookieAuthFileGroupReadable 1
2020-12-03 01:56:29 +01:00
CookieAuthFile /var/db/tor/control_auth_cookie
DataDirectory /var/db/tor
2020-05-26 16:13:57 +02:00
DataDirectoryGroupReadable 1
HiddenServiceDir /var/db/tor/mempool
2022-01-04 07:28:17 +01:00
HiddenServicePort 80 127.0.0.1:81
HiddenServiceVersion 3
HiddenServiceDir /var/db/tor/bisq
HiddenServicePort 80 127.0.0.1:82
2020-05-26 16:13:57 +02:00
HiddenServiceVersion 3
2022-01-04 07:28:17 +01:00
HiddenServiceDir /var/db/tor/liquid
HiddenServicePort 80 127.0.0.1:83
HiddenServiceVersion 3
```
2020-05-26 16:13:57 +02:00
2020-05-25 13:58:46 +02:00
### Bitcoin
Build [Bitcoin Core ](https://github.com/bitcoin/bitcoin ) from source. Alternatively, install the OS packages:
```
2022-05-09 06:57:48 +02:00
pkg install -y bitcoin-daemon bitcoin-utils
2020-05-25 13:58:46 +02:00
```
2022-05-08 00:25:57 +02:00
Configure your `bitcoin.conf` like this:
2020-05-25 13:58:46 +02:00
```
2022-01-04 07:28:17 +01:00
datadir=/bitcoin
2020-05-25 13:58:46 +02:00
server=1
2022-01-04 07:28:17 +01:00
txindex=1
2020-05-25 13:58:46 +02:00
listen=1
discover=1
2022-01-04 07:28:17 +01:00
par=16
dbcache=4096
maxmempool=1337
mempoolexpiry=999999
maxconnections=42
2020-05-25 13:58:46 +02:00
onion=127.0.0.1:9050
rpcallowip=127.0.0.1
2022-01-04 07:28:17 +01:00
rpcuser=foo
rpcpassword=bar
2020-05-25 13:58:46 +02:00
[main]
bind=127.0.0.1:8333
rpcbind=127.0.0.1:8332
2022-01-04 07:28:17 +01:00
whitelist=bloomfilter@127.0.0.1
2020-05-25 13:58:46 +02:00
[test]
2022-01-04 07:28:17 +01:00
daemon=1
2020-05-25 13:58:46 +02:00
bind=127.0.0.1:18333
rpcbind=127.0.0.1:18332
2022-01-04 07:28:17 +01:00
[signet]
daemon=1
bind=127.0.0.1:38333
rpcbind=127.0.0.1:38332
2020-05-25 13:58:46 +02:00
```
### Elements
Build [Elements Core ](https://github.com/ElementsProject/elements ) from source:
```
2022-05-09 06:57:48 +02:00
./autogen.sh
MAKE=gmake CC=cc CXX=c++ CPPFLAGS=-I/usr/local/include \
2022-05-08 00:25:57 +02:00
./configure --with-gui=no --disable-wallet
2022-05-09 06:57:48 +02:00
gmake -j19
gmake install
2020-05-25 13:58:46 +02:00
```
2022-05-08 00:25:57 +02:00
Configure your `elements.conf` like this:
2020-05-25 13:58:46 +02:00
```
server=1
daemon=1
listen=1
2022-01-04 07:28:17 +01:00
rpcuser=foo
rpcpassword=bar
2020-05-25 13:58:46 +02:00
mainchainrpchost=127.0.0.1
2022-01-04 07:28:17 +01:00
mainchainrpcuser=foo
mainchainrpcpassword=bar
2020-05-25 13:58:46 +02:00
txindex=1
2022-01-04 07:28:17 +01:00
[liquidv1]
validatepegin=1
mainchainrpcport=8332
[liquidtestnet]
validatepegin=0
anyonecanspendaremine=0
initialfreecoins=2100000000000000
con_dyna_deploy_start=0
con_max_block_sig_size=150
checkblockindex=0
fallbackfee=0.00000100
con_has_parent_chain=0
parentgenesisblockhash=NULL
pubkeyprefix=36
scriptprefix=19
blindedprefix=23
bech32_hrp=tex
blech32_hrp=tlq
pchmessagestart=410edd62
dynamic_epoch_length=1000
signblockscript=51210217e403ddb181872c32a0cd468c710040b2f53d8cac69f18dad07985ee37e9a7151ae
evbparams=dynafed:0:::
addnode=liquid-testnet.blockstream.com:18892
addnode=liquidtestnet.com:18891
addnode=liquid.network:18444
2020-05-25 13:58:46 +02:00
```
2022-05-08 00:25:57 +02:00
Start `elementsd` and wait for it to sync the Liquid blockchain.
2020-05-25 13:58:46 +02:00
### Electrs
Install [Electrs ](https://github.com/Blockstream/electrs ) from source:
```
2022-05-09 06:57:48 +02:00
git clone https://github.com/Blockstream/electrs
cd electrs
git checkout new-index
2020-05-25 13:58:46 +02:00
```
2022-01-04 07:28:17 +01:00
You'll need one instance per network. Build and run them one at a time:
2020-05-25 13:58:46 +02:00
```
2022-05-09 06:57:48 +02:00
./electrs-start-mainnet
./electrs-start-testnet
./electrs-start-signet
./electrs-start-liquid
./electrs-start-liquidtestnet
2020-05-25 13:58:46 +02:00
```
### MariaDB
2022-05-08 00:25:57 +02:00
Import the historical mempool fee database snapshot:
2020-05-25 13:58:46 +02:00
```
2022-05-09 06:57:48 +02:00
mysql -u root
create database mempool;
grant all on mempool.* to 'mempool'@'localhost' identified by 'mempool';
create database mempool_testnet;
grant all on mempool_testnet.* to 'mempool_testnet'@'localhost' identified by 'mempool_testnet';
create database mempool_signet;
grant all on mempool_signet.* to 'mempool_signet'@'localhost' identified by 'mempool_signet';
create database mempool_liquid;
grant all on mempool_liquid.* to 'mempool_liquid'@'localhost' identified by 'mempool_liquid';
create database mempool_liquidtestnet;
grant all on mempool_liquidtestnet.* to 'mempool_liquidtestnet'@'localhost' identified by 'mempool_liquidtestnet';
2020-05-26 06:23:32 +02:00
```
2022-01-05 10:51:58 +01:00
2022-01-04 07:28:17 +01:00
### Bisq
Build bisq-statsnode normally and run using options like this:
2020-05-26 06:23:32 +02:00
```
2022-05-09 06:57:48 +02:00
./bisq-statsnode --dumpBlockchainData=true --dumpStatistics=true
2020-05-25 13:58:46 +02:00
```
2022-05-08 00:25:57 +02:00
If Bisq is happy, it should dump JSON files for Bisq Markets and BSQ data into `/bisq` for the Mempool backend to use.
2022-01-04 07:28:17 +01:00
2020-05-25 13:58:46 +02:00
### Mempool
2022-05-08 00:25:57 +02:00
After all 3 electrs instances are fully indexed, install your 3 Mempool nodes:
2020-05-25 13:58:46 +02:00
```
2022-05-09 06:57:48 +02:00
./mempool-install-all
./mempool-upgrade-all
2020-05-25 13:58:46 +02:00
```
2022-05-08 00:25:57 +02:00
Finally, start your 3 Mempool backends:
2020-05-25 13:58:46 +02:00
```
2022-05-09 06:57:48 +02:00
./mempool-start-all
2020-05-25 13:58:46 +02:00
```
### Nginx
2022-05-08 00:25:57 +02:00
Get an SSL certificate using `certbot` :
2020-05-25 13:58:46 +02:00
```
2022-05-09 06:57:48 +02:00
certbot --nginx -d mempool.ninja
2020-05-25 13:58:46 +02:00
```
2022-05-08 00:25:57 +02:00
Make a symlink from `/usr/local/etc/nginx/mempool` to `/mempool/mempool` , copy the `nginx.conf` , and edit as necessary. You probably only need to edit the top-level `nginx.conf` file.
2020-05-25 13:58:46 +02:00
```
2022-05-09 06:57:48 +02:00
cd /usr/local/etc/nginx
ln -s /mempool/mempool
cp /mempool/mempool/nginx.conf .
vi nginx.conf
2020-05-25 13:58:46 +02:00
```
2022-05-08 00:25:57 +02:00
Restart `nginx` :
2020-05-25 13:58:46 +02:00
```
2022-05-09 06:57:48 +02:00
service nginx restart
2020-05-25 13:58:46 +02:00
```
### Done
2022-05-08 00:25:57 +02:00
If everything went well, your site should look like the one at https://mempool.space/.