Here’s a little how-to on how to use the new syncthing-plugin for your Freenas-server. Syncthing is an opensource file synchronisation client/server application. It’s a great alternative to btsync or Dropbox.
Note: The following text contains passages from my other guide on how to setup Freenas 9.2.1 with Transmission and Couchpotato/Sickbeard as a DLNA-Server. That’s because there are many similar steps to perform when setting up Freenas plugins.
Table of contents
Prepatory work
Installing plugins is very easy, as long as you stick to the available ones provided by Freenas. In the Plugins-menu, click on the plugins and then on Install, to install them. Each plugin is installed into a jail, a separate “operating system” in Freenas itself. Here are the steps required to install the plugin:
You’re going to need a place to store the synchronized data. We’re going to use a separate ZFS-dataset here. If you’re already familar with Freenas, feel free to use an existing dataset.
This is the most important part and you should carefully read the documentation the Freenas community offers. I will not go into detail on what volumes or RAIDs to use. It mainly depends on your needs and what you’ve got hardware-wise.
To create a dataset, you first need a volume, that is, a collection of your hard-drives. If you already created a volume, skip this step.
Afterwars, you have to create a new empty volume and attach disks to it: open Storage > Volumes > ZFS Volume Manager, give your new volume a name, add your disks and configure the layout.
To create a dataset click on your created storage, then hit the “Create dataset”-button (the one that looks like an excel-document with a plus). There, set the name for the dataset (e.g. backup). You can ignore all other options for now, as they are for advanced users.
Changing permissions of the storage
There are two possible configurations for the permissions of the storage: the secure (and a little bit harder) way and the easy way. I’ll describe both, but if you care about security (e.g, when you don’t trust the users of your network), take the secure way.
The secure way
Taking this way, you’ll have to create a new user on your Freenas that has permissions to access the storage. This way you don’t have to give read/write permissions to everybody on your network. This user was created in the syncthing-jail when you installed the plugin. We need it’s user-id and group-id, because the ids from the plugin have to match the ids from the user we are going to create in Freenas. Please keep in mind that these are separate users and are managed differently! To find out the ids, you’re going to have to connect to the jail (see [this part][] on how to do it) and enter the following:
root@syncthing_1:/ # grep "syncthing" /etc/passwd
A line along these lines will appear:
syncthing:*:983:983:Syncthing Daemon:/var/tmp/syncthing:/usr/sbin/nologin
Notice the two numbers 983. The first one is the user-id, the second one is the group-id. They could be different on your installation!
With these numbers you can create the user in Freenas. But first you need to create the group the user will be in. For that click on Account > Groups > Add group:
Then into the fields insert the group-id from earlier and as a name enter “syncthing”, then hit the OK-button:
Now you can create the user. To do that, click on Account > Users > Add user.
There fill in the user-id from earlier, as name again syncthing. You have also have to fill out the Full Name and password but the contents of these don’t matter.
Next thing you have to do is to change the permissions of the storage so the newly created user can access it. To change the permissions, click on the “Storage” tab, select the volume you want to edit and click the first button in the bottom line that displays hard disks and a key. There, set the Owner (user) to “syncthing”, the Owner (group) to “syncthing” and activate the read/write/execute buttons for the user and group. Last, tick the Set permission recursively:
Then, go to each user who should have access to syncthing. On the bottom of each user setting panel you will find the section “Auxiliary groups”. Add the syncthing group to the “Selected” section.
If you came this far, you can skip the easy way!
The easy way
The easy way is to set the ownership of the storage to nobody and give read/write/execute permissions to everybody. You should only do this, if you trust the users of your network. To change permissions, click on the “Storage” tab, select the volume you want to edit and click the first button in the bottom line that displays hard disks and a key. There, set the Owner (user) to “nobody”, the Owner (group) to “nogroup” and activate all buttons in the mode. Type of ACL should be set to Unix. Tick the box that says “Set permission recursively” so all other folders and files in the volume will have the same permissions.
Enabling access to the jail
SSH to your Freenas
You’ll likely need command-line access to your Freenas installation and to the jail as well. To enable SSH access to Freenas, go to Services and click on the screwdriver next to SSH. Tick the “Login as root with password” box and save the settings. After that, enable the SSH-Service by clicking the red OFF-button. Now you’re able to connect to your Freenas with SSH by entering the following line into your terminal-emulator of choice:
ssh root@192.168.0.14
(change the address to the address of your Freenas)
Then enter the admin-password and you should be connected to your box.
Using Putty to enter your Freenas
If you’re on Windows and want to connect to your Freenas-installation using Putty, you have to enter the IP-address of Freenas into the “Host Name”-field, then press “open”.
If Putty cannot connect, you probably didn’t use the correct IP-address or you forgot to enable SSH.
Entering the jails
To enter the syncthong, type “jls” on the command-line. There you’ll see all available jails. To connect to them, enter “jexec # tcsh” where # is the number of the jail.
[root@freenas] ~# jls
JID IP Address Hostname Path
1 - syncthing_1 /mnt/media/jails/syncthing_1
[root@freenas] ~# jexec 1 tcsh
root@syncthing_1:/ #
Adding the storage to the plugin
Now we’ll have to add the dataset to the syncthing-plugin, so it can access the storage. Since jails are separate systems in the server-OS itself, they cannot by default access other parts of your system.
To add the storage, go to Jails, click the plus next to the plugin, open the “Storage” tab and click “Add storage”. You’ll then have to enter the source and destination addresses.
The source is the storage or dataset you created in the first place. If you did not create a dataset before, you either have to do this now or create normal directories as sources with mkdir on the server. The destinations are directories in the jails that get mapped to the storages outside the jails.
If the destination addresses in the jails do not exist, tick the “Create directory”-box.
To manually create the directories, enter the jail, then you can create directories with the following command:
mkdir -p /media/backup
Then enter the following command the get the permissions right. It’s different depending on which way you chose earlier:
The secure way:
chmod -R 770 /media/backup
The easy way:
chmod -R 777 /media/backup
Configuring Syncthing
Now it’s time to open syncthing and configure it. You’ll have to open its frontend. The following screenshot shows, how to find out the ip-address of syncthing.
Now follow the official syncthing-guide on how to get started here!
[this part]: