合 安装openGauss极简版单节点和一主一备节点环境
Tags: 高可用单机openGauss一主一备单节点极简版
在Docker中快速体验openGauss数据库:https://www.dbaup.com/zaidockerzhongkuaisutiyanopengaussshujuku.html
在CentOS7中安装openGauss数据库单机版:https://www.dbaup.com/zaicentos7zhonganzhuangopengaussshujukudanjiban.html
PG12高可用之1主2从流复制环境搭建及切换测试:https://www.dbaup.com/dbbao60pg12gaokeyongzhi1zhu2congliufuzhihuanjingdajianjiqiehuanceshi.html
参考:https://opengauss.org/zh/docs/2.1.0/docs/Quickstart/Quickstart.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 | docker rm -f lhropengausssimple docker run -d --name lhropengausssimple -h lhropengausssimple \ -p 35432-35439:5432-5439 -p 35632-35639:5632-5639 \ -v /sys/fs/cgroup:/sys/fs/cgroup \ --privileged=true lhrbest/lhrcentos76:8.5 \ /usr/sbin/init docker exec -it lhropengausssimple 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 echo 'export LANG=en_US.UTF-8' >> /etc/profile cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime sysctl -w kernel.sem="250 85000 250 330" -- 创建用户和组 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 ## 解压数据库安装包,85Mb wget https://opengauss.obs.cn-south-1.myhuaweicloud.com/2.1.0/x86/openGauss-2.1.0-CentOS-64bit.tar.bz2 tar -jxf openGauss-2.1.0-CentOS-64bit.tar.bz2 -C /opengauss chown -R omm:dbgrp /opengauss -- 单节点安装 su - omm cd /opengauss/simpleInstall sh install.sh -w lhr@123XXT -- 启动停止 gs_ctl start|stop|restart -D $GAUSSHOME/data/single_node -Z single_node gs_ctl status -D $GAUSSHOME/data/single_node -- 连接,-r表示可以使用上下左右键 gsql -d postgres -r # 环境变量,会自动写入 /home/omm/.bashrc export GAUSSHOME=/opengauss export PATH=$GAUSSHOME/bin:$PATH export LD_LIBRARY_PATH=$GAUSSHOME/lib:$LD_LIBRARY_PATH export GS_CLUSTER_NAME=dbCluster ulimit -n 1000000 # 环境变量 echo "export PGDATA=$GAUSSHOME/data/single_node" >> /home/omm/.bashrc source /home/omm/.bashrc -- 配置远程访问 create database omm; alter system set password_policy=0; alter system set password_encryption_type=1; alter system set listen_addresses = '*'; echo "host all all 0.0.0.0/0 sha256" >> /opengauss/data/single_node/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 -p35432 -r psql -d postgres -U lhr -h 192.168.66.35 -p35432 -- 解锁用户 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 195 196 197 198 199 200 201 202 203 | [omm@lhropengausssimple bin]$ /opengauss/bin/gaussdb -V gaussdb (openGauss 2.1.0 build 590b0f8e) compiled at 2021-09-30 14:29:04 commit 0 last mr [omm@lhropengausssimple bin]$ [omm@lhropengausssimple bin]$ cd /opengauss/simpleInstall [omm@lhropengausssimple simpleInstall]$ sh install.sh -w lhr@123XXT [step 1]: check parameter [step 2]: check install env and os setting [step 3]: change_gausshome_owner [step 4]: set environment variables [step 6]: init datanode The files belonging to this database system will be owned by user "omm". This user must also own the server process. The database cluster will be initialized with locale "en_US.UTF-8". The default database encoding has accordingly been set to "UTF8". The default text search configuration will be set to "english". creating directory /opengauss/data/single_node ... ok creating subdirectories ... ok selecting default max_connections ... 100 selecting default shared_buffers ... 32MB creating configuration files ... ok Begin init undo subsystem meta. [INIT UNDO] Init undo subsystem meta successfully. creating template1 database in /opengauss/data/single_node/base/1 ... The core dump path is an invalid directory 2021-10-24 09:57:56.002 [unknown] [unknown] localhost 140606630728640 0[0:0#0] [BACKEND] WARNING: macAddr is 578/2886795268, sysidentifier is 37923857/327574, randomNum is 1556938646 ok initializing pg_authid ... ok setting password ... ok initializing dependencies ... ok loading PL/pgSQL server-side language ... ok creating system views ... ok creating performance views ... ok loading system objects' descriptions ... ok creating collations ... ok creating conversions ... ok creating dictionaries ... ok setting privileges on built-in objects ... ok initialize global configure for bucketmap length ... ok creating information schema ... ok loading foreign-data wrapper for distfs access ... ok loading foreign-data wrapper for hdfs access ... ok loading foreign-data wrapper for log access ... ok loading hstore extension ... ok loading foreign-data wrapper for MOT access ... ok loading security plugin ... ok update system tables ... ok creating snapshots catalog ... ok vacuuming database template1 ... ok copying template1 to template0 ... ok copying template1 to postgres ... ok freezing database template0 ... ok freezing database template1 ... ok freezing database postgres ... ok WARNING: enabling "trust" authentication for local connections You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run gs_initdb. Success. You can now start the database server of single node using: gaussdb -D /opengauss/data/single_node --single_node or gs_ctl start -D /opengauss/data/single_node -Z single_node -l logfile [step 7]: start datanode [2021-10-24 09:59:29.904][842][][gs_ctl]: gs_ctl started,datadir is /opengauss/data/single_node [2021-10-24 09:59:30.073][842][][gs_ctl]: waiting for server to start... .0 LOG: [Alarm Module]can not read GAUSS_WARNING_TYPE env. 0 LOG: [Alarm Module]Host Name: lhropengausssimple 0 LOG: [Alarm Module]Host IP: 172.17.0.4 0 LOG: [Alarm Module]Cluster Name: dbCluster 0 LOG: [Alarm Module]Invalid data in AlarmItem file! Read alarm English name failed! line: 55 0 WARNING: failed to open feature control file, please check whether it exists: FileName=gaussdb.version, Errno=2, Errmessage=No such file or directory. 0 WARNING: failed to parse feature control file: gaussdb.version. 0 WARNING: Failed to load the product control file, so gaussdb cannot distinguish product version. The core dump path is an invalid directory 2021-10-24 09:59:30.416 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [BACKEND] LOG: when starting as multi_standby mode, we couldn't support data replicaton. gaussdb.state does not exist, and skipt setting since it is optional.2021-10-24 09:59:30.416 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [BACKEND] LOG: [Alarm Module]can not read GAUSS_WARNING_TYPE env. 2021-10-24 09:59:30.416 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [BACKEND] LOG: [Alarm Module]Host Name: lhropengausssimple 2021-10-24 09:59:30.416 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [BACKEND] LOG: [Alarm Module]Host IP: 172.17.0.4 2021-10-24 09:59:30.416 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [BACKEND] LOG: [Alarm Module]Cluster Name: dbCluster 2021-10-24 09:59:30.416 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [BACKEND] LOG: [Alarm Module]Invalid data in AlarmItem file! Read alarm English name failed! line: 55 2021-10-24 09:59:30.452 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [BACKEND] LOG: loaded library "security_plugin" 2021-10-24 09:59:30.453 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [BACKEND] WARNING: could not create any HA TCP/IP sockets 2021-10-24 09:59:30.537 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [BACKEND] WARNING: No explicit IP is configured for listen_addresses GUC. 2021-10-24 09:59:30.537 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [BACKEND] LOG: InitNuma numaNodeNum: 1 numa_distribute_mode: none inheritThreadPool: 0. 2021-10-24 09:59:30.538 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [BACKEND] LOG: reserved memory for backend threads is: 220 MB 2021-10-24 09:59:30.538 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [BACKEND] LOG: reserved memory for WAL buffers is: 128 MB 2021-10-24 09:59:30.538 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [BACKEND] LOG: Set max backend reserve memory is: 348 MB, max dynamic memory is: 11069 MB 2021-10-24 09:59:30.538 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [BACKEND] LOG: shared memory 358 Mbytes, memory context 11417 Mbytes, max process memory 12288 Mbytes 2021-10-24 09:59:30.626 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [CACHE] LOG: set data cache size(402653184) 2021-10-24 09:59:30.664 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [CACHE] LOG: set metadata cache size(134217728) 2021-10-24 09:59:30.738 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [SEGMENT_PAGE] LOG: Segment-page constants: DF_MAP_SIZE: 8156, DF_MAP_BIT_CNT: 65248, DF_MAP_GROUP_EXTENTS: 4175872, IPBLOCK_SIZE: 8168, EXTENTS_PER_IPBLOCK: 1021, IPBLOCK_GROUP_SIZE: 4090, BMT_HEADER_LEVEL0_TOTAL_PAGES: 8323072, BktMapEntryNumberPerBlock: 2038, BktMapBlockNumber: 25, BktBitMaxMapCnt: 512 2021-10-24 09:59:30.827 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [BACKEND] LOG: gaussdb: fsync file "/opengauss/data/single_node/gaussdb.state.temp" success 2021-10-24 09:59:30.827 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [BACKEND] LOG: create gaussdb state file success: db state(STARTING_STATE), server mode(Normal) 2021-10-24 09:59:30.857 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [BACKEND] LOG: max_safe_fds = 979, usable_fds = 1000, already_open = 11 The core dump path is an invalid directory 2021-10-24 09:59:30.860 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [BACKEND] LOG: user configure file is not found, it will be created. 2021-10-24 09:59:30.871 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [BACKEND] LOG: the configure file /opengauss/etc/gscgroup_omm.cfg doesn't exist or the size of configure file has changed. Please create it by root user! 2021-10-24 09:59:30.871 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [BACKEND] LOG: Failed to parse cgroup config file. 2021-10-24 09:59:30.910 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [EXECUTOR] WARNING: Failed to obtain environment value $GAUSSLOG! 2021-10-24 09:59:30.910 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [EXECUTOR] DETAIL: N/A 2021-10-24 09:59:30.910 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [EXECUTOR] CAUSE: Incorrect environment value. 2021-10-24 09:59:30.910 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [EXECUTOR] ACTION: Please refer to backend log for more details. 2021-10-24 09:59:30.913 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [EXECUTOR] WARNING: Failed to obtain environment value $GAUSSLOG! 2021-10-24 09:59:30.913 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [EXECUTOR] DETAIL: N/A 2021-10-24 09:59:30.913 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [EXECUTOR] CAUSE: Incorrect environment value. 2021-10-24 09:59:30.913 [unknown] [unknown] localhost 140607086257088 0[0:0#0] 0 [EXECUTOR] ACTION: Please refer to backend log for more details. . [2021-10-24 09:59:32.130][842][][gs_ctl]: done [2021-10-24 09:59:32.130][842][][gs_ctl]: server started (/opengauss/data/single_node) import sql file Would you like to create a demo database (yes/no)? YES Please type 'yes' or 'no': yes Load demoDB [school,finance] success. [complete successfully]: You can start or stop the database server using: gs_ctl start|stop|restart -D $GAUSSHOME/data/single_node -Z single_node [omm@lhropengausssimple simpleInstall]$ gs_ctl status -D $GAUSSHOME/data/single_node [2021-10-25 16:10:28.173][1117][][gs_ctl]: gs_ctl status,datadir is /opengauss/data/single_node gs_ctl: server is running (PID: 706) /opengauss/bin/gaussdb "-D" "/opengauss/data/single_node" [omm@lhropengausssimple simpleInstall]$ pwd /opengauss/simpleInstall [omm@lhropengausssimple simpleInstall]$ ll total 64 -rw-r--r-- 1 omm dbgrp 10883 Sep 30 14:39 finance.sql -rw-r--r-- 1 omm dbgrp 12842 Sep 30 14:39 install.sh -rw-r--r-- 1 omm dbgrp 4491 Oct 24 09:59 load.log -rw-r--r-- 1 omm dbgrp 5167 Sep 30 14:39 README.md -rw-r--r-- 1 omm dbgrp 19926 Sep 30 14:39 school.sql [omm@lhropengausssimple simpleInstall]$ cd .. [omm@lhropengausssimple opengauss]$ ll total 40 drwxr-xr-x 3 omm dbgrp 4096 Sep 30 14:39 bin drwx------ 3 omm dbgrp 4096 Oct 24 09:57 data drwxr-xr-x 3 omm dbgrp 4096 Sep 30 14:39 etc drwxr-xr-x 3 omm dbgrp 4096 Sep 30 14:39 include drwxr-xr-x 4 omm dbgrp 4096 Sep 30 14:39 jre drwxr-xr-x 5 omm dbgrp 4096 Sep 30 14:39 lib drwx------ 2 omm dbgrp 4096 Oct 24 09:59 logs drwxr-xr-x 5 omm dbgrp 4096 Sep 30 14:39 share drwxr-xr-x 2 omm dbgrp 4096 Oct 24 09:59 simpleInstall -rw-r--r-- 1 omm dbgrp 32 Sep 30 14:39 version.cfg [omm@lhropengausssimple opengauss]$ ps -ef|grep omm root 414 19 0 09:55 pts/0 00:00:00 su - omm omm 415 414 0 09:55 pts/0 00:00:00 -bash omm 845 0 4 09:59 pts/0 00:00:02 /opengauss/bin/gaussdb -D /opengauss/data/single_node omm 973 415 0 10:00 pts/0 00:00:00 ps -ef omm 974 415 0 10:00 pts/0 00:00:00 grep --color=auto omm [omm@lhropengausssimple opengauss]$ cd bin [omm@lhropengausssimple bin]$ ./gsql gsql: FATAL: database "omm" does not exist [omm@lhropengausssimple bin]$ ./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 -----------+-------+----------+-------------+-------------+------------------- finance | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 | postgres | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 | school | 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 (5 rows) openGauss=# C:\Users\lhrxxt>psql -d postgres -U lhr -h 192.168.66.35 -p35432 Password for user lhr: psql (14.0, server 9.2.4) Type "help" for help. postgres=> \du List of roles Role name | Attributes | Member of ------------------------+------------------------------------------------+----------- gs_role_account_lock | Cannot login | {} gs_role_copy_files | Cannot login | {} gs_role_pldebugger | Cannot login | {} gs_role_replication | Cannot login | {} gs_role_signal_backend | Cannot login | {} gs_role_tablespace | Cannot login | {} lhr | | {} omm | Superuser, Create role, Create DB, Replication | {} |
一主一备安装
部署一主一备环境
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 | -- 安装一主一备节点(之前的配置和单节点一样) su - omm cd /opengauss/simpleInstall sh install.sh -w lhr@123XXT --multinode -p 5434 -- 启动停止 primary: gs_ctl start|stop|restart -D $GAUSSHOME/data/master -M primary standby: gs_ctl start|stop|restart -D $GAUSSHOME/data/slave -M standby -- 连接,-r表示可以使用上下左右键 gsql -d postgres -r -- 修改参数文件 -- master alter system set replconninfo1 = 'localhost=127.0.0.1 localport=5435 localheartbeatport=5439 localservice=5438 remotehost=127.0.0.1 remoteport=5635 remoteheartbeatport=5639 remoteservice=5638'; -- slave alter system set replconninfo1 = 'localhost=127.0.0.1 localport=5635 localheartbeatport=5639 localservice=5638 remotehost=127.0.0.1 remoteport=5435 remoteheartbeatport=5439 remoteservice=5438'; # 环境变量 cat >> /home/omm/.bashrc <"EOF" export GAUSSHOME=/opengauss export PATH=$GAUSSHOME/bin:$PATH export LD_LIBRARY_PATH=$GAUSSHOME/lib:$LD_LIBRARY_PATH export GS_CLUSTER_NAME=dbCluster ulimit -n 1000000 EOF source /home/omm/.bashrc -- 配置远程访问 gsql -d postgres -p 5434 gsql -d postgres -p 5634 -- f 为主,t为备 select pg_is_in_recovery(); create database omm; alter system set password_policy=0; alter system set password_encryption_type=1; alter system set listen_addresses = '*'; echo "host all all 0.0.0.0/0 sha256" >> /opengauss/data/master/pg_hba.conf echo "host all all 0.0.0.0/0 sha256" >> /opengauss/data/slave/pg_hba.conf -- 重启(必须带-M参数,否则主备关系破坏) gs_ctl restart -D /opengauss/data/master/ -M primary gs_ctl restart -D /opengauss/data/slave/ -M standby -- 查询主备关系 gs_ctl query -D /opengauss/data/master select * from pg_stat_replication; select pg_is_in_recovery(); -- 新建用户 -- 初始化数据库的用户,是不能通过IP远程连接的,所以需要创建另外一个用户才能远程连接 gsql -p 5434 # 创建用户(初始化数据库的用户不能进行远程连接,需要重新创建用户) create user lhr with password 'lhr' sysadmin ; grant all PRIVILEGES to lhr; -- 验证远程登录数据库 gsql -dpostgres -h172.17.0.7 -Ulhr -r -W'lhr' -- 远程连接 gsql -d postgres -U lhr -W'lhr' -h 192.168.66.35 -p35434 -r psql -d postgres -U lhr -h 192.168.66.35 -p35434 -- 解锁用户 alter user lhr account unlock; -- 重新构建主备关系 gs_ctl build -D /opengauss/data/slave -b full -M standby |
安装过程: