My Banana Pi M3 multiservice setup (ddns, seedbox, bitcoin, megatools, ZNC)


A long time ago, I won Banana Pi M3. As you probably read this blog, I have also an Odroid U3. I used to have a Raspberry Pi and Banana Pi M1 but I sold them.


My Banana Pi M3 with the case I bought

I'll write here all the configuration and installation. It'll be helpfull for me, so when I'll have to re-install everything, I'll use this post. When I say installation, this tutorial will cover.

1. Installation and some tweaks of the OS
2. Install freedns with Inadyn
3. Install new version of ZNC
4. Install megatools
5. Install bitcoin
6. Install seedbox (Deluge)

Let's start

1. Installation and some tweaks of the OS

I tried many distros and versions of distros. The one that worked fine was ARMBIAN Debian Jessie 8 (the file decompress as -. So I remaned as bpi-m3-new-image-debian-8-jessie.img). Not sure if it's pure debian or something mixed. It's the only distro that worked. My board is a testing board. Here I will tell you what tweaks I made to run the OS.

As you probably know, banana pi M3 has an emmc chip. This is a chip on board that is quite fast. It means install the OS on board to be faster. This procedure isn't very difficult. You can find more here.

First of all copy the image on a SD card. Boot the M3 with the SD card and login using ssh (ssh root@IP. When it prompts for a password, it's bananapi).

Run the command to see the path of the EMMC (it's on "/dev/mmcblk1")

fdisk -l


/dev/mmcblk1

Switch to the path of images (copy the 7GB image to a USB. Plug it and mount it), and run the command

sudo dd if=bpi-m3-new-image-debian-8-jessie.img of=/dev/mmcblk1 bs=10MB

When finish burning, remove the SD card, and restart the BPI-M3. Check if the system starts normally on the EMMC flash boot.

Now update and upgrade the system

apt-get update && apt-get upgrade

SYSTEMD

Something that bothered me was the fact that didnt' have systemd installed so I installed it myself. Some people hate it, I personally can use it easier than the systemv-init.

apt-get install systemd systemd-sysv
reboot


It's Banana Pi M3 ;-)

ADD STORAGE TO FSTAB

Next step, I mounted a USB as storage for seedbox and save some files. I prefer NTFS as system files.

apt-get install ntfs-3g
mkdir /media/sd

Then I edit fstab (nano /etc/fstab) and add the USB (named as sd) to mount it automatically after reboot.

# [file system] [dir] [type] [options] [dump] [pass]
/dev/sdb1 /media/sd ntfs-3g defaults 0 0

(be careful of the alignment)

STATIC IP

Edit the interfaces file

nano /etc/network/interfaces

and commend the line iface eth0 inet dhcp and add the following (be careful he alignment)

iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1

and reboot.

ADD NEW USER

This will be user for running znc and as security measure when we'll disable ssh for root (see some info here).

adduser eiosifidis

the system will ask you some information. Most important is to set the password.

Finally grant user Administrative Privileges

visudo

and add the last line

# User privilege specification
root ALL=(ALL:ALL) ALL
eiosifidis ALL=(ALL:ALL) ALL

DISABLE SSH FOR ROOT

As security measure, disable ssh for root. When you ssh the system use the user (see some info here).

To disable root SSH login, edit /etc/ssh/sshd_config with your favorite text editor.

nano /etc/ssh/sshd_config

Change this line:

#PermitRootLogin yes

Edit to this:

PermitRootLogin no

Restart the service

systemctl restart sshd


2. Install freedns with Inadyn

I had to use a ddns service to update my external IP. My router doesn't have all services, so it was easier for me to setup INADYN with a freeDNS service.

First of all install inadyn.

apt-get install inadyn curl

Then edit the conf file

nano /etc/inadyn.conf

Make sure that you have similar to the following text.

# Please edit following options before starting daemon

# Service provider
# Please see inadyn(8) for a complete list of providers
system default@freedns.afraid.org

# Your username
username [username]

# Your password
password [password]

# Your hostname. This option can appear multiple times
alias [url]

Where [username] and [password] you can write the credentials you got from freeDNS.
Where [url] is the address you use as ddns.

Now you have to start and enable the service. Edit the service file.

nano /lib/systemd/system/inadyn.service

Make sure the file has the following content.

[Unit]
Description=inadyn Dynamic DNS Update Client
After=network.target

[Service]
Type=forking
ExecStart=/usr/sbin/inadyn

[Install]
WantedBy=multi-user.target

Now you can start the service.

systemctl start inadyn.service
systemctl enable inadyn.service

Wait for couple of minutes until there's an update of the external IP.


3. Install new version of ZNC

Since I'm involved in FOSS communities, we usually have meetings online. Our tool is IRC.
But how can I be online all the time and keep logs? It's not that important to be online 24/7. I mean I can live without IRC 24/7. Anyway, the tool I use called ZNC.

I can install ZNC from official repositories but it's old version. New versions allow me to connect 1 user to many IRC servers. The older versions I had to reate different users for each IRC server. So I have to compile it. The new versions can be found at http://znc.in/releases/.

Let's start the procedure. First of all download the latest version.

wget http://znc.in/releases/znc-1.6.4.tar.gz

or

wget http://znc.in/releases/znc-latest.tar.gz

then decompress and move to the folder

tar -xzvf znc-1.6.4.tar.gz
cd znc-1.6.4

Now start compile and then install. It'll take a while, so go make a sandwich or drink coffee.

./configure
make
make install

When it's over, log out from super user and log in as user. Use the command

znc --makeconf

to configure your ZNC installation.

Then run ZNC with the command

znc

Remember, everytime you reboot, you have to log in as user and run znc.

For a detailed tutorial about installation on Debian, check your this tutorial.


4. Install megatools

You see that I promote Nextcloud as cloud solution. I use mega.nz to host some files from my university, files that all my friends have or want to download to study and pass exams. I use it mainly to upload files. The question is why don't you use your desktop? Well I can have this open all the time, syncing during the time I have my desktop turned off.

Let's see how to install it. First of all, update and install the following

apt-get update && apt-get upgrade -y && apt-get install screen -y

Edit the sources list

nano /etc/apt/sources.list

and add the following repos

deb http://ftp.de.debian.org/debian/ unstable main non-free contrib
deb-src http://ftp.de.debian.org/debian/ unstable main non-free contrib

then install megatools

apt-get update && apt-get install megatools -y

after you install megatools, edit the sources.list file and either delete the 2 repos or just add the # to comment them. You don't want to upgrade from those repositories.

Log off the administrator and log in as user. Create the file with your credentials.

nano .megarc

and add the following text (use your username and password)

#Change your username and password to the ones you registered.
[Login]
Username = account@mail.tld
Password = PW12345

save the file and now you can upload the file you want.

I have a folder in the SD card (created as root)

mkdir /media/sd/megatools

to sync your files, use the command

megacopy --local megatools --remote /Root/Uploads

and then move it from your browser from Uploads folder to the folder you want.


5. Install bitcoin

I have a bitcoin miner on USB. It's not as profitable as I thought. But since I have my banana pi online 24/7, I thought why not use it? I see my dashboard here.

There are 2 ways. I use the second one. First of all install bfgminer.

apt-get install bfgminer

From your registration on the service, you have credentials for your worker. Let's assume there are
WORKER: username.worker1
PASSWORD: PASSWORD

You can create a bash shell file

nano bitcoin.sh

and add the following (it depends on where you do the mining)

#!/bin/sh
bfgminer -o stratum+tcp://stratum.bitcoin.cz:3333 -u username.worker1 -p PASSWORD -S all

do it executable

chmod +x bitcoin.sh

and then run it (./bitcoin.sh). You can add the sign "&" to run in the background. You have to run the same command after reboot.

I prefer systemd.

Create a conf file

nano /etc/bfgminer.conf

and add the following

{
"pools" : [
{
"url" : "stratum+tcp://stratum.bitcoin.cz:3333",
"user" : "username.worker1",
"pass" : "PASSWORD"
}
],
"log": 900,
"syslog": true,
"quiet": true,
"real-quiet": true
}

then create a .service file

nano /lib/systemd/system/bitcoin.service

and add the following

[Unit]
Description=Bitcoin miner featuring overclocking, monitoring, fan speed control and remote management. For FPGA/GPU/CPU Bitcoin mining.

[Service]
ExecStart=/usr/bin/bfgminer -T --config /etc/bfgminer.conf -S all --syslog
Restart=all

[Install]
WantedBy=network-online.target

and start and enable the service.

systemctl start bitcoin.service
systemctl enable bitcoin.service

See more information about the .service file, here and about the .conf file, here.

https://github.com/pgremo/piminer/blob/master/roles/miner/files/usr/lib/systemd/system/bfgminer.service
https://github.com/lmacken/bfgminer-ansible/blob/master/bfgminer.conf


6. Install seedbox (Deluge)

I wrote many tutorials how to create a seedbox with transmission and rTorrent. I didn't write anything about deluge. Deluge is a software I used before to download torrents. Now I prefer transmission but after I use seedbox, I just don't bother to leave my computer on to download files.

I used the tutorial for raspberry pi as base but with some changes.

First of all, make sure you create the folders on the sd card, so everything will be saved there.

mkdir /media/sd/complete

you can create another folder to save the files during the download procedure.

Let's start setup deluge

apt-get install deluged deluge-console

now run the daemon (create a configuration file) and then shut it down

deluged
pkill deluged

Edit the configuration file

cp ~/.config/deluge/auth ~/.config/deluge/auth.old

nano ~/.config/deluge/auth

Once inside nano, you’ll need to add a line to the bottom of the configuration file with the following convention:

user:password:level

Where in user is the username you want for Deluge, password is the password you want, and the level is 10 (the full-access/administrative level for the daemon).

Once you’ve saved them, start up the daemon again and then the console

deluged
deluge-console



If starting the console gives you an error code instead of nice cleanly formatted console interface type “exit” and then make sure you’ve started up the daemon.

Once you’re inside the console, you need to make a quick configuration change.
Enter the following:

config -s allow_remote True
config allow_remote
exit

This enables remote connections to your Deluge daemon and double checks that the config variable has been set. Now it’s time to kill the daemon and restart it one more time so that the config changes take effect:

pkill deluged
deluged

You can start and enable the service on systemd everytime you reboot.

systemctl start deluged
systemctl enable deluged

Now you can connect with desktop client but I prefer the web interface although I'll have less features than the thinclient.

apt-get install python-mako deluge-web

now run the web UI

deluge-web

The default port for the WebUI is 8112, if you wish to change it use the following commands:

pkill deluge-web
nano ~/.config/deluge/web.conf

This stops the WebUI and opens up the configuration file for it. Use nano to edit the line: “port”: 8112, and replace the 8112 with any port number (above 1000, as 1-1000 are reserved by the system).

I didn't find how to run it on systemd. Maybe I need to create a .service file.
By default deluge-web runs on the foreground, we have address “&” sign at the end of the command to put it on background.

deluge-web&

Everytime you reboot, you have to run this command. If you don't, you won't have the WebUI. Deluge downloads the files and you can also connect via the thinclient.

Once you have the WebUI up and running, it’s time to connect into it using a web browser. Open up a browser on your regular desktop machine and point it at the IP address : PORT.

You’ll be greeted with a password prompt (the default password is “deluge") and be immediately encouraged to change it after you enter it for the first time.



Here is how to use encrypt deluge.

1 σχόλιο:

Από το Blogger.