#apt-get update
#apt-get install rsync
#apt-get install postgresql
root@slave:~# passwd postgres
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
root@slave:~# su - postgres
postgres@slave:~$ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/var/lib/postgresql/.ssh/id_rsa):
/var/lib/postgresql/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /var/lib/postgresql/.ssh/id_rsa.
Your public key has been saved in /var/lib/postgresql/.ssh/id_rsa.pub.
The key fingerprint is:
bb:94:19:67:f7:17:42:5a:e5:8b:d4:2c:e0:4a:3a:96 postgres@slave
The key's randomart image is:
+--[ RSA 2048]----+
| . . |
| . . = |
| . . = + |
| + . = o .|
| ES.o..o o |
| . .B . .. .|
| = . .|
| . . . |
| . |
+-----------------+
#apt-get install rsync
#apt-get install postgresql
root@slave:~# passwd postgres
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
root@slave:~# su - postgres
postgres@slave:~$ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/var/lib/postgresql/.ssh/id_rsa):
/var/lib/postgresql/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /var/lib/postgresql/.ssh/id_rsa.
Your public key has been saved in /var/lib/postgresql/.ssh/id_rsa.pub.
The key fingerprint is:
bb:94:19:67:f7:17:42:5a:e5:8b:d4:2c:e0:4a:3a:96 postgres@slave
The key's randomart image is:
+--[ RSA 2048]----+
| . . |
| . . = |
| . . = + |
| + . = o .|
| ES.o..o o |
| . .B . .. .|
| = . .|
| . . . |
| . |
+-----------------+
postgres@slave:~$ scp /var/lib/postgresql/.ssh/id_rsa.pub ttadmin@192.168.1.122:/home/ttadmin/
The authenticity of host '192.168.1.122 (192.168.1.122)' can't be established.
ECDSA key fingerprint is df:56:af:bb:72:07:58:0f:5f:45:ae:05:48:f6:79:a8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.122' (ECDSA) to the list of known hosts.
ttadmin@192.168.1.122's password:
id_rsa.pub 100% 396 0.4KB/s 00:00
postgres@slave:~$
root@master:~# passwd postgres
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
root@master:~# su - postgres
postgres@master:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/var/lib/postgresql/.ssh/id_rsa):
Created directory '/var/lib/postgresql/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /var/lib/postgresql/.ssh/id_rsa.
Your public key has been saved in /var/lib/postgresql/.ssh/id_rsa.pub.
The key fingerprint is:
9f:2c:a3:a2:08:d2:50:c3:3e:6a:12:28:73:75:dd:5c postgres@master
The key's randomart image is:
+--[ RSA 2048]----+
| E |
| . . o . |
| + . . . o |
|.o o . |
|* + S |
|.B . o . |
|=.. o + |
|=. . . o |
|. .. .. |
+-----------------+
postgres@master:~$ scp /var/lib/postgresql/.ssh/id_rsa.pub ttadmin@192.168.1.125:/home/ttadmin/
The authenticity of host '192.168.1.125 (192.168.1.125)' can't be established.
ECDSA key fingerprint is df:56:af:bb:72:07:58:0f:5f:45:ae:05:48:f6:79:a8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.125' (ECDSA) to the list of known hosts.
ttadmin@192.168.1.125's password:
id_rsa.pub 100% 397 0.4KB/s 00:00
postgres@master:~$
postgres@slave:~$ exit
logout
root@slave:~# cat /home/ttadmin/id_rsa.pub >> /var/lib/postgresql/.ssh/authorize d_keys
root@slave:~# cd /var/lib/postgresql/.ssh/
root@slave:/var/lib/postgresql/.ssh# ls -lah
total 24K
drwx------ 2 postgres postgres 4.0K May 13 01:18 .
drwxr-xr-x 4 postgres postgres 4.0K May 13 01:16 ..
-rw-r--r-- 1 root root 397 May 13 01:18 authorized_keys
-rw------- 1 postgres postgres 1.7K May 13 01:09 id_rsa
-rw-r--r-- 1 postgres postgres 396 May 13 01:09 id_rsa.pub
-rw-r--r-- 1 postgres postgres 222 May 13 01:12 known_hosts
root@slave:/var/lib/postgresql/.ssh# chown postgres:postgres authorized_keys
root@slave:/var/lib/postgresql/.ssh# chmod 644 authorized_keys
root@slave:/var/lib/postgresql/.ssh# ls -lah
total 24K
drwx------ 2 postgres postgres 4.0K May 13 01:18 .
drwxr-xr-x 4 postgres postgres 4.0K May 13 01:16 ..
-rw-r--r-- 1 postgres postgres 397 May 13 01:18 authorized_keys
-rw------- 1 postgres postgres 1.7K May 13 01:09 id_rsa
-rw-r--r-- 1 postgres postgres 396 May 13 01:09 id_rsa.pub
-rw-r--r-- 1 postgres postgres 222 May 13 01:12 known_hosts
root@slave:/var/lib/postgresql/.ssh# nano /etc/ssh/sshd_config
//uncommand AuthorizedKeyFile
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys
postgres@master:~$ exit
logout
root@master:~# cat /home/ttadmin/id_rsa.pub >> /var/lib/postgresql/.ssh/authoriz ed_keys
root@master:~# cd /var/lib/postgresql/.ssh/
root@master:/var/lib/postgresql/.ssh# ls -lah
total 24K
drwx------ 2 postgres postgres 4.0K May 13 01:24 .
drwxr-xr-x 4 postgres postgres 4.0K May 13 01:24 ..
-rw-r--r-- 1 root root 396 May 13 01:24 authorized_keys
-rw------- 1 postgres postgres 1.7K May 13 01:14 id_rsa
-rw-r--r-- 1 postgres postgres 397 May 13 01:14 id_rsa.pub
-rw-r--r-- 1 postgres postgres 222 May 13 01:14 known_hosts
root@master:/var/lib/postgresql/.ssh# chown postgres:postgres authorized_keys
root@master:/var/lib/postgresql/.ssh# chmod 644 authorized_keys
root@master:/var/lib/postgresql/.ssh# nano /etc/ssh/sshd_config
root@master:/var/lib/postgresql/.ssh# cd
root@master:~# su - postgres
postgres@master:~$ ssh postgres@192.168.1.125
Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-31-generic x86_64)
* Documentation: https://help.ubuntu.com/
New release '16.04.2 LTS' available.
Run 'do-release-upgrade' to upgrade to it.
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
postgres@slave:~$
-------------------------------------------------------------
root@slave:~#
root@slave:~# su - postgres
postgres@slave:~$ ssh postgres@192.168.1.122
Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-31-generic x86_64)
* Documentation: https://help.ubuntu.com/
New release '16.04.2 LTS' available.
Run 'do-release-upgrade' to upgrade to it.
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
postgres@master:~$
---------------------------------------------
postgres@slave:~$ exit
logout
Connection to 192.168.1.125 closed.
postgres@master:~$ psql -c "CREATE USER rep REPLICATION LOGIN CONNECTION LIMIT 1 ENCRYPTED PASSWORD 'treecare';"
CREATE ROLE
postgres@master:~$ exit
logout
root@master:~# cd /etc/postgresql/9.3/main/
root@master:/etc/postgresql/9.3/main# ls
environment pg_hba.conf postgresql.conf
pg_ctl.conf pg_ident.conf start.conf
root@master:/etc/postgresql/9.3/main# nano pg_hba.conf
//add the live below
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
host replication rep 192.168.1.125/24 md5
root@master:/etc/postgresql/9.3/main# nano postgresql.conf
//edit following things
root@master:/etc/postgresql/9.3/main# service postgresql start
* Starting PostgreSQL 9.3 database server [ OK ]
-------------------------
root@slave:~# service postgresql stop
* Stopping PostgreSQL 9.3 database server [ OK ]
root@slave:~# cd /etc/postgresql/9.3/main/
root@slave:/etc/postgresql/9.3/main# ls
environment pg_hba.conf postgresql.conf
pg_ctl.conf pg_ident.conf start.conf
root@slave:/etc/postgresql/9.3/main# nano pg_hba.conf
//add this line
host replication rep 192.168.1.122/24 md5
root@slave:/etc/postgresql/9.3/main# nano postgresql.conf
//edit following
listen_addresses = 'localhost, 192.168.1.125' # what IP address(es) t$
wal_level = hot_standby # minimal, archive, or hot_standby
archive_mode = on # allows archiving to be done
# (change requires restart)
archive_command = 'cd .' # command to use to archive a logfile s$
max_wal_senders = 1 # max number of walsender processes
hot_standby = on # "on" allows queries during recovery
---------------------------------------------
root@master:/etc/postgresql/9.3/main# su - postgres
postgres@master:~$ psql -c "select pg_start_backup('initial_backup');"
pg_start_backup
-----------------
0/2000028
(1 row)
postgres@master:~$ rsync -cva --inplace --exclude=*pg_xlog* /var/lib/postgresql/9.3/main/ 192.168.1.125:/var/lib/postgresql/9.3/main/ sending incremental file list
./
backup_label
postmaster.pid
base/
base/1/
base/12061/
base/12066/
base/12066/pg_internal.init
global/
global/11809
global/11809_vm
global/11811
global/11812
global/pg_control
global/pg_internal.init
pg_clog/
pg_clog/0000
pg_multixact/
pg_multixact/members/
pg_multixact/offsets/
pg_notify/
pg_serial/
pg_snapshots/
pg_stat/
pg_stat_tmp/
pg_stat_tmp/db_0.stat
pg_stat_tmp/db_12066.stat
pg_stat_tmp/global.stat
pg_subtrans/
pg_tblspc/
pg_twophase/
sent 141,271 bytes received 4,278 bytes 97,032.67 bytes/sec
total size is 19,660,126 speedup is 135.08
postgres@master:~$ psql -c "select pg_stop_backup();"
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
pg_stop_backup
----------------
0/2000190
(1 row)
------------------------------------------------
//create a file
root@slave:/var/lib/postgresql/9.3/main# nano recovery.conf
standby_mode= 'on'
primary_conninfo = 'host=192.168.1.122 port=5432 user=rep password=treecare'
trigger_file = '/tmp/postgresql.trigger.5432'
root@slave:/var/lib/postgresql/9.3/main# service postgresql start * Starting PostgreSQL 9.3 database server [ OK ]
root@slave:/var/lib/postgresql/9.3/main# nano /var/log/postgresql/postgresql-9.3-main.log
//check the log
--------------------------------------------
postgres@master:~$ psql
psql (9.3.16)
Type "help" for help.
postgres=# CREATE TABLE rep_test (name varchar(40));
CREATE TABLE
postgres=# INSERT INTO rep_test VALUES ('boobalan');
INSERT 0 1
postgres=# INSERT INTO rep_test VALUES ('rajaram');
INSERT 0 1
postgres=#
--------------------------
now test your slave server
No comments:
Post a Comment