一、环境配制
1、确认OS版本
安装依赖包
yum -y install redhat-lsb
查看版本
[root@CentOS ~]# lsb_release -d
Description: CentOS Linux release 7.6.1810 (Core)
2、为配制本地源挂载光驱
root下执行
mkdir -p /media/cdrom/
mount /dev/cdrom /media/cdrom
或使用iso文件
mkdir -p /media/cdrom/
mount -o loop /root/CentOS-7.6-x86_64-DVD-1804.iso /media/cdrom
3、配制本地源
root下执行
整理/etc/yum.repos.d/ 下的文件,可以只保留一个,内容改为
[base]
name=base
baseurl=file:///media/cdrom
enabled=1
gpgcheck=0
root下执行
yum clean all
yum makecache
4、安装python3
root下执行
1).安装依赖环境
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel gcc-c++ lrzsz
2).下载Python3
地址 https://www.python.org/downloads/
wget https://www.python.org/ftp/python/3.6.15/Python-3.6.15.tgz
3).安装python3
mkdir -p /usr/local/python3
tar -zxvf Python-3.6.15.tgz -C /usr/local/python3
4).进入解压后的目录,编译安装。
安装在 /usr/local/python3
cd /usr/local/python3/Python-3.6.15
./configure --prefix=/usr/local/python3 --enable-shared CFLAGS=-fPIC
make && make install
5).建立python3的软链
ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3.6 -f
ln -s /usr/local/python3/bin/python3 /usr/bin/python3 -f
ln -s /usr/local/python3/bin/pip3.6 /usr/bin/pip3.6 -f
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 -f
6).复制so
cp /usr/local/python3/Python-3.6.15/libpython3.6m.so.1.0 /usr/lib64/
7).并将/usr/local/python3/bin加入PATH(OMM下也要配制)
配制环境变量
vim ~/.bash_profile
# User specific environment and startup programs
PATH=$PATH:/usr/local/python3/bin
export PATH
8).验正版本
# python3 -V
Python 3.6.15
# pip3 -V
pip 18.1 from /usr/local/python3/lib/python3.6/site-packages/pip (python 3.6)
5、启动命令界面
systemctl set-default multi-user.target
6、禁止 SELINUX、防火墙
systemctl disable firewalld.service
systemctl stop firewalld.service
sed -i '/^SELINUX=/c'SELINUX=disabled /etc/selinux/config
重启后确认更改正确
[root@mogdb-02 ~]# getenforce
Disabled
7、安装依赖包
yum install bzip2-x86_64 libaio-devel flex bison ncurses-devel glibc-devel patch redhat-lsb-core readline-devel lrzsz tigervnc-server
8、设置编码
echo "export LANG=en_US.UTF-8" >> ~/.bash_profile
9、关闭swap交换内存
cp /etc/fstab /etc/fstab.bak
sed -i '/swap/s/^/#/' /etc/fstab
cat /etc/fstab|grep -v ^#|grep -v '^$'
关闭swap
swapoff -a
10、MTU使用默认值
[root@CentOS-7 ~]# ifconfig | grep mtu
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
11、设置root用户远程登录
sed -i 's/^Banner .*/Banner none/' /etc/ssh/sshd_config
sed -i 's/^#PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config
sed -i 's/^PermitRootLogin no/PermitRootLogin yes/' /etc/ssh/sshd_config
systemctl restart sshd
[root@CentOS yum.repos.d]# egrep 'Banner|PermitRootLogin' /etc/ssh/sshd_config
PermitRootLogin yes
# the setting of "PermitRootLogin without-password".
#Banner none
12、关闭透明大页
验正是否关闭
[root@mogdb-304 ~]# cat /proc/sys/vm/nr_hugepages
0
[root@mogdb-304 ~]# grep -i HugePages_Total /proc/meminfo
HugePages_Total: 0
关闭:更改 /etc/default/grub,增加 transparent_hugepage=never
[root@mogdb-304 ~]# cat /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos_centos-76/root rd.lvm.lv=centos_centos-76/swap rd.lvm.lv=centos_centos-76/usr rhgb quiet transparent_hugepage=never"
GRUB_DISABLE_RECOVERY="true"
13、更改文件系统参数
vi /etc/security/limits.conf
root soft as unlimited
omm soft as unlimited
root hard as unlimited
omm hard as unlimited
root soft nproc unlimited
omm soft nproc unlimited
root hard nproc unlimited
omm hard nproc unlimited
* soft nofile 1000000
* hard nofile 1000000
* stack size 3072
14、准备安装目录
mkdir -p /opt/mogdb/db1
mkdir -p /opt/mogdb
mkdir -p /opt/omm/mogdb
cd /opt/omm/mogdb
15、手动配制ssh互信
PTK可自动配置互信,如果遇到问题可以手动配制
ssh-keygen -t rsa
ssh-copy-id mogdb-02
二、PTK安装
参见: https://docs.mogdb.io/zh/ptk/v1.1/install
1. 安装
curl --proto '=https' --tlsv1.2 -sSf https://cdn-mogdb.enmotech.com/ptk/install.sh | sh
安装后,重连ssh,或重启或执行下面命令
export PATH=/root/.ptk/bin:$PATH
2. 升级
ptk self upgrade
3. 查看下载链接
无外网环境下可以用下面的命令查看对应的MogDB下载链接,根据得到的地址去下载
./ptk download --dryrun
[root@localhost omm]# ./ptk download --dryrun
INFO[2023-10-23T18:47:55.460] PTK Version: 1.0.9 release
INFO[2023-10-23T18:47:55.460] detect current os...
INFO[2023-10-23T18:47:55.536] target url: https://cdn-mogdb.enmotech.com/mogdb-media/5.0.2/Kylin_x86_64/MogDB-5.0.2-Kylin-x86_64-all.tar.gz
三、单机安装
单机安装不支持CM,配制CM会有提示
[PTK-4039] cm_servers requires at least 2 hosts
1、配制安装参数
参见: https://docs.mogdb.io/zh/ptk/v1.1/usage-config
[root@mogdb-02 software]# cat config.yaml
global:
cluster_name: dbCluster
user: omm
group: dbgrp
base_dir: /opt/mogdb
data_dir: /opt/mogdb/db1
tool_dir: /opt/mogdb/tool
tmp_dir: /opt/mogdb/tmp
log_dir: /opt/mogdb/log
db_servers:
- host: 192.168.56.66
db_port: 5432
2、checkos
check时增加参数 gen-warning-fix # 输出 root-fix 脚本的时候,将 warning 级别的检查项也生成修复指令
[root@mogdb-02 software]# ptk checkos -f config.yaml --gen-warning-fix
INFO[2022-12-02T10:59:20.876] prechecking dependent tools...
INFO[2022-12-02T10:59:21.223] [192.168.56.61][omm] check port 5432
INFO[2022-12-02T10:59:22.093] [192.168.56.61][omm] port 5432 is free
ERRO[2022-12-02T10:59:42.772] [192.168.56.61][omm] not found package: numactl
INFO[2022-12-02T10:59:42.790] [192.168.56.61][omm] platform: centos_7_64bit
INFO[2022-12-02T10:59:42.796] [192.168.56.61][omm] kernel version: 3.10.0-957.el7.x86_64
INFO[2022-12-02T10:59:42.868] [192.168.56.61][omm] locale: LANG=en_US.UTF-8
INFO[2022-12-02T10:59:42.883] [192.168.56.61][omm] timezone: +0800
WARN[2022-12-02T10:59:42.906] [192.168.56.61][omm] device(dm-1) 'IO Request'=128, expect 256
WARN[2022-12-02T10:59:42.906] [192.168.56.61][omm] device(dm-8) 'IO Request'=128, expect 256
WARN[2022-12-02T10:59:42.906] [192.168.56.61][omm] device(sda) 'IO Request'=32768, expect 256
WARN[2022-12-02T10:59:42.906] [192.168.56.61][omm] device(sr0) 'IO Request'=32768, expect 256
WARN[2022-12-02T10:59:42.907] [192.168.56.61][omm] device(dm-0) 'IO Request'=128, expect 256
WARN[2022-12-02T10:59:42.907] [192.168.56.61][omm] device(dm-2) 'IO Request'=128, expect 256
WARN[2022-12-02T10:59:42.907] [192.168.56.61][omm] device(dm-3) 'IO Request'=128, expect 256
WARN[2022-12-02T10:59:42.907] [192.168.56.61][omm] device(dm-4) 'IO Request'=128, expect 256
WARN[2022-12-02T10:59:42.907] [192.168.56.61][omm] device(dm-5) 'IO Request'=128, expect 256
WARN[2022-12-02T10:59:42.907] [192.168.56.61][omm] device(dm-6) 'IO Request'=128, expect 256
WARN[2022-12-02T10:59:42.907] [192.168.56.61][omm] device(dm-7) 'IO Request'=128, expect 256
INFO[2022-12-02T10:59:42.924] [192.168.56.61][omm] swap memory 10485756kB, total memory 8008932kB
WARN[2022-12-02T10:59:42.931] [192.168.56.61][omm] net.ipv4.tcp_retries1=3, expect 5
WARN[2022-12-02T10:59:43.033] [192.168.56.61][omm] net.ipv4.tcp_syn_retries=6, expect 5
INFO[2022-12-02T10:59:43.114] [192.168.56.61][omm] check kernel.core_pattern
INFO[2022-12-02T10:59:43.126] [192.168.56.61][omm] check removeIPC value
INFO[2022-12-02T10:59:43.199] all checkers finished
INFO[2022-12-02T10:59:43.200] write fix os script to root_fix_os.2022.1202.105943.sh success
INFO[2022-12-02T10:59:43.200] Time elapsed: 22s
# Check Results
Item | Level
------------------------------------+-----------
A1.Check_OS_Version | OK
A2.Check_Kernel_Version | OK
A3.Check_Unicode | OK
A4.Check_TimeZone | OK
A5.Check_Swap_Memory_Configure | Warning
A6.Check_SysCtl_Parameter | Abnormal
A7.Check_FileSystem_Configure | OK
A8.Check_Disk_Configure | OK
A9.Check_BlockDev_Configure | OK
A9.Check_Logical_Block | OK
A10.Check_IO_Request | Warning
A10.Check_Asynchronous_IO_Request | OK
A10.Check_IO_Configure | OK
A11.Check_Network_Configure | OK
A12.Check_Time_Consistency | OK
A13.Check_Firewall_Service | OK
A14.Check_THP_Service | OK
A15.Check_Dependent_Package | Abnormal
A16.Check_CPU_Instruction_Set | OK
A17.Check_Port | OK
Total count 20, abnormal count 2, warning count 2
Failed to check os, can’t perform installation unless fix all the abnormal items
You can use 'ptk checkos -i ITEM --detail' to get detail message
Please check root_fix_os.[TIMESTAMP].sh for commands to resolve.
3、通过前面生成的脚本 Fix 问题
需要保证yum正常,执行脚本后要重启
[root@mogdb-02 software]# ll
total 16
drwxr-xr-x 3 54332 54331 4096 Jun 16 17:26 compat-tools-master
-rw-r--r-- 1 root root 208 Dec 2 10:58 config.yaml
-rw------- 1 54332 54331 1872 Jun 27 21:47 dbSingle.xml
drwxr-xr-x 2 root root 46 Dec 2 10:35 mogdb
-rwxr--r-- 1 root root 438 Dec 2 10:59 root_fix_os.2022.1202.105943.sh
[root@mogdb-02 software]# sh root_fix_os.2022.1202.105943.sh
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
epel/x86_64/metalink | 7.0 kB 00:00:00
* base: mirrors.aliyun.com
* epel: mirrors.bfsu.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/4): epel/x86_64/group_gz | 98 kB 00:00:00
(2/4): epel/x86_64/updateinfo | 1.0 MB 00:00:00
(3/4): epel/x86_64/primary_db | 7.0 MB 00:00:00
(4/4): updates/7/x86_64/primary_db | 18 MB 00:00:19
Resolving Dependencies
--> Running transaction check
---> Package numactl.x86_64 0:2.0.12-5.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================================================
Installing:
numactl x86_64 2.0.12-5.el7 base 66 k
Transaction Summary
===============================================================================================================================================================
Install 1 Package
Total download size: 66 k
Installed size: 141 k
Downloading packages:
numactl-2.0.12-5.el7.x86_64.rpm | 66 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : numactl-2.0.12-5.el7.x86_64 1/1
Verifying : numactl-2.0.12-5.el7.x86_64 1/1
Installed:
numactl.x86_64 0:2.0.12-5.el7
Complete!
fs.file-max = 6815744
kernel.shmmni = 4096
net.ipv4.conf.all.rp_filter = 2
net.ipv4.conf.default.rp_filter = 2
fs.aio-max-nr = 1048576
net.ipv4.ip_local_port_range = 9000 65500
net.ipv4.tcp_max_tw_buckets = 10000
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_keepalive_time = 30
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_retries2 = 12
net.ipv4.ip_local_reserved_ports = 5432-5439,20050-20057
net.core.wmem_max = 21299200
net.core.rmem_max = 21299200
net.core.wmem_default = 21299200
net.core.rmem_default = 21299200
kernel.sem = 250 6400000 1000 25600
net.ipv4.tcp_rmem = 8192 250000 16777216
net.ipv4.tcp_wmem = 8192 250000 16777216
vm.min_free_kbytes = 400469
net.core.netdev_max_backlog = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.core.somaxconn = 65535
kernel.shmall = 1152921504606846720
kernel.shmmax = 18446744073709551615
kernel.core_pattern = /var/log/coredump/%e.%p.%u.%t.core
执行完之后要重启
4、Install
Fix 之后要重启,使参数生效后再安装
cd /opt/omm/
ptk install -f config.yaml
录入初始用户密码,本例中为 Enmotech@123
[root@mogdb-02 software]# ptk install -f config.yaml --pkg MogDB-3.0.4-CentOS-x86_64.tar.gz
INFO[2022-12-02T11:03:28.593] PTK Version: 0.5.4 release
INFO[2022-12-02T11:03:28.593] load config from config.yaml
If you continue to install the software,
you are accepting the license agreement of the software.
[Y]: Accept and continue
[C]: Show content of licence agreement
[N]: Abort installation and exit
Please enter (Default [Y]): y
Cluster Name: "dbCluster"
+--------------+---------------+-------------+------+---------+------------------+----------+
| az(priority) | ip | user(group) | port | role | data dir | upstream |
+--------------+---------------+-------------+------+---------+------------------+----------+
| AZ1(1) | 192.168.56.61 | omm(omm) | 5432 | primary | /opt/mogdb/db1/db1 | - |
+--------------+---------------+-------------+------+---------+------------------+----------+
Is cluster config correct?[Y/N](default=Y) y
INFO[2022-12-02T11:03:44.835] start check os ...
INFO[2022-12-02T11:03:44.847] prechecking dependent tools...
WARN[2022-12-02T11:03:44.924] [192.168.56.61][omm] device(dm-0) 'IO Request'=128, expect 256
WARN[2022-12-02T11:03:44.924] [192.168.56.61][omm] device(dm-2) 'IO Request'=128, expect 256
WARN[2022-12-02T11:03:44.924] [192.168.56.61][omm] device(dm-6) 'IO Request'=128, expect 256
WARN[2022-12-02T11:03:44.924] [192.168.56.61][omm] device(dm-8) 'IO Request'=128, expect 256
WARN[2022-12-02T11:03:44.924] [192.168.56.61][omm] device(sda) 'IO Request'=32768, expect 256
WARN[2022-12-02T11:03:44.924] [192.168.56.61][omm] device(dm-1) 'IO Request'=128, expect 256
WARN[2022-12-02T11:03:44.924] [192.168.56.61][omm] device(dm-3) 'IO Request'=128, expect 256
WARN[2022-12-02T11:03:44.924] [192.168.56.61][omm] device(dm-4) 'IO Request'=128, expect 256
WARN[2022-12-02T11:03:44.924] [192.168.56.61][omm] device(dm-5) 'IO Request'=128, expect 256
WARN[2022-12-02T11:03:44.924] [192.168.56.61][omm] device(dm-7) 'IO Request'=128, expect 256
WARN[2022-12-02T11:03:44.924] [192.168.56.61][omm] device(sr0) 'IO Request'=32768, expect 256
INFO[2022-12-02T11:03:44.962] [192.168.56.61][omm] timezone: +0800
INFO[2022-12-02T11:03:44.976] [192.168.56.61][omm] swap memory 10485756kB, total memory 8008932kB
INFO[2022-12-02T11:03:45.087] [192.168.56.61][omm] platform: centos_7_64bit
INFO[2022-12-02T11:03:45.091] [192.168.56.61][omm] kernel version: 3.10.0-957.el7.x86_64
INFO[2022-12-02T11:03:45.142] [192.168.56.61][omm] locale: LANG=en_US.UTF-8
WARN[2022-12-02T11:03:45.167] [192.168.56.61][omm] net.ipv4.tcp_syn_retries=6, expect 5
WARN[2022-12-02T11:03:45.200] [192.168.56.61][omm] net.ipv4.tcp_retries1=3, expect 5
INFO[2022-12-02T11:03:45.350] [192.168.56.61][omm] check kernel.core_pattern
INFO[2022-12-02T11:03:45.372] [192.168.56.61][omm] check removeIPC value
INFO[2022-12-02T11:04:06.478] [192.168.56.61][omm] check port 5432
INFO[2022-12-02T11:04:07.435] [192.168.56.61][omm] port 5432 is free
INFO[2022-12-02T11:04:07.435] all checkers finished
INFO[2022-12-02T11:04:07.435] Time elapsed: 22s
INFO[2022-12-02T11:04:07.436] check os success
INFO[2022-12-02T11:04:07.436] start check distro ...
INFO[2022-12-02T11:04:07.436] check distro success
INFO[2022-12-02T11:04:07.436] start check user ...
INFO[2022-12-02T11:04:07.450] check user success
INFO[2022-12-02T11:04:07.450] start check port ...
INFO[2022-12-02T11:04:09.331] check port success
INFO[2022-12-02T11:04:09.331] start prepare installation package ...
INFO[2022-12-02T11:04:09.331] installation package is ready
INFO[2022-12-02T11:04:09.331] start validate installation package ...
INFO[2022-12-02T11:04:14.074] parsed kernel package name: MogDB-3.0.4-CentOS-64bit.tar.gz
INFO[2022-12-02T11:04:14.131] db product: MogDB, version: 3.1.0, number: 92.781, commit_id: 2aa5b715
INFO[2022-12-02T11:04:14.131] validate installation package success
INFO[2022-12-02T11:04:14.131] start complete the configuration ...
Please enter db password (8~16 characters): Enmotech@123
Retype db password: Enmotech@123
INFO[2022-12-02T11:12:06.633] complete the configuration success
INFO[2022-12-02T11:12:06.633] start distribute installation package ...
INFO[2022-12-02T11:12:06.805] distrubite packages success
INFO[2022-12-02T11:12:06.805] start setup db ...
WARN[2022-12-02T11:12:06.817] [192.168.56.61][omm] not found recommended config for version 3.1.0, fallback to use 3.0.3 recommended config
INFO[2022-12-02T11:12:06.818] [192.168.56.61][omm] create os user omm, group omm
INFO[2022-12-02T11:12:06.881] [192.168.56.61][omm] set ulimit configs
INFO[2022-12-02T11:12:06.886] [192.168.56.61][omm] set user omm profiles
INFO[2022-12-02T11:12:07.009] [192.168.56.61][omm] check or set C library
INFO[2022-12-02T11:12:07.024] [192.168.56.61][omm] make dir(s): /opt/mogdb/tool,/opt/mogdb/tool/ptk_tool/bin
INFO[2022-12-02T11:12:07.968] [192.168.56.61][omm] decompress MogDB-3.0.4-CentOS-x86_64.tar.gz to dir /opt/mogdb/tool
INFO[2022-12-02T11:12:10.440] [192.168.56.61][omm] decompress *-om.tar.gz to dir /opt/mogdb/tool
INFO[2022-12-02T11:12:11.728] [192.168.56.61][omm] try to fix psutil python lib
INFO[2022-12-02T11:12:11.789] [192.168.56.61][omm] write file /opt/mogdb/tool/ptk_tool/bin/README.md
INFO[2022-12-02T11:12:11.852] [192.168.56.61][omm] write file /opt/mogdb/tool/ptk_tool/bin/pscp
INFO[2022-12-02T11:12:11.920] [192.168.56.61][omm] write file /opt/mogdb/tool/ptk_tool/bin/pssh
INFO[2022-12-02T11:12:11.964] [192.168.56.61][omm] write file /opt/mogdb/tool/ptk_tool/bin/task_pool.py
INFO[2022-12-02T11:12:11.987] [192.168.56.61][omm] change /opt/mogdb/tool owner to omm
INFO[2022-12-02T11:12:11.997] [192.168.56.61][omm] make dir(s): /opt/mogdb/app
INFO[2022-12-02T11:12:12.229] [192.168.56.61][omm] decompress MogDB-3.0.4-CentOS-64bit.tar.gz to dir /opt/mogdb/app
INFO[2022-12-02T11:12:17.506] [192.168.56.61][omm] fix dynamic linker for gs_initdb
INFO[2022-12-02T11:12:17.590] [192.168.56.61][omm] fix dynamic linker for mogdb
INFO[2022-12-02T11:12:17.685] [192.168.56.61][omm] change /opt/mogdb/app owner to omm
INFO[2022-12-02T11:12:17.706] [192.168.56.61][omm] make dir(s): /opt/mogdb/db1/log/gs_profile,/opt/mogdb/db1/log/pg_log,/opt/mogdb/db1/log/pg_audit,/opt/mogdb/db1/log/bin,/opt/mogdb/db1/log/pg_log/dn_6001,/opt/mogdb/db1/log/pg_audit/dn_6001
INFO[2022-12-02T11:12:18.751] [192.168.56.61][omm] make dir(s): /opt/mogdb/tmp
INFO[2022-12-02T11:12:18.840] [192.168.56.61][omm] save version to upgrade_version
INFO[2022-12-02T11:12:18.890] [192.168.56.61][omm] create file cluster_manual_start
INFO[2022-12-02T11:12:18.931] [192.168.56.61][omm] generate cluster_static_config file
INFO[2022-12-02T11:12:18.938] [192.168.56.61][omm] change /opt/mogdb/app/bin/cluster_static_config owner to omm
INFO[2022-12-02T11:12:18.942] [192.168.56.61][omm] make dir(s): /opt/mogdb/db1/db1
INFO[2022-12-02T11:12:19.031] [192.168.56.61][omm] change /opt/mogdb/db1/db1 owner to omm
INFO[2022-12-02T11:12:19.034] [192.168.56.61][omm] the database is initializing, please wait a few minutes
INFO[2022-12-02T11:12:36.690] [192.168.56.61][omm] config postgresql.conf
INFO[2022-12-02T11:12:36.791] [192.168.56.61][omm] config pg_hba.conf
INFO[2022-12-02T11:12:36.843] setup db success
INFO[2022-12-02T11:12:36.843] generate certification files
INFO[2022-12-02T11:12:37.177] download certification files
INFO[2022-12-02T11:12:37.267] certification files setup success
INFO[2022-12-02T11:12:37.267] start build ssh trust ...
INFO[2022-12-02T11:12:37.364] ssh trust build success
INFO[2022-12-02T11:12:37.364] start launch db ...
INFO[2022-12-02T11:12:37.364] [192.168.56.61][omm] start db by gs_ctl ...
INFO[2022-12-02T11:12:37.364] [192.168.56.61][omm] the database is starting, please wait a few minutes
INFO[2022-12-02T11:12:38.450] [192.168.56.61][omm] start db success
INFO[2022-12-02T11:12:38.450] [192.168.56.61][omm] start alter db initial password ...
INFO[2022-12-02T11:12:38.576] [192.168.56.61][omm] alter db password success
INFO[2022-12-02T11:12:38.576] launch db success
INFO[2022-12-02T11:12:38.576] clear temp dirs ...
INFO[2022-12-02T11:12:38.596] clear temp dirs success
INFO[2022-12-02T11:12:38.596] Time elapsed: 9m4s
cluste_name | host | user | port | status | message
--------------+---------------+------+------+---------------+----------
dbCluster | 192.168.56.61 | omm | 5432 | start_success | success
Successfully set finish flag.
Preinstallation succeeded.
5、gen-om-xml
可以通过gen-om-xml命令生成 gs_om 的 XML 配置文件
ptk gen-om-xml -f config.yaml
/opt/omm/config_20221202111918.xml
[root@mogdb-02 software]# cat config_20221202111918.xml
<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
<CLUSTER>
<PARAM name="clusterName" value="dbCluster"></PARAM>
<PARAM name="nodeNames" value="mogdb-02"></PARAM>
<PARAM name="gaussdbLogPath" value="/opt/mogdb/db1/log"></PARAM>
<PARAM name="gaussdbAppPath" value="/opt/mogdb/app"></PARAM>
<PARAM name="gaussdbToolPath" value="/opt/mogdb/tool"></PARAM>
<PARAM name="backIP1s" value="192.168.56.61"></PARAM>
<PARAM name="clusterType" value="single-inst"></PARAM>
</CLUSTER>
<DEVICELIST>
<DEVICE sn="mogdb-02">
<PARAM name="name" value="mogdb-02"></PARAM>
<PARAM name="azName" value="AZ1"></PARAM>
<PARAM name="azPriority" value="1"></PARAM>
<PARAM name="backIp1" value="192.168.56.61"></PARAM>
<PARAM name="sshIp1" value="192.168.56.61"></PARAM>
<PARAM name="dataNum" value="1"></PARAM>
<PARAM name="dataPortBase" value="5432"></PARAM>
<PARAM name="dataNode1" value="/opt/mogdb/db1/db1"></PARAM>
</DEVICE>
</DEVICELIST>
</ROOT>
6、根据需要设置IP白名单
gs_guc set -I all -N all -h “host all all 0.0.0.0/0 md5”
四、安装扩展
1、安装所有扩展
ptk cluster -n dbCluster install-plugin --pkg
2、安装指定扩展
ptk cluster -n dbCluster install-plugin -p whale-5.0.0-01-CentOS-x86_64.tar.gz
五、compat-tools
compat-tools是一个兼容工具集合,旨在为从其他异构数据库,迁移到 openGauss 之后的系统,创建必要的函数,以及系统视图的兼容。为后续的系统运维与应用改造提供便利。
脚本中带有版本控制,直接运行脚本时,会根据如下三种情况进行处理:
若待创建对象在目标数据库中不存在,则直接进行创建
若待创建对象版本高于目标数据库中的对象版本,则进行升级重建
若待创建对象版本不高于目标数据库中的对象版本,则跳过创建
注意
1、 如果要安装扩展 whale,需要在compat-tools之前安装
2、 安装compat-tools,需要确认参数 behavior_compat_options=‘display_leading_zero’,如果参数不对,设置后重启再验正
cmsdb=# show behavior_compat_options;
behavior_compat_options
-------------------------
display_leading_zero
(1 row)
3、 为避免超时,建议延长超时设置
更改文件 Oracle_Packages.sql ,设置如下参数
set statement_timeout = 6000000;
4、 安装完后要验正 dbms_lob功能是否正常安装
select dbms_lob.substr('abc',1,2);
1、下载
git clone https://gitee.com/enmotech/compat-tools.git
2、安装
注意:安装tools之前,需要先创建whale,假设目标DB为omm
gsql -d omm -r
omm=# create extension whale;
CREATE EXTENSION
开始安装tools
[omm@mogdb-02 compat-tools]$ gsql -d omm -f runMe.sql
3、卸载
[omm@mogdb-02 compat-tools]$ gsql -d omm -f uninstall.sql
六、卸载MogDB
1、查看当前已经安装的MogDB
[root@mogdb-02 ~]# ptk ls
cluster_name | id | addr | user | data_dir | db_version | create_time | comment
---------------+------+--------------------+------+-----------------+--------------------------------+---------------------+----------
dbCluster | 6001 | 192.168.56.62:5432 | omm | /opt/mogdb/db1/db1 | MogDB 3.0.3.6 (build fffcf561) | 2023-03-01 10:27:46 |
2、停止DB
根据前面查看到的信息,操作对应的cluster
[root@mogdb-02 ~]# ptk cluster stop -n dbCluster
==================== stop cluster: "dbCluster" ====================
INFO[2023-05-08T11:29:27.982] operation: stop
INFO[2023-05-08T11:29:27.982] ========================================
INFO[2023-05-08T11:29:27.982] stop db [192.168.56.62:5432] ...
INFO[2023-05-08T11:29:29.035] stop db [192.168.56.62:5432] successfully
INFO[2023-05-08T11:29:29.035] ========================================
INFO[2023-05-08T11:29:29.035] stop successfully
3、uninstall
根据前面查看到的信息,操作对应的cluster
ptk uninstall -n dbCluster
4、手动清理残留信息
手动删除残留的安装目录
rm /opt/mogdb/* -rf
rm /opt/mogdb/db1/* -rf
rm /var/spool/mail/omm -rf
八、集群安装
1、添加vip
ifconfig enp0s8:5432 192.168.56.69 netmask 255.255.255.0 up
生成加密密码
[root@ha-01 mogdb]# ptk encrypt Enmotech@123
Enmotech@123: pTk6MmYyYmNlOTc8Qz5DPUM8PHlTWDFCUkZGYnljRVU5MWJ1NzdWcktaRU80XzZfMERFMDNPZnVIaV9TVzQ=
2、创建配置文件
2.1 一主一备
# 集群级别的配置信息,其中 `db_port` 和 `ssh_option` 字段是 **可重用字段**
global:
cluster_name: dbCluster # 集群名称,PTK管理的集群的唯一标识
user: omm # 运行数据库的操作系统用户名
group: dbgrp # 运行数据库的操作系统用户组
db_port: 5432 # 数据库端口
ha_port: 5433 # 数据库实例角色,若不填,PTK 会随机选择一个实例作为主库,其余自动为备库
enable_cm: yes
db_password: "pTk6ZTQ5NTlhOTA8Qz5DPUQ/QmFWbUlNNGRwLU5jQlBkUEtLY2pfY0wtcUN4Tm5aajBFcFJHQWpJQWViOVk="
base_dir: /opt/mogdb # 数据库安装的基础目录,一般建议指定到配置文件中 ssh 用户可访问的目录下的路径,让PTK自动创建。
# # gs_initdb 工具支持参数列表,安装时会追加到指令中
gs_initdb_opts:
- "--encoding=UTF-8"
- "--dbcompatibility=A"
# MogDB 高可用组件 CM 配置信息,若不使用 CM 组件,则无需填写该字段
# MogDB 高可用组件 CM 配置信息,若不使用 CM 组件,则无需填写该字段
cm_option:
dir: /opt/mogdb/cm # CM 安装目录
cm_server_port: 15300 # cm server 监听端口
db_service_vip: "192.168.56.69" # 数据库提供服务的虚拟IP
# SSH 登录信息,登录用户需为 **root** 或者具有 sudo 权限的用户
# SSHOption SSH 登录认证信息,支持密码和密钥两种方式,二者需至少设置一种
ssh_option:
port: 22 # SSH 服务端口
user: root # SSH 登录用户
password: "pTk6NjI1MjNlZmY8Qz5DPUQ/Q1EtSkcxQVpFOWFxUnlzX3lnZFNRa0paS0lJQnByY2VDY1pNTG4tdGVFRXc=" # SSH 登录用户密码
conn_timeout: 5m0s # SSH 登录连接超时时间,支持单位 m(分),s(秒)
exec_timeout: 5m0s # SSH 执行单条命令时的超时时间,支持单位 m(分),s(秒)
# 集群内的数据库实例服务器配置信息
db_servers:
- host: 192.168.56.66 # 数据库实例服务器 IP (仅支持 IPv4)
# 数据库主备间日志复制IP,默认和数据库监听地址相同
ha_ips:
- 192.168.10.66
role: primary # 数据库实例角色,若不填,PTK 会随机选择一个实例作为主库,其余自动为备库
az_name: AZ1 # Available Zone (可用区) 名称
az_priority: 1 # 可用区使用的优先级,数值越小优先级越高
- host: 192.168.56.67 # 数据库实例服务器 IP (仅支持 IPv4)
# 数据库主备间日志复制IP,默认和数据库监听地址相同
ha_ips:
- 192.168.10.67
role: standby # 数据库实例角色,若不填,PTK 会随机选择一个实例作为主库,其余自动为备库
az_name: AZ1 # Available Zone (可用区) 名称
az_priority: 1 # 可用区使用的优先级,数值越小优先级越高
# 集群内的CM服务部署机器列表
cm_servers:
- host: 192.168.56.66 # CM Server 服务器 IP (仅支持 IPv4)
port: 0 # CM Server 监听端口
role: ""
- host: 192.168.56.67 # CM Server 服务器 IP (仅支持 IPv4)
port: 25300 # CM Server 监听端口
role: ""
2.2 一主一备一级联
[root@mogdb-02 software]# cat config_cm.yaml
# 集群级别的配置信息,其中 `db_port` 和 `ssh_option` 字段是 **可重用字段**
global:
cluster_name: dbCluster # 集群名称,PTK管理的集群的唯一标识
user: omm # 运行数据库的操作系统用户名
group: dbgrp # 运行数据库的操作系统用户组
db_port: 5432 # 数据库端口
ha_port: 5433 # 数据库实例角色,若不填,PTK 会随机选择一个实例作为主库,其余自动为备库
enable_cm: yes
db_password: "pTk6ZTQ5NTlhOTA8Qz5DPUQ/QmFWbUlNNGRwLU5jQlBkUEtLY2pfY0wtcUN4Tm5aajBFcFJHQWpJQWViOVk="
base_dir: /opt/mogdb # 数据库安装的基础目录,一般建议指定到配置文件中 ssh 用户可访问的目录下的路径,让PTK自动创建。
# # gs_initdb 工具支持参数列表,安装时会追加到指令中
gs_initdb_opts:
- "--encoding=UTF-8"
- "--dbcompatibility=A"
# MogDB 高可用组件 CM 配置信息,若不使用 CM 组件,则无需填写该字段
# MogDB 高可用组件 CM 配置信息,若不使用 CM 组件,则无需填写该字段
cm_option:
dir: /opt/mogdb/cm # CM 安装目录
cm_server_port: 15300 # cm server 监听端口
db_service_vip: "192.168.56.69" # 数据库提供服务的虚拟IP
# SSH 登录信息,登录用户需为 **root** 或者具有 sudo 权限的用户
# SSHOption SSH 登录认证信息,支持密码和密钥两种方式,二者需至少设置一种
ssh_option:
port: 22 # SSH 服务端口
user: root # SSH 登录用户
password: "pTk6NjI1MjNlZmY8Qz5DPUQ/Q1EtSkcxQVpFOWFxUnlzX3lnZFNRa0paS0lJQnByY2VDY1pNTG4tdGVFRXc=" # SSH 登录用户密码
conn_timeout: 5m0s # SSH 登录连接超时时间,支持单位 m(分),s(秒)
exec_timeout: 5m0s # SSH 执行单条命令时的超时时间,支持单位 m(分),s(秒)
# 集群内的数据库实例服务器配置信息
db_servers:
- host: 192.168.56.66 # 数据库实例服务器 IP (仅支持 IPv4)
# 数据库主备间日志复制IP,默认和数据库监听地址相同
ha_ips:
- 192.168.10.66
role: primary # 数据库实例角色,若不填,PTK 会随机选择一个实例作为主库,其余自动为备库
az_name: AZ1 # Available Zone (可用区) 名称
az_priority: 1 # 可用区使用的优先级,数值越小优先级越高
- host: 192.168.56.67 # 数据库实例服务器 IP (仅支持 IPv4)
# 数据库主备间日志复制IP,默认和数据库监听地址相同
ha_ips:
- 192.168.10.67
role: standby # 数据库实例角色,若不填,PTK 会随机选择一个实例作为主库,其余自动为备库
az_name: AZ1 # Available Zone (可用区) 名称
az_priority: 1 # 可用区使用的优先级,数值越小优先级越高
- host: 192.168.56.68 # 数据库实例服务器 IP (仅支持 IPv4)
# 数据库主备间日志复制IP,默认和数据库监听地址相同
ha_ips:
- 192.168.10.68
role: cascade_standby # 数据库实例角色,若不填,PTK 会随机选择一个实例作为主库,其余自动为备库
upstream_host: 192.168.56.67 # 当实例角色为 cascade_standby 时,该字段表示要跟随的上游备库 IP
az_name: AZ1 # Available Zone (可用区) 名称
az_priority: 1 # 可用区使用的优先级,数值越小优先级越高
# 集群内的CM服务部署机器列表
cm_servers:
- host: 192.168.56.66 # CM Server 服务器 IP (仅支持 IPv4)
port: 0 # CM Server 监听端口
role: ""
- host: 192.168.56.67 # CM Server 服务器 IP (仅支持 IPv4)
port: 25300 # CM Server 监听端口
role: ""
3、checkos
[root@mogdb-02 software]# ptk checkos -f config_cm.yaml --gen-warning-fix
4、通过前面生成的脚本 Fix 问题
需要保证yum正常,执行脚本后要重启
[root@mogdb-02 software]# ll
-rwxr--r-- 1 root root 438 Dec 2 10:59 root_fix_os.2022.1202.105943.sh
[root@mogdb-02 software]# sh root_fix_os.2022.1202.105943.sh
执行完之后要重启
5、Install
Fix 之后要重启,使参数生效后再安装
cd /opt/omm/
ptk install -f config_cm.yaml
录入初始用户密码,本例中为 Enmotech@123
[root@mogdb-02 software]# ptk install -f config_cm.yaml --pkg MogDB-5.0.1-CentOS-x86_64-all.tar.gz
6、配制vip
增加vip启停权限
把命令加入sudoers,各节点都要加
echo "Cmnd_Alias COMMAND_FLAG = /usr/sbin/ifconfig * netmask * up, /usr/sbin/ifconfig * down" >> /etc/sudoers
echo "omm ALL=(root) NOPASSWD:COMMAND_FLAG" >> /etc/sudoers
omm下测试权限
[omm@ha-01 ~]$ sudo /usr/sbin/ifconfig enp0s8:5432 192.168.56.69 netmask 255.255.255.0 up
[omm@ha-01 ~]$ ifconfig
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.56.66 netmask 255.255.255.0 broadcast 192.168.56.255
inet6 fe80::a00:27ff:fe77:bb6b prefixlen 64 scopeid 0x20<link>
ether 08:00:27:77:bb:6b txqueuelen 1000 (Ethernet)
RX packets 242 bytes 20806 (20.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 163 bytes 25373 (24.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp0s8:5432: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.56.69 netmask 255.255.255.0 broadcast 192.168.56.255
ether 08:00:27:77:bb:6b txqueuelen 1000 (Ethernet)
设置vip资源文件
增加vip资源
cm_ctl res --add --res_name="VIP_az" --res_attr="resources_type=VIP, float_ip=192.168.56.69"
增加vip资源与各节点映射
cm_ctl res --edit --res_name="VIP_az" --add_inst="node_id=1, res_instance_id=6001" --inst_attr="base_ip=192.168.56.66"
cm_ctl res --edit --res_name="VIP_az" --add_inst="node_id=2, res_instance_id=6002" --inst_attr="base_ip=192.168.56.67"
复制资源配制到各节点
建议使用cm_ctl res --check命令进行检查。自定义资源文件要求每个节点都要有且一致,检查完成没有错误后,需要手动将该文件分发到其他节点,分发完成后需要重启集群才能生效。
将在cm_agent目录下生成cm_resource.json文件
[omm@ha-01 ~]$ cat /opt/mogdb/cm/cm_agent/cm_resource.json
{
"resources": [{
"name": "VIP_az",
"resources_type": "VIP",
"instances": [{
"node_id": 1,
"res_instance_id": 6001,
"inst_attr": "base_ip=192.168.56.66"
}, {
"node_id": 2,
"res_instance_id": 6002,
"inst_attr": "base_ip=192.168.56.67"
}],
"float_ip": "192.168.56.69"
}]
scp /opt/mogdb/cm/cm_agent/cm_resource.json omm@192.168.56.67:/opt/mogdb/cm/cm_agent
8、根据需要设置IP白名单
gs_guc set -I all -N all -h “host all all 0.0.0.0/0 md5”
九、集群管理
1、查看集群VIP
[omm@ha-01 ~]$ cm_ctl show
[ Network Connect State ]
Network timeout: 6s
Current CMServer time: 2023-10-07 11:16:10
Network stat('Y' means connected, otherwise 'N'):
| \ | Y | Y |
| Y | \ | Y |
| Y | Y | \ |
[ Node Disk HB State ]
Node disk hb timeout: 200s
Current CMServer time: 2023-10-07 11:16:11
Node disk hb stat('Y' means connected, otherwise 'N'):
| N | N | N |
[ FloatIp Network State ]
node instance base_ip float_ip_name float_ip
------------------------------------------------------------
1 ha-01 6001 192.168.56.66 VIP_az 192.168.56.69
2、启动集群
[omm@ha-01 ~]$ cm_ctl start
cm_ctl: checking cluster status.
cm_ctl: checking cluster status.
cm_ctl: checking finished in 638 ms.
cm_ctl: start cluster.
cm_ctl: start nodeid: 1
cm_ctl: start nodeid: 2
cm_ctl: start nodeid: 3
.
cm_ctl: start cluster successfully.
3、切换到备机
[omm@ha-01 ~]$ cm_ctl switchover -A
cm_ctl: cmserver is switching over all the master and standby pairs.
...
cm_ctl: switchover -A successfully.
查看状态
[ CMServer State ]
node node_ip instance state
-------------------------------------------------------------
1 ha-01 192.168.56.66 1 /opt/mogdb/cm/cm_server Primary
2 ha-02 192.168.56.67 2 /opt/mogdb/cm/cm_server Standby
[ Cluster State ]
cluster_state : Normal
redistributing : No
balanced : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state
---------------------------------------------------------------
1 ha-01 192.168.56.66 6001 /opt/mogdb/db1 P Standby Normal
2 ha-02 192.168.56.67 6002 /opt/mogdb/db1 S Primary Normal
3 ha-03 192.168.56.68 6003 /opt/mogdb/db1 C Cascade Standby Normal
4、切换到原始状态
[omm@ha-01 ~]$ cm_ctl switchover -a
cm_ctl: cmserver is rebalancing the cluster automatically.
...
cm_ctl: switchover successfully.
查看状态
[omm@ha-01 ~]$ gs_om -t status --detail
[ CMServer State ]
node node_ip instance state
-------------------------------------------------------------
1 ha-01 192.168.56.66 1 /opt/mogdb/cm/cm_server Primary
2 ha-02 192.168.56.67 2 /opt/mogdb/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 ha-01 192.168.56.66 6001 /opt/mogdb/db1 P Primary Normal
2 ha-02 192.168.56.67 6002 /opt/mogdb/db1 S Standby Normal
3 ha-03 192.168.56.68 6003 /opt/mogdb/db1 C Cascade Standby Normal
5、 build备库
删除备库文件
[omm@ha-02 data]$ rm $PGDATA/global -rf
[omm@ha-02 data]$ ll global
ls: cannot access global: No such file or directory
查看备库状态
[omm@ha-01 ~]$ gs_om -t status --detail
[ CMServer State ]
node node_ip instance state
-------------------------------------------------------------
1 ha-01 192.168.56.66 1 /opt/mogdb/cm/cm_server Primary
2 ha-02 192.168.56.67 2 /opt/mogdb/cm/cm_server Standby
[ Cluster State ]
cluster_state : Unavailable
redistributing : No
balanced : Yes
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state
---------------------------------------------------------------
1 ha-01 192.168.56.66 6001 /opt/mogdb/db1 P Primary Normal
2 ha-02 192.168.56.67 6002 /opt/mogdb/db1 S Down Unknown
3 ha-03 192.168.56.68 6003 /opt/mogdb/db1 C Cascade Standby Need repair(Connecting)
[omm@ha-01 ~]$
build
[omm@ha-01 ~]$ cm_ctl build -n 2 -D $PGDATA -f
.......................
cm_ctl: build successfully.
查看节点状态
[omm@ha-01 ~]$ gs_om -t status --detail
[ CMServer State ]
node node_ip instance state
-------------------------------------------------------------
1 ha-01 192.168.56.66 1 /opt/mogdb/cm/cm_server Primary
2 ha-02 192.168.56.67 2 /opt/mogdb/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 ha-01 192.168.56.66 6001 /opt/mogdb/db1 P Primary Normal
2 ha-02 192.168.56.67 6002 /opt/mogdb/db1 S Standby Normal
3 ha-03 192.168.56.68 6003 /opt/mogdb/db1 C Cascade Standby Normal
查看文件
[omm@ha-02 data]$ ll $PGDATA/global | wc
102 911 5443
6、 build主库
[omm@ha-01 data]$ ll global | wc
102 911 5443
[omm@ha-01 data]$ rm $PGDATA/global -rf
查看集群状态(要等待自动切换)
[omm@ha-01 ~]$ gs_om -t status --detail
[ CMServer State ]
node node_ip instance state
-------------------------------------------------------------
1 ha-01 192.168.56.66 1 /opt/mogdb/cm/cm_server Primary
2 ha-02 192.168.56.67 2 /opt/mogdb/cm/cm_server Standby
[ Cluster State ]
cluster_state : Unavailable
redistributing : No
balanced : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state
---------------------------------------------------------------
1 ha-01 192.168.56.66 6001 /opt/mogdb/db1 P Down Unknown
2 ha-02 192.168.56.67 6002 /opt/mogdb/db1 S Primary Normal
3 ha-03 192.168.56.68 6003 /opt/mogdb/db1 C Cascade Standby Need repair(Connecting)
重建节点,与上节命令一样
[omm@ha-01 ~]$ cm_ctl build -n 1 -D $PGDATA -f -b full
.......................
cm_ctl: build successfully.
查看状态
[omm@ha-01 ~]$ gs_om -t status --detail
[ CMServer State ]
node node_ip instance state
-------------------------------------------------------------
1 ha-01 192.168.56.66 1 /opt/mogdb/cm/cm_server Primary
2 ha-02 192.168.56.67 2 /opt/mogdb/cm/cm_server Standby
[ Cluster State ]
cluster_state : Normal
redistributing : No
balanced : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state
---------------------------------------------------------------
1 ha-01 192.168.56.66 6001 /opt/mogdb/db1 P Standby Normal
2 ha-02 192.168.56.67 6002 /opt/mogdb/db1 S Primary Normal
3 ha-03 192.168.56.68 6003 /opt/mogdb/db1 C Cascade Standby Normal
7、 查看集群状态
cm_ctl query -Cvi
[omm@node109 dn1]$ cm_ctl query -Cvi
[ CMServer State ]
node node_ip instance state
-------------------------------------------
1 node109 172.16.108.109 1 Standby
2 node110 172.16.108.110 2 Primary
[ Defined Resource State ]
node node_ip res_name instance state
-----------------------------------------------------
1 node109 172.16.108.109 dms_res 6001 OnLine
2 node110 172.16.108.110 dms_res 6002 OnLine
1 node109 172.16.108.109 dss 20001 OnLine
2 node110 172.16.108.110 dss 20002 OnLine
[ Cluster State ]
cluster_state : Normal
redistributing : No
balanced : Yes
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state | node node_ip instance state
--------------------------------------------------------------------------------------------------------------
1 node109 172.16.108.109 6001 P Primary Normal | 2 node110 172.16.108.110 6002 S Standby Normal
8、 关闭集群
[omm@ha-01 ~]$ cm_ctl stop
cm_ctl: stop cluster.
cm_ctl: stop nodeid: 1
cm_ctl: stop nodeid: 2
cm_ctl: stop nodeid: 3
..........
cm_ctl: stop cluster successfully.
十、集群升级
注意升级前尽量备份
tar -cvf mogdb_bak_202402221723.tar db1 log mogdb tmp tool
升级
/opt/omm 为插件包所在目录,需要升级的插件都放在该目录下,PTK会自动查找
ptk cluster -n dbCluster upgrade -p MogDB-5.0.5-CentOS-x86_64-all.tar.gz --plugin-dir /opt/omm
出错后回滚
ptk cluster -n dbCluster upgrade-rollback
十一、 集群缩容
参考: https://docs.mogdb.io/zh/ptk/v1.0/usage-scale
[root@ha-01 ~]# ptk cluster -n dbCluster scale-in -H 192.168.56.68
INFO[2023-10-31T14:50:27.556] PTK Version: 1.0.10 release
The cluster will contains 2 cm nodes, so please confirm following cms configs:
- (Optional) db_service_vip=""
- (Required) third_party_gateway_ip=""
- (Optional) cms_enable_failover_on2nodes="True"
- (Optional) cms_enable_db_crash_recovery="False"
✔ The 'third_party_gateway_ip' is not configed, please enter: 192.168.56.67
Now, these configs are:
- db_service_vip=""
- third_party_gateway_ip="192.168.56.67"
- cms_enable_failover_on2nodes="True"
- cms_enable_db_crash_recovery="False"
✔ Do you want to modify them (default=n) [y/n]: n
INFO[2023-10-31T14:50:42.059] start scale-in ...
INFO[2023-10-31T14:50:43.564] start precheck ...
INFO[2023-10-31T14:50:43.856] precheck success
Cluster Name: "dbCluster"
+--------------+---------------+-------------+----------+--------------------+--------------------+---------------+
| az(priority) | ip | user(group) | port | role | data dir | upstream |
+--------------+---------------+-------------+----------+--------------------+--------------------+---------------+
| AZ1(1) | 192.168.56.66 | omm(dbgrp) | db:5432 | db:standby | db:/opt/mogdb/db1 | - |
| | | | cm:15300 | | cm:/opt/mogdb/cm | |
| | 192.168.56.67 | omm(dbgrp) | db:5432 | db:primary | db:/opt/mogdb/db1 | - |
| | | | cm:25300 | | cm:/opt/mogdb/cm | |
| | 1̶9̶2̶.̶1̶6̶8̶.̶5̶6̶.̶6̶8̶ | o̶m̶m̶(̶d̶b̶g̶r̶p̶)̶ | d̶b̶:̶5̶4̶3̶2̶ | d̶b̶:̶c̶a̶s̶c̶a̶d̶e̶_̶s̶t̶a̶n̶d̶b̶y̶ | d̶b̶:̶/̶o̶p̶t̶/̶m̶o̶g̶d̶b̶/̶d̶a̶t̶a̶ | 1̶9̶2̶.̶1̶6̶8̶.̶5̶6̶.̶6̶7̶ |
+--------------+---------------+-------------+----------+--------------------+--------------------+---------------+
✔ Please confirm cluster after scale-in (default=n) [y/n]: y
INFO[2023-10-31T14:50:48.399] start drop nodes ...
INFO[2023-10-31T14:50:48.399] [192.168.56.68][omm] remove cron task: om_monitor
INFO[2023-10-31T14:50:48.561] [192.168.56.68][omm] stop user "omm" db process
INFO[2023-10-31T14:50:50.844] [192.168.56.68][omm] remove files: /opt/mogdb/app,/opt/mogdb/tool,/opt/mogdb/db1,/opt/mogdb/log,/opt/mogdb/tmp
INFO[2023-10-31T14:50:51.182] [192.168.56.68][omm] remove user "omm" from cron.allow
INFO[2023-10-31T14:50:51.254] [192.168.56.68][omm] remove user "omm" ulimits
INFO[2023-10-31T14:50:51.331] [192.168.56.68][omm] remove base dir if empty: /opt/mogdb
INFO[2023-10-31T14:50:51.398] [192.168.56.68][omm] kill user "omm" process
INFO[2023-10-31T14:50:51.495] [192.168.56.68][omm] delete user "omm"
INFO[2023-10-31T14:50:51.654] drop nodes success
INFO[2023-10-31T14:50:51.654] start update remaining cluster config ...
INFO[2023-10-31T14:50:51.654] db instance count reduce from 3 to 2
INFO[2023-10-31T14:50:51.654] [192.168.56.66][omm] update config ...
INFO[2023-10-31T14:50:51.654] [192.168.56.66][omm] config postgresql.conf
INFO[2023-10-31T14:50:51.654] [192.168.56.67][omm] update config ...
INFO[2023-10-31T14:50:51.654] [192.168.56.67][omm] config postgresql.conf
INFO[2023-10-31T14:50:51.654] [192.168.56.66][omm] update cm config file: /opt/mogdb/cm/cm_server/cm_server.conf
INFO[2023-10-31T14:50:51.655] [192.168.56.67][omm] update cm config file: /opt/mogdb/cm/cm_server/cm_server.conf
INFO[2023-10-31T14:50:51.859] [192.168.56.66][omm] clear hba
INFO[2023-10-31T14:50:51.864] [192.168.56.67][omm] clear hba
INFO[2023-10-31T14:50:51.983] [192.168.56.66][omm] generate cluster_static_config file
INFO[2023-10-31T14:50:51.995] [192.168.56.67][omm] generate cluster_static_config file
INFO[2023-10-31T14:50:52.137] [192.168.56.66][omm] change /opt/mogdb/app/bin/cluster_static_config owner to omm
INFO[2023-10-31T14:50:52.137] [192.168.56.67][omm] change /opt/mogdb/app/bin/cluster_static_config owner to omm
INFO[2023-10-31T14:50:52.285] [192.168.56.66][omm] reload db ...
INFO[2023-10-31T14:50:52.290] [192.168.56.67][omm] reload db ...
INFO[2023-10-31T14:50:52.393] update cluster config success
INFO[2023-10-31T14:50:52.393] restart cm cluster ...
INFO[2023-10-31T14:50:53.558] restart cm cluster success
INFO[2023-10-31T14:50:53.558] reload cm cluster ...
WARN[2023-10-31T14:50:53.653] cm_ctl reload failed: Process exited with status 255: cm_ctl: send reload msg to cm_server, connect fail.
INFO[2023-10-31T14:50:53.655] scale-in success
INFO[2023-10-31T14:50:53.655] time elapsed: 12s
[root@ha-01 ~]# ptk cluster -n dbCluster status
[ Cluster State ]
cluster_name : dbCluster
cluster_state : Normal
database_version : openGauss 5.1.0 (build b5a8d5b0)
[ CMServer State ]
id | ip | port | hostname | role
-----+---------------+-------+----------+----------
1 | 192.168.56.66 | 15300 | ha-01 | primary
2 | 192.168.56.67 | 25300 | ha-02 | standby
[ Datanode State ]
cluster_name | id | ip | port | user | nodename | db_role | state | upstream
---------------+------+---------------+------+------+----------+---------+--------+-----------
dbCluster | 6001 | 192.168.56.66 | 5432 | omm | dn_6001 | standby | Normal | -
| 6002 | 192.168.56.67 | 5432 | omm | dn_6002 | primary | Normal | -
十二、 集群扩容
扩容要求,现有环境需要是CM,否则会有提示
not support scale-out cm server on cluster which cm not installed
1、 扩容前状态
[root@mogdb-01 omm]# ptk cluster -n dbCluster status
[ Cluster State ]
cluster_name : dbCluster
cluster_state : Normal
database_version : MogDB 5.0.1.6 (build d78fb13b)
[ CMServer State ]
id | ip | port | hostname | role
-----+---------------+-------+----------+----------
1 | 192.168.56.66 | 15300 | mogdb-01 | primary
2 | 192.168.56.67 | 25300 | mogdb-02 | standby
[ Datanode State ]
cluster_name | id | ip | port | user | nodename | db_role | state | uptime | upstream
---------------+------+---------------+------+------+----------+---------+--------+----------+-----------
dbCluster | 6001 | 192.168.56.66 | 5432 | omm | dn_6001 | primary | Normal | 00:06:07 | -
| | 192.168.10.66 | | | | | | |
| 6002 | 192.168.56.67 | 5432 | omm | dn_6002 | standby | Normal | 00:05:27 | -
| | 192.168.10.67 | | | | | | |
[root@mogdb-01 omm]#
2、编辑配制文件
该文件参考一主一备一级联,去掉其中主与备,只保留本次要扩容的级联信息
# 集群级别的配置信息,其中 `db_port` 和 `ssh_option` 字段是 **可重用字段**
global:
cluster_name: dbCluster # 集群名称,PTK管理的集群的唯一标识
user: omm # 运行数据库的操作系统用户名
group: dbgrp # 运行数据库的操作系统用户组
db_port: 5432 # 数据库端口
ha_port: 5433 # 数据库实例角色,若不填,PTK 会随机选择一个实例作为主库,其余自动为备库
enable_cm: yes
db_password: "pTk6ZTQ5NTlhOTA8Qz5DPUQ/QmFWbUlNNGRwLU5jQlBkUEtLY2pfY0wtcUN4Tm5aajBFcFJHQWpJQWViOVk="
base_dir: /opt/mogdb # 数据库安装的基础目录,一般建议指定到配置文件中 ssh 用户可访问的目录下的路径,让PTK自动创建。
# # gs_initdb 工具支持参数列表,安装时会追加到指令中
gs_initdb_opts:
- "--encoding=UTF-8"
- "--dbcompatibility=A"
# MogDB 高可用组件 CM 配置信息,若不使用 CM 组件,则无需填写该字段
# MogDB 高可用组件 CM 配置信息,若不使用 CM 组件,则无需填写该字段
cm_option:
dir: /opt/mogdb/cm # CM 安装目录
cm_server_port: 15300 # cm server 监听端口
db_service_vip: "192.168.56.69" # 数据库提供服务的虚拟IP
# SSH 登录信息,登录用户需为 **root** 或者具有 sudo 权限的用户
# SSHOption SSH 登录认证信息,支持密码和密钥两种方式,二者需至少设置一种
ssh_option:
port: 22 # SSH 服务端口
user: root # SSH 登录用户
password: "pTk6NjI1MjNlZmY8Qz5DPUQ/Q1EtSkcxQVpFOWFxUnlzX3lnZFNRa0paS0lJQnByY2VDY1pNTG4tdGVFRXc=" # SSH 登录用户密码
conn_timeout: 5m0s # SSH 登录连接超时时间,支持单位 m(分),s(秒)
exec_timeout: 5m0s # SSH 执行单条命令时的超时时间,支持单位 m(分),s(秒)
# 集群内的数据库实例服务器配置信息
db_servers:
- host: 192.168.56.68 # 数据库实例服务器 IP (仅支持 IPv4)
# 数据库主备间日志复制IP,默认和数据库监听地址相同
ha_ips:
- 192.168.10.68
role: cascade_standby # 数据库实例角色,若不填,PTK 会随机选择一个实例作为主库,其余自动为备库
upstream_host: 192.168.56.67 # 当实例角色为 cascade_standby 时,该字段表示要跟随的上游备库 IP
az_name: AZ1 # Available Zone (可用区) 名称
az_priority: 1 # 可用区使用的优先级,数值越小优先级越高
3、扩容
ptk cluster -n dbCluster scale-out -c config_cm_3.yaml
扩容后状态查询
[root@mogdb-01 omm]# ptk cluster -n dbCluster status
[ Cluster State ]
cluster_name : dbCluster
cluster_state : Normal
database_version : MogDB 5.0.1.6 (build d78fb13b)
[ CMServer State ]
id | ip | port | hostname | role
-----+---------------+-------+----------+----------
1 | 192.168.56.66 | 15300 | mogdb-01 | primary
2 | 192.168.56.67 | 25300 | mogdb-02 | standby
[ Datanode State ]
cluster_name | id | ip | port | user | nodename | db_role | state | uptime | upstream
---------------+------+---------------+------+------+----------+-----------------+--------+----------+----------------
dbCluster | 6001 | 192.168.56.66 | 5432 | omm | dn_6001 | primary | Normal | 00:21:43 | -
| | 192.168.10.66 | | | | | | |
| 6002 | 192.168.56.67 | 5432 | omm | dn_6002 | standby | Normal | 00:21:03 | -
| | 192.168.10.67 | | | | | | |
| 6003 | 192.168.56.68 | 5432 | omm | dn_6003 | cascade_standby | Normal | 00:01:11 | 192.168.56.67
| | 192.168.10.68 | | | | | | |
[root@mogdb-01 omm]#
附、问题处理
附1、 version `OPENSSL_1_1_1f’ not found
发现环境
[sqd@node152 ~]$ 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"
[sqd@node152 ~]$ uname -a
Linux node152 4.19.90-24.4.v2101.ky10.aarch64 #1 SMP Mon May 24 14:45:37 CST 2021 aarch64 aarch64 aarch64 GNU/Linux
处理方法
unset LD_LIBRARY_PATH && ssh-keygen
附2、 initialize the memory protect for g_instance.attr.attr_storage.cstore_buffers (1024 Mbytes) or shared memory (4250 Mbytes) is larger.
虚拟机内存太少引起,更改如下参数
gs_guc set -N all -I all -c "max_process_memory = 4GB"
gs_guc set -N all -I all -c "shared_buffers = 512MB"
gs_guc set -N all -I all -c "cstore_buffers = 16MB"
gs_om -t stop
gs_om -t start
附3、 配制 oracle_fdw 环境变量
解压Oracle客户端,配制环境变量
export ORACLE_HOME=/opt/instantclient_19_19
export PATH=
O
R
A
C
L
E
H
O
M
E
:
ORACLE_HOME:
ORACLEHOME:PATH
export TNS_ADMIN=
O
R
A
C
L
E
H
O
M
E
/
n
e
t
w
o
r
k
/
a
d
m
i
n
e
x
p
o
r
t
L
D
L
I
B
R
A
R
Y
P
A
T
H
=
ORACLE_HOME/network/admin export LD_LIBRARY_PATH=
ORACLEHOME/network/adminexportLDLIBRARYPATH=ORACLE_HOME:$LD_LIBRARY_PATH
export NLS_LANG=‘AMERICAN_AMERICA.AL32UTF8’
export PATH
## 附4、 国产系统中文环境
yum -y install glibc-locale-source glibc-all-langpacks
locale -a | grep zh_CN
## 附5、 root 密码变动
运行命令时提供新的密码即可
[root@ha-01 ~]# ptk cluster -n dbCluster status
ERRO[2023-11-06T11:03:43.625] [192.168.56.67][omm] failed to connect to root@192.168.56.67: SSHConnectError: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none password], no supported methods remain
✔ password
✔ please enter the password for connecting root@192.168.56.67: ********
[ Cluster State ]
cluster_name : dbCluster
cluster_state : Normal
database_version : openGauss 5.1.0 (build b5a8d5b0)
[ CMServer State ]
id | ip | port | hostname | role
-----±--------------±------±---------±---------
1 | 192.168.56.66 | 15300 | ha-01 | primary
2 | 192.168.56.67 | 25300 | ha-02 | standby
[ Datanode State ]
cluster_name | id | ip | port | user | nodename | db_role | state | upstream
---------------±-----±--------------±-----±-----±---------±--------±-------±----------
dbCluster | 6001 | 192.168.56.66 | 5432 | omm | dn_6001 | primary | Normal | -
| 6002 | 192.168.56.67 | 5432 | omm | dn_6002 | standby | Normal | -
[root@ha-01 ~]#
## 附6、 更改hostname
同步更改 /etc/hosts文件即可