PostgreSQL HA 之 patroni + zookeeper

一、环境准备

        linux:CentOS Linux release 7.5.1804 (Core) 

        zookeeper: 3.3.6

        patroni: 1.4.4

        PostgreSQL: 10.4

  地址划分:

      192.168.0.2 zookeeper

      192.168.0.4 master

      192.168.0.5 slave

     192.168.0.6 slave

   下载地址:

        zookeeper:https://archive.apache.org/dist/zookeeper/zookeeper-3.3.6/zookeeper-3.3.6.tar.gz

        patroni:https://codeload.github.com/zalando/patroni/zip/1de7c78c04dab9882f6113815d377e6f3490d5dd

        PostgreSQL:https://ftp.postgresql.org/pub/source/v10.4/postgresql-10.4.tar.gz

二、安装zookeeper

  1.  下载: wget https://archive.apache.org/dist/zookeeper/zookeeper-3.3.6/zookeeper-3.3.6.tar.gz
  2.  解压: tar -zxvf zookeeper-3.3.6.tar.gz
  3. cd zookeeper-3.3.6
  4. cp conf/zoo_sample.cfg conf/zoo.cfg
  5. 修改conf/zoo.cfg中对应配置

    # The number of milliseconds of each tick
    tickTime=2000
    # The number of ticks that the initial 
    # synchronization phase can take
    initLimit=10
    # The number of ticks that can pass between 
    # sending a request and getting an acknowledgement
    syncLimit=5
    # the directory where the snapshot is stored.
    dataDir=/home/postgres/zookeeper-data
    dataLogDir=/home/postgres/zookeeper-log
    # the port at which the clients will connect
    clientPort=2181
    server.1=192.168.0.2:2888:3888
  6. 启动:bin/zkServer.sh start

三、安装PostgreSQL

  1.  下载: wget https://ftp.postgresql.org/pub/source/v10.4/postgresql-10.4.tar.gz   
  2.  解压:tar  -zxvf  postgresql-10.4.tar.gz
  3.  cd   postgresql-10.4
  4.  配置:./configure --prefix=`pwd`/release --with-wal-segsize=64
  5. 编译安装:make -j10 && make install 
  6. 增加相应环境变量:vim ~/.bash_profile
     export PGHOME=$HOME/postgresql-10.4/release
     export PGUSER=postgres
     export PGDBTABASE=postgres
     export PGPORT=5432
     export PGDATA=$HOME/data
     export PGHOST=127.0.0.1
     export PATH=$PGHOME/bin:$HOME/bin:$PATH
     export LD_LIBRARY_PATH=$PGHOME/lib::$LD_LIBRARY_PATH
  7. 使配置生效:source ~/.bash_profile 
  8. 初始化数据库(只在192.168.0.4):initdb -D ~/data -E UTF-8 --locale='C' 
  9. 修改数据库postgresql.conf配置(紧测试用,与性能无关)

    [pg1@PostgreSQL3 data]$ grep ^[a-zA-Z] postgresql.conf
    listen_addresses = '*'        # what IP address(es) to listen on;
    max_connections = 100            # (change requires restart)
    unix_socket_directories = '.'    # comma-separated list of directories
    shared_buffers = 128MB            # min 128kB
    dynamic_shared_memory_type = posix    # the default is the first option
    wal_log_hints = on            # also do full page writes of non-critical updates
    max_wal_size = 1GB
    min_wal_size = 512MB
    wal_keep_segments = 10        # in logfile segments, 16MB each; 0 disables
    wal_sender_timeout = 60s    # in milliseconds; 0 disables
    max_replication_slots = 10    # max number of replication slots
    synchronous_standby_names = 'postgresql0, postgresql1, postgresql2'    # standby servers that provide sync rep
    logging_collector = on        # Enable capturing of stderr and csvlog
    log_directory = 'log'            # directory where log files are written,
    log_filename = 'postgresql-%a.log'    # log file name pattern,
    log_file_mode = 0600            # creation mode for log files,
    log_truncate_on_rotation = on        # If on, an existing log file with the
    log_rotation_age = 1d            # Automatic rotation of logfiles will
    log_checkpoints = on
    log_connections = on
    log_line_prefix = '%m [%p] '        # special values:
    log_statement = 'all'            # none, ddl, mod, all
    log_timezone = 'US/Eastern'
    datestyle = 'iso, mdy'
    timezone = 'US/Eastern'
    lc_messages = 'C'            # locale for system error message
    lc_monetary = 'C'            # locale for monetary formatting
    lc_numeric = '

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值