another technical blog...technically

Monday, April 16, 2018

Another HOWTO about media center on Raspberry pi3 (Part 1/2)

Hi guys, it's a long time i don't touch my raspberry pi 2 media server (from now LittleBox). So with the raspberry pi3 release, i decided to do a little upgrade and creating the new LittleBox. which is the same as the old one, but with pi3, so more powerful.
Because of i have lost all the old scripts during SD formatting i decided to rewrite them and to share everything with you :-).
For the old version i decided to use just the command line version of Raspbian, so i controlled it using PuTTY sessions from my own pc (just like the old-fashioned way) this time i noticed the default version is the one with UI so ... why not? and this also has driven me to change some of the installed softwares.

Goals

My hardware configuration is about a Raspberry pi3, with a little fan, an attached HDD of 2TB formatted in NTFS and a ethernet connection. My goal is to create a small PC based on latest RaspBian installation that acts as a:
  • Media center 
  • Home Backup NAS 
  • Download station
So i've installed the following:
  • aMule: old but good... maybe 
  • avconv: useful for media conversion 
  • Plex: THE media server 
  • Transmission: just a torrent daemon 
  • VLC & AV codec: you never know 
  • Dos2Unix: sometimes used when i edit some files from Windows PC 
  • Fail2Ban: useful if you expose your little server on the internet 
  • MailUtils: utilities to send email, useful to send some mails directly to me 
  • Monit: useful to monitor some services 
  • NTFS-3G: drivers for NTFS filesystem
  • SMB Server: the best way to share files between a UNIX like system and a Windows one 

HDD Install

Let's create a folder to mount the HDD
sudo mkdir /media/Vault
sudo chmod 777 /media/Vault 
then install the NTFS drivers:
sudo apt-get install ntfs-3g
then edit the fstab file
sudo nano /etc/fstab
and add the following lines
# Custom
/dev/sda1    /media/Vault   ntfs-3g   rw,default   0   0 
Now if you reboot, the HDD will results mounted at /media/Vault

Setup SMB Sharing 

Let's now setup the SMB share, at first let's install the package
sudo apt-get install samba samba-common-bin
sudo apt-get install cifs-utils
Then let's edit the smb.conf adding the following lines
sudo nano /etc/samba/smb.conf
wins support = yes [pi] 
   comment= Pi Home 
   path=/home/pi 
   browseable=Yes 
   writeable=Yes 
   only guest=no 
   create mask=0777 
   directory mask=0777 
   public=no 

[Vault] 
   comment= Vault 
   path=/media/Vault 
   browseable=Yes 
   writeable=Yes 
   only guest=no 
   create mask=0777 
   directory mask=0777 
   public=no 
after that, you need to change the SMB password for pi user:
sudo smbpasswd -a pi 
Now you'll be able to access the pi home and the external HDD with a Windows PC.

InstAll

Be sure you have enabled SSH and VNC.
Now it's time to install aMule and Transmission and configure them to be accessible from the web
In this script i download the amule daemon and i get an encrypted version of the chosen password i will set up for the user who login to the web aMule server.
sudo apt-get install amule-daemon amule-utils 
amuled –f  
amuleweb -w 
echo -n YourPreferredPassword | md5sum | cut -d ' ' -f 1 
dc9dc28b924dc716069dc60fbdcbdc30 

nano /home/pi/.aMule/amule.conf  
Here the rows of the file i want to edit, note that i use the external HDD to store Temp files and incoming file cause i want to reduce as much as i can the write operations on the SD card:
[eMule] 
AddServerListFromServer=1 
AddServerListFromClient=1 
SafeServerConnect=1 
...
TempDir=/media/Vault/Download/Temp 
IncomingDir=/media/Vault/Download 
...

[ExternalConnect] 
AcceptExternalConnections=1 
ECAddress=127.0.0.1 
ECPort=4712 
ECPassword=dc9dc28b924dc716069dc60fbdcbdc30 

