Skip to content
This repository has been archived by the owner on Jun 24, 2021. It is now read-only.

installation_3.1_bitcoin_neo4j

Stéphane Traumat edited this page Nov 21, 2019 · 25 revisions

Debian server (release 10.x).

The operation system we choosed is Debian Buster, you can download it here.

Some packages must be installed to make blockchain2graph work :

apt-get update
apt-get -y install automake build-essential module-assistant autoconf libssl-dev libboost-dev libboost-chrono-dev libboost-filesystem-dev libboost-program-options-dev libboost-system-dev libboost-test-dev libboost-thread-dev git libtool shtool autogen pkg-config vim libevent-dev wget curl locate ntp htop openjdk-11-jdk ca-certificates dirmngr gnupg software-properties-common
apt-get -y upgrade

Bitcoin core (release 0.18.x).

The next step is now to download Bitcoin core sources from github, build it and create a Linux daemon.

Create a user.

/usr/sbin/useradd -s /usr/sbin/nologin -r -m -d /home/bitcoin bitcoind

Get the sources.

cd /home/bitcoin  
git clone -b v0.18.1 https://github.com/bitcoin/bitcoin.git

Compile and install.

cd /home/bitcoin/bitcoin
./autogen.sh
./configure --without-gui --disable-wallet
make
make install

Set bitcoind configuration.

Now, we have to create the configuration file for the bitcoind deamon. This file is named bitcoin.conf should be created in the directory /home/bitcoin/.bitcoin.

You can do it with the commands :

mkdir /home/bitcoin/.bitcoin
touch /home/bitcoin/.bitcoin/bitcoin.conf

This is the content of the configuration file you have to setup :

rpcauth=bitcoinrpc:2c36ebb190eba7bb00df12ddda7b5115$f1a1d565e8d6aad38b6c31d4c2d922b7f180b020b83fdf4e7fe77bd825fb6607
server=1
rest=1
txindex=1
rpcthreads=8
rpcbind=127.0.0.1
rpcbind=YOUR_PUBLIC_SERVER_IP
rpcport=8332
rpcallowip=0.0.0.0/0
rpcallowip=::/0

In the file above, replace YOUR_PUBLIC_SERVER_IP by your server public IP address if you want the API to be called from outside. A sample bitcoin.conf file is available here.

Setup the linux service.

Now, you have to create a file named bitcoind in /etc/init.d/ with the command :

touch /etc/init.d/bitcoind

Edit this file to create your daemon or copy our bitcoind service code here.

After that, you have to make it executable with the command :

chmod +x /etc/init.d/bitcoind

and finally, add it as a system init script :

/usr/sbin/update-rc.d bitcoind defaults

Check if bitcoind is running.

After restarting the server, use this command :

bitcoin-cli -datadir=/home/bitcoin/ -conf=/home/bitcoin/.bitcoin/bitcoin.conf getblockchaininfo

You should get a reply looking this :

{
  "chain": "main",
  "blocks": 8859,
  "headers": 506482,
  "bestblockhash": "000000001ba3e0220bbdd8e7e5ad80e28db57c2ccd798346aac2a0114c8207cb",
  "difficulty": 1,
  "mediantime": 1238140259,
  "verificationprogress": 3.071215408814337e-05,
  "chainwork": "0000000000000000000000000000000000000000000000000000229c229c229c",
  "pruned": false,
  "softforks": [
    {
      "id": "bip34",
      "version": 2,
      "reject": {
        "status": false
      }
    }, 
    {
      "id": "bip66",
      "version": 3,
      "reject": {
        "status": false
      }
    }, 
    {
      "id": "bip65",
      "version": 4,
      "reject": {
        "status": false
      }
    }
  ],
  "bip9_softforks": {
    "csv": {
      "status": "defined",
      "startTime": 1462060800,
      "timeout": 1493596800,
      "since": 0
    },
    "segwit": {
      "status": "defined",
      "startTime": 1479168000,
      "timeout": 1510704000,
      "since": 0
    }
  }
}

