|PolarDB-O主备高可用部署及切换排雷指引( 五 )
psql -h$PGDATA -p$PGPORT -c''select * from pg_stat_replication;''
Expanded display is on.
polardb=# select * from pg_stat_replication;
-[ RECORD 1 ]----+---------------------------------
pid | 22449
usesysid | 16384
usename | replicator
application_name | standby_3232296579_5432
client_addr | 192.168.238.131
client_hostname |
client_port | 60866
backend_start | 03-NOV-20 13:58:17.811323 +08:00
backend_xmin |
state | streaming
sent_lsn | 0/41BD1648
write_lsn | 0/41BD1648
flush_lsn | 0/41BD1648
replay_lsn | 0/41BD1648
write_lag | 00:00:00.002793
flush_lag | 00:00:00.002801
replay_lag | 00:00:00.003894
sync_priority | 1
sync_state | sync
创建个表测试下主备是否同步
polardb=# create table t1( id int);
polardb=# insert into t1 values(1);
INSERT 0 1
polardb=# insert into t1 values(2);
INSERT 0 1
polardb=# select * from t1;
id
----
1 2 (2 rows)
4、Cluster Manager部署
1)SSH配置
在CM节点root用户执行以下命令:
ssh-keygen -t rsa
ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.238.131 #备节点IP
ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.238.130 #主节点IP
2)禁用防火墙
systemctl disable firewalld.service
systemctl stop firewalld.service
3)端口说明
PolarDB:5432/tcp
Cluster Manager:5500,5501/tcp
4)RPM包安装
rpm -ivh polardb-clustermanager-1.0.0-20200904155748.x86_64.rpm
安装后会有三个文件 , 如下所示:
# /usr/local/polardb_cluster_manager/bin/polardb-cluster-manager
#/usr/local/polardb_cluster_manager/bin/polardb_cluster_manager_control.py
#/usr/local/polardb_cluster_manager/bin/supervisor.py
5)配置服务
① 在主库主机上创建aurora探测用户
/usr/local/polardb_o_current/bin/createuser -p $PGPORT -h $PGDATA --login aurora -P -s
密码aurora
② 在CM主机上创建配置文件 , 如下所示:
mkdir -p /root/polardb_cluster_manager/conf
vi /root/polardb_cluster_manager/conf/polardb_cluster_manager.conf
{
''work_mode'':''PolarPure'',
''consensus'':{ ''port'':5001 },
''account_info'':{ ''aurora_user'':''aurora'',
''aurora_password'':''aurora'',
''replica_user'':''replicator'',
''replica_password'':''replicator'' },
''cluster_info'':{ ''port'':5000 }
}
排雷3:
注意:
此处注意检查双引号间一定别有空格 , 用户及密码跟之前步骤探测和复制用户对应上
- consensus是内置一致性服务端口 , 不对外服务;
- cluster_info是cm对外接口的服务端口;
- aurora_user是刚创建的探测用户的账号、密码 , 权限为superuser;
- replica_user是刚创建的复制用户的账号密码 , 权限可以为replication或superuser 。
1)启动服务
1/usr/local/polardb_cluster_manager/bin/polardb_cluster_manager_control.py /root/polardb_cluster_manager/ start