openGauss单机+主从集群部署_万能场景安装_搭建_适用所有场景_openGauss3.0.0_openGauss课程

一、opengauss 的背景和行业现状

2022 年,七大 openGauss 商业版发布,是基于 openGauss3.0 推出商业发行版

目前海量数据库 Vastbase 表现最佳,一直是 TOP 1

作者认为之所以海量数据库 Vastbase 目前无法被同行超越,和各家研发实力和技术背景有关

众所周知,opengauss 起源于 postgresql,在此基础上做了改良

海量数据库从 postgresql 就已经开始做商业版,一直做到 opengauss,经验最丰富,其他产品例如 MongoDB 是紧随其后 (在此不讨论其存在的意义),目前产品百花齐放,更显锦上添花

Vastbase G100 采用业界证明稳定高效的日志流复制技术实现集群内主备库的数据和状态传输,

并通过一主多备的部署和配置架构实现了多点可读、数据不丢失、异地灾备等关键高可用场景。

二、实验设计背景

本实验是单机openGauss3.0.0新增从库or重搭从库,形成主从。

因为直接部署一套主从太简单了,而且在使用过程中,从库故障需要重新搭建从库,或者需要新增从库,这个时候由于数据库已经上线了,只能在原有基础上进行延申配置。

本实验也同样适用于最初搭建主从环境的情况,先搭建一个主库交付,再配置多个从库,所以本实验适用于所有openGauss主从搭建、运维、管理场景。

实验环境:华为云服务器2台

规格:通用计算增强型 | c7.xlarge.4 | 4vCPUs | 16GiB  

镜像:openEuler 20.03 64bit |公共镜像

三、搭建单机opengauss

3.1获取openGauss-3.0.0安装包

[root@master ~]# wget https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.0.0/x86_openEuler/openGauss-3.0.0-openEuler-64bit-all.tar.gz

3.2设置字符集

[root@master ~]# vim /etc/profile

添加

export LANG=en_US.UTF-8

3.3关闭swap交换内存(可选)

[root@master ~]# swapoff -a

3.4关闭RemoveIPC

[root@master ~]# vim /etc/systemd/logind.conf

RemoveIPC=no

[root@master ~]# vim /usr/lib/systemd/system/systemd-logind.service

RemoveIPC=no

重新加载

[root@master ~]# systemctl daemon-reload

[root@master ~]# systemctl restart systemd-logind

检查是否生效

[root@master ~]# loginctl show-session | grep RemoveIPC

RemoveIPC=no

[root@master ~]# systemctl show systemd-logind | grep RemoveIPC

RemoveIPC=no

3.5修改主机名

[root@master ~]# cat /etc/hostname

master

[root@master ~]# cat /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.0.12 master

3.6解压软件包

[root@master ~]# mkdir -p /data/openGauss/

[root@master ~]# tar -zxvf openGauss-3.0.0-openEuler-64bit-all.tar.gz -C /data/openGauss/

openGauss-3.0.0-openEuler-64bit-cm.tar.gz

openGauss-3.0.0-openEuler-64bit-om.tar.gz

openGauss-3.0.0-openEuler-64bit.tar.bz2

openGauss-3.0.0-openEuler-64bit-cm.sha256

openGauss-3.0.0-openEuler-64bit-om.sha256

openGauss-3.0.0-openEuler-64bit.sha256

upgrade_sql.tar.gz

upgrade_sql.sha256

3.7创建用户组和用户

[root@master ~]# groupadd dbgroup

[root@master ~]# useradd -g dbgroup omm

[root@master ~]# passwd omm

Changing password for user omm.

New password:  

BAD PASSWORD: The password is shorter than 8 characters

Retype new password:  

passwd: all authentication tokens updated successfully.

3.8配置操作系统参数

cat >> /etc/sysctl.conf << EOF

net.ipv4.tcp_max_tw_buckets = 10000

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_keepalive_time = 30

net.ipv4.tcp_keepalive_probes = 9

net.ipv4.tcp_keepalive_intvl = 30

net.ipv4.tcp_retries1 = 5

net.ipv4.tcp_syn_retries = 5

net.ipv4.tcp_synack_retries = 5

net.ipv4.tcp_retries2 = 12

vm.overcommit_memory = 0

net.ipv4.tcp_rmem = 8192 250000 16777216

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.ip_local_port_range = 26000 65535

kernel.sem = 250 6400000 1000 25600

vm.min_free_kbytes = 419430  

net.core.somaxconn = 65535

