Skip to content

Sådan opsættes Multi-Master PostgreSQL Replikation på Ubuntu 22.04

Netcloud24
Cloud Infrastructure Expert
NetCloud24 Expert Guides Open the dedicated video page

Video transcript: NetCloud24 Expert Guides. Practical knowledge for a reliable cloud. Cloud and VPS expertise, security, performance, and step-by-step tutorials. Learn, deploy, and keep building with NetCloud24.

 

 

 

I denne vejledning vil vi gennemgå, hvordan du kan opsætte Multi-Master PostgreSQL replikation på en Ubuntu 22.04-server. Multi-Master replikation giver dig mulighed for at have flere PostgreSQL-servere, der kan skrive data, hvilket øger tilgængelighed og skalerbarhed. Denne installation kan være særligt nyttig for brugere af en VPS-server.

Forudsætninger

  • Ubuntu 22.04 installeret på dine servere.
  • Root-adgang eller sudo-rettigheder.
  • En aktiv internetforbindelse.
  • PostgreSQL installeret på alle servere.

Trin 1: Opdater systemet

Først skal du opdatere dit system for at sikre, at alle pakker er opdaterede:

sudo apt update && sudo apt upgrade -y

Trin 2: Installer PostgreSQL

Installer PostgreSQL, hvis det ikke allerede er installeret:

sudo apt install postgresql postgresql-contrib -y

Trin 3: Konfigurer PostgreSQL til replikation

Rediger konfigurationsfilen for PostgreSQL:

sudo nano /etc/postgresql/14/main/postgresql.conf

Tilføj eller ændre følgende indstillinger:

listen_addresses = '*'
wal_level = logical
max_replication_slots = 10
max_wal_senders = 10
hot_standby = on

Trin 4: Konfigurer pg_hba.conf

Tillad replikation fra de andre servere ved at redigere pg_hba.conf:

Visual overview of Sådan opsættes Multi-Master PostgreSQL Replikation på Ubuntu 22.04
Visual overview: Sådan opsættes Multi-Master PostgreSQL Replikation på Ubuntu 22.04
sudo nano /etc/postgresql/14/main/pg_hba.conf

Tilføj følgende linjer for at tillade replikation:

host replication all 192.168.1.0/24 md5

Trin 5: Genstart PostgreSQL

Genstart PostgreSQL-tjenesten for at anvende ændringerne:

sudo systemctl restart postgresql

Trin 6: Opret replikationsbruger

Log ind på PostgreSQL som superbruger og opret en replikationsbruger:

sudo -u postgres psql
CREATE ROLE replicator WITH REPLICATION LOGIN PASSWORD 'your_password';

Trin 7: Opsætning af Multi-Master Replikation

For hver server, skal du køre følgende kommandoer for at opsætte replikationen:

SELECT pg_create_physical_replication_slot('slot_name');

Trin 8: Test Replikationen

Tjek status for replikationen ved at logge ind på PostgreSQL og køre:

SELECT * FROM pg_stat_replication;

Afslutning

Du har nu opsat Multi-Master PostgreSQL replikation på Ubuntu 22.04. Denne løsning kan være særligt nyttig for dem, der ønsker høj tilgængelighed og skalerbarhed fra en VPS-server.

“`

Windows VPS Deutschland

Windows VPS España

Windows VPS Nederland

Key topics covered in Sådan opsættes Multi-Master PostgreSQL Replikation på Ubuntu 22.04
Key topics covered in this NetCloud24 guide.

Windows VPS Italia

Windows VPS Portugal

VPS Windows Italia

Windows VPS

Windows VPS

Windows VPS Sverige

Windows VPS Norge

Windows VPS

Windows VPS Türkiye

Practical checklist for Sådan opsættes Multi-Master PostgreSQL Replikation på Ubuntu 22.04
Practical checklist for applying the guidance in this article.

Windows RDS (Remote Desktop Services)

Windows VPS

Sådan opsættes Multi-Master PostgreSQL Replikation på Ubuntu 22.04
Sådan opsættes Multi-Master PostgreSQL Replikation på Ubuntu 22.04
Explore more

More on this topic

Netcloud24
Netcloud24
Cloud Infrastructure Expert · NetCloud24

Comments are closed.