暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

openGauss 3.0一主一备安装

原创 吾喾 2022-10-07
1173

前期规划:

环境:麒麟V10系统 + openGauss 3.0


IP主机名
192.168.6.201ccf10

192.168.6.202ccf11


目录名称

所属用户目录路径

权限

数据库软件目录

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

cat >> /etc/hosts <<EOF
192.168.6.201 ccf10
192.168.6.202 ccf11
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
# 分发整合后的文件到其它节点
scp ~/.ssh/authorized_keys 192.168.6.202:~/.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>
<CLUSTER>
<PARAM name="clusterName" value="openGauss" />
<PARAM name="nodeNames" value="ccf10,ccf11"/>
<PARAM name="gaussdbAppPath" value="/opt/openGauss/app" />
<PARAM name="gaussdbLogPath" value="/var/log/omm" />
<PARAM name="tmpMppdbPath" value="/opt/openGauss/tmp"/>
<PARAM name="gaussdbToolPath" value="/opt/openGauss/install/om" />
<PARAM name="corePath" value="/opt/openGauss/corefile"/>
<PARAM name="backIp1s" value="192.168.6.201,192.168.6.202"/>
</CLUSTER>

<DEVICELIST>
<DEVICE sn="ccf10">
<PARAM name="name" value="ccf10"/>
<PARAM name="azName" value="AZ1"/>
<PARAM name="azPriority" value="1"/>
<PARAM name="backIp1" value="192.168.6.201"/>
<PARAM name="sshIp1" value="192.168.6.201"/>
<!-- dn -->
<PARAM name="dataNum" value="1"/>
<PARAM name="dataPortBase" value="15400"/>
<PARAM name="dataNode1" value="/data/openGauss,ccf11,/data/openGauss"/>
<PARAM name="dataNode1_syncNum" value="0"/>
</DEVICE>

<DEVICE sn="ccf11">
<PARAM name="name" value="ccf11"/>
<PARAM name="azName" value="AZ1"/>
<PARAM name="azPriority" value="1"/>
<PARAM name="backIp1" value="192.168.6.202"/>
<PARAM name="sshIp1" value="192.168.6.202"/>
</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执行安装脚本

[root@ccf10 script]# su - omm
[omm@ccf10 ~]$ cd /opt/openGauss/script/
[omm@ccf10 script]$ ./gs_install -X /home/omm/cluster_config.xml --gsinit-parameter="--locale=en_US.utf8"

3.4安装完成,环境变量修改.bashrc添加以下内容

[omm@ccf10 script]$ cd
[omm@ccf10 ~]$ vi .bashrc

export PGPORT=15400 #改成前面cluster_config.xml配置的端口
export PGDATA=/data/openGauss

[omm@ccf10 ~]$ source .bashrc

3.5检查主从

[omm@ccf10 ~]$ gs_ctl query
[2022-10-04 16:15:10.956][146056][][gs_ctl]: gs_ctl query ,datadir is /data/openGauss
HA state:
local_role : Primary
static_connections : 1
db_state : Normal
detail_information : Normal

Senders info:
sender_pid : 144430
local_role : Primary
peer_role : Standby
peer_state : Normal
state : Streaming
sender_sent_location : 0/4000388
sender_write_location : 0/4000388
sender_flush_location : 0/4000388
sender_replay_location : 0/4000388
receiver_received_location : 0/4000388
receiver_write_location : 0/4000388
receiver_flush_location : 0/4000388
receiver_replay_location : 0/4000388
sync_percent : 100%
sync_state : Async
sync_priority : 0
sync_most_available : Off
channel : 192.168.6.201:15401-->192.168.6.202:45600

Receiver info:
No information
[omm@ccf10 ~]$
[omm@ccf11 ~]$ gs_ctl query
[2022-10-04 16:14:40.329][68722][][gs_ctl]: gs_ctl query ,datadir is /data/openGauss
HA state:
local_role : Standby
static_connections : 1
db_state : Normal
detail_information : Normal

Senders info:
No information
Receiver info:
receiver_pid : 68011
local_role : Standby
peer_role : Primary
peer_state : Normal
state : Normal
sender_sent_location : 0/4000388
sender_write_location : 0/4000388
sender_flush_location : 0/4000388
sender_replay_location : 0/4000388
receiver_received_location : 0/4000388
receiver_write_location : 0/4000388
receiver_flush_location : 0/4000388
receiver_replay_location : 0/4000388
sync_percent : 100%
channel : 192.168.6.202:45600<--192.168.6.201:15401
[omm@ccf11 ~]$
[omm@ccf11 ~]$ 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 ccf10 192.168.6.201 15400 6001 /data/openGauss P Primary Normal
2 ccf11 192.168.6.202 15400 6002 /data/openGauss S Standby Normal

[omm@ccf10 ~]$ gsql -d postgres

openGauss=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+-------+----------+------------+------------+-------------------
mydb1 | omm | UTF8 | en_US.utf8 | en_US.utf8 |
postgres | omm | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | omm | UTF8 | en_US.utf8 | en_US.utf8 | =c/omm +
| | | | | omm=CTc/omm
template1 | omm | UTF8 | en_US.utf8 | en_US.utf8 | =c/omm +
| | | | | omm=CTc/omm
(4 rows)

测试建库建表均成功在备库查询到,创建完成。

最后修改时间:2022-10-08 09:31:01
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

文章被以下合辑收录

评论