net.ipv4.tcp_syncookies = 1

net.core.netdev_max_backlog = 65535

net.ipv4.tcp_max_syn_backlog = 65535

net.ipv4.tcp_fin_timeout = 60

kernel.shmall = 1152921504606846720

kernel.shmmax = 18446744073709551615

net.ipv4.tcp_sack = 1

net.ipv4.tcp_timestamps = 1

vm.extfrag_threshold = 500

vm.overcommit_ratio = 90

net.ipv4.ip_local_reserved_ports = 20050-20057,26000-26007

EOF

[root@master ~]# sysctl -p

3.9修改系统资源限制

[root@master ~]# echo "* soft stack 3072" >> /etc/security/limits.conf

[root@master ~]# echo "* hard stack 3072" >> /etc/security/limits.conf

[root@master ~]# echo "* soft nofile 1000000" >> /etc/security/limits.conf

[root@master ~]# echo "* hard nofile 1000000" >> /etc/security/limits.conf

[root@master ~]# echo "* soft nproc unlimited" >> /etc/security/limits.d/90-nproc.conf

[root@master ~]# tail -n 4 /etc/security/limits.conf

[root@master ~]# tail -n 1 /etc/security/limits.d/90-nproc.conf

3.10关闭htp并reboot

[root@master ~]# vim /etc/rc.d/rc.local

if test -f /sys/kernel/mm/transparent_hugepage/enabled; then

echo never > /sys/kernel/mm/transparent_hugepage/enabled

fi

if test -f /sys/kernel/mm/transparent_hugepage/defrag; then

echo never > /sys/kernel/mm/transparent_hugepage/defrag

fi

[root@master ~]# chmod +x /etc/rc.d/rc.local

[root@master ~]# reboot

3.11安装基础环境必备软件

[root@master ~]# yum install expect libaio.so.*

3.12编辑xml文件

[root@momo488 data]# cat momo488.xml  

   

       

       

       

       

       

       

       

         

   

   

       

           

           

           

           

           

    

    

    

    

           

       

   

3.13解压软件包

[root@master openGauss]# tar -zxvf openGauss-3.0.0-openEuler-64bit-om.tar.gz

[root@momo488 ~]# chown -R omm:dbgroup /data

[root@momo488 ~]# chmod -R 755 /data

[root@momo488 ~]# cat>> /etc/profile<

export LD_LIBRARY_PATH=/data/openGauss/script/gspylib/clib:$LD_LIBRARY_PATH

EOF

3.14运行gs_preinstall

[root@master openGauss]# /data/openGauss/script/gs_preinstall -U omm -G dbgroup -X /data/momo488.xml

3.15运行gs_install

[omm@master ~]$ gs_install -X /data/momo488.xml --gsinit-parameter="--locale=en_US.utf8"

密码设置:MoMo488_2023

3.16登录数据库

[omm@master ~]$ gsql -d postgres -p 15400

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=# create database momo488db;

CREATE DATABASE

[omm@master ~]$  gsql -d momo488db -p 15400

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.

momo488db=# create table momo24(si int);

CREATE TABLE

momo488db=# insert into momo24 values (4);

INSERT 0 1

momo488db=# select * from momo24;

si  

----

 4

(1 row)

这里是模拟生产环境已经上线,具有了一些老数据,在此基础上增加新的从库节点,或者从库故障需要重搭一个从库,新从库也应该同步这些老数据。

四、扩容/搭建从库节点,增加1个从库slave01

4.1编辑xml文件

[root@master data]# pwd

/data

[root@master data]# vi momo488TOmomoslave01.xml  

   

       

       

       

       

       

       

       

         

   

   

       

           

           

           

           

               

           

           

           

           

       

       

           

           

           

           

           

       

   

4.2主从服务器都修改主机名和映射

[root@slave01 ~]# cat /etc/hostname

slave01

[root@master ~]# cat /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.0.12 master

192.168.0.73 slave01

把多余的行删掉,否则容易出问题,通过ping主机名测试,不能有解析成127.0.0.1的,必须是实际的IP地址

4.3把从服务器环境按照主服务器再配置一遍

4.4配置主从之间的互信

root用户配置互信

ssh-keygen -t rsa

cat .ssh/id_rsa.pub >> ~/.ssh/authorized_keys

ssh-keyscan -t rsa master >> ~/.ssh/known_hosts  

ssh-keyscan -t rsa slave01 >> ~/.ssh/known_hosts  

scp -r ~/.ssh slave01:~

测试

ssh master

ssh slave01

