技术交流QQ群:①185473046   ②190706903   ③203744115   网站地图
登录

下次自动登录
现在的位置: 首页openGauss>正文
CentOS 7.x安装配置openGauss数据库
2022年12月27日 openGauss 暂无评论 ⁄ 被围观 3,183次+

openGauss是由华为开源的一款关系型数据库,基于PostgreSQL数据库开发。

操作系统:CentOS 7.x

官方网站:https://opengauss.org/zh/

下载地址:https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.1.0/x86/openGauss-3.1.0-CentOS-64bit-all.tar.gz

安装前系统设置

1、关闭SELINUX

vi /etc/selinux/config

#SELINUX=enforcing #注释掉

#SELINUXTYPE=targeted #注释掉

SELINUX=disabled #增加

:wq! #保存退出

setenforce 0 #使配置立即生效

2、开启防火墙5432端口

CentOS 7.x默认使用的是firewall作为防火墙,这里改为iptables防火墙。

2.1、关闭firewall:

systemctl stop firewalld.service #停止firewall

systemctl disable firewalld.service #禁止firewall开机启动

systemctl mask firewalld

systemctl stop firewalld

yum remove firewalld

2.2、安装iptables防火墙

yum install iptables-services #安装

vi /etc/sysconfig/iptables #编辑防火墙配置文件

# sample configuration for iptables service

# you can edit this manually or use system-config-firewall

# please do not ask us to add additional ports/services to this default configuration

*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [0:0]

-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

-A INPUT -p icmp -j ACCEPT

-A INPUT -i lo -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 5432 -j ACCEPT

-A INPUT -j REJECT --reject-with icmp-host-prohibited

-A FORWARD -j REJECT --reject-with icmp-host-prohibited

COMMIT

:wq! #保存退出

systemctl restart iptables.service #最后重启防火墙使配置生效

systemctl enable iptables.service #设置防火墙开机启动

/usr/libexec/iptables/iptables.init restart #重启防火墙

3、操作系统参数设置

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

net.ipv4.tcp_retries1=5

net.ipv4.tcp_syn_retries=5

net.sctp.path_max_retrans=10

net.sctp.max_init_retransmits=10

kernel.shmmax = 17179869184

kernel.shmall = 4194304

kernel.sem=  500 5120000 2500 9000

EOF

lsmod |grep sctp

yum -y install lksctp*

modprobe sctp

sysctl -p #设置立即生效

echo 17179869184 > /proc/sys/kernel/shmmax

echo 4194304 > /proc/sys/kernel/shmall

echo "* soft stack 3072" >> /etc/security/limits.conf

echo "* hard stack 3072" >> /etc/security/limits.conf

echo "* soft nofile 1000000" >> /etc/security/limits.conf

echo "* hard nofile 1000000" >> /etc/security/limits.conf

echo "* soft nproc unlimited" >> /etc/security/limits.d/90-nproc.conf

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

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

echo 'echo never > /sys/kernel/mm/transparent_hugepage/defrag' >> /etc/rc.d/rc.local

echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.d/rc.local

chmod +x /etc/rc.d/rc.local

/usr/bin/sh /etc/rc.d/rc.local

4、修改主机名称

这里设置主机名为:opengauss-master

hostnamectl set-hostname opengauss-master #CentOS 7.x 8.x

vi /etc/hostname #编辑配置文件CentOS 7.x

opengauss-master #修改localhost.localdomain为opengauss-master

:wq! #保存退出

vi /etc/hosts #编辑配置文件

127.0.0.1 opengauss-master localhost #修改localhost.localdomain为opengauss-master

192.168.21.128 opengauss-master

:wq! #保存退出

5、设置操作系统字符集编码

LANG=en_US.UTF-8

echo "LANG=en_US.UTF-8" >> /etc/profile

source /etc/profile

echo $LANG

6、设置时区同步时间

rm -rf /etc/localtime #先删除默认的时区设置

ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime #替换上海/北京作为默认

yum install -y ntp #安装ntp

