Skip to content

Server setup

Brendan Ward edited this page Apr 6, 2019 · 1 revision

Server setup

Server

sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Add this to /etc/fstab: /swapfile none swap sw 0 0

Setup accounts and directories

Create user for the application

  • sudo adduser app --disabled-password

Install and build mbtileserver

  • Install go 1.12 according to the installation instructions on the Golang site: https://github.com/golang/go/wiki/Ubuntu
  • note: go get installs to ~/go` by default
  • sudo su app && cd ~
  • mkdir go
  • go get github.com/consbio/mbtileserver, this installs mbtilserver to ~/go/bin/mbtileserver

As ubuntu user, grant mbtileserver ability to bind port 80:

  • sudo setcap CAP_NET_BIND_SERVICE=+eip /home/app/go/bin/mbtileserver

Copy the tiles to /home/app/tiles.

Verify that mbtileserver starts properly and is able to obtain certificates for HTTPS connections.
From /home/app directory, run /home/app/go/bin/mbtileserver -d /home/app/tiles -p 443 --domain <DOMAIN> --redirect --tls Note: update <DOMAIN> to proper domain for this server. Then make a connection to that URL to force server to obtain certificates from Let's Encrypt. In your browser: https://<DOMAIN>/services

You should see this on the server, and no errors:

INFO[0000] Found 116 mbtiles files in ./

--------------------------------------
Use Ctrl-C to exit the server
--------------------------------------
HTTPS server started on port 443
⇨ https server started on [::]:443
HTTP server with redirect started on port 80
⇨ http server started on [::]:80

Stop mbtileserver with CTRL-C.

Certificates are cached in /home/app/.certs directory. Verify that there is an entry for <DOMAIN> above.

Setup mbtileserver service:

Paste the following into /etc/systemd/system/mbtileserver.service, updating variables as needed:

[Unit]
Description=MBTileserver
Documentation=https://github.com/consbio/mbtileserver
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service

[Service]
Restart=on-abnormal
RestartSec=60
User=app

WorkingDirectory=/home/app
ExecStart=/home/app/go/bin/mbtileserver -d ./ -p 443 --domain <DOMAIN> --redirect --tls
ExecReload=/bin/kill -USR1 $MAINPID

[Install]
WantedBy=multi-user.target

Verify that it starts correctly:

  • sudo service mbtileserver start
  • sudo service mbtileserver status should report no errors

Register the service to start on server reboot:

  • sudo systemctl daemon-reload
  • sudo systemctl enable mbtileserver
Clone this wiki locally