necessary653 2023-10-09 20:20 采纳率: 50%
浏览 50
已结题

postgresql中的patroni+etcd 集群应用

在postgresql+patroni+etcd 中 etcd 正常启动 在启动patroni的时候 老是失败,关于patroni的配置文件 也没有发现有什么问题

img

[root@vm02 script]# cat pg2.yml 
scope: batman
namespace: /service/
name: pg2

restapi:
  listen: 10.0.0.102:8008
  connect_address: 10.0.0.102:8008
#  certfile: /etc/ssl/certs/ssl-cert-snakeoil.pem
#  keyfile: /etc/ssl/private/ssl-cert-snakeoil.key
#  authentication:
#    username: username
#    password: password

# ctl:
#   insecure: false # Allow connections to SSL sites without certs
#   certfile: /etc/ssl/certs/ssl-cert-snakeoil.pem
#   cacert: /etc/ssl/certs/ssl-cacert-snakeoil.pem

etcd:
  host: 10.0.0.102:2379
  scheme: http
bootstrap:
  # this section will be written into Etcd:/<namespace>/<scope>/config after initializing new cluster
  # and all other cluster members will use it as a `global configuration`
  dcs:
    ttl: 30
    loop_wait: 10
    retry_timeout: 10
    maximum_lag_on_failover: 1048576
#    master_start_timeout: 300
#    synchronous_mode: false
    #standby_cluster:
      #host: 127.0.0.1
      #port: 1111
      #primary_slot_name: patroni
    postgresql:
      use_pg_rewind: true
      use_slots: true
      parameters:
        wal_level: hot_standby
        hot_standby: "on"
#        wal_keep_segments: 8
#        max_wal_senders: 10
#        max_replication_slots: 10
#        wal_log_hints: "on"
#        archive_mode: "on"
#        archive_timeout: 1800s
#        archive_command: mkdir -p ../wal_archive && test ! -f ../wal_archive/%f && cp %p ../wal_archive/%f
#      recovery_conf:
#        restore_command: cp ../wal_archive/%f %p

  # some desired options for 'initdb'
  initdb:  # Note: It needs to be a list (some options need values, others are switches)
  - encoding: UTF8
  - data-checksums

  pg_hba:  # Add following lines to pg_hba.conf after running 'initdb'
  - host replication vm_replica 0.0.0.0/0 md5
  - host all all 0.0.0.0/0 md5
#  - hostssl all all 0.0.0.0/0 md5

  # Additional script to be launched after initial cluster creation (will be passed the connection URL as parameter)
# post_init: /usr/local/bin/setup_cluster.sh

  # Some additional users users which needs to be created after initializing new cluster
  users:
    admin:
      password: admin
      options:
        - createrole
        - createdb

postgresql:
  listen: 10.0.0.102:15432
  connect_address: 10.0.0.102:15432
  data_dir: /home/postgres/pg/data
#  bin_dir:
#  config_dir:
  pgpass: /home/postgres/.pgpass
  authentication:
    replication:
      username: vm_replica
      password: 123456
    superuser:
      username: postgres
      password: 123456
  parameters:
    unix_socket_directories: '.'

watchdog:
  mode: automatic # Allowed values: off, automatic, required
  device: /dev/watchdog
  safety_margin: 5

tags:
    nofailover: false
    noloadbalance: false
    clonefrom: false
    nosync: false


  • 写回答

16条回答 默认 最新

  • 专家-赤兔[在线] 优质创作者: 编程框架技术领域 2023-10-09 20:31
    关注
    获得0.90元问题酬金

    引自强大而免费的微信小程序:皆我百晓生。如有帮助,还望采纳。


    根据提供的配置文件,可以看到patroni的配置如下:

    scope: batman
    namespace: /service/
    name: pg2
     
    restapi:
      listen: 10.0.0.102:8008
      connect_address: 10.0.0.102:8008
     
    etcd:
      host: 10.0.0.102:2379
      scheme: http
     
    bootstrap:
      dcs:
        ttl: 30
        loop_wait: 10
        retry_timeout: 10
        maximum_lag_on_failover: 1048576
     
      postgresql:
        use_pg_rewind: true
        use_slots: true
        parameters:
          wal_level: hot_standby
          hot_standby: "on"
     
    initdb:
      - encoding: UTF8
      - data-checksums
     
    pg_hba:
      - host replication vm_replica 0.0.0.0/0 md5
      - host all all 0.0.0.0/0 md5
     
    users:
      admin:
        password: admin
        options:
          - createrole
          - createdb
     
    postgresql:
      listen: 10.0.0.102:15432
      connect_address: 10.0.0.102:15432
      data_dir: /home/postgres/pg/data
      pgpass: /home/postgres/.pgpass
      authentication:
        replication:
          username: vm_replica
          password: 123456
        superuser:
          username: postgres
          password: 123456
      parameters:
        unix_socket_directories: '.'
     
    watchdog:
      mode: automatic
      device: /dev/watchdog
      safety_margin: 5
     
    tags:
      nofailover: false
      noloadbalance: false
      clonefrom: false
      nosync: false
    

    根据配置文件,可以看到以下几点有可能导致启动失败:

    1. etcd的地址配置为host: 10.0.0.102:2379,请确保etcd服务已经正确安装和启动,并且可通过该地址访问到etcd服务。

    2. postgresql的监听地址配置为10.0.0.102:15432,请确保该地址没有被其他进程占用,或者修改为其他可用的地址和端口。

    3. pg_hba中配置的用户名和密码需要与实际数据库用户匹配。请确保vm_replicapostgres这两个用户在数据库中已经创建。

    4. data_dir指定了postgresql的数据目录,请确保该目录已经存在,并且具有读写权限。

    5. 其他可能的问题是缺少某些依赖包或启动脚本。

    请检查以上配置和问题,确保配置正确并且环境满足要求后,重新启动patroni。如果问题仍然存在,请提供相关错误消息以便进一步排查问题。

    评论

报告相同问题?

问题事件

  • 系统已结题 10月17日
  • 创建了问题 10月9日