Showing posts with label Setup and Installation. Show all posts
Showing posts with label Setup and Installation. Show all posts

How to install Shinobi in a FreeNAS (11.3-RELEASE) Jail

I've been running Shinobi in a FreeNAS jail for more than 2 years now and although there were some hiccups, they are still manageable. I created a blog post on how to do that as well but that's for a previous version of FreeNAS. FreeNAS has had several updates since then and so did Shinobi so I decided to write up another post on how to setup and install the latest Shinobi (as of writing) to a FreeNAS (11.3-RELEASE) jail.

NOTE: The following setup guide is actually taken from the freebsd.sh and freenas.csh scripts that comes with Shinobi. Unfortunately, running either scripts produces some errors for me and installation fails at some point. So what I did is get the commands that works and I execute them one by one.

Installation and Setup

  1. Login to FreeNAS ui as root and navigate to Jails and add a Jail.
  2. Launch the Shell for that Jail. Must be root.
  3. To download Shinobi, we'll need to install the git application. Run the command below and follow the installation instructions.

    TIP: You can copy the commands here and paste them in FreeNAS shell by pressing Shift + Insert keys on your keyboard.
    pkg install git
  4. Shinobi requires certain software to run properly so we'll need to install them first. Type the following commands and follow the installation instructions to install.
    pkg install ffmpeg
    pkg install x264
    pkg install x265
    pkg install node
    pkg install npm
    pkg install mysql57-server
    
  5. Now we download Shinobi.
    git clone https://gitlab.com/Shinobi-Systems/Shinobi.git Shinobi
  6. Change directory to Shinobi..
    cd Shinobi
    It is also a good idea to know which directory Shinobi was installed.
    pwd
    Take note of this as you might need to change the path on some of my setups later. In this tutorial, I installed Shinobi in /root so you might see me referencing /root/Shinobi. Yours might be different so just replace the path if necessary.

  7. We'll need to do some additional setups for the MySQL server.
    • First of, enable mysql.
      sysrc mysql_enable=YES
    • Then start mysql.
      service mysql-server start
    • Now we need to login to mysql via command line but before we can do that, we need to know the password. After a fresh install of MySQL server, a file with a temporary password is generated. This file is usually located in /home/.mysql_secret. In this case, it should be in /root/.mysql_secret. To view the file, run the command below and make sure to take note of the password.
      cat /root/.mysql_secret
    • Login to MySQL
      mysql -h localhost -u root -p
      It will now ask you to type the password. Once logged in, we need to change the password for security purposes.
      alter user 'root'@'localhost' identified by 'newpassword';
    • Assuming we are still in the mysql command line interface, let's now add Shinobi user to the database.
      source /root/Shinobi/sql/user.sql
      If this work properly, you should see a message similar to "Query OK..."
    • Next, setup Shinobi framework to the database.
      source /root/Shinobi/sql/framework.sql
      This is it for the MySQL setup. Type quit to exit mysql command line interface.
  8. Now on to the Shinobi setups. I've listed the commands below. Just type them one by one.
    npm install -g npm -g
    npm install --unsafe-perm
    npm install pm2@3.0.0 -g
    cd Shinobi
    cp conf.sample.json conf.json
    cp super.sample.json super.json
    pm2 start camera.js
    pm2 start cron.js
    pm2 save
    pm2 list
    pm2 startup rcd

That's it. If everything went well, you should be able to access your Shinobi server through your browser and opening http://your_jail_ip_address:8080. Default username is admin@shinobi.video and password is admin.

P.S. I also developed an android application which you can get at Google Play. It needs a lot of work but if setup correctly, you will be able to view and control your cameras.

Setup FreeNAS Dynamic DNS with Namecheap

In my previous post, I discussed about setting up Shinobi on a FreeNAS jail. I also mentioned that in doing this, I will need to port forward my Shinobi jail ip to make it accessible from outside. This way I can view my streams from anywhere.

In this post, I will be writing about how to setup ddns in FreeNAS with Namecheap as the provider. This is recommended if your ISP supplies you a dynamic ip address, which is my case, as opposed to having a static ip address which you can directly assign to a domain or subdomain in your Namecheap Advanced DNS setup page.

There are actually two ways that I know of on how to do this:
  1. Using FreeNAS Dynamic DNS
  2. Using FreeNAS cron job

Using FreeNAS Dynamic DNS


Login to your FreeNAS admin user interface and navigate to Dynamic DNS under Services.


Enter the following information:
FieldValue
  
ProviderCustom Provider
Use SSLChecked
Custom Serverdynamicdns.park-your-domain.com
Custom Path/update?host=%h&domain=[domain]&password=[password]
Domain Namehost
Usernamedomain name
PasswordNamecheap DDNS Password
Confirm PasswordNamecheap DDNS Password
Update Period600


Explanation of fields and values

Provider
This is the DNS provider. However at the time of this writing, Namecheap is not included among the list. So in order to use Namecheap, we use Custom Provider. Fortunately, Namecheap provides a way to update your host's ip address through your browser. This can be done by simply opening the URL and passing the appropriate parameters. You can find more information on this in their Knowledgebase here.
https://dynamicdns.park-your-domain.com/update?host=%h&domain=[domain]&password=[password]
Use SSL
Whether or not Namecheap's custom server is using SSL. Since the URL uses HTTPS, then we check SSL.
Custom Server
This is the hostname in the provided URL earlier.
Custom Path
This is the path along with the required query parameters and values after the custom server hostname in the URL mentioned above. /update?host=%h&domain=[domain]&password=[password]

where:
  • %h is the value of the field Domain Name
  • domain is your domain.tld. For ex: google.com
  • password is you Namecheap DDNS password which can be seen at the Namecheap Advanced DNS page. See sample screen shot below.

Update Period
This is the frequency you want FreeNAS Dynamic DNS service to update your host's ip address in seconds.

Once you've entered all the necessary information, click OK. Make sure the your Dynamic DNS service is running by the way. You can check that by going to the Services tab.


After the update period has passed, go to your Namecheap's Advanced DNS page and check your updated ip address.

Using FreeNAS cron job


As mentioned earlier, Namecheap provides a way to update your host's ip address through your browser.

To use this in a cron job, we simply need to execute a command like curl or wget to access the URL. I'll be using curl in my case. The only difference here is that we specify the host value here as opposed to using %h earlier. For example:
curl "https://dynamicdns.park-your-domain.com/update?host=www&domain=google.com&password=your-namecheap-dns-password-here"
Then specify the preferred schedule. Once the cron job executes, go to your Namecheap's Advanced DNS page and check your updated ip address.

That's it. Enjoy!

References

How to install Shinobi Video on a FreeNAS Jail

Prelude


So I've been doing a lot of research lately on how I should go about setting up surveillance cameras around our home. Features like remote viewing, motion detection and alerts are a necessity. At first I thought of using ip cameras then just use their own application for remote viewing and recording like Mi Home from Xiaomi, Hik-Connect from HikVision and so on. This was okay at first but then I found out that most of these cameras upload data to their corresponding servers. From what I understand, these servers act as relays in order to allow consumers to view live streams from their camera remotely without having the need for static ip addresses, port forwarding as well as DVRs/NVRs.

It does make sense to do this in some way because it does make it easier for consumers. Otherwise consumers will need to request static ip addresses from their respective ISPs or setup a DDNS at home, then setup port forwarding on their routers. Security also needs to be considered since they are opening their network to the internet.

However, the fact that these cameras uploads data to their respective servers made me think twice because of privacy reasons. Since I already have a FreeNAS available at home, I decided to just install a surveillance software on it, setup DDNS and setup port forwarding on my router.

First things first, I need to decide which software to use. My requirements are:
  • Should be free.
  • Should support linux (Ubuntu, CentOS, FreeBSD).
  • Should not require too much RAM and CPU.

I only looked at a few software.
  • Zoneminder. Unfortunately, I had a hard time setting this up on a CentOS7 in Google Compute Engine.
  • Shinobi. Successful on first attempt in Google Compute Engine. Also looks promising.
  • Motion. Didn't get to try it since I already installed Shinobi successfully.

And that's how I came to a decision. Shinobi it is.

Before we begin, here are some information about my FreeNAS.
root@shinobi_1:/ # uname -a                                                     
FreeBSD shinobi_1 11.1-STABLE FreeBSD 11.1-STABLE #0 r321665+9902d126c39(freenas/11.1-stable): Tue Aug 21 12:24:37 EDT 2018     root@nemesis.tn.ixsystems.com:/freenas-11-releng/freenas/_BE/objs/freenas-11-releng/freenas/_BE/os/sys/FreeNAS.amd64  amd64
root@shinobi_1:/ # 
Specs:
Intel(R) Pentium(R) CPU G4600 @ 3.60GHz
8GB RAM
2x2TB HDD 3.5"
1x500GB HDD 2.5"

Installation and Setup


Navigate to Jails and add a Jail.
Launch the Shell for that Jail. Must be root.

In my current FreeNAS version, running the installation produces an error.
Shared object "libdl.so.1" not found,
In order to fix this, I had to make some modifications as suggested in this thread. Basically modified the file /usr/local/etc/pkg/repos/FreeBSD.conf

from
FreeBSD: {
  url: "pkg+http://pkg.FreeBSD.org/freebsd:11:x86:64/latest",
  mirror_type: "srv",
  enabled: yes
}
to
FreeBSD: {
  url: "pkg+http://pkg.FreeBSD.org/freebsd:11:x86:64/release_2",
  mirror_type: "srv",
  enabled: yes
}
Then execute the following commands:
pkg update -f
pkg upgrade -f
Once done, pull the repository.
git clone https://gitlab.com/Shinobi-Systems/Shinobi.git Shinobi
Change directory to Shinobi.
cd Shinobi
Start the installer.
chmod +x INSTALL/freenas.sh && INSTALL/freenas.csh
Instructions on how to access your Shinobi instance will be available at the end of the installation process. By default, the URL for the super user should be:
http://your_jails_ip_address:8080/super
Here is where you create user accounts. To access the Dashboard, go to:
http://your_jails_ip_address:8080
Username and Password for this are those created mentioned above.

Sample screenshot after successful installation

Here is a sample screen shot of the Shinobi setup.


And that's it. Enjoy!

Here are some of the references that helped me achieve this.


UPDATE: I've been using Shinobi for more than a year now and it has been sufficient for my needs. I also developed an android application which you can get at Google Play. It needs a lot of work but if setup correctly, you will be able to view and control your cameras.