How-To:InstallNRSRaspberryPi

From Nxt Wiki
Jump to: navigation, search
This page contains changes which are not marked for translation.

Other languages:
Deutsch • ‎English • ‎español • ‎italiano • ‎Nederlands • ‎português do Brasil • ‎русский • ‎українська • ‎中文(简体)‎

1 Installing Nxt (and the NRS client) on Raspberry Pi

(Originally created by barbarosinciler at nextcoin.org . If this is of value to you, please donate some Nxt to him at address 7121642459245273749. The Java package that installs Nxt on your Pi was written by davethetrousers, at 14923118471272229432)

Raspbian and the NRS client for Nxt both run very well on a Raspberry Pi. CPU usage is approximately ~15-20% with the web client open and an account unlocked. Without the web client open (still unlocked) it is less than ~10% most of the time (it occasionally peaks higher and MAY occasionally spike to full load). Memory usage is about 100MB

Once this software is installed on your Raspberry Pi, it will start automatically on boot. You can administer it using remote desktop from another PC.

This tutorial makes the following assumptions; adjust accordingly!

  • your installation PC's is running Windows and has an IP of 192.168.1.20
  • your network router's IP is 192.168.1.1

1.1 Basic Raspbian install guide

  1. download and install Raspbian
    • Download the Raspbian image from [1]
    • Download diskimager for windows [2].
    • Install image on an SD Card, and boot the Raspberry from the card. You should see a config menu.
      • Expand filesystem and change your password.
      • Enable boot to desktop.
      • Set internationalisation options (language, keyboard and timezone)
      • Under advanced options enable ssh and set a hostname like "rpi".
      • Reboot. Now you should see a desktop and the system is running

1.2 Update the system

  1. open the bash commandline (LXTerminal), type the following, and follow the instructions:
    • sudo apt-get upgrade
      sudo apt-get dist-upgrade
  2. Check your IP configuration
    • Your Pi should pick up an IP address from DHC, and this can be confirmed with the ifconfig command in a shell. To configure a static ip, open the bash commandline (LXTerminal) and type the following:
      • sudo nano /etc/network/interfaces
    • Change the following entry from:
      iface eth0 inet dhcp
      To:
      iface eth0 inet static
      address 192.168.1.10
      netmask 255.255.255.0
      gateway 192.168.1.1
      network 192.168.1.0
      broadcast 192.168.1.255
    • Press CTRL and O at the same time to save the file
    • Press CTRL and X together to exit
    • Reboot your Pi

1.3 Install XRDP (RDP server)

  1. Open the bash commandline (LXTerminal) and type the following, and follow the instructions:
    • sudo apt-get install xrdp
      sudo apt-get upgrade xrdp
  2. Now you can use Microsoft Remote Desktop and work remote on the Raspberry.
    • In windows go to start -> open -> and type "mstsc"
    • Enter your Raspberry's address (192.168.1.10), connect and sign in with your password


1.4 Router/firewall port forwarding

  1. Make sure to forward TCP port 7874 tcp on your network router to the IP your raspberry has (192.168.1.10)

1.5 Install NXT Client

You have two possible options here:

  1. Use your Raspberry Pi with the standalone package Oracle JRE included (all credits to the author: davethetrousers )
    1. Download the tar.gz file from davethetrousers' mirror with wget and extract it:
      • wget http://109.230.224.65/~nxt/nxt_rasppi.tar.gz
        tar -xf nxt_rasppi.tar.gz
      • To start NRS automatically on raspberry reboot edit the run_nxt.sh file in nxt folder:
        • nano nxt/run_nxt.sh
      • Copy the code located at the end of this document, and paste it into your file.
      • Press CTRL and O at the same time to save
      • Press CTRL and X together to exit.
      • Enter: crontab -e
      • Insert the code at the end of the file:
        @reboot /home/pi/nxt/run_nxt.sh start
      • Press CTRL and O at the same time to save
      • Press CTRL and X together to exit.
    2. Now the raspberry should be able to load the NRS software on boot
  2. Step by step installation from devs mirror with build in raspbian java
    1. Download the NRS client (current version: 1.11.9) https://bitbucket.org/Jelurida/nxt/downloads/nxt-client-1.11.9.zip
    2. Unzip the file:
      unzip nxt.zip
    3. Now the NRS client is in your home folder (/home/pi/nxt/)
    4. Enter: crontab -e
      • Insert the code at the end of the file:
        @reboot /home/pi/nxt/run.sh
      • Press CTRL and O at the same time to save
      • Press CTRL and X together to exit.
    5. Now the raspberry should be able to load the NRS software on boot

