|
| 1 | +使用的环境是Ubuntu 22.04. |
| 2 | +# 编译安装 |
| 3 | +需要安装的依赖以及编译官方源码的过程可以参考FISCO官方编译文档[5. 节点源码编译 — FISCO BCOS 3.0 v3.6.0 文档](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/tutorial/compile_binary.html) |
| 4 | +(建议安装v3.2.0版本) |
| 5 | +## 克隆代码 |
| 6 | +克隆我们的优化代码: |
| 7 | +```bash |
| 8 | +# 建议创建另一个编译目录,区别于官方源码 |
| 9 | +mkdir -p ~/TEPBFT && cd ~/TEPBFT |
| 10 | + |
| 11 | +# 克隆我们的优化代码 |
| 12 | +https://github.com/SICC-Group/TEP-BFT.gitt |
| 13 | + |
| 14 | +# 切换到源码目录 |
| 15 | +cd FISCO-BCOS |
| 16 | +``` |
| 17 | +## 编译 |
| 18 | +```bash |
| 19 | +# 进入源码目录 |
| 20 | +cd ~/TEPBFT/FISCO-BCOS |
| 21 | + |
| 22 | +# 创建编译目录 |
| 23 | +mkdir -p build && cd build |
| 24 | +cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_STATIC=ON |
| 25 | + |
| 26 | +# 编译源码(高性能机器可添加-j4使用4核加速编译) |
| 27 | +make -j4 |
| 28 | +# 如果上面这个命令卡的时间太长,可以make clean后改用下面这个命令: |
| 29 | +# make |
| 30 | + |
| 31 | +# 生成tgz包 |
| 32 | +rm -rf fisco-bcos-tars-service/*.tgz && make tar |
| 33 | +``` |
| 34 | +编译完的二进制文件位于**FISCO-BCOS/build/fisco-bcos-air/**路径下。 |
| 35 | +# 部署 |
| 36 | +## 安装SGX驱动程序 |
| 37 | +```bash |
| 38 | +# 更新apt源并安装软件 |
| 39 | +sudo apt update |
| 40 | +sudo apt-get install -y gcc git make vim curl |
| 41 | + |
| 42 | +# 克隆linux-sgx-driver仓库并编译 |
| 43 | +git clone https://github.com/intel/linux-sgx-driver |
| 44 | +cd linux-sgx-driver/ |
| 45 | +make |
| 46 | + |
| 47 | +# 安装驱动 |
| 48 | +sudo mkdir -p "/lib/modules/$(uname -r)/kernel/drivers/intel/sgx" |
| 49 | +sudo cp isgx.ko "/lib/modules/$(uname -r)/kernel/drivers/intel/sgx" |
| 50 | +sudo sh -c "grep -qxF 'isgx' /etc/modules || echo 'isgx' >> /etc/modules" |
| 51 | +sudo depmod |
| 52 | +sudo modprobe isgx |
| 53 | +lsmod | grep isgx |
| 54 | +``` |
| 55 | +## 安装SGX PSW |
| 56 | +```bash |
| 57 | +cd ~ |
| 58 | +# 添加SGX仓库并安装依赖 |
| 59 | +echo 'deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu jammy main' | sudo tee /etc/apt/sources.list.d/intel-sgx.list |
| 60 | +wget "https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key" |
| 61 | +sudo apt-key add intel-sgx-deb.key |
| 62 | +sudo apt update |
| 63 | +sudo apt-get install -y libssl-dev libcurl4-openssl-dev libprotobuf-dev |
| 64 | + |
| 65 | +# 安装SGX相关库 |
| 66 | +sudo apt-get install -y libsgx-launch libsgx-urts libsgx-epid libsgx-quote-ex libsgx-dcap-ql |
| 67 | +``` |
| 68 | +## 安装Gramine包 |
| 69 | +```bash |
| 70 | +# 添加gramine仓库并安装 |
| 71 | +sudo curl -fsSLo /usr/share/keyrings/gramine-keyring.gpg https://packages.gramineproject.io/gramine-keyring.gpg |
| 72 | +echo "deb [arch=amd64 signed-by=/usr/share/keyrings/gramine-keyring.gpg] https://packages.gramineproject.io/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/gramine.list |
| 73 | +sudo curl -fsSLo /usr/share/keyrings/intel-sgx-deb.asc https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key |
| 74 | +echo "deb [arch=amd64 signed-by=/usr/share/keyrings/intel-sgx-deb.asc] https://download.01.org/intel-sgx/sgx_repo/ubuntu jammy main" | sudo tee /etc/apt/sources.list.d/intel-sgx.list |
| 75 | +sudo apt-get update |
| 76 | +sudo apt-get install -y gramine |
| 77 | + |
| 78 | +# 生成SGX私钥 |
| 79 | +sudo gramine-sgx-gen-private-key |
| 80 | + |
| 81 | +# 安装32位库 |
| 82 | +sudo apt-get install -y lib32stdc++6 lib32z1 |
| 83 | +``` |
| 84 | +## 搭建网络 |
| 85 | +```bash |
| 86 | +cd TEPBFT |
| 87 | +curl -#LO https://osp-1257653870.cos.ap-guangzhou.myqcloud.com/FISCO-BCOS/FISCO-BCOS/releases/v3.2.0/build_chain.sh |
| 88 | + |
| 89 | +# 这代码作用是通过build脚本搭建多机节点,ip根据服务器私网ip修改 |
| 90 | +# 只在一台服务器中运行这个命令就行 |
| 91 | +# 已经搭建过需要先删除nodes文件夹,再搭建 |
| 92 | +bash build_chain.sh -p 30300,20200 -l [私网IP]:1,[私网IP]:1,[私网IP]:1,[私网IP]:1 |
| 93 | + |
| 94 | + |
| 95 | +# 创建Makefile fisco-bcos.manifest.template,填充内容 |
| 96 | +# 位置应该在每个服务器的nodes/服务器私网IP/node0/下 |
| 97 | +cd ~/fisco/nodes/私网IP/node0/ |
| 98 | +vim Makefile |
| 99 | +# 填充文件内容如最后 |
| 100 | +vim fisco-bcos.manifest.template |
| 101 | +# 填充文件内容如最后 |
| 102 | + |
| 103 | +# 将编译得到的fisco-bcos二进制可执行程序、Makefile和fisco-bcos.manifest.template复制到每个服务器或物理机的节点文件夹中 |
| 104 | +cp fisco-bcos Makefile fisco-bcos.manifest.template ~/fisco/nodes/[私网IP]/node0/ |
| 105 | + |
| 106 | +# 启动所有的服务器或物理机,创建对应文件夹 |
| 107 | +mkdir -p ~/fisco/nodes |
| 108 | + |
| 109 | +# 使用公网IP把文件夹分别复制到各自节点的服务器上 |
| 110 | +# 注意公私网IP地址要对应好,公网IP会更换 |
| 111 | +scp -r ~/fisco/nodes/[私网IP]/ root@[公网IP]:~/fisco/nodes |
| 112 | + |
| 113 | + |
| 114 | +# 修改openssl文件 |
| 115 | +sudo vim /etc/ssl/openssl.cnf |
| 116 | +# 注释掉 |
| 117 | +# providers = provider_sect |
| 118 | + |
| 119 | +# 编译 |
| 120 | +cd ~/fisco/nodes/[私网IP]/node0/ |
| 121 | +make SGX=1 |
| 122 | +``` |
| 123 | +# 运行 |
| 124 | +```bash |
| 125 | +# 在~/fisco/nodes/[私网IP]/node0/下 |
| 126 | +# 每台机器这样启动,直接命令行输入 |
| 127 | +sudo gramine-sgx fisco-bcos -c config.ini -g config.genesis |
| 128 | +``` |
| 129 | +# 压测 |
| 130 | +参考FISCO官方的压测文件[9. 压力测试指南](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/operation_and_maintenance/stress_testing.html) |
| 131 | +# 配置文件 |
| 132 | +## Makefile |
| 133 | +```bash |
| 134 | +# none/error/warning/debug/trace/all |
| 135 | +GRAMINE_LOG_LEVEL = error |
| 136 | +# directory with arch-specific libraries, used by Redis |
| 137 | +# the below path works for Debian/Ubuntu; for CentOS/RHEL/Fedora, you should |
| 138 | +# overwrite this default like this: `ARCH_LIBDIR=/lib64 make` |
| 139 | +ARCH_LIBDIR ?= /lib/$(shell $(CC) -dumpmachine) |
| 140 | + |
| 141 | +.PHONY: all |
| 142 | +all: fisco-bcos.manifest.sgx fisco-bcos.sig |
| 143 | + |
| 144 | +fisco-bcos.manifest: fisco-bcos.manifest.template |
| 145 | + gramine-manifest \ |
| 146 | + -Dlog_level=$(GRAMINE_LOG_LEVEL) \ |
| 147 | + -Darch_libdir=$(ARCH_LIBDIR) \ |
| 148 | + $< >$@ |
| 149 | + |
| 150 | +fisco-bcos.sig fisco-bcos.manifest.sgx: sgx_sign |
| 151 | + @: |
| 152 | + |
| 153 | +.INTERMEDIATE: sgx_sign |
| 154 | +sgx_sign: fisco-bcos.manifest fisco-bcos |
| 155 | + gramine-sgx-sign \ |
| 156 | + --manifest $< \ |
| 157 | + --output $<.sgx |
| 158 | + |
| 159 | +.PHONY: clean |
| 160 | +clean: |
| 161 | + $(RM) *.token *.sig *.manifest.sgx *.manifest |
| 162 | + |
| 163 | +.PHONY: distclean |
| 164 | +distclean: clean |
| 165 | +``` |
| 166 | +## fisco-bcos.manifest.template |
| 167 | +```bash |
| 168 | +# Redis manifest file example |
| 169 | + |
| 170 | +################################## GRAMINE #################################### |
| 171 | + |
| 172 | +loader.entrypoint = "file:{{ gramine.libos }}" |
| 173 | + |
| 174 | +libos.entrypoint = "/fisco-bcos" |
| 175 | + |
| 176 | +loader.log_level = "{{ log_level }}" |
| 177 | + |
| 178 | +#loader.pal_internal_mem_size = "1G" |
| 179 | + |
| 180 | +loader.insecure__use_cmdline_argv = true |
| 181 | + |
| 182 | +################################# ENV VARS #################################### |
| 183 | + |
| 184 | +loader.env.LD_LIBRARY_PATH = "/lib:{{ arch_libdir }}:/usr/{{ arch_libdir }}" |
| 185 | + |
| 186 | +################################## SIGNALS #################################### |
| 187 | + |
| 188 | +sys.enable_sigterm_injection = true |
| 189 | + |
| 190 | +################################# MOUNT FS ################################### |
| 191 | + |
| 192 | +fs.mounts = [ |
| 193 | + { path = "/lib", uri = "file:{{ gramine.runtimedir() }}" }, |
| 194 | + |
| 195 | + { path = "{{ arch_libdir }}", uri = "file:{{ arch_libdir }}" }, |
| 196 | + |
| 197 | + { path = "/usr/{{ arch_libdir }}", uri = "file:/usr/{{ arch_libdir }}" }, |
| 198 | + |
| 199 | + { path = "/etc", uri = "file:/etc" }, |
| 200 | + |
| 201 | + { path = "/fisco-bcos", uri = "file:fisco-bcos" }, |
| 202 | +] |
| 203 | + |
| 204 | +############################### SGX: GENERAL ################################## |
| 205 | + |
| 206 | +sgx.debug = true |
| 207 | + |
| 208 | +sgx.enclave_size = "8192M" |
| 209 | + |
| 210 | +sgx.max_threads = 1024 |
| 211 | + |
| 212 | +#sgx.rpc_thread_num = 64 |
| 213 | + |
| 214 | +#sgx.enable_status = true |
| 215 | + |
| 216 | +#sgx.profile.with_stack = true |
| 217 | + |
| 218 | +#sgx.profile.enable = "all" |
| 219 | + |
| 220 | +#sgx.profile.mode = "ocall_outer" |
| 221 | + |
| 222 | +################################## Thread Size |
| 223 | +#################################### |
| 224 | + |
| 225 | +sys.stack.size = "218K" |
| 226 | + |
| 227 | +sgx.file_check_policy = "allow_all_but_log" |
| 228 | + |
| 229 | +sgx.nonpie_binary = true |
| 230 | + |
| 231 | +############################# SGX: TRUSTED FILES ############################### |
| 232 | + |
| 233 | +sgx.trusted_files = [ |
| 234 | + "file:{{ gramine.libos }}", |
| 235 | + "file:fisco-bcos", |
| 236 | + "file:{{ gramine.runtimedir() }}/", |
| 237 | + "file:{{ arch_libdir }}/", |
| 238 | + "file:/usr/{{ arch_libdir }}/", |
| 239 | +] |
| 240 | + |
| 241 | +############################# SGX: ALLOWED FILES ############################### |
| 242 | + |
| 243 | +sgx.allowed_files = [ |
| 244 | + # Name Service Switch (NSS) files. Glibc reads these files as part of name- |
| 245 | + # service information gathering. For more info, see 'man nsswitch.conf'. |
| 246 | + "file:/etc/nsswitch.conf", |
| 247 | + "file:/etc/ethers", |
| 248 | + "file:/etc/hosts", |
| 249 | + "file:/etc/group", |
| 250 | + "file:/etc/passwd", |
| 251 | + # getaddrinfo(3) configuration file. Glibc reads this file to correctly find |
| 252 | + # network addresses. For more info, see 'man gai.conf'. |
| 253 | + "file:/etc/gai.conf", |
| 254 | +] |
| 255 | +``` |
0 commit comments