Чтобы подготовить удаленную базу данных к установке компонентов Traffic Monitor, выполните на сервере базы данных следующие действия:
Установите дополнительные пакеты, выполнив команды:
yum -y install pgagent_12* postgresql-contrib
- Убедитесь, что SELinux отключен.
С инструкцией по отключению SELinux можно ознакомиться на официальном сайте РЕД ОС. Создайте или дополните файл
/etc/systemd/system/postgresql-12.service.d/override.confследующим содержимым:[Service] Environment=PGDATA=/u01/postgres
Для применения изменений в конфигурации сервиса выполните команду:
systemctl daemon-reload
Создайте директории для файлов и архивов, а затем инициализируйте базу данных:
mkdir -p /u01/postgres chown postgres:postgres /u01/postgres sudo -u postgres initdb --encoding=UTF8 --locale=en_US.UTF-8 -D /u01/postgres mkdir -p /u01/postgres/tmp /u02/pgdata /u02/pgdata1 /u02/arch
Создайте конфигурационный файл
/u01/postgres/iwtm-postgres.conf. Например, с помощью команды:touch /u01/postgres/iwtm-postgres.conf
Добавьте в файл
/u01/postgres/iwtm-postgres.conf:# ----------------------------- # PostgreSQL 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 = kB # min 128KiB huge_pages = try # on, off, or try max_locks_per_transaction = 256 temp_buffers = MB work_mem = MB effective_cache_size = MB min_wal_size = MB max_wal_size = MB 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 stats_temp_directory = '/u01/postgres/pg_stat_tmp' autovacuum_max_workers = 5 autovacuum_naptime = 20 max_parallel_maintenance_workers = 8 maintenance_work_mem = GB autovacuum_freeze_max_age = 1000000000 shared_preload_libraries = 'pg_stat_statements' track_io_timing = on track_activity_query_size = 32768 enable_partitionwise_join = on constraint_exclusion = off # on, off, or partition standard_conforming_strings = on
Важно!
В примере содержимого конфигурационного файла указаны пустые поля значений для параметров:
shared_bufferswork_memmaintenance_work_memeffective_cache_sizetemp_buffersmin_wal_sizemax_wal_size
Настройте эти параметры в соответствии с официальной инструкцией (на английском).
- Смените у конфигурационного файла владельца и группу на
postgres:chown -R postgres:postgres /u02 /u01
Добавьте в конфигурационный файл
/u01/postgres/postgresql.confссылку на файлiwtm-postgres.confс помощью команды:echo "include = 'iwtm-postgres.conf'" >> /u01/postgres/postgresql.conf
Настройте файл доступа
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:]]*127.0.0.1/32[[:space:]]*ident|host all all 127.0.0.1/32 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
Запустите сервис
postgresqlи проверьте его статус с помощью команд:systemctl enable postgresql systemctl start postgresql systemctl status postgresql
Измените для администратора базы данных пароль по умолчанию:
su - postgres psql -p 5433 alter user postgres password 'xxXX1234';
Создайте нужные расширения, выполнив запросы:
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;
Для выхода введите команды:
\q exit
- Для настройки в ОС пользователя
pgagentвыполните команды:mkdir -p /home/pgagent touch /home/pgagent/.pgpass echo "127.0.0.1:5433:postgres:postgres:xxXX1234" > /home/pgagent/.pgpass chmod 0600 /home/pgagent/.pgpass chown -R pgagent:pgagent /home/pgagent usermod -s /bin/bash pgagent sed -i "s|DBPORT=5432|DBPORT=5433|" /etc/pgagent/pgagent_12.conf
Создайте или отредактируйте файл
/etc/sudoers.d/pgagent, чтобы его содержимое соответствовало образцу:# allow pgagent to execute any command
pgagent ALL = (postgres) NOPASSWD: ALL
Defaults:pgagent !requirettyВажно!
Пустая строка в конце файла
pgagentобязательна.Измените для
/etc/sudoers.d/pgagentправа, владельца и группу, выполнив команды:chmod 440 /etc/sudoers.d/pgagent chown root:root /etc/sudoers.d/pgagent
Запустите сервис
pgagentи проверьте его статус с помощью команд:systemctl enable pgagent_12 systemctl start pgagent_12 systemctl status pgagent_12
По завершении настройки убедитесь в отсутствии критических ошибок в логах базы данных и /var/log/pgagent_12.log.