繼上篇安裝完成GaussDB 200之后,本文講一下如何使用這個環境做些開發測試,特別是使用Data Studio進行遠程訪問。
01 創建用戶、數據庫
首先,在omm用戶下,用管理員登陸,創建測試用戶和測試數據庫。
# su - omm
$ source ${BIGDATA_HOME}/mppdb/.mppdbgs_profile
$ gsql -d postgres -p 25308
postgres=# CREATE USER testuser WITH PASSWORD "Test@123";
CREATE ROLE
postgres=# CREATE DATABASE testdb;
CREATE DATABASE
登出管理員之后,嘗試使用新建的賬號進行登陸
$ gsql -d testdb -p 25308 -U testuser -W Test@123
gsql ((GaussDB Kernel V300R002C00 build 8a9c1eb6) compiled at 2019-08-01 18:47:38 commit 6093 last mr 10175 )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
創建測試表
testdb=> create table t1 (c1 varchar(20), c2 int);
NOTICE: The 'DISTRIBUTE BY' clause is not specified. Using 'c1' as the distribution column by default.
HINT: Please use 'DISTRIBUTE BY' clause to specify suitable data distribution column.
CREATE TABLE
testdb=> insert into t1 values ('hello', 1);
INSERT 0 1
testdb=> insert into t1 values ('world', 2);
INSERT 0 1
testdb=> select * from t1;
c1 | c2
-------+----
world | 2
hello | 1
(2 rows)
02 使用GUI工具遠程登陸
方法一、打開訪問控制進行遠程連接
將需要連接的主機IP添加到監聽地址列表。
# 切換到omm用戶
# su - omm
# 查看已有的監聽地址
$ gs_guc check -Z coordinator -I all -c "listen_addresses"
expected guc information: host0: listen_addresses=NULL: [/srv/Bigdata/mppdb/data1/coordinator/postgresql.conf]
gs_guc check: host0: listen_addresses='localhost,192.168.2.111': [/srv/Bigdata/mppdb/data1/coordinator/postgresql.conf]
Total GUC values: 1. Failed GUC values: 0.
The value of parameter listen_addresses is same on all instances.
listen_addresses='localhost,192.168.2.111'
# 添加遠程訪問機器的IP
gs_guc set -I all -Z coordinator -c "listen_addresses='localhost,192.168.2.111,192.168.2.112'"
expected instance path: [/srv/Bigdata/mppdb/data1/coordinator/postgresql.conf]
gs_guc set: listen_addresses='localhost,192.168.2.111,192.168.2.112': [/srv/Bigdata/mppdb/data1/coordinator/postgresql.conf]
Total instances: 1. Failed instances: 0.
Success to perform gs_guc!
# 添加密碼登陸方式
$ gs_guc set -Z coordinator -N all -I all -h "host all testuser 192.168.1.112/32 sha256"
Begin to perform gs_guc for all coordinators.
Total instances: 1. Failed instances: 0.
Success to perform gs_guc!
# 重啟數據庫實例使配置生效
$ gs_om -t stop
$ cm_ctl query
$ cm_ctl start
$ gs_om -t start
然后,找一個Windows的終端,解壓Data Studio之后按以下信息進行連接配置。
但是在我的小內存情況下,一旦改了以上配置之后,就會造成數據庫實例啟動不起來,並且日志有There is insufficient memory for the Java Runtime Environment to continue.
錯誤,可能就是增加監聽造成了內存不足。
於是考慮不修改配置,嘗試使用ssh端口轉發的方式進行連接,在遠程主機上模擬本地訪問。
方式二、使用SSH端口轉發GUI連接
首先,使用終端工具連接GaussDB的服務器,並配置端口轉發。這里以Putty為例,將本地的25308端口映射到GaussDB主機的25308端口。
然后,在Data Studio配置連接本地的25308端口,讓ssh轉發到GaussDB主機上。
最后,登陸連接,查詢剛才新建的t1表進行測試。
可以看到成功的查詢出通過命令行插入的兩條數據。
03 總結
- 通常情況下,遠程連接需要在主機上增加監聽IP和登陸控制配置;
- 在小內存測試主機上,增加監聽可能造成數據庫實例無法啟動;
- 可以通過SSH端口轉發的方式,另辟蹊徑實現工具的遠程訪問。
歡迎掃描二維碼關注公眾號,可以手機訪問文章