-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65bd687
commit b1d51bc
Showing
13 changed files
with
183 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,45 +19,46 @@ | |
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
# | ||
# pgsql13-barman-centos8 | ||
# pgsql13-pgmoneta-centos8 | ||
FROM centos:centos8 | ||
|
||
LABEL maintainer="Jesper Pedersen <[email protected]>" | ||
|
||
LABEL summary="PostgreSQL 13 Barman" \ | ||
description="PostgreSQL 13 Barman" | ||
LABEL summary="PostgreSQL 13 pgmoneta" \ | ||
description="PostgreSQL 13 pgmoneta" | ||
|
||
# COPY conf/licenses /licenses | ||
|
||
ENV PGVERSION="13" | ||
ENV PGROOT="/usr/pgsql-${PGVERSION}" | ||
|
||
RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm \ | ||
&& rpm -Uvh https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm \ | ||
# && dnf -y update \ | ||
&& dnf -y module disable postgresql \ | ||
&& dnf -y install wget tar \ | ||
&& dnf -y install postgresql13 postgresql13-libs barman crontabs \ | ||
&& dnf -y install pgmoneta \ | ||
&& dnf -y clean all | ||
|
||
RUN useradd -ms /bin/bash pgmoneta | ||
|
||
COPY root/ / | ||
|
||
RUN mkdir -p /conf /pgconf /pgbackup | ||
RUN mkdir -p /conf /pgconf /pgmoneta | ||
COPY conf/* /conf/ | ||
RUN chown barman:barman /etc/barman.conf | ||
RUN chown -R barman:barman /conf /pgconf /pgbackup | ||
RUN chmod 700 /conf /pgconf /pgbackup | ||
RUN chown -R pgmoneta:pgmoneta /conf /pgconf /pgmoneta | ||
RUN chmod 700 /conf /pgconf /pgmoneta | ||
|
||
RUN mkdir -p /usr/local/bin | ||
RUN cd /tmp \ | ||
&& wget https://github.com/prometheus/node_exporter/releases/download/v1.1.1/node_exporter-1.1.1.linux-amd64.tar.gz \ | ||
&& tar xzf node_exporter-1.1.1.linux-amd64.tar.gz \ | ||
&& mv node_exporter-1.1.1.linux-amd64/node_exporter /usr/local/bin/node_exporter \ | ||
&& rm -Rf node_exporter-1.1.1.linux-amd64 node_exporter-1.1.1.linux-amd64.tar.gz \ | ||
&& chown barman:barman /usr/local/bin/node_exporter | ||
&& wget https://github.com/prometheus/node_exporter/releases/download/v1.2.1/node_exporter-1.2.1.linux-amd64.tar.gz \ | ||
&& tar xzf node_exporter-1.2.1.linux-amd64.tar.gz \ | ||
&& mv node_exporter-1.2.1.linux-amd64/node_exporter /usr/local/bin/node_exporter \ | ||
&& rm -Rf node_exporter-1.2.1.linux-amd64 node_exporter-1.2.1.linux-amd64.tar.gz \ | ||
&& chown pgmoneta:pgmoneta /usr/local/bin/node_exporter | ||
|
||
VOLUME ["/pgconf", "/pgmoneta"] | ||
|
||
VOLUME ["/pgconf", "/pgbackup"] | ||
EXPOSE 5001 | ||
EXPOSE 9100 | ||
|
||
USER barman | ||
USER pgmoneta | ||
WORKDIR /home/pgmoneta | ||
|
||
CMD ["/usr/bin/run-barman"] | ||
CMD ["/usr/bin/run-pgmoneta"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# PostgreSQL pgmoneta | ||
|
||
This project contains the PostgreSQL pgmoneta image. | ||
|
||
## Getting Started | ||
|
||
```bash | ||
# Create the image | ||
make build | ||
|
||
# Run, and register the container under postgresql-pgmoneta | ||
podman run -p 5001:5001 -p 9102:9100 --name postgresql-pgmoneta -d -e PG_PRIMARY_NAME=192.168.1.12 -e PG_PRIMARY_PORT=5432 -e PG_REPL_NAME=repl -e PG_REPL_PASSWORD=mypass -e PG_WAL_NAME=backup pgsql13-pgmoneta-centos8 | ||
|
||
# Shell to postgresql- | ||
podman exec -it postgresql-pgmoneta /usr/bin/bash | ||
|
||
# Stop the container | ||
podman stop postgresql-pgmoneta | ||
|
||
# Start the container | ||
podman start postgresql-pgmoneta | ||
|
||
# Remove the container | ||
podman rm postgresql-pgmoneta | ||
``` | ||
|
||
## Configuration | ||
|
||
| Property | Default | Unit | Required | Description | | ||
|----------|---------|------|----------|-------------| | ||
| PG_PRIMARY_NAME | | String | Yes | The IP of the PostgreSQL server | | ||
| PG_PRIMARY_PORT | | String | Yes | The port of the PostgreSQL server | | ||
| PG_BACKUP_NAME | | String | Yes | The replication user name | | ||
| PG_BACKUP_PASSWORD | | String | Yes | The replication user password | | ||
| PG_BACKUP_SLOT | | String | Yes | The name of the WAL slot | | ||
|
||
## SSL support | ||
|
||
SSL support will be enabled when `/pgconf` contains the files `root.crt`, `server.crt` and `server.key`. | ||
|
||
Remember to disable passphase such that the server can boot without a password prompt. | ||
|
||
A guide to this can be found [here](https://www.howtoforge.com/postgresql-ssl-certificates). | ||
Test and production environments should **NOT** be using self-signed certificates. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[pgmoneta] | ||
host = * | ||
metrics = 5001 | ||
|
||
base_dir = /home/pgmoneta | ||
|
||
compression = zstd | ||
|
||
retention = 7 | ||
|
||
log_type = file | ||
log_level = info | ||
log_path = /tmp/pgmoneta.log | ||
|
||
unix_socket_dir = /tmp/ | ||
pgsql_dir = /usr/bin/ | ||
|
||
tls = off | ||
tls_cert_file = /pgmoneta/server.crt | ||
tls_key_file = /pgmoneta/server.key | ||
tls_ca_file = /pgmoneta/root.crt | ||
|
||
[primary] | ||
host = PG_PRIMARY_NAME | ||
port = PG_PRIMARY_PORT | ||
user = PG_REPL_NAME | ||
wal_slot = PG_WAL_NAME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/bin/bash | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2021 Jesper Pedersen <[email protected]> | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining | ||
# a copy of this software and associated documentation files (the "Software"), | ||
# to deal in the Software without restriction, including without limitation | ||
# the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
# and/or sell copies of the Software, and to permit persons to whom the Software | ||
# is furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
# | ||
|
||
NODE_EXPORTER_PIDFILE=/tmp/node_exporter.pid | ||
|
||
function trap_sigterm() { | ||
kill -SIGINT $(head -1 $NODE_EXPORTER_PIDFILE) | ||
} | ||
|
||
trap 'trap_sigterm' SIGINT SIGTERM | ||
|
||
if [ ! -f /pgmoneta/pgmoneta.conf ]; then | ||
export PG_PRIMARY_NAME=${PG_PRIMARY_NAME} | ||
export PG_PRIMARY_PORT=${PG_PRIMARY_PORT} | ||
export PG_BACKUP_NAME=${PG_BACKUP_NAME} | ||
export PG_BACKUP_PASSWORD=${PG_BACKUP_PASSWORD} | ||
export PG_BACKUP_SLOT=${PG_BACKUP_SLOT} | ||
|
||
if [ -z "${PG_PRIMARY_NAME}" ] || [ -z "${PG_PRIMARY_PORT}" ] || | ||
[ -z "${PG_BACKUP_NAME}" ] || [ -z "${PG_BACKUP_PASSWORD}" ] || [ -z "${PG_BACKUP_SLOT}" ]; then | ||
echo "PG_PRIMARY_NAME, PG_PRIMARY_PORT, PG_BACKUP_NAME, PG_BACKUP_PASSWORD, and PG_BACKUP_SLOT needs to be defined." | ||
exit 1 | ||
fi | ||
|
||
sed -i "s/PG_PRIMARY_NAME/$PG_PRIMARY_NAME/g" /conf/pgmoneta.conf | ||
sed -i "s/PG_PRIMARY_PORT/$PG_PRIMARY_PORT/g" /conf/pgmoneta.conf | ||
sed -i "s/PG_BACKUP_NAME/$PG_BACKUP_NAME/g" /conf/pgmoneta.conf | ||
sed -i "s/PG_BACKUP_SLOT/$PG_BACKUP_SLOT/g" /conf/pgmoneta.conf | ||
|
||
if [ -f /pgconf/root.crt ] && [ -f /pgconf/server.crt ] && [ -f /pgconf/server.key ]; then | ||
sed -i "s/tls = off/tls = on/g" /conf/pgmoneta.conf | ||
|
||
cp /pgconf/root.crt /pgmoneta | ||
cp /pgconf/server.crt /pgmoneta | ||
cp /pgconf/server.key /pgmoneta | ||
chmod 0600 /pgmoneta/server.key | ||
fi | ||
|
||
cp /conf/pgmoneta.conf /pgmoneta | ||
|
||
pgmoneta-admin -g master-key | ||
pgmoneta-admin -f /pgmoneta/pgmoneta_users.conf -U ${PG_BACKUP_NAME} -P ${PG_BACKUP_PASSWORD} add-user | ||
|
||
echo "PATH=/usr/pgsql-13/bin:$PATH" > /home/pgmoneta/.bashrc | ||
echo "export PATH" >> /home/pgmoneta/.bashrc | ||
|
||
(crontab -l ; echo "00 06 * * 0 /usr/bin/pgmoneta-cli -c /pgmoneta/pgmoneta.conf backup primary") | crontab - | ||
fi | ||
|
||
/usr/local/bin/node_exporter >> /tmp/node_exporter.log 2>&1 & | ||
echo $! > $NODE_EXPORTER_PIDFILE | ||
|
||
exec pgmoneta -c /pgmoneta/pgmoneta.conf -a /pgmoneta/pgmoneta_hba.conf -u /pgmoneta/pgmoneta_users.conf "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.