Giter VIP home page Giter VIP logo

traccar-server's Introduction

Traccar server

This is the repository to create the traccar-server with a standalone MySQL database and Traefik reverse proxy via docker-compose file.

Minimum VPS configuration

Setup Instructions

Install Docker

  1. First, in order to ensure the downloads are valid, add the GPG key for the official Docker repository to your system:
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  2. Add the Docker repository to APT sources:
    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  3. Next, update the package database with the Docker packages from the newly added repo:
    sudo apt-get update
  4. Make sure you are about to install from the Docker repo instead of the default Ubuntu 16.04 repo:
    apt-cache policy docker-ce
    You should see output similar to the follow:
docker-ce:
    Candidate: 18.06.1~ce~3-0~ubuntu
    Version table:
        18.06.1~ce~3-0~ubuntu 500
            500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
  1. Finally, install Docker:
    sudo apt-get install -y docker-ce
  2. Docker should now be installed, the daemon started, and the process enabled to start on boot. Check that it's running:
    sudo systemctl status docker
  3. If you want to avoid typing sudo whenever you run the docker command, add your username to the docker group:
    sudo usermod -aG docker ${USER}
  4. To apply the new group membership, log out of the server and back in.
  5. Afterwards, you can confirm that your user is now added to the docker group by typing:
    id -nG

Install Docker Compose

  1. We'll check the current release and if necessary, update it in the command below:
    ssudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  2. Next we'll set the permissions:
    sudo chmod +x /usr/local/bin/docker-compose
  3. Then we'll verify that the installation was successful by checking the version:
    docker-compose -v

Install the repository into the VPS

  1. Clone the repository.
  2. Step into the just created folder

Configure environment variables

  1. Set your mysql username and password parameters as environment variables:
    export MYSQL_USER=YOUR_USERNAME export MYSQL_ROOT_PASSWORD=YOUR_ROOT_PASSWORD export MYSQL_PASSWORD=YOUR_USER_PASSWORD export MYSQL_DATABASE=YOUR_DATABASE_NAME
  2. Set your domain:
    export DOMAIN=YOUR_DOMAIN.com
  3. Alternatively you can set all these variables in .env file and export all at once on the system startup by adding the following command to your .bashrc:
    export $(<PATH_TO_THE_REPOSITORY/.env)

Customize your volumes in the docker-compose.yml file according to the customization you want to have

  1. Set your mysql username and password parameters as environment variables:
    export MYSQL_USER=YOUR_USERNAME export MYSQL_ROOT_PASSWORD=YOUR_ROOT_PASSWORD export MYSQL_PASSWORD=YOUR_USER_PASSWORD export MYSQL_DATABASE=YOUR_DATABASE_NAME
  2. Set your domain:
    export DOMAIN=YOUR_DOMAIN.com
  3. Alternatively you can set all these variables in .env file and export all at once on the system startup by adding the following command to your .bashrc:
    export $(<PATH_TO_THE_REPOSITORY/.env)

Create the traccar configuration file

  1. Create a traccar.xml file with your configuration inside the folder traccar/conf/
  2. A sample configuration file is provided on traccar/conf/sample_traccar.xml
  3. Replace [DATABASE] with your MySQL database name
  4. Replace [USER] with your MySQL username
  5. Replace [PASSWORD] with your MySQL passoword
  6. For more details on the available options fro traccar configuration file, pelase check: https://www.traccar.org/configuration-file/

Create the traefik configuration file

  1. Create a traefik.toml file with your configuration inside the folder traefik/
  2. A sample configuration file is provided on traefik/traefik_sample.toml. The standard login\username for the Web UI is admin\admin
  3. For configuration examples, including Let's Encrypt support please check https://docs.traefik.io/v1.7/user-guide/examples/

Restore the database

IF YOU HAVE A DATABASE BACKUP, ENSURE YOU DO THIS BEFORE STARTING TRACCAR-SERVER

  1. In the machine and the respective folder where the backup is located, transfer the backup file to the VPS:
    rsync -avzhe ssh ./backup.sql user@VPS_ip:~/backup.sql
  2. Connect to the VPS via SSH:
    ssh user@VPS_ip
  3. Step into the clonned repository:
    cd traccar-server
  4. Run the MySQL database:
    docker-compose up -d db
  5. Check if everything is working via the commands:
    docker-compose ps or docker ps
    docker-compose logs
  6. Transfer the last backup to the database:
    docker exec -i db sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD" "$MYSQL_DATABASE"' < ~/backup.sql

Aditional customization

  1. Customize your volumes in the docker-compose.yml file according to the customization you want to have

Execute all the services

docker-compose up -d or docker-compose up -d --build --force-recreate to force recreation of image and container
Check if everything is working via the commands:
docker-compose ps or docker ps
Check the logs of each container via the command:
docker-compose logs container_name

Other useful repositories

To run all the services together, clone all the repositories to your machine, define the same compose project name for all of them at the .env file located on each repository and run each service through the docker-compose up -d command on each repository.

traccar-server's People

Contributors

rafaelmiquelino avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

traccar-server's Issues

data not persistent

This is my docker-compose file:

version: "3"
services:
db:
image: mysql:8.0.13
container_name: db
command: --default-authentication-plugin=mysql_native_password
restart: always
env_file: .env
volumes:
- /etc/localtime:/etc/localtime:ro
- db-datavolume:/var/lib/mysql
- ./mysql:/etc/mysql/conf.d
ports:
- "3306:3306"

traccar:
    image: traccar/traccar:4.8-alpine
    container_name: traccar
    depends_on:
        - db
    restart: always
    volumes:
        - ./traccar/conf/traccar.xml:/opt/traccar/conf/traccar.xml:ro
        - /var/log/traccar:/opt/traccar/logs:rw
        - ./traccar/web/favicon.ico:/opt/traccar/web/favicon.ico:ro
        - ./traccar/web/icon.png:/opt/traccar/web/icon.png:ro
        - ./traccar/web/logo.svg:/opt/traccar/web/logo.svg:ro
        - ./traccar/web/release.html:/opt/traccar/web/release.html:ro
        - ./traccar/web/app.css:/opt/traccar/web/app.css:ro
    ports:
        - "5002-5150:5002-5150"
        - "8083:8082"

    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

volumes:
db-datavolume:

When I do a docker-compose down
and then
docker-compose up
All the data (users, devices,etc.) disappears and I have to reenter it again.

Which I don't understand since there is a volume for the db.

Is there a routine in the traccar server that reinitializes the db every time it starts? Doesn't make sense to me.

Apart from that small detail everything runs fine.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.