Add systemd services and single-server deployment examples
This commit is contained in:
1 parent
c20c41b2cd
commit
57e991ea2a
10 files changed
+306
-62
No files matched your search
@@ -0,0 +1,175 @@
|
||||
# Install Coulobre Panel on one server
|
||||
|
||||
This setup runs the panel, its Celery worker and scheduler, MariaDB, RabbitMQ,
|
||||
and Apache on one Ubuntu server. Use Ubuntu 24.04 or later. Apache serves the
|
||||
panel and its static files and connects to Gunicorn over a Unix socket.
|
||||
|
||||
## Install the package and configure local services
|
||||
|
||||
Run these commands from a Coulobre checkout on the server.
|
||||
|
||||
```sh
|
||||
sudo apt install apache2 mariadb-server rabbitmq-server python3-venv python3-dev \
|
||||
build-essential pkg-config default-libmysqlclient-dev
|
||||
sudo useradd --system --user-group --no-create-home --home-dir /nonexistent \
|
||||
--shell /usr/sbin/nologin coulobre-panel
|
||||
sudo python3 -m venv /opt/coulobre
|
||||
sudo /opt/coulobre/bin/pip install '.[server,mariadb]'
|
||||
|
||||
sudo install -d -m 0750 /etc/coulobre
|
||||
sudo install -d -o coulobre-panel -g coulobre-panel -m 0755 /var/www/coulobre-panel-static
|
||||
if ! sudo test -e /etc/coulobre/panel.env; then
|
||||
sudo install -m 0600 deploy/panel.env.example /etc/coulobre/panel.env
|
||||
fi
|
||||
```
|
||||
|
||||
Generate separate random values for the Django secret key, the database
|
||||
password, and the broker password. Use this command for each value.
|
||||
|
||||
```sh
|
||||
python3 -c 'import secrets; print(secrets.token_urlsafe(48))'
|
||||
```
|
||||
|
||||
Start MariaDB and RabbitMQ. In `sudo mariadb`, create the panel database and
|
||||
login. Substitute the generated database password.
|
||||
|
||||
```sh
|
||||
sudo systemctl enable --now mariadb rabbitmq-server
|
||||
```
|
||||
|
||||
```sql
|
||||
CREATE DATABASE coulobre_panel CHARACTER SET utf8mb4;
|
||||
CREATE USER 'coulobre'@'localhost' IDENTIFIED BY 'replace-with-database-password';
|
||||
GRANT ALL PRIVILEGES ON coulobre_panel.* TO 'coulobre'@'localhost';
|
||||
```
|
||||
|
||||
Create a dedicated RabbitMQ virtual host and login. Enter the generated broker
|
||||
password when prompted by `rabbitmqctl add_user`.
|
||||
|
||||
```sh
|
||||
sudo rabbitmqctl add_vhost coulobre
|
||||
sudo rabbitmqctl add_user coulobre
|
||||
sudo rabbitmqctl set_permissions -p coulobre coulobre '.*' '.*' '.*'
|
||||
```
|
||||
|
||||
Set `listeners.tcp.1 = 127.0.0.1:5672` in `/etc/rabbitmq/rabbitmq.conf` and
|
||||
restart RabbitMQ to bind its AMQP listener to loopback. Keep MariaDB and
|
||||
RabbitMQ management and cluster ports private. [RabbitMQ listener settings](https://www.rabbitmq.com/docs/networking#listeners)
|
||||
|
||||
Edit `/etc/coulobre/panel.env` with `sudoedit`. Set `COULOBRE_ALLOWED_HOSTS`
|
||||
to the hostname browsers will use, enter the Django secret and the database
|
||||
password, and place the broker password after `coulobre:` in
|
||||
`COULOBRE_BROKER_URL`. The sample connects to MariaDB through its local Unix
|
||||
socket and uses the dedicated RabbitMQ virtual host.
|
||||
|
||||
## Prepare the panel
|
||||
|
||||
Run the Django management commands as the service user with the same
|
||||
environment the systemd services will use.
|
||||
|
||||
```sh
|
||||
panel_manage() {
|
||||
sudo systemd-run --quiet --wait --pipe --collect --uid=coulobre-panel \
|
||||
--property=EnvironmentFile=/etc/coulobre/panel.env \
|
||||
/opt/coulobre/bin/python -m django "$@"
|
||||
}
|
||||
|
||||
panel_manage check --deploy
|
||||
panel_manage migrate --noinput
|
||||
panel_manage collectstatic --noinput
|
||||
|
||||
sudo systemd-run --quiet --pty --collect --uid=coulobre-panel \
|
||||
--property=EnvironmentFile=/etc/coulobre/panel.env \
|
||||
/opt/coulobre/bin/python -m django createsuperuser
|
||||
```
|
||||
|
||||
HTTPS proxy mode enables HSTS for the panel hostname. Django reports `W005`
|
||||
and `W021` for the optional subdomain and browser preload settings.
|
||||
|
||||
## Configure Apache and DNS
|
||||
|
||||
Install the shared Apache directives and enable the modules for your setup.
|
||||
Replace the example hostname in the chosen virtual host with the hostname
|
||||
from `COULOBRE_ALLOWED_HOSTS`.
|
||||
|
||||
```sh
|
||||
sudo install -m 0644 deploy/apache/panel-proxy.inc /etc/coulobre/panel-proxy.inc
|
||||
sudo a2enmod headers proxy proxy_http
|
||||
```
|
||||
|
||||
### Public server
|
||||
|
||||
Publish A or AAAA records for the IPv4 and IPv6 addresses that can reach the
|
||||
panel. Allow TCP ports 80 and 443 at the firewall. If the server is behind NAT,
|
||||
use the router's public address in DNS and forward those ports to Apache.
|
||||
Install the TLS virtual host, enable `mod_ssl`, and set the certificate and key
|
||||
paths for the panel hostname.
|
||||
|
||||
```sh
|
||||
sudo a2enmod ssl
|
||||
sudo install -m 0644 deploy/apache/panel-tls.conf.example \
|
||||
/etc/apache2/sites-available/coulobre-panel.conf
|
||||
```
|
||||
|
||||
### LAN only
|
||||
|
||||
Use the same TLS virtual host with a hostname that internal DNS resolves to the
|
||||
server's private address. Use a certificate that clients on the LAN trust, such
|
||||
as one issued by your internal CA. Limit access to the panel's HTTP and HTTPS
|
||||
ports to your private network. On a host with public and private web traffic,
|
||||
use the private address in the panel's virtual hosts in place of `*`.
|
||||
|
||||
### External reverse proxy
|
||||
|
||||
Point the public DNS records at the reverse proxy. Configure it to redirect
|
||||
HTTP to HTTPS, preserve the requested hostname when forwarding, and replace
|
||||
`X-Forwarded-For` with the client address. The origin example uses HTTP on a
|
||||
private network. Use a TLS connection to Apache if the upstream connection
|
||||
crosses an untrusted network.
|
||||
|
||||
```sh
|
||||
sudo a2enmod remoteip
|
||||
sudo install -m 0644 deploy/apache/panel-origin.conf.example \
|
||||
/etc/apache2/sites-available/coulobre-panel.conf
|
||||
```
|
||||
|
||||
Set `192.168.10.20` to the private listener address on the Apache host and
|
||||
`192.168.10.10` to the network peer address of your reverse proxy. Use the
|
||||
proxy address in both `RemoteIPInternalProxy` and the `CONN_REMOTE_ADDR`
|
||||
access rule. Restrict the origin port to the proxy at the firewall too. The
|
||||
rule checks the peer connection, so it still applies when Apache recognizes a
|
||||
different visitor IP from the trusted proxy.
|
||||
[Apache client IP handling](https://httpd.apache.org/docs/2.4/mod/mod_remoteip.html)
|
||||
|
||||
Each virtual host sends its HTTPS indicator to Gunicorn itself. The TLS
|
||||
virtual host handles HTTPS at Apache, while the private origin is reserved
|
||||
for the external proxy's HTTPS traffic. Apache passes a single visitor IP
|
||||
based on the connection or a trusted proxy. [Django HTTPS proxy settings](https://docs.djangoproject.com/en/5.2/ref/settings/#secure-proxy-ssl-header)
|
||||
|
||||
The addresses for hosted sites, mail, and authoritative DNS can differ from
|
||||
the panel hostname. Configure the corresponding public DNS records for each
|
||||
service using its reachable address.
|
||||
|
||||
## Start the services
|
||||
|
||||
Install and enable the three units. The panel's socket directory is available
|
||||
to Apache workers. The scheduler stores its state in a private directory and
|
||||
there is one scheduler for the installation.
|
||||
|
||||
```sh
|
||||
sudo install -m 0644 deploy/systemd/*.service /etc/systemd/system/
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable --now coulobre-panel.service coulobre-worker.service coulobre-beat.service
|
||||
|
||||
sudo a2ensite coulobre-panel
|
||||
sudo apache2ctl configtest
|
||||
sudo systemctl reload apache2
|
||||
```
|
||||
|
||||
Sign in with the administrator account. Add a hosting account and request an
|
||||
Apache preview to verify that RabbitMQ, the scheduler, and the worker are
|
||||
connected. Follow their logs with `journalctl`.
|
||||
|
||||
```sh
|
||||
sudo journalctl -u coulobre-panel -u coulobre-worker -u coulobre-beat
|
||||
```
|
||||
Reference in new issue
Block a user