omm用户配置互信

ssh-keygen -t rsa

cat .ssh/id_rsa.pub >> ~/.ssh/authorized_keys

ssh-keyscan -t rsa master >> ~/.ssh/known_hosts  

ssh-keyscan -t rsa slave01 >> ~/.ssh/known_hosts  

scp -r ~/.ssh slave01:~

chmod 700 /home/omm

chmod 700 /home/omm/.ssh

chmod 600 /home/omm/.ssh/authorized_keys  

chmod 600 /home/omm/.ssh/id_rsa

测试

ssh master

ssh slave01

4.5 单机扩展到主备的时候,主库需要以primary方式启动

[omm@master~]$ gs_ctl stop -D /data/openGauss/install/data/dn

[omm@master~]$ gs_ctl start -D /data/openGauss/install/data/dn -M primary

4.6主机环境变量

[root@master ~]# cat /etc/profile

export LANG=en_US.UTF-8

export LD_LIBRARY_PATH=/data/openGauss/script/gspylib/clib:

export GPHOME=/data/openGauss/install/om

export PATH=$GPHOME/script/gspylib/pssh/bin:$GPHOME/script:$PATH

export LD_LIBRARY_PATH=$GPHOME/script/gspylib/clib:$LD_LIBRARY_PATH

export LD_LIBRARY_PATH=$GPHOME/lib:$LD_LIBRARY_PATH

export PYTHONPATH=$GPHOME/lib

export PATH=/root/gauss_om/omm/script:$PATH

export GAUSSHOME=/data/openGauss/install/app

export PGHOST=/data/openGauss/tmp

没有这两行就会报错,所以提前加上

[root@master ~]# source /etc/profile

4.7执行扩展

/data/openGauss/script/gs_expansion -U omm -G dbgroup -X /data/momo488TOmomoslave01.xml -h 192.168.0.73

密码设置:MoMo488_2023

[root@master ~]# /data/openGauss/script/gs_expansion -U omm -G dbgroup -X /data/momo488TOmomoslave01.xml -h 192.168.0.73

Start expansion without cluster manager component.

Start to preinstall database on new nodes.

Start to send soft to each standby nodes.

End to send soft to each standby nodes.

Start to preinstall database step.

Preinstall 192.168.0.73 success

End to preinstall database step.

End to preinstall database on new nodes.

Start to install database on new nodes.

Installing database on node 192.168.0.73:

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:MoMo488_2023

Please repeat for database:MoMo488_2023

begin to create CA cert files

The sslcert will be generated in /data/openGauss/install/app/share/sslcert/om

NO cm_server instance, no need to create CA for CM.

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.

Configuring pg_hba on all nodes.

Configuration is completed.

Successfully started cluster.

Successfully installed application.

end deploy..

192.168.0.73 install success.

Finish to install database on all nodes.

Database on standby nodes installed finished.

Checking gaussdb and gs_om version.

End to check gaussdb and gs_om version.

Start to establish the relationship.

Start to build standby 192.168.0.73.

Build standby 192.168.0.73 success.

Start to generate and send cluster static file.

End to generate and send cluster static file.

Expansion results:

192.168.0.73: Success

Expansion Finish.

[root@master om]#  

4.8检查扩容后的集群状态

[omm@master ~]$ gs_om -t status --detail

[   Cluster State   ]

cluster_state   : Normal

redistributing  : No

current_az      : AZ_ALL

[  Datanode State   ]

   node   node_ip         port      instance                                state

--------------------------------------------------------------------------------------------------

1  master  192.168.0.12    15400      6001 /data/openGauss/install/data/dn   P Primary Normal

2  slave01 192.168.0.73    15400      6002 /data/openGauss/install/data/dn   S Standby Normal

4.9登录从库查看数据是否同步

[omm@slave01 ~]$ gsql -d momo488db -p 15400

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.

momo488db=# select * from momo24;

si  

----

 4

(1 row)

momo488db=#  

4.10主库增加数据,查看从库是否同步

[omm@master ~]$ gsql -d momo488db -p 15400

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.

momo488db=# insert into momo24 values (488);

INSERT 0 1

momo488db=# select * from momo24;

si  

-----

  4

488

(2 rows)

[omm@slave01 ~]$ gsql -d momo488db -p 15400

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.

momo488db=# select * from momo24;

si  

-----

  4

488

(2 rows)

本文参考官方文档

https://docs.opengauss.org/zh/

https://docs.vastdata.com.cn/zh/
 

你可能感兴趣的:(数据库)