Skip to content

Instantly share code, notes, and snippets.

@derblub
Forked from zenxedo/TrueNAS Setup.md
Created February 24, 2018 15:23
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derblub/1eb6c9ddabc5236c242aa02b5a03639a to your computer and use it in GitHub Desktop.
Save derblub/1eb6c9ddabc5236c242aa02b5a03639a to your computer and use it in GitHub Desktop.
Ultimate FreeNAS 11.1 Setup

FreeNAS

This page was forked so be sure to check the Original for more and the links.

WARNING This page contains incomplete and possibly incorrect info. The page is constantly being edited and worked on. Many of these should work but some may be broken. Use at your own risk.

Create a "media" dataset

Create a dataset called "media" with directories for tv, movies, downloads
Give your dataset unix permissions to the default FreeNAS media user media:media

Adding Storage to you Jails

Using Radarr for example:
/mnt/YourVolume/media/movies  to /movies
/mnt/YourVolume/media/downloads to /downloads

Changing the config file location

This is optional and adds another layer of complexity

Using Radarr for example:
/mnt/YourVolume/apps/Radarr to /config

In the jail you then link the files
ln -s /config/config.xml /usr/local/sonarr/config.xml
ln -s /config/nzbdrone.db /usr/localsonarr/nzbdrone/db

You will either need to delete the config files or move them depending on if you already have the files before linking. After you do this your config files will be safe if you delete the jail

Permissions

Each time you create a new jail you will have to change the default user to media:media so the jails can work together properly.

Use the name of your plugin instead of PLUGIN

service PLUGIN onestop
chown -R media:media /usr/local/PLUGIN (this location might be different for some of the apps)
sysrc 'PLUGIN_user=media'
sysrc 'PLUGIN_group=media'
service PLUGIN start

My current setup (dates show the last successful test):

Configuration:

Other Apps:

Default User Ports/UID/Location info not correct

PORT - SERVICE - USER (UID) - DATA-DIRECTORY
sonarr - 8989 - media (816) - /usr/local/sonarr
radarr - 7878 - radarr (352) - /usr/local/radarr
jackett - 9117 - jackett () - /usr/local/jackett
plexmediaserver 32400 - plex (972) - /usr/local/plexdata
transmission - 9091 -transmission (921) - /usr/local/etc/transmission
unifi  - 8443 -
sabnzbd - media (816) - /usr/local/sabnzbd
headphones - 8181 - media (816) - /usr/local/headphones
madsonic - subsonic (844) - /usr/local/madsonic
plexmediaserver - plex (972) - /usr/local/plexdata
emby-server - emby (983) - /usr/local/emby-server
subsonic - media (816) - /usr/local/subsonic
syncthing - syncthing (983) - /usr/local/syncthing

Apps

Transmission

pkg install -y transmission-daemon
pkg update
sysrc transmission_download_dir=""
sysrc transmission_enable="YES"
service transmission start

# you may need to change the white list in settings.json to 0.0.0.0

Organizr https://forums.freenas.org/index.php?resources/fn11-jails-for-plex-plexpy-sonarr-radarr-jackett-ombi-transmission-nzbget-sabnzbd-organizr.58/

pkg install -y nginx wget php70 php70-curl php70-pdo php70-sqlite3 php70-simplexml php70-zip php70-openssl curl php70-hash php70-json php70-session php70-pdo_sqlite

sysrc nginx_enable=YES
sysrc php_fpm_enable=YES
wget https://github.com/causefx/Organizr/archive/master.zip
unzip master.zip -d /usr/local/www
rm master.zip
chown -R www:www /usr/local/www/Organizr-master

Configure php-fpm

Edit /usr/local/etc/php-fpm.conf with your favorite editor and make the following change:
Code:
listen = /var/run/php-fpm.sock

Uncomment the following lines:
Code:
listen.owner = www
listen.group = www
listen.mode = 0660

Create a php.ini from the template

cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini

Edit /usr/local/etc/php.ini with your favorite editor and make the following change:
Code:
date.timezone = "Universal"

Uncomment the following line and change the setting to 0:
Code:
cgi.fix_pathinfo=0

Create or replace /usr/local/etc/nginx/nginx.conf with the following which is the default with the bare minimum changes required to run Organizr.

