亚洲中字慕日产2020,大陆极品少妇内射AAAAAA,无码av大香线蕉伊人久久,久久精品国产亚洲av麻豆网站

資訊專欄INFORMATION COLUMN

PostgreSQL10 一主多從 安裝實(shí)踐

IT那活兒 / 1358人閱讀
PostgreSQL10 一主多從 安裝實(shí)踐
[
1、環(huán)境
]

主機(jī)

操作系統(tǒng)

IP

數(shù)據(jù)庫

角色

同步方式

pg01

CentOS7.7

192.168.137.200

PostgreSQL10.10

-

pg02

CentOS7.7

192.168.137.201

PostgreSQL10.10

同步

pg03

CentOS7.7

192.168.137.202

PostgreSQL10.10

異步

所有主機(jī)已安裝好PostgreSQL數(shù)據(jù)庫軟件。


[
2、主從配置
]


2.1、主節(jié)點(diǎn)配置

初始化數(shù)據(jù)庫

initdb -D $PGDATA -E UTF8 --locale=C -U postgres –W


日志:

The files belonging to this database system will be owned by user "postgres".

This user must also own the server process.


The database cluster will be initialized with locale "C".

The default text search configuration will be set to "english".


Data page checksums are disabled.


Enter new superuser password:

Enter it again:


creating directory /pgsql/pgsql/data ... ok

creating subdirectories ... ok

selecting default max_connections ... 100

selecting default shared_buffers ... 128MB

selecting default timezone ... Asia/Shanghai

selecting dynamic shared memory implementation ... posix

creating configuration files ... ok

running bootstrap script ... ok

performing post-bootstrap initialization ... ok

syncing data to disk ... ok


WARNING: enabling "trust" authentication for local connections

You can change this by editing pg_hba.conf or using the option -A, or

--auth-local and --auth-host, the next time you run initdb.


Success. You can now start the database server using:


pg_ctl -D /pgsql/pgsql/data -l logfile start


2.2、修改配置文件

vi $PGDATA/postgresql.conf


listen_addresses   = *       # 監(jiān)聽所有ip

port              = 5432      # 監(jiān)聽端口

wal_level          = replica   # 該級別支持wal歸檔和復(fù)制

max_wal_senders    = 10        # 并發(fā)的從庫數(shù)量, 發(fā)送 wal 進(jìn)程數(shù)

wal_keep_segments  = 256       # 默認(rèn)是0,代表主庫wal日志文件保存的個(gè)數(shù),

# 可以防止主庫生成日志太快而被覆蓋的情況發(fā)生

wal_sender_timeout = 60s       # 流復(fù)制超時(shí)時(shí)間, 發(fā)送 wal 日志超時(shí)時(shí)間

max_connections    = 100       # 最大連接數(shù)

hot_standby        = on        # 設(shè)置為備庫時(shí)是否支持可讀

archive_mode       = on        # 開啟歸檔模式

archive_command    = cp %p $PGDATA/pg_archive/%f  # 歸檔動(dòng)作

synchronous_standby_names = pg02   # 指定備庫 pg02 為同步流復(fù)制


vi $PGDATA/pg_hba.conf

host    replication     repl           192.168.137.0/24        md5


創(chuàng)建歸檔目錄

mkdir$PGDATA/pg_archive


2.3、啟動(dòng)數(shù)據(jù)庫

pg_ctl -D $PGDATA -l $PGDATA/logfile start

waiting for server to start.... done

server started


查看日志

cat$PGDATA/logfile


查看進(jìn)程

ps-ef | grep postgres


2.4、創(chuàng)建復(fù)制賬戶

psql

CREATE ROLE repl LOGIN REPLICATION PASSWORD Yike_repl;


發(fā)現(xiàn)命令hang住

Ctrl+C

取消后發(fā)現(xiàn)報(bào)錯(cuò)如下

因?yàn)榕渲梦募镏付藀g02為同步流復(fù)制,但是pg02還不可用,所以報(bào)錯(cuò)。


雖然取消了,但是用戶已經(jīng)創(chuàng)建成功。


2.5、配置密碼文件


vi ~/.pgpass

192.168.137.200:5432:replication:repl:Yike_repl

192.168.137.201:5432:replication:repl:Yike_repl

192.168.137.202:5432:replication:repl:Yike_repl


chmod 600 ~/.pgpass



[
3、從庫配置
]


3.1、配置pg02從庫(同步)

復(fù)制主庫

pg_basebackup -h 192.168.137.200 -p 5432 -U repl -F p -P -X s -R -D $PGDATA

Password:


配置recovery.conf

vi $PGDATA/recovery.conf


standby_mode = on

primary_conninfo = host=192.168.137.200 port=5432 user=repl application_name=pg02

recovery_target_timeline = latest


配置postgresql.conf

vi $PGDATA/postgresql.conf


#synchronous_standby_names = pg02


配置密碼文件

vi ~/.pgpass

192.168.137.200:5432:replication:repl:Yike_repl

192.168.137.201:5432:replication:repl:Yike_repl

192.168.137.202:5432:replication:repl:Yike_repl


chmod 600 ~/.pgpass


啟動(dòng)pg02備庫

pg_ctl -D $PGDATA -l $PGDATA/logfile start


主庫查詢:

select pid, usename, client_addr, client_port, sync_state from pg_stat_replication;


從庫已經(jīng)成功連接到主庫,同步方式為sync


主庫創(chuàng)建測試表,發(fā)現(xiàn)不會(huì)再hang住了


從庫查看t1表


3.2、配置pg03從庫(異步)

步驟同3.1相同

pg_basebackup -h 192.168.137.200 -p 5432 -U repl -F p -P -X s -R -D $PGDATA

Password:

122783/122783 kB (100%), 1/1 tablespace


vi $PGDATA/recovery.conf


standby_mode = on

primary_conninfo = host=192.168.137.200 port=5432 user=repl application_name=pg03

recovery_target_timeline = latest


vi $PGDATA/postgresql.conf


#synchronous_standby_names = pg02


vi ~/.pgpass

192.168.137.200:5432:replication:repl:Yike_repl

192.168.137.201:5432:replication:repl:Yike_repl

192.168.137.202:5432:replication:repl:Yike_repl


chmod 600 ~/.pgpass


pg_ctl -D $PGDATA -l $PGDATA/logfile start


psql

dt t1


主庫查詢發(fā)現(xiàn)兩個(gè)從庫都已連接到主庫


[
4、主從切換
]


PostgreSQL是通過PGDATA目錄下的recovery.conf文件確定主從角色的,啟動(dòng)時(shí)如果存在該文件,則會(huì)以從庫角色啟動(dòng),不存在則以主庫角色啟動(dòng)。主從切換后,新從庫的recovery.conf文件會(huì)自動(dòng)重命名為recovery.done。


4.1、角色確認(rèn)

pg_controldata $PGDATA | grep state


pg01:


pg02:


pg03:


當(dāng)前pg01 為主庫,pg02、pg03為從庫


4.2、模擬主庫故障

pg01執(zhí)行

pg_ctl -D $PGDATA stop

waiting for server to shut down..... done

server stopped


此時(shí)從庫日志報(bào)錯(cuò)



4.3、提升pg02為主庫

pg02執(zhí)行

pg_ctl -D $PGDATA promote


pg_controldata $PGDATA | grep state


角色已切換從主庫

recovery文件已自動(dòng)重命名


4.4、pg03指向新主庫

修改recovery文件

vi $PGDATA/recovery.conf

standby_mode = on

primary_conninfo = host=192.168.137.201 port=5432 user=repl application_name=pg03

recovery_target_timeline = latest


重啟數(shù)據(jù)庫

pg_ctl -D $PGDATA -l $PGDATA/logfile restart


日志不再報(bào)錯(cuò)


