admin管理员组

文章数量:1569958

前言

        结合老师资料和CSDN摸索出来的安装教程,安装是成功的,后续数据使用也没问题。废话不多说。使用的虚拟机软件是VirtualBox 6.1,通信工具是putty,操作系统是Centos7.6,可视化文件传输软件WinScp,openGauss数据库2.1.0。

一、虚拟机配置

1.Centos光盘文件下载

        由于外网下载过慢,可以通过镜像下载。之前使用的阿里云,不知道为啥不可以了。(55条消息) CentOS7.6(1810)下载地址(2020.8.11)_InceZangwill的博客-CSDN博客

CentOS-7-x86_64-DVD-1810.iso 标准安装版7.6,一般下载这个就可以了(推荐),因为其他版本,不确定有没有安装需要的工具而且也不知道是否支持openGauss,特别是最小化安装,安装过程还需要下载其他的包,新手不推荐。

2.虚拟机软件安装

        使用VirtualBox软件,为了防止不兼容使用旧版本,使用6.1版本。下载地址: Download_Old_Builds_6_1 – Oracle VM VirtualBox

选择Window host 版本下载。

安装参考链接:超级详细的 VirtualBox 虚拟机安装 及入门教程_virtualbox安装_IT小郭.的博客-CSDN博客

3.创建虚拟机

1)新建虚拟机
打开 VirtualBox > 新建 自己为虚拟电脑取个名字,选择 Other Linux(64-bit),然后点击下一步。

这里大小建议在可接受程度,加大点,不建议太小,应该20--40G?

 2)在新建的虚拟机上为安装 CentOS 7.6 设置

这里选择虚拟盘,找到你下载的centos光盘文件,即iso文件 ,完成后点ok

继续设置启动顺序,将光驱启动设置为第一项

 接下来设置网卡,因为只需要满足学习使用即可,只用创建一个网卡,选择“桥接网卡”模式,其中原理搜一搜即可。

 3)开始安装

使用方向键,选择第一个 Install 开始安装

 选择使用的语言

 这里安装位置,使用默认的配置就好

 

 设置网络和主机名,输入自己想要的主机名字后,记得点击“应用”,再打开,然后点击 完成

接下来设置“软件选择“,为了避免工具遗漏,我们选择”GNOME桌面:版,安装,勾选“开发工具、安全性工具、系统管理工具”,不推荐最小安装。点击完成

点击“开始安装”后,会提醒你没有设置管理员密码,点击“ROOT密码”,设置你想要的密码,但你要记住,后续要用到,我这里使用123456,因为太简单要点击两次完成进行确定。

 然后等待安装,安装完成后点击“重启”

再同意许可协议

 

 

 这里看大家的喽,大家应该都是科学上网的优秀青年(狗头保命)

时区随意,

感觉不重要,跳过

设置你虚拟机的用户名

设置虚拟机用户的密码,这里我用了openGauss

 

现在就是虚拟机的友好桌面了

二、Centos 7.6 上安装 openGauss2.1.0

虚拟机登录桌面账号:xuanhuo16         openGauss

1.图形界面->命令行

在图形界面任何界面按 ctrl+alt+f3 ,这时就会切换到命令行界面;

1)登录root账号,注意输入数字时,小键盘无法使用

 看到下图这样,就是登录成功了

 2.设置静态ip

1)查看电脑的ip信息

window键+R  打开运行命令框,再输入cmd,调出命令行

输入命令 ipconfig ,查看ip相关信息

 找到下列信息,因为我用的wifi,建议再使用自己的热点的前提下查看,后期的操作,都需要你的实际电脑连在同一个wifi下,先不要关闭

 2)在虚拟机中输入命令
  • cd /etc/sysconfig/network-scripts/                进入目录

  • ls                     查看当前目录文件,找到对应的网卡文件,我这里是ifcf-enp0s3

