Support #675
Updated by Daniel Curtis about 9 years ago
This is a guide for installing the Traccar GPS tracking server on FreeBSD 9.
h2. Prepare the Environment
* Make sure the system is up to date:
<pre>
pkg update && pkg upgrade
</pre>
* Install a few dependencies:
<pre>
pkg install openjdk-jre maven3 mysql-connector-java git unzip
</pre>
* Create the traccar user and group:
<pre>
pw groupadd traccar
pw useradd traccar -c Traccar -m -d /home/traccar -g traccar -s /bin/sh
</pre>
* Create a traccar directory:
<pre>
mkdir /usr/local/www/traccar
</pre>
* Change the ownership of the traccar directory to traccar user:
<pre>
chown traccar:traccar /usr/local/www/traccar
</pre>
h2. Install MySQL Server
* Install mysql55-server:
<pre>
pkg install mysql55-{server,client}
</pre>
* Start and enable mysql at boot:
<pre>
echo 'mysql_enable="YES"' >> /etc/rc.conf
service mysql start
</pre>
* Secure the installation:
<pre>
mysql_secure_installation
</pre>
* Log into the mysql interface:
<pre>
mysql -u root -p
</pre>
#* Then create the user traccaruser for the database
<pre>
CREATE USER 'traccaruser'@'localhost' IDENTIFIED BY 'SuperSecretPassword';
</pre>
#* And create the database traccardb and make the traccaruser the owner:
<pre>
CREATE DATABASE IF NOT EXISTS `traccardb`;
GRANT ALL PRIVILEGES ON `traccardb`.* TO 'traccaruser'@'localhost';
</pre>
#* Then quit out of the mysql interface:
<pre>
flush privileges;
exit
</pre>
h2. Install Traccar Server
* Switch to the traccar user:
<pre>
su - traccar
</pre>
h3. Install from Package
* Download and unzip the latest package:
<pre>
fetch https://github.com/tananaev/traccar/releases/download/v3.1/traccar-linux-64-3.1.zip
unzip traccar-linux-64-3.1.zip
</pre>
* Run the installer:
<pre>
sh traccar.run --noexec --target /usr/local/www/traccar
</pre>
* Exit from the traccar user:
<pre>
exit
</pre>
* Create the traccar init script:
<pre>
vi /usr/local/etc/rc.d/traccar
</pre>
#* And add the following:
<pre>
#!/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”
</pre>
* Make the init scrip executable:
<pre>
chmod +x /usr/local/etc/rc.d/traccar
</pre>
* Fix the configuration paths using sed:
<pre>
sed -i '' -e 's/\/opt/\/usr\/local\/www/g' /usr/local/www/traccar/conf/traccar.xml
</pre>
* Edit the traccar config:
<pre>
vi /usr/local/www/traccar/conf/traccar.xml
</pre>
#* And modify the database configuration:
<pre>
<entry key='web.address'>192.168.10.35</entry>
<entry key='database.driver'>com.mysql.jdbc.Driver</entry>
<entry key='database.url'>jdbc:mysql://127.0.0.1:3306/traccardb?allowMultiQueries=true&autoReconnect=true&useUnicode=yes&characterEncoding=UTF-8&sessionVariables=sql_mode=ANSI_QUOTES</entry>
<entry key='database.user'>traccaruser</entry>
<entry key='database.password'>SuperSecretPassword</entry>
</pre>
* Start and enable traccar server:
<pre>
echo 'traccar_enable="YES"' >> /etc/rc.conf
service traccar start
</pre>
* Open a web browser and go to http://traccar.example.com:8082
h2. Install Nginx
* Install nginx:
<pre>
pkg install nginx
</pre>
* Start and enable nginx at boot:
<pre>
echo 'nginx_enable="YES"' >> /etc/rc.conf
service nginx start
</pre>
* Create a configuration directory to make managing individual server blocks easier
<pre>
mkdir /usr/local/etc/nginx/conf.d
</pre>
* Edit the main nginx config file:
<pre>
vi /usr/local/etc/nginx/nginx.conf
</pre>
#* And strip down the config file and add the include statement at the end to make it easier to handle various server blocks:
<pre>
#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;
}
</pre>
* Then create the traccar.example.com server block config:
<pre>
vi /usr/local/etc/nginx/conf.d/traccar.example.com.conf
</pre>
#* And add the following:
<pre>
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;
}
}
</pre>
h2. Resources
* https://www.traccar.org/
* https://github.com/tananaev/traccar
* https://www.traccar.org/build/
* https://www.traccar.org/freebsd/
* https://www.traccar.org/mysql/