NAC全程为Near application cluster(近实时应用集群以下简称NAC)技术,易景的NAC技术采用存算分离架构(WORK-DATA),WORK节点与DATA节点间使用私有协议进行通信。NAC技术成功解决了SQL多次解析的问题和函数透明负载的问题(这两项技术也是国际上首次实现),体验接近于Oracle RAC,甚至能提供比RAC更优的性能表现,且比RAC更容易扩展。
一、介绍NAC架构的环境搭建及简单演示:
统一集群名称:Nac统一数据库名称:metadata统一用户名: ww统一用户密码:123456统一servername:foreign_server_01主数据节点IP:10.16.6.196 主数据节点端口:1940工作节点一IP: 10.16.6.196 工作节点一端口:1941工作节点二IP: 10.16.6.196 工作节点二端口:1942Etcd服务IP:10.16.16.155 Etcd服务端口:2379
1.1 初始化数据库实例数据目录/data/nac_dn
The files belonging to this database system will be owned by user "wangjiajia".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".Data page checksums are disabled.fixing permissions on existing directory /home/wangjiajia/Workspace/Halo_Database/.build/data/nac_dn ... okcreating subdirectories ... okselecting dynamic shared memory implementation ... posixselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting default time zone ... Asia/Shanghaicreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... oksyncing data to disk ... okinitdb: warning: enabling "trust" authentication for local connectionsYou can change this by editing pg_hba.conf or using the option -A, or--auth-local and --auth-host, the next time you run initdb.Success. You can now start the database server using:/home/wangjiajia/Workspace/Halo_Database/.build/product/dbms/14NAC/bin/pg_ctl -D home/wangjiajia/Workspace/Halo_Database/.build/data/nac_dn -l logfile start
1.2 修改参数信息
# 修改配置文件vi postgresql.conf# 修改内容listen_addresses = '*'# 端口设置port = 1940# 模式设置database_compat_mode = 'oracle'# 集群名设置cluster_name = 'nacww'
1.3 设置环境变量脚本
1.4 修改pg_hba.conf
host all all 0.0.0.0/0 md5
1.5 数据库设置
pg_ctl startwaiting for server to start....2024-07-15 10:59:48.693 CST [1431117] LOG: starting 羲和(Halo) 1.0.14.11 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-15), 64-bit2024-07-15 10:59:48.694 CST [1431117] LOG: listening on IPv4 address "0.0.0.0", port 19402024-07-15 10:59:48.694 CST [1431117] LOG: listening on IPv6 address "::", port 19402024-07-15 10:59:48.709 CST [1431117] LOG: listening on Unix socket "/var/run/halo/.s.PGSQL.1940"2024-07-15 10:59:48.744 CST [1431118] LOG: database system was shut down at 2024-07-15 10:44:18 CST2024-07-15 10:59:48.763 CST [1431117] LOG: database system is ready to accept connectionsdoneserver started$ psqlpsql (1.0.14.11)Type "help" for help.halo0root=# create user ww WITH SUPERUSER;CREATE ROLEhalo0root=# alter user ww password '123456';create database metadata;CREATE DATABASEhalo0root=# \q[wangjiajia@wangjiajia-dev nac_dn]$ hsql -Uww -d metadatapsql (1.0.14.11)Type "help" for help.
至此主数据节点设置完毕
二、ETCD设置
key:Nac_metadata_servername 经过base64编码后:TmFjX21ldGFkYXRhX3NlcnZlcm5hbWU=value:foreign_server_01 经过base64编码后:Zm9yZWlnbl9zZXJ2ZXJfMDE=执行命令:curl -L http://10.16.16.155:2379/v3/kv/put -X POST -d '{"key":"TmFjX21ldGFkYXRhX3NlcnZlcm5hbWU=", "value": "Zm9yZWlnbl9zZXJ2ZXJfMDE="}'
三、工作节点一
3.1 初始化数据库目录
pg_ctl init -D /home/wangjiajia/Workspace/Halo_Database/.build/data/nac1The files belonging to this database system will be owned by user "wangjiajia".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".Data page checksums are disabled.fixing permissions on existing directory /home/wangjiajia/Workspace/Halo_Database/.build/data/nac1 ... okcreating subdirectories ... okselecting dynamic shared memory implementation ... posixselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting default time zone ... Asia/Shanghaicreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... oksyncing data to disk ... okinitdb: warning: enabling "trust" authentication for local connectionsYou can change this by editing pg_hba.conf or using the option -A, or--auth-local and --auth-host, the next time you run initdb.Success. You can now start the database server using:home/wangjiajia/Workspace/Halo_Database/.build/product/dbms/14NAC/bin/pg_ctl -D home/wangjiajia/Workspace/Halo_Database/.build/data/nac1 -l logfile start
3.2 第一次修改参数信息
# 修改配置文件vi postgresql.conf# 修改内容port = 1921 # 端口设置database_compat_mode = 'oracle' # 模式设置cluster_name = 'nacww' # 集群名设置
3.3 设置环境变量脚本
3.4 数据库设置
pg_ctl startwaiting for server to start....2024-07-15 11:21:51.855 CST [1431245] LOG: starting 羲和(Halo) 1.0.14.11 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-15), 64-bit2024-07-15 11:21:51.856 CST [1431245] LOG: listening on IPv6 address "::1", port 19412024-07-15 11:21:51.856 CST [1431245] LOG: listening on IPv4 address "127.0.0.1", port 19412024-07-15 11:21:51.872 CST [1431245] LOG: listening on Unix socket "/var/run/halo/.s.PGSQL.1941"2024-07-15 11:21:51.923 CST [1431246] LOG: database system was shut down at 2024-07-15 11:17:59 CST2024-07-15 11:21:51.943 CST [1431245] LOG: database system is ready to accept connectionsdoneserver started[wangjiajia@wangjiajia-dev .build]$[wangjiajia@wangjiajia-dev .build]$[wangjiajia@wangjiajia-dev .build]$ psqlpsql (1.0.14.11)Type "help" for help.halo0root=# create user ww WITH SUPERUSER;CREATE ROLEhalo0root=# alter user ww password '123456';ALTER ROLEhalo0root=# create database metadata;CREATE DATABASEhalo0root=# \qhsql -Uww -d metadatapsql (1.0.14.11)Type "help" for help.metadata=# create extension dlb_fdw;2024-07-15 11:22:55.273 CST [1431261] ERROR: schema "oracle" does not exist2024-07-15 11:22:55.273 CST [1431261] STATEMENT: create extension dlb_fdw;ERROR: schema "oracle" does not existmetadata=# create extension aux_oracle cascade;NOTICE: installing required extension "plorasql"NOTICE: installing required extension "pgcrypto"CREATE EXTENSIONmetadata=# create extension dlb_fdw;CREATE EXTENSIONmetadata=# \q
3.5 再次修改配置文件
# 修改配置文件vim postgresql.conf# 修改内容instance_type = 'DLB' # 设置架构模式etcd_ip='10.16.16.155' # IPetcd_port=2379 # Portuuid 生成唯一标识node_id = '4f2c5a19-5dd7-43e2-c6f2-be51035b4111'
3.6 再次配置数据库
[wangjiajia@wangjiajia-dev nac1]$ pg_ctl restartwaiting for server to shut down....2024-07-15 11:26:34.168 CST [1431245] LOG: received fast shutdown request2024-07-15 11:26:34.189 CST [1431245] LOG: aborting any active transactions2024-07-15 11:26:34.193 CST [1431245] LOG: background worker "logical replication launcher" (PID 1431252) exited with exit code 12024-07-15 11:26:34.194 CST [1431247] LOG: shutting down2024-07-15 11:26:34.606 CST [1431245] LOG: database system is shut downdoneserver stoppedwaiting for server to start....2024-07-15 11:26:34.737 CST [1431285] LOG: starting 羲和(Halo) 1.0.14.11 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-15), 64-bit2024-07-15 11:26:34.738 CST [1431285] LOG: listening on IPv6 address "::1", port 19412024-07-15 11:26:34.738 CST [1431285] LOG: listening on IPv4 address "127.0.0.1", port 19412024-07-15 11:26:34.756 CST [1431285] LOG: listening on Unix socket "/var/run/halo/.s.PGSQL.1941"2024-07-15 11:26:34.799 CST [1431286] LOG: database system was shut down at 2024-07-15 11:26:34 CST2024-07-15 11:26:35.019 CST [1431285] LOG: database system is ready to accept connectionsdoneserver started[wangjiajia@wangjiajia-dev nac1]$[wangjiajia@wangjiajia-dev nac1]$[wangjiajia@wangjiajia-dev nac1]$ hsql -Uww -d metadatapsql (1.0.14.11)Type "help" for help.metadata=# CREATE SERVER foreign_server_01metadata-# FOREIGN DATA WRAPPER dlb_fdwmetadata-# OPTIONS (host '10.16.6.196', port '1940', dbname 'metadata');CREATE SERVERmetadata=# CREATE USER MAPPING FOR wwmetadata-# SERVER foreign_server_01metadata-# OPTIONS (user 'ww', password '123456');CREATE USER MAPPINGCREATE SERVER foreign_server_01FOREIGN DATA WRAPPER dlb_fdwOPTIONS (host '10.16.6.196', port '1940', dbname 'metadata');CREATE USER MAPPING FOR wwSERVER foreign_server_01OPTIONS (user 'ww', password '123456');
四、工作节点二
同上,按照工作节点一步骤设置即可
五、验证NAC功能
metadata=# CREATE TABLE t1(a int);NOTICE: 工作节点待执行命令: psql -dmetadata -Uww -c"CREATE FOREIGN TABLE public.t1( a integer ) SERVER foreign_server_01 OPTIONS (schema_name 'public', table_name 't1')";CREATE TABLEmetadata=# alter table t1 rename to t2;NOTICE: 工作节点待执行命令: psql -dmetadata -Uww -c"ALTER LOCAL table t1 rename to t2;";ALTER TABLEmetadata=# create view v2 as select count(*) from t2;NOTICE: 工作节点待执行命令: psql -dmetadata -Uww -c"CREATE LOCAL view v2 as select count(*) from t2;";CREATE VIEWmetadata=# drop view v2;NOTICE: 工作节点待执行命令: psql -dmetadata -Uww -c"DROP LOCAL VIEW IF EXISTS v2;";DROP VIEWmetadata=# drop table t2;NOTICE: 工作节点待执行命令: psql -dmetadata -Uww -c"DROP FOREIGN TABLE t2";DROP TABLE
至此NAC功能演示结束,有想了解更多的朋友,请留言关注。
文章转载自Halo Tech,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




