Описание плейбука Ansible по развертыванию кластера Postgresql + Patroni + Pgbouncer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
--- - hosts: postgresql_nodes become: yes tasks: # Установка необходимых пакетов - name: Install necessary packages for PostgreSQL, Patroni, and PgBouncer apt: name: - postgresql-{{ postgresql_version }} - postgresql-client-{{ postgresql_version }} - postgresql-contrib-{{ postgresql_version }} - pgbouncer - python3-pip - etcd state: present update_cache: yes - name: Установка psycopg>=3.0.0 через pip (альтернатива) pip: name: psycopg version: ">=3.0.0" state: present executable: /usr/bin/pip3 # Укажите путь к вашему pip # Установка Patroni - name: Install Patroni pip: name: patroni[etcd3] state: present - name: Install python-etcd pip: name: python-etcd state: present # Конфигурация Patroni - name: Create Patroni configuration directory file: path: "{{ patroni_config_dir }}" state: directory mode: '0755' - name: Create Patroni configuration file template: src: patroni.yml.j2 dest: "{{ patroni_config_dir }}/patroni.yml" mode: '0644' - name: Создание юнит-файла systemd для Patroni copy: dest: /etc/systemd/system/patroni.service content: | [Unit] Description=Patroni High Availability PostgreSQL After=network.target [Service] Type=simple User=postgres ExecStart=/usr/local/bin/patroni /etc/patroni/patroni.yml Restart=always LimitNOFILE=1024 [Install] WantedBy=multi-user.target - name: Перезагрузка systemd для загрузки нового юнит-файла command: systemctl daemon-reload - name: Ensure /var/lib/postgresql/.ansible/tmp exists with correct permissions file: path: /var/lib/postgresql/.ansible/tmp state: directory owner: postgres group: postgres mode: '0755' - name: Stop PostgreSQL service systemd: name: postgresql state: stopped enabled: yes - name: Enable and start Patroni service systemd: name: patroni enabled: yes state: restarted # Конфигурация PgBouncer - name: Установка PgBouncer apt: name: pgbouncer state: present - name: Настройка PgBouncer copy: dest: /etc/pgbouncer/pgbouncer.ini content: | [databases] * = host=localhost port=5432 [pgbouncer] listen_addr = {{ pgbouncer_listen_addr }} listen_port = {{ pgbouncer_listen_port }} auth_type = {{ pgbouncer_auth_type }} auth_file = /etc/pgbouncer/userlist.txt pool_mode = {{ pgbouncer_pool_mode }} max_client_conn = 1000 default_pool_size = 20 - name: Добавление пользователей PgBouncer copy: dest: /etc/pgbouncer/userlist.txt content: | "postgres" "{{ postgresql_superuser_password }}" # "postgres" "md5{{ postgresql_superuser_password | password_hash('md5') }}" - name: Configure systemd service for PgBouncer copy: content: | [Unit] Description=PgBouncer After=network.target [Service] Type=simple ExecStart=/usr/sbin/pgbouncer /etc/pgbouncer/pgbouncer.ini User=postgres Group=postgres Restart=always [Install] WantedBy=multi-user.target dest: /etc/systemd/system/pgbouncer.service owner: root group: root mode: '0644' - name: Reload systemd daemon systemd: daemon_reload: yes - name: Запуск PgBouncer systemd: name: pgbouncer enabled: yes state: restarted |
1. Хосты и привилегии
Recommended Posts
Плейбук Ansible по развертыванию haproxy
15.02.2024