Difference between revisions of "Running your own Insight explorer"

From DigiByte Wiki
Jump to navigation Jump to search
(Removed older legacy fluff)
(Updated instructions for latest, as of Nov'19)
(2 intermediate revisions by 2 users not shown)
Line 3: Line 3:
  
 
This is useful if you want the API's to be able to access for integrating external products in to the blockchain.
 
This is useful if you want the API's to be able to access for integrating external products in to the blockchain.
 +
 +
If you want to run this within a Docker container, you can [https://gitlab.com/utarn/digibyte-insight/blob/master/Dockerfile start here instead].
  
 
 
 
 
Line 48: Line 50:
 
export INSIGHT_NETWORK='livenet'
 
export INSIGHT_NETWORK='livenet'
 
export BITCOIND_DATADIR=~/.digibyte/
 
export BITCOIND_DATADIR=~/.digibyte/
 +
export BITCOIND_USER=user
 +
export BITCOIND_PASS=pass
 +
export INSIGHT_PUBLIC_PATH=public
 
export INSIGHT_FORCE_RPC_SYNC=1
 
export INSIGHT_FORCE_RPC_SYNC=1
 
EOF</pre>
 
EOF</pre>
Line 56: Line 61:
 
<pre>curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash</pre>
 
<pre>curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash</pre>
  
After you've run this, log out of the DigiByte user and then log back in again for the changes to your profile to take effect, as well as load the variables we set for Insight earlier.
+
After you've run this, run the following to load the variables we set for Insight earlier.
<pre>exit
+
<pre>source ~/.profile</pre>
su - digibyte</pre>
 
  
 
&nbsp;
 
&nbsp;
Line 79: Line 83:
 
EOF</pre>
 
EOF</pre>
  
We do this first and foremost because we want to ensure that DigiByte gets started up with the right settings first time around.
+
We do this first and foremost because we want to ensure that DigiByte gets started up with the right settings first time around. We want the rpcuser/pass to match what we had earlier
  
 
Get the latest DigiByte Core from GitHub, 7.17.2 at the time of writing:
 
Get the latest DigiByte Core from GitHub, 7.17.2 at the time of writing:
Line 99: Line 103:
 
== Insight installation ==
 
== Insight installation ==
  
Now we install a specific version of node, as this is the last supported version in that generation:
+
Now we install a specific version of node, as this is the last supported LTS version in that generation:
<pre>nvm install v0.10.48</pre>
+
<pre>nvm install v10.17.0</pre>
  
 
Now we grab the Insight server:
 
Now we grab the Insight server:
Line 108: Line 112:
 
<pre>npm install</pre>
 
<pre>npm install</pre>
  
Then we're going to sync insight with DigiByte Core. We do this manually on first-run, as it won't resume unless it's 97% sync'd
+
Then we're going to sync insight with DigiByte Core. This should sync using the .blk files to begin with and then change to using RPC later
<pre>~/insight/node_modules/insight-bitcore-api/util/sync.js -D -v --rpc</pre>
+
<pre>INSIGHT_NETWORK=livenet BITCOIND_USER=user BITCOIND_PASS=pass INSIGHT_PUBLIC_PATH=public &nbsp;npm start</pre>
 
 
-D tells it to delete the existing data (There shouldn't be any anyways, but in case there's been an issue and you're running this a second time around...)
 
 
 
-v tells it to be verbose
 
 
 
--rpc tells it to use RPC, rather than the index files
 
  
This process will likely take 12+ hours, depending on your CPU.
+
This process will likely take 4-5&nbsp;hours, depending on your CPU etc (As of November 2019)
  
Once completed, you should still be in ~/insight, and so can simply run:
+
Once completed, you should still be in ~/insight, and so can simply re-run the same command as previous to restart in RPC mode
<pre>node start</pre>
+
<pre>npm start</pre>
  
You may also want to run this inside a screen session or use pm2 to monitor it.
+
You may also want to run this inside a screen session, or use pm2 to monitor it.
  
As soon as you've run this you can load up [http://server.ip:3000 http://server.ip:3000] and should be greeted with your Insight server.
+
As soon as you've run this you can load up [http://server.ip:3000 http://server.ip:3000] and should be greeted with your Insight server. You can follow along at http://server.ip:3000/status and see the sync progress
  
 
&nbsp;
 
&nbsp;

Revision as of 02:29, 14 November 2019

Here are some quick and dirty instructions on how to run your own Insight explorer, similar to DigiExplorer.info and now including support for DigiAssets

This is useful if you want the API's to be able to access for integrating external products in to the blockchain.

If you want to run this within a Docker container, you can start here instead.

 

System requirements

You will need a Linux server with at least 4GB of RAM (6GB preferred) and a 50GB HDD (as of early 2019).

You obviously need to be mildly familiar with the command line and setting these things up.

While this will work on CentOS etc, this presumes a Debian / Ubuntu server

 

Getting started

Start with the following as root

apt-get install python curl build-essential screen git nginx software-properties-common

This will give you some basic tools needed

 

Installing certbot for ssl

We are going to install the basics now for certbot so you will be running a free SSL certificate

add-apt-repository universe
add-apt-repository ppa:certbot/certbot
apt-get update
apt-get install certbot python-certbot-nginx
certbot --nginx

Follow the Certbot instructions for your domain.

 

User account preparation

If you don't already have one, create a DigiByte user for this to be run as:

useradd digibyte -m -s /bin/bash
su - digibyte

Now that you are the DigiByte user, you'll want to run the following to setup some environment variables:

cat <<EOF >> ~/.profile
export INSIGHT_NETWORK='livenet'
export BITCOIND_DATADIR=~/.digibyte/
export BITCOIND_USER=user
export BITCOIND_PASS=pass
export INSIGHT_PUBLIC_PATH=public
export INSIGHT_FORCE_RPC_SYNC=1
EOF

This allows the Insight service to run on mainnet (It presumes testnet otherwise), with the right directory etc

These changes won't take effect right away,that's fine

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash

After you've run this, run the following to load the variables we set for Insight earlier.

source ~/.profile

 

 

DigiByte Core

Before we download DigiByte Core, you're going to want to run the following to setup your digibyte.conf: 

mkdir -vp ~/.digibyte

cat <<EOF > ~/.digibyte/digibyte.conf
server=1
maxconnections=300
rpcallowip=127.0.0.1
daemon=1
rpcuser=user
rpcpassword=pass
txindex=1
EOF

We do this first and foremost because we want to ensure that DigiByte gets started up with the right settings first time around. We want the rpcuser/pass to match what we had earlier

Get the latest DigiByte Core from GitHub, 7.17.2 at the time of writing:

wget https://github.com/digibyte/digibyte/releases/download/v7.17.2/digibyte-7.17.2-x86_64-linux-gnu.tar.gz
tar xvzf digibyte-7.17.2-x86_64-linux-gnu.tar.gz
./digibyte-7.17.2/bin/digibyted

This should start the DigiByte Core wallet in the background, you can check the progress by running:

tail -f ~/.digibyte/debug.log

You can stop looking at the logs with Ctrl + C, and it won't stop the DigiByte Core service.

Allow DigiByte to fully sync up, it may take a couple of hours depending on your CPU / connection etc

 

 

Insight installation

Now we install a specific version of node, as this is the last supported LTS version in that generation:

nvm install v10.17.0

Now we grab the Insight server:

git clone https://github.com/DigiByte-Core/insight.git && cd insight

Now that we have it downloaded, we want to install the other prerequisites:

npm install

Then we're going to sync insight with DigiByte Core. This should sync using the .blk files to begin with and then change to using RPC later

INSIGHT_NETWORK=livenet BITCOIND_USER=user BITCOIND_PASS=pass INSIGHT_PUBLIC_PATH=public  npm start

This process will likely take 4-5 hours, depending on your CPU etc (As of November 2019)

Once completed, you should still be in ~/insight, and so can simply re-run the same command as previous to restart in RPC mode

npm start

You may also want to run this inside a screen session, or use pm2 to monitor it.

As soon as you've run this you can load up http://server.ip:3000 and should be greeted with your Insight server. You can follow along at http://server.ip:3000/status and see the sync progress

 

Finishing the nginx reverse-proxy

So we're installed and running, but we don't want to keep having to use Port 3000. You also likely want to be using HTTPS, so we'll setup nginx to handle the rest. Time to edit your nginx config:

nano -w /etc/nginx/sites-enabled/default

Under the Default Server configuration you'll see server_name, set this to be your URL, such as:

server_name explorer-1.us.digibyteservers.io;

You also want to add:

        location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        }

If you already have a "location /" then you can comment it out with a # at the start of the line.

Also, be sure to comment out:

#try_files $uri $uri/ =404;

If it's still in there and uncommented.

Once saved you can then run:

/etc/init.d/nginx restart

This will restart your nginx server and you should be able to browse to https://server/ and have it display your Insight explorer

You can also test the API's by browsing to: https://server/api/addr/DD2GiYVo3uL7SBmg5jtXDxfYZhdzGt3kRx?noTxList=1

For reference it should look like: https://explorer-1.us.digibyteservers.io/api/addr/DD2GiYVo3uL7SBmg5jtXDxfYZhdzGt3kRx?noTxList=1