部署openGauss向量数据库(机密虚拟机)
本章节部署使用的硬件服务器需搭载鲲鹏920新型号处理器。请参见《鲲鹏BoostKit机密计算 机密虚拟机与机密容器 特性指南》获取License使能TEE,参照软件编译、软件部署安装章节完成机密计算软件环境部署,根据实际需要配置机密虚拟机内存、CPU等规格参数,完成机密虚拟机创建。按如下步骤进入机密虚拟机进行向量数据库部署。
启动机密虚拟机
安装openGauss数据库
- 创建用户组和用户,当前指定用户名为omm,指定用户密码Dify@123。
groupadd omm useradd -g omm -m -s /bin/bash omm passwd omm(回车后键入用户密码)
- 修改root用户下单个进程的上限。
ulimit -n 1000000
- 修改新用户omm的软限制和硬限制。
- 编辑limits.conf文件。
vi /etc/security/limits.conf
- 在文件结尾处添加以下两行内容。
omm hard nofile 1000000 omm soft nproc 1000000
- 按“Esc”键,输入:wq!,按“Enter”保存并退出编辑。
- 编辑limits.conf文件。
- 切换到新创建的用户下。
su - omm
- 获取openGauss安装包,请根据实际情况选择对应平台的极简版安装包。
wget https://opengauss.obs.cn-south-1.myhuaweicloud.com/7.0.0-RC2/openEuler24.03/arm/openGauss-Server-7.0.0-RC2-openEuler24.03-aarch64.tar.bz2
- 解压openGauss压缩包到安装目录,假定安装目录为“/opt/software/openGauss”,请用实际值替换。
tar -jxf openGauss-Server-x.x.x-openEuler24.03-aarch64.tar.bz2 -C /opt/software/openGauss
- 进入解压后目录下的“simpleInstall”。
cd /opt/software/openGauss/simpleInstall
- 执行install.sh脚本安装openGauss。当前指定数据库密码为Dify@123,指定端口号为8888。
sh install.sh -w "Dify@123" -p 8888 &&source ~/.bashrc
- 安装后,该数据库部署节点的名称为sgnode(gs_initdb指定)。
- 执行时,如果出现报错“the maximum number of SEMMNI is not correct, the current SEMMNI is xxx. Please check it.”,请使用有root权限的用户执行如下命令。
sysctl -w kernel.sem="250 85000 250 330"
- 安装后,数据库目录安装路径“/opt/software/openGauss/data/single_node”,其中“/opt/software/openGauss”为解压包路径,“data/single_node”为新创建的数据库节点目录。
- 安装完成后,默认生成名称为postgres的数据库。第一次连接数据库时可以连接到此数据库。
- -w:初始化数据库密码(gs_initdb指定),因安全需要,此项必须设置。
- -p:指定openGauss端口号,如不指定,默认为5432。
- -h|--help:打印使用说明。
- 安装执行完成后,使用ps和gs_ctl查看进程是否正常。
ps ux | grep gaussdb gs_ctl query -D /opt/software/openGauss/data/single_node
执行ps命令,显示类似如下信息。omm 24209 11.9 1.0 1852000 355816 pts/0 Sl 01:54 0:33 /opt/software/openGauss/bin/gaussdb -D /opt/software/openGauss/data/single_node omm 20377 0.0 0.0 119880 1216 pts/0 S+ 15:37 0:00 grep --color=auto gaussdb
执行gs_ctl命令,显示类似如下信息。gs_ctl query ,datadir is /opt/software/openGauss/data/single_node HA state: local_role : Normal static_connections : 0 db_state : Normal detail_information : Normal Senders info: No information Receiver info: No information
远程连接机密虚拟机内的数据库
远程连接机密虚拟机内的数据库,需要修改数据库的postgresql.conf和pg_hba.conf配置文件,以下操作均在创建的omm用户下进行。
- 编辑postgresql.conf配置文件。该文件路径为ps ux命令回显的-D之后的路径加配置文件名。
ps ux vim /opt/software/openGauss/data/single_node/postgresql.conf
- 按“i”进入编辑模式,修改如下内容。
listen_addresses为listen_addresses = '*' local_bind_address为local_bind_address = '0.0.0.0' password_encryption_type为password_encryption_type = 1
- 按“Esc”键,输入:wq!,按“Enter”保存并退出编辑。
- 编辑pg_hba.conf配置文件。该文件路径为ps ux命令回显的-D之后的路径加配置文件名。
ps ux vim /opt/software/openGauss/single_node/pg_hba.conf
- 按“i”进入编辑模式,在# IPv4 local connections:部分里新增如下内容。
host all all 0.0.0.0/0 md5
- 按“Esc”键,输入:wq!,按“Enter”保存并退出编辑。
- 重启数据库以使修改生效。
gs_ctl restart -D /opt/software/openGauss/data/single_node
- 连接数据库。
gsql -d postgres -p 8888 -r
- 创建数据库用户gaussdb及密码'Dify@123'(用于远程连接数据库)。
create user gaussdb with password 'Dify@123' sysadmin;
执行后显示如下信息:
NOTICE: The encrypted password contains MD5 ciphertext, which is not secure. CREATE ROLE
随后便可以在宿主机远程连进数据库,下图为使用Python测试结果。
下图是Python的脚本(这里测试使用的用户为test):

下图为运行结果:

下载并且安装加速包
远程连接机密虚拟机下载并且安装加速包,其中安装加速包需要以root权限安装。
- 从鲲鹏社区获取检索加速包,上传到服务器并解压。
unzip BoostKit-SRA_Recall-1.1.0.zip
- 安装加速包。
rpm -ivh boostkit-sra_recall-1.1.0-1.aarch64.rpm
执行后显示如下信息:

- 修改omm用户环境变量,添加DATAVEC_PQ_LIB_PATH环境变量。
su omm vim ~/.bashrc
- 按“i”进入编辑模式,添加如下内容。
DATAVEC_PQ_LIB_PATH=/usr/local/sra_recall/lib

- 按“Esc”键,输入:wq!,按“Enter”保存并退出编辑。
- 使配置生效。
source ~/.bashrc
- 编辑postgresql.conf文件。该文件路径为ps_ux命令回显的“-D”之后的路径加该配置文件名。
ps ux vim /opt/software/openGauss/data/single_node/postgresql.conf
- 按“i”进入编辑模式,添加如下内容。
enable_pq = on

- 按“Esc”键,输入:wq!,按“Enter”保存并退出编辑。
- 重启以使修改生效。
gs_ctl restart -D /opt/software/openGauss/data/single_node
- 重启完成后可以连接数据库。
gsql -d postgres -p 8888 -r
- 执行以下语句测试配置是否生效。
drop table if exists t; CREATE TABLE t (val vector(3)); INSERT INTO t (val) VALUES ('[0,0,0]'), ('[1,2,3]'), ('[1,1,1]'), (NULL); CREATE INDEX ON t USING hnsw (val vector_l2_ops) with (enable_pq = on, pq_m=1, pq_ksub=256); INSERT INTO t (val) VALUES ('[1,2,4]'); SELECT * FROM t ORDER BY val <-> '[3,3,3]';显示如下结果:

父主题: 方案部署指南