Skip to content

Instantly share code, notes, and snippets.

@jbfarez
Last active December 29, 2017 21:35
Show Gist options
  • Save jbfarez/50773967e63f5eec6e864f00035c66eb to your computer and use it in GitHub Desktop.
Save jbfarez/50773967e63f5eec6e864f00035c66eb to your computer and use it in GitHub Desktop.
XCXT Masternode setup

CoinonatX masternode setup

Summary

This document is a guide to setup a CoinonatX masternode on a Debian server, created at Scaleway, and it assume you’re running Windows or Mac. Requirements:

  • A server running Linux
  • A static IP address
  • Basic Linux skills some errors could be encountered
  • ⚠️ Be really careful with security, you MUST follow the security steps if you don’t want to loose your wallet

💲 The average monthly cost of the masternode is around USD 4 (on Scaleway)

Prerequisites

SSH configuration

  • Windows
    • Download and install PuTTY for your platform
    • Run the PuTTYgen utility at C:\Program Files\PuTTY\puttygen.exe
    • At the bottom, in the Type of key to generate section, select RSA
    • Click the Generate
    • Move the mouse pointer around in the blank area of the Key section as prompted while the key is being generated
    • Once complete, add email address to the key comment field to help identify the key
    • Optional: enter a passphrase in the Key passphrase field. If the passphrase left blank, you will be able to use the private key for logging in without entering a passphrase. If you enter a passphrase, you will need both the private key and the passphrase each time you log in
    • Click Save public key and save the key somewhere safe on your computer
    • Click Save private key and save the key somewhere safe on your computer – it can be the same place as the public key. Remember to keep the private key secure. If you lose it, you won’t be able to log in to your server
  • Mac / Linux
    • From the Terminal, run this command to create a key pair: ssh-keygen

    • Press enter to save the keys in the default location /Users/username/.ssh/id_rsa (leave the name as id_rsa unless you need to rename it, for example, because you have other keys there)

    • Optional: enter a passphrase. If the passphrase left blank, you will be able to use the private key for logging in without entering a passphrase. If you enter a passphrase, you will need both the private key and the passphrase each time you log in

    • Now the private key, id_rsa, and the public key, id_rsa.pub, in the .ssh directory of your home directory are created. Remember to keep the private key secure

Server creation

Note: this step is optional, if you already have a service provider, you can skip this step

Since a masternode require to be up 24/7, you could use an suggested easy to use VPS service https://www.scaleway.com/ (Vultr is also a good choice).

  • Create your account

  • On the top right corner, click on your nameaccountcredentials

    • Add the previously generated SSH public key
  • Go to the Server tab

    • Click Create server

    • Name your server to easily identify it

    • Choose the location for your server

    • In Server range select Starter range

      • Go to X86 section
      • A good choice for masternode is VC1S (2 vcpu, 2 Gb RAM, 200Mb traffic) instance
    • Select the OS to use, in this documentation Debian Jessie will be used

    • Optional: Add tags to filter your servers

    • Finally click Create server at the right bottom corner

Server setup

Login to the server as root by using PuTTY (Windows) or Terminal (Mac / Linux)

Change root password

  • In the terminal, run: passwd

  • Choose a very strong password (suggest 32 characters with numbers and special characters like $ or #) and keep it in a safe place Add the connection user

  • Create the user (replace my_user by the name you want, for exemple, you can use a usual nickname): adduser <my_user>

  • You’ll be asked for setting up a password for the user. It’s a good way to use the same policy as the root password (many characters and keep it in safe place)

  • The created users will need permissions to be granted as root, so it must be added to the sudoers. To do it so: usermod -aG sudo <my_user>

  • Switch to the new user: su - <my_user>

  • Create the .ssh directory: mkdir ~/.ssh chmod 0700 ~/.ssh touch ~/.ssh/authorized_keys chmod 0600 ~/.ssh/authorized_keys

  • Paste the previously created SSH public key to the following file:

    • On your local machine: cat ~/.ssh/id_rsa.pub ← Copy the output of this command
    • On the remote server: vi ~/.ssh/authorized_keys ← Paste here with your favorite editor
  • Ensure the key pasted begin by ssh-rsa end by the e-mail address you’ve set

  • Logout from the server and try to connect to with the new user

  • You should be able to connect to without typing the user password (if you’ve setup a passphrase during SSH key creation, you will be asked for)

  • Ensure that you are able to become root from the new user: sudo -i whoami

  • The result should be root, if not, you have to get back to the begin of the Add connection user step

  • ⚠️ If you don’t take care of this, you can be unable to connect to your server

Securing SSH server

  • Connect to your server then become root

  • Edit /etc/ssh/sshd_config with your favorite editor

  • Find the line that specifies PasswordAuthentication, uncomment it by deleting the # at the start of the line, then change its value to "no". It should end up looking like this: PasswordAuthentication no

  • Find, uncomment and change these values as well: PermitRootLogin no PubkeyAuthentication yes ChallengeResponseAuthentication no

  • Save your changes and restart SSH server: sudo /etc/init.d/ssh restart

  • Open a new terminal then verify your changes (Can’t connect as root and ability to connect as user)

  • Install fail2ban to avoid bruteforce stupid attacks sudo apt-get install fail2ban

Compile and install CoinonatX

Create the swap space

In this step we will create a 1Gb swap partition.

  • Login to your server and become root

  • Create the swap file: sudo dd if=/dev/zero of=/var/swap.img bs=1024k count=1000 sudo mkswap /var/swap.img sudo swapon /var/swap.img

  • Make the swap persistant to reboot sudo chmod 0600 /var/swap.img sudo chown root:root /var/swap.img sudo vi /etc/fstab

  • Add the following line at the end of the fstab, save and exit: /var/swap.img none swap sw 0 0

Software prerequisites

In order to be able to compile the project, some packages needs to be installed. Just follow the guide.

  • Package install: sudo apt-get update sudo apt-get install git build-essential g++ libdb++-dev
    libminiupnpc-dev libtool automake autotools-dev
    autoconf pkg-config libssl-dev libgmp3-dev
    libevent-dev bsdmainutils libboost-all-dev
    apt-transport-https ca-certificates curl gnupg2
    software-properties-common

  • Install Berkeley DB 4.8: echo "deb http://ppa.launchpad.net/bitcoin/bitcoin/ubuntu trusty main" | sudo tee /etc/apt/source.list.d/bitcoin-ppa.list sudo apt-get update sudo apt-get install libdb4.8-dev libdb4.8++-dev

Compile CoinonatX daemon

⚠️ All the operations below are run by root direclty.

  • Retrieve the sources: sudo -i # If not root mkdir /opt/build cd /opt/build git clone https://github.com/CoinonatX/CoinonatX.git coinonatx

  • Compile and install the project (it can take several times): cd coinonatx/src make -f makefile.unix # Headless CoinonatX cp CoinonatXd /usr/local/sbin/coinonatxd

Setup the masternode

Configure CoinonatX daemon

There is 2 main steps to configure CoinonatX daemon, the 1st one consist to make a basic config to synchronize the wallet and get the masternode key. The 2nd one is to configure the masternode itself to be ready to process transactions.

  • 1st step:

    • Go to the home directory of the user who will execute the daemon then create the directory: mkdir ~/.CoinonatX

    • Create the configuration file: cd ~/.CoinonatX touch coinonatx.conf chmod 0600 coinonatx.conf

    • Edit the configuration file (~/.Coinonatx/coinonatx.conf): rpcuser=<choose_username> rpcpassword=<choose_password> rpcport=<choose_port> rpcallowip=127.0.0.1 daemon=1 server=1 port=15015

    • Start the daemon, It will start syncing blocks. This may take a while as it needs to download a large number of files (blocks) to catch up with the other masternodes on the network: coinonatxd

    • One way to monitor the progress is to type the following command and look at the “blocks” value, which will increase every time you run the command, until it’s caught up (at this time, December 2017, the height is 186 920). You may need to wait a few minutes after starting the daemon before you can run this command: coinonatxd getinfo

    • Until the chain is completely in sync, you could generate the wallet address to deposit XCXT into, as this is the collateral of starting a masternode. This will be the first address in the wallet on this server: coinonatxd getaccountaddress 0

    • Send exactly 5000 XCXT to this address from Cryptopia (or the exchange where your coins from). Note, if there is a transaction fee, you need to take this into account so the server receives 5000 XCXT after the fee is deducted, so you may need to send 5000.001 XCXT from the exchange, for example. Also, you need to send this as ONE transaction. Don’t send 2500, then another 2500. Don’t send 5001 and send 1 back

    • Now you need to create a masternode key and make a copy of it. Copy it to a safe place. We’ll refer to it as masternodekey later: coinonatxd masternode genkey

    • Stop the daemon: coinonatxd stop

    • Wait until the process is stopped. You can check by running: ps auxwwf | grep -i coinonatx

  • 2nd step:

    • Now, you have to update the configuration file (~/.Coinonatx/coinonatx.conf) to set your server as masternode: rpcuser=<your_username> rpcpassword=<your_password> rpcport=<your_port> rpcallowip=127.0.0.1 daemon=1 staking=0 listen=1 server=1 port=15015 masternode=1 masternodeaddr=<your_public_ip_address>:15015 masternodeprivkey= # The masternodekey previously generated

    • Save the file and exit

    • Start the daemon: coinonatxd

    • Wait for the daemon to be in sync. Once it's done the block that has your 5000 XCXT deposit, this will show up next to balance if you run coinonatxd getinfo

    • Now you need to wait for your 5000 XCXT deposit to have at least 15 confirmations. You can see how many confirmations you have with the command: coinonatxd listtransactions

    • Once you have the 15 confirmations, start the masternode: coinonatxd masternode start

    • It's done, your masternode is up and running, you can easily monitor the balance by running coinonatxd getinfo and see how many transactions your node has treated with coinonatxd listtransactions

Backup

Even if the provider is trustable, you are dealing with certain amount of money (not virtual only), so it’s strongly recommended to make regular backups of the wallet and the configuration.

There is different approaches to deal with backup from Snapshots to Rsync, it will be described in a different guide. But in a first time you can just:

  • Stop the masternode
  • Stop the daemon
  • Copy the directory to a temporary place mkdir ~/backups # Only if the directory doesn't exist yet cp -r ~/.CoinonatX /tmp/xcxt_backup tar czf ~/backups/xcxt_backup.tgz /tmp/xcxt_backup
  • Start the daemon
  • Start the masternode

Notes

This document is highly inspired by the Chaincoin documentation to build a masternode. Thanks to the team!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment