Project

General

Profile

Support #675

Install Traccar Server on FreeBSD

Added by Daniel Curtis about 9 years ago. Updated about 9 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Global Positioning Server
Target version:
Start date:
10/14/2015
Due date:
% Done:

100%

Estimated time:
4.00 h
Spent time:

Description

This is a guide for installing the Traccar GPS tracking server on FreeBSD 9.

Prepare the Environment

  • Make sure the system is up to date:
    pkg update && pkg upgrade
    
  • Install a few dependencies:
    pkg install openjdk-jre maven3 mysql-connector-java git unzip
    
  • Create the traccar user and group:
    pw groupadd traccar
    pw useradd traccar -c Traccar -m -d /home/traccar -g traccar -s /bin/sh
    
  • Create a traccar directory:
    mkdir /usr/local/www/traccar
    
  • Change the ownership of the traccar directory to traccar user:
    chown traccar:traccar /usr/local/www/traccar
    

Install MySQL Server

  • Install mysql55-server:
    pkg install mysql55-{server,client}
    
  • Start and enable mysql at boot:
    echo 'mysql_enable="YES"' >> /etc/rc.conf
    service mysql start
    
  • Secure the installation:
    mysql_secure_installation
    
  • Log into the mysql interface:
    mysql -u root -p
    
    • Then create the user traccaruser for the database
      CREATE USER 'traccaruser'@'localhost' IDENTIFIED BY 'SuperSecretPassword';
      
    • And create the database traccardb and make the traccaruser the owner:
      CREATE DATABASE IF NOT EXISTS  `traccardb`;
      GRANT ALL PRIVILEGES ON `traccardb`.* TO 'traccaruser'@'localhost';
      
    • Then quit out of the mysql interface:
      flush privileges;
      exit
      

Install Traccar Server

  • Switch to the traccar user:
    su - traccar
    

Install from Package

  • Download and unzip the latest package:
    fetch https://github.com/tananaev/traccar/releases/download/v3.1/traccar-linux-64-3.1.zip
    unzip traccar-linux-64-3.1.zip
    
  • Run the installer:
    sh traccar.run --noexec --target /usr/local/www/traccar
    
  • Exit from the traccar user:
    exit
    
  • Create the traccar init script:
    vi /usr/local/etc/rc.d/traccar
    
    • And add the following:
      #!/bin/sh
      #
      
      # PROVIDE: traccar
      # REQUIRE: DAEMON
      # BEFORE:
      # KEYWORD: shutdown
      
      # Add the following lines to /etc/rc.conf to enable `traccar':
      #
      # traccar_enable="YES" 
      #
      
      . /etc/rc.subr
      
      name="traccar" 
      rcvar=traccar_enable
      
      # read configuration and set defaults
      load_rc_config "$name" 
      : ${traccar_enable="NO"}
      : ${traccar_root="/usr/local/www/traccar"} 
      : ${traccar_java="java"}
      : ${traccar_user="traccar"}
      : ${traccar_stdout="/dev/null"}
      : ${traccar_stderr="/dev/null"}
      
      traccar_chdir=${traccar_root}
      
      command="$traccar_java" 
      command_args="-jar $traccar_root/tracker-server.jar $traccar_root/conf/traccar.xml" 
      pidfile="/var/run/$name.pid" 
      required_files="$traccar_root/conf/traccar.xml" 
      
      start_cmd="/usr/sbin/daemon -p $pidfile -u $traccar_user $command $command_args > $traccar_stdout 2> $traccar_stderr" 
      
      run_rc_command "$1”
      
  • Make the init scrip executable:
    chmod +x /usr/local/etc/rc.d/traccar
    
  • Fix the configuration paths using sed:
    sed -i '' -e 's/\/opt/\/usr\/local\/www/g' /usr/local/www/traccar/conf/traccar.xml
    
  • Edit the traccar config:
    vi /usr/local/www/traccar/conf/traccar.xml
    
    • And modify the database configuration:
      <entry key='database.driver'>com.mysql.jdbc.Driver</entry> 
      <entry key='database.url'>jdbc:mysql://127.0.0.1:3306/traccardb?allowMultiQueries=true&amp;autoReconnect=true&amp;useUnicode=yes&amp;characterEncoding=UTF-8&amp;sessionVariables=sql_mode=ANSI_QUOTES</entry>
      <entry key='database.user'>traccaruser</entry> 
      <entry key='database.password'>SuperSecretPassword</entry>
      
  • Start and enable traccar server:
    echo 'traccar_enable="YES"' >> /etc/rc.conf
    service traccar start
    

Install Nginx

  • Install nginx:
    pkg install nginx
    
  • Start and enable nginx at boot:
    echo 'nginx_enable="YES"' >> /etc/rc.conf
    service nginx start
    
  • Create a configuration directory to make managing individual server blocks easier
    mkdir /usr/local/etc/nginx/conf.d
    
  • Edit the main nginx config file:
    vi /usr/local/etc/nginx/nginx.conf
    
    • And strip down the config file and add the include statement at the end to make it easier to handle various server blocks:
      #user  nobody;
      worker_processes  1;
      error_log  /var/log/nginx-error.log;
      
      events {
        worker_connections  1024;
      }
      
      http {
        include       mime.types;
        default_type  application/octet-stream;
      
        sendfile        on;
        #tcp_nopush     on;
      
        #keepalive_timeout  0;
        keepalive_timeout  65;
      
        #gzip  on;
      
        # Load config files from the /etc/nginx/conf.d directory
        include /usr/local/etc/nginx/conf.d/*.conf;
      
      }
      
  • Then create the traccar.example.com server block config:
    vi /usr/local/etc/nginx/conf.d/traccar.example.com.conf
    
    • And add the following:
      server {
        listen 80;
        server_name traccar.example.com;
        access_log  /var/log/traccar.example.com-access.log;
        error_log  /var/log/traccar.example.com-error.log;
      
        location / {
          proxy_pass http://127.0.0.1:8082;
          proxy_redirect off;
          proxy_buffering off;
          proxy_set_header    Host            $host;
          proxy_set_header    X-Real-IP       $remote_addr;
          proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
          port_in_redirect off;
          proxy_connect_timeout       900;
          proxy_send_timeout          900;
          proxy_read_timeout          900;
          send_timeout                900;
        }
      }
      

Resources

#1

Updated by Daniel Curtis about 9 years ago

  • Description updated (diff)
  • Status changed from New to Resolved
  • % Done changed from 0 to 100
#2

Updated by Daniel Curtis about 9 years ago

  • Description updated (diff)
#3

Updated by Daniel Curtis about 9 years ago

  • Description updated (diff)
#4

Updated by Daniel Curtis about 9 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF