安装opengauss极简版一主一备节点环境-4008云顶国际网站
【摘要】 参考:https://opengauss.org/zh/docs/2.1.0/docs/quickstart/quickstart.html-- 安装一主一备节点(之前的配置和单节点一样)docker rm -f lhropengausssimpledocker run -d --name lhropengausssimple -h lhropengausssimple \ -p 3543...
参考:
-- 安装一主一备节点(之前的配置和单节点一样)
docker rm -f lhropengausssimple
docker run -d --name lhropengausssimple -h lhropengausssimple \
-p 35432-35439:5432-5439 -p 35632-35639:5632-5639 \
-v /sys/fs/cgroup:/sys/fs/cgroup \
--privileged=true lhrbest/lhrcentos76:8.5 \
/usr/sbin/init
docker exec -it lhropengausssimple bash
cd /soft
#close selinux
sed -i 's/selinux=enforcing/selinux=disabled/g' /etc/selinux/config
setenforce 0
#close firewalld
systemctl stop firewalld && systemctl disable firewalld
echo 'export lang=en_us.utf-8' >> /etc/profile
cp /usr/share/zoneinfo/asia/shanghai /etc/localtime
sysctl -w kernel.sem="250 85000 250 330"
-- 创建用户和组
groupadd dbgrp
useradd -g dbgrp -d /home/omm -m -s /bin/bash omm
echo "lhr" | passwd --stdin omm
## 创建相关目录
mkdir /opengauss
chgrp dbgrp -r /opengauss
chmod 775 -r /opengauss
## 解压数据库安装包,85mb
wget https://opengauss.obs.cn-south-1.myhuaweicloud.com/2.1.0/x86/opengauss-2.1.0-centos-64bit.tar.bz2
tar -jxf opengauss-2.1.0-centos-64bit.tar.bz2 -c /opengauss
chown -r omm:dbgrp /opengauss
su - omm
cd /opengauss/simpleinstall
sh install.sh -w lhr@123xxt --multinode -p 5434
-- 启动停止
primary: gs_ctl start|stop|restart -d $gausshome/data/master -m primary
standby: gs_ctl start|stop|restart -d $gausshome/data/slave -m standby
-- 连接,-r表示可以使用上下左右键
gsql -d postgres -r
-- 修改参数文件
-- master
alter system set replconninfo1 = 'localhost=127.0.0.1 localport=5435 localheartbeatport=5439 localservice=5438 remotehost=127.0.0.1 remoteport=5635 remoteheartbeatport=5639 remoteservice=5638';
-- slave
alter system set replconninfo1 = 'localhost=127.0.0.1 localport=5635 localheartbeatport=5639 localservice=5638 remotehost=127.0.0.1 remoteport=5435 remoteheartbeatport=5439 remoteservice=5438';
# 环境变量
cat >> /home/omm/.bashrc <"eof"
export gausshome=/opengauss
export path=$gausshome/bin:$path
export ld_library_path=$gausshome/lib:$ld_library_path
export gs_cluster_name=dbcluster
ulimit -n 1000000
eof
source /home/omm/.bashrc
-- 配置远程访问
gsql -d postgres -p 5434
gsql -d postgres -p 5634
-- f 为主,t为备
select pg_is_in_recovery();
create database omm;
alter system set password_policy=0;
alter system set password_encryption_type=1;
alter system set listen_addresses = '*';
echo "host all all 0.0.0.0/0 sha256" >> /opengauss/data/master/pg_hba.conf
echo "host all all 0.0.0.0/0 sha256" >> /opengauss/data/slave/pg_hba.conf
-- 重启(必须带-m参数,否则主备关系破坏)
gs_ctl restart -d /opengauss/data/master/ -m primary
gs_ctl restart -d /opengauss/data/slave/ -m standby
-- 查询主备关系
gs_ctl query -d /opengauss/data/master
select * from pg_stat_replication;
select pg_is_in_recovery();
-- 新建用户
-- 初始化数据库的用户,是不能通过ip远程连接的,所以需要创建另外一个用户才能远程连接
gsql -p 5434
# 创建用户(初始化数据库的用户不能进行远程连接,需要重新创建用户)
create user lhr with password 'lhr' sysadmin ;
grant all privileges to lhr;
-- 验证远程登录数据库
gsql -dpostgres -h172.17.0.7 -ulhr -r -w'lhr'
-- 远程连接
gsql -d postgres -u lhr -w'lhr' -h 192.168.66.35 -p35434 -r
psql -d postgres -u lhr -h 192.168.66.35 -p35434
-- 解锁用户
alter user lhr account unlock;
-- 重新构建主备关系
gs_ctl build -d /opengauss/data/slave -b full -m standby
查询主备关系
[omm@lhropengausssimple ~]$ gs_ctl query -d /opengauss/data/master
[2022-01-07 10:48:22.065][12294][][gs_ctl]: gs_ctl query ,datadir is /opengauss/data/master
ha state:
local_role : primary
static_connections : 1
db_state : normal
detail_information : normal
senders info:
sender_pid : 11825
local_role : primary
peer_role : standby
peer_state : normal
state : streaming
sender_sent_location : 0/6000cf0
sender_write_location : 0/6000cf0
sender_flush_location : 0/6000cf0
sender_replay_location : 0/6000cf0
receiver_received_location : 0/6000cf0
receiver_write_location : 0/6000cf0
receiver_flush_location : 0/6000cf0
receiver_replay_location : 0/6000cf0
sync_percent : 100%
sync_state : sync
sync_priority : 1
sync_most_available : off
channel : 127.0.0.1:5435-->127.0.0.1:50000
receiver info:
no information
[omm@lhropengausssimple ~]$ gs_ctl query -d /opengauss/data/slave
[2022-01-07 10:48:26.782][12303][][gs_ctl]: gs_ctl query ,datadir is /opengauss/data/slave
ha state:
local_role : standby
static_connections : 1
db_state : normal
detail_information : normal
senders info:
no information
receiver info:
receiver_pid : 11824
local_role : standby
peer_role : primary
peer_state : normal
state : normal
sender_sent_location : 0/6000cf0
sender_write_location : 0/6000cf0
sender_flush_location : 0/6000cf0
sender_replay_location : 0/6000cf0
receiver_received_location : 0/6000cf0
receiver_write_location : 0/6000cf0
receiver_flush_location : 0/6000cf0
receiver_replay_location : 0/6000cf0
sync_percent : 100%
channel : 127.0.0.1:50000<--127.0.0.1:5435
[omm@lhropengausssimple ~]$ gsql -p 5434
gsql ((opengauss 2.1.0 build 590b0f8e) compiled at 2021-09-30 14:29:04 commit 0 last mr )
non-ssl connection (ssl connection is recommended when requiring high-security)
type "help" for help.
omm=# select pg_is_in_recovery();
pg_is_in_recovery
-------------------
f
(1 row)
postgres=> \x
expanded display is on.
postgres=> select * from pg_stat_replication;
-[ record 1 ]------------ ----------------------------------
pid | 140431925966592
usesysid | 10
usename | omm
application_name | walsender to standby[walreceiver]
client_addr | 127.0.0.1
client_hostname |
client_port | 50000
backend_start | 2022-01-07 10:40:53.51429308
state | streaming
sender_sent_location | 0/6000268
receiver_write_location | 0/6000268
receiver_flush_location | 0/6000268
receiver_replay_location | 0/6000268
sync_priority | 1
sync_state | sync
[omm@lhropengausssimple slave]$ gsql -p 5634
gsql ((opengauss 2.1.0 build 590b0f8e) compiled at 2021-09-30 14:29:04 commit 0 last mr )
non-ssl connection (ssl connection is recommended when requiring high-security)
type "help" for help.
omm=# select pg_is_in_recovery();
pg_is_in_recovery
-------------------
t
(1 row)
主从切换
主从switchover切换
在备机做切换:
[omm@lhropengausssimple ~]$ gs_ctl switchover -d /opengauss/data/slave/
[2022-01-07 11:21:22.238][16834][][gs_ctl]: gs_ctl switchover ,datadir is /opengauss/data/slave
[2022-01-07 11:21:22.239][16834][][gs_ctl]: switchover term (1)
[2022-01-07 11:21:22.252][16834][][gs_ctl]: waiting for server to switchover..............
[2022-01-07 11:21:33.593][16834][][gs_ctl]: done
[2022-01-07 11:21:33.593][16834][][gs_ctl]: switchover completed (/opengauss/data/slave)
[omm@lhropengausssimple ~]$ gs_ctl query -d /opengauss/data/master
[2022-01-07 11:22:10.434][16926][][gs_ctl]: gs_ctl query ,datadir is /opengauss/data/master
ha state:
local_role : standby
static_connections : 1
db_state : normal
detail_information : normal
senders info:
no information
receiver info:
receiver_pid : 16882
local_role : standby
peer_role : primary
peer_state : normal
state : normal
sender_sent_location : 0/6005408
sender_write_location : 0/6005408
sender_flush_location : 0/6005408
sender_replay_location : 0/6005408
receiver_received_location : 0/6005408
receiver_write_location : 0/6005408
receiver_flush_location : 0/6005408
receiver_replay_location : 0/6005408
sync_percent : 100%
channel : 127.0.0.1:50120<--127.0.0.1:5635
[omm@lhropengausssimple ~]$ gs_ctl query -d /opengauss/data/slave/
[2022-01-07 11:22:19.877][16940][][gs_ctl]: gs_ctl query ,datadir is /opengauss/data/slave
ha state:
local_role : primary
static_connections : 1
db_state : normal
detail_information : normal
senders info:
sender_pid : 16883
local_role : primary
peer_role : standby
peer_state : normal
state : streaming
sender_sent_location : 0/6005408
sender_write_location : 0/6005408
sender_flush_location : 0/6005408
sender_replay_location : 0/6005408
receiver_received_location : 0/6005408
receiver_write_location : 0/6005408
receiver_flush_location : 0/6005408
receiver_replay_location : 0/6005408
sync_percent : 100%
sync_state : sync
sync_priority : 1
sync_most_available : off
channel : 127.0.0.1:5635-->127.0.0.1:50120
receiver info:
no information
主从failover切换
在备机操作:
[omm@lhropengausssimple ~]$ gs_ctl failover -d /opengauss/data/master/
[2022-01-07 11:25:04.187][17134][][gs_ctl]: gs_ctl failover ,datadir is /opengauss/data/master
[2022-01-07 11:25:04.188][17134][][gs_ctl]: failover term (1)
[2022-01-07 11:25:04.200][17134][][gs_ctl]: waiting for server to failover...
.[2022-01-07 11:25:05.232][17134][][gs_ctl]: done
[2022-01-07 11:25:05.232][17134][][gs_ctl]: failover completed (/opengauss/data/master)
[omm@lhropengausssimple ~]$ gs_ctl query -d /opengauss/data/slave/
[2022-01-07 11:25:21.319][17169][][gs_ctl]: gs_ctl query ,datadir is /opengauss/data/slave
ha state:
local_role : primary
static_connections : 1
db_state : normal
detail_information : normal
senders info:
no information
receiver info:
no information
[omm@lhropengausssimple ~]$ gs_ctl query -d /opengauss/data/master/
[2022-01-07 11:25:28.813][17180][][gs_ctl]: gs_ctl query ,datadir is /opengauss/data/master
ha state:
local_role : primary
static_connections : 1
db_state : normal
detail_information : normal
senders info:
no information
receiver info:
no information
-- 由于slave已经为异常库,所以,这里重启slave库
gs_ctl restart -d /opengauss/data/slave/ -m standby
[omm@lhropengausssimple ~]$ gs_ctl query -d /opengauss/data/slave/
[2022-01-07 11:27:30.297][17740][][gs_ctl]: gs_ctl query ,datadir is /opengauss/data/slave
ha state:
local_role : standby
static_connections : 1
db_state : need repair
detail_information : wal segment removed
senders info:
no information
receiver info:
no information
可见,现在为2个主库,重启“slave”之后,“slave”为standby,对于“slave”应该为备库,所以,这里只能重建:
-- 重新构建主备关系
gs_ctl build -d /opengauss/data/slave -b full -m standby
[omm@lhropengausssimple ~]$ gs_ctl build -d /opengauss/data/slave -b full -m standby
[2022-01-07 11:29:30.081][19353][][gs_ctl]: gs_ctl full build ,datadir is /opengauss/data/slave
waiting for server to shut down.... done
server stopped
[2022-01-07 11:29:31.109][19353][][gs_ctl]: current workdir is (/home/omm).
[2022-01-07 11:29:31.109][19353][][gs_ctl]: fopen build pid file "/opengauss/data/slave/gs_build.pid" success
[2022-01-07 11:29:31.109][19353][][gs_ctl]: fprintf build pid file "/opengauss/data/slave/gs_build.pid" success
[2022-01-07 11:29:31.129][19353][][gs_ctl]: fsync build pid file "/opengauss/data/slave/gs_build.pid" success
[2022-01-07 11:29:31.130][19353][][gs_ctl]: set gaussdb state file when full build:db state(building_state), server mode(standby_mode), build mode(full_build).
[2022-01-07 11:29:31.140][19353][datanode1][gs_ctl]: connect to server success, build started.
[2022-01-07 11:29:31.140][19353][datanode1][gs_ctl]: create build tag file success
[2022-01-07 11:29:31.390][19353][datanode1][gs_ctl]: clear old target dir success
[2022-01-07 11:29:31.390][19353][datanode1][gs_ctl]: create build tag file again success
[2022-01-07 11:29:31.390][19353][datanode1][gs_ctl]: get system identifier success
[2022-01-07 11:29:31.391][19353][datanode1][gs_ctl]: receiving and unpacking files...
[2022-01-07 11:29:31.391][19353][datanode1][gs_ctl]: create backup label success
info: the starting position of the xlog copy of the full build is: 0/403bdc8. the slot minimum lsn is: 0/403bdc8.
[2022-01-07 11:29:31.652][19353][datanode1][gs_ctl]: xlog start point: 0/403bdc8
[2022-01-07 11:29:31.652][19353][datanode1][gs_ctl]: begin build tablespace list
[2022-01-07 11:29:31.652][19353][datanode1][gs_ctl]: finish build tablespace list
[2022-01-07 11:29:31.652][19353][datanode1][gs_ctl]: begin get xlog by xlogstream
[2022-01-07 11:29:31.652][19353][datanode1][gs_ctl]: starting background wal receiver
[2022-01-07 11:29:31.652][19353][datanode1][gs_ctl]: starting walreceiver
[2022-01-07 11:29:31.652][19353][datanode1][gs_ctl]: begin receive tar files
[2022-01-07 11:29:31.653][19353][datanode1][gs_ctl]: receiving and unpacking files...
[2022-01-07 11:29:31.660][19353][datanode1][gs_ctl]: check identify system success
[2022-01-07 11:29:31.661][19353][datanode1][gs_ctl]: send start_replication 0/4000000 success
[2022-01-07 11:29:34.015][19353][datanode1][gs_ctl]: finish receive tar files
[2022-01-07 11:29:34.015][19353][datanode1][gs_ctl]: xlog end point: 0/7000058
[2022-01-07 11:29:34.016][19353][datanode1][gs_ctl]: fetching mot checkpoint
gs_ctl: no mot checkpoint exists
[2022-01-07 11:29:34.017][19353][datanode1][gs_ctl]: waiting for background process to finish streaming...
[2022-01-07 11:29:36.717][19353][datanode1][gs_ctl]: starting fsync all files come from source.
[2022-01-07 11:30:06.777][19353][datanode1][gs_ctl]: finish fsync all files.
[2022-01-07 11:30:06.847][19353][datanode1][gs_ctl]: build dummy dw file success
[2022-01-07 11:30:06.847][19353][datanode1][gs_ctl]: rename build status file success
[2022-01-07 11:30:06.869][19353][datanode1][gs_ctl]: build completed(/opengauss/data/slave).
[2022-01-07 11:30:07.071][19353][datanode1][gs_ctl]: waiting for server to start...
.0 log: [alarm module]can not read gauss_warning_type env.
0 log: [alarm module]host name: lhropengausssimple
0 log: [alarm module]host ip: 172.17.0.7
0 log: [alarm module]cluster name: dbcluster
0 log: [alarm module]invalid data in alarmitem file! read alarm english name failed! line: 55
0 warning: failed to open feature control file, please check whether it exists: filename=gaussdb.version, errno=2, errmessage=no such file or directory.
0 warning: failed to parse feature control file: gaussdb.version.
0 warning: failed to load the product control file, so gaussdb cannot distinguish product version.
the core dump path is an invalid directory
2022-01-07 11:30:07.396 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [backend] log: when starting as multi_standby mode, we couldn't support data replicaton.
2022-01-07 11:30:07.396 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [backend] log: [alarm module]can not read gauss_warning_type env.
2022-01-07 11:30:07.396 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [backend] log: [alarm module]host name: lhropengausssimple
2022-01-07 11:30:07.396 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [backend] log: [alarm module]host ip: 172.17.0.7
2022-01-07 11:30:07.396 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [backend] log: [alarm module]cluster name: dbcluster
2022-01-07 11:30:07.397 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [backend] log: [alarm module]invalid data in alarmitem file! read alarm english name failed! line: 55
2022-01-07 11:30:07.464 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [backend] log: loaded library "security_plugin"
2022-01-07 11:30:07.614 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [backend] warning: no explicit ip is configured for listen_addresses guc.
2022-01-07 11:30:07.614 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [backend] log: initnuma numanodenum: 1 numa_distribute_mode: none inheritthreadpool: 0.
2022-01-07 11:30:07.614 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [backend] log: reserved memory for backend threads is: 220 mb
2022-01-07 11:30:07.614 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [backend] log: reserved memory for wal buffers is: 128 mb
2022-01-07 11:30:07.614 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [backend] log: set max backend reserve memory is: 348 mb, max dynamic memory is: 11069 mb
2022-01-07 11:30:07.614 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [backend] log: shared memory 358 mbytes, memory context 11417 mbytes, max process memory 12288 mbytes
2022-01-07 11:30:07.696 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [cache] log: set data cache size(402653184)
2022-01-07 11:30:07.727 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [cache] log: set metadata cache size(134217728)
2022-01-07 11:30:07.785 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [segment_page] log: segment-page constants: df_map_size: 8156, df_map_bit_cnt: 65248, df_map_group_extents: 4175872, ipblock_size: 8168, extents_per_ipblock: 1021, ipblock_group_size: 4090, bmt_header_level0_total_pages: 8323072, bktmapentrynumberperblock: 2038, bktmapblocknumber: 25, bktbitmaxmapcnt: 512
2022-01-07 11:30:07.861 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [backend] log: gaussdb: fsync file "/opengauss/data/slave/gaussdb.state.temp" success
2022-01-07 11:30:07.861 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [backend] log: create gaussdb state file success: db state(starting_state), server mode(standby)
2022-01-07 11:30:07.911 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [backend] log: max_safe_fds = 975, usable_fds = 1000, already_open = 15
the core dump path is an invalid directory
2022-01-07 11:30:07.917 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [backend] log: the configure file /opengauss/etc/gscgroup_omm.cfg doesn't exist or the size of configure file has changed. please create it by root user!
2022-01-07 11:30:07.917 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [backend] log: failed to parse cgroup config file.
2022-01-07 11:30:07.959 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [executor] warning: failed to obtain environment value $gausslog!
2022-01-07 11:30:07.959 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [executor] detail: n/a
2022-01-07 11:30:07.959 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [executor] cause: incorrect environment value.
2022-01-07 11:30:07.959 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [executor] action: please refer to backend log for more details.
2022-01-07 11:30:07.965 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [executor] warning: failed to obtain environment value $gausslog!
2022-01-07 11:30:07.965 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [executor] detail: n/a
2022-01-07 11:30:07.965 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [executor] cause: incorrect environment value.
2022-01-07 11:30:07.965 [unknown] [unknown] localhost 140319055131584 0[0:0#0] 0 [executor] action: please refer to backend log for more details.
...........
[2022-01-07 11:30:19.120][19353][datanode1][gs_ctl]: done
[2022-01-07 11:30:19.120][19353][datanode1][gs_ctl]: server started (/opengauss/data/slave)
[2022-01-07 11:30:19.120][19353][datanode1][gs_ctl]: fopen build pid file "/opengauss/data/slave/gs_build.pid" success
[2022-01-07 11:30:19.120][19353][datanode1][gs_ctl]: fprintf build pid file "/opengauss/data/slave/gs_build.pid" success
[2022-01-07 11:30:19.145][19353][datanode1][gs_ctl]: fsync build pid file "/opengauss/data/slave/gs_build.pid" success
[omm@lhropengausssimple ~]$
[omm@lhropengausssimple ~]$
[omm@lhropengausssimple ~]$ gs_ctl query -d /opengauss/data/slave/
[2022-01-07 11:30:34.278][19488][][gs_ctl]: gs_ctl query ,datadir is /opengauss/data/slave
ha state:
local_role : standby
static_connections : 1
db_state : normal
detail_information : normal
senders info:
no information
receiver info:
receiver_pid : 19472
local_role : standby
peer_role : primary
peer_state : normal
state : normal
sender_sent_location : 0/8000148
sender_write_location : 0/8000148
sender_flush_location : 0/8000148
sender_replay_location : 0/8000148
receiver_received_location : 0/8000148
receiver_write_location : 0/8000148
receiver_flush_location : 0/8000148
receiver_replay_location : 0/8000148
sync_percent : 100%
channel : 127.0.0.1:39592<--127.0.0.1:5435
[omm@lhropengausssimple ~]$ gs_ctl query -d /opengauss/data/master
[2022-01-07 11:30:38.960][19497][][gs_ctl]: gs_ctl query ,datadir is /opengauss/data/master
ha state:
local_role : primary
static_connections : 1
db_state : normal
detail_information : normal
senders info:
sender_pid : 19473
local_role : primary
peer_role : standby
peer_state : normal
state : streaming
sender_sent_location : 0/8000148
sender_write_location : 0/8000148
sender_flush_location : 0/8000148
sender_replay_location : 0/8000148
receiver_received_location : 0/8000148
receiver_write_location : 0/8000148
receiver_flush_location : 0/8000148
receiver_replay_location : 0/8000148
sync_percent : 100%
sync_state : sync
sync_priority : 1
sync_most_available : off
channel : 127.0.0.1:5435-->127.0.0.1:39592
receiver info:
no information
可见,主从已经恢复正常状态!!!
【4008云顶国际集团的版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区),文章链接,文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件至:进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容。
- 点赞
- 收藏
- 关注作者
评论(0)