注意命令格式

 注意在这个network-scripts下,输入命令 

  • vim ifcfg-enp0s3              编辑命令

参照你电脑的ip信息进行编辑

  • BOOTPROTO=static
  • IPADDR=值,你电脑ipv4的地址,没占用的,就是值+1,+……,不要大于255
  • GATEWAY,NETMASK的值,和你的电脑的一样
  • DNS1=114.114.114.114                  和我一样就好,我也是"偷"的,可尝试其他的
  • ONBOOT=yes             设置开机自启动
  • 对了,修改的操作:按‘i’键,进入编辑模式,修改完后按‘esc’退出编辑模式,按住shift键,冒号+w+q!强制保存

 

 保存后,重启网卡

  • service network restart
  • ping baidu                        测试是否连通,若出现64 bytes字样即通,通过  ctrl+c 结束通信

到这里静态ip设置完成

参照链接: Virtualbox虚拟机桥接模式配置_linux_即将头秃的程序媛-华为云开发者联盟 (csdn)

支持!

3.使用SSH通信工具putty继续安装

putty的安装和使用参考:putty安装和使用_你好世界wxx的博客-CSDN博客

1)打开putty,输入虚拟机ip地址,结点名字,我这里使用openGauss1,点击 "save",保存结点,下次可快速打开,但要注意你实际电脑的wifi是否与你设置虚拟ip是网络一致。
使用 putty 连接,进行后续 openGauss 的安装设置等工作。使用 putty 的好处就是可以直接复制粘贴命令了,复制后单击鼠标右键即可粘贴。

 

 打开后,点击 Accept,接受密钥啥的

2)登录
输入用户名为 root,密码为 123456,注意密码输入的时候,是看不到的 确认用户名和密码输入后,按回车键即可。

 3)继续安装
3-1 关闭防火墙

 下面只用复制粘贴绿色的文字到 putty 上执行,后面也是如此,不再赘述。

[root@opengauss ~]# systemctl stop firewalld.service [root@opengauss ~]# systemctl disable firewalld.service Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service
3-2 设置字符集及环境变量

注意EOF是结束写入的命令,前面不要加空格,否则将把EOF写入文件,是否写错可以进入对应的文件查看 cd /etc/profile/   再 vim 文件

[root@opengauss ~]# cat >>/etc/profile<<EOF > export LANG=en_US.UTF‐8 > EOF [root@opengauss ~]# cat >>/etc/profile<<EOF > export packagePath=/opt/software/openGauss > EOF [root@opengauss ~]# source /etc/profile [root@opengauss ~]# cat >>/etc/profile<<EOF > export LD_LIBRARY_PATH=$packagePath/script/gspylib/clib:$LD_LIBRARY_PATH > EOF [root@opengauss ~]# source /etc/profile 验证是否生效 [root@opengauss ~]# echo $LD_LIBRARY_PATH 输出  /opt/software/openGauss/script/gspylib/clib:
3-3 关闭 swap 交换内存

[root@opengauss ~]# swapoff -a