Neo4j (release 3.5.x).

Add the repository.

To install Neo4j in a proper way, you have to add it the repository the list of sources with the following commands :

wget -O - https://debian.neo4j.org/neotechnology.gpg.key | apt-key add -
echo "deb http://debian.neo4j.org/repo stable/" | tee /etc/apt/sources.list.d/neo4j.list

Install.

Install neo4j with this command :

apt-get update;apt-get -y install neo4j=1:3.5.12;apt-mark hold neo4j

According to your needs, you can change the neo4 configuration ( /etc/neo4j/neo4j.conf ) :

  • dbms.directories.data : to set where neo4j should store data.
  • dbms.memory.pagecache.size : The amount of memory to use for mapping the store files. We advise 13000m.
  • dbms.memory.heap.initial_size : heap initial size. We advise 11000m.
  • dbms.memory.heap.max_size : heap maximal size. We advise 11000m.
  • dbms.connectors.default_listen_address : uncomment.
  • dbms.connector.bolt.listen_address: uncomment.
  • dbms.connector.http.listen_address : uncomment.
  • dbms.connector.https.listen_address : uncomment.

Check if neo4j is running.

In the console, type /usr/sbin/service neo4j status, you should get a reponse looking like this :

● neo4j.service - Neo4j Graph Database
   Loaded: loaded (/lib/systemd/system/neo4j.service; disabled; vendor preset: enabled)
   Active: active (running) since Sun 2018-01-28 20:42:21 UTC; 3min 58s ago
 Main PID: 2397 (java)

Make neo4j start automatically.

systemctl enable neo4j

Change database password.

To change the neo4J default password, use the command line :

curl -H "Content-Type: application/json" -X POST -d '{"password":"YOUR_NEW_PASSWORD"}' -u neo4j:neo4j http://localhost:7474/user/neo4j/password

note : wait a bit before running this command because neo4j needs some time to start.

Blockchain2graph.

Create a user.

/usr/sbin/useradd -s /usr/sbin/nologin -r -m -d /home/blockchain2graph blockchain2graph

Download Blockchain2graph.

You can download Blockchain2graph with the command :

mkdir /var/blockchain2graph
wget -O /var/blockchain2graph/blockchain2graph-bitcoin-neo4j.jar https://github.com/straumat/blockchain2graph/releases/download/version-3.1/blockchain2graph-bitcoin-neo4j.jar

Setup rights.

We will change the owner of the jar

chown blockchain2graph:blockchain2graph /var/blockchain2graph/blockchain2graph-bitcoin-neo4j.jar

Create a service and set configuration.

We will now create a service to run blockchain2graph :

touch /etc/systemd/system/blockchain2graph-bitcoin-neo4j.service

Here is the content, change it acording to your configuration :

[Unit]
Description=Blockchain2graph-bitcoin-neo4j
After=syslog.target

[Service]
Environment="SPRING_DATA_NEO4J_URI=bolt://neo4j:b2g135!@localhost"
Environment="BITCOINCORE_HOSTNAME=5.196.65.205"
Environment="BITCOINCORE_PORT=8332"
Environment="BITCOINCORE_USERNAME=bitcoinrpc"
Environment="BITCOINCORE_PASSWORD=JRkDy3tgCYdmCEqY1VdfdfhTswiRva"
ExecStart=/usr/bin/java -jar /var/blockchain2graph/blockchain2graph-bitcoin-neo4j.jar SuccessExitStatus=143

[Install]
WantedBy=multi-user.target

You can start blockchain2graph with the command : /usr/sbin/service blockchain2graph-bitcoin-neo4j start

Make neo4j start automatically.

systemctl enable blockchain2graph-bitcoin-neo4j

Check if blockchain2graph is running.

You can now connect to the blockchain2graph console at : http://YOUR_IP:YOUR_PORT/.

If it's not working, check the logs by looking at /var/log/syslog.