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

openGauss 1.0.1单机版安装

原创 .key 2021-12-01
853

环境信息:

OpenGauss版本:1.0.1
软件包下载地址:https://opengauss.org/zh/download.html
Linux:CentOS 7.6
192.168.0.246 opengauss

1. 安装依赖包

# yum源配置
[root@opengauss ~]# mkdir /etc/yum.repos.d/repo_bak
[root@opengauss ~]# mv /etc/yum.repos.d/* /etc/yum.repos.d/repo_bak/
[root@opengauss ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo
[root@opengauss ~]# yum clean all ; yum repolist

# 安装依赖包
[root@opengauss ~]# yum -y install java-1.8.0-openjdk* psmisc bzip2 python3 python3-devel lksctp*
[root@opengauss ~]# yum -y install libaio-devel flex bison ncurses-devel glibc-devel patch redhat-lsb-core

2. 配置主机域名解析

[root@opengauss ~]# vim /etc/hosts
......
192.168.0.246 opengauss

3. 关闭安全策略

# 临时关闭selinux
[root@opengauss ~]# setenforce 0

# 永久关闭selinux,重启后生效
[root@opengauss ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config 

# 关闭防火墙
[root@opengauss ~]# systemctl stop firewalld
[root@opengauss ~]# systemctl disable firewalld

4. 修改字符集

[root@opengauss ~]# echo $LANG
zh_CN.UTF-8

[root@opengauss ~]# echo "export LANG=en_US.UTF8" >> ~/.bash_profile 
[root@opengauss ~]# source ~/.bash_profile
[root@opengauss ~]# echo $LANG
en_US.UTF8

5. 配置ssh服务

[root@opengauss ~]# cat /etc/ssh/sshd_config | grep "Banner"
#Banner none      #注释掉ssh登录的欢迎信息
[root@opengauss ~]# cat /etc/ssh/sshd_config | grep "PermitRootLogin"
PermitRootLogin yes   #允许root用户远程登录

# 若修改过则需重启sshd服务
[root@opengauss ~]# systemctl restart sshd

6. 关闭swap分区

# 注释开机挂载swap分区
[root@opengauss ~]# cat /etc/fstab | grep swap
#/dev/mapper/centos_centos7-swap swap                    swap    defaults        0 0

# 关闭swap分区
[root@opengauss ~]# swapoff -a
[root@opengauss ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           3.8G        122M        3.5G         11M        184M        3.5G
Swap:            0B          0B          0B     # swap分区已经被关闭

7. 关闭大透明页

# 修改如下
[root@opengauss ~]# sed -i 's/GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX="rhgb quiet transparent_hugepage=never"/' /etc/default/grub 
[root@opengauss ~]# cat /etc/default/grub | grep -i "grub_cmdline_linux"

GRUB_CMDLINE_LINUX="rhgb quiet transparent_hugepage=never"

# 重新编译grub,关闭透明页
[root@opengauss ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
# 检查透明页是否已禁用
[root@opengauss ~]# cat /proc/meminfo | grep -i "huge"

# [可选]临时关闭透明页
[root@opengauss ~]# echo "never" > /sys/kernel/mm/transparent_hugepage/enabled
[root@opengauss ~]# echo "never" > /sys/kernel/mm/transparent_hugepage/defrag

8. 检查时区

# 设置为上海时区
[root@opengauss ~]# ll /etc/localtime 
lrwxrwxrwx. 1 root root 35 Oct 28 16:51 /etc/localtime -> ../usr/share/zoneinfo/Asia/Shanghai

# 同步系统时间至硬件
[root@opengauss ~]# hwclock -w

9. 操作系统资源限制

[root@opengauss ~]# cat >> /etc/security/limits.conf <<EOF
* soft stack 3072
* hard stack 3072
* soft nofile 1000000
* hard nofile 1000000
EOF

[root@opengauss ~]# vim /etc/security/limits.d/20-nproc.conf 
......
*          soft    nproc     unlimited

10. 内核参数配置

[root@opengauss ~]# vim /etc/sysctl.conf
vm.swappiness=0
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_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.sctp.path_max_retrans = 10
net.sctp.max_init_retransmits = 10
net.sctp.association_max_retrans = 10
net.sctp.hb_interval = 30000
net.ipv4.tcp_retries2 = 12
vm.overcommit_memory = 0
net.sctp.sndbuf_policy = 0
net.sctp.rcvbuf_policy = 0
net.sctp.sctp_mem = 94500000 915000000 927000000
net.sctp.sctp_rmem = 8192 250000 16777216
net.sctp.sctp_wmem = 8192 250000 16777216
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 = 201318     # 该值设置为系统总内存的5%,单位:字节
net.core.somaxconn = 65535
net.ipv4.tcp_syncookies = 1
net.sctp.addip_enable = 0
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

[root@opengauss ~]# sysctl -p
Tips: 新系统执行sysctl -p命令时可能会输出很多文件或目录不存在错误,      重启操作系统后再次执行sysctl -p便没有这些报错。

11. 创建XML配置文件

[root@opengauss ~]# vim ~/cluster_config.xml
<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
    <!-- openGauss整体信息 -->
    <CLUSTER>
        <!-- 数据库名称 -->
        <PARAM name="clusterName" value="dbCluster" />
        <!-- 数据库节点名称(hostname) -->
        <PARAM name="nodeNames" value="opengauss" />
        <!-- 数据库安装目录-->
        <PARAM name="gaussdbAppPath" value="/opt/huawei/opengauss/app" />
        <!-- 日志目录-->
        <PARAM name="gaussdbLogPath" value="/var/log/opengauss" />
        <!-- 临时文件目录-->
        <PARAM name="tmpMppdbPath" value="/opt/huawei/opengauss/tmp" />
        <!-- 数据库工具目录-->
        <PARAM name="gaussdbToolPath" value="/opt/huawei/opengauss/om" />
        <!-- 数据库core文件目录-->
        <PARAM name="corePath" value="/opt/huawei/opengauss/corefile" />
        <!-- 节点IP,与数据库节点名称列表一一对应 -->
        <PARAM name="backIp1s" value="192.168.0.246"/> 
		<!-- opengauss类型,此处示例为单机类型 -->
		<PARAM name="clusterType" value="single-inst"/>
    </CLUSTER>
    <!-- 每台服务器上的节点部署信息 -->
    <DEVICELIST>
        <!-- 节点1上的部署信息 -->
        <DEVICE sn="opengauss">
            <!-- 节点1的主机名称 -->
            <PARAM name="name" value="opengauss"/>
            <!-- 节点1所在的AZ及AZ优先级 -->
            <PARAM name="azName" value="AZ1"/>
            <PARAM name="azPriority" value="1"/>
            <!-- 节点1的IP,如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP -->
            <PARAM name="backIp1" value="192.168.0.246"/>
            <PARAM name="sshIp1" value="192.168.0.246"/>
               
	    <!--dbnode-->
		<!-- 当前主机上需要部署的数据库节点个数 -->
	    <PARAM name="dataNum" value="1"/>
		<!-- DBnode端口号 -->
	    <PARAM name="dataPortBase" value="26000"/>
		<!-- DBnode节点数据存储目录 -->
	    <PARAM name="dataNode1" value="/srv/BigData/OpenGauss/data1"/>
            <PARAM name="dataNode1_syncNum" value="0"/>
        </DEVICE>
    </DEVICELIST>
</ROOT>

12. 创建目录并解压软件包

# 创建数据目录
[root@opengauss ~]# mkdir -p /srv/BigData/OpenGauss/data1
# 创建软件包存放目录
[root@opengauss ~]# mkdir -p /opt/software/openGauss
[root@opengauss ~]# chmod 755 -R /opt/software
[root@opengauss ~]# cd /opt/software/openGauss# 将opengauss软件包上传至该目录
[root@opengauss openGauss]# ls
openGauss-1.0.1-CentOS-64bit.tar.gz
[root@opengauss openGauss]# tar -zxvf openGauss-1.0.1-CentOS-64bit.tar.gz 

# 将XML配置文件移动至解压目录下
[root@opengauss ~]# mv ~/cluster_config.xml /opt/software/openGauss/

13. 执行交互式预安装

[root@opengauss ~]# export LD_LIBRARY_PATH=/opt/software/openGauss/script/gspylib/clib:$LD_LIBRARY_PATH
[root@opengauss ~]# cd /opt/software/openGauss/script/
[root@opengauss script]# ./gs_preinstall -U omm -G dbgrp -X /opt/software/openGauss/cluster_config.xml --sep-env-file=/srv/BigData/OpenGauss/db1_env
......
Are you sure you want to create trust for root (yes/no)? yes
Please enter password for root.
Password:        # 输入root用户的密码
......
Are you sure you want to create the user[omm] and create trust for it (yes/no)? yes
Please enter password for cluster user.
Password:        # 设置omm用户的密码
Please enter password for cluster user again.
Password:        # 再次输入omm用户的密码
Successfully created [omm] user on all nodes.
......
Successfully set finish flag.
Preinstallation succeeded.      # 成功。

14. 检查参数配置情况

# 预安装完成后重启一次操作系统,使预安装的部分参数配置生效
[root@opengauss ~]# reboot
# 执行检查命令
[root@opengauss ~]# /opt/software/openGauss/script/gs_checkos -i A -h opengauss --detail

# 使用tree命令查看预安装产生的目录文件
[root@opengauss ~]# tree -L 2 /opt/huawei/opengauss/
/opt/huawei/opengauss/
|-- app_13b34b53
|-- corefile
|-- om
|   |-- lib
|   |-- openGauss-1.0.1-CentOS-64bit.sha256
|   |-- openGauss-1.0.1-CentOS-64bit.tar.bz2
|   |-- openGauss-Package-bak_13b34b53.tar.gz
|   |-- script
|   `-- version.cfg
`-- tmp

6 directories, 4 files


# 检查环境变量文件
[root@opengauss ~]# cat /srv/BigData/OpenGauss/db1_env

15. 执行数据库安装

[root@opengauss ~]# chown -R omm:dbgrp /opt/huawei/ /opt/software/ /srv/BigData/
[root@opengauss ~]# su - omm
[omm@opengauss ~]$ source /srv/BigData/OpenGauss/db1_env 
[omm@opengauss ~]$ gs_install -X /opt/software/openGauss/cluster_config.xml \
--gsinit-parameter="--encoding=UTF8" \
--dn-guc="max_connections=1000" \
--dn-guc="max_process_memory=3GB" \
--dn-guc="shared_buffers=128MB" \
--dn-guc="bulk_write_ring_size=128MB" \
--dn-guc="cstore_buffers=16MB"
......
Tips: 若主机内存大于等于32GB就直接执行"gs_install -X /opt/software/openGauss/cluster_config.xml"即可,      这些参数是主机内存不满足推荐要求时需要加上。

encrypt cipher and rand files for database.
Please enter password for database:     # 输入数据库omm用户初始密码
Please repeat for database:             # 再次输入数据库omm用户初始密码
begin to create CA cert files
......
Successfully installed application.
end deploy..          # 成功

16. 数据库登录测试

[root@opengauss ~]# gsql -d postgres -p 26000 -r
postgres=# \l
ERROR:  Please use "ALTER ROLE user_name IDENTIFIED BY 'password' REPLACE 'old password';" to modify the initial password of user omm before operation!

# 修改omm用户密码
postgres=# alter role omm identified by 'Huawei@123!@#' replace 'Huawei@123';
ALTER ROLE
postgres=# \l
                         List of databases
   Name    | Owner | Encoding | Collate | Ctype | Access privileges 
-----------+-------+----------+---------+-------+-------------------
 postgres  | omm   | UTF8     | C       | C     | 
 template0 | omm   | UTF8     | C       | C     | =c/omm           +
           |       |          |         |       | omm=CTc/omm
 template1 | omm   | UTF8     | C       | C     | =c/omm           +
           |       |          |         |       | omm=CTc/omm
(3 rows)

openGauss=# create database chenyq;
CREATE DATABASE
openGauss=# \l
                         List of databases
   Name    | Owner | Encoding | Collate | Ctype | Access privileges 
-----------+-------+----------+---------+-------+-------------------
 chenyq    | omm   | UTF8     | C       | C     | 
 postgres  | omm   | UTF8     | C       | C     | 
 template0 | omm   | UTF8     | C       | C     | =c/omm           +
           |       |          |         |       | omm=CTc/omm
 template1 | omm   | UTF8     | C       | C     | =c/omm           +
           |       |          |         |       | omm=CTc/omm
(4 rows)

openGauss=# \c chenyq;
Non-SSL connection (SSL connection is recommended when requiring high-security)
You are now connected to database "chenyq" as user "omm".
chenyq=# create table chenyq(id int);
CREATE TABLE
chenyq=# insert into chenyq values(1);
INSERT 0 1
chenyq=# select * from chenyq;
 id 
----
  1
(1 row)

17. 实验环境清理

# 卸载数据库
[omm@opengauss ~]$ gs_uninstall --delete-data
......
Successfully uninstalled application.
Uninstallation succeeded.

# 卸载omm用户和用户组
[root@opengauss01 ~]# cd /opt/software/openGauss/script/
[root@opengauss01 script]# source /srv/BigData/OpenGauss/db1_env
[root@opengauss01 script]# ./gs_postuninstall -U omm -X /opt/software/openGauss/cluster_config.xml --delete-user --delete-group
......
Successfully deleted local node's logs.
Successfully cleaned environment.
# 成功卸载

# 删除运行环境目录
[root@opengauss ~]# rm -rf /srv/BigData/OpenGauss/ /opt/huawei/
最后修改时间:2021-12-01 15:51:30
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论