In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Database master-slave hot standby database installation
1. Install the yum source
Open https://yum.postgresql.org/repopackages.php, find the version you need, and right-click to copy the link address.
If you are not sure whether the copy is successful, you can paste it out and have a look.
Enter CentOS7 in root mode and enter: yum install + the link you just copied
Enter.
Enter: y, enter.
two。 Install PostgreSQL
Enter: yum install-y postgresql94-server postgresql94-contrib
Enter. (if you use other versions of PostgreSQL, you need to replace two of the 94 with corresponding numbers.)
Enter y and enter.
Enter: / usr/pgsql-9.4/bin/postgresql94-setup initdb
Enter and initialize the database. (if you use other versions of PostgreSQL, you need to replace 9.4 and 94 with corresponding numbers.)
(skip the following two steps if firewalld Firewall is not installed)
Input: firewall-cmd-- add-service=postgresql-- permanent
Enter and open the firewall.
Input: firewall-cmd-reload
Enter and restart the firewall.
Change the default PostgreSQL user password
After PostgreSQL is installed, a user is created named postgres.
Input: su-postgres
Enter and switch to the user.
Input: psql-U postgres
Enter and log in to the database.
Input: ALTER USER postgres with encrypted password 'abc123'
(don't miss ";") enter and set the password of the default user postgre. Here the password is abc123, which can be changed by yourself.
Enter:\ Q
Enter and exit the database.
Input: exit
Enter and exit the user.
4. Configure remote access
Input: vi / var/lib/pgsql/9.4/data/postgresql.conf
Enter to enter the document content. (if you use other versions of PostgreSQL, you need to replace 9.4 with the corresponding version.)
Scroll down the cursor to find listen_addresses.
Press I key to enter "insert edit mode" and remove the # before "listen_address" to make the configuration parameter effective.
If you want to be open to all IP, just change localhost to *.
If you want to open only part of the IP, separate multiple IP with (comma + space).
When you are finished editing, press ESC and enter:: wq
Enter and "Save exit" document.
Input: vi / var/lib/pgsql/9.4/data/pg_hba.conf
Enter to enter the document content. (if you use other versions of PostgreSQL, you need to replace 9.4 with the corresponding version.)
Move the cursor to the bottom.
Press the I key to enter insert edit mode and add an IP that allows connections under the IPv4 local connections.
If you want to allow all IPv4 addresses, add a line: host all all 0.0.0.0 md5
The IPv6 method is similar.
When you are finished editing, press ESC and enter:: wq
Enter and "Save exit" document.
Input: systemctl restart postgresql-9.4.service
Enter and restart the postgressql service. (if you use other versions of PostgreSQL, you need to replace 9.4 with the corresponding version.)
At this point, the postgreSQL database has been successfully installed, so use a visual tool to connect.
PostgreSQL master-slave stream replication deployment
172.16.125.201 deploy the primary server
172.16.125.200 deployment from the server
Master server configuration
one. First, you need to create a database user for master-slave synchronization. Create the user replica and grant login and replication permissions.
Input: su-postgres
Enter and switch to the user.
Input: psql-U postgres
Enter and log in to the database.
Input: CREATE ROLE replica login replication encrypted password 'replica'
two。 Modify pg_hba.conf to allow replica users to synchronize.
Input: vi / var/lib/pgsql/9.4/data/pg_hba.conf
Enter to enter the document content.
Press the I key to enter insert edit mode and add two lines of configuration below IPv4 local connections.
Allow 200 to connect to the primary server:
Host all all 172.16.125.200/32 trust
Allow 200 to use the replica user to copy:
Host replication replica 172.16.125.200/32 md5
If you don't understand, technical documentation supports
When you are finished editing, press ESC and enter:: wq
Enter and "Save exit" document.
3. Modify postgresql.conf
Input: vi / var/lib/pgsql/9.4/data/postgresql.conf
Enter to enter the document content.
Press I to enter insert Edit Mode and modify the following configuration.
Monitor all IP:
Listen_addresses ='*'
Allow archiving:
Archive_mode = on
Use this command to archive the logfile segment:
Archive_command ='cp% p / opt/pgsql/pg_archive/%f'
Wal_level = hot_standby
This setting allows a maximum of several stream replication connections, almost a few from, just a few:
Max_wal_senders = 2
Sets the maximum number of xlog retained for stream replication:
Wal_keep_segments = 256
Set the timeout for data sent by the stream replication host:
Wal_sender_timeout = 60s
Note that the max_connections of the slave library must be greater than that of the master library:
Max_connections = 100
When you are finished editing, press ESC and enter:: wq
Enter and "Save exit" document.
Input: systemctl restart postgresql-9.4.service
Enter and restart the postgressql service.
4. Test 201 can connect to the 200 database. Run the following command on 201:
Enter: psql-h 172.16.125.200-U postgres
Enter and enter the password for the 200 database
Enter and connect to the 200 database
Configure from the server
1. Copy data from master node to slave node
Input: su-postgres
Enter and switch to the user
Enter: rm-rf / var/lib/pgsql/9.4/data/*
Enter to empty all the data in the data directory.
Input: pg_basebackup-h 172.16.125.201-U replica-D / var/lib/pgsql/9.4/data-X stream-P
Enter to copy data from 201 to 201 (basic backup)
Input: mkdir / opt/pgsql
Enter and create a pgsql folder
Input: mkdir / opt/pgsql/pg_archive
Enter and create a pg_archive folder
two。 Configure recovery.conf
Enter:
Cp / usr/pgsql-9.4/share/recovery.conf.sample / var/lib/pgsql/9.4/data/recovery.conf
Enter, copy recovery.conf
Input: vi / var/lib/pgsql/9.4/data/recovery.conf
Enter to enter the document content.
Press I to enter insert Edit Mode and modify the following configuration.
Indicates that the node is from the server:
Standby_mode = on
Information about the primary server and the users connected:
Primary_conninfo = 'host=172.16.125.201 port=5432 user=replica password=replica'
Recovery_target_timeline = 'latest'
When you are finished editing, press ESC and enter:: wq
Enter and "Save exit" document.
3. Configure postgresql.conf
Input: vi / var/lib/pgsql/9.4/data/postgresql.conf
Enter to enter the document content.
Press I to enter insert Edit Mode and modify the following configuration.
Wal_level = hot_standby
Generally speaking, for applications that check more than write, the maximum number of connections from the library is relatively large:
Max_connections = 1000
This indicates that this machine is not only used for data archiving, but also for data query:
Hot_standby = on
Maximum delay time for data stream backup:
Max_standby_streaming_delay = 30s
How often do you report the status of slaves to the master, and set the maximum interval:
Wal_receiver_status_interval = 10s
If there is an incorrect data replication, whether to give feedback to the master:
Hot_standby_feedback = on
When you are finished editing, press ESC and enter:: wq
Enter and "Save exit" document.
Input: systemctl restart postgresql-9.4.service
Enter and restart the postgressql service.
At this point, the PostgreSQL master-slave stream replication installation and deployment is complete, so test it with a visual tool.
Insert or delete data on the primary server (201)
The corresponding changes can be seen from the server (200).
You can only query from the server (200), not insert or delete.
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: 267
*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.