1

mogdb/opengauss 手动部署(非om工具)单机,主备,主备级联架构 -利来国际app

李宏达 2021-06-13
1055

1. 关闭防火墙,selinux

systemctl disable firewalld.service systemctl stop firewalld.service setenforce=0 sed -i '/^selinux=/c'selinux=disabled /etc/selinux/config

2. 安装依赖包

yum install libaio-devel -y

3. 创建相关目录,用户,组

groupadd dbgrp -g 2000 useradd omm -g 2000 -u 2000 echo "[email protected]" | passwd --stdin omm mkdir -p /opt/mogdb/software chown -r omm:dbgrp /opt/

4. 上传并解压二进制文件

[[email protected] software]# pwd /opt/mogdb/software [[email protected] software]# ls -lrt total 90236 -r-------- 1 root root 92401412 jun 13 06:14 mogdb-2.0.0-openeuler-64bit.tar.bz2 chown omm:dbgrp mogdb-2.0.0-openeuler-64bit.tar.bz2 su - omm cd /opt/mogdb/software/ tar -xf mogdb-2.0.0-openeuler-64bit.tar.bz2

1. 配置环境变量

echo "export gausshome=/opt/mogdb/software" >> /home/omm/.bashrc && \ echo "export path=\$gausshome/bin:\$path " >> /home/omm/.bashrc && \ echo "export ld_library_path=\$gausshome/lib:\$ld_library_path" >> /home/omm/.bashrc source /home/omm/.bashrc

2. init数据库

bin/gs_initdb --pgdata=/opt/mogdb/data --nodename=primary [email protected] --encoding=utf-8 --locale=en_us.utf-8

3. 修改初始化参数

echo "port=26000" >> /opt/mogdb/data/postgresql.conf echo "listen_addresses = '0.0.0.0'" >> /opt/mogdb/data/postgresql.conf echo "password_encryption_type = 0" >> /opt/mogdb/data/postgresql.conf echo "log_directory = 'pg_log'" >> /opt/mogdb/data/postgresql.conf echo "remote_read_mode=non_authentication" >> /opt/mogdb/data/postgresql.conf echo "host all all 0.0.0.0/0 md5" >> /opt/mogdb/data/pg_hba.conf

4. 启动数据库

gs_ctl start -d /opt/mogdb/data

至此单机安装完成

1. 主库操作

  • 配置连接通道
echo "replconninfo1='localhost=172.16.0.106 localport=26001 localheartbeatport=26005 localservice=26004 remotehost=172.16.0.245 remoteport=26001 remoteheartbeatport=26005 remoteservice=26004' " >> /opt/mogdb/data/postgresql.conf

localhost为主库ip,remotehost为备库ip

  • 将主库以primary方式启动
gs_ctl restart -d /opt/mogdb/data/ -m primary

2. 备库操作

  • 前期准备工作如上(一)
  • 配置环境变量
echo "export gausshome=/opt/mogdb/software" >> /home/omm/.bashrc && \ echo "export path=\$gausshome/bin:\$path " >> /home/omm/.bashrc && \ echo "export ld_library_path=\$gausshome/lib:\$ld_library_path" >> /home/omm/.bashrc source /home/omm/.bashrc - 将主库的配置文件传到备库 scp /opt/mogdb/data/pg_hba.conf /opt/mogdb/data/postgresql.conf 172.16.0.245:/opt/mogdb/data/
  • 配置连接通道,将localhost和remotehost对调.
    sed -i “/^replconninfo1/creplconninfo1=‘localhost=172.16.0.245 localport=26001 localheartbeatport=26005 localservice=26004 remotehost=172.16.0.106 remoteport=26001 remoteheartbeatport=26005 remoteservice=26004’” /opt/mogdb/data/postgresql.conf

localhost为备库ip,remotehost为主库ip

  • 构建主备关系
gs_ctl build -d /opt/mogdb/data/ -b full -m standby
  • 查询主备状态
    • 主库
[[email protected] data]$ gs_ctl query -d /opt/mogdb/data/ [2021-06-13 07:51:41.119][159054][][gs_ctl]: gs_ctl query ,datadir is /opt/mogdb/data ha state: local_role : primary static_connections : 1 db_state : normal detail_information : normal senders info: sender_pid : 159041 local_role : primary peer_role : standby peer_state : normal state : streaming sender_sent_location : 0/14000258 sender_write_location : 0/14000258 sender_flush_location : 0/14000258 sender_replay_location : 0/14000258 receiver_received_location : 0/14000258 receiver_write_location : 0/14000258 receiver_flush_location : 0/14000258 receiver_replay_location : 0/14000258 sync_percent : 100% sync_state : sync sync_priority : 1 sync_most_available : off channel : 172.16.0.106:26001-->172.16.0.245:60856 receiver info: no information
  • 备库
[[email protected] data]$ gs_ctl query -d /opt/mogdb/data/ [2021-06-13 07:51:32.743][123204][][gs_ctl]: gs_ctl query ,datadir is /opt/mogdb/data ha state: local_role : standby static_connections : 1 db_state : normal detail_information : normal senders info: no information receiver info: receiver_pid : 123194 local_role : standby peer_role : primary peer_state : normal state : normal sender_sent_location : 0/14000140 sender_write_location : 0/14000140 sender_flush_location : 0/14000140 sender_replay_location : 0/14000140 receiver_received_location : 0/14000140 receiver_write_location : 0/14000140 receiver_flush_location : 0/14000140 receiver_replay_location : 0/14000140 sync_percent : 100% channel : 172.16.0.245:60856<--172.16.0.106:26001

至此主备已安装完成

1. 主备安装如上(一,二,三)

2. 添加复制通道

  • 主库操作
    gsql -d postgres -p26000 -c “alter system set replconninfo2 to ‘localhost=172.16.0.106 localport=26001 localheartbeatport=26005 localservice=26004 remotehost=172.16.0.127 remoteport=26001 remoteheartbeatport=26005 remoteservice=26004 iscascade=true’;”

  • 备库操作
    gsql -d postgres -p26000 -c “alter system set replconninfo2 to ‘localhost=172.16.0.245 localport=26001 localheartbeatport=26005 localservice=26004 remotehost=172.16.0.127 remoteport=26001 remoteheartbeatport=26005 remoteservice=26004 iscascade=true’;”

3. 级联库操作

  • 前期准备工作如上(一)
  • 配置环境变量
echo "export gausshome=/opt/mogdb/software" >> /home/omm/.bashrc && \ echo "export path=\$gausshome/bin:\$path " >> /home/omm/.bashrc && \ echo "export ld_library_path=\$gausshome/lib:\$ld_library_path" >> /home/omm/.bashrc source /home/omm/.bashrc
  • 将备库的配置文件传到备库
scp /opt/mogdb/data/pg_hba.conf /opt/mogdb/data/postgresql.conf 172.16.0.245:/opt/mogdb/data/
  • 配置连接通道
sed -i "/^replconninfo1/creplconninfo1='localhost=172.16.0.127 localport=26001 localheartbeatport=26005 localservice=26004 remotehost=172.16.0.106 remoteport=26001 remoteheartbeatport=26005 remoteservice=26004'" /opt/mogdb/data/postgresql.conf sed -i "/replconninfo2/creplconninfo2='localhost=172.16.0.127 localport=26001 localheartbeatport=26005 localservice=26004 remotehost=172.16.0.245 remoteport=26001 remoteheartbeatport=26005 remoteservice=26004'" /opt/mogdb/data/postgresql.conf

localhost为级联ip,remotehost为主库ip和备库ip。

  • 构建主备关系
gs_ctl build -d /opt/mogdb/data/ -b full -m cascade_standby

4 查看主备级联状态

  • 主库
[[email protected] ~]$ gs_ctl query -d /opt/mogdb/data [2021-06-13 08:37:03.281][207069][][gs_ctl]: gs_ctl query ,datadir is /opt/mogdb/data ha state: local_role : primary static_connections : 2 db_state : normal detail_information : normal senders info: sender_pid : 206143 local_role : primary peer_role : standby peer_state : normal state : streaming sender_sent_location : 0/1a000140 sender_write_location : 0/1a000140 sender_flush_location : 0/1a000140 sender_replay_location : 0/1a000140 receiver_received_location : 0/1a000140 receiver_write_location : 0/1a000140 receiver_flush_location : 0/1a000140 receiver_replay_location : 0/1a000140 sync_percent : 100% sync_state : sync sync_priority : 1 sync_most_available : off channel : 172.16.0.106:26001-->172.16.0.245:34586 receiver info: no information
  • 备库
[[email protected] ~]$ gs_ctl query -d /opt/mogdb/data [2021-06-13 08:37:09.128][147065][][gs_ctl]: gs_ctl query ,datadir is /opt/mogdb/data ha state: local_role : standby static_connections : 2 db_state : normal detail_information : normal senders info: sender_pid : 147043 local_role : standby peer_role : cascade standby peer_state : normal state : streaming sender_sent_location : 0/1a000140 sender_write_location : 0/1a000140 sender_flush_location : 0/1a000140 sender_replay_location : 0/1a000140 receiver_received_location : 0/1a000140 receiver_write_location : 0/1a000140 receiver_flush_location : 0/1a000140 receiver_replay_location : 0/1a000140 sync_percent : 100% sync_state : async sync_priority : 0 sync_most_available : off channel : 172.16.0.245:26001-->172.16.0.127:49110 receiver info: receiver_pid : 146771 local_role : standby peer_role : primary peer_state : normal state : normal sender_sent_location : 0/1a000140 sender_write_location : 0/1a000140 sender_flush_location : 0/1a000140 sender_replay_location : 0/1a000140 receiver_received_location : 0/1a000140 receiver_write_location : 0/1a000140 receiver_flush_location : 0/1a000140 receiver_replay_location : 0/1a000140 sync_percent : 100% channel : 172.16.0.245:34586<--172.16.0.106:26001
  • 级联库
[[email protected] data]$ gs_ctl query -d /opt/mogdb/data [2021-06-13 08:36:56.223][273241][][gs_ctl]: gs_ctl query ,datadir is /opt/mogdb/data ha state: local_role : cascade standby static_connections : 2 db_state : normal detail_information : normal senders info: no information receiver info: receiver_pid : 273237 local_role : cascade standby peer_role : standby peer_state : normal state : normal sender_sent_location : 0/1a000140 sender_write_location : 0/1a000140 sender_flush_location : 0/1a000140 sender_replay_location : 0/1a000140 receiver_received_location : 0/1a000140 receiver_write_location : 0/1a000140 receiver_flush_location : 0/1a000140 receiver_replay_location : 0/1a000140 sync_percent : 100% channel : 172.16.0.127:49110<--172.16.0.245:26001

至此主备级联安装完成

「喜欢文章,快来给作者赞赏墨值吧」
【利来手机国际的版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:[email protected]进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论