合 在docker中快速体验GBase 8c集群环境
环境准备
1 2 3 4 5 6 7 8 9 | docker rm -f gbase8c docker run -itd --name gbase8c -h gbase8c \ -p 5432:5432 \ -v /sys/fs/cgroup:/sys/fs/cgroup \ --privileged=true \ lhrbest/gbase8c:8cV5_S3.0.0B76_1.0 \ /usr/sbin/init docker exec -it gbase8c bash |
数据库启停
启动数据库服务
1 2 3 4 | systemctl start etcd.service su - gbase /home/gbase/gbase_package/script/gha_ctl start all -l http://127.0.0.1:2379 |
停止数据库服务
1 2 3 4 5 6 7 8 9 | su - gbase /home/gbase/gbase_package/script/gha_ctl stop all -l http://127.0.0.1:2379 -- 或 systemctl stop coordinator_gbase_cn1.service systemctl stop datanode_gbase_dn1_1.service systemctl stop gtm_gbase_gtm1.service systemctl stop server_gbase_gha_server1.service systemctl stop etcd.service |
状态检查
执行
1 2 | /home/gbase/gbase_package/script/gha_ctl monitor -l http://127.0.0.1:2379 /home/gbase/gbase_package/script/gha_ctl monitor -l http://127.0.0.1:2379 -H |
结果如下,说明集群安装正常,数据服务启动中
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 | [root@gbase8c /]# /home/gbase/gbase_package/script/gha_ctl monitor -l http://127.0.0.1:2379 -H +----+-------------+-----------+-------+---------+--------+ | No | name | host | port | state | leader | +----+-------------+-----------+-------+---------+--------+ | 0 | gha_server1 | 127.0.0.1 | 20001 | running | True | +----+-------------+-----------+-------+---------+--------+ +----+------+-----------+------+---------------------------+---------+---------+ | No | name | host | port | work_dir | state | role | +----+------+-----------+------+---------------------------+---------+---------+ | 0 | gtm1 | 127.0.0.1 | 6666 | /home/gbase/data/gtm/gtm1 | running | primary | +----+------+-----------+------+---------------------------+---------+---------+ +----+------+-----------+------+----------------------------+---------+---------+ | No | name | host | port | work_dir | state | role | +----+------+-----------+------+----------------------------+---------+---------+ | 0 | cn1 | 127.0.0.1 | 5432 | /home/gbase/data/coord/cn1 | running | primary | +----+------+-----------+------+----------------------------+---------+---------+ +----+-------+-------+-----------+-------+----------------------------+---------+---------+ | No | group | name | host | port | work_dir | state | role | +----+-------+-------+-----------+-------+----------------------------+---------+---------+ | 0 | dn1 | dn1_1 | 127.0.0.1 | 15432 | /home/gbase/data/dn1/dn1_1 | running | primary | | 1 | dn2 | dn2_1 | 127.0.0.1 | 20010 | /home/gbase/data/dn2/dn2_1 | running | primary | +----+-------+-------+-----------+-------+----------------------------+---------+---------+ +----+-----------------------+--------+---------+----------+ | No | url | name | state | isLeader | +----+-----------------------+--------+---------+----------+ | 0 | http://127.0.0.1:2379 | node_0 | healthy | True | +----+-----------------------+--------+---------+----------+ [root@gbase8c /]# [root@gbase8c /]# /home/gbase/gbase_package/script/gha_ctl monitor -l http://127.0.0.1:2379 { "cluster": "gbase", "version": "V5_S3.0.0B76", "server": [ { "name": "gha_server1", "host": "127.0.0.1", "port": "20001", "state": "running", "isLeader": true } ], "gtm": [ { "name": "gtm1", "host": "127.0.0.1", "port": "6666", "workDir": "/home/gbase/data/gtm/gtm1", "agentPort": "8001", "state": "running", "role": "primary", "agentHost": "127.0.0.1" } ], "coordinator": [ { "name": "cn1", "host": "127.0.0.1", "port": "5432", "workDir": "/home/gbase/data/coord/cn1", "agentPort": "8003", "state": "running", "role": "primary", "agentHost": "127.0.0.1", "central": true } ], "datanode": { "dn1": [ { "name": "dn1_1", "host": "127.0.0.1", "port": "15432", "workDir": "/home/gbase/data/dn1/dn1_1", "agentPort": "8005", "state": "running", "role": "primary", "agentHost": "127.0.0.1" } ], "dn2": [ { "name": "dn2_1", "host": "127.0.0.1", "port": "20010", "workDir": "/home/gbase/data/dn2/dn2_1", "agentPort": "8007", "state": "running", "role": "primary", "agentHost": "127.0.0.1" } ] }, "dcs": { "clusterState": "healthy", "members": [ { "url": "http://127.0.0.1:2379", "id": "b71f75320dc06a6c", "name": "node_0", "isLeader": true, "state": "healthy" } ] } } |
连接和 SQL 测试
在主节点 gbase8c
执行 $ gsql -d postgres -p 5432
,出现 postgres=#
操作符说明客户端工具 gsql 成功连接 GBase 8c 数据库。
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 | [gbase@gbase8c script]$ gsql -d postgres -p 5432 gsql ((multiple_nodes GBase8cV5 3.0.0B76 build 47948f99) compiled at 2023-02-27 16:04:20 commit 0 last mr 1232 ) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. testdb=# select version(); version --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- PostgreSQL 9.2.4 (multiple_nodes GBase8cV5 3.0.0B76 build 47948f99) compiled at 2023-02-27 16:04:20 commit 0 last mr 1232 on x86_64-unknown-linux-gnu, compiled by g++ (GCC) 7.3.0, 64-bit (1 row) testdb=# postgres=# create database testdb; CREATE DATABASE postgres=# \c testdb Non-SSL connection (SSL connection is recommended when requiring high-security) You are now connected to database "testdb" as user "gbase". testdb=# create table student(ID int, Name varchar(10)); CREATE TABLE testdb=# insert into student values(1, 'Mike'),(2,'John'); INSERT 0 2 testdb=# select * from student; id | name ----+------ 1 | Mike 2 | John (2 rows) testdb=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+-------+----------+---------+-------+------------------- postgres | gbase | UTF8 | C | C | template0 | gbase | UTF8 | C | C | =c/gbase + | | | | | gbase=CTc/gbase template1 | gbase | UTF8 | C | C | =c/gbase + | | | | | gbase=CTc/gbase testdb | gbase | UTF8 | C | C | (4 rows) testdb=# \d student Table "public.student" Column | Type | Modifiers --------+-----------------------+----------- id | integer | name | character varying(10) | testdb=# testdb=# create database lhrdb; CREATE DATABASE postgres=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+-------+----------+---------+-------+------------------- lhrdb | gbase | UTF8 | C | C | postgres | gbase | UTF8 | C | C | template0 | gbase | UTF8 | C | C | =c/gbase + | | | | | gbase=CTc/gbase template1 | gbase | UTF8 | C | C | =c/gbase + | | | | | gbase=CTc/gbase testdb | gbase | UTF8 | C | C | (5 rows) postgres=# |
远程登录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | C:\Users\lhr>psql -U gha -h 192.168.59.220 -p 5432 -d postgres Password for user gha: 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 -----------+-------+----------+---------+-------+------------------- lhrdb | gbase | UTF8 | C | C | postgres | gbase | UTF8 | C | C | template0 | gbase | UTF8 | C | C | =c/gbase + | | | | | gbase=CTc/gbase template1 | gbase | UTF8 | C | C | =c/gbase + | | | | | gbase=CTc/gbase testdb | gbase | UTF8 | C | C | (5 rows) postgres=> |
备注
所有用户的密码均为lhr