一、准备阶段
两台虚拟机操作系统配置依据这篇文章
https://blog.51cto.com/u_13236892/6116256
额外添加的就是两台机器都在/etc/hosts添加对方的ip和主机名映射
二、搭建主从
1、概述
只需要在其中一台机器上传安装包和配置文件即可,要求两台机器得root密码一致
2、配置文件设置
vi /opt/software/openGauss/cluster_config.xml
3、加载环境变量
export LD_LIBRARY_PATH=/opt/software/openGauss/script/gspylib/clib:$LD_LIBRARY_PATH
4、环境初始化
cd /opt/software/openGauss/script
[root@prod script]# ./gs_preinstall -U omm -G dbgrp -X /opt/software/openGauss/cluster_config.xml
Parsing the configuration file.
Successfully parsed the configuration file.
Installing the tools on the local node.
Successfully installed the tools on the local node.
Are you sure you want to create trust for root (yes/no)? yes #输入root密码
Please enter password for root.
Password:
Creating SSH trust for the root permission user.
Checking network information.
All nodes in the network are Normal.
Successfully checked network information.
Creating SSH trust.
Creating the local key file.
Successfully created the local key files.
Appending local ID to authorized_keys.
Successfully appended local ID to authorized_keys.
Updating the known_hosts file.
Successfully updated the known_hosts file.
Appending authorized_key on the remote node.
Successfully appended authorized_key on all remote node.
Checking common authentication file content.
Successfully checked common authentication content.
Distributing SSH trust file to all node.
Successfully distributed SSH trust file to all node.
Verifying SSH trust on all hosts.
Successfully verified SSH trust on all hosts.
Successfully created SSH trust.
Successfully created SSH trust for the root permission user.
Setting pssh path
Successfully set core path.
Distributing package.
Begin to distribute package to tool path.
Successfully distribute package to tool path.
Begin to distribute package to package path.
Successfully distribute package to package path.
Successfully distributed package.
Are you sure you want to create the user[omm] and create trust for it (yes/no)? yes #创建omm设置密码
Please enter password for cluster user.
Password:
Please enter password for cluster user again.
Password:
Successfully created [omm] user on all nodes.
Preparing SSH service.
Successfully prepared SSH service.
Installing the tools in the cluster.
Successfully installed the tools in the cluster.
Checking hostname mapping.
Successfully checked hostname mapping.
Creating SSH trust for [omm] user.
Please enter password for current user[omm].
Password: #输入omm密码
Checking network information.
All nodes in the network are Normal.
Successfully checked network information.
Creating SSH trust.
Creating the local key file.
Successfully created the local key files.
Appending local ID to authorized_keys.
Successfully appended local ID to authorized_keys.
Updating the known_hosts file.
Successfully updated the known_hosts file.
Appending authorized_key on the remote node.
Successfully appended authorized_key on all remote node.
Checking common authentication file content.
Successfully checked common authentication content.
Distributing SSH trust file to all node.
Successfully distributed SSH trust file to all node.
Verifying SSH trust on all hosts.
Successfully verified SSH trust on all hosts.
Successfully created SSH trust.
Successfully created SSH trust for [omm] user.
Checking OS software.
Successfully check os software.
Checking OS version.
Successfully checked OS version.
Creating cluster's path.
Successfully created cluster's path.
Setting SCTP service.
Successfully set SCTP service.
Set and check OS parameter.
Setting OS parameters.
Successfully set OS parameters.
Warning: Installation environment contains some warning messages.
Please get more details by "/opt/software/openGauss/script/gs_checkos -i A -h node1_hostname,node2_hostname --detail".
Set and check OS parameter completed.
Preparing CRON service.
Successfully prepared CRON service.
Setting user environmental variables.
Successfully set user environmental variables.
Setting the dynamic link library.
Successfully set the dynamic link library.
Setting Core file
Successfully set core path.
Setting pssh path
Successfully set pssh path.
Set ARM Optimization.
No need to set ARM Optimization.
Fixing server package owner.
Setting finish flag.
Successfully set finish flag.
Preinstallation succeeded.
#环境初始化完成以后会发现配置文件里面的目录已经建好,用户权限基本上都已经设置好
#在有安装包的这台机器,omm用户可以免密登录自己或者集群其他用户的机器,免密配置写到当前和其他机器/home/omm/.ssh/authorized_keys里面
#omm用户必须有这个免密才能执行gs_om -t status --detail,但是日志文件拷贝却不走这个免密
5、参数检查
/opt/software/openGauss/script/gs_checkos -i A -h node1_hostname,node2_hostname --detail
会同时检查多台机器的的环境配置
cat >>/etc/sysctl.conf
6、数据库安装
su - omm
gs_install -X /opt/software/openGauss/cluster_config.xml
--gsinit-parameter="--encoding=UTF8"
--dn-guc="max_connections=10000"
--dn-guc="max_process_memory=12GB"
--dn-guc="shared_buffers=6GB"
--dn-guc="bulk_write_ring_size=128MB"
--dn-guc="cstore_buffers=16MB"
--dn-guc="session_timeout = 0"
--dn-guc="password_effect_time = 0"
输出内容:
Parsing the configuration file.
Check preinstall on every node.
Successfully checked preinstall on every node.
Creating the backup directory.
Successfully created the backup directory.
begin deploy..
Installing the cluster.
begin prepare Install Cluster..
Checking the installation environment on all nodes.
begin install Cluster..
Installing applications on all nodes.
Successfully installed APP.
begin init Instance..
encrypt cipher and rand files for database.
Please enter password for database: ## 数据库初始用户omm的密码复杂度要求:大写+小写+数字+特殊字符(任选3类,至少8位)
Please repeat for database:
begin to create CA cert files
The sslcert will be generated in /gauss/app/share/sslcert/om
Cluster installation is completed.
Configuring.
Deleting instances from all nodes.
Successfully deleted instances from all nodes.
Checking node configuration on all nodes.
Initializing instances on all nodes.
Updating instance configuration on all nodes.
Check consistence of memCheck and coresCheck on database nodes.
Successful check consistence of memCheck and coresCheck on all nodes.
Configuring pg_hba on all nodes.
Configuration is completed.
Successfully started cluster.
Successfully installed application.
end deploy..
三、集群基础操作
1、gs_om操作
执行任何命令会都显示集群所有节点的信息
1、查看集群状态
gs_om -t status --detail
[ Cluster State ]
cluster_state : Normal
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state
----------------------------------------------------------------------------------
1 prod.opengauss.com 192.168.0.11 6001 /gauss/data/db1 P Primary Normal
2 stb1.opengauss.com 192.168.0.12 6002 /gauss/data/db1 S Standby Normal
2、执行重启会两台机器都重启,并且主从保持原样
gs_om -t restart
3、停掉所有节点服务
gs_om -t stop
2、gs_ctl操作
1、停止单个实例
su - omm
gs_ctl stop -D /gauss/data/db1
2、启动单个实例
gs_ctl start -D /gauss/data/db1 #默认以主节点启动,如果有其他主节点就会出现双主现象,即两台机器都是primary
gs_ctl start -D /gauss/data/db1 -M standby #启动节点,以从节点启动
3、主从切换
1、主备机正常,在线手动切换
必须在要切换为主机的备机上,执行switchover命令才会生效。在主机上执行switchover命令,仅作查询使用。
su - omm -c "gs_ctl switchover -D /gauss/data/db1"
su - omm -c "gs_om -t refreshconf"
2、主节点宕机,从节点切主
从节点执行操作
su - omm -c "gs_ctl failover -D /gauss/data/db1"
su - omm -c "gs_om -t refreshconf"
4、sql查询主从状态
1、复制连接配置检查
show replconninfo1;
replconninfo1
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
localhost=192.168.0.11 localport=26001 localheartbeatport=26005 localservice=26004 remotehost=192.168.0.12 remoteport=26001 remoteheartbeatport=26005 remoteservice=26004
postgres=# show max_wal_senders;
max_wal_senders
-----------------
16
2、检查日志传送线程状态
- 在Primary机器检查日志发送线程状态
postgres=# pset expanded
Expanded display is on.
postgres=# select * from pg_stat_get_wal_senders();
-[ RECORD 1 ]--------------+----------------------------------------
pid | 140097998878464
sender_pid | 21609
local_role | Primary
peer_role | Standby
peer_state | Normal
state | Streaming
catchup_start | 2021-01-06 16:40:33.679871+08
catchup_end | 2021-01-06 16:40:33.707802+08
sender_sent_location | 0/7002380
sender_write_location | 0/7002380
sender_flush_location | 0/7002380
sender_replay_location | 0/7002380
receiver_received_location | 0/7002380
receiver_write_location | 0/7002380
receiver_flush_location | 0/7002380
receiver_replay_location | 0/7002380
sync_percent | 100%
sync_state | Async
sync_priority | 0
sync_most_available | Off
channel | 192.168.0.11:26001-->192.168.0.12:54854
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net