user  www;
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        root   /usr/local/www/Organizr-master;
       
        location / {
            index  index.php index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/local/www/nginx-dist;
        }
     
        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            include fastcgi_params;
        }
}

restart jail and navigate to the ip:port

Jackett

https://github.com/Jackett/Jackett/releases https://forums.freenas.org/index.php?threads/need-help-installing-jackett-on-freenas-in-a-jail.38384/

pkg install -y jackett
pkg upgrade
sysrc jackett_enable=YES
service jackett start

Sonarr

https://github.com/Sonarr/Sonarr/wiki/Installation-FreeBSD

pkg install sonarr
pkg upgrade
sysrc sonarr_enable=YES
service sonarr start

# not a good option but works for in app updates if you want
chmod 777 /usr/local/share/sonarr

Radarr

https://github.com/Radarr/Radarr/releases https://github.com/Radarr/Radarr


pkg install radarr
pkg upgrade
sysrc radarr_enable=YES
service radarr start

Emby

pkg update && pkg upgrade
pkg install -y emby-server
sysrc emby_server_enable=YES
service emby-server start

# Update FreeBSD ports tree
portsnap fetch update
# might need to run this, watch log closely
portsnap extract

# Remove default FFMpeg package
pkg delete -f ffmpeg

# Reinstall FFMpeg from ports with lame option enabled
cd /usr/ports/multimedia/ffmpeg
make config

# enable the lame option
# enable the ass subtitles option
# enable the opus subtitles option
# enable the x265 subtitles option

# last step
make install clean

Plex

pkg install -y plexmediaserver
sysrc plexmediaserver_enable=YES
service plexmediaserver start
ln -s /mnt/myVol/jails/plex/usr/local/plexdata/Plex\ Media\ Server/Logs/ Plex\ Logs

Might be an issue:There has been new security settings added and there was a problem with the plex scanner making a request to a local agent. To fix it you should add 192.168.1.0/24 to Settings -> Server -> Network -> Enabled Advanced -> "List of IP Address and networks that are allowed without auth" add 192.168.1.0/24. After that, click refresh all and the scanner should be able to connect to the local agent.

Ombi

https://github.com/tidusjar/Ombi/releases https://forums.freenas.org/index.php?threads/plex-request-or-similar.42187/

pkg update && pkg upgrade
pkg install -y mono screen
echo 'jail_sysvipc_allow="YES"' >> /etc/rc.conf
fetch https://github.com/tidusjar/Ombi/releases/download/v2.0.1/Ombi.zip
unzip Ombi.zip
mv Release /usr/local/Ombi
rm Ombi.zip
touch /etc/rc.d/ombi
echo "/usr/local/bin/screen -d -m -S root nohup /usr/local/bin/mono /usr/local/Ombi/Ombi.exe" >> /etc/rc.d/ombi
chmod 555 /etc/rc.d/ombi

restart jail
use your browser and navigate to jail_ip:3579

Extra if you know what this is:
mkdir -p /usr/local/Ombi/Backups
mv /usr/local/Ombi/Ombi.sqlite /config/Ombi.sqlite
ln -s /config/Ombi.sqlite /usr/local/Ombi/Ombi.sqlite
mv /usr/local/Ombi/Backups /config/Backups
ln -s /config/Backups /usr/local/Ombi/Backups

Unifi

https://www.freshports.org/net-mgmt/unifi5/ https://forums.freenas.org/index.php?resources/installing-ubiquiti-unifi-controller-in-a-jail.55/

pkg update && pkg upgrade -y
pkg install -y bash llvm40 openjdk8
portsnap fetch extract
cd /usr/ports/net-mgmt/unifi5/ && make -DBATCH install clean
sysrc unifi_enable=YES
service unifi start

You must use the ssl site https://yourip:8443

Updates:
portsnap fetch extract
cd /usr/ports/net-mgmt/unifi5
service unifi stop
make reinstall clean
service unifi start

PlexPy

pkg install -y plexpy
pkg update
sysrc plexpy_enable=YES
service plexpy start

Updates

pkg upgrade "name of package without quotes"
pkg upgrade  :updates all the packages in the jail

Config Locations

Jackett
/usr/local/jackett/ServerConfig.json
/usr/local/jackett/indexers

