Installation

1. Vorarbeiten

Wenn etwas von den Standardwerten abweichen soll, dann müssen die Umgebungsvariablen in der ~/.bashrc hinzugefügt/angepasst werden.

export LG_NAME=locr-geocoder # optional
export LG_INI_FILE=/etc/locr/geocoder.ini # optional
export LG_PORT=9012 # optional

und mit dem folgenden Kommando aktualisieren

source ~/.bashrc

Die Datei /etc/locr/geocoder.ini hat folgendes Grundgerüst und Standardwerte:

[DB]
host=127.0.0.1
port=5432
name=locr_geocoder
user=postgres
password=

2. Installation aus den Quellen

mkdir -p ~/projects && cd ~/projects
git clone git@bitbucket.org:locr/locrgeocoder.git LocrGeocoder
cd LocrGeocoder

3. Container Service installieren

./scripts/install_service.sh

4. Update script im home-Verzeichnis erstellen

cat <<EOF >~/update_locr_geocoder.sh
#!/usr/bin/env bash

cd ${PWD}/scripts
./update_service.sh
EOF

chmod +x ~/update_locr_geocoder.sh

5. nginx konfigurieren

sudo cp installation_files/nginx/conf.d/locr-geocoder /etc/nginx/conf.d

Sicherstellen, dass folgende Zeile in der /etc/nginx/sites-enabled/default Datei vorhanden ist!

server {
    ...
    include conf.d/locr-geocoder;
    ...
}

nginx neustarten

sudo service nginx restart

6. Daten erstellen/importieren

6.1. neue Daten erstellen

export PGPASSWORD=<secret>
export PGDATABASE=locr_geocoder
export PGUSER=postgres # optional
export PGHOST="127.0.0.1" # optional
export PGPORT=5432 # optional
export TMPDIR=/tmp # optional

./scripts/prepare_db.sh

npm install
# OpenAddresses Quellen von https://batch.openaddresses.io/data
# Stand: 2024-08-25
node ./scripts/oa_importer.mjs --country=at # 2'930'014 Einträge
./scripts/import_plz_data.sh # nur für 'de' Import
node ./scripts/oa_importer.mjs --country=de # ca. 15 Minuten; 6'994'900 Einträge
node ./scripts/oa_importer.mjs --country=fr # ca. 18 Minuten; 26'040'540 Einträge

# NAD Daten werden momentan nicht verwendet.
# ./scripts/import_nad_data.sh # ca. 01:30h (Download ca. 7.5GB, ca. 10min bei 12MB/s Downloadgeschwindigkeit)
./scripts/import_tiger_data.sh # Dieses script muss vor import_oa_us.sh ausgeführt werden!
./scripts/import_oa_us.sh

./scripts/import_addresses_ca.sh
./scripts/import_ca_postal_codes.sh

6.2. erstellte Daten sichern

Datenbank sollte ca. 55GB groß sein.

sudo -u postgres pg_dump $PGDATABASE | gzip > /tmp/2024-08-25_locr_geocoder.gz

6.3. gezippte Datei auf Server kopieren

scp /tmp/2024-08-25_locr_geocoder.gz serverconnect@maps1.locr.com:~/

6.4. kopierte Datei auf Server (maps1.locr.com) ins /var/www/archive Verzeichnis verschieben

sudo mv ~/2024-08-25_locr_geocoder.gz /var/www/archives && sudo chown root:root /var/www/archives/2024-08-25_locr_geocoder.gz

6.5. existierende Daten auf neuen Server importieren

sudo -u postgres psql --command="CREATE DATABASE locr_geocoder"
sudo -u postgres psql --command="CREATE EXTENSION IF NOT EXISTS postgis" locr_geocoder

wget -O /tmp/locr_geocoder.gz https://maps1.locr.com/archives/2024-08-25_locr_geocoder.gz
cat /tmp/locr_geocoder.gz | gunzip | sudo -u postgres psql locr_geocoder
rm /tmp/locr_geocoder.gz

7. Running LG on a Raspberry Pi (RPi)

Setup an SD image for the RPi device using the [RPi-Imager tool](https://www.raspberrypi.com/software/). Choose "locrgeocoder" as the device name and select the appropriate options for remote access.

7.1. Install the required packages

Install nodejs version 18!

ssh pi@locrgeocoder

sudo apt install nginx php-fpm git postgresql

7.2. Configure the LG database

Add a new DB user and a matching database.

sudo su postgres

createuser geo -P --interactive

psql
CREATE DATABASE geo;

exit
exit

Edit pg_hba.conf.

sudo nano /etc/postgresql/13/main/pg_hba.conf

Add:

host    pi              pi              0.0.0.0/0               md5
host    pi              pi              ::/0                    md5

Edit postgresql.conf.

sudo nano /etc/postgresql/13/main/postgresql.conf

Change:

#listen_addresses = 'localhost'          # what IP address(es) to listen on;

to:

listen_addresses = '*'          # what IP address(es) to listen on;

Restart the PostgreSQL database.

sudo service postgresql restart

7.3. Add an appropriate certificate for HTTPS protocol access

Setup snakeoil cert for local access.

sudo apt install ssl-cert
sudo make-ssl-cert generate-default-snakeoil

Alternatively letsencrypt service for internet access.

sudo apt install snapd
sudo snap install core; sudo snap refresh core
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot --nginx

7.4. Add a new RPi user

sudo adduser geo sudo

exit

ssh geo@locrgeocoder

ssh-keygen

7.5. Install the LG

Copy the public key to Bitbucket for repository access.

git clone git@bitbucket.org:locr/phpgeocoder.git

cd phpgeocoder

npm i

Create soft link for the Nginx "www" folder.

sudo ln -s /home/vms2/phpgeocoder/ /var/www/locr-geocoder

7.6. Prepare Nginx and PHP FastCGI

Nginx config preparation.

sudo nano /etc/nginx/sites-enabled/default

Change (example for snakeoil certificate):

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html;

to:

# SSL configuration
#
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
include snippets/snakeoil.conf;
root /var/www;

Also change:

# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
#       include snippets/fastcgi-php.conf;
#
#       # With php-fpm (or other unix sockets):
#       fastcgi_pass unix:/run/php/php7.4-fpm.sock;
#       # With php-cgi (or other tcp sockets):
#       fastcgi_pass 127.0.0.1:9000;
#}

to:

# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
       include snippets/fastcgi-php.conf;
       # With php-fpm (or other unix sockets):
       fastcgi_pass unix:/run/php/php7.4-fpm.sock;
       # With php-cgi (or other tcp sockets):
#       fastcgi_pass 127.0.0.1:9000;
       fastcgi_read_timeout 6000s;
}
sudo nano /etc/nginx/nginx.conf

Change:

#user www-data;

To:

user geo;

PHP FastCGI config setup.

sudo nano /etc/php/7.4/fpm/pool.d/www.conf

Change:

user = www-data
group = www-data

to:

user = geo
group = geo

also change:

listen.owner = www-data
listen.group = www-data

to:

listen.owner = geo
listen.group = geo
sudo nano /etc/php/7.4/fpm/php.ini

Change:

max_execution_time = 30

to:

max_execution_time = 6000

Then restart the services.

sudo service nginx stop
sudo service nginx start

sudo service php7.4-fpm stop
sudo service php7.4-fpm start