3-4 准备 yum 环境
备份原有的 yum 配置文件,注意空格和间隔,回车 [root@opengauss ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak                     格式: mv 操作数 操作数 下载可用源的 repo 文件 [root@opengauss ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun/repo/Centos-7.repo           格式:curl  -o 操作数 操作数 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 2523 100 2523 0 0 13867 0 --:--:-- --:--:-- --:- -:-- 13939 查看 repo 文件内容是否正确,一般没啥问题 [root@opengauss ~]# cat /etc/yum.repos.d/CentOS-Base.repo # CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base] name=CentOS-$releasever - Base - mirrors.aliyun failovermethod=priority baseurl=http://mirrors.aliyun/centos/$releasever/os/$basearch/ http://mirrors.aliyuncs/centos/$releasever/os/$basearch/ http://mirrors.cloud.aliyuncs/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun/centos/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-$releasever - Updates - mirrors.aliyun failovermethod=priority baseurl=http://mirrors.aliyun/centos/$releasever/updates/$basearc h/ http://mirrors.aliyuncs/centos/$releasever/updates/$basearch/ http://mirrors.cloud.aliyuncs/centos/$releasever/updates/$basearc h/ gpgcheck=1 gpgkey=http://mirrors.aliyun/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras - mirrors.aliyun failovermethod=priority baseurl=http://mirrors.aliyun/centos/$releasever/extras/$basearch / http://mirrors.aliyuncs/centos/$releasever/extras/$basearch/ http://mirrors.cloud.aliyuncs/centos/$releasever/extras/$basearch / gpgcheck=1 gpgkey=http://mirrors.aliyun/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus - mirrors.aliyun failovermethod=priority baseurl=http://mirrors.aliyun/centos/$releasever/centosplus/$base arch/ http://mirrors.aliyuncs/centos/$releasever/centosplus/$basearch/ http://mirrors.cloud.aliyuncs/centos/$releasever/centosplus/$base arch/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.aliyun/centos/RPM-GPG-KEY-CentOS-7 #contrib - packages by Centos Users [contrib] name=CentOS-$releasever - Contrib - mirrors.aliyun failovermethod=priority baseurl=http://mirrors.aliyun/centos/$releasever/contrib/$basearc h/ http://mirrors.aliyuncs/centos/$releasever/contrib/$basearch/ http://mirrors.cloud.aliyuncs/centos/$releasever/contrib/$basearc h/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.aliyun/centos/RPM-GPG-KEY-CentOS-7
3-5  yum 安装相关包
执行以下命令,安装所需的包。 [root@opengauss ~]# yum install -y libaio-devel flex bison ncurses-devel glibc.devel patch lsb_release wget python3 Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun * extras: mirrors.aliyun * updates: mirrors.aliyun 。。。。。。。。。。。 需要安装一段时间,安装成功后会显示 complete!
3-6 设置默认 Python 版本为 3.x
[root@opengauss ~]# cd /usr/bin [root@opengauss bin]# mv python python.bak [root@opengauss bin]# ln -s python3 /usr/bin/python [root@opengauss bin]# python -V Python 3.6.8 用 yum --help 命令来验证 yum 是否能使用,对了使用上下键可以查看使用过的命令 [root@opengauss bin]# yum --help File "/usr/bin/yum", line 30 except KeyboardInterrupt, e: ^ SyntaxError: invalid syntax 发现不可用 不能使用需要修改/usr/bin/yum 文件,把#!/usr/bin/python 这行修改为 #!/usr/bin/python2.7(或者对应的 python 2.x 的版本)。输入"i"切换到编 辑模式,移动鼠标到修改位置修改内容,然后按下 ESC 键退出编辑模式,然后 输入":wq"退出并进行保存。如果不修改,则输入:q! [root@opengauss bin]# vi /usr/bin/yum 打开文档,将下面用黄色标亮的文字修改一下 [root@opengauss bin]# vi /usr/bin/yum #!/usr/bin/python import sys try: import yum 按键盘上的 i,就可以修改,修改为 #!/usr/bin/python2.7 修改后,保存退出,先按键盘上的 esc 键退出编辑模式,然后输入:wq!进行保 再次用 yum --help 命令来验证 yum 是否能使用 [root@opengauss bin]# yum --help Loaded plugins: fastestmirror Usage: yum [options] COMMAND List of Commands: 。。。。。。。。。。。。。。。。。。 经过测试,这次 ok
3-7  创建存放数据库的安装目录
[root@opengauss bin]# mkdir -p /opt/software/openGauss [root@opengauss bin]# cd /opt/software/openGauss [root@opengauss openGauss]#
3-8  创建 XML 配置文件,用于数据库安装
[root@opengauss openGauss]# vi clusterconfig.xml 将以下内容添加进 clusterconfig.xml 文件中。输入"i"切换到编辑模式,复 制内容粘贴到文档中,然后按下 ESC 键退出编辑模式,然后输入":wq"退出并 进行保存。 下面的文档中黄色标出的地方,需要根据 centos 安装时的主机名和 ip 地址进 行设置。 <?xml version="1.0" encoding="UTF-8"?> <ROOT> <!-- openGauss 整体信息 --> <CLUSTER> <PARAM name="clusterName" value="dbCluster" /> <PARAM name="nodeNames" value=" opengauss " /> <PARAM name="backIp1s" value=" 192.168.1.7 "/> <PARAM name="gaussdbAppPath" value="/opt/gaussdb/app" /> <PARAM name="gaussdbLogPath" value="/var/log/gaussdb" /> <PARAM name="gaussdbToolPath" value="/opt/huawei/wisequery" /> <PARAM name="corePath" value="/opt/opengauss/corefile"/> <PARAM name="clusterType" value="single-inst"/> </CLUSTER> <!-- 每台服务器上的节点部署信息 --> <DEVICELIST> <!-- node1 上的节点部署信息 --> <DEVICE sn="1000001"> <PARAM name="name" value=" opengauss "/> <PARAM name="azName" value="AZ1"/> <PARAM name="azPriority" value="1"/>  <!-- 如果服务器只有一个网卡可用,将 backIP1 和 sshIP1 配置 成同一个 IP --> <PARAM name="backIp1" value=" 192.168.1.7 "/> <PARAM name="sshIp1" value=" 192.168.1.7 "/> <!--dbnode--> <PARAM name="dataNum" value="1"/> <PARAM name="dataPortBase" value="26000"/> <PARAM name="dataNode1" value=" /gaussdb/data/opengauss "/> </DEVICE> </DEVICELIST> </ROOT>
3-8  使用putty将安装包解压至存放目录

使用 openGauss-2.1.0-CentOS-64bit-all.tar.gz,已经提前下载 使用 winSCP 连接服务器,上传该安装包 winscp的安装参考:  WinSCP软件安装教程_winscp安装 invalid character in path_Xavier Jiezou的博客-CSDN博客 安装包 下载地址:软件包 | openGauss     选择2.01企业版

打开winscp软件,创立通信,安装参考: WinSCP软件安装教程_winscp安装 invalid character in path_Xavier Jiezou的博客-CSDN博客 这里主机名是安装 centos 时的。用户名为 root,密码是 openGauss,设置后, 点击登录

登录后,在左边选择自己电脑中存放安装包的位置 ,右边就是服务器中,要上传安装包的位置

找到你下载openGauss-2.1.0-CentOS-64bit-all.tar.gz的路径

在右侧虚拟机目录找到 /opt/software/openGauss/,这是之前3-7创的

 

在左侧的压缩包中点击右键,在出现的菜单中选择上传 

 

 上传成功

 3-9 将下载好的安装包解压至存放目录
先解压 openGauss-2.1.0-CentOS-64bit-all.tar.gz 包。注意命令是在openGauss目录下输入的 [root@opengauss openGauss]# tar -zxvf openGauss-2.1.0-CentOS-64bit-all.tar.gz openGauss-2.1.0-CentOS-64bit-om.tar.gz openGauss-2.1.0-CentOS-64bit.tar.bz2 openGauss-2.1.0-CentOS-64bit-om.sha256 openGauss-2.1.0-CentOS-64bit.sha256 upgrade_sql.tar.gz upgrade_sql.sha256 再解压 openGauss-2.1.0-CentOS-64bit-om.tar.gz [root@opengauss openGauss]# tar -zxvf openGauss-2.1.0-CentOS-64bit-om.tar.gz ./lib/ ./lib/pyasn1/ ./lib/pyasn1/codec/ ./lib/pyasn1/codec/cer/ 。。。。。。。。。。。。 解压后如下,用 ls 命令查看如下: [root@opengauss openGauss]# ls clusterconfig.xml openGauss-2.1.0-CentOS- 64bit-om.tar.gz simpleInstall lib openGauss-2.1.0-CentOS- 64bit.sha256 upgrade_sql.sha256 openGauss-2.1.0-CentOS-64bit-all.tar.gz openGauss-2.1.0-CentOS- 64bit.tar.bz2 upgrade_sql.tar.gz openGauss-2.1.0-CentOS-64bit-om.sha256 script version.cfg 安装包解压后,会在/opt/software/openGauss 路径下自动生成 script 子目 录,并且在 script 目录下生成 gs_preinstall 等各种 OM 工具脚本。 这些是我们后续安装需要使用的。 更改权限。 [root@opengauss openGauss]# chmod 755 -R /opt/software
3-10 执行初始化脚本

[root@opengauss openGauss]# cd script

[root@opengauss script]#   python gs_preinstall -U omm -G dbgrp -X /opt/software/openGauss/clusterconfig.xml

没有错误跳过即可 [GAUSS-50217] : Failed to decompress version.cfg.The cmd is cd /opt/software/openGauss/script/../ && tar -xpf `head -1 version. cfg`*.tar.bz2 ./version.cfg. The output is tar (child): lbzip2: Cannot exec: No such file or directory tar (child): Error is not recoverable: exiting now tar: Child returned status 2 tar: Error is not recoverable: exiting now. 出现错误,因为少解压软件,安装。。 [root@opengauss script]# yum install bzip2 报错,无法安装 Downloading packages: File "/usr/libexec/urlgrabber-ext-down", line 28 except OSError, e: ^ SyntaxError: invalid syntax 从网上查找解决方案 [root@opengauss script]# vi /usr/libexec/urlgrabber-ext-down 将第一行"#!/usr/bin/python" 改为 " #!/usr/bin/python2.7 "即可。 修改后,重新安装 [root@opengauss script]# yum install bzip2 这次安装成功! 继续执行初始化脚本

[root@opengauss script]# python gs_preinstall -U omm -G dbgrp -X /opt/software/openGauss/clusterconfig.xml Parsing the configuration file. Successfully parsed the configuration file. Installing the tools on the local node. Successfully installed the tools on the local node. Setting pssh path Successfully set core path. 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:这里输入密码为 openGauss@123,但是输入的时候是看不到的 Please enter password for cluster user again. Password: 这里输入密码为 openGauss@123,但是输入的时候是看不到的 Successfully created [omm] user on all nodes. Preparing SSH service. Successfully prepared SSH service. Checking OS software. Successfully check os software. Checking OS version. Successfully checked OS version. Creating cluster's path. Successfully created cluster's path. Set and check OS parameter. Setting OS parameters. Successfully set OS parameters. Warning: Installation environment contains some warning messages. Please get more details by "/opt/software/openGauss/script/gs_checkos -i A -h opengauss --detail". Set and check OS parameter completed. Preparing CRON service. Successfully prepared CRON service. Setting user environmental variables. Successfully set user environmental variables. Setting the dynamic link library. Successfully set the dynamic link library. Setting Core file Successfully set core path. Setting pssh path Successfully set pssh path. Setting Cgroup. Successfully set Cgroup. Set ARM Optimization. No need to set ARM Optimization. Fixing server package owner. Setting finish flag. Successfully set finish flag. Preinstallation succeeded. 初始化安装成功!
3-11 初始化数据库
用 init 6 重启下虚拟机(主要是为了释放一些内存资源)。 [root@opengauss script]# init 6 等虚拟机重启后,再重新打开 putty 连接 输入用户名 root,密码 openGauss 先更新下权限。 [root@opengauss ~]# chmod 755 -R /opt/software 使用 omm 用户进行数据库初始化。 [root@opengauss ~]# su - omm Last login: Sun Mar 27 01:07:53 CST 2022 on pts/0 [omm@opengauss ~]$ cd /opt/software/openGauss/script [omm@opengauss script]$ gs_install -X /opt/software/openGauss/clusterconfig.xml --gsinit- parameter="--encoding=UTF8" --dn-guc="max_process_memory=4GB" --dn-guc="shared_buffers=128MB" --dn-guc="bulk_write_ring_size=128MB" --dn-guc="cstore_ buffers=16MB" 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: 这里输入密码为 openGauss@123,但 输入时看不到 Please repeat for database: 这里输入密码为 openGauss@123,但是输入的 时候是看不到的 begin to create CA cert files The sslcert will be generated in /opt/gaussdb/app/share/sslcert/om 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.. 安装成功!
3-12 测试!!

终于到这一步了,终于等到你~~~~

使用普通用户登录

[omm@opengauss script]$ su - omm Password: 这里输入密码为 openGauss@123 Last login: Sun Mar 27 01:20:15 CST 2022 on pts/0 [omm@opengauss ~]$ gs_om -t start Starting cluster. ========================================= [SUCCESS] opengauss: [2022-03-27 01:26:42.531][6742][][gs_ctl]: gs_ctl started,datadir is /gaussdb/data/opengauss [2022-03-27 01:26:42.537][6742][][gs_ctl]: another server might be running; Please use the restart command ========================================= Successfully started. [omm@opengauss ~]$ gsql -d postgres -p 26000 -r gsql ((openGauss 2.1.0 build 590b0f8e) compiled at 2021-09-30 14:29:04 commit 0 last mr ) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. openGauss=# 成功!!! 千辛万苦

三、使用SQL语句测试

sql语句参考链接:openGauss数据库基本操作(超详细)_hlsongsong的博客-CSDN博客

1.创建数据库用户

create user joe password "Huawei_123";

2.创建数据库,并指定所有者owner

create database joe_db owner joe;

3. 切换到joe_db数据库


openGauss=# \c joe_db


4. 切换到joe用户


joe_db=# \c - joe
Password for user joe:  Huawei_123

 

5. 为用户joe创建一个模式joe1


create schema 模式名 authorization 用户名;
create schema joe1 authorization joe;
joe_db=> create schema joe1 authorization joe;

6. 创建表

CREATE TABLE teacher (
tno VARCHAR(20) NOT NULL PRIMARY KEY,
name VARCHAR(15) NOT NULL,
gender CHAR(3),
email VARCHAR(50) NOT NULL,
address VARCHAR(100) NOT NULL
);

7.报错

普通用户创建数据库时报错:ERROR: permission denied to create database
登陆超级用户omm进入数据库,进行授权

GRANT ALL PRIVILEGES TO 新用户;

\q         退出数据库

su - omm         omm登录

gs_om -t start

gsql -d postgres -p 26000 -r

GRANT ALL PRIVILEGES TO joe;

 继续刚才的,切换数据库joe_db,用户joe,继续创建表,不用再创模式了

参考原文链接:opengauss(postgresql)创建用户等基本命令_opengauss创建用户_vv_a的博客-CSDN博客

 8.往teacher表插入数据记录

INSERT INTO teacher VALUES ('21003','花花','男','123@qq','上海天龙人');

 9.插入成功,查看表中数据

select * from teacher;

总结

        恭喜你走到最后,it的勇士!这些都是我以学校老师提供的资料为主体,参考网上资料摸索出来的,当初折磨了两三个星期,最后发现可以直接从实验室拷贝一份老师已经安装好的(但是账号是老师设置的,网卡和ip还要自己设置)。过程是曲折的,关于Linux操作系统、openGauss数据库才刚刚开始学习,很多东西都是先学先卖,还有很多的要学,若在安装过程遇到任何问题,请尽情百度,或者为什么不问问“万能的”GPT呢?第一次写博客,希望这篇文章给你带来帮助。

本文标签: openGauss