Sonarr
/usr/local/sonarr/cofig.xml
/usr/local/sonarr/nzbdrone.db

Radarr
/usr/local/radarr/cofig.xml
/usr/local/radarr/nzbdrone.db

Transmission
/usr/local/etc/transmission/home

Plex
/usr/local/plexdata/Plex Media Server

Backups

Important files

Sonarr: download backup through web interface or nzbdrone.db & config.xml
Radarr: download backup through web interface or nzbdrone.db & config.xml
Unifi: download backup through web interface
Ombi: Ombi.sqlite
Headphones: headphones.db config.ini

Plexpy

/usr/local/plexpy/config.ini
/usr/local/plexpy/plexpy.db 
/usr/local/plexpy/plexpy.log
/usr/local/plexpy/backups

Emby

/var/db/emby-server/config
/var/db/emby-server/plugins
/var/db/emby-server/data/collections
/var/db/emby-server/data/playlists
/var/db/emby-server/data/displaypreferences.db
/var/db/emby-server/data/userdata_v2.db (if present)
/var/db/emby-server/data/users.db

Additionally, backup the library database file, but put it into a separate place from the others. This file will not be copied into your new Emby Server installation, but we will migrate your user data, such as watched data, favorites, etc.

/ProgramData/data/library.db

You'll need a Sqlite database editor such as DB Browser for Sqlite.
 
You'll need to open the old library.db file, then attach the new library.db file. You can then migrate the data using:
REPLACE INTO NewDB.userdata SELECT * FROM userdata

Install Emby on the new machine as you normally would. When the startup wizard launches in the browser, do not complete it and instead shut down the server.
 
Now take all of the files you backed up from the old server and copy them into the equivalent locations on the new server.
 
Then launch the new server, sign into the dashboard and setup your library paths. Allow the scan to complete as normal.

https://emby.media/community/index.php?/topic/10427-how-to-migrate-media-browser-server/
Sabnzbd replacement: sabnzbd.ini
Plex: not worth it

Common Commands

https://www-uxsup.csx.cam.ac.uk/pub/doc/suse/suse9.0/userguide-9.0/ch24s04.html

cd /directorypath	: Change to directory.
chmod [options] mode filename	: Change a file’s permissions.
chown [options] filename :	Change who owns a file.
cp [options] :source destination	: Copy files and directories.
ln -s test symlink	: Creates a symbolic link named symlink that points to the file test
mkdir [options] directory	: Create a new directory.
mv -i myfile yourfile : Move the file from "myfile" to "yourfile". This effectively changes the name of "myfile" to "yourfile".
mv -i /data/myfile :	Move the file from "myfile" from the directory "/data" to the current working directory.
rm [options] directory	: Remove (delete) file(s) and/or directories.
tar [options] filename :	Store and extract files from a tarfile (.tar) or tarball (.tar.gz or .tgz).
touch filename :	Create an empty file with the specified name.

Testing

service [name of service] start
service [name of service] stop
service [name of service] restart

Sabnzbd

pkg install sabnzbd
pkgupdate
sysrc sabnzbd_enable=YES
service sabnzbd start

Headphones

pkg update && pkg upgrade
pkg install py27-sqlite3  py27-cheetah
cd /usr/local && git clone git://github.com/rembo10/headphones.git
chown -R media:media headphones
cp /usr/local/headphones/init-scripts/init.freebsd /usr/local/etc/rc.d/headphones
chmod +x /usr/local/etc/rc.d/headphones
sysrc headphones_enable=YES
sysrc headphones_user=media
sysrc headphones_group=media

# edit rc.d/headphones, change python lcation to /usr/local/bin/python

Subsonic

https://project.altservice.com/issues/752

pkg install subsonic-standalone
pkg update
sysrc subsonic_enable=YES
service subsonic start

use your browser and navigate to jail_ip:4040

# edit usr/local/etc/rc.d/subsonic if you want web index /subsonic
# turn off transcoding for each player in Subsonic settings
# add storage and media folders
# change admin password and grant access to music folders

Madsonic

pkg install -y madsonic
pkg update
sysrc madsonic_enable=YES
service madsonic start

Calibre

