Чтобы подготовить удаленную базу данных к установке компонентов Traffic Monitor, выполните на сервере базы данных следующие действия:

  1.  Установить репозитории, выполнив команду:

    deb https://dl.astralinux.ru/astra/frozen/1.7_x86-64/1.7.9/repository-base/ 1.7_x86-64 main contrib non-free
    deb https://dl.astralinux.ru/astra/frozen/1.7_x86-64/1.7.9/repository-main/ 1.7_x86-64 main contrib non-free
    deb https://dl.astralinux.ru/astra/frozen/1.7_x86-64/1.7.9/repository-update/ 1.7_x86-64 main contrib non-free
  2. Выполнить обновление с помощью команды:

    apt update
  3. Скачайте пакеты СУБД Postgres Pro15 с официального репозитория:

    postgrespro-std-15-server_15.18.1-1.17x8664_amd64.deb
    postgrespro-std-15-libs_15.18.1-1.17x8664_amd64.deb
    postgrespro-std-15-contrib_15.18.1-1.17x8664_amd64.deb
    postgrespro-std-15-client_15.18.1-1.17x8664_amd64.deb
  4. Установите пакеты:

    apt install -y postgrespro-std-15*
  5. Установите pgagent:

    apt-get install -y pgagent
  6. Остановите работу сервисов postgresql и pgagent, используя команды:

    systemctl stop postgrespro-std-15
    systemctl stop pgagent
  7. Выполните генерацию локали:
    LOCALE_TO_GENERATE="en_US.UTF-8"
    sed -i "s/^#\s*${LOCALE_TO_GENERATE}/${LOCALE_TO_GENERATE}/" /etc/locale.gen
    locale-gen "$LOCALE_TO_GENERATE"
  8. Создайте директории для файлов и архивов, инициализируйте базу данных и смените директориям владельца и группу на postgres:

    mkdir -p /u01/postgres
    chown -R postgres:postgres /u01
    su - postgres 
    cd /opt/pgpro/std-15/bin/
    ./initdb --encoding=UTF8 --locale=en_US.UTF-8 -D /u01/postgres 
  9. Создайте конфигурационный файл /u01/postgres/iwtm-postgres.conf. Например, с помощью команды:

    touch /u01/postgres/iwtm-postgres.conf
  10. Добавьте в файл /u01/postgres/iwtm-postgres.conf:

    # -----------------------------
    # Postgres Pro configuration file
    # -----------------------------
    #
    # IWTM custom values
     
    listen_addresses = '*'
    port = 5433
    max_connections = 1000                     # (change requires restart)
    tcp_keepalives_idle = 60                   # TCP_KEEPIDLE, in seconds'
    tcp_keepalives_interval = 20               # TCP_KEEPINTVL, in seconds'
    tcp_keepalives_count = 2                   # TCP_KEEPCNT
     
    shared_buffers = 128kB
     
    huge_pages = try                           # on, off, or try
     
    max_locks_per_transaction = 512
    temp_buffers = 32MB
    work_mem = 16MB
    effective_cache_size = 4096MB
     
    min_wal_size = 6144MB
    max_wal_size = 6144MB
    lc_messages = 'en_US.UTF-8'                # locale for system error message
    log_directory = 'pg_log'
    log_filename = 'postgresql.log'            # log file name pattern
    log_rotation_age = 0                       # Automatic rotation of logfiles will happen after that time. 0 disables.
    log_rotation_size = 0                      # Automatic rotation of logfiles will happen after that much log output. 0 disables.
    log_min_duration_statement = 120000        # -1 is disabled, 0 logs all statements
    track_activity_query_size = 32768          # (change requires restart)
    log_autovacuum_min_duration = 30000        # -1 disables, 0 logs all actions and
    # stats_temp_directory = '/u01/postgres/pg_stat_tmp'
     
    autovacuum_max_workers = 5
    autovacuum_naptime = 20
    maintenance_work_mem = 1GB
    autovacuum_freeze_max_age = 1000000000
     
    shared_preload_libraries = 'pg_stat_statements'
    track_io_timing = on
    track_activity_query_size = 32768
     
    constraint_exclusion = off                 # on, off, or partition
    standard_conforming_strings = on
  11. Смените у конфигурационного файла владельца и группу на postgres, а также права на них:

    chown postgres:postgres /u01/postgres/iwtm-postgres.conf
    chmod 600 /u01/postgres/iwtm-postgres.conf
  12. Добавьте в конфигурационный файл /var/lib/pgpro/std-15/data/postgresql.conf ссылку на файл iwtm-postgres.conf с помощью команды:

    echo "include = 'iwtm-postgres.conf'" >>  /u01/postgres/postgresql.conf
  13. Создайте директории для файлов и архивов, инициализируйте базу данных и смените директориям владельца и группу на postgres:

    mkdir -p /u01/postgres/tmp
    mkdir -p /u02/pgdata
    mkdir -p /u02/pgdata1
    mkdir -p /u02/arch
    chown -R postgres:postgres /u02
    chown -R postgres:postgres /u01
    usermod -a -G shadow postgres
    setfacl -d -m u:postgres:r /etc/parsec/macdb
    setfacl -R -m u:postgres:r /etc/parsec/macdb
    setfacl -m u:postgres:rx /etc/parsec/macdb
    setfacl -d -m u:postgres:r /etc/parsec/capdb
    setfacl -R -m u:postgres:r /etc/parsec/capdb
    setfacl -m u:postgres:rx /etc/parsec/capdb
  14. Отредактируйте файл доступа /u01/postgres/pg_hba.conf:

    sed -i "s|host[[:space:]]*all[[:space:]]*all[[:space:]]*127.0.0.1/32[[:space:]]*md5|host    all             all             127.0.0.1/32            trust|" /u01/postgres/pg_hba.conf
    sed -i "s|local[[:space:]]*all[[:space:]]*all[[:space:]]*peer|local   all             all                                     trust|" /u01/postgres/pg_hba.conf
    sed -i "s|host[[:space:]]*all[[:space:]]*all[[:space:]]*::1/128[[:space:]]*ident|host    all             all             ::1/128                 trust|"     /u01/postgres/pg_hba.conf
    echo "# Enable not local access" >> /u01/postgres/pg_hba.conf
    echo "host    postgres        all             0.0.0.0/0               md5" >> /u01/postgres/pg_hba.conf
  15. Выполнить копирование файлов pgagent /usr/share/postgresql/15/extension/ в /opt/pgpro/std-15/share/extension/


  16. Сделайте замену pgdata:

    echo "PGDATA= /u01/postgres" > /etc/default/postgrespro-std-15
  17. Измените для администратора базы данных пароль по умолчанию:

    su - postgres
    psql -p 5433 -h localhost
    alter user postgres password 'xxXX1234';
  18. Создайте нужные расширения, выполнив запросы:

    create extension if not exists adminpack;
    create extension if not exists dblink;
    create extension if not exists lo;
    create extension if not exists xml2;
    create extension if not exists tablefunc;
    create extension if not exists intarray;
    create extension if not exists file_fdw;
    create extension if not exists "uuid-ossp";
    create extension if not exists pgcrypto;
    create extension if not exists pgrowlocks;
    create extension if not exists autoinc;
    create extension if not exists hstore;
    create extension if not exists pg_stat_statements;
    create extension if not exists pg_buffercache;
    create extension if not exists pgagent;

    Вы можете выполнить все команды одним запросом

  19. Для выхода введите команды:

    \q
    exit
  20. Добавьте пользователя и группу pgagent:pgagent:

    groupadd -f -r pgagent 
    useradd -g pgagent -r -s /bin/false -c "pgAgent Job Schedule" pgagent
  21. Для настройки в ОС пользователя pgagent выполните команды:

    mkdir -p /home/pgagent
    chmod 0600 /home/pgagent
    chown pgagent:pgagent /home/pgagent
    touch /home/pgagent/.pgpass
    echo "127.0.0.1:5433:postgres:postgres:xxXX1234" > /home/pgagent/.pgpass
    chmod 0600 /home/pgagent/.pgpass
    chown pgagent:pgagent /home/pgagent/.pgpass 
    usermod -s /bin/bash pgagent
  22. Для настройки файлов с логами выполните:

    touch /var/log/pgagent.log
    chown pgagent:pgagent /var/log/pgagent.log
  23. Создайте /etc/sudoers.d/pgagent со следующим содержимым:

    # allow pgagent to execute any command
    pgagent ALL = (postgres) NOPASSWD: ALL
    Defaults:pgagent !requiretty
  24. Измените для /etc/sudoers.d/pgagent права, владельца и группу, выполнив команды:

    chmod 440 /etc/sudoers.d/pgagent
    chown root:root /etc/sudoers.d/pgagent
  25. Отредактируйте конфигурационный файл /etc/pgagent/pgagent_15.conf с помощью команд:

    mkdir /etc/pgagent
    touch /etc/pgagent/pgagent.conf
  26. Добавить в pgagent.conf:

    DBNAME=postgres
    DBUSER=postgres
    DBHOST=127.0.0.1
    DBPORT=5433
    LOGFILE=/var/log/pgagent.log
    LD_LIBRARY_PATH=/opt/pgpro/std-15/lib
  27. Для настройки сервиса pgagent создайте директорию и файл с помощью команд:

    mkdir -p /usr/lib/systemd/system
    touch /usr/lib/systemd/system/pgagent.service
  28. Добавьте в файл /usr/lib/systemd/system/pgagent.service следующее содержимое:

    "[Unit]
    Description=PgAgent for PostgreSQL
    After=syslog.target
    After=network.target
    
    [Service]
    Type=forking
    
    User=pgagent
    Group=pgagent
    
    # Location of the configuration file
    EnvironmentFile=/etc/pgagent/pgagent.conf
    
    # Where to send early-startup messages from the server (before the logging
    # options of pgagent.conf take effect)
    # This is normally controlled by the global default set by systemd
    # StandardOutput=syslog
    
    # Disable OOM kill on the postmaster
    OOMScoreAdjust=-1000
    
    ExecStart=/usr/bin/pgagent -s \${LOGFILE} hostaddr=\${DBHOST} dbname=\${DBNAME} user=\${DBUSER} port=\${DBPORT}
    KillMode=mixed
    KillSignal=SIGINT
    
    Restart=on-failure
    
    # Give a reasonable amount of time for the server to start up/shut down
    TimeoutSec=300
    
    [Install]
    WantedBy=multi-user.target"  
  29. Примените изменения в конфигурации, выполнив команду:

    systemctl daemon-reload
  30. Включите сервис pgagent, запустите его, а затем проверьте его статус с помощью команд:

    systemctl enable pgagent
    systemctl start pgagent
    systemctl status pgagent

По завершении настройки убедитесь в отсутствии критических ошибок в логах базы данных и /var/log/pgagent.log