Last active
November 19, 2018 09:33
-
-
Save junderw/46ad42ebf2c4863a42aed14df10b0f2f to your computer and use it in GitHub Desktop.
Simple setup for Ubuntu 18.04 server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### new ubuntu 18.04 server | |
### Be sure to run | |
# sudo apt-get update && sudo apt-get -y upgrade && sudo reboot | |
### For security updates | |
### Then run this script with passwordless sudo account ubuntu (default for ubuntu AWS EC2): | |
# CERTDOMAIN=something.yourdomain.com [email protected] ./thisScript.sh | |
# Install Bitcoin 0.17.0 etc. | |
sudo add-apt-repository -y ppa:bitcoin/bitcoin &>/dev/null | |
sudo apt-get update &>/dev/null | |
sudo apt-get install -y python build-essential libzmq3-dev libsnappy-dev &>/dev/null | |
sudo apt-get install -y bitcoind &>/dev/null | |
# Create bitcoind service | |
BITCOINBINPATH=$(which bitcoind) | |
echo "[Unit] | |
Description=bitcoind | |
After=syslog.target network.target | |
[Service] | |
Type=simple | |
ExecStart=$BITCOINBINPATH -server -regtest -txindex -zmqpubhashtx=tcp://127.0.0.1:30001 -zmqpubhashblock=tcp://127.0.0.1:30001 -rpcworkqueue=32 | |
WorkingDirectory=/home/ubuntu | |
KillMode=process | |
Restart=always | |
User=ubuntu | |
Group=ubuntu | |
[Install] | |
WantedBy=multi-user.target" | sudo tee /etc/systemd/system/bitcoind.service > /dev/null | |
sudo systemctl enable bitcoind.service &>/dev/null | |
sudo systemctl start bitcoind &>/dev/null | |
sleep 2 | |
bitcoin-cli -regtest generate 500 &>/dev/null | |
# Install nvm | |
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh 2>/dev/null | bash &>/dev/null | |
export NVM_DIR="$HOME/.nvm" | |
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" | |
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" | |
nvm install v10 &>/dev/null | |
# Install LevelDB | |
export LDBVER="1.20" | |
wget https://github.com/google/leveldb/archive/v${LDBVER}.tar.gz &>/dev/null | |
tar xvf v${LDBVER}.tar.gz &>/dev/null | |
rm -f v${LDBVER}.tar.gz &>/dev/null | |
cd leveldb-${LDBVER} | |
make &>/dev/null | |
scp -r out-static/lib* out-shared/lib* "/usr/local/lib" &>/dev/null | |
cd include | |
scp -r leveldb /usr/local/include &>/dev/null | |
ldconfig &>/dev/null | |
cd ../.. | |
rm -rf leveldb-${LDBVER}/ &>/dev/null | |
# Clone regtest-server | |
git clone https://github.com/bitcoinjs/regtest-server.git &>/dev/null | |
cd regtest-server/ | |
npm i &>/dev/null | |
# Create API auth key(s) | |
mkdir ../regtest-server-data | |
echo "satoshi" > ../regtest-server-data/KEYS | |
# Create node service with needed Environment | |
NODEBINPATH=$(which node) | |
CURRENTDIR=$(pwd) | |
echo "[Unit] | |
Description=regtestapp | |
After=syslog.target network.target | |
[Service] | |
Type=simple | |
Environment=\"RPCCOOKIE=/home/ubuntu/.bitcoin/regtest/.cookie\" | |
Environment=\"KEYDB=/home/ubuntu/regtest-server-data/KEYS\" | |
Environment=\"INDEXDB=/home/ubuntu/regtest-server-data/db\" | |
Environment=\"ZMQ=tcp://127.0.0.1:30001\" | |
Environment=\"RPCCONCURRENT=32\" | |
Environment=\"RPC=http://localhost:18443\" | |
Environment=\"PORT=8080\" | |
ExecStart=$NODEBINPATH $CURRENTDIR/index.js | |
WorkingDirectory=/home/ubuntu | |
KillMode=process | |
Restart=always | |
User=ubuntu | |
Group=ubuntu | |
[Install] | |
WantedBy=multi-user.target" | sudo tee /etc/systemd/system/regtestapp.service > /dev/null | |
sudo systemctl enable regtestapp.service &>/dev/null | |
sudo systemctl start regtestapp &>/dev/null | |
# Create script for cronjob | |
echo "sudo systemctl stop regtestapp | |
sudo systemctl stop bitcoind | |
sudo rm -rf /home/ubuntu/.bitcoin | |
sudo systemctl start bitcoind | |
sleep 3 | |
$(which bitcoin-cli) -regtest generate 500 &>/dev/null | |
sleep 3 | |
sudo systemctl start regtestapp" > /home/ubuntu/regtest-server-data/resetRegtestServer.sh | |
chmod 755 /home/ubuntu/regtest-server-data/resetRegtestServer.sh | |
# Create cronjob | |
echo "0 5 * * 0 root /home/ubuntu/regtest-server-data/resetRegtestServer.sh" | sudo tee /etc/cron.d/resetregtestserver > /dev/null | |
# Install nginx | |
sudo apt-get install -y nginx &>/dev/null | |
sudo unlink /etc/nginx/sites-enabled/default &>/dev/null | |
# something.yourdomain.com is pointing to your server | |
echo "server { | |
listen 80; | |
server_name $CERTDOMAIN; | |
location / { | |
proxy_pass http://127.0.0.1:8080; | |
} | |
}" | sudo tee /etc/nginx/sites-available/reverse-proxy.conf > /dev/null | |
sudo ln -s /etc/nginx/sites-available/reverse-proxy.conf /etc/nginx/sites-enabled/reverse-proxy.conf &>/dev/null | |
sudo service nginx configtest &>/dev/null | |
sudo service nginx restart &>/dev/null | |
# Install certbot | |
sudo add-apt-repository -y ppa:certbot/certbot &>/dev/null | |
sudo apt-get update &>/dev/null | |
sudo apt-get install -y python-certbot-nginx &>/dev/null | |
sudo certbot --nginx --non-interactive --agree-tos -d $CERTDOMAIN -m $CERTEMAIL &>/dev/null | |
# change local bitcoinjs-lib /test/integration/_regtest.js | |
# APIURL to "https://something.yourdomain.com/1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment