前期规划:
环境:麒麟V10系统 + openGauss 3.0
IP | 主机名 | |
---|---|---|
主 | 192.168.6.201 | ccf10 |
备1 | 192.168.6.202 | ccf11 |
备2 | 192.168.6.203 | ccf12 |
目录名称 | 所属用户 | 目录路径 | 权限 |
---|---|---|---|
数据库软件目录 | omm | /opt/openGauss | 755 |
数据库数据目录 | omm | /data/openGauss | 700 |
数据库备份目录 | omm | /data/backup | 700 |
数据库归档目录 | omm | /data/archive_wals | 700 |
数据库core_dump目录 | omm | /data/core_pattern | 700 |
1.查看系统环境
[root@ccf10 ~]# lscpu
架构: x86_64
...
型号名称: Intel(R) Core(TM) i7-4810MQ CPU @ 2.80GHz
[root@ccf10 ~]#
[root@ccf10 ~]# cat /etc/os-release
NAME="Kylin Linux Advanced Server"
VERSION="V10 (Sword)"
ID="kylin"
VERSION_ID="V10"
PRETTY_NAME="Kylin Linux Advanced Server V10 (Sword)"
ANSI_COLOR="0;31"
2.安装前环境配置
2.1主机名和hosts配置
[root@ccf10 ~]# hostnamectl set-hostname ccf10
--hostnamectl set-hostname ccf11
--hostnamectl set-hostname ccf12
cat >> /etc/hosts <<EOF
192.168.6.201 ccf10
192.168.6.202 ccf11
192.168.6.203 ccf12
EOF
2.2关闭防火墙
[root@ccf10 ~]# systemctl status firewalld.service
[root@ccf10 ~]# systemctl stop firewalld.service
[root@ccf10 ~]# systemctl disable firewalld.service
2.3selinux设置
[root@ccf10 ~]#sed -i 's/SELINUX\=enforcing/SELINUX\=disabled/g' /etc/selinux/config
2.4关闭透明大页transparent_hugepage
[root@ccf10 ~]# sed -i 's/quiet/quiet transparent_hugepage=never numa=off/' /etc/default/grub
[root@ccf10 ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
[root@ccf10 ~]# reboot
[root@ccf10 ~]# cat /sys/kernel/mm/transparent_hugepage/enabled
[root@ccf10 ~]# grep -i huge /proc/meminfo
2.5IPC参数设置
[root@ccf10 ~]# echo "RemoveIPC=no">> /etc/systemd/logind.conf
[root@ccf10 ~]# echo "RemoveIPC=no">> /usr/lib/systemd/system/systemd-logind.service
[root@ccf10 ~]# systemctl daemon-reload
[root@ccf10 ~]# systemctl stop systemd-logind
[root@ccf10 ~]# systemctl start systemd-logind
2.6内核参数调整/etc/sysctl.conf添加以下内容
[root@ccf10 ~]# cat >> /etc/sysctl.conf <<EOF
net.ipv4.tcp_max_tw_buckets=10000
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_keepalive_probes=9
net.ipv4.tcp_keepalive_intvl=30
net.ipv4.tcp_retries1 = 5 #默认为3
net.ipv4.tcp_syn_retries = 5 #默认为6
net.ipv4.tcp_synack_retries = 5
net.ipv4.tcp_retries2 = 12 #默认为15
net.ipv4.tcp_rmem = 8192 250000 16777216
vm.overcommit_memory = 0
net.ipv4.tcp_wmem = 8192 250000 16777216
net.core.wmem_max = 21299200
net.core.rmem_max = 21299200
net.core.wmem_default = 21299200
net.core.rmem_default = 21299200
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_sack = 1
net.ipv4.tcp_timestamps = 1
fs.aio-max-nr=1048576
fs.file-max= 76724600
kernel.sem = 4096 2147483647 2147483646 512000
kernel.shmall = 1048576 # page, 80% MEM
kernel.shmmax = 4294967296 # bytes, 80% MEM
kernel.shmmni = 819200
net.core.netdev_max_backlog = 65535
net.core.somaxconn = 65535
net.ipv4.tcp_fin_timeout = 60
vm.swappiness = 0
net.ipv4.ip_local_port_range = 26000 65535
fs.nr_open = 20480000
EOF
2.7时区配置,如果不是CST建议调整
[root@ccf10 ~]# cat /etc/localtime
如果不是CST建议调整:
timedatectl set-timezone 'Asia/Shanghai'
date
hwclock -r
2.8创建用户与目录
groupadd -g 1000 dbgrp
useradd -u 1000 omm -g dbgrp
echo "Omm@1000"|passwd omm --stdin
mkdir -p /data/{openGauss,backup,archive_wals,core_pattern}
chmod 700 /data/{openGauss,backup,archive_wals,core_pattern}
chown -R omm:dbgrp /data/{openGauss,backup,archive_wals,core_pattern}
mkdir -p /opt/openGauss
chown omm:dbgrp -R /opt/openGauss/
chmod 755 -R /opt/openGauss/
2.9修改资源限制/etc/security/limits.conf添加以下内容
[root@ccf10 ~]# cat >> /etc/security/limits.conf <<EOF
omm soft nproc unlimited
omm hard nproc unlimited
omm soft nofile 1000000
omm hard nofile 1000000
omm soft stack unlimited
omm hard stack unlimited
omm soft core unlimited
omm hard core unlimited
omm soft memlock unlimited
EOF
2.10core_pattern设置,为记录数据库异常宕机信息
[root@ccf10 ~]# cat /proc/sys/kernel/core_pattern
[root@ccf10 ~]# echo "/data/core_pattern/core-%e-%p-%t"> /proc/sys/kernel/core_pattern
2.11配置yum源并安装依赖包
umount /dev/sr0
mount /dev/sr0 /mnt
[root@ccf10 yum.repos.d]# vi /etc/yum.repos.d/kylin_x86_64.repo
###Kylin Linux Advanced Server 10 - os repo###
[local]
name=Kylin Linux Advanced Server 10
baseurl=file:///mnt
enabled=1
gpgcheck=0
gpgkey=file:///mnt/RPM-GPG-KEY-kylin
yum repolist
yum
install -y zlib-devel libaio libuuid readline-devel krb5-libs libicu
libxslt tcl perl openldap pam openssl-devel libxml2 python3
2.12修改默认python版本
[root@ccf10 script]# python -V
Python 2.7.18
[root@ccf10 script]# which python
/usr/bin/python
[root@ccf10 script]# mv /usr/bin/python /usr/bin/pythonbak
[root@ccf10 script]# ln -s /usr/bin/python3
python3 python3.7m python3-chardetect
python3.7 python3.7m-config python3-config
python3.7-config python3.7m-x86_64-config
[root@ccf10 script]# ln -s /usr/bin/python3 /usr/bin/python
[root@ccf10 script]#
[root@ccf10 script]# python -V
Python 3.7.9
2.13设置root用户远程登录
vim /etc/ssh/sshd_config
a.修改权限配置
•注释掉“PermitRootLogin no”。
#PermitRootLogin no
•将“PermitRootLogin”改为“yes”。
PermitRootLogin yes
b.修改Banner配置
vim /etc/ssh/sshd_config
修改Banner配置,注释掉“Banner”所在的行。
#Banner XXXX
systemctl restart sshd.service
2.14对于X86,MTU值推荐1500;对于ARM,MTU值推荐8192。
--ifconfig 网卡名称 mtu mtu值
ifconfig ens32 mtu 8192
对虚拟机内存小的情况,关闭swap交换内存
swapoff -a
3.数据库安装配置(采用cluster_config.xml安装主从)
需配置root与omm用户ssh互信
# 每个节点都执行
ssh-keygen -t rsa # 一路回车
# 将公钥添加到认证文件中
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
# 并设置authorized_keys的访问权限
chmod 600 ~/.ssh/authorized_keys
# 只要在一个节点执行即可。这里在 192.168.6.201上执行
ssh 192.168.6.202 cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys
ssh 192.168.6.203 cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys
# 分发整合后的文件到其它节点
scp ~/.ssh/authorized_keys 192.168.6.202:~/.ssh/
scp ~/.ssh/authorized_keys 192.168.6.203:~/.ssh/
3.1解压文件及配置cluster_config.xml
[root@ccf10 ~]# cd /opt/openGauss/
[root@ccf10 openGauss]# mv /root/openGauss-3.0.0-openEuler-64bit-all.tar.gz ./
tar -zxvf openGauss-3.0.0-openEuler-64bit-all.tar.gz
tar -zxvf openGauss-3.0.0-openEuler-64bit-om.tar.gz
[root@ccf10 openGauss]# cp script/gspylib/etc/conf/cluster_config_template.xml /home/omm/cluster_config.xml
[root@ccf10 openGauss]# vi /home/omm/cluster_config.xml
<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
<!-- openGauss整体信息 -->
<CLUSTER>
<!-- 数据库名称 -->
<PARAM name="clusterName" value="openGauss" />
<!-- 数据库节点名称(hostname) -->
<PARAM name="nodeNames" value="ccf10,ccf11,ccf12" />
<!-- 数据库安装目录-->
<PARAM name="gaussdbAppPath" value="/opt/openGauss/install/app" />
<!-- 日志目录-->
<PARAM name="gaussdbLogPath" value="/var/log/omm" />
<!-- 临时文件目录-->
<PARAM name="tmpMppdbPath" value="/opt/openGauss/tmp"/>
<!-- 数据库工具目录-->
<PARAM name="gaussdbToolPath" value="/opt/openGauss/install/om" />
<!-- 数据库core文件目录-->
<PARAM name="corePath" value="/data/core_pattern"/>
<!-- 节点IP,与数据库节点名称列表一一对应 -->
<PARAM name="backIp1s" value="192.168.6.201,192.168.6.202,192.168.6.203"/>
</CLUSTER>
<!-- 每台服务器上的节点部署信息 -->
<DEVICELIST>
<!-- node1上的节点部署信息 -->
<DEVICE sn="omm1">
<!-- 节点1的主机名称 -->
<PARAM name="name" value="ccf10"/>
<!-- 节点1所在的AZ及AZ优先级 -->
<PARAM name="azName" value="AZ1"/>
<PARAM name="azPriority" value="1"/>
<!-- 如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP -->
<PARAM name="backIp1" value="192.168.6.201"/>
<PARAM name="sshIp1" value="192.168.6.201"/>
<!-- cm主 -->
<!--CM数据目录-->
<PARAM name="cmsNum" value="1"/>
<PARAM name="cmDir" value="/opt/openGauss/install/cm"/>
<!--主节点CM监听端口-->
<PARAM name="cmServerPortBase" value="8008"/>
<!--CM所有实例所在节点名及监听ip-->
<PARAM name="cmServerRelation" value="ccf10,ccf11,ccf12"/>
<PARAM name="cmServerListenIp1" value="192.168.6.201,192.168.6.202,192.168.6.203"/>
<PARAM name="cmServerHaIp1" value="192.168.6.201,192.168.6.202,192.168.6.203"/>
<!-- cmServerlevel目前只支持1 -->
<PARAM name="cmServerlevel" value="1"/>
<!--dnnode-->
<PARAM name="dataNum" value="1"/>
<!--DBnode端口号-->
<PARAM name="dataPortBase" value="15400"/>
<!--DBnode主节点上数据目录,及备机数据目录-->
<PARAM name="dataNode1" value="/data/openGauss,ccf11,/data/openGauss,ccf12,/data/openGauss"/>
<!--DBnode节点上设定同步模式的节点数-->
<PARAM name="dataNode1_syncNum" value="1"/>
</DEVICE>
<!-- node2上的节点部署信息,其中“name”的值配置为主机名称 -->
<DEVICE sn="omm2">
<!-- 节点2的主机名称 -->
<PARAM name="name" value="ccf11"/>
<!-- 节点2所在的AZ及AZ优先级 -->
<PARAM name="azName" value="AZ1"/>
<PARAM name="azPriority" value="1"/>
<!-- 如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP -->
<PARAM name="backIp1" value="192.168.6.202"/>
<PARAM name="sshIp1" value="192.168.6.202"/>
<!-- cm -->
<PARAM name="cmDir" value="/opt/openGauss/install/cm"/>
<!--备节点CM监听端口-->
<PARAM name="cmServerPortStandby" value="8008"/>
</DEVICE>
<!-- node3上的节点部署信息,其中“name”的值配置为主机名称 -->
<DEVICE sn="omm3">
<!-- 节点3的主机名称 -->
<PARAM name="name" value="ccf12"/>
<!-- 节点3所在的AZ及AZ优先级 -->
<PARAM name="azName" value="AZ1"/>
<PARAM name="azPriority" value="1"/>
<!-- 如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP -->
<PARAM name="backIp1" value="192.168.6.203"/>
<PARAM name="sshIp1" value="192.168.6.203"/>
<!-- cm -->
<PARAM name="cmDir" value="/opt/openGauss/install/cm"/>
<!--备节点CM监听端口-->
<PARAM name="cmServerPortStandby" value="8008"/>
</DEVICE>
</DEVICELIST>
</ROOT>
3.2执行预安装脚本
[root@ccf10 script]# ./gs_preinstall -U omm -G dbgrp -X /home/omm/cluster_config.xml
[root@ccf10 script]# chown omm:dbgrp -R /opt/openGauss/
3.3执行安装脚本(默认SQL_ASCII字符)
[root@ccf10 script]# su - omm
[omm@ccf10 ~]$ cd /opt/openGauss/script/
[omm@ccf10 script]$ ./gs_install -X /home/omm/cluster_config.xml
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:
Please repeat for database:
begin to create CA cert files
The sslcert will be generated in /opt/openGauss/install/app/share/sslcert/om
Create CA files for cm beginning.
Create CA files on directory [/opt/openGauss/install/app_02c14696/share/sslcert/cm]. file list: ['cacert.pem', 'server.key', 'server.crt', 'client.key', 'client.crt', 'server.key.cipher', 'server.key.rand', 'client.key.cipher', 'client.key.rand']
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.
Starting cluster.
======================================================================
Successfully started primary instance. Wait for standby instance.
======================================================================
.
Successfully started cluster.
======================================================================
cluster_state : Normal
redistributing : No
node_count : 3
Datanode State
primary : 1
standby : 2
secondary : 0
cascade_standby : 0
building : 0
abnormal : 0
down : 0
Successfully installed application.
end deploy..
[omm@ccf10 script]$
3.4安装完成,环境变量修改
[omm@ccf10 script]$ cd
[omm@ccf10 ~]$ cat >> /home/omm/.bashrc <<EOF
export PGPORT=15400 #改成前面cluster_config.xml配置的端口
export PGDATA=/data/openGauss
EOF
[omm@ccf10 ~]$ source .bashrc
检查主从
[omm@ccf10 ~]$ gs_ctl query
[2022-10-07 09:33:52.205][99660][][gs_ctl]: gs_ctl query ,datadir is /data/openGauss
HA state:
local_role : Primary
static_connections : 2
db_state : Normal
detail_information : Normal
Senders info:
sender_pid : 77516
local_role : Primary
peer_role : Standby
peer_state : Normal
state : Streaming
sender_sent_location : 0/60001E8
sender_write_location : 0/60001E8
sender_flush_location : 0/60001E8
sender_replay_location : 0/60001E8
receiver_received_location : 0/60001E8
receiver_write_location : 0/60001E8
receiver_flush_location : 0/60001E8
receiver_replay_location : 0/60001E8
sync_percent : 100%
sync_state : Quorum
sync_priority : 1
sync_most_available : Off
channel : 192.168.6.201:15401-->192.168.6.203:31106
sender_pid : 77522
local_role : Primary
peer_role : Standby
peer_state : Normal
state : Streaming
sender_sent_location : 0/60001E8
sender_write_location : 0/60001E8
sender_flush_location : 0/60001E8
sender_replay_location : 0/60001E8
receiver_received_location : 0/60001E8
receiver_write_location : 0/60001E8
receiver_flush_location : 0/60001E8
receiver_replay_location : 0/60001E8
sync_percent : 100%
sync_state : Quorum
sync_priority : 1
sync_most_available : Off
channel : 192.168.6.201:15401-->192.168.6.202:34426
Receiver info:
No information
[omm@ccf10 ~]$
[omm@ccf10 ~]$ gs_om -t status --detail
[ CMServer State ]
node node_ip instance state
-------------------------------------------------------------------------
1 ccf10 192.168.6.201 1 /opt/openGauss/install/cm/cm_server Primary
2 ccf11 192.168.6.202 2 /opt/openGauss/install/cm/cm_server Standby
3 ccf12 192.168.6.203 3 /opt/openGauss/install/cm/cm_server Standby
[ Cluster State ]
cluster_state : Normal
redistributing : No
balanced : Yes
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state
---------------------------------------------------------------
1 ccf10 192.168.6.201 6001 /data/openGauss P Primary Normal
2 ccf11 192.168.6.202 6002 /data/openGauss S Standby Normal
3 ccf12 192.168.6.203 6003 /data/openGauss S Standby Normal
[omm@ccf10 ~]$
3.5设置备机可读
备机可读特性为可选特性,需要修改配置参数并重启主备机器后才能使用。在开启备机可读之后,备机将支持读操作,并满足数据一致性要求。
操作步骤
1.如果主备机上的openGauss数据库实例正在运行,请先分别停止主备机上的数据库实例。
2.分别打开主机与备机的postgresql.conf配置文件,找到并将对应参数修改为:wal_level=hot_standby;hot_standby = on。默认装完正确的
3.参数max_standby_streaming_delay, max_prepared_transactions, max_standby_archive_delay, hot_standby_feedback可以参考开发者指南中参数说明按需进行设置。
4.修改完成后,分别启动主备机即可。
[omm@ccf10 ~]$ grep -Ev '^$|^\s*#' $PGDATA/postgresql.conf #默认值
listen_addresses = 'localhost,192.168.6.201' # what IP address(es) to listen on;
local_bind_address = '192.168.6.201'
port = 15400 # (change requires restart)
max_connections = 5000 # (change requires restart)
unix_socket_directory = '/opt/openGauss/tmp' # (change requires restart)
unix_socket_permissions = 0700 # begin with 0 to use octal notation
session_timeout = 10min # allowed duration of any unused session, 0s-86400s(1 day), 0 is disabled
ssl = on # (change requires restart)
ssl_cert_file = 'server.crt' # (change requires restart)
ssl_key_file = 'server.key' # (change requires restart)
ssl_ca_file = 'cacert.pem' # (change requires restart)
modify_initial_password = true #Whether to change the initial password of the initial user
max_process_memory = 2GB
shared_buffers = 553MB # min 128kB
bulk_write_ring_size = 2GB # for bulkload, max shared_buffers
max_prepared_transactions = 800 # zero disables the feature
work_mem = 64MB # min 64kB
maintenance_work_mem = 128MB # min 1MB
cstore_buffers = 1GB #min 16MB
wal_level = hot_standby # minimal, archive, hot_standby or logical
checkpoint_segments = 64 # in logfile segments, min 1, 16MB each
enable_incremental_checkpoint = on # enable incremental checkpoint
incremental_checkpoint_timeout = 60s # range 1s-1h
max_wal_senders = 16 # max number of walsender processes
wal_keep_segments = 16 # in logfile segments, 16MB each; 0 disables
enable_slot_log = off
max_replication_slots = 8 # max number of replication slots.i
replconninfo1 = 'localhost=192.168.6.201 localport=15401 localheartbeatport=15405 localservice=15404 remotehost=192.168.6.202 remoteport=15401 remoteheartbeatport=15405 remoteservice=15404' # replication connection information used to connect primary on standby, or standby on primary,
replconninfo2 = 'localhost=192.168.6.201 localport=15401 localheartbeatport=15405 localservice=15404 remotehost=192.168.6.203 remoteport=15401 remoteheartbeatport=15405 remoteservice=15404' # replication connection information used to connect secondary on primary or standby,
synchronous_standby_names = 'ANY 1(dn_6002,dn_6003)' # standby servers that provide sync rep
data_replicate_buffer_size = 128MB # data replication buffer size
walsender_max_send_size = 8MB # Size of walsender max send size
enable_data_replicate = off
hot_standby = on # "on" allows queries during recovery
enable_mergejoin = off
enable_nestloop = off
enable_kill_query = off # optional: [on, off], default: off
logging_collector = on # Enable capturing of stderr and csvlog
log_directory = '/var/log/omm/omm/pg_log/dn_6001' # directory where log files are written,
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # log file name pattern,
log_file_mode = 0600 # creation mode for log files,
log_rotation_size = 20MB # Automatic rotation of logfiles will
log_min_duration_statement = 1800000 # -1 is disabled, 0 logs all statements
log_connections = off # log connection requirement from client
log_disconnections = off # log disconnection from client
log_duration = off # log the execution time of each query
log_hostname = off # log hostname
log_line_prefix = '%m %c %d %p %a %x %n %e ' # special values:
log_timezone = 'PRC'
enable_alarm = on
connection_alarm_rate = 0.9
alarm_report_interval = 10
alarm_component = '/opt/huawei/snas/bin/snas_cm_cmd'
use_workload_manager = off # Enables workload manager in the system.
autovacuum = on # Enable autovacuum subprocess? default value is 'on'
datestyle = 'iso, mdy'
timezone = 'PRC'
lc_messages = 'C' # locale for system error message
lc_monetary = 'C' # locale for monetary formatting
lc_numeric = 'C' # locale for number formatting
lc_time = 'C' # locale for time formatting
default_text_search_config = 'pg_catalog.english'
lockwait_timeout = 1200s # Max of lockwait_timeout and deadlock_timeout + 1s
pgxc_node_name = 'dn_6001_6002_6003' # Coordinator or Datanode name
audit_enabled = on
audit_directory = '/var/log/omm/omm/pg_audit/dn_6001'
explain_perf_mode = pretty
job_queue_processes = 10 # Number of concurrent jobs, optional: [0..1000], default: 10.
replication_type = 1
application_name = 'dn_6001'
recovery_max_workers = 4
enable_global_syscache = off
enable_double_write = on
available_zone = 'AZ1'
以下为修改内容:
sed -i 's/max_connections \= 5000/max_connections \= 8000/g' $PGDATA/postgresql.conf
sed -i 's/max_process_memory \= 2GB/max_process_memory \= 2GB/g' $PGDATA/postgresql.conf #75%MEM
sed -i 's/shared_buffers \= 553MB/shared_buffers \= 600MB/g' $PGDATA/postgresql.conf #25%MEM
sed -i 's/work_mem \= 64MB/work_mem \= 64MB/g' $PGDATA/postgresql.conf
sed -i 's/maintenance_work_mem \= 128MB/maintenance_work_mem \= 128MB/g' $PGDATA/postgresql.conf
sed -i 's/cstore_buffers \= 16MB/cstore_buffers \= 16MB/g' $PGDATA/postgresql.conf
sed -i 's/session_timeout \= 10min/session_timeout \= 0/g' $PGDATA/postgresql.conf
cat >> $PGDATA/postgresql.conf<<EOF
effective_cache_size=1GB #75% OS_MEM
vacuum_cost_limit = 10000
archive_mode = on
archive_dest='/data/archive_wals'
autovacuum_max_workers=5
autovacuum_naptime=20s
autovacuum_vacuum_cost_delay=0
track_sql_count=on
log_statement='ddl'
password_reuse_time=90
password_encryption_type=0 #如果要使用pg兼容的客户端工具,建议设置成0
random_page_cost=1.4 #根据实际情况来定,如果是SSD建议1.2或者1.4
password_effect_time = 0 #The password effect time(0-999),默认值90d
password_notify_time = 0 #The password notify time(0-999),默认值7d
max_files_per_process = 100000 # 允许同时打开的files的最大数量
track_activity_query_size=4096 # 设置用于跟踪每一个活动会话的当前正在执行命令的字节数
remote_read_mode=non_authentication
hot_standby_feedback = on
EOF
[omm@ccf10 ~]$ grep -Ev '^$|^\s*#' $PGDATA/postgresql.conf
3.6集群状态查询及启停
(1)状态查询
[omm@ccf10 ~]$ cm_ctl query -Cv
[ CMServer State ]
node instance state
-------------------------
1 ccf10 1 Primary
2 ccf11 2 Standby
3 ccf12 3 Standby
[ Cluster State ]
cluster_state : Normal
redistributing : No
balanced : Yes
current_az : AZ_ALL
[ Datanode State ]
node instance state | node instance state | node instance state
---------------------------------------------------------------------------------------------------------------
1 ccf10 6001 P Primary Normal | 2 ccf11 6002 S Standby Normal | 3 ccf12 6003 S Standby Normal
[omm@ccf10 ~]$
(2)集群启停
启动集群,可以在任一节点执行启停。
cm_ctl stop
cm_ctl start
单独启停节点1服务
cm_ctl stop -n 1 -D $PGDATA
cm_ctl start -n 1 -D $PGDATA
3.7验证
[omm@ccf10 ~]$ gsql -d postgres -r
gsql ((openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:19 commit 0 last mr )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
openGauss=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+-------+-----------+---------+-------+-------------------
postgres | omm | SQL_ASCII | C | C |
template0 | omm | SQL_ASCII | C | C | =c/omm +
| | | | | omm=CTc/omm
template1 | omm | SQL_ASCII | C | C | =c/omm +
| | | | | omm=CTc/omm
(3 rows)
openGauss=# CREATE DATABASE mydb WITH ENCODING 'GBK' template = template0;
CREATE DATABASE
openGauss=# CREATE DATABASE mydb1 WITH ENCODING 'UTF8' template = template0;
CREATE DATABASE
openGauss=#
openGauss=# \c mydb
Non-SSL connection (SSL connection is recommended when requiring high-security)
You are now connected to database "mydb" as user "omm".
mydb=# CREATE USER ccf IDENTIFIED BY 'Ccf.1234';
CREATE ROLE
mydb=#
mydb=# CREATE TABLESPACE tbs_ccf RELATIVE LOCATION 'tablespace/tablespace_1';
CREATE TABLESPACE
mydb=# GRANT CREATE ON TABLESPACE tbs_ccf TO ccf;
GRANT
mydb=# create table ccf.chen01(i int);
CREATE TABLE
mydb=# insert into ccf.chen01 values(1);
INSERT 0 1
mydb=# select * from ccf.chen01;
i
---
1
(1 row)
mydb=#
测试建库建表均成功在备库查询到,创建完成。
[root@ccf10 ~]# shutdown -h now
[omm@ccf12 ~]$ cm_ctl query -Cv
[ CMServer State ]
node instance state
-------------------------
1 ccf10 1 Down
2 ccf11 2 Standby
3 ccf12 3 Primary
[ Cluster State ]
cluster_state : Degraded
redistributing : No
balanced : No
current_az : AZ_ALL
[ Datanode State ]
node instance state | node instance state | node instance state
---------------------------------------------------------------------------------------------------------------
1 ccf10 6001 P Down Unknown | 2 ccf11 6002 S Primary Normal | 3 ccf12 6003 S Standby Normal
[omm@ccf12 ~]$
[omm@ccf10 ~]$ gs_om -t status --detail
[ CMServer State ]
node node_ip instance state
-------------------------------------------------------------------------
1 ccf10 192.168.6.201 1 /opt/openGauss/install/cm/cm_server Standby
2 ccf11 192.168.6.202 2 /opt/openGauss/install/cm/cm_server Standby
3 ccf12 192.168.6.203 3 /opt/openGauss/install/cm/cm_server Primary
[ Cluster State ]
cluster_state : Normal
redistributing : No
balanced : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state
---------------------------------------------------------------
1 ccf10 192.168.6.201 6001 /data/openGauss P Standby Normal
2 ccf11 192.168.6.202 6002 /data/openGauss S Primary Normal
3 ccf12 192.168.6.203 6003 /data/openGauss S Standby Normal
[omm@ccf10 ~]$ cm_ctl query -Cv
[ CMServer State ]
node instance state
-------------------------
1 ccf10 1 Standby
2 ccf11 2 Standby
3 ccf12 3 Primary
[ Cluster State ]
cluster_state : Normal
redistributing : No
balanced : No
current_az : AZ_ALL
[ Datanode State ]
node instance state | node instance state | node instance state
---------------------------------------------------------------------------------------------------------------
1 ccf10 6001 P Standby Normal | 2 ccf11 6002 S Primary Normal | 3 ccf12 6003 S Standby Normal
[omm@ccf10 ~]$