2017-08-21 16:34:05 +00:00
# Installing Dendrite
Dendrite can be run in one of two configurations:
2020-05-14 15:49:18 +00:00
* **Monolith mode**: All components run in the same process. In this mode,
2022-01-05 17:44:49 +00:00
it is possible to run an in-process [NATS Server ](https://github.com/nats-io/nats-server )
instead of running a standalone deployment. This will usually be the preferred model for
low-to-mid volume deployments, providing the best balance between performance and resource usage.
* **Polylith mode**: A cluster of individual components running in their own processes, dealing
with different aspects of the Matrix protocol (see [WIRING.md ](WIRING-Current.md )). Components
communicate with each other using internal HTTP APIs and [NATS Server ](https://github.com/nats-io/nats-server ).
This will almost certainly be the preferred model for very large deployments but scalability
comes with a cost. API calls are expensive and therefore a polylith deployment may end up using
disproportionately more resources for a smaller number of users compared to a monolith deployment.
2020-05-14 15:49:18 +00:00
2022-01-05 17:44:49 +00:00
In almost all cases, it is **recommended to run in monolith mode with PostgreSQL databases** .
2020-10-26 22:09:13 +00:00
2020-07-14 11:58:00 +00:00
Regardless of whether you are running in polylith or monolith mode, each Dendrite component that
2022-01-05 17:44:49 +00:00
requires storage has its own database connections. Both Postgres and SQLite are supported and can
be mixed-and-matched across components as needed in the configuration file.
2020-05-14 15:49:18 +00:00
2020-07-14 11:58:00 +00:00
Be advised that Dendrite is still in development and it's not recommended for
use in production environments just yet!
2017-08-21 16:34:05 +00:00
## Requirements
2020-05-14 15:49:18 +00:00
Dendrite requires:
2021-08-03 10:35:29 +00:00
* Go 1.15 or higher
2022-01-05 17:44:49 +00:00
* PostgreSQL 12 or higher (if using PostgreSQL databases, not needed for SQLite)
2020-05-14 15:49:18 +00:00
If you want to run a polylith deployment, you also need:
2017-08-21 16:34:05 +00:00
2022-01-05 17:44:49 +00:00
* A standalone [NATS Server ](https://github.com/nats-io/nats-server ) deployment with JetStream enabled
2020-05-14 15:49:18 +00:00
2020-10-26 22:09:13 +00:00
## Building Dendrite
2020-05-14 15:49:18 +00:00
Start by cloning the code:
2017-08-21 16:34:05 +00:00
2020-05-14 15:49:18 +00:00
```bash
git clone https://github.com/matrix-org/dendrite
cd dendrite
```
Then build it:
```bash
2019-05-21 20:56:55 +00:00
./build.sh
2017-08-21 16:34:05 +00:00
```
2022-01-05 17:44:49 +00:00
## Install NATS Server
2017-08-21 16:34:05 +00:00
2022-01-05 17:44:49 +00:00
Follow the [NATS Server installation instructions ](https://docs.nats.io/running-a-nats-service/introduction/installation ) and then [start your NATS deployment ](https://docs.nats.io/running-a-nats-service/introduction/running ).
2018-03-09 10:12:29 +00:00
2022-01-05 17:44:49 +00:00
JetStream must be enabled, either by passing the `-js` flag to `nats-server` ,
or by specifying the `store_dir` option in the the `jetstream` configuration.
2018-03-09 10:12:29 +00:00
2017-08-21 16:34:05 +00:00
## Configuration
2020-10-26 22:09:13 +00:00
### PostgreSQL database setup
2017-08-21 16:34:05 +00:00
2022-01-05 17:44:49 +00:00
Assuming that PostgreSQL 12 (or later) is installed:
2020-05-14 15:49:18 +00:00
* Create role, choosing a new password when prompted:
2017-08-21 16:34:05 +00:00
```bash
2020-05-14 15:49:18 +00:00
sudo -u postgres createuser -P dendrite
2017-08-21 16:34:05 +00:00
```
2020-05-14 15:49:18 +00:00
2020-12-14 09:42:27 +00:00
At this point you have a choice on whether to run all of the Dendrite
components from a single database, or for each component to have its
own database. For most deployments, running from a single database will
be sufficient, although you may wish to separate them if you plan to
split out the databases across multiple machines in the future.
On macOS, omit `sudo -u postgres` from the below commands.
* If you want to run all Dendrite components from a single database:
```bash
sudo -u postgres createdb -O dendrite dendrite
```
... in which case your connection string will look like `postgres://user:pass@database/dendrite` .
* If you want to run each Dendrite component with its own database:
2020-05-14 15:49:18 +00:00
2017-08-21 16:34:05 +00:00
```bash
2022-01-05 17:44:49 +00:00
for i in mediaapi syncapi roomserver federationapi appservice keyserver userapi_accounts userapi_devices; do
2017-08-21 16:34:05 +00:00
sudo -u postgres createdb -O dendrite dendrite_$i
done
```
2020-12-14 09:42:27 +00:00
... in which case your connection string will look like `postgres://user:pass@database/dendrite_componentname` .
### SQLite database setup
**WARNING:** SQLite is suitable for small experimental deployments only and should not be used in production - use PostgreSQL instead for any user-facing federating installation!
Dendrite can use the built-in SQLite database engine for small setups.
The SQLite databases do not need to be pre-built - Dendrite will
create them automatically at startup.
2018-03-02 14:33:49 +00:00
2020-05-14 15:49:18 +00:00
### Server key generation
2017-08-21 16:34:05 +00:00
2020-10-26 22:09:13 +00:00
Each Dendrite installation requires:
2020-12-14 09:42:27 +00:00
* A unique Matrix signing private key
* A valid and trusted TLS certificate and private key
2020-10-26 22:09:13 +00:00
To generate a Matrix signing private key:
```bash
./bin/generate-keys --private-key matrix_key.pem
```
2020-12-14 09:42:27 +00:00
**WARNING:** Make sure take a safe backup of this key! You will likely need it if you want to reinstall Dendrite, or
2020-10-26 22:09:13 +00:00
any other Matrix homeserver, on the same domain name in the future. If you lose this key, you may have trouble joining
federated rooms.
2020-05-14 15:49:18 +00:00
2020-10-26 22:09:13 +00:00
For testing, you can generate a self-signed certificate and key, although this will not work for public federation:
2017-08-21 16:34:05 +00:00
```bash
2020-10-26 22:09:13 +00:00
./bin/generate-keys --tls-cert server.crt --tls-key server.key
2017-08-21 16:34:05 +00:00
```
2020-12-14 09:42:27 +00:00
If you have server keys from an older Synapse instance,
[convert them ](serverkeyformat.md#converting-synapse-keys ) to Dendrite's PEM
2020-10-22 11:21:31 +00:00
format and configure them as `old_private_keys` in your config.
2020-05-14 15:49:18 +00:00
### Configuration file
2017-08-21 16:34:05 +00:00
Create config file, based on `dendrite-config.yaml` . Call it `dendrite.yaml` . Things that will need editing include *at least* :
2020-05-14 15:49:18 +00:00
* The `server_name` entry to reflect the hostname of your Dendrite server
* The `database` lines with an updated connection string based on your
2020-10-20 10:22:46 +00:00
desired setup, e.g. replacing `database` with the name of the database:
2020-12-14 09:42:27 +00:00
* For Postgres: `postgres://dendrite:password@localhost/database` , e.g.
* `postgres://dendrite:password@localhost/dendrite_userapi_account` to connect to PostgreSQL with SSL/TLS
* `postgres://dendrite:password@localhost/dendrite_userapi_account?sslmode=disable` to connect to PostgreSQL without SSL/TLS
2020-10-26 22:09:13 +00:00
* For SQLite on disk: `file:component.db` or `file:///path/to/component.db` , e.g. `file:userapi_account.db`
* Postgres and SQLite can be mixed and matched on different components as desired.
2022-01-05 17:44:49 +00:00
* Either one of the following in the `jetstream` configuration section:
* The `addresses` option — a list of one or more addresses of an external standalone
NATS Server deployment
* The `storage_path` — where on the filesystem the built-in NATS server should
store durable queues, if using the built-in NATS server
2020-05-14 15:49:18 +00:00
There are other options which may be useful so review them all. In particular,
if you are trying to federate from your Dendrite instance into public rooms
then configuring `key_perspectives` (like `matrix.org` in the sample) can
help to improve reliability considerably by allowing your homeserver to fetch
public keys for dead homeservers from somewhere else.
2017-08-21 16:34:05 +00:00
2020-10-20 10:22:46 +00:00
**WARNING:** Dendrite supports running all components from the same database in
2020-10-26 22:09:13 +00:00
PostgreSQL mode, but this is **NOT** a supported configuration with SQLite. When
2020-10-20 10:22:46 +00:00
using SQLite, all components **MUST** use their own database file.
2017-08-21 16:34:05 +00:00
## Starting a monolith server
2017-08-22 10:01:14 +00:00
The monolith server can be started as shown below. By default it listens for
2020-05-14 15:49:18 +00:00
HTTP connections on port 8008, so you can configure your Matrix client to use
2020-10-26 22:09:13 +00:00
`http://servername:8008` as the server:
```bash
./bin/dendrite-monolith-server
```
If you set `--tls-cert` and `--tls-key` as shown below, it will also listen
for HTTPS connections on port 8448:
2017-08-22 10:01:14 +00:00
```bash
./bin/dendrite-monolith-server --tls-cert=server.crt --tls-key=server.key
```
2017-08-21 16:34:05 +00:00
2022-01-05 17:44:49 +00:00
If the `jetstream` section of the configuration contains no `addresses` but does
contain a `store_dir` , Dendrite will start up a built-in NATS JetStream node
automatically, eliminating the need to run a separate NATS server.
2020-05-14 15:49:18 +00:00
## Starting a polylith deployment
2017-08-21 16:34:05 +00:00
2020-07-14 11:58:00 +00:00
The following contains scripts which will run all the required processes in order to point a Matrix client at Dendrite.
2017-08-21 16:34:05 +00:00
2020-10-20 10:22:46 +00:00
### nginx (or other reverse proxy)
2017-08-21 16:34:05 +00:00
2020-10-20 10:22:46 +00:00
This is what your clients and federated hosts will talk to. It must forward
requests onto the correct API server based on URL:
2017-08-21 16:34:05 +00:00
2020-10-20 10:22:46 +00:00
* `/_matrix/client` to the client API server
* `/_matrix/federation` to the federation API server
* `/_matrix/key` to the federation API server
* `/_matrix/media` to the media API server
2017-08-21 16:34:05 +00:00
2020-10-20 10:22:46 +00:00
See `docs/nginx/polylith-sample.conf` for a sample configuration.
2017-08-21 16:34:05 +00:00
2020-05-14 15:49:18 +00:00
### Client API server
2017-08-21 16:34:05 +00:00
2020-07-14 11:58:00 +00:00
This is what implements CS API endpoints. Clients talk to this via the proxy in
order to send messages, create and join rooms, etc.
2020-05-14 15:49:18 +00:00
```bash
2020-10-20 15:11:24 +00:00
./bin/dendrite-polylith-multi --config=dendrite.yaml clientapi
2020-05-14 15:49:18 +00:00
```
### Sync server
2017-08-21 16:34:05 +00:00
2020-05-14 15:49:18 +00:00
This is what implements `/sync` requests. Clients talk to this via the proxy
in order to receive messages.
2017-08-21 16:34:05 +00:00
```bash
2020-10-20 15:11:24 +00:00
./bin/dendrite-polylith-multi --config=dendrite.yaml syncapi
2017-08-21 16:34:05 +00:00
```
2020-05-14 15:49:18 +00:00
### Media server
2017-08-21 16:34:05 +00:00
2020-05-14 15:49:18 +00:00
This implements `/media` requests. Clients talk to this via the proxy in
order to upload and retrieve media.
2017-08-21 16:34:05 +00:00
```bash
2020-10-20 15:11:24 +00:00
./bin/dendrite-polylith-multi --config=dendrite.yaml mediaapi
2017-08-21 16:34:05 +00:00
```
2017-09-25 10:20:36 +00:00
2020-05-14 15:49:18 +00:00
### Federation API server
2017-09-25 10:20:36 +00:00
2020-07-14 11:58:00 +00:00
This implements the federation API. Servers talk to this via the proxy in
2017-09-25 10:20:36 +00:00
order to send transactions. This is only required if you want to support
federation.
```bash
2020-10-20 15:11:24 +00:00
./bin/dendrite-polylith-multi --config=dendrite.yaml federationapi
2017-09-25 10:20:36 +00:00
```
2020-07-14 11:58:00 +00:00
### Internal components
This refers to components that are not directly spoken to by clients. They are only
contacted by other components. This includes the following components.
#### Room server
This is what implements the room DAG. Clients do not talk to this.
```bash
2020-10-20 15:11:24 +00:00
./bin/dendrite-polylith-multi --config=dendrite.yaml roomserver
2020-07-14 11:58:00 +00:00
```
#### Appservice server
2018-07-05 16:34:59 +00:00
This sends events from the network to [application
services](https://matrix.org/docs/spec/application_service/unstable.html)
running locally. This is only required if you want to support running
application services on your homeserver.
```bash
2020-10-20 15:11:24 +00:00
./bin/dendrite-polylith-multi --config=dendrite.yaml appservice
2018-07-05 16:34:59 +00:00
```
2020-05-14 15:49:18 +00:00
2020-07-14 11:58:00 +00:00
#### Key server
2020-05-14 15:49:18 +00:00
2020-07-14 11:58:00 +00:00
This manages end-to-end encryption keys for users.
2020-05-14 15:49:18 +00:00
```bash
2020-10-20 15:11:24 +00:00
./bin/dendrite-polylith-multi --config=dendrite.yaml keyserver
2020-05-14 15:49:18 +00:00
```
2020-06-19 08:37:19 +00:00
2020-07-14 11:58:00 +00:00
#### EDU server
This manages processing EDUs such as typing, send-to-device events and presence. Clients do not talk to
```bash
2020-10-20 15:11:24 +00:00
./bin/dendrite-polylith-multi --config=dendrite.yaml eduserver
2020-07-14 11:58:00 +00:00
```
#### User server
2020-06-19 08:37:19 +00:00
This manages user accounts, device access tokens and user account data,
amongst other things.
```bash
2020-10-20 15:11:24 +00:00
./bin/dendrite-polylith-multi --config=dendrite.yaml userapi
2020-06-19 08:37:19 +00:00
```