PostgreSQL שכפול עבדים רב
en:PostgreSQL replication slaves multi
ro:PostgreSQL replicare sclavi multi
ru:PostgreSQL репликации рабы multi
pl:PostgreSQL replikacji niewolników multi
ja:PostgreSQL のレプリケーション スレーブ マルチ
ar:كيو النسخ المتماثل العبيد متعددة
zh:PostgreSQL 复制奴隶多
de:PostgreSQL Replikation Sklaven multi
nl:PostgreSQL replicatie slaven multi
it:PostgreSQL replica schiavi multi
pt:Multi de escravos de replicação PostgreSQL
es:PostgreSQL replicación esclavos multi
fr:Replication PostgreSQL multi slaves
מאמר זה הוא התוצאה של תרגום אוטומטי המבוצע על ידי תוכנה. אתה יכול להציג את מקור המאמר כאן.
מבוא | _. _. דף זה עוסק מימוש שכפול אסינכרוני PostgreSQL זרימה עם אדון אחד, שני עבדים. סלאבי שלנו יהיה מוגדר בתור המתנה חם, זאת אומרת שזה יהיה ניתן לבצע שאילתות | _. _. לקריאה בלבד | _. _. על אלה.
בהקשר של יישום זה | _. _. יש לנו | _. _. דביאן שרתים | _. _. עדכון | _. _. ואז נחבר ql | _. _. אנו מפעילים את התצוגה המורחבת, שנבדוק שלנו שכפול | _. _. יש לנו כל כך הרבה שלנו | _. _. שכפול עם שני שרתים סלאביות שלנו | _. _. | _. _. ו | _. _. תמיד מחובר ql במאסטר, צור מסד נתונים של מבחן | _. _. | _. _. | _. _. כדי לאשר כי השכפול הוא פונקציונלי | _. _. בדוק כך שמסד הנתונים הוא טוב משוכפלים על שלנו | _. _. סלאביים | _. _. טוב אז אוטומטית שכפול מסד הנתונים שיצרנו על המאסטר-סלאבי שני שלנו. | _. _. יהיה האדון שלנו | _. _. | _. _. יהיה עבד | _. _. Postgres | _. _. יהיה עבד השני | _. _. ציין הזמנות יהיה לעקור כאשר הם נמצאים לפניו של | _. _. ואני כמשתמש המערכת כאשר הם נמצאים לפניו של | _. _. התקנת PostgreSQL וטרום-תצורה של כל שרתי שלושה: _! _ | כל ההזמנות של החלק הזה הם לעשות על כל אחד השרתים. (כצעד ראשון, מומלץ יש קובץ | _. _. עם חיבורים לכל שרת, ככה: _! _ | באמצעות התאמת עם שפורסמו את כתובות ה-ip של שרתי משלך | _. _. להוסיף הגשת אפט PostgreSQL | _. _. אנו מייבאים את המפתח הציבורי של הפיקדון | _. _. אנו מעדכנים את המטמון מתאים לקחת בחשבון הפיקדון | _. _. אנו מתקינים את החבילה ql | _. _. התקנת הגרסה היציבה האחרונה היא | _. _. בזמן כתיבת | _. _. הוא קובע סיסמה | _. _. של הבחירה שלו אבל מאובטחת | _. _. יוצרת ssh מפתח זוג | _. _. ללא ביטוי | _. _. עבור המשתמש postgres מערכת | _. _. . קיבלנו postgres משתמש מאז ובין הציבור של כל שרת ssh מפתח | _. _. מאז השרת הראשון | _. _. Postgres | _. _. במקרה שלנו: _! _ | השנייה | _. _. Postgres | _. _. בשבילנו | _. _. ו troisiseme | _. _. Postgres | _. _. מהרגע הראשון והשלישי בשרת | _. _. שלישי אל השרת הראשון והשני | _. _. קביעת התצורה של תבנית הבסיס: _! _ | האם רק האדון: _! _ | Postgres | _. _. במקרה שלנו: _! _ | אנו יוצרים את התפקיד | _. _. משתמש בשכפול: _! _ | הערה: _! _ | אנו מגדירים גבול חיבור של | _. _. . כי יש לנו | _. _. סלאביים | _. _. נוכל לערוך את קובץ ההגדרות הראשי של postgresql | _. _. כדי להגדיר את ההנחיות הבאות: _! _ | הערה: _! _ | אנו מפעילים בארכיון לשרת השני שלנו | _. _. התאמה אישית של ה-IP של השרת שלך | _. _. כי הזהירות עוד יותר, אבל זה איננו חובה. אנחנו גם להגדיר את הפרמטרים hot_standby, ובכן להתעלם ממנו על המאסטר, ובמקרה זה צריך להורידו לדרגת עבד בעתיד. ) היא מפרסמת כעת את קובץ אימות postgresql | _. _. כדי להוסיף את האישור המשתמש שלנו של שכפול להתחבר מהמחשב שלנו סלאבית או את השורה הבאה בסוף הקובץ: _. _ | בבקשה להתאים את הקו הזה לפי שם המשתמש שלך שכפול, רשת | _. _. או כתובות ip בהתאמה: _! _ | של סלאבית שלך | _. _. הפעל מחדש את שירות postgresql לקחת בחשבון את תצורת שלנו | _. _. בבסיס | _. _. פעולה זו מבטיחה כי השירות הופעל בהצלחה | _. _. קביעת תצורה של סלאבית | _. _. על העבד הראשון | _. _. בואו נפסיק את השירות postgresql | _. _. נוכל לערוך את קובץ ההגדרות הראשי של postgresql | _. _. כדי להגדיר זאת הנחיות בתור הבסיס, על ידי התאמת רק כתובת ה-IP של העבד הראשון על ידי העבד השני ב- rsync בארכיון הפקודה אם ברצונך להפעיל אותו גם | _. _. היא מפרסמת כעת את קובץ אימות postgresql | _. _. להוספת ההרשאות של המשתמש בשכפול שלנו להתחבר מהשרתים אחרים: _! _ | שהוא יעשה את זה. למקרה העבדים צריך קידום מאסטר | _. _. הערה: _! _ | בתצורה זו דומה לזו של האדון שלנו מאפשרת לקדם בקלות זה עבד בתור אדון במקרה הצורך.
עבור פעולות שלמטה, להיכנס בתור משתמש מערכת postgres | _. _. אנו יוצרים את ספריית היעד של החומה לאכול את התפוחים של הארכיונים מאסטר | _. _. נסיר את ספריית נתונים postgresql | _. _. זה הופך את הגיבוי הבסיס | _. _. התאמה אישית של ה-ip של המאסטר שלך ואת שם המשתמש שלך של שכפול :
, תתבקש להזין את הסיסמה של המשתמש שלך של שכפול | _. _. קביעת התצורה של שכפול על-ידי יצירת הקובץ | _. _. עם הפרמטרים הבאים: _! _ | הערה: _! _ | הקובץ המפעיל הוא הקובץ אנו יוצרים כאשר אנחנו רוצים שכפול עצירה העבד שלו ומתחיל לקבל את כתבי הקודש, כאשר אנחנו רוצים לקדם אותו כמאסטר. לפני קידום לקריסה העבד של אדונו, נא ודא כי הבסיס הראשונית תעלה לא כדי להימנע מכל שחיתות. 3 שורש, נחזור. ונתחיל את השירות: _! _ | פעולה זו מבטיחה כי השירות הופעל בהצלחה | _. _. אם נחבר האדון שלנו, אנחנו כבר יכולים לבדוק שלנו שכפול בין האדון העבדים הראשון הוא פונקציונלי | _. _. זה מתחבר האדון שלנו, אנחנו מעבירים postgres מערכת המשתמש | _. _. ואז נחבר postgresql | _. _. אנו מפעילים את התצוגה המורחבת, שנבדוק שלנו שכפול | _. _. שלנו שכפול אסינכרוני זרימה עם העבד הראשון שלנו הוא היטב עשה. בשלב זה יש לנו בסיס שכפול | _. _. העבד קלאסי | _. _. סינגל עבד הזרמת אסינכרוני | _. _. על העבד השני | _. _. לחזור על אותו מה נעשה העבד הראשון ללא ספק בהתאמת שלה hostname בכתובת הקובץ recovery.conf ו- ip לפי סדר ביצוע הצ'ק-אין בקובץ התצורה הראשי, אם גם אתם רוצים לאפשר אחסון בארכיון על העבדים השני. 8 (ביקורת ובדיקה רב שלנו לשלוט שכפול הסלאבים | _. _. זה מקשר המאסטר, אתה מחובר המשתמש postgres) :
Postgres01 (10.1.1.75) : כדי להסיר אותו, מאז המאסטר
Postgres02 (10.1.1.90) :
Postgres03 (10.1.1.199) :
"#" "$".
/etc/hosts () :
# cat /etc/hosts 127.0.0.1 localhost 10.1.1.75 postgres01 10.1.1.90 postgres02 10.1.1.199 postgres03
:
# echo "deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main" > /etc/apt/sources.list.d/postgres.list
:
# gpg --keyserver pgpkeys.mit.edu --recv-key 7FCC7D46ACCC4CF8 && gpg -a --export 7FCC7D46ACCC4CF8 | apt-key add -
gpg: directory `/root/.gnupg' created
gpg: new configuration file `/root/.gnupg/gpg.conf' created
gpg: WARNING: options in `/root/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/root/.gnupg/secring.gpg' created
gpg: keyring `/root/.gnupg/pubring.gpg' created
gpg: requesting key ACCC4CF8 from hkp server pgpkeys.mit.edu
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key ACCC4CF8: public key "PostgreSQL Debian Repository" imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
OK
:
# apt-get update
( 9.5 ) :
# apt-get install postgresql
() () :
# passwd postgres
# su - postgres
$ ssh-keygen
:
(postgres01 ) (postgres02 ) (postgres03) :
root@postgres01:~# su - postgres
postgres@postgres01:~$ ssh-copy-id postgres02
postgres@postgres01:~$ ssh-copy-id postgres03
:
root@postgres02:~# su - postgres
postgres@postgres02:~$ ssh-copy-id postgres01
postgres@postgres02:~$ ssh-copy-id postgres03
:
root@postgres03:~# su - postgres
postgres@postgres03:~$ ssh-copy-id postgres01
postgres@postgres03:~$ ssh-copy-id postgres02
(postgres01 ) :
/ :
# su - postgres
$ psql -c "CREATE USER repuser REPLICATION LOGIN CONNECTION LIMIT 2 ENCRYPTED PASSWORD '<mot de passe repuser>';"
: 2 2
/etc/postgresql/9.5/main/postgresql.conf :
listen_addresses = '*'
wal_level = hot_standby
archive_mode = on
archive_command = 'rsync -av %p postgres@<ip du premier slave>:/var/lib/postgresql/wal_archive/%f'
max_wal_senders = 2
wal_keep_segments = 256
hot_standby = on
: ()
/etc/postgresql/9.5/main/pg_hba.conf :
hostssl replication repuser <ip du réseau de vos serveurs>/24 md5
()
() :
# systemctl restart postgresql
:
root@postgres01:~# systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled)
Active: active (exited) since Thu 2016-06-02 12:06:28 CEST; 22s ago
Process: 77056 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 77056 (code=exited, status=0/SUCCESS)
root@postgres01:~# ps -u postgres u
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
postgres 77038 0.0 4.4 227300 21836 ? S 12:06 0:00 /usr/lib/postgresql/9.5/bin/postgres -D /var/lib/postgresql/9.
postgres 77040 0.0 0.8 227300 4160 ? Ss 12:06 0:00 postgres: checkpointer process
postgres 77041 0.0 1.0 227300 4968 ? Ss 12:06 0:00 postgres: writer process
postgres 77042 0.0 1.7 227300 8776 ? Ss 12:06 0:00 postgres: wal writer process
postgres 77043 0.0 1.3 227728 6708 ? Ss 12:06 0:00 postgres: autovacuum launcher process
postgres 77044 0.0 0.6 82244 3392 ? Ss 12:06 0:00 postgres: archiver process
postgres 77045 0.0 0.8 82244 4244 ? Ss 12:06 0:00 postgres: stats collector process
:
# systemctl stop postgresql
/etc/postgresql/9.5/main/postgresql.conf :
listen_addresses = '*'
wal_level = hot_standby
archive_mode = on
archive_command = 'rsync -av %p postgres@<ip du second slave>:/var/lib/postgresql/wal_archive/%f'
max_wal_senders = 2
wal_keep_segments = 256
hot_standby = on
/etc/postgresql/9.5/main/pg_hba.conf () :
hostssl replication repuser <ip du réseau de vos serveurs>/24 md5
:
:
# su – postgres
:
$ mkdir /var/lib/postgresql/wal_archive
:
$ rm -rf /var/lib/postgresql/9.5/main
() :
$ pg_basebackup -h <ip de votre master> -D /var/lib/postgresql/9.5/main -U repuser -v -P --xlog
/var/lib/postgresql/9.5/main/recovery.conf :
standby_mode = on
primary_conninfo = 'host=<ip de votre master> port=5432 user=repuser password=<mot de passe de repuser> sslmode=require application_name=<hostname de votre slave>'
trigger_file = '/var/lib/postgresql/9.5/postgres.trigger'
:
:
# systemctl start postgresql
:
# systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled)
Active: active (exited) since Thu 2016-06-02 12:53:42 CEST; 1min 6s ago
Process: 8894 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 8894 (code=exited, status=0/SUCCESS)
# ps -u postgres u
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
postgres 8878 0.0 4.4 227308 21892 ? S 12:53 0:00 /usr/lib/postgresql/9.5/bin/postgres -D /var/lib/postgresql/9.
postgres 8879 0.0 1.1 227376 5700 ? Ss 12:53 0:00 postgres: startup process recovering 00000001000000000000000
postgres 8880 0.0 0.8 227308 4140 ? Ss 12:53 0:00 postgres: checkpointer process
postgres 8881 0.0 1.0 227308 5236 ? Ss 12:53 0:00 postgres: writer process
postgres 8882 0.0 0.6 82252 3316 ? Ss 12:53 0:00 postgres: stats collector process
postgres 8883 0.0 1.7 238064 8520 ? Ss 12:53 0:00 postgres: wal receiver process streaming 0/30003E0
:
:
# su - postgres
:
$ psql
:
postgres=# \x
Expanded display is on.
postgres=# select * from pg_stat_replication;
-[ RECORD 1 ]----+------------------------------
pid | 78879
usesysid | 16384
usename | repuser
application_name | postgres02
client_addr | 10.1.1.90
client_hostname |
client_port | 49009
backend_start | 2016-06-02 12:53:36.641823+02
backend_xmin |
state | streaming
sent_CRElocation | 0/30004C0
write_location | 0/30004C0
flush_location | 0/30004C0
replay_location | 0/30004C0
sync_priority | 0
sync_state | async
/ ()
:
# su – postgres
:
$ psql
:
postgres=# \x
Expanded display is on.
postgres=# select * from pg_stat_replication;
-[ RECORD 1 ]----+------------------------------
pid | 78879
usesysid | 16384
usename | repuser
application_name | postgres02
client_addr | 10.1.1.90
client_hostname |
client_port | 49009
backend_start | 2016-06-02 12:53:36.641823+02
backend_xmin |
state | streaming
sent_location | 0/5000140
write_location | 0/5000140
flush_location | 0/5000140
replay_location | 0/5000140
sync_priority | 0
sync_state | async
-[ RECORD 2 ]----+------------------------------
pid | 82725
usesysid | 16384
usename | repuser
application_name | postgres03
client_addr | 10.1.1.199
client_hostname |
client_port | 51754
backend_start | 2016-06-02 14:31:43.759683+02
backend_xmin |
state | streaming
sent_location | 0/5000140
write_location | 0/5000140
flush_location | 0/5000140
replay_location | 0/5000140
sync_priority | 0
sync_state | async
2 (postgres02 03).
(ex : checkrep) :
postgres=# CREATE DATABASE checkrep;
2 :
root@postgres02:~# su - postgres
postgres@postgres02:~$ psql
psql (9.5.3)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
checkrep | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
root@postgres03:~# su - postgres
postgres@postgres03:~$ psql
psql (9.5.3)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
checkrep | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
:
postgres=# DROP DATABASE checkrep;
הפעלת רענון אוטומטי של התגובות