ntpdate time1.aliyun.com #执行时间同步

hwclock --systohc #系统时钟和硬件时钟同步

7、安装依赖包

yum install libaio-devel flex bison ncurses-devel glibc-devel patch redhat-lsb python3 bzip2

#服务器需要用到Python-3.x命令,但CentOS 7.x 默认版本Python-2.7.x,需要切换到Python-3.x版本

mv /usr/bin/python /usr/bin/python.bak

ln -s python3 /usr/bin/python

8、设置yum使用python2.7否则无法通过yum install安装软件

vi /usr/bin/yum

#!/usr/bin/python2.7

:wq! 保存退出

vi /usr/libexec/urlgrabber-ext-down

/usr/bin/python2.7

:wq! 保存退出

yum install telnet

#设置完成之后重启下系统,继续操作

安装数据库

1、上传安装包到目录/usr/local/src/openGauss下面

2、安装数据库

2.1解压数据库安装包

cd /usr/local/src/openGauss

tar -zxvf openGauss-3.1.0-CentOS-64bit-all.tar.gz

tar -zxvf openGauss-3.1.0-CentOS-64bit-om.tar.gz

2.2创建数据库用户和用户组并设置权限

groupadd dbgrp

useradd -g dbgrp omm

echo 'omm@a1b2c3' | passwd --stdin omm

mkdir -p /data/server/openGauss

chmod 775 /data/server/openGauss -R

chown omm:dbgrp /data/server/openGauss -R

2.3创建配置文件

vi /usr/local/src/openGauss/cluster_config.xml

<?xml version="1.0" encoding="UTF-8"?>

<ROOT>

<!-- openGauss整体信息 -->

<CLUSTER>

<!-- 数据库名称 -->

<PARAM name="clusterName" value="huaweidbCluster" />

<!-- 数据库节点名称(主机的hostname名称) -->

<PARAM name="nodeNames" value="opengauss-master" />

<!-- 数据库安装目录-->

<PARAM name="gaussdbAppPath" value="/data/server/openGauss/app" />

<!-- 日志目录-->

<PARAM name="gaussdbLogPath" value="/data/server/openGauss/log/omm" />

<!-- 临时文件目录-->

<PARAM name="tmpMppdbPath" value="/data/server/openGauss/tmp" />

<!-- 数据库工具目录-->

<PARAM name="gaussdbToolPath" value="/data/server/openGauss/om" />

<!-- 数据库core文件目录-->

<PARAM name="corePath" value="/data/server/openGauss/corefile" />

<!-- 节点IP,与数据库节点名称列表一一对应 -->

<PARAM name="opengauss-master" value="192.168.21.128"/>

</CLUSTER>

<!-- 每台服务器上的节点部署信息 -->

<DEVICELIST>

<!-- 节点1上的部署信息 -->

<DEVICE sn="opengauss-master">

<!-- 节点1的主机名称 -->

<PARAM name="name" value="opengauss-master"/>

<!-- 节点1所在的AZ及AZ优先级 -->

<PARAM name="azName" value="AZ1"/>

<PARAM name="azPriority" value="1"/>

<!-- 节点1的IP,如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP -->

<PARAM name="backIp1" value="192.168.21.128"/>

<PARAM name="sshIp1" value="192.168.21.128"/>

<!--dbnode-->

<PARAM name="dataNum" value="1"/>

<PARAM name="dataPortBase" value="5432"/>

<PARAM name="dataNode1" value="/data/server/openGauss/data/dn"/>

<PARAM name="dataNode1_syncNum" value="0"/>

</DEVICE>

</DEVICELIST>

</ROOT>

:wq! #保存退出

nodeNames value=opengauss-master

sn=opengauss-master

把value后面的值改为主机名

backIp1 value=192.168.21.128

sshIp1 value=192.168.21.128

节点IP,与数据库节点名称列表对应

dataPortBase value=5432

数据库端口

2.4执行预安装脚本

为了保证openGauss正确安装,需要对主机环境进行初始化

cd /usr/local/src/openGauss/script/

./gs_preinstall -U omm -G dbgrp -X /usr/local/src/openGauss/cluster_config.xml

根据提示输入y继续

#如果报错[GAUSS-50202] 权限不足,请检查服务器上的优化参数设置,可以把这个几个配置文件恢复到初始化设置,一般就能解决报错问题 /etc/security/limits.conf  /etc/security/limits.d/20-nproc.conf  /etc/sysctl.conf

2.5检查系统环境

cd /usr/local/src/openGauss/script/

/usr/local/src/openGauss/script/gs_checkos -i A -h opengauss-master --detail

2.6安装数据库

chown omm.dbgrp /usr/local/src/openGauss/ -R

su - omm #切换到omm用户

cd /usr/local/src/openGauss/script/

gs_install -X /usr/local/src/openGauss/cluster_config.xml

Please enter password for database:

设置数据库密码,最少包含8个字符:A1b2c3@#

不能和用户名、当前密码(ALTER)、或当前密码反序相同。

至少包含大写字母(A-Z)、小写字母(a-z)、数字、非字母数字字符(限定为~!@#$%^&*()-_=+|[{}];:,<.>/?)四类字符中的三类字符。

#启动数据库

gs_ctl start -D /data/server/openGauss/data/dn

#查看数据库状态

gs_om -t status

gs_om -t status --detail

gs_om -t status --all

gs_checkperf

#查看进程

ps -ef | grep gaussdb | egrep -v "grep"

#查看实例状态

gs_om -t status --detail

#进入控制台

gsql -d postgres -p 5432

select version(); #查看版本

SHOW server_version;

SELECT * FROM pg_settings WHERE NAME='server_version';

\q  #退出控制台

2.7连接数据库、创建用户、数据库、schema

gsql -d postgres -p 5432

create user admin with password "A1b2c3@#";

create database testdb owner admin;

GRANT ALL PRIVILEGES TO admin;

\c testdb admin;

create schema testdb authorization admin;

create table test(id int,name varchar(200));

insert into test values (1,'myname');

select * from test;

\q  #退出控制台

3、使用工具进行连接操作

#Windows 需要提前安装好jdk-11.0.17_windows-x64_bin并配置好环境变量

3.1工具下载Data Studio_3.1.0

https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.1.0/DataStudio_win_64.zip

3.2开始openGauss数据库监听

cd /data/server/openGauss/data/dn

cp postgresql.conf postgresql.conf-bak

cp pg_hba.conf pg_hba.conf-bak

vi /data/server/openGauss/data/dn/postgresql.conf

ssl = off

listen_addresses = 'localhost,192.168.21.100' #192.168.21.100需要替换为openGauss所在节点实际IP。

password_encryption_type = 1  #修改为1,同时支持sha256 + md5加密,支持用pgsql客户端连接工具

#Password storage type, 0 is md5 for PG, 1 is sha256 + md5, 2 is sha256 only

:wq! 保存退出

vi /data/server/openGauss/data/dn/pg_hba.conf

# IPv4 local connections:

host all all 0.0.0.0/0 sha256

#host all admin 0.0.0.0/0 md5

:wq! 保存退出

增加Data Studio所在Windows 机器的IP远程访问连接许可,新增一行然后保存退出。

gs_om -t restart  #重启数据库

3.3打开Data Studio_3.1.0

配置好连接信息

gs_om -t stop #关闭

gs_om -t start #启动

至此,CentOS 7.x安装配置openGauss数据库完成。

     

  系统运维技术交流QQ群:①185473046 系统运维技术交流□Ⅰ ②190706903 系统运维技术交流™Ⅱ ③203744115 系统运维技术交流™Ⅲ

给我留言

您必须 [ 登录 ] 才能发表留言!



Copyright© 2011-2024 系统运维 All rights reserved
版权声明:本站所有文章均为作者原创内容,如需转载,请注明出处及原文链接
陕ICP备11001040号-3