31.2. Пример процесса установки #
Пример организован следующим образом:
Используются инструменты Docker Engine и Docker Compose.
Для обеспечения сетевого взаимодействия контейнеров используется сетевой драйвер
macvlan, если отсутствуют ограничения трафика.Образы контейнеров основаны на Debian 12.
Образы контейнеров создаются, используя стандартные имена объектов, например,
ppemдля базы данных репозитория.PostgreSQL используется в качестве примера контейнерной СУБД. База данных репозитория для менеджера размещается в отдельном контейнере и также использует PostgreSQL.
В ходе интеграции агента в образ контейнера СУБД используется менеджер служб systemd.
Исполняемый файл
systemdбудет указан по умолчанию, поэтому контейнер должен запускаться с расширенными правами.
Инструкция ниже позволяет протестировать процесс установки и получить минимальную рабочую версию PPEM, подходящую для управления контейнерной СУБД в демонстрационных целях.
Примечание
Инструкцию можно адаптировать под разные среды. Скорректируйте команды и имена объектов в соответствии с вашей операционной системой и другими требованиями.
Чтобы установить PPEM, выполните следующие действия:
Разверните и запустите менеджер:
Создайте отдельный каталог для файлов, необходимых для установки менеджера, например:
mkdir ppem
Создайте файл
ppem/Dockerfileсо следующим содержимым:FROM debian:12 RUN <<EOF set -e apt-get update apt-get -y install curl curl https://repo.postgrespro.com/ppem/ppem/keys/pgpro-repo-add.sh | bash - apt install -y ppem cat <<EOF2 >/etc/ppem-manager.yml http: server: address: "" port: 80 static_files_path: "/usr/share/ppem/web-app" security: enabled: true repo: url: postgres://ppem:ppem@db/ppem EOF2 EOF ENTRYPOINT ["/usr/sbin/ppem-manager", "-config", "/etc/ppem-manager.yml"] EXPOSE 80Создайте файл
ppem/docker-compose.ymlсо следующим содержимым:--- services: db: image: postgres:17 environment: POSTGRES_PASSWORD: ppem POSTGRES_USER: ppem POSTGRES_DB: ppem volumes: - db_data:/var/lib/postgresql/data manager: build: manager depends_on: - db ports: - 8080:80 volumes: db_data:Создайте образ и запустите контейнеры, необходимые для работы службы менеджера:
docker compose up -f ppem/ -d --build
Получите API-ключ для настройки агентов:
В навигационной панели перейдите в Главная.
Если на странице отображается инструкция по установке агента, скопируйте ключ из инструкции.
Если инструкции нет, выполните следующие действия:
В навигационной панели перейдите в Инфраструктура → Агенты.
В столбце Ключ аутентификации для любого агента нажмите либо , чтобы скопировать ключ, либо , чтобы посмотреть ключ.
Разверните и запустите контейнерную СУБД:
Создайте отдельный каталог для файлов, необходимых для установки СУБД, например:
mkdir dbms
Создайте файл
dbms/Dockerfileсо следующим содержимым:FROM debian:12 COPY start.sh /usr/local/bin/ COPY start.service /etc/systemd/system/ # Systemd and Postgres RUN <<EOF apt-get update && \ apt-get install -y \ systemd \ postgresql \ postgresql-contrib \ sudo \ curl \ gnupg \ lsb-release apt-get clean rm -rf /var/lib/apt/lists/ find /etc/systemd/system \ /lib/systemd/system \ -path '*.wants/*' \ -not -name '*journald*' \ -not -name '*systemd-tmpfiles*' \ -not -name '*systemd-user-sessions*' \ -delete systemctl enable start.service /etc/init.d/postgresql stop rm -rf /var/lib/postgresql/15/main/* EOF # PPEM Agent RUN <<EOF set -e curl https://repo.postgrespro.com/ppem/ppem/keys/pgpro-repo-add.sh | bash - apt install -y ppem-agent systemctl enable ppem-agent EOF EXPOSE 5432 VOLUME /var/lib/postgresql/15/main VOLUME [ "/sys/fs/cgroup" ] CMD [ "/lib/systemd/systemd" ]Файл
Dockerfileпо умолчанию использует исполняемый файлsystemd.Создайте файл службы
systemddbms/start.serviceсо следующим содержимым:[Unit] Description=Systemd-oriented wrapper for database init [Service] Type=oneshot ExecStart=/bin/bash /usr/local/bin/start.sh RemainAfterExit=yes [Install] WantedBy=multi-user.target
Для управления СУБД файл службы использует скрипт
start.sh.Создайте файл скрипта
dbms/start.shсо следующим содержимым:#!/bin/bash set -eo pipefail PGDATA=/var/lib/postgresql/15/main init_db() { chown postgres:postgres ${PGDATA} su -l postgres -c "/usr/lib/postgresql/15/bin/initdb -A trust -D ${PGDATA}" sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/g" /etc/postgresql/15/main/postgresql.conf mv ${PGDATA}/pg_hba.conf /etc/postgresql/15/main/pg_hba.conf echo "host all all al md5" >> /etc/postgresql/15/main/pg_hba.conf systemctl start postgresql psql -U postgres -c "ALTER USER postgres WITH PASSWORD 'postgres';" } if [ "$(ls -1 ${PGDATA} | wc -l)" -eq 0 ]; then init_db else systemctl start postgresql fiСоздайте файл
dbms/docker-compose.ymlсо следующим содержимым:--- services: agent: build: agent hostname: agent privileged: true volumes: - postgres_data:/var/lib/postgresql/15/main - /sys/fs/cgroup:/sys/fs/cgroup:rw - ./ppem-agent.yml:/etc/ppem-agent.yml networks: companynetwork: volumes: postgres_data: networks: companynetwork: driver: macvlan driver_opts: parent: eth0 ipam: config: - subnet: 10.5.1.0/24 gateway: 10.5.1.1В файле конфигурации агента
dbms/ppem-agent.ymlукажите значения для следующих параметров:agent.manager.api_key: ранее полученный API-ключ для подключения агента к менеджеру.agent.manager.url: URL для подключения агента к менеджеру.Пример:
http://ppem.example.com:8080/v1.
При необходимости используйте пример файла конфигурации агента.
Создайте образ и запустите контейнер СУБД с интегрированным агентом:
docker compose up -f dbms/ -d --build
PPEM будет установлен. Вы можете обновить страницу браузера с веб-приложением и начать работу.
31.2. Installation Process Example #
The example is organized as follows:
Docker Engine and Docker Compose tools are used.
The
macvlannetwork driver is used for container networking, assuming there are no traffic restrictions.The container images are based on Debian 12 images.
The container images are built using standard object names, for example,
ppemfor the repository database.PostgreSQL is used as sample containerized DBMS. The repository database for the manager runs in a separate container and uses PostgreSQL, too.
When integrating the agent into the DBMS container image, the systemd service manager is used.
The
systemdexecutable will be specified as the default one, therefore the container must be run with elevated privileges.
These instructions will help you to test the installation process and get a minimal working version of PPEM suitable for managing containerized DBMS for demonstration purposes.
Note
The instructions can be adapted to various environments. Correct the commands and object names according to your operating system and other requirements.
Perform the following steps to install PPEM:
Get the manager up and running:
Create a separate directory for the files that are required to install the manager, for example:
mkdir ppem
Create the
ppem/Dockerfilefile with the following content:FROM debian:12 RUN <<EOF set -e apt-get update apt-get -y install curl curl https://repo.postgrespro.com/ppem/ppem/keys/pgpro-repo-add.sh | bash - apt install -y ppem cat <<EOF2 >/etc/ppem-manager.yml http: server: address: "" port: 80 static_files_path: "/usr/share/ppem/web-app" security: enabled: true repo: url: postgres://ppem:ppem@db/ppem EOF2 EOF ENTRYPOINT ["/usr/sbin/ppem-manager", "-config", "/etc/ppem-manager.yml"] EXPOSE 80Create the
ppem/docker-compose.ymlfile with the following content:--- services: db: image: postgres:17 environment: POSTGRES_PASSWORD: ppem POSTGRES_USER: ppem POSTGRES_DB: ppem volumes: - db_data:/var/lib/postgresql/data manager: build: manager depends_on: - db ports: - 8080:80 volumes: db_data:Build the image and start the containers required for the manager service to operate:
docker compose up -f ppem/ -d --build
Get an API key to configure agents:
In the navigation panel, go to Summary.
If the agent installation instruction is displayed on the page, then copy the key from the instruction.
If no instruction is displayed, then complete the following steps:
In the navigation panel, go to Infrastructure → Agents.
In the Authentication key column for any agent, click either to copy the key or to view the key.
Get containerized DBMS up and running:
Create a separate directory for the files that are required to install the DBMS, for example:
mkdir dbms
Create the
dbms/Dockerfilefile with the following content:FROM debian:12 COPY start.sh /usr/local/bin/ COPY start.service /etc/systemd/system/ # Systemd and Postgres RUN <<EOF apt-get update && \ apt-get install -y \ systemd \ postgresql \ postgresql-contrib \ sudo \ curl \ gnupg \ lsb-release apt-get clean rm -rf /var/lib/apt/lists/ find /etc/systemd/system \ /lib/systemd/system \ -path '*.wants/*' \ -not -name '*journald*' \ -not -name '*systemd-tmpfiles*' \ -not -name '*systemd-user-sessions*' \ -delete systemctl enable start.service /etc/init.d/postgresql stop rm -rf /var/lib/postgresql/15/main/* EOF # PPEM Agent RUN <<EOF set -e curl https://repo.postgrespro.com/ppem/ppem/keys/pgpro-repo-add.sh | bash - apt install -y ppem-agent systemctl enable ppem-agent EOF EXPOSE 5432 VOLUME /var/lib/postgresql/15/main VOLUME [ "/sys/fs/cgroup" ] CMD [ "/lib/systemd/systemd" ]The above
Dockerfileuses thesystemdexecutable as the default one.Create the
dbms/start.servicesystemdunit file with the following content:[Unit] Description=Systemd-oriented wrapper for database init [Service] Type=oneshot ExecStart=/bin/bash /usr/local/bin/start.sh RemainAfterExit=yes [Install] WantedBy=multi-user.target
The above unit file uses the
start.shscript to manage the DBMS.Create the
dbms/start.shscript file with the following content:#!/bin/bash set -eo pipefail PGDATA=/var/lib/postgresql/15/main init_db() { chown postgres:postgres ${PGDATA} su -l postgres -c "/usr/lib/postgresql/15/bin/initdb -A trust -D ${PGDATA}" sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/g" /etc/postgresql/15/main/postgresql.conf mv ${PGDATA}/pg_hba.conf /etc/postgresql/15/main/pg_hba.conf echo "host all all al md5" >> /etc/postgresql/15/main/pg_hba.conf systemctl start postgresql psql -U postgres -c "ALTER USER postgres WITH PASSWORD 'postgres';" } if [ "$(ls -1 ${PGDATA} | wc -l)" -eq 0 ]; then init_db else systemctl start postgresql fiCreate the
dbms/docker-compose.ymlfile with the following content:--- services: agent: build: agent hostname: agent privileged: true volumes: - postgres_data:/var/lib/postgresql/15/main - /sys/fs/cgroup:/sys/fs/cgroup:rw - ./ppem-agent.yml:/etc/ppem-agent.yml networks: companynetwork: volumes: postgres_data: networks: companynetwork: driver: macvlan driver_opts: parent: eth0 ipam: config: - subnet: 10.5.1.0/24 gateway: 10.5.1.1In the
dbms/ppem-agent.ymlagent configuration file, specify values for the following parameters:agent.manager.api_key: The previously obtained API key for connecting the agent to the manager.agent.manager.url: The URL for connecting the agent to the manager.Example:
http://ppem.example.com:8080/v1.
If necessary, use the sample agent configuration file as a reference.
Build the image and start the DBMS container with the integrated agent:
docker compose up -f dbms/ -d --build
PPEM will be installed. You can update the browser page with the web application and start working.