pkg install calibre
sysrc calibre_enable=YES
sysrc calibre_port=8082
sysrc calibre_user=media
sysrc calibre_group=media
sysrc calibre_library=/mnt/media/books

Nginx webserver + PHP + MYSQL

For PHP5-extensions, include: bz2 ctype curl ftp dom exif fileinfo gd gmp iconv json ldap mbstring mcrypt mysql mysqli openssl pdo_mysql pdo_pgsql pdo_sqlite pgsql xsl zip zlib

For PHP5, include: FPM

pkg install -y nginx mysql56-server postgresql94-server php56-extensions
cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini
cd /usr/local/etc/nginx && cp nginx.conf-dist nginx.conf && cp mime.types-dist mime.types
sysrc nginx_enable=YES
sysrc php_fpm_enable=YES
sysrc mysql_enable=YES
sysrc postgresql_enable=YES
service postgresql initdb
service postgresql start
service mysql-server start
mysql_secure_installation
su pgsql
passwd

Modify nginx.conf similar to the attached nginx.conf file. Make sure to pay close attention to where "root" is and "location ~ .php$". You can overwrite the file with ":wq!"

Create a similar index.html as below in folder /usr/local/www.

NextCloud

cd /usr/ports/www/nextcloud && make config-recursive install clean
su pgsql
createdb ocdb
psql -s ocdb
create user <user> password <password>
GRAND ALL PRIVELEGES ON DATABASE ocdb TO <user>

Muximux

Install NGINX

http://linoxide.com/unix/freebsd-11-webserver-nginx-mysql-php-7-0-fpm/

pkg install -y php70 php70-json php70-session php70-openssl php70-zlib
pkg install -y nginx git
sysrc nginx_enable=YES
sysrc php_fpm_enable=YES
cd /usr/local/www
git clone https://github.com/mescon/Muximux Muximux

service nginx start

look on here for how to configure nginx if you don't already have an nginx.conf or else move your nginx.conf, ssl certs, .htaccess to their proper locations

cd /usr/local/etc/
nano php-fpm.conf


;listen = 127.0.0.1:9000
listen = /var/run/php-fpm.sock

#Just uncomment these lines
listen.owner = www
listen.group = www
listen.mode = 0660

cd /usr/local/etc/
cp php.ini-production php.ini
nano php.ini
Set cgi.fix_pathinfo=0

sysrc php_fpm_enable=YES
service php-fpm start

Test your setup

cd /usr/local/www/nginx/
nano info.php
=====================
<?php phpinfo(); ?>
=====================

Test at http://<JAIL IP>/info.php

Install Muximux

https://github.com/mescon/Muximux ''' pkg -y install git cd /usr/local/www git clone https://github.com/mescon/Muximux ''' move your settings.ini.php over if you have one Your settings.ini.php will never be overwritten if you use git pull or download the ZIP-file again

Crashplan

Create a jail using the FreeNAS web UI

Jail name: backup_jail
IPv4 address: 192.168.1./24
autostart: checked
type: portjail
VIMAGE: unchecked
vanilla: checked

Now add the directories you want to backup and where the backups should go.

Ports and dependencies

ssh root@192.168.1.2
jls
jexec 5 tcsh
passwd
portsnap fetch && portsnap extract && portsnap update
sysrc sshd_enable=YES
vi /etc/ssh/sshd_config
# add the following to the end of the file
Match User backup
    AllowTcpForwarding yes

adduser # backup with Uid 1002

Download the java runtime in order to please the CrashPlan overlords (or alternatively, modify the crashplan port scripts): http://www.oracle.com/technetwork/java/javase/downloads/index.html Scroll down to Java SE 8u111/112 and click JRE Download (third button). Accept the license and download jdk-8u112-linux-i586.tar.gz. Then scp or ftp it over:

scp ~/Downloads/jdk-8u112-linux-i586.tar.gz root@192.168.1.2:/mnt/tetra/backup_jail/usr/ports/distfiles/

This is just to appease the makefile, and instead we will use OpenJDK's JRE anyways. The following takes quite a while to install.

Install java and crashplan

cd /usr/ports/java/openjdk8-jre/ && make config-recursive && make install clean
cd /usr/ports/sysutils/linux-crashplan/ && make config-recursive && make install clean
sysrc crashplan_enable=YES

Now change the default Java binary path:

vi /usr/local/share/crashplan/install.vars
  JAVACOMMON=/usr/local/bin/java

Restart the jail. Now follow this guide to modify your current crashplan install to work on the remote machine. You will need to create a port bridge over ssh, which you can do with the following command (before starting up crashplan locally):

ssh -L 4200:localhost:4243 backup@192.168.1.4

And grab the file /var/lib/crashplan/.ui_info from the server and bring it to your local host where you will run the crashplan desktop client.

Helpful codes

Mounting USB drive:

kldload fuse
mkdir /mnt/usb
ntfs-3g /dev/da1s1 /mnt/usb
ntfs-3g -o permissions /dev/da1s1 /mnt/usb

LEMP Server - FreeBSD, Nginx, MariaDB & PHP (FastCGI)

Install Nginx

pkg install -y nano

pkg search nginx
pkg install -y nginx-1.8.0_3,2
cd /usr/local/etc/nginx/
mv nginx.conf nginx.conf.original

nano nginx.conf
=====================
# Define user that run nginx
user  www;
worker_processes  2;

# Define error log
error_log /var/log/nginx/error.log info;

events {
  worker_connections  1024;
}

http {
  include       mime.types;
  default_type  application/octet-stream;

  # Define access log
  access_log /var/log/nginx/access.log;

  sendfile        on;
  keepalive_timeout  65;

  server {
    listen       80;
    server_name  localhost;

    # Define web data
    root /usr/local/www/nginx;
    index index.php index.html index.htm;

    location / {
      try_files $uri $uri/ =404;
    }

    error_page      500 502 503 504  /50x.html;
    location = /50x.html {
      root /usr/local/www/nginx;
    }

    # Configuration for PHP-FPM
      location ~ \.php$ {
      try_files $uri =404;
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_pass unix:/var/run/php-fpm.sock;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $request_filename;
      include fastcgi_params;
    }
  }
}
=====================

mkdir -p /var/log/nginx/
touch /var/log/nginx/{error,access}.log
cd /usr/local/www/
rm -r nginx
mkdir nginx
cp nginx-dist/index.html nginx/index.html

sysrc nginx_enable=YES

nginx -t # check that there are no errors
service nginx start

Install MariaDB

pkg search mariadb
pkg install -y mariadb100-server-10.0.22 mariadb100-client-10.0.22
cp /usr/local/share/mysql/my-medium.cnf /usr/local/etc/my.cnf
sysrc mysql_enable=YES
service mysql-server start

mysql_secure_installation

Enter current password for root (enter for none):
#Just press Enter here
Change the root password? [Y/n] Y
#Type your password for mariadb here
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Test your connection:
mysql -u root -p<your password>

Install PHP with FastCGI (FPM)

pkg search php56
pkg install -y php56-5.6.16 php56-mysqli-5.6.16

cd /usr/local/etc/
nano php-fpm.conf

Line 164:
;listen = 127.0.0.1:9000
listen = /var/run/php-fpm.sock

Line 175:
#Just uncomment these lines
listen.owner = www
listen.group = www
listen.mode = 0660

cd /usr/local/etc/
cp php.ini-production php.ini
nano php.ini
Set cgi.fix_pathinfo=0

sysrc php_fpm_enable=YES
service php-fpm start

Test your setup

cd /usr/local/www/nginx/
nano info.php
=====================
<?php phpinfo(); ?>
=====================

Test at http://<JAIL IP>/info.php

Headphones

pkg install -y git
cd /usr/local && git clone git://github.com/rembo10/headphones.git
chown -R media headphones && chgrp -R media headphones
cp /usr/local/headphones/init-alt.freebsd /usr/local/etc/rc.d/headphones
chmod +x /usr/local/etc/rc.d/headphones
sysrc headphones_enable=YES
sysrc headphones_user=media

Alarmserver

pkg install python
pkg install py27-tornado py27-OpenSSL
cd /usr/local/share/
git clone https://github.com/juggie/AlarmServer
change the config example file
cd usr/local/share/AlarmServer
python alarmserver.py

ZoneMinder

pkg install -y nano fish zoneminder
sysrc zoneminder_enable=YES
service zoneminder start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment