一、环境准备
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
- 下载: wget https://archive.apache.org/dist/zookeeper/zookeeper-3.3.6/zookeeper-3.3.6.tar.gz
- 解压: tar -zxvf zookeeper-3.3.6.tar.gz
- cd zookeeper-3.3.6
- cp conf/zoo_sample.cfg conf/zoo.cfg
- 修改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 - 启动:bin/zkServer.sh start
三、安装PostgreSQL
- 下载: wget https://ftp.postgresql.org/pub/source/v10.4/postgresql-10.4.tar.gz
- 解压:tar -zxvf postgresql-10.4.tar.gz
- cd postgresql-10.4
- 配置:./configure --prefix=`pwd`/release --with-wal-segsize=64
- 编译安装:make -j10 && make install
- 增加相应环境变量: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 - 使配置生效:source ~/.bash_profile
- 初始化数据库(只在192.168.0.4):initdb -D ~/data -E UTF-8 --locale='C'
- 修改数据库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 = '