暂无图片
暂无图片
2
暂无图片
暂无图片
暂无图片

NAC介绍及演示

Halo Tech 2024-08-06
166

    NAC全程为Near application cluster(近实时应用集群以下简称NAC)技术,易景的NAC技术采用存算分离架构(WORK-DATA),WORK节点与DATA节点间使用私有协议进行通信。NAC技术成功解决了SQL多次解析的问题和函数透明负载的问题(这两项技术也是国际上首次实现),体验接近于Oracle RAC,甚至能提供比RAC更优的性能表现,且比RAC更容易扩展。

一、介绍NAC架构的环境搭建及简单演示:

    统一集群名称:Nac
    统一数据库名称:metadata
    统一用户名: ww
    统一用户密码:123456
    统一servernameforeign_server_01
    主数据节点IP:10.16.6.196 主数据节点端口:1940
    工作节点一IP: 10.16.6.196 工作节点一端口:1941
    工作节点二IP: 10.16.6.196 工作节点二端口:1942
    Etcd服务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 ... ok
      creating subdirectories ... ok
      selecting dynamic shared memory implementation ... posix
      selecting default max_connections ... 100
      selecting default shared_buffers ... 128MB
      selecting default time zone ... Asia/Shanghai
      creating configuration files ... ok
      running bootstrap script ... ok
      performing post-bootstrap initialization ... ok
      syncing data to disk ... ok
      initdb: 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 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 start
            waiting for server to start....2024-07-15 10:59:48.693 CST [1431117LOG:  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-bit
            2024-07-15 10:59:48.694 CST [1431117LOG:  listening on IPv4 address "0.0.0.0", port 1940
            2024-07-15 10:59:48.694 CST [1431117LOG:  listening on IPv6 address "::", port 1940
            2024-07-15 10:59:48.709 CST [1431117LOG:  listening on Unix socket "/var/run/halo/.s.PGSQL.1940"
            2024-07-15 10:59:48.744 CST [1431118LOG:  database system was shut down at 2024-07-15 10:44:18 CST
            2024-07-15 10:59:48.763 CST [1431117LOG:  database system is ready to accept connections
             done
            server started


            $ psql
            psql (1.0.14.11)
            Type "help" for help.


            halo0root=# create user ww WITH SUPERUSER;
            CREATE ROLE


            halo0root=# alter user ww password '123456';
            create database metadata;
            CREATE DATABASE


            halo0root=# \q
            [wangjiajia@wangjiajia-dev nac_dn]$ hsql -Uww -d metadata
            psql (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/nac1
                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/nac1 ... ok
                creating subdirectories ... ok
                selecting dynamic shared memory implementation ... posix
                selecting default max_connections ... 100
                selecting default shared_buffers ... 128MB
                selecting default time zone ... Asia/Shanghai
                creating configuration files ... ok
                running bootstrap script ... ok
                performing post-bootstrap initialization ... ok
                syncing data to disk ... ok


                initdb: 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 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 start
                    waiting for server to start....2024-07-15 11:21:51.855 CST [1431245LOG:  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-bit
                    2024-07-15 11:21:51.856 CST [1431245LOG:  listening on IPv6 address "::1", port 1941
                    2024-07-15 11:21:51.856 CST [1431245LOG:  listening on IPv4 address "127.0.0.1", port 1941
                    2024-07-15 11:21:51.872 CST [1431245LOG:  listening on Unix socket "/var/run/halo/.s.PGSQL.1941"
                    2024-07-15 11:21:51.923 CST [1431246LOG:  database system was shut down at 2024-07-15 11:17:59 CST
                    2024-07-15 11:21:51.943 CST [1431245LOG:  database system is ready to accept connections
                    done


                    server started
                    [wangjiajia@wangjiajia-dev .build]$ 
                    [wangjiajia@wangjiajia-dev .build]$ 
                    [wangjiajia@wangjiajia-dev .build]$ psql
                    psql (1.0.14.11)
                    Type "help" for help.


                    halo0root=# create user ww WITH SUPERUSER;
                    CREATE ROLE


                    halo0root=# alter user ww password '123456';
                    ALTER ROLE


                    halo0root=# create database metadata;
                    CREATE DATABASE


                    halo0root=# \q
                    hsql -Uww -d metadata
                    psql (1.0.14.11)
                    Type "help" for help.


                    metadata=# create extension dlb_fdw;
                    2024-07-15 11:22:55.273 CST [1431261ERROR:  schema "oracle" does not exist
                    2024-07-15 11:22:55.273 CST [1431261STATEMENT:  create extension dlb_fdw;
                    ERROR: schema "oracle" does not exist


                    metadata=#  create extension aux_oracle cascade;
                    NOTICE:  installing required extension "plorasql"
                    NOTICE:  installing required extension "pgcrypto"
                    CREATE EXTENSION


                    metadata=# create extension dlb_fdw;
                    CREATE EXTENSION


                    metadata=# \q

                    3.5 再次修改配置文件

                      # 修改配置文件vim postgresql.conf


                      # 修改内容
                      instance_type = 'DLB' # 设置架构模式
                      etcd_ip='10.16.16.155' # IP
                      etcd_port=2379 # Port


                      uuid 生成唯一标识
                      node_id = '4f2c5a19-5dd7-43e2-c6f2-be51035b4111'

                      3.6 再次配置数据库

                        [wangjiajia@wangjiajia-dev nac1]$ pg_ctl restart
                        waiting for server to shut down....2024-07-15 11:26:34.168 CST [1431245] LOG:  received fast shutdown request
                        2024-07-15 11:26:34.189 CST [1431245] LOG:  aborting any active transactions
                        2024-07-15 11:26:34.193 CST [1431245] LOG:  background worker "logical replication launcher" (PID 1431252) exited with exit code 1
                        2024-07-15 11:26:34.194 CST [1431247LOG:  shutting down
                        2024-07-15 11:26:34.606 CST [1431245LOG:  database system is shut down
                        done


                        server stopped
                        waiting for server to start....2024-07-15 11:26:34.737 CST [1431285LOG:  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-bit
                        2024-07-15 11:26:34.738 CST [1431285LOG:  listening on IPv6 address "::1", port 1941
                        2024-07-15 11:26:34.738 CST [1431285LOG:  listening on IPv4 address "127.0.0.1", port 1941
                        2024-07-15 11:26:34.756 CST [1431285LOG:  listening on Unix socket "/var/run/halo/.s.PGSQL.1941"
                        2024-07-15 11:26:34.799 CST [1431286LOG:  database system was shut down at 2024-07-15 11:26:34 CST
                        2024-07-15 11:26:35.019 CST [1431285LOG:  database system is ready to accept connections
                        done


                        server started
                        [wangjiajia@wangjiajia-dev nac1]$ 
                        [wangjiajia@wangjiajia-dev nac1]$ 
                        [wangjiajia@wangjiajia-dev nac1]$  hsql -Uww -d metadata
                        psql (1.0.14.11)
                        Type "help" for help.


                        metadata=# CREATE SERVER foreign_server_01
                        metadata-# FOREIGN DATA WRAPPER dlb_fdw
                        metadata-# OPTIONS (host '10.16.6.196', port '1940', dbname 'metadata');
                        CREATE SERVER


                        metadata=# CREATE USER MAPPING FOR ww
                        metadata-# SERVER foreign_server_01
                        metadata-# OPTIONS (user 'ww', password '123456');
                        CREATE USER MAPPING


                        CREATE SERVER foreign_server_01
                        FOREIGN DATA WRAPPER dlb_fdw
                        OPTIONS (host '10.16.6.196', port '1940', dbname 'metadata');


                        CREATE USER MAPPING FOR ww
                        SERVER foreign_server_01
                        OPTIONS (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 TABLE


                          metadata=# alter table t1 rename to t2;
                          NOTICE:  工作节点待执行命令: psql -dmetadata -Uww -c"ALTER LOCAL table t1 rename to t2;";
                          ALTER TABLE


                          metadata=# create view v2 as select count(*) from t2;
                          NOTICE:  工作节点待执行命令: psql -dmetadata -Uww -c"CREATE LOCAL view v2 as select count(*) from t2;";
                          CREATE VIEW


                          metadata=# drop view v2;
                          NOTICE:  工作节点待执行命令: psql -dmetadata -Uww -c"DROP LOCAL VIEW IF EXISTS v2;";
                          DROP VIEW


                          metadata=# drop table t2;
                          NOTICE:  工作节点待执行命令: psql -dmetadata -Uww -c"DROP FOREIGN TABLE t2";
                          DROP TABLE

                              至此NAC功能演示结束,有想了解更多的朋友,请留言关注

                          文章转载自Halo Tech,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

                          评论