In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail how to install the master-slave structure of the POSTGRESQL10.3 source code. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Download POSTGRESQL source code installation package and host configuration
Https://www.postgresql.org/ftp/source/v10.3/
Postgresql-10.3.tar.gz
Virtual machine environment
Node1 192.168.159.151
Node2 192.168.159.152
The operating system is redhat6.5
Database is postgresql10.3
Both nodes are configured with / etc/hosts
Vi / etc/hosts
Node1 192.168.159.151
Node2 192.168.159.152
II. Compilation and installation
(1) create a postgres user
Useradd-m-r-s / bin/bash-u 5432 postgres
(2) install related dependency packages
Yum install gettext gcc make perl python perl-ExtUtils-Embed readline-devel zlib-devel openssl-devel libxml2-devel cmake gcc-c++ libxslt-devel openldap-devel pam-devel python-devel cyrus-sasl-devel libgcrypt-devel libgpg-error-devel libstdc++-devel
(3) configure POSTGRES
. / configure-- prefix=/opt/postgresql-10.3-- with-segsize=8-- with-wal-segsize=64-- with-wal-blocksize=16-- with-blocksize=16-- with-libedit-preferred-- with-perl-- with-python-- with-openssl-- with-libxml-- with-libxslt-- enable-profiling-- enable-thread-safety-- enable-nls=zh_CN
If the following yellow output appears in the last few lines, the configuration is correct, otherwise continue to install the dependency package according to the error prompt
Configure: using CPPFLAGS=-D_GNU_SOURCE-I/usr/include/libxml2
Configure: using LDFLAGS=-Wl,--as-needed
Configure: creating. / config.status
Config.status: creating GNUmakefile
Config.status: creating src/Makefile.global
Config.status: creating src/include/pg_config.h
Config.status: creating src/include/pg_config_ext.h
Config.status: creating src/interfaces/ecpg/include/ecpg_config.h
Config.status: linking src/backend/port/tas/dummy.s to src/backend/port/tas.s
Config.status: linking src/backend/port/dynloader/linux.c to src/backend/port/dynloader.c
Config.status: linking src/backend/port/posix_sema.c to src/backend/port/pg_sema.c
Config.status: linking src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.c
Config.status: linking src/backend/port/dynloader/linux.h to src/include/dynloader.h
Config.status: linking src/include/port/linux.h to src/include/pg_config_os.h
Config.status: linking src/makefiles/Makefile.linux to src/Makefile.port
(4) compilation
Make & & make install
The following yellow output appears in the last few lines to be configured correctly
Make [1]: Leaving directory `/ opt/postgresql-10.3/src'
Make-C config install
Make [1]: Entering directory `/ opt/postgresql-10.3/config'
/ bin/mkdir-p'/ opt/postgresql-10.3/lib/pgxs/config'
/ usr/bin/install-c-m 755. / install-sh' / opt/postgresql-10.3/lib/pgxs/config/install-sh'
/ usr/bin/install-c-m 755. / missing' / opt/postgresql-10.3/lib/pgxs/config/missing'
Make [1]: Leaving directory `/ opt/postgresql-10.3/config'
PostgreSQL installation complete.
(5) installation
Make world & & make install-world
The following yellow output appears in the last few lines to be configured correctly
Make [1]: Leaving directory `/ opt/postgresql-10.3/src'
Make-C config install
Make [1]: Entering directory `/ opt/postgresql-10.3/config'
/ bin/mkdir-p'/ opt/postgresql-10.3/lib/pgxs/config'
/ usr/bin/install-c-m 755. / install-sh' / opt/postgresql-10.3/lib/pgxs/config/install-sh'
/ usr/bin/install-c-m 755. / missing' / opt/postgresql-10.3/lib/pgxs/config/missing'
Make [1]: Leaving directory `/ opt/postgresql-10.3/config'
PostgreSQL installation complete.
Make: Leaving directory `/ opt/postgresql-10.3'
(6) create relevant directories and configure environment variables
Mkdir-p / data/pgdata/serverlog
Mkdir / data/pg
Su-postgres
Vi .bash _ profile (delete all the original, copy and paste the following yellow parts directly)
# .bash _ profile
# Get the aliases and functions
If [- f ~ / .bashrc]; then
. ~ / .bashrc
Fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
Export PATH
# postgres
# PostgreSQL Port
PGPORT=5432
# PostgreSQL data directory
PGDATA=/data/pgdata
Export PGPORT PGDATA
# the language used
Export LANG=zh_CN.utf8
# PostgreSQL installation directory
Export PGHOME=/data/pg
# PostgreSQL connection Library File
Export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH
Export DATE= `date + "% Y%m%d%H%M" `
# add the command line of PostgreSQL to the PATH environment variable
Export PATH=$PGHOME/bin:$PATH
# man manual for PostgreSQL
Export MANPATH=$PGHOME/share/man:$MANPATH
# default user for PostgreSQL
Export PGUSER=postgres
# PostgreSQL default host address
Export PGHOST=127.0.0.1
# default database name
Export PGDATABASE=postgres
# define log storage directory
PGLOG= "$PGDATA/serverlog" source .bash _ profile
(7) initialize the database
# execute database initialization script
Root user login
Chown-R postgres.postgres / data/
Su-postgres
$/ opt/postgresql-10.3/bin/initdb-- encoding=utf8-D / data/pg/data warning: "trust" authentication was initiated for local connections.
You can change it by editing pg_hba.conf or your next time
Use the-An or-- auth-local and-- auth-host options when initdb. Success. You can now start the database server using: starting the database
Su-postgres
/ opt/postgresql-10.3/bin/pg_ctl-D / data/pg/data-l logfile start
(8) copy of relevant commands
Root user
Mkdir / data/pg/bin
Cp / opt/postgresql-10.3/bin/* / data/pg/bin
Chown-R postgres.postgres / data/pg/bin
Third, postgresql master-slave building
1. Configuration of main library
(1) create a user replica copied by the user
Su-postgres
Psql
CREATE ROLE replica login replication encrypted password 'replica'
(2) modify the pg_hba.conf file and specify replica to log in to the network (last added)
Vi / data/pg/data/pg_hba.conf
Host replication replica 192.168.159.0/24 md5
Host all replica 192.168.159.0/24 trust
(3) the main library configuration file modifies the following items, while others remain unchanged.
Vi / data/pg/data/postgresql.conf
Listen_addresses ='*'
Wal_level = hot_standby # hot standby mode
Max_wal_senders= 6 # can set up a maximum of several stream copy links, as many as there are from.
Wal_keep_segments = 20 # important configuration (the setting here will affect the number of files in the pg_wal directory. It is recommended not to set it too large. 20 is enough)
Wal_send_timeout = 60s
Max_connections = 512 # the max_connections of the slave library is larger than the master library
Archive_mode = on # allow archiving
# archive_command ='cp% p / url/path%f' # set according to the actual situation
2. From the library environment
(1) empty the data folder directory of the database.
Rm-rf / var/lib/pgsql/10/data/*
(2) run on the standby database
Pg_basebackup-F p-- progress-D / data/pg/data/-h 192.168.159.151-p 5432-U replica-- password
Enter password replica
!!! Note that after the replication is completed, all the files in the data directory must be re-authorized in the standby library.
Chown-R postgres.postgres / data/pg/data/
(3) create recovery.conf file
Cp / opt/postgresql-10.3/share/recovery.conf.sample / data/pg/data/recovery.conf
Vi / data/pg/data/recovery.conf
Standby_mode = on
Primary_conninfo = 'host=192.168.159.151 port=5432 user=replica password=replica'
Recovery_target_timeline = 'latest'
Trigger_file ='/ data/pg/data/trigger.kenyon'
(4) configure postgresql.conf file
Vi / data/pg/data/postgresql.conf
Listen_addresses ='*'
Wal_level = hot_standby
Max_connections = 1000 # generally, the maximum slave link is larger than the master link.
Hot_standby = on # indicates that this machine is not only used for data archiving, but also for query
Max_standby_streaming_delay = 30s
Wal_receiver_status_interval = 10s # how often do you report the slave status to the master?
Hot_standby_feedback = on # if there is incorrect data replication, whether to make an example to the master
(5) start the backup database
Su-postgres
/ opt/postgresql-10.3/bin/pg_ctl-D / data/pg/data/-l logfile start
If it cannot be started, copy the file postmaster.opts from the main library to the standby library as follows:
Scp / data/pg/data/postmaster.opts 192.168.159.152:/data/pg/data/
Chown-R postgres.postgres / data/pg/data/
Cd / data/pg/
Chmod 700 data/
3. Verify the master-slave function
Main database query
Su-postgres
Psql
Postgres=# select client_addr,sync_state from pg_stat_replication
Client_addr | sync_state
-+-
192.168.159.152 | async
(1 row)
The following problems were found when logging in to postgres
-bash-4.1 $
Root user execution
Cp / etc/skel/.bash* / var/lib/pgsql/
Log in again and you can become
[postgres@node1 ~] $
On "POSTGRESQL10.3 source code how to install master-slave build" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.