pg02執(zhí)行:

select pid, usename, client_addr, client_port, sync_state from pg_stat_replication;


pg03已經(jīng)連接到新主庫


4.5、原主庫重建為從庫(同步)

修改原主庫參數(shù)

vi $PGDATA/postgresql.conf

#synchronous_standby_names = pg02


編輯recover文件

vi $PGDATA/recovery.conf


standby_mode = on

primary_conninfo = host=192.168.137.201 port=5432 user=repl application_name=pg01

recovery_target_timeline = latest


修改新庫參數(shù)

vi $PGDATA/postgresql.conf

synchronous_standby_names = pg01


pg_ctl –D $PGDATA reload


select pid, usename, client_addr, client_port, sync_state from pg_stat_replication;

主庫查詢發(fā)現(xiàn)兩個(gè)從庫都已連接到主庫

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://www.ezyhdfw.cn/yun/130106.html

相關(guān)文章

  • 面試官:咱們來聊一聊mysql主從延遲

    摘要:編輯器編輯器背景編輯器前段時(shí)間遇到一個(gè)線上問題,后來排查好久發(fā)現(xiàn)是因?yàn)橹鲝耐窖舆t導(dǎo)致的,所以今天寫一篇文章總結(jié)一下這個(gè)問題希望對你有用。編輯器幾句嘮叨編輯器大家好,我是小飯,一枚后端工程師。背景前段時(shí)間遇到一個(gè)線上問題,后來排查好久發(fā)現(xiàn)是因?yàn)橹鲝耐窖舆t導(dǎo)致的,所以今天寫一篇文章總結(jié)一下這個(gè)問題希望對你有用。如果覺得還不錯(cuò),記得加個(gè)關(guān)注點(diǎn)個(gè)贊哦思維導(dǎo)圖思維導(dǎo)圖常見的主從架構(gòu)隨著日益增長的訪...

    EasonTyler 評論0 收藏0
  • HotFrameLearning Redis_01_簡介

    摘要:收到后則會(huì)調(diào)用指令一個(gè)子進(jìn)程來持久化存儲(chǔ)的數(shù)據(jù),在的持久化的這個(gè)短短期間內(nèi),的指令則存儲(chǔ)到內(nèi)存中。經(jīng)過官網(wǎng)的測試性能結(jié)果達(dá)到的。 HotFrameLearning Redis_01_簡介 - 一、大致介紹 1、介紹Redis之前,我有一堆的疑問,Redis是什么?有什么用?它能干什么?有什么特性?能解決我們?nèi)粘5哪男﹩栴}? 為什么要用Redis?Redis好在哪里?除了Redis...

    focusj 評論0 收藏0
  • Yii2 數(shù)據(jù)庫復(fù)制和讀寫分離

    摘要:前言許多數(shù)據(jù)庫支持?jǐn)?shù)據(jù)庫復(fù)制來獲得更好的數(shù)據(jù)庫可用性,以及更快的服務(wù)器響應(yīng)時(shí)間,減少數(shù)據(jù)庫的壓力。通過數(shù)據(jù)庫復(fù)制功能,數(shù)據(jù)從所謂的主服務(wù)器被復(fù)制到從服務(wù)器。 前言 許多數(shù)據(jù)庫支持?jǐn)?shù)據(jù)庫復(fù)制來獲得更好的數(shù)據(jù)庫可用性,以及更快的服務(wù)器響應(yīng)時(shí)間,減少數(shù)據(jù)庫的壓力。通過數(shù)據(jù)庫復(fù)制功能,數(shù)據(jù)從所謂的主服務(wù)器被復(fù)制到從服務(wù)器。主服務(wù)器做增刪改,而從服務(wù)器做查詢。 讀寫分離前提條件:linux數(shù)據(jù)庫...

    William_Sang 評論0 收藏0

發(fā)表評論

0條評論

最新活動(dòng)
閱讀需要支付1元查看
<