These instructions are based on getting the software up and running from scratch on a Debian Buster (10.9, stable as of 2021-05-16) system.
In the end the installed packages were as per the files:
A simple Debian install was performed in a VirtualBox VM to ensure no confounding factors. Only the bare minimum was installed, and then the following packages also installed:
apt install screen sudo git
A specific user was created:
useradd -c 'EDDN Gateway' -m -s /bin/bash eddn
Some additional Debian packages and python modules are required:
apt install python-pip virtualenv
You will need a mysql/mariab database:
apt install mariadb-server
mysqladmin create eddn
# Generate a secure password somehow, e.g.
dd if=/dev/urandom bs=512 count=1 | sha256sum
mysql mysql # Connect to the database as root
> CREATE USER IF NOT EXISTS 'eddn'@'localhost' IDENTIFIED BY ' SOME SECURE PASSWORD ';
> GRANT ALL PRIVILEGES on eddn.* TO 'eddn'@'localhost';
> \q
In order to get host performance metrics (CPU, RAM and network usage) you will need to install netdata. On Debian-based systems:
apt install netdata
The default configuration should be all you need, listening on
127.0.0.1:19999
.
We assume that you're using a TLS certificate from LetsEncrypt, it's free!
It will be necessary to renew the TLS certificate using certbot, or some alternative ACME client. We'll assume certbot.
On a Debian system simply:
apt install certbot
Although this version might be a little old now, it does work.
If you are taking over hosting the EDDN relay then hopefully you have access to the existing certificate files.
So, first copy those into place:
cd /etc/letsencrypt
mkdir -p archive/eddn.edcd.io
mkdir -p live/eddn.edcd.io
cd archive/eddn.edcd.io
cp <source for all *.pem files> .
chmod 644 *.pem
chmod 600 privkey*.pem
cd ../../live/eddn.edcd.io
# NB: You need to check what the *newest* file is. The `1` will be a
# greater number if the certificate has ever been renewed.
ln -s ../../archive/eddn.edcd.io/fullchain1.pem fullchain.pem
ln -s ../../archive/eddn.edcd.io/privkey1.pem privkey.pem
After this you need to ensure that the certificate stays renewed. With a Debian system using certbot:
-
There should already be a systemd timer set up:
systemctl status certbot.timer
If that doesn't show "
; enabled;
" in:Loaded: loaded (/lib/systemd/system/certbot.timer; enabled; vendor preset: enabled)
then:
systemctl enable certbot.timer
This will renew the certificate as necessary (i.e. when <= 30 days until it expires, or whatever current LetsEncrypt and certbot policy causes). But it will not ensure the files are in all the places you might need them to be.
-
Ensure the certificate files are deployed to where they're needed. When using the certbot timer the easiest thing to do is to utilise a script in
/etc/letsencrypt/renewal-hooks/deploy/
.There are example files for this in
contrib/letsencrypt/
:mkdir -p /etc/letsencrypt/renewal-hooks/deploy cp contrib/letsencrypt/deploy-changed-certs /etc/letsencrypt/renewal-hooks/deploy mkdir -p /etc/scripts cp contrib/letsencrypt/certbot-common /etc/scripts/
Remember to edit them to suit your setup!
There are multiple ports that you'll have to ensure are allowed through any firewall, and some of them also require being reverse proxied correctly.
The reverse proxies pertain to:
-
The port for the Gateway to receive uploads from senders (e.g. Elite Dangerous Market Connector). This is also used for the 'monitor' web page to obtain stats about messages passing through the Gateway.
-
A set of URLs for accessing netdata.
These all for TCP, no UDP:
-
443
- a web server capable of reverse proxying set up for TLS on the public host name of the EDDN service. This is used to serve the schemas, the monitor web page, and to reverse proxy URLs beginning/netdata/
to the netdata service. -
Default:
4430
- Gateway 'http' port, used both for EDDN senders to upload, and also for the Gateway message rate stats on the monitor web page.But that's the public port. The Gateway process itself listens on
8081
. So you'll need a reverse proxy listening on port4430
and forwarding all requests to127.0.0.1:8081
. -
Default:
9091
- Monitor 'http' port, used for the monitor web page to query schema and software statistics. No reverse proxy setup. -
Default:
9500
- The port on the Relay that EDDN listeners connect to in order to receive the zeromq stream. No reverse proxy setup. -
Default:
9090
- The Relay 'http' port for its portion of the message statistics on the monitor web page. No reverse proxy setup.
There's also the internal 8500
port, but that's literally only used for
the Monitor and Relay to pick up zeromq messages forwarded from the
Gateway, so all over localhost.
See Configuration for guidance on what override config settings can be used to change any of these ports.
If you already have an Apache installation it will be easier to just use it for the reverse proxy.
Ensure you have these modules installed and active:
a2enmod proxy proxy_http
There is an example VirtualHost configuration in
contrib/apache-eddn.conf
which makes the following assumptions:
- The usual Apache default configuration is in place elsewhere.
- The hostname being used -
ServerName
. - The location of the monitor files -
DocumentRoot
. - The location of the schema files -
Alias /schemas/ ...
. - The location of the TLS certificate files -
SSLCertificateFile
and `SSLCertificateKeyFile.
You should be able to:
-
Copy
contrib/apache-eddn.conf
into/etc/apache/sites-available/
as an appropriate filename for the hostname you're using. -
Edit to suit the local situation/setup. Remember to ensure the configured log directory exists.
-
Enable the site:
a2ensite <filename without trailing .conf> apache2ctl configtest # CHECK THE OUTPUT apache2ctl graceful
If you don't yet have nginx installed then start with:
apt install nginx-light
There is an example configuration in contrib/nginx-eddn.conf
which makes
some assumptions:
- That it will listen on the standard HTTP and HTTPS ports.
- The hostname being used -
server_name
directives. - The location of the monitor files -
root
directive. - The location of the schema files -
location
directive. - The location of the TLS certificate files -
ssl_certificate
andssl_certificate_key
directives.
You should be able to:
-
Copy
contrib/nginx-eddn.conf
into/etc/nginx/sites-available/eddn
. -
Edit to suit the local situation/setup.
-
Enable the site:
cd /etc/nginx/sites-enabled ln -s /etc/nginx/sites-available/eddn systemctl restart nginx.service
If you're already using another web server you'll need to duplicate at least the use of a TLS certificate and the Reverse Proxying as required.
We'll assume you're setting up a development environment so use dev
in the
path and some other configuration. The scripts currently support three
environments: live
, beta
and dev
.
mkdir -p ${HOME}/dev
cd ${HOME}/dev
git clone https://github.com/EDCD/EDDN.git EDDN.git
cd EDDN.git
We'll assume this ${HOME}/dev/EDDN.git
path elsewhere in this document.
So as to not have any python package version requirements clash with anything else it's best to use a Python virtual environment (venv). You will have installed the Debian package 'virtualenv' above for this purpose.
We'll put the venv in ${HOME}/dev/python2.7-venv
with the following
command:
cd ${HOME}/dev
virtualenv -p /usr/bin/python2.7 ${HOME}/dev/python2.7-venv
And for future ease of changing python versions:
ln -s python2.7-venv python-venv
And now start using this venv:
. python-venv/bin/activate
Installing extra necessary python modules is simple:
pip install -r requirements.txt
You will need to get the database schema in place:
mysql -p eddn < ${HOME}/eddn/dev/EDDN/schema.sql
<the password you set in the "CREATE USER" statement above>
Ref: As root.
There are three components to this application.
-
Gateway - this is where senders connect to upload messages. It performs schema validation and then passes the messages on to both the Monitor and the Relay (they connect and perform zeromq subscription). This requires port
4430
to make it past any firewall, NAT etc and to the Gateway process. However, the actual Gateway process listens on port8081
and the reverse proxy setup forwards port4430
traffic to this. -
Monitor - this gathers statistics about the messages, such as the sending software name and version. This requires port
9091
to make it past any firewall, NAT etc, and to the Monitor process. -
Relay - this is where listeners connect in order to be sent messages that have passed the schema and duplicate checks. This requires ports 9500 and
9090
to make it past any firewall, NAT etc, and to the Relay process.
There also port 8500
which is used purely over localhost for the communication
from the Gateway to the Relay and Monitor.
As the code currently (2021-05-16) stands it MUST run on a standalone host such that everything is served relative to the path root, not a path prefix.
See also the post-installation notes for some caveats about running this other than on the actual eddn.edcd.io host.
Default application configuration is in the file src/eddn/conf/Settings.py
.
Do not change anything in this file, see below about overriding using
another file.
-
You will need to obtain a TLS certificate from, e.g. LetsEncrypt. The application will need access to this and its private key file.
CERT_FILE = '/etc/letsencrypt/live/YOUROWN.eddn.edcd.io/fullchain.pem' KEY_FILE = '/etc/letsencrypt/live/YOUROWN.eddn.edcd.io/privkey.pem'
-
Network configuration
-
RELAY_HTTP_BIND_ADDRESS
andRELAY_HTTP_PORT
define the IP and port on which the Relay listens for, e.g./stats/
requests. -
RELAY_RECEIVER_BINDINGS
defines where the Relay connects in order to subscribe to messages from the Gateway. Should matchGATEWAY_SENDER_BINDINGS
. -
RELAY_SENDER_BINDINGS
defines the address the application listens on for connections from listeners such as eddb.io. -
RELAY_DUPLICATE_MAX_MINUTES
how many minutes to keep messages hashes cached for so as to detect, and not Relay out, duplicate messages. If you set this to the literal stringfalse
the duplication checks will be disabled. This is very handy when testing the code. -
GATEWAY_HTTP_BIND_ADDRESS
andGATEWAY_HTTP_PORT
define where the Gateway listens to for incoming messages from senders. Might be forwarded from nginx or other reverse proxy. -
GATEWAY_SENDER_BINDINGS
is where the Gateway listens for connections from the Relay and Monitor in order to send them messages that passed schema checks. -
GATEWAY_JSON_SCHEMAS
defines the schemas used for validation. Note that these are full public URLs which are served by your web server. -
GATEWAY_OUTDATED_SCHEMAS
any past schemas that are no longer valid. -
MONITOR_HTTP_BIND_ADDRESS
andMONITOR_HTTP_PORT
define where the Monitor listens to for web connections, e.g. the statistics page. -
MONITOR_RECEIVER_BINDINGS
defines where the Monitor connects in order to subscribe to messages from the Gateway. Should matchGATEWAY_SENDER_BINDINGS
. -
MONITOR_UA
appears to be unused.
-
-
Database Configuration
MONITOR_DB
- defines the necessary information for the application to connect to a mysql/mariadb database for storing stats.database
- the name of the databaseuser
- the user to connect aspassword
- the secure password you set above when installing and configuring mariadb/mysql.
It is assumed that the database is on
localhost
.
To change anything from the defaults create an override config file, which must be in valid JSON format (so no comments, no dangling commas etc). You can then pass this file to the application scripts, e.g.:
python Gateway.py --config some/other/configfile.json
You only need to define the settings that you need to change from defaults, e.g. certificate files and database credentials, without worrying about the basic setup.
There is an example of this in eddn-settings-overrides-EXAMPLE.json. It sets:
- The TLS CERT and KEY files.
- The gateway to listen on
0.0.0.0
rather than localhost (necessary when testing in a VM). - Configures the database connection and credentials.
- Turns off the relay duplicate check.
You have some choices for how to run the application components:
If you are just testing out code changes then you can choose to run
this application directly from the source using the script
systemd/start-eddn-service
. You'll need to run it as, e.g.
systemd/start-eddn-service dev gateway --from-source
When using --from-source
you can also supply a --background
argument to
put the process into the background with a .pid
file written in the logs
directory.
Check the systemd/eddn_<environment>_config
files for the location of
the logs directory.
Otherwise you will want to utilise the setup.py
file to build and
install the application files. You'll need to do some setup first as
there are necessary files not checked into git, because they're per
environment:
-
Change directory to the top level of the git clone.
-
Create a file
setup_env.py
with contents:EDDN_ENV="dev"
Replace
dev
with the environment you're setting up for. -
As we're using a python venv we can now just run:
python setup.py install
to install it all. This will install a python egg into the python venv, and then also ensure that the monitor and schema files are in place, along with support scripts.
There is an example systemd setup in
systemd
that assumes this local installation.There are also some SysV style init.d scripts in
contrib/init.d/
for running the components. They will need theDAEMON
lines tweaking for running from another location.
You should now have:
-
~/.local/bin
- with some scripts and per-environment config files:-
start-eddn-dev-service
- script that runs a specified EDDN service. This is intended to be used by the contrib systemd setup, but will work standalone as well. -
eddn-logs-archive
- script that potentially archives and expires existing archival logs for the specified environment.
-
-
~/.local/share/eddn/dev
- with the monitor and schema files, along with an example config override file if you didn't already have aconfig.json
here.
systemd/
contains two systemd unit files to enable starting the services
via system, including at boot time.
-
systemd/[email protected]
- a systemd template unit file that can be used to start/stop any of the EDDN services in the live environment. You would invoke it like:systemctl start [email protected]
-
systemd/eddn.target
- a system target until file which will start all of:
To get them working:
-
copy both files into
/etc/systemd/system/
. -
Enable the target and services: 1.
systemctl enable eddn.target
1.systemctl enable [email protected]
1.systemctl enable [email protected]
1.systemctl enable [email protected]
If you're not using the live
environment then there are some edits you
need to make.
All of the contrib/monitor
files have the hostname eddn.edcd.io
hard-coded. You will need to perform search and replace on the
installed/live files to use a test host. The files in question are:
monitor/js/eddn.js
monitor/schemas.html
Replace the string eddn.edcd.io
with the hostname you're using.
You'll need to perform similar substitutions if you change the
configuration to use any different port numbers.
There is an EDDN Status web page usually provided at, e.g.
https://eddn.edcd.io/. This is enabled by the Monitor component through
the combination of the contrib/monitor/
files and API endpoints provided
by the Monitor process itself.
You will need to configure a reverse proxy to actually enable access to this.
There is an example nginx configuration in contrib/nginx-eddn.conf
.
The necessary files should be put in place by
The 'monitor' files are what form the status/statistics page at https://eddn.edcd.io/, so they need to be installed somewhere in a static manner accessible to nginx.
Although setup.py installs the files you might still need to ensure the permissions are correct for your web server to access them.
chmod -R og+rX ${HOME} ${HOME}/.local ${HOME}/.local/share ${HOME}/.local/share/eddn
chmod -R og+rX ${HOME}/.local/share/eddn/schemas
In order to test all of this in a VM you might need to set up a double proxying:
Internet -> existing server -> VM -> nginx -> EDDN scripts
If using Apache on a Debian server then you need some ProxyPass directives:
<IfModule mod_proxy.c>
SSLProxyEngine On
SSLProxyVerify none
ProxyPreserveHost On
# Pass through 'gateway' upload URL to Debian VM
ProxyPass "/eddn/upload/" "https://VM_HOST:8081/upload/"
# Pass through 'monitor' URLs to Debian VM
ProxyPass "/eddn/" "https://VM_HOST/"
</IfModule>
This assumes you don't have a dedicated virtual host in this case, hence the "/eddn" prefix there. Remove that if you are using a dedicated virtual host on the 'existing server'.
You'll also need to redirect the Gateway and Relay ports using firewall rules. With iptables:
PUB_INT=<your public facing interface>
PRIV_INT=<internal interface if testing on internal network>
ANYWHERE="0.0.0.0/0" # Not strictly necessary, but it's good to be explicit
# The IP your host/VM can be reached on.
YOUR_EDDN_IP=...
# Port 4430 is for senders to the Gateway
iptables -t nat -A PREROUTING -i ${PUB_INT} -p tcp -s ${ANYWHERE} --dport 4430 -j DNAT --to-destination ${YOUR_EDDN_IP}
iptables -t nat -A PREROUTING -i ${PRIV_INT} -p tcp -s ${ANYWHERE} --dport 4430 -j DNAT --to-destination ${YOUR_EDDN_IP}
iptables -t nat -A OUTPUT -p tcp -s ${ANYWHERE} --dport 4430 -j DNAT --to-destination ${YOUR_EDDN_IP}
# Port 9500 is for listeners connecting to the Relay
iptables -t nat -A PREROUTING -i ${PUB_INT} -p tcp -s ${ANYWHERE} --dport 9500 -j DNAT --to-destination ${YOUR_EDDN_IP}
iptables -t nat -A PREROUTING -i ${PRIV_INT} -p tcp -s ${ANYWHERE} --dport 9500 -j DNAT --to-destination ${YOUR_EDDN_IP}
iptables -t nat -A OUTPUT -p tcp -s ${ANYWHERE} --dport 9500 -j DNAT --to-destination ${YOUR_EDDN_IP}
# Port 9090 is for the Relay web server, stats API
iptables -t nat -A PREROUTING -i ${PUB_INT} -p tcp -s ${ANYWHERE} --dport 9090 -j DNAT --to-destination ${YOUR_EDDN_IP}
iptables -t nat -A PREROUTING -i ${PRIV_INT} -p tcp -s ${ANYWHERE} --dport 9090 -j DNAT --to-destination ${YOUR_EDDN_IP}
iptables -t nat -A OUTPUT -p tcp -s ${ANYWHERE} --dport 9090 -j DNAT --to-destination ${YOUR_EDDN_IP}
# Port 9091 is for the Monitor web server, stats API
iptables -t nat -A PREROUTING -i ${PUB_INT} -p tcp -s ${ANYWHERE} --dport 9091 -j DNAT --to-destination ${YOUR_EDDN_IP}
iptables -t nat -A PREROUTING -i ${PRIV_INT} -p tcp -s ${ANYWHERE} --dport 9091 -j DNAT --to-destination ${YOUR_EDDN_IP}
iptables -t nat -A OUTPUT -p tcp -s ${ANYWHERE} --dport 9091 -j DNAT --to-destination ${YOUR_EDDN_IP}