postgresql多例項建立與Slony-I複製配置
[[email protected] slony1-2.2.5]$
[[email protected] slony1-2.2.5]$ ./configure --with-perltools
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking which template to use... linux
configure: using CFLAGS=
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for ld used by GCC... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for perl... /usr/bin/perl
checking for tar... /bin/tar
checking for bison... bison -y
checking for sed... sed
checking for the pthreads library -lpthreads... no
checking whether pthreads work without any flags... no
checking whether pthreads work with -Kthread... no
checking whether pthreads work with -kthread... no
checking for the pthreads library -llthread... no
checking whether pthreads work with -pthread... yes
checking for joinable pthread attribute... PTHREAD_CREATE_JOINABLE
checking if more special flags are required for pthreads... no
checking for cc_r... gcc
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking fcntl.h usability... yes
checking fcntl.h presence... yes
checking for fcntl.h... yes
checking limits.h usability... yes
checking limits.h presence... yes
checking for limits.h... yes
checking stddef.h usability... yes
checking stddef.h presence... yes
checking for stddef.h... yes
checking sys/socket.h usability... yes
checking sys/socket.h presence... yes
checking for sys/socket.h... yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking for inttypes.h... (cached) yes
checking for gettimeofday... yes
checking for dup2... yes
checking for alarm... yes
checking for memset... yes
checking for select... yes
checking for strdup... yes
checking for strerror... yes
checking for strtol... yes
checking for strtoul... yes
checking for int32_t... yes
checking for uint32_t... yes
checking for u_int32_t... yes
checking for int64_t... yes
checking for uint64_t... yes
checking for u_int64_t... yes
checking for size_t... yes
checking for ssize_t... yes
checking for POSIX signal interface... yes
checking for flex... /usr/bin/flex
configure: using
checking if you have requested slony1-engine building... yes
checking for pg_config... /usr/local/pgsql/bin/pg_config
pg_config says pg_bindir is /usr/local/pgsql9.5.1/bin/
pg_config says pg_libdir is /usr/local/pgsql9.5.1/lib/
pg_config says pg_includedir is /usr/local/pgsql9.5.1/include/
pg_config says pg_pkglibdir is /usr/local/pgsql9.5.1/lib/
pg_config says pg_includeserverdir is /usr/local/pgsql9.5.1/include/server/
checking for correct version of PostgreSQL... pg_config says pg_sharedir is /usr/local/pgsql9.5.1/share/
checking for PQunescapeBytea in -lpq... yes
checking libpq-fe.h usability... yes
checking libpq-fe.h presence... yes
checking for libpq-fe.h... yes
checking postgres.h usability... yes
checking postgres.h presence... yes
checking for postgres.h... yes
checking for utils/typcache.h... yes
checking for plpgsql.so... yes
checking for postgresql.conf.sample... skipped due to override
checking for PQputCopyData in -lpq... yes
checking for PQsetNoticeReceiver in -lpq... yes
checking for PQfreemem in -lpq... yes
checking PostgreSQL for thread-safety... PQisthreadsafe() true
checking for ScanKeywordLookup... yes, and it takes arguments
checking for typenameTypeId... checking for typenameTypeId... yes, and it takes 2 arguments
checking for GetActiveSnapshot... yes
checking for ScanKeywordLookup... no
checking for GetConfigOptionByName... checking for GetConfigOptionByName... yes, and it takes 2 arguments
checking for set_config_option... yes, and it takes arguments
yes, and it takes arguments
yes, and it takes 8 arguments
checking for set_config_option... checking for standard_conforming_strings... yes
checking whether GetTopTransactionId is declared... yes
checking for LookupExplicitNamespace 2 args... yes, and it takes 2 arguments
checking for DBD::Pg... checking if you have requested documentation building... no
configure: creating ./config.status
config.status: creating Makefile.global
config.status: creating GNUmakefile
config.status: creating slony1.spec
config.status: creating Makefile.port
config.status: creating config.h
[[email protected] slony1-2.2.5]$
[[email protected] slony1-2.2.5]$
[[email protected] slony1-2.2.5]$ make
make[1]: Entering directory `/usr/local/src/slony1-2.2.5/src'
make[2]: Entering directory `/usr/local/src/slony1-2.2.5/src/parsestatements'
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -I/usr/local/pgsql9.5.1/include/ -c -o test-scanner.o test-scanner.c
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -I/usr/local/pgsql9.5.1/include/ -c -o scanner.o scanner.c
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -o test-scanner test-scanner.c scanner.o
./test-scanner < /dev/null > emptytestresult.log
./test-scanner < ./test_sql.sql > test_sql.log
./test-scanner < ./cstylecomments.sql > cstylecomments.log
make[2]: Leaving directory `/usr/local/src/slony1-2.2.5/src/parsestatements'
make[2]: Entering directory `/usr/local/src/slony1-2.2.5/src/slon'
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -pthread -I../.. -I../../src/slon -I/usr/local/pgsql9.5.1/include/ -c -o slon.o slon.c
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -pthread -I../.. -I../../src/slon -I/usr/local/pgsql9.5.1/include/ -c -o runtime_config.o runtime_config.c
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -pthread -I../.. -I../../src/slon -I/usr/local/pgsql9.5.1/include/ -c -o local_listen.o local_listen.c
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -pthread -I../.. -I../../src/slon -I/usr/local/pgsql9.5.1/include/ -c -o remote_listen.o remote_listen.c
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -pthread -I../.. -I../../src/slon -I/usr/local/pgsql9.5.1/include/ -c -o remote_worker.o remote_worker.c
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -pthread -I../.. -I../../src/slon -I/usr/local/pgsql9.5.1/include/ -c -o sync_thread.o sync_thread.c
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -pthread -I../.. -I../../src/slon -I/usr/local/pgsql9.5.1/include/ -c -o monitor_thread.o monitor_thread.c
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -pthread -I../.. -I../../src/slon -I/usr/local/pgsql9.5.1/include/ -c -o cleanup_thread.o cleanup_thread.c
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -pthread -I../.. -I../../src/slon -I/usr/local/pgsql9.5.1/include/ -c -o scheduler.o scheduler.c
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -pthread -I../.. -I../../src/slon -I/usr/local/pgsql9.5.1/include/ -c -o dbutils.o dbutils.c
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -pthread -I../.. -I../../src/slon -I/usr/local/pgsql9.5.1/include/ -c -o conf-file.o conf-file.c
conf-file.l: In function ‘ProcessConfigFile’:
conf-file.l:272: warning: label ‘cleanup_exit’ defined but not used
conf-file.l: At top level:
conf-file.c:1219: warning: ‘input’ defined but not used
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -pthread -I../.. -I../../src/slon -I/usr/local/pgsql9.5.1/include/ -c -o confoptions.o confoptions.c
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -pthread -I../.. -I../../src/slon -I/usr/local/pgsql9.5.1/include/ -c -o misc.o misc.c
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -pthread -I../.. -I../../src/slon -o slon slon.o runtime_config.o local_listen.o remote_listen.o remote_worker.o sync_thread.o monitor_thread.o cleanup_thread.o scheduler.o dbutils.o conf-file.o confoptions.o misc.o ../parsestatements/scanner.o -pthread -L/usr/local/pgsql9.5.1/lib/ -lpq -Wl,-rpath,/usr/local/pgsql9.5.1/lib/
make[2]: Leaving directory `/usr/local/src/slony1-2.2.5/src/slon'
make[2]: Entering directory `/usr/local/src/slony1-2.2.5/src/slonik'
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -I../.. -DPGSHARE="\"/usr/local/pgsql9.5.1/share/\"" -I/usr/local/pgsql9.5.1/include/ -c -o slonik.o slonik.c
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -I../.. -DPGSHARE="\"/usr/local/pgsql9.5.1/share/\"" -I/usr/local/pgsql9.5.1/include/ -c -o dbutil.o dbutil.c
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -I../.. -DPGSHARE="\"/usr/local/pgsql9.5.1/share/\"" -I/usr/local/pgsql9.5.1/include/ -c -o parser.o parser.c
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -I../.. -DPGSHARE="\"/usr/local/pgsql9.5.1/share/\"" -I/usr/local/pgsql9.5.1/include/ -c -o scan.o scan.c
scan.c:2066: warning: ‘input’ defined but not used
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -I../.. -DPGSHARE="\"/usr/local/pgsql9.5.1/share/\"" slonik.o dbutil.o parser.o ../parsestatements/scanner.o scan.o -L/usr/local/pgsql9.5.1/lib/ -lpq -Wl,-rpath,/usr/local/pgsql9.5.1/lib/ -o slonik
make[2]: Leaving directory `/usr/local/src/slony1-2.2.5/src/slonik'
make[2]: Entering directory `/usr/local/src/slony1-2.2.5/src/backend'
cp ../misc/avl_tree.c avl_tree.c
cp ../misc/avl_tree.h avl_tree.h
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -I../.. -fpic -I/usr/local/pgsql9.5.1/include/server/ -c -o slony1_funcs.o slony1_funcs.c
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -I../.. -fpic -L/usr/local/pgsql9.5.1/lib/ -lpq -Wl,-rpath,/usr/local/pgsql9.5.1/lib/ -shared -o slony1_funcs.2.2.5.so slony1_funcs.o
make[2]: Leaving directory `/usr/local/src/slony1-2.2.5/src/backend'
make[2]: Entering directory `/usr/local/src/slony1-2.2.5/src/ducttape'
make[2]: Leaving directory `/usr/local/src/slony1-2.2.5/src/ducttape'
make[2]: Entering directory `/usr/local/src/slony1-2.2.5/src/slony_logshipper'
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -I../.. -DPGSHARE="\"/usr/local/pgsql9.5.1/share/\"" -I/usr/local/pgsql9.5.1/include/ -c -o slony_logshipper.o slony_logshipper.c
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -I../.. -DPGSHARE="\"/usr/local/pgsql9.5.1/share/\"" -I/usr/local/pgsql9.5.1/include/ -c -o dbutil.o dbutil.c
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -I../.. -DPGSHARE="\"/usr/local/pgsql9.5.1/share/\"" -I/usr/local/pgsql9.5.1/include/ -c -o ipcutil.o ipcutil.c
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -I../.. -DPGSHARE="\"/usr/local/pgsql9.5.1/share/\"" -I/usr/local/pgsql9.5.1/include/ -c -o parser.o parser.c
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -I../.. -DPGSHARE="\"/usr/local/pgsql9.5.1/share/\"" -I/usr/local/pgsql9.5.1/include/ -c -o scan.o scan.c
gcc -g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -I../.. -DPGSHARE="\"/usr/local/pgsql9.5.1/share/\"" slony_logshipper.o dbutil.o ipcutil.o parser.o ../parsestatements/scanner.o scan.o -L/usr/local/pgsql9.5.1/lib/ -lpq -Wl,-rpath,/usr/local/pgsql9.5.1/lib/ -o slony_logshipper
make[2]: Leaving directory `/usr/local/src/slony1-2.2.5/src/slony_logshipper'
make[1]: Leaving directory `/usr/local/src/slony1-2.2.5/src'
make[1]: Entering directory `/usr/local/src/slony1-2.2.5/tools'
for subdir in altperl ; do \
make -C $subdir all || exit; \
done
make[2]: Entering directory `/usr/local/src/slony1-2.2.5/tools/altperl'
make[2]: Leaving directory `/usr/local/src/slony1-2.2.5/tools/altperl'
make[1]: Leaving directory `/usr/local/src/slony1-2.2.5/tools'
All of Slony-I is successfully made. Ready to install
[[email protected] slony1-2.2.5]$
[[email protected] slony1-2.2.5]#
[[email protected] slony1-2.2.5]# make install
make[1]: Entering directory `/usr/local/src/slony1-2.2.5/src'
make[2]: Entering directory `/usr/local/src/slony1-2.2.5/src/parsestatements'
make[2]: Nothing to be done for `install'.
make[2]: Leaving directory `/usr/local/src/slony1-2.2.5/src/parsestatements'
make[2]: Entering directory `/usr/local/src/slony1-2.2.5/src/slon'
/bin/sh /usr/local/src/slony1-2.2.5/config/mkinstalldirs /usr/local/pgsql9.5.1/bin/
/bin/sh /usr/local/src/slony1-2.2.5/config/install-sh -c -m 755 slon /usr/local/pgsql9.5.1/bin/
make[2]: Leaving directory `/usr/local/src/slony1-2.2.5/src/slon'
make[2]: Entering directory `/usr/local/src/slony1-2.2.5/src/slonik'
/bin/sh /usr/local/src/slony1-2.2.5/config/mkinstalldirs /usr/local/pgsql9.5.1/bin/
/bin/sh /usr/local/src/slony1-2.2.5/config/install-sh -c -m 755 slonik /usr/local/pgsql9.5.1/bin/
make[2]: Leaving directory `/usr/local/src/slony1-2.2.5/src/slonik'
make[2]: Entering directory `/usr/local/src/slony1-2.2.5/src/backend'
/bin/sh /usr/local/src/slony1-2.2.5/config/mkinstalldirs /usr/local/pgsql9.5.1/lib/
/bin/sh /usr/local/src/slony1-2.2.5/config/mkinstalldirs /usr/local/pgsql9.5.1/share/
/bin/sh /usr/local/src/slony1-2.2.5/config/install-sh -c -m 755 slony1_funcs.2.2.5.so /usr/local/pgsql9.5.1/lib/
for file in slony1_base.sql slony1_funcs.sql slony1_base.v83.sql slony1_base.v84.sql slony1_funcs.v83.sql slony1_funcs.v84.sql; do \
/bin/sh /usr/local/src/slony1-2.2.5/config/install-sh -c -m 644 $file /usr/local/pgsql9.5.1/share//`basename $file .sql`.2.2.5.sql || exit ; \
done
make[2]: Leaving directory `/usr/local/src/slony1-2.2.5/src/backend'
make[2]: Entering directory `/usr/local/src/slony1-2.2.5/src/ducttape'
/bin/sh /usr/local/src/slony1-2.2.5/config/mkinstalldirs
make[2]: Leaving directory `/usr/local/src/slony1-2.2.5/src/ducttape'
make[2]: Entering directory `/usr/local/src/slony1-2.2.5/src/slony_logshipper'
/bin/sh /usr/local/src/slony1-2.2.5/config/mkinstalldirs /usr/local/pgsql9.5.1/bin/
/bin/sh /usr/local/src/slony1-2.2.5/config/install-sh -c -m 755 slony_logshipper /usr/local/pgsql9.5.1/bin/
make[2]: Leaving directory `/usr/local/src/slony1-2.2.5/src/slony_logshipper'
make[1]: Leaving directory `/usr/local/src/slony1-2.2.5/src'
make[1]: Entering directory `/usr/local/src/slony1-2.2.5/tools'
for subdir in altperl ; do \
make -C $subdir install || exit; \
done
make[2]: Entering directory `/usr/local/src/slony1-2.2.5/tools/altperl'
/bin/sh /usr/local/src/slony1-2.2.5/config/mkinstalldirs /usr/local/etc
/bin/sh /usr/local/src/slony1-2.2.5/config/mkinstalldirs /usr/local/pgsql9.5.1/lib/
/bin/sh /usr/local/src/slony1-2.2.5/config/mkinstalldirs /usr/local/bin
/bin/sh /usr/local/src/slony1-2.2.5/config/install-sh -c -m 644 slon_tools.conf-sample /usr/local/etc
/bin/sh /usr/local/src/slony1-2.2.5/config/install-sh -c -m 644 slon-tools /usr/local/pgsql9.5.1/lib//slon-tools.pm
for file in slonik_add_node.pl slonik_build_env.pl slonik_create_set.pl slonik_drop_node.pl slonik_drop_sequence.pl slonik_drop_set.pl slonik_drop_table.pl slonik_execute_script.pl slonik_failover.pl slonik_init_cluster.pl slonik_merge_sets.pl slonik_move_set.pl slonik_print_preamble.pl slonik_restart_node.pl slonik_store_node.pl slonik_subscribe_set.pl slonik_uninstall_nodes.pl slonik_unsubscribe_set.pl slonik_update_nodes.pl slon_kill.pl slon_start.pl slon_status.pl slon_watchdog2.pl slon_watchdog.pl slony_show_configuration.pl ; do \
tmpname=`echo $file | sed "s#\.pl##"` && \
/bin/sh /usr/local/src/slony1-2.2.5/config/install-sh -c -m 755 $tmpname /usr/local/bin \
|| exit; \
done
make[2]: Leaving directory `/usr/local/src/slony1-2.2.5/tools/altperl'
make[1]: Leaving directory `/usr/local/src/slony1-2.2.5/tools'
All of Slony-I is successfully installed
[[email protected] slony1-2.2.5]#
[[email protected] slony1-2.2.5]# '
結果驗證為:
[[email protected] slony1-2.2.5]$ which postgres
/usr/local/pgsql/bin/postgres
[[email protected] slony1-2.2.5]$ which slon
/usr/local/pgsql/bin/slon
[[email protected] slony1-2.2.5]$ which slonik
/usr/local/pgsql/bin/slonik
[[email protected] slony1-2.2.5]$
[[email protected] slony1-2.2.5]# chown -R postgres:postgres /usr/local/pgsql/
[[email protected] slony1-2.2.5]#
[[email protected] slony1-2.2.5]# ll /usr/local/pgsql/bin/postgres
-rwxr-xr-x 1 postgres postgres 6703495 Mar 16 2016 /usr/local/pgsql/bin/postgres
[[email protected] slony1-2.2.5]# ll /usr/local/pgsql/bin/slon
-rwxr-xr-x 1 postgres postgres 389518 Nov 19 10:29 /usr/local/pgsql/bin/slon
[[email protected] slony1-2.2.5]# ll /usr/local/pgsql/bin/slonik
-rwxr-xr-x 1 postgres postgres 274680 Nov 19 10:29 /usr/local/pgsql/bin/slonik
[[email protected] slony1-2.2.5]#
############################ 第三部分 配置和驗證Slony-I複製 步驟一:規劃和建立複製環境: 進行復制的兩個postgresql的例項埠和庫名分別如下: 192.168.10.119 : 5432 master 192.168.10.119 : 5433 slave 在兩臺資料庫中,都建立一個名為 slony 的超級使用者,給 slony-I 使用,命令如下: create user slony superuser password 'slonytest'; 在主庫上建立一個名稱為 master 的資料庫,作為複製的源資料庫,命令為: psql -h 192.168.10.119 -p 5432 postgres postgres create database master; alter database master owner to slony; 在備庫上建立一個名稱為 slave 的目標資料庫,作為複製的目標資料庫,命令為: psql -h 192.168.10.119 -p 5433 postgres postgres create database slave; alter database slave owner to slony; 後面的複製,就是在 master 資料庫和slave 資料庫之間進行;為了演示覆制,在master庫和slave庫中建一個測試表,命令如下: create table synctab01(id int primary key, note text); 為了能夠讓機器相互付昂文,在 pg_hba.conf 檔案中加入以下內容: host all all 192.168.1.0/24 md5 為了讓備註生效,執行如下命令: pg_ctl reload 確認資料庫監聽,已經監聽到本機的IP中,可以修改 postgresql.conf 檔案中的監聽選項: listen_addresses = '*' 測試在兩臺機器上,分別能夠用slony使用者進行資料庫訪問: psql -h 192.168.10.119 -p 5432 -U slony -d master psql -h 192.168.10.119 -p 5433 -U slony -d slave 如果驗證都能夠正常訪問,則到此,複製前的postgresql環境準備就結束了。 接下來使用 altperl scripts 指令碼完成Slony資料同步的配置工作。 步驟二:編輯 slon_tools.conf 配置檔案 首先要配置好一個名為 slon_tools.conf 的配置檔案,這個檔案要放在 /usr/local/etc 目錄下。 安裝完 slony-I後,這個目錄下會有一個示例檔案 slon_tools.conf-sample ,把這個檔案拷貝成 slon_tools.conf ,然後修改。 cd /usr/local/etc ls cp slon_tools.conf-sample slon_tools.conf 修改檔案,把檔案中叢集的名稱改成配置的名稱,這裡修改為 cluster01 , 命令為: vim slon_tools.conf
if ($ENV{"SLONYNODES"}) {
require $ENV{"SLONYNODES"};
} else {
#$CLUSTER_NAME = 'replication';
$CLUSTER_NAME = 'cluster01';
#$PIDFILE_DIR = '/var/run/slony1';
$PIDFILE_DIR = '/usr/local/pgsql/log';
#$LOGDIR = '/var/log/slony1';
$LOGDIR = '/usr/local/pgsql/log';
#目前只有兩個主從複製,只需要配置兩個伺服器即可
add_node(node => 1,
host => '192.168.10.119',
dbname => 'master',
port => 5432,
user => 'slony',
password => 'slonytest');
add_node(node => 2,
host => '192.168.10.119',
dbname => 'slave',
port => 5433,
user => 'slony',
password => 'slonytest');
}
# 設定複製集的配置項,主要配置要同步那些表和序列。
$SLONY_SETS = {
"set1_name" => {
"set_id" => 1,
"table_id" => 1,
"sequence_id" => 1,
"pkeyedtables" => ["synctab01"],
"keyedtables" => {},
"sequences" => [],
},
};
# 上面的叢集名稱、日誌路徑、複製集中的同步主鍵表、唯一鍵表、序列等配置完成後,將 slon_tools.conf 檔案拷貝到其他機器上。初始化叢集。
if ($ENV{"SLONYNODES"}) { require $ENV{"SLONYNODES"}; } else { #$CLUSTER_NAME = 'replication'; $CLUSTER_NAME = 'cluster01'; #$PIDFILE_DIR = '/var/run/slony1'; $PIDFILE_DIR = '/usr/local/pgsql/log'; #$LOGDIR = '/var/log/slony1'; $LOGDIR = '/usr/local/pgsql/log'; #目前只有兩個主從複製,只需要配置兩個伺服器即可 add_node(node => 1, host => '192.168.10.119', dbname => 'master', port => 5432, user => 'slony', password => 'slonytest'); add_node(node => 2, host => '192.168.10.119', dbname => 'slave', port => 5433, user => 'slony', password => 'slonytest'); } # 設定複製集的配置項,主要配置要同步那些表和序列。 $SLONY_SETS = { "set1_name" => { "set_id" => 1, "table_id" => 1, "sequence_id" => 1, "pkeyedtables" => ["synctab01"], "keyedtables" => {}, "sequences" => [], }, }; # 上面的叢集名稱、日誌路徑、複製集中的同步主鍵表、唯一鍵表、序列等配置完成後,將 slon_tools.conf 檔案拷貝到其他機器上。初始化叢集。 在一個節點配置完成後,將配置好的 slon_tools.conf 檔案拷貝到其他 slony機器。 scp slon_tools.conf 192.168.10.119:`pwd`/. 步驟三:啟動同步服務 slony配置檔案配置完畢,並拷貝到叢集中各個節點後,需要初始化和啟動同步服務。 初始化叢集,執行 slonik_init_cluster | slonik 命令如下: [[email protected] etc]$ slonik_init_cluster | slonik <stdin>:10: Set up replication nodes <stdin>:13: Next: configure paths for each node/origin <stdin>:16: Replication nodes prepared <stdin>:17: Please start a slon replication daemon for each node [[email protected] etc]$ 命令 slonik_init_cluster 會讀取配置檔案 slon_tools.conf 中的內容,自動初始化 slony叢集在資料庫中的同步配置。後面一些 slony指令碼也會讀取配置檔案 slon_tools.conf。 在master節點上,啟動 slony 守護程序,命令後的序號對應配置檔案中master節點的節點號。 [[email protected] etc]$ slon_start 1 Invoke slon for node 1 - /usr/local/pgsql9.5.1/bin//slon -p /var/run/slony1/cluster01_node1.pid -s 1000 -d2 cluster01 'host=192.168.10.119 dbname=master user=slony port=5432 password=slonytest' > /usr/local/pgsql/log/node1/master-2016-11-19.log 2>&1 & Slon failed to start for cluster cluster01, node node1 如果上面啟動錯誤,需要根據日誌提示,解決錯誤後,再次啟動: [[email protected] etc]$ slon_start 1 Invoke slon for node 1 - /usr/local/pgsql9.5.1/bin//slon -p /usr/local/pgsql/log/cluster01_node1.pid -s 1000 -d2 cluster01 'host=192.168.10.119 dbname=master user=slony port=5432 password=slonytest' > /usr/local/pgsql/log/node1/master-2016-11-19.log 2>&1 & Slon successfully started for cluster cluster01, node node1 PID [11298] Start the watchdog process as well... 在slave節點上,啟動 slony守護程序,命令後的序號對應配置檔案中 slave 節點的節點號。 [[email protected] etc]$ slon_start 2 Invoke slon for node 2 - /usr/local/pgsql9.5.1/bin//slon -p /var/run/slony1/cluster01_node2.pid -s 1000 -d2 cluster01 'host=192.168.10.119 dbname=slave user=slony port=5433 password=slonytest' > /usr/local/pgsql/log/node2/slave-2016-11-19.log 2>&1 & Slon failed to start for cluster cluster01, node node2 再次啟動: [[email protected] etc]$ slon_start 2 Invoke slon for node 2 - /usr/local/pgsql9.5.1/bin//slon -p /usr/local/pgsql/log/cluster01_node2.pid -s 1000 -d2 cluster01 'host=192.168.10.119 dbname=slave user=slony port=5433 password=slonytest' > /usr/local/pgsql/log/node2/slave-2016-11-19.log 2>&1 & Slon successfully started for cluster cluster01, node node2 PID [11323] Start the watchdog process as well... 啟動slony守護程序時的錯誤處理: 第一次啟動時報錯,不能開啟pid檔案,修改檔案路徑: [[email protected] etc]$ cat /usr/local/pgsql/log/node1/master-2016-11-19.log 2016-11-19 11:51:41 CST CONFIG main: slon version 2.2.5 starting up 2016-11-19 11:51:41 CST FATAL Cannot open pid_file "/var/run/slony1/cluster01_node1.pid" 再次啟動,就可以正常啟動了。 使用命令 “ slonik_create_set 1 | slonik ” 建立資料集,如下: [[email protected] etc]$ slonik_create_set 1 | slonik <stdin>:11: Subscription set 1 (set1_name) created <stdin>:12: Adding tables to the subscription set <stdin>:16: Add primary keyed table public.synctab01 <stdin>:19: Adding sequences to the subscription set <stdin>:20: All tables added [[email protected] etc]$ 使用命令 “ slonik_subscribe_set 1 2 | slonik ” 增加資料訂閱者,其中命令的第一個數字 1 代表同步集號,第二個數字2代表資料訂閱者的節點號,如下: [[email protected] etc]$ slonik_subscribe_set 1 2 | slonik <stdin>:6: Subscribed nodes to set 1 到此,同步就配置完了。 步驟四:驗證同步效果 下面測試同步效果。
在master主庫上新增一條記錄:
postgres=# \c master
You are now connected to database "master" as user "postgres".
master=# \d
List of relations
Schema | Name | Type | Owner
--------+-----------+-------+----------
public | synctab01 | table | postgres
(1 row)
master=#
master=# select * from synctab01;
id | note
----+------
(0 rows)
master=#
master=# insert into synctab01 values(1,'111');
INSERT 0 1
master=#
master=# select * from synctab01;
id | note
----+------
1 | 111
(1 row)
在slave從庫上確認資料狀態:
postgres=# \c slave
You are now connected to database "slave" as user "postgres".
slave=#
slave=# \d
List of relations
Schema | Name | Type | Owner
--------+-----------+-------+----------
public | synctab01 | table | postgres
(1 row)
slave=#
slave=# select * from synctab01;
id | note
----+------
(0 rows)
slave=# select * from synctab01;
id | note
----+------
1 | 111
(1 row)
在master主庫上新增一條記錄: postgres=# \c master You are now connected to database "master" as user "postgres". master=# \d List of relations Schema | Name | Type | Owner --------+-----------+-------+---------- public | synctab01 | table | postgres (1 row) master=# master=# select * from synctab01; id | note ----+------ (0 rows) master=# master=# insert into synctab01 values(1,'111'); INSERT 0 1 master=# master=# select * from synctab01; id | note ----+------ 1 | 111 (1 row) 在slave從庫上確認資料狀態: postgres=# \c slave You are now connected to database "slave" as user "postgres". slave=# slave=# \d List of relations Schema | Name | Type | Owner --------+-----------+-------+---------- public | synctab01 | table | postgres (1 row) slave=# slave=# select * from synctab01; id | note ----+------ (0 rows) slave=# select * from synctab01; id | note ----+------ 1 | 111 (1 row) 至此兩個 postgresql 單例項之間的主從同步就確認完畢了。
相關推薦
postgresql多例項建立與Slony-I複製配置
第一部分 在一個主機上建立多個 postgresql例項 步驟一:安裝postgresql軟體 安裝 postgresql例項,從postgresql官網上 https://www.postgresql.org/ 下載postgresql安裝軟體,解壓縮,建立po
ACTIVITI 5.22.0 流程退回上一節點,實現多例項序列與並行退回
import java.util.ArrayList; import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util
centos7上mariadb10.3多例項安裝部署及主從複製
mariaDB是開源的資料庫,是mysql的衍生版。 Mariadb官方: https://mariadb.com/ os:centos7 mariadb:10.3 yum安裝實現。
Docker Compose進行多容器建立與日常維護
談到微服務的話題,技術上我們往往會涉及到多服務、多容器的部署與管理。 Docker 有三個主要的作用:Build, Ship和Run。使用docker compose我們可以在Run的層面解決很多實際問題,如:通過建立compose(基於YUML語法)檔案,在這個檔案上面描述應用的架構,如使用什麼映象、資料卷
Anaconda多環境python管理(建立、刪除、複製環境)
Anaconda介紹 Anaconda是一款對python多環境進行管理的軟體。它能夠比較方便快捷地獲取包,並且對包和相關環境進行統一的管理。Anaconda中包含了conda、python在內的超過180個科學包及其依賴項。 管理環境 Anaconda的一個最大的優勢在於可以同
(11)Spring學習記錄---Spring_bean(靜態,例項工廠與FactoryBean建立Bean)
通過靜態工廠方法建立bean 1.Car.class private String band; private double price; public Car(String band, double price) { super(); this.ban
安裝mysql與多例項安裝
安裝mysql(通用二進位制格式) 第一步:準備mysql的配置檔案(不再提供配置檔案模版) 首先需要從網路下載一個my.cnf檔案,放在/etc下 說明: 安裝位置:/usr/local/mysql 資料位置: /data/mysql/mysql3306/data 臨時檔案位置
Visual C++網路程式設計經典案例詳解 第3章 多執行緒與非同步套接字程式設計 程序間通訊 命名管道 命名管道例項
vc新增控制檯工程 名字命名管道例項 新增原始檔 名字 伺服器 #include<windows.h> //包含標頭檔案 #include<stdio.h> int main() {
mysql 多例項 主從複製實戰記錄
本文章: 參考 跟老男孩學linux-web叢集實戰 第九章 大環境: contos:Linux localhost 2.6.32-754.3.5.el6.x86_64 #1 SMP Tue Aug 14 20:46:41 UTC 2018 x86_64 x8
Java基礎加強之多執行緒篇 - 執行緒建立與終止、互斥、通訊、本地變數
執行緒建立與終止 執行緒建立 Thread類與 Runnable 介面的關係 public interface Runnable { public abstract void run(); } public class Thread implements Run
建造者模式-複雜例項的建立與組裝
建造者模式定義 將一個複雜物件的構建與它的表示分離,使得同樣的構建過程可以建立不同的表示。 建造者模式結構圖 建造者模式角色介紹 Builder:抽象建造者角色,負責定義建立Product產品物件的各個部件介面,同時定義獲取完成Product產品物件的介面。 Con
MySQL 多表結構的建立與分析
=====================多對一===================== create table press( id int primary key auto_increment, name varchar(20) ); create table book( id
Montouch多檢視的建立與銷燬
釋放一個引用了另外一個檢視的方法,步驟如下。 1) UIViewController A是主檢視控制器; B是子檢視控制器. 2) A建立了B的例項並且儲存B的引用. 3) A增加B的檢視為A的子檢視. 一切都是正常的,可以看到B正確的顯示在A的視圖裡. 4) A移除B檢視.B的檢視在程式碼中不存在任何
馳騁工作流引擎JFlow與activiti的對比之4種包含多例項的模式
無同步的多例項(MIwithout) 在流程中,一個活動可以啟用多個例項,每個例項相互獨立,並不需要在後面進行同步。 例子:比如使用者購買了N本書,於是後續的支付賬單、更新客戶可以以本書為單位各自執行。 ACTIVITI 中的支援情況: 支援這種模式,但是不允許在後面進行結束動
SQL Server 多例項下的複製
一.本文所涉及的內容(Contents) 二.背景(Contexts) 在伺服器A有一個數據庫Task,需要把部分表部分欄位釋出訂閱到伺服器B的TaskSiteInfo資料庫上,但是A伺服器有些特別,因為它除了有個預設的例項之外,還有一個命名例項:TZR06\SQLSERVER2008R2,如果是
Amazon EC2安裝mysql多例項並配置主從複製
1、MySQL安裝: EC2直接使用yum安裝mysql很方便: yum install mysql mysql-server mysql-libs 此處安裝了三個包 完事之後可以直接使用 service mysqld start 啟動mysql服務
java多執行緒與高併發庫應用(二)執行緒建立和定時任務Timer
1、建立執行緒的兩種方式, 通過start, 執行run方法。 第一種實現runnable, 定義類實現Runnable介面 重寫Runnable介面中的run方法 通過Thread建立執行緒物件 將Runnable介面的子類物件作為實際引數傳遞
C語言多執行緒基礎-01-執行緒的建立與銷燬
一.執行緒建立 首先要關聯標頭檔案Window.h,需要使用Windows系統的底層方法 1.1 執行緒建立演示: //定義一個方法,彈出一個訊息框 //該方法返回值為DWORD WINAPI型別,引數為一個空指標 DWORD WINAPI run(voi
C++第三章(類和物件)下篇 (動態建立與釋放,物件的賦值和複製,靜態資料成員,友元)
一,物件的動態建立與釋放 new (程式設計師怎麼會沒有朋友??? 來讓我給你new 一個) 在我學過的c中 我們一般都用 malloc 來動態申請空間。現在我們可以用new 來申請空間 Box *pt; pt = new Box; c++允許在new時進行賦值 Box *
docker一個映象建立多例項啟動多個容器分配不同的埠號,達到高可用的目的
利用一個映象去建立多個微服務例項,實現擴充套件服務的目的,主要難點是利用配置檔案分別啟動不同的例項,剛開始沒有搞清楚配置檔案和容器啟動的關係,被坑了很長時間程式碼其實很簡單,就是一個註冊服務中心,以開發環境配置檔案建立服務註冊中心,以測試環境配置服務註冊中心,使兩個服務