合 在CentOS7中安装openGauss数据库单机版
- 在Docker中快速体验openGauss数据库:https://www.dbaup.com/zaidockerzhongkuaisutiyanopengaussshujuku.html
在CentOS下安装openGauss
软件包下载地址:https://opengauss.org/zh/download.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | docker rm -f lhropengauss docker run -d --name lhropengauss -h lhropengauss \ -p 25432-25435:5432-5435 \ -v /sys/fs/cgroup:/sys/fs/cgroup \ --privileged=true lhrbest/lhrcentos76:8.5 \ /usr/sbin/init docker exec -it lhropengauss bash cd /soft #close selinux sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config setenforce 0 #close firewalld systemctl stop firewalld && systemctl disable firewalld cat >> /etc/rc.d/rc.local <<"EOF" if test -f /sys/kernel/mm/transparent_hugepage/enabled; then echo never > /sys/kernel/mm/transparent_hugepage/enabled fi if test -f /sys/kernel/mm/transparent_hugepage/defrag; then echo never > /sys/kernel/mm/transparent_hugepage/defrag fi EOF chmod +x /etc/rc.d/rc.local -- 创建用户和组 groupadd dbgrp useradd -g dbgrp -d /home/omm -m -s /bin/bash omm echo "lhr" | passwd --stdin omm ## 创建相关目录 mkdir /opengauss chgrp dbgrp -R /opengauss chmod 775 -R /opengauss export LD_LIBRARY_PATH=/soft/script/gspylib/clib:$LD_LIBRARY_PATH ## 解压数据库安装包(96MB) wget https://opengauss.obs.cn-south-1.myhuaweicloud.com/2.1.0/x86/openGauss-2.1.0-CentOS-64bit-all.tar.gz tar -zxvf openGauss-2.1.0-CentOS-64bit-all.tar.gz tar -zxvf openGauss-2.1.0-CentOS-64bit-om.tar.gz [root@lhropengauss soft]# ll -h total 193M -rw-r--r-- 1 root root 96M Sep 30 15:39 openGauss-2.1.0-CentOS-64bit-all.tar.gz -rw-r--r-- 1 root root 65 Sep 30 14:40 openGauss-2.1.0-CentOS-64bit-om.sha256 -rw-r--r-- 1 root root 14M Sep 30 14:40 openGauss-2.1.0-CentOS-64bit-om.tar.gz -rw-r--r-- 1 root root 65 Sep 30 14:41 openGauss-2.1.0-CentOS-64bit.sha256 -rw-r--r-- 1 root root 84M Sep 30 14:41 openGauss-2.1.0-CentOS-64bit.tar.bz2 -rw------- 1 root root 65 Sep 30 14:39 upgrade_sql.sha256 -rw------- 1 root root 220K Sep 30 14:39 upgrade_sql.tar.gz cat > /soft/clusterconfig.xml <<"EOF" <?xml version="1.0" encoding="UTF-8"?> <ROOT> <!-- openGauss整体信息 --> <CLUSTER> <!-- 数据库名称 --> <PARAM name="clusterName" value="gsCluster" /> <!-- 数据库节点名称(hostname) --> <PARAM name="nodeNames" value="lhropengauss" /> <!-- 节点后端通讯IP,与nodeNames对应 --> <PARAM name="backIp1s" value="127.0.0.1"/> <!-- 数据库安装目录 与其他路径相互独立--> <PARAM name="gaussdbAppPath" value="/opengauss/app" /> <!-- 日志目录,与其他路径相互独立,默认路径"$GAUSSLOG/安装用户名"--> <PARAM name="gaussdbLogPath" value="/opengauss/log/omm" /> <!-- 临时文件目录,默认位置在/opt/huawei/wisequery/perfadm_db--> <PARAM name="tmpMppdbPath" value="/opengauss/tmp" /> <!--数据库工具目录,与其他路径相互独立,默认路径在"/opt/huawei/wisequery"--> <PARAM name="gaussdbToolPath" value="/opengauss/om" /> <!--数据库core文件目录--> <PARAM name="corePath" value="/opengauss/corefile" /> <!-- openGauss类型,此处示例为单机类型,“single-inst”表示单机或单击主备部署形态--> <PARAM name="clusterType" value="single-inst"/> </CLUSTER> <!-- 每台服务器上的节点部署信息 --> <DEVICELIST> <!-- node1上的节点部署信息 --> <DEVICE sn="1000001"> <PARAM name="name" value="lhropengauss"/> <!-- 节点所在的AZ及AZ优先级 --> <PARAM name="azName" value="AZ1"/> <PARAM name="azPriority" value="1"/> <!-- 如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP --> <PARAM name="backIp1" value="127.0.0.1"/> <PARAM name="sshIp1" value="127.0.0.1"/> <!--dbnode--> <!--当前主机上需要部署的数据库节点个数--> <PARAM name="dataNum" value="1"/> <!--DBnode端口号--> <PARAM name="dataPortBase" value="5432"/> <!--DBnode节点数据存储目录--> <PARAM name="dataNode1" value="/opengauss/data/db1"/> </DEVICE> </DEVICELIST> </ROOT> EOF -- 执行交互式初始化(预安装) cd /soft/script python3 gs_preinstall -U omm -G dbgrp -X /soft/clusterconfig.xml -- 如果在预安装失败 就执行 gs_checkos -i A -h lhropengauss --detail 命令 查看失败原因 -- 安装opengauss su - omm gs_install -X /soft/clusterconfig.xml -- 设置密码lhr@123456 echo "export PGDATA=/opengauss/data/db1" >> /home/omm/.bashrc source /home/omm/.bashrc -- 查询状态 gs_om -t status gs_om -t status --detail gs_ctl status -D /opengauss/data/db1 -- 启动 gs_ctl start -D /opengauss/data/db1 -- 重启 gs_om -t stop && gs_om -t start -- 环境变量,会自动配置到 /home/omm/.bashrc export GPHOME=/opengauss/om export PATH=$GPHOME/script/gspylib/pssh/bin:$GPHOME/script:$PATH export LD_LIBRARY_PATH=$GPHOME/lib:$LD_LIBRARY_PATH export PYTHONPATH=$GPHOME/lib export GAUSSHOME=/opengauss/app export PATH=$GAUSSHOME/bin:$PATH export LD_LIBRARY_PATH=$GAUSSHOME/lib:$LD_LIBRARY_PATH export S3_CLIENT_CRT_FILE=$GAUSSHOME/lib/client.crt export GAUSS_VERSION=2.1.0 export PGHOST=/opengauss/tmp export GAUSSLOG=/opengauss/log/omm/omm umask 077 export GAUSS_ENV=2 export GS_CLUSTER_NAME=gsCluster # openGauss是源于PostgreSQL的数据库,默认初始化postgres数据库不变,如果当前用户不是postgres就要指定数据库名登录 gsql -d postgres create database omm; -- 去掉密码复杂度验证策略 alter system set password_policy=0; -- 使用md5和sha256,否则不能登录 alter system set password_encryption_type=1; -- 修改初始化用户的密码(若需要),openGauss 加强安全,如果需要修改初始化数据库用户的密码,需要用REPLACE哦! postgres=# ALTER ROLE gauss IDENTIFIED BY 'lhr@123456' REPLACE 'lhr@123456'; -- 配置远程登录 cat >> /opengauss/data/db1/postgresql.conf <<"EOF" listen_addresses = '*' local_bind_address = '0.0.0.0' cstore_buffers=16MB bulk_write_ring_size=128MB shared_buffers=128MB max_process_memory=2GB EOF echo "host all all 0.0.0.0/0 sha256" >> /opengauss/data/db1/pg_hba.conf -- 重启 gs_ctl restart -- 新建用户 -- 初始化数据库的用户,是不能通过IP远程连接的,所以需要创建另外一个用户才能远程连接 # 创建用户(初始化数据库的用户不能进行远程连接,需要重新创建用户) create user lhr with password 'lhr' sysadmin ; grant all PRIVILEGES to lhr; -- 验证远程登录数据库 gsql -dpostgres -h172.17.0.6 -Ulhr -r -W'lhr' -- 远程连接 gsql -d postgres -U lhr -W'lhr' -h 192.168.66.35 -p25432 -r psql -d postgres -U lhr -h 192.168.66.35 -p25432 -- 解锁用户 alter user lhr account unlock; |
安装过程:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | [root@lhropengauss script]# python3 gs_preinstall -U omm -G dbgrp -X /soft/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 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 "/soft/script/gs_checkos -i A -h lhropengauss --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. [root@lhropengauss script]# /soft/script/gs_checkos -i A -h lhropengauss --detail Checking items: A1. [ OS version status ] : Normal [lhropengauss] centos_7.6.1810_64bit A2. [ Kernel version status ] : Normal The names about all kernel versions are same. The value is "3.10.0-1127.10.1.el7.x86_64". A3. [ Unicode status ] : Normal The values of all unicode are same. The value is "LANG=en_US.UTF-8". A4. [ Time zone status ] : Normal The informations about all timezones are same. The value is "+0800". A5. [ Swap memory status ] : Normal The value about swap memory is correct. A6. [ System control parameters status ] : Normal All values about system control parameters are correct. A7. [ File system configuration status ] : Normal Both soft nofile and hard nofile are correct. A8. [ Disk configuration status ] : Normal The value about XFS mount parameters is correct. A9. [ Pre-read block size status ] : Normal The value about Logical block size is correct. A10.[ IO scheduler status ] : Normal The value of IO scheduler is correct. BondMode Null A11.[ Network card configuration status ] : Warning [lhropengauss] BondMode Null Warning reason: Failed to obtain the network card TXRX value in docker container. Commands for obtain the network card TXRX: /sbin/ethtool -g eth0 | grep 'RX:' | tail -n 2. Error: Cannot get device ring settings: Operation not supported Warning reason: Failed to obtain the network card TXRX value in docker container. Commands for obtain the network card TXRX: /sbin/ethtool -g eth0 | grep 'TX:' | tail -n 2. Error: Cannot get device ring settings: Operation not supported Warning reason: network 'eth0' 'mtu' RealValue '1500' ExpectedValue '8192' A12.[ Time consistency status ] : Normal The ntpd service is started, local time is "2022-01-06 15:52:40". A13.[ Firewall service status ] : Normal The firewall service is stopped. A14.[ THP service status ] : Normal The THP service is stopped. Total numbers:14. Abnormal numbers:0. Warning numbers:1. [root@lhropengauss script]# su - omm Last login: Thu Jan 6 15:51:34 CST 2022 on pts/0 [omm@lhropengauss data]$ gs_install -X /soft/clusterconfig.xml 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: Please repeat for database: begin to create CA cert files The sslcert will be generated in /opengauss/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.. [omm@lhropengauss data]$ gs_ctl status [2022-01-06 16:26:56.451][12455][][gs_ctl]: gs_ctl status,datadir is /opengauss/data/db1 gs_ctl: server is running (PID: 11524) /opengauss/app/bin/gaussdb "-D" "/opengauss/data/db1" [omm@lhropengauss ~]$ gs_om -t status ----------------------------------------------------------------------- cluster_name : gsCluster cluster_state : Normal redistributing : No ----------------------------------------------------------------------- [omm@lhropengauss ~]$ gs_ctl status [2022-01-06 16:55:27.824][21116][][gs_ctl]: gs_ctl status,datadir is /opengauss/data/db1 gs_ctl: server is running (PID: 20111) /opengauss/app/bin/gaussdb "-D" "/opengauss/data/db1" [omm@lhropengauss db1]$ 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 lhropengauss 127.0.0.1 5432 6001 /opengauss/data/db1 P Primary Normal [omm@lhropengauss ~]$ gsql -d postgres 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=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+-------+-----------+---------+-------+------------------- postgres | omm | SQL_ASCII | C | C | template0 | omm | SQL_ASCII | C | C | =c/omm + | | | | | omm=CTc/omm template1 | omm | SQL_ASCII | C | C | =c/omm + | | | | | omm=CTc/omm (3 rows) openGauss=# create database omm; CREATE DATABASE openGauss=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+-------+-----------+---------+-------+------------------- omm | omm | SQL_ASCII | C | C | postgres | omm | SQL_ASCII | C | C | template0 | omm | SQL_ASCII | C | C | =c/omm + | | | | | omm=CTc/omm template1 | omm | SQL_ASCII | C | C | =c/omm + | | | | | omm=CTc/omm (4 rows) C:\Users\lhrxxt>psql -d postgres -U lhr -h 192.168.66.35 -p25432 Password for user lhr: psql (14.0, server 9.2.4) SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off) Type "help" for help. postgres=> \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+-------+-----------+---------+-------+------------------- omm | omm | SQL_ASCII | C | C | postgres | omm | SQL_ASCII | C | C | template0 | omm | SQL_ASCII | C | C | =c/omm + | | | | | omm=CTc/omm template1 | omm | SQL_ASCII | C | C | =c/omm + | | | | | omm=CTc/omm (4 rows) |
gsql客户端安装
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | mkdir /usr/local/gsql_client cd /usr/local/gsql_client wget https://obs.myhuaweicloud.com/dws/download/dws_client_8.1.x_redhat_x64.zip --no-check-certificate unzip dws_client_8.1.x_redhat_x64.zip source gsql_env.sh cat >> ~/.bashrc <<"EOF" export PATH=/usr/local/gsql_client/bin:$PATH export LD_LIBRARY_PATH=/usr/local/gsql_client/lib:$LD_LIBRARY_PATH EOF source ~/.bashrc gsql -d postgres -U gaussdb -W'lhr@123XXT' -h 192.168.66.35 -p15432 -r -- 用psql也可以登陆 psql -d postgres -U gaussdb -h 192.168.66.35 -p15432 |
注意:psql和gsql的lib库不兼容,参考:https://www.dbaup.com/guzhangchulipsqlkehuduanlianjiepgbaocuopsql-error-expected-authentication-request-from-serv.html
若只是客户端,则建议如下配置:
1 2 3 4 5 6 7 | cat > ~/.gsql_env <<"EOF" export LD_LIBRARY_PATH=/usr/local/gsql_client/lib export PATH=/usr/local/gsql_client/bin:$PATH EOF source ~/.gsql_env |
使用:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | [root@docker35 ~]# export LD_LIBRARY_PATH=/usr/local/gsql_client/lib [root@docker35 ~]# export PATH=/usr/local/gsql_client/bin:$PATH [root@docker35 ~]# gsql -d postgres -U gaussdb -W'lhr@123XXT' -h 192.168.66.35 -p15432 -r gsql ((GaussDB 8.1.0 build be03b9a0) compiled at 2021-03-12 14:18:02 commit 1237 last mr 2001 release) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. postgres=> \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+-------+----------+-------------+-------------+------------------- omm | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 | postgres | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 | template0 | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/omm + | | | | | omm=CTc/omm template1 | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/omm + | | | | | omm=CTc/omm (4 rows) postgres=> |
html巡检
巡检可以参考:https://www.dbaup.com/opengaussshujukuxunjianjiaoben.html
卸载openGauss工具之gs_uninstall
openGauss提供了gs_uninstall工具来帮助完成openGauss的卸载。
语法
卸载openGauss
1gs_uninstall [--delete-data] [-L] [-l LOGFILE]显示帮助信息
1gs_uninstall -? | --help显示版本号信息
本人提供Oracle(OCP、OCM)、MySQL(OCP)、PostgreSQL(PGCA、PGCE、PGCM)等数据库的培训和考证业务,私聊QQ646634621或微信dbaup66,谢谢!