[WebServer] 
Enabled=1 
Password=dc9dc28b924dc716069dc60fbdcbdc30 
PasswordLow=dc9dc28b924dc716069dc60fbdcbdc30 
...
After that we just need to change the default amule user who is pi:
sudo nano /etc/default/amule-daemon 
AMULED_USER="pi" 
Now aMule will be available at port 4711 via browser, to make it available as soon as the server is reeboted, we can use crontab, so:
crontab -e 
#Amule 
@reboot amuled -f 
It's time to install Trasmission daemon and setup some settings so:
sudo apt-get install  transmission-daemon 
sudo nano /etc/transmission-daemon/settings.json 
Here the configuration i use, i think they are really self-descriptive:
"blocklist-enabled": true, 
"blocklist-url": "http://john.bitsurge.net/public/biglist.p2p.gz", 
"download-dir": "/media/Vault/Download" 
"incomplete-dir": "/media/Vault/Download/Temp" 
"incomplete-dir-enabled": true 
"peer-port-random-on-start": false, 
"port-forwarding-enabled": true, 
rpc-password: YourPreferredPassword, 
rpc-username: pi,  
rpc-whitelist: *.*.*.* 
sudo /etc/init.d/transmission-daemon reload 
sudo /etc/init.d/transmission-daemon restart 
Now let's install Plex Media Server, using a custom repository from dev2day
sudo apt-get update && sudo apt-get install apt-transport-https -y --force-yes 
wget -O - https://dev2day.de/pms/dev2day-pms.gpg.key | sudo apt-key add - 
echo "deb https://dev2day.de/pms/ jessie main" | sudo tee /etc/apt/sources.list.d/pms.list 
sudo apt-get update 
sudo apt-get install plexmediaserver -y 
sudo apt-get install libexpat1 -y 
sudo apt-get install mkvtoolnix -y 

sudo service plexmediaserver restart 

sudo nano /etc/default/plexmediaserver 
PLEX_MEDIA_SERVER_TMPDIR=/media/Vault/Download/Temp 
PLEX_MEDIA_SERVER_USER=pi 
sudo chown pi /var/lib/plexmediaserver/ 
and now we can install al the other software stated before
sudo apt-get install libav-tools libavcodec-extra vlc dos2unix ufw fail2ban
Now it's time for Monit which will help us to quickly understand what's going on on our little server
sudo apt-get install monit 
sudo nano /etc/monit/monitrc
set httpd port 2812 address 0.0.0.0 
   allow 0.0.0.0/0.0.0.0 
   allow pi:YourPreferredPassword 

check process aMule matching "amuled" 
   start program = "/etc/init.d/amule-daemon start" 
   stop program = "/etc/init.d/amule-daemon stop" 
   if failed host 127.0.0.1 port 4711 then restart 

check process Plex with pidfile "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/plexmediaserver.pid" 
    start program = "/etc/init.d/plexmediaserver start" 
    stop  program = "/etc/init.d/plexmediaserver stop" 
    if failed port 32400 type tcp then restart 
    if 3 restarts within 5 cycles then alert 

check process SSHd 
    with pidfile "/var/run/sshd.pid" 
    start program = "/etc/init.d/sshd start" 
    stop program = "/etc/init.d/sshd stop" 
    if 3 restarts within 3 cycles then alert 
    if failed port 22 protocol ssh then restart 

check process Transmission matching "transmission-daemon" 
    start program = "/etc/init.d/transmission-daemon start" 
    stop program  = "/etc/init.d/transmission-daemon stop" 
    if failed host 127.0.0.1 port 9091 type TCP for 2 cycles then restart 
    if 2 restarts within 3 cycles then unmonitor 
So now everything is lock and load but in the second part, that i promise, it will be more interesting, "i'll introduce some custom scripts that will help you to manage your personal littlebox, stay tuned
written in: Milano MI, Italia

0 commenti:

Post a Comment

Because of a lot of SPAM about courses, I need to moderate all comments here.
I ensure you that I will answer whenever possible (if you are not a spammer).

Me, myself and I

My Photo
I'm just another IT guy sharing his knowledge with all of you out there.
Wanna know more?