1.6 Stop script for the Nxt software

  1. Create a new file in the /home/pi/nxt/ folder and name it something like "stop_nxt.sh":
    nano nxt/stop_nxt.sh
    1. If you are using davethetrousers' Java package, enter this code:
      /home/pi/nxt/ejre1.7.0_45/bin/java -Xmx1024M -cp nxt.jar;lib/*;conf nxt.Nxt STOP.PORT=11111 STOP.KEY=123456 --stop
    2. If you downloaded the Nxt software directly:
      /usr/bin/java -Xmx1024M -cp nxt.jar;lib/*;conf nxt.Nxt STOP.PORT=11111 STOP.KEY=123456 --stop
  2. Press CTRL and O at the same time to save
  3. Press CTRL and X together to exit.

Now you can stop the client on bash command line with the following command:
sudo bash nxt/stop_nxt.sh Before reboot your Pi, you should use this script to prevent a blockchain error!

Now you can reboot the system with:
sudo reboot

1.7 Connecting from your PC instead of localhost

  1. Create a nxt.properties file under the nxt/conf/ folder. You can create the file from command line using the command nano nxt/conf/nxt.properties and write the following in it. Make sure to modify the IP accordingly to yours:
    nxt.allowedBotHosts=127.0.0.1; localhost; 192.168.1.20; 0:0:0:0:0:0:0:1;
    nxt.allowedUserHosts=127.0.0.1; localhost; 192.168.1.20; 0:0:0:0:0:0:0:1;
  2. Press CTRL and O at the same time to save
  3. Press CTRL and X together to exit

1.8 Manually start forging with the NRS client

To start forging you will need to be logged in with your web browser once.

  1. Open http://192.168.1.10:7876
  2. Unlock your account with your passphrase (unlocking an address takes a few seconds).
  3. If on the left side, next to the red dot, it says "Not forging", click it to start.
  4. Now you can close your browser. It will keep forging.

1.9 Handling NRS and Java errors

You can check the java logfiles (nxtout.txt and nxterr.txt) in the nxt folder for errors!

1.10 Having issues?

Check the FAQ and the "common problems and resolutions" pages!

1.11 Additional useful commands and tools

1.11.1 Mount your local windows hard drive remotely, for Raspberry Pi data sharing

sudo mount -t cifs //192.168.1.20/c$ /mnt -o user=myusername Where:

  • x = The IP address of your Windows PC
  • myusername = your username on the windows PC

1.11.2 Start the menu changing raspbian settings (language, keyboard, timezone, hostname etc.)

sudo raspi-config

1.11.3 Check the built-in Java configuration

sudo update-alternatives --config java (The standard location is marked with a star, and the path is something like /usr/lib/jvm/jdk-7-oracle-armhf/jre/bin/java/ The defaults are priority = 317 and auto-modus. If that is ok, confirm by pressing Enter.

1.11.4 Remote administration with putty

You can manage your raspberry with the tool "putty" through a command line SSL connection. Download the tool from [3]

1.12 run_nxt.sh file

Use the following code in your run_nxt.sh script:

#!/bin/bash
### BEGIN INIT INFO
# Provides:          NXTserver
# Required-Start:    $local_fs $remote_fs $network $syslog $named $sshd
# Required-Stop:     
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start/stop NXT server
### END INIT INFO

if [ `id -u` != "0" ] && [ "$1" = "start" -o "$1" = "stop" ] ; then
  echo "You must be root to start/stop nxt."
  exit 1
fi

# Settings
nxtdir=/home/pi/nxt
nxt=nxt.jar
java=/usr/bin/java
nxtpid=/var/run/nxt.pid
nxtlog=/home/pi/nxt/nxt.log
nxtuser=pi
nxtgroup=pi
nxtnice=19
timeout=700
maxmem=120
# end Settings

# check for exist files and dirs
test -d $nxtdir || exit 0
test -f $nxtdir/$nxt || exit 0
test -f $java || exit 0

# make sure $nxtdir is ours!
chown -R $nxtuser:$nxtgroup $nxtdir

. /lib/lsb/init-functions

function status {

    start-stop-daemon -T --pidfile "$nxtpid" && echo "NXT server is started." \
    || { echo "NXT server is stopped." ; return 1; }

    return 0;
}

case "$1" in
    start)
        log_daemon_msg "Starting NXT server..." "" || true

        # check if server is running
        if [ -e $nxtpid ]; then
            pid=`cat $nxtpid`
            var=`ps -p$pid | wc -l`

            if [ $var -lt "2" ]; then
                # clear logfile
                echo -n > $nxtlog
            else
                echo -n " NXT server is already running!"
                log_end_msg 0 || true
                exit 0
            fi
        fi
        
        # Enable Debug for more info when starting NXT
        if cat $nxtdir/conf/nxt.properties | grep -q  "nxt.debug="; then
            if cat $nxtdir/conf/nxt.properties | grep -q  "nxt.debug=true"; then
                # Debug is enabled, nothing todo...
                echo -n ""
            elif cat $nxtdir/conf/nxt.properties | grep -q  "nxt.debug=false"; then
                echo nxt.debug=true >> $nxtdir/conf/nxt.properties
            fi
        else
            echo nxt.debug=true >> $nxtdir/conf/nxt.properties
        fi
                
        # n minute timeout.
        sleep $timeout &
        timerPid=$!

        # check log file and generate status-msg; will be killed when server is started or timeout hit
        tail -q -n0 -F --pid=$timerPid $nxtlog 2> /dev/null | while read line; do

            if echo $line | grep -q  "Scanning blockchain"; then
                echo -n " Scanning blockchain"            
            elif echo $line | grep -q  "processed block"; then
                echo -n "."            
            fi

            if echo $line | grep -q  "started successfully."; then
                echo -n "NXT server started successfully."
                log_end_msg 0 || true
                # stop the timer..
                kill $timerPid > /dev/null 2>&1
				$nxtdir/traffic_shaper.sh > /dev/null 2>&1
            fi
        done &
        
        # start server
        if start-stop-daemon --start --name nxt --nicelevel $nxtnice --chuid $nxtuser:$nxtgroup --pidfile $nxtpid -m --chdir $nxtdir --exec $java >> $nxtlog 2>&1 -- -Xmx"$maxmem"m -cp $nxt:lib/*:conf nxt.Nxt >> $nxtlog 2>&1 & then
            # wait for the timer to expire (or be killed)
            wait %sleep > /dev/null 2>&1
        else
            log_end_msg 1 || true
        fi
        ;;
    stop)
        log_daemon_msg "Stopping NXT server..." || true

        # check if server is running
        if start-stop-daemon --stop --pidfile $nxtpid > /dev/null 2>&1; then
            
            while status > /dev/null; do
                sleep 1;
            done
            
            echo -n " NXT server stopped."
            log_end_msg 0 || true
            rm $nxtpid  > /dev/null 2>&1
        else 
            echo -n " NXT server is not running!"
            log_end_msg 0 || true
            exit 0
        fi
        ;;
    restart)
        $0 stop
        sleep 1
        $0 start
        ;;
    status)
        status
        ;;
    *)
        echo "usage:`basename $0` start | stop | restart | status"
        exit 1
        ;;
esac