• sgx支持数据库环境配置,编译,debug



    环境都编译为debug模式,为了开发,并利用sgx的debugger sgx-gdb进行debug

    查看cpu是否支持sgx


    dell@dell-Precision-3630-Tower  /nvme  lscpu
    Architecture:                       x86_64
    CPU op-mode(s):                     32-bit, 64-bit
    Byte Order:                         Little Endian
    Address sizes:                      39 bits physical, 48 bits virtual
    CPU(s):                             16
    On-line CPU(s) list:                0-15
    Thread(s) per core:                 2
    Core(s) per socket:                 8
    Socket(s):                          1
    NUMA node(s):                       1
    Vendor ID:                          GenuineIntel
    CPU family:                         6
    Model:                              158
    Model name:                         Intel(R) Xeon(R) E-2288G CPU @ 3.70GHz
    Stepping:                           13
    CPU MHz:                            3700.000
    
    --到以下网站查看是否支持
    https://ark.intel.com/content/www/us/en/ark/products/193743/intel-xeon-e2288g-processor-16m-cache-3-70-ghz.html
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    在这里插入图片描述

    bios中开启sgx服务,f12,找到sgx选项,设置为enabled,内存设置为最大128mb

    sgx debug环境编译


    • 操作系统ubuntu20.04

    • 可参考https://zhuanlan.zhihu.com/p/560110720,但是这个是release版本,如果需要debug,所有都编译为debug

    • 顺序:sgx driver->sgx sdk->six psw

    sgx driver

    • 在该下载地址将.bin文件下载,https://download.01.org/intel-sgx/latest/linux-latest/distro/ubuntu20.04-server/

    • 赋予.bin文件执行权限

    sudo chmod 777 sgx_linux_x64_driver_2.11.054c9c4c.bin
    
    • 1
    • 运行该bin文件,完成驱动安装
    sudo ./sgx_linux_x64_driver_2.11.054c9c4c.bin
    
    • 1

    构建sgx sdk和sgx psw软件包

    • 参考链接:https://github.com/intel/linux-sgx/tree/master
    sudo apt-get install build-essential ocaml ocamlbuild automake autoconf libtool wget python-is-python3 libssl-dev git cmake perl
    sudo apt-get install libssl-dev libcurl4-openssl-dev protobuf-compiler libprotobuf-dev debhelper cmake reprepro unzip pkgconf libboost-dev libboost-system-dev libboost-thread-dev lsb-release libsystemd0
    sudo apt-get install build-essential python-is-python3
    sudo apt-get install libssl-dev libcurl4-openssl-dev libprotobuf-dev
    
    • 1
    • 2
    • 3
    • 4

    注意:要构建 Intel® SGX SDK,gcc 版本需要为 7.3 或更高版本,glibc 版本需要为 2.27 或更高版本。

    • 下载源代码并准备子模块和预构建的二进制文件:
    git clone https://github.com/intel/linux-sgx.git
    cd linux-sgx && make preparation
    
    • 1
    • 2

    上面的代码make preparation将触发脚本download_prebuilt.sh下载预构建的二进制文件。您可能需要为wget脚本使用的工具设置 https 代理(如export https_proxy=http://test-proxy:test-port

    注意:如果遇到任何网络下载的问题,自己按照export的方式挂代理

    • 将当前操作系统发行版对应的缓解工具从 external/toolset/{current_distr} 复制到 /usr/local/bin 并确保它们具有执行权限:
    sudo cp external/toolset/{current_distr}/* /usr/local/bin
    which ar as ld objcopy objdump ranlib
    
    • 1
    • 2

    sgx sdk安装

    make sdk DEBUG=1
    make sdk_install_pkg DEBUG=1
    
    • 1
    • 2
    • 进入linux-sgx文件夹,输入
    cd linux/installer/bin
    ./sgx_linux_x64_sdk_${version}.bin
    注意:运行第二条命令时,它询问是否安装在当前文件夹的时候,最好选择“no”,然后输入/opt/intel/, 即将SGX SDK安装在/opt/intel/文件夹下。
    
    • 1
    • 2
    • 3
    • 安装完成后,根据提示输入source命令。

    sgx psw安装

    make psw DEBUG=1
    make deb_psw_pkg DEBUG=1
    
    • 1
    • 2
    • 要构建本地 Debian 软件包存储库
    make deb_local_repo
    
    • 1

    You can find the local package repository located under linux/installer/deb/sgx_debian_local_repo.

    • 修改/etc/apt/sources.list,添加以下行
    deb [trusted=yes arch=amd64] file:/PATH_TO_LOCAL_REPO focal main
    
    • 1

    PATH_TO_LOCAL_REPO替换为linux/installer/deb/sgx_debian_local_repo的绝对路径

    • 更新apt
    sudo apt update
    
    • 1
    • 安装
    apt-get install libsgx-launch-dbgsym libsgx-urts-dbgsym
    apt-get install libsgx-epid-dbgsym libsgx-urts-dbgsym
    apt-get install libsgx-quote-ex-dbgsym libsgx-urts-dbgsym
    apt-get install libsgx-dcap-ql-dbgsym
    
    • 1
    • 2
    • 3
    • 4

    使用代码示例测试SGX SDK包

    • 硬件模式下编译并运行代码示例
    cd ${sgx-sdk-install-path}/SampleCode/LocalAttestation
    make
    cd bin
    ./app
    
    • 1
    • 2
    • 3
    • 4

    编译encdb


    pg的编译参考:https://blog.csdn.net/twi_twi/article/details/127146765,仅做参考

    docker cp 405cc8900e78:/home/postgresql-14.2.3.tar.gz .
    
    apt-get update
    apt-get install build-essential libreadline-dev zlib1g-dev libssl-dev libxml2-dev 
    libxslt-dev cmake g++
    sudo apt install -y make automake libtool cmake
    sudo apt install -y libssl-dev libboost-all-dev
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    编译

    tar xvf postgresql-14.2.3.tar.gz
    ./configure --enable-debug --enable-cassert --prefix=/nvme/encdb/pgsql142 CFLAGS=-O0
    #按照自己的需求修改
    make -j && make install
    
    --添加用户postgres
    useradd -m -d /nvme/encdb/postgres -s /bin/bash postgres
    #新用户postgres的主目录为/nvme/encdb/postgres
    #指定了用户的默认登录 shell为/bin/bash
    passwd postgres
    
    
    --创建数据目录
    cd /nvme/encdb/pgsql142
    mkdir data 
    chown postgres:postgres data
    ls -al
    #output
    drwxr-xr-x  7 root     root     4096 Sep  2 07:02 .
    drwxr-xr-x  1 root     root     4096 Sep  2 03:39 ..
    -rw-r--r--  1 root     root     3337 Sep  2 07:02 1
    drwxr-xr-x  2 root     root     4096 Sep  2 03:39 bin
    drwx------ 19 postgres postgres 4096 Sep  2 07:46 data
    drwxr-xr-x  6 root     root     4096 Sep  2 03:39 include
    drwxr-xr-x  4 root     root     4096 Sep  2 03:39 lib
    drwxr-xr-x  6 root     root     4096 Sep  2 03:39 share
    
    --配置环境变量
    vim ~/.bashrc
    export PGHOME=/nvme/encdb/pgsql142
    export PGDATA=$PGHOME/data
    export PGPORT=5432
    export PGUSER=postgres
    export PATH=$PGHOME/bin:$PATH:$HOME/bin
    export LD_LIBRARY_PATH=$PGHOME/lib
    
    source ~/.bashrc
    
    --初始化数据库
    su - postgres
    ./initdb -D /nvme/encdb/pgsql142/data
    
    --启动服务
    ./pg_ctl -D /nvme/encdb/pgsql142/data -l /nvme/encdb/pgsql142/data/startup.log start
    
    ##以下的感觉可以不需要
    --配置服务
    # 修改/usr/local/pgsql/data目录下的两个文件。
    # 1) postgresql.conf   配置PostgreSQL数据库服务器的相应的参数。  
    # 2) pg_hba.conf        配置对数据库的访问权限。
    
    [postgres@i-vfyxrtmx data]$ vi postgresql.conf 
    listen_addresses = '*'                  # what IP address(es) to listen on;
                                            # comma-separated list of addresses;
                                            # defaults to 'localhost'; use '*' for all
                                            # (change requires restart)
    port = 5432                            # (change requires restart)
    #其中,参数“listen_addresses”表示监听的IP地址,默认是在localhost处监听,也就是127.0.0.1的ip地址上监听,只接受来自本机localhost的连接请求,这会让远程的主机无法登陆这台数据库,如果想从其他的机器上登陆这台数据库,需要把监听地址改为实际网络的地址,一种简单的方法是,将行开头的#去掉,把这个地址改为*,表示在本地的所有地址上监听。
    
    [postgres@weekend02 data]$ vi pg_hba.conf 
    # 找到最下面这一行 ,这样局域网的人才能访问。红色为新添加内容。
    #IPv4 local connections:
    host    all             all             0.0.0.0/0               trust
    host    all             all             127.0.0.1/32            trust
    
    
    • 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

    sgx-gdb

    路径:/opt/intel/sgxsdk/bin
    使用方式与gdb差不多

  • 相关阅读:
    vscode使用ssh连接远程Ubuntu服务器(记录)
    Spring Security认证器实现
    Springboot-‘@Getter‘ not applicable to type,报错是因为没有引用lombok依赖
    java本地运行spark代理示例
    png图片自动转ttf字体(使用python实现)
    游戏缺少dll文件用什么修复?教你多种dll文件修复方法搞定!
    【】如何实现异步通知的重试机制
    【Android音视频开发】音频编码原理
    Codesys 获取系统年、月、日、时、分、秒、星期几 +解决时区问题+ ST语言编程实现代码
    【Mars3d】进行水平测量measure.area({的时候,会被模型遮挡的处理方法
  • 原文地址:https://blog.csdn.net/weixin_40579705/article/details/133278726