Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monolithic mode for the docker image #282

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ RUN apk --update --no-cache add \
python3 \
py3-pip \
rrdtool \
rrdtool-cached \
runit \
shadow \
syslog-ng=3.30.1-r4 \
Expand Down Expand Up @@ -109,7 +110,7 @@ RUN apk --update --no-cache add -t build-dependencies \
linux-headers \
musl-dev \
python3-dev \
&& git clone --branch ${LIBRENMS_VERSION} https://github.com/librenms/librenms.git . \
&& git clone --depth 1 --branch ${LIBRENMS_VERSION} https://github.com/librenms/librenms.git . \
&& pip3 install --ignore-installed -r requirements.txt --upgrade \
&& COMPOSER_CACHE_DIR="/tmp" composer install --no-dev --no-interaction --no-ansi \
&& mkdir config.d \
Expand All @@ -129,7 +130,7 @@ RUN apk --update --no-cache add -t build-dependencies \

COPY rootfs /

EXPOSE 8000 514 514/udp 162 162/udp
EXPOSE 8000 42217 514 514/udp 162 162/udp
VOLUME [ "/data" ]

ENTRYPOINT [ "/init" ]
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,22 @@ If you are interested, [check out](https://hub.docker.com/r/crazymax/) my other
* [Dispatcher service](doc/docker/environment-variables.md#dispatcher-service) as "sidecar" container
* Syslog-ng support through a ["sidecar" container](doc/docker/environment-variables.md#syslog-ng)
* Snmp-trap support through a ["sidecar" container](doc/docker/environment-variables.md#snmptrapd)
* Sidecar modular service mode or monolitic mode
* Built-in LibreNMS [Weathermap plugin](https://docs.librenms.org/Extensions/Weathermap/)
* Ability to add custom Monitoring plugins
* Ability to add custom alert templates
* OPCache enabled to store precompiled script bytecode in shared memory
* [s6-overlay](https://github.com/just-containers/s6-overlay/) as process supervisor
* [Traefik](https://github.com/containous/traefik-library-image) as reverse proxy and creation/renewal of Let's Encrypt certificates (see [this template](examples/traefik))
* [Memcached](https://github.com/docker-library/memcached) image ready to use for better scalability
* [RRDcached](https://github.com/crazy-max/docker-rrdcached) image ready to use for data caching and graphs
* [Redis](https://github.com/docker-library/redis) image ready to use for better scalability
* [RRDcached](https://github.com/crazy-max/docker-rrdcached) Either by sidecar or external image for data caching and graphs
* [msmtpd SMTP relay](https://github.com/crazy-max/docker-msmtpd) image to send emails
* [MariaDB](https://github.com/docker-library/mariadb) image as database instance

## Docker Compose Recipes

Visit the [usage documentation](doc/usage.md) and run the stand-alone docker compose.

## Build locally

```shell
Expand Down
25 changes: 16 additions & 9 deletions doc/docker/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
* `REAL_IP_FROM`: Trusted addresses that are known to send correct replacement addresses (default `0.0.0.0/32`)
* `REAL_IP_HEADER`: Request header field whose value will be used to replace the client address (default `X-Forwarded-For`)
* `LOG_IP_VAR`: Use another variable to retrieve the remote IP address for access [log_format](http://nginx.org/en/docs/http/ngx_http_log_module.html#log_format) on Nginx. (default `remote_addr`)
* `REDIS_HOST`: Redis host for poller synchronization
* `REDIS_SENTINEL`: Redis Sentinel host for high availability Redis cluster
* `REDIS_SENTINEL_SERVICE`: Redis Sentinel service name (default `librenms`)
* `REDIS_SCHEME`: Redis scheme (default `tcp`)
* `REDIS_PORT`: Redis port (default `6379`)
* `REDIS_PASSWORD`: Redis password
* `REDIS_DB`: Redis database (default `0`)
* `REDIS_CACHE_DB`: Redis cache database (default `1`)
* `SESSION_DRIVER`: [Driver to use for session storage](https://github.com/librenms/librenms/blob/master/config/session.php) (default `file`)
* `CACHE_DRIVER`: [Driver to use for cache and locks](https://github.com/librenms/librenms/blob/master/config/cache.php) (default `database`)

### Dispatcher service

Expand All @@ -21,13 +31,6 @@
* `SIDECAR_DISPATCHER`: Set to `1` to enable sidecar dispatcher mode for this container (default `0`)
* `DISPATCHER_NODE_ID`: Unique node ID for your dispatcher service
* `DISPATCHER_ARGS`: Additional args to pass to the [dispatcher service](https://github.com/librenms/librenms/blob/master/librenms-service.py)
* `REDIS_HOST`: Redis host for poller synchronization
* `REDIS_SENTINEL`: Redis Sentinel host for high availability Redis cluster
* `REDIS_SENTINEL_SERVICE`: Redis Sentinel service name (default `librenms`)
* `REDIS_SCHEME`: Redis scheme (default `tcp`)
* `REDIS_PORT`: Redis port (default `6379`)
* `REDIS_PASSWORD`: Redis password
* `REDIS_DB`: Redis database (default `0`)

### Syslog-ng

Expand Down Expand Up @@ -65,6 +68,10 @@
* `LIBRENMS_SNMP_COMMUNITY`: This container's SNMP v2c community string (default `librenmsdocker`)
* `LIBRENMS_WEATHERMAP`: Enable LibreNMS [Weathermap plugin](https://docs.librenms.org/Extensions/Weathermap/) (default `false`)
* `LIBRENMS_WEATHERMAP_SCHEDULE`: CRON expression format (default `*/5 * * * *`)
* `MEMCACHED_HOST`: Hostname / IP address of a Memcached server
* `MEMCACHED_PORT`: Port of the Memcached server (default `11211`)
* `RRDCACHED_SERVER`: RRDcached server (eg. `rrdcached:42217`)

### Additional

LibreNMS supports most environment variables provided by Laravel (the framework LibreNMS is built on top of).

Check the [Laravel docs](https://laravel.com/docs) for additonal variables.
45 changes: 39 additions & 6 deletions doc/usage.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,62 @@
## Use this image
# Use this image

### Docker Compose
## Docker Compose

Docker compose is the recommended way to run this image. Copy the content of folder [examples/compose](../examples/compose) in `/var/librenms/` on your host for example. Edit the compose and env files with your preferences and run the following commands:
Docker compose is the recommended way to run this image.

```bash
### Modular sidecar layout

Copy the contents of the examples folder [examples/compose](../examples/compose) to your host.
Edit the compose and env files with your preferences and run the following commands:
You should carefully review the Docker compose file and edit it to suit your needs.

```shell
docker-compose up -d
docker-compose logs -f
```

### Command line
### Stand-alone layout

Install mariadb and librenms as two containers listening on port 8000.
This uses pwgen to generate a random mysql password, alternatively, you may just enter a password.

```shell
wget https://raw.githubusercontent.com/librenms/docker/master/examples/monolithic/docker-compose.yml
MYSQL_PASSWORD="`pwgen -Bs1 12`" docker-compose up -d
docker-compose logs -f
```

### Stand-alone layout with HTTPS

Use Traefik to generate a letsencrypt ssl certificate and redirect to https. Uses pwgen.

```shell
wget https://raw.githubusercontent.com/librenms/docker/master/examples/compose/docker-compose-monolithic-https.yml

MYSQL_PASSWORD="`pwgen -Bs1 12`" \
LETSENCRYPT_EMAIL="[email protected]" \
LIBRENMS_BASE_URL="public-dns.example.com" \
docker-compose -f docker-compose-monolithic-https.yml up -d

docker-compose logs -f
```

## Command line

You can also use the following minimal command :

```bash
docker run -d -p 8000:8000 --name librenms \
-v $(pwd)/data:/data \
-e "DB_HOST=db" \
-e "MONOLITHIC=1" \
librenms/librenms:latest
```

> `-e "DB_HOST=db"`<br />
> :warning: `db` must be a running MySQL instance

### First launch
## First launch

On first launch, an initial administrator user will be created:

Expand Down
38 changes: 30 additions & 8 deletions examples/compose/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ services:
- "MYSQL_PASSWORD=${MYSQL_PASSWORD}"
restart: always

memcached:
image: memcached:alpine
container_name: librenms_memcached
environment:
- "TZ=${TZ}"
restart: always

redis:
image: redis:5.0-alpine
container_name: librenms_redis
Expand Down Expand Up @@ -54,7 +47,6 @@ services:
protocol: tcp
depends_on:
- db
- memcached
- msmtpd
volumes:
- "./librenms:/data"
Expand All @@ -69,9 +61,13 @@ services:
- "DB_USER=${MYSQL_USER}"
- "DB_PASSWORD=${MYSQL_PASSWORD}"
- "DB_TIMEOUT=60"
- "RRDCACHED_SERVER=rrdcached:42217"
- "REDIS_HOST=redis"
- "REDIS_PORT=6379"
- "REDIS_DB=0"
- "REDIS_CACHE_DB=1"
- "CACHE_DRIVER=redis"
- "SESSION_DRIVER=redis"
restart: always

dispatcher:
Expand All @@ -97,6 +93,7 @@ services:
- "DB_USER=${MYSQL_USER}"
- "DB_PASSWORD=${MYSQL_PASSWORD}"
- "DB_TIMEOUT=60"
- "RRDCACHED_SERVER=rrdcached:42217"
- "DISPATCHER_NODE_ID=dispatcher1"
- "REDIS_HOST=redis"
- "REDIS_PORT=6379"
Expand Down Expand Up @@ -170,3 +167,28 @@ services:
- "DB_TIMEOUT=60"
- "SIDECAR_SNMPTRAPD=1"
restart: always

rrdcached:
image: librenms/librenms:latest
container_name: librenms_rrdcached
hostname: librenms-rrdcached
cap_add:
- NET_ADMIN
- NET_RAW
depends_on:
- librenms
ports:
- target: 42217
published: 42217
protocol: tcp
volumes:
- "./librenms:/data"
env_file:
- "./librenms.env"
environment:
- "TZ=${TZ}"
- "PUID=${PUID}"
- "PGID=${PGID}"
- "SIDECAR_RRDCACHED=1"
- "RRDCACHED_SERVER=rrdcached:42217"
restart: always
4 changes: 1 addition & 3 deletions examples/compose/librenms.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ REAL_IP_HEADER=X-Forwarded-For
LOG_IP_VAR=remote_addr

LIBRENMS_SNMP_COMMUNITY=librenmsdocker
MEMCACHED_HOST=memcached
MEMCACHED_PORT=11211

LIBRENMS_WEATHERMAP=false
LIBRENMS_WEATHERMAP_SCHEDULE=*/5 * * * *
LIBRENMS_WEATHERMAP_SCHEDULE="*/5 * * * *"
88 changes: 88 additions & 0 deletions examples/monolithic/docker-compose-monolithic-https.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
version: "3.5"

services:
db:
image: mariadb:10.7
container_name: librenms_db
restart: always
command:
- "mysqld"
- "--innodb-file-per-table=1"
- "--lower-case-table-names=0"
- "--character-set-server=utf8mb4"
- "--collation-server=utf8mb4_unicode_ci"
volumes:
- "./db:/var/lib/mysql"
environment:
- "TZ=${TZ}"
- "MYSQL_ALLOW_EMPTY_PASSWORD=yes"
- "MYSQL_DATABASE=librenms"
- "MYSQL_USER=librenms"
- "MYSQL_PASSWORD=${MYSQL_PASSWORD}"

# simple static Traefik config, you may want to use the docker provider and labels instead
traefik:
image: traefik:2.8 # please check version tag to use the most current version
restart: unless-stopped
volumes:
- ./letsencrypt/:/letsencrypt/ # TLS certificate storage
ports:
- "80:80"
- "443:443"
command:
- "--entryPoints.web.address=:80"
- "--entryPoints.websecure.address=:443"
- "--certificatesresolvers.letsencryptresolver.acme.tlschallenge=true"
- "--certificatesresolvers.letsencryptresolver.acme.tlschallenge.entrypoint=websecure"
- "--certificatesresolvers.letsencryptresolver.acme.email=$LETSENCRYPT_EMAIL"
- "--certificatesresolvers.letsencryptresolver.acme.storage=/letsencrypt/acme.json"
- "--certificatesresolvers.letsencryptresolver.acme.caserver: https://acme-staging-v02.api.letsencrypt.org/directory" # Use staging server first
- "--http.routers.http-catchall.entrypoints=web"
- "--http.routers.http-catchall.rule=HostRegexp(`{host:.+}`)"
- "--http.routers.http-catchall.middlewares=redirect-to-https"
- "--http.middlewares.redirect-to-https.redirectscheme.scheme=https"
- "--http.routers.librenms.entrypoints=websecure"
- "--http.routers.librenms.tls.certresolver=letsencryptresolver"
- "--http.routers.librenms.rule=Host(`$LIBRENMS_BASE_URL`)"
- "--http.routers.librenms.service=librenms"

librenms:
image: librenms/librenms:latest
container_name: librenms
hostname: librenms
restart: always
cap_add:
- NET_ADMIN
- NET_RAW
ports:
- target: 8000
published: 8000
protocol: tcp
- target: 162
published: 162
protocol: tcp
- target: 162
published: 162
protocol: udp
- target: 514
published: 514
protocol: tcp
- target: 514
published: 514
protocol: udp
depends_on:
- db
volumes:
- "./librenms:/data"
environment:
- "MONOLITHIC=1"
- "TZ=${TZ}"
- "PUID=${PUID}"
- "PGID=${PGID}"
- "DB_HOST=db"
- "DB_NAME=librenms"
- "DB_USER=librenms"
- "DB_PASSWORD=${MYSQL_PASSWORD}"
- "DB_TIMEOUT=60"


60 changes: 60 additions & 0 deletions examples/monolithic/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
version: "3.5"

services:
db:
image: mariadb:10.7
container_name: librenms_db
command:
- "mysqld"
- "--innodb-file-per-table=1"
- "--lower-case-table-names=0"
- "--character-set-server=utf8mb4"
- "--collation-server=utf8mb4_unicode_ci"
volumes:
- "./db:/var/lib/mysql"
environment:
- "TZ=${TZ}"
- "MYSQL_ALLOW_EMPTY_PASSWORD=yes"
- "MYSQL_DATABASE=librenms"
- "MYSQL_USER=librenms"
- "MYSQL_PASSWORD=${MYSQL_PASSWORD}"
restart: always

librenms:
image: librenms/librenms:latest
container_name: librenms
hostname: librenms
cap_add:
- NET_ADMIN
- NET_RAW
ports:
- target: 8000
published: 8000
protocol: tcp
- target: 162
published: 162
protocol: tcp
- target: 162
published: 162
protocol: udp
- target: 514
published: 514
protocol: tcp
- target: 514
published: 514
protocol: udp
depends_on:
- db
volumes:
- "./librenms:/data"
environment:
- "MONOLITHIC=1"
- "TZ=${TZ}"
- "PUID=${PUID}"
- "PGID=${PGID}"
- "DB_HOST=db"
- "DB_NAME=librenms"
- "DB_USER=librenms"
- "DB_PASSWORD=${MYSQL_PASSWORD}"
- "DB_TIMEOUT=60"
restart: always
Loading