scifanchain / node

Scifanchain node based on substrate-node-template.
The Unlicense
2 stars 0 forks source link

创建第一条 赛凡 链 #2

Open stvenyin opened 3 years ago

stvenyin commented 3 years ago

基础环境:

虚拟机操作系统:Ubuntu 20.04

虚拟机ID地址:192.168.1.43

环境配置 安装依赖 cp /etc/apt/source.list /etc/apt/source.list.bak

vim source.list deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse

sudo apt update sudo apt upgrade sudo apt install -y git clang curl libssl-dev

安装v2ray [v2ray详细搭建使用|一键搞定繁琐的V2Ray配置 ](url)https://blog.codefat.cn/2020/11/15/v2ray%E8%AF%A6%E7%BB%86%E6%90%AD%E5%BB%BA%E4%BD%BF%E7%94%A8FanQ/

安装 Rust

安装

curl https://sh.rustup.rs -sSf | sh

rustup换源 在~/.bashrc中写入

export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup

cargo换源 在$HOME/.cargo/下创建config文件 并写入以下内容

[source.crates-io] registry = "https://github.com/rust-lang/crates.io-index" replace-with = 'ustc' [source.ustc] registry = "https://mirrors.ustc.edu.cn/crates.io-index" [http] check-revoke = false

配置

source ~/.cargo/env

将默认工具链配置为最新稳定版

rustup default stable rustup update

安装 nightly 编译链

rustup update nightly

给 nightly 编译链添加 wasm 编译target

rustup target add wasm32-unknown-unknown --toolchain nightly

编译 Scifanchain Node Scifanchain Node 是 Substrate Developer Hub 提供的一个基于 Substrate 框架的模板程序。 git clone https://github.com/scifanchain/node.git

编译

cd node cargo build --release

安装 scifanchain client scifanchain client 是 Substrate Developer Hub 提供的一个基于 ReactJS 的前端应用,用来与 Scifanchain Node 区块链进行交互。

安装 Node.js 安装:

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - sudo apt-get install -y nodejs https://substrate.dev/docs/zh-CN/tutorials/create-your-first-substrate-chain/setup 1.nvm 安装 https://blog.csdn.net/yanzhi_2016/article/details/87915573 2.nodejs配置淘宝源 3.安装yarn https://classic.yarnpkg.com/en/docs/install/#debian-stable yarn 配置淘宝源https://juejin.cn/post/6844903889087496200 Usage Error: This tool requires a Node version compatible with >=10.17 <14 || >14.1 (got 10.6.0). Upgrade Node, or set YARN_IGNORE_NODE=1 in your environment. node版本较低 https://translate.google.com.hk/translate?hl=zh-CN&sl=en&u=https://stackoverflow.com/questions/56617209/the-engine-node-is-incompatible-with-this-module&prev=search&pto=aue polkadot.js https://polkadot.js.org/docs/api/start/api.query

确认 root@stvenyin/ #node -v v14.16.1 root@stvenyin/ #npm -v 6.14.12

安装 Yarn 安装:

sudo npm install --global yarn

root@stvenyin# yarn -v 1.22.10

nginx做端口转发(很重要) 观察第一张启动成功的截图,可以发现服务启动在127.0.0.1上,这里我们只需要对127.0.0.1:9944做成端口转发就行,端口我设置为9900,以实现0.0.0.0:9900的效果。

vi /etc/nginx/substrate.conf

写入以下内容

server { listen 9900; # 将端口转发为9900

location / {
proxy_pass http://localhost:9944; # 指向本地服务端口
proxy_http_version 1.1;
proxy_read_timeout 120s;
proxy_redirect off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

} 配置nginx.conf

vi /etc/nginx/nginx.conf user nginx; worker_processes 1;

error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid;

events { worker_connections 1024; }

http { include /etc/nginx/mime.types; default_type application/octet-stream;

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

access_log  /var/log/nginx/access.log  main;

sendfile        on;
#tcp_nopush     on;

keepalive_timeout  65;

#gzip  on;
include /etc/nginx/conf.d/substrate.conf; # 引入substrate.conf

} 重新导入nginx配置

nginx -s reload tips:这里做成端口转发是十分有必要的,因为前端项目在宿主机访问的时候,会request ws://127.0.0.1:9944,这里的127.0.0.1:9944 就是我们nginx转发的端口,而且还是虚拟机的内网ip,所以不替换这里的ip和端口会导致前端项目运行失败。

安装 scifanchain client

git clone https://github.com/scifanchain/client.git

安装依赖

cd client yarn install yarn build yarn start

与节点交互 启动 Node cd node

在开发模式下启动一个临时节点

./target/release/node-template --dev --tmp

其中:

--dev -- 指定开发模式 --tmp -- 节点数据存放在临时目录 2021-06-18 10:01:22 Low open file descriptor limit configured for the process. Current value: 4096, recommended value: 10000. 2021-06-18 10:01:22 Running in --dev mode, RPC CORS has been disabled. 2021-06-18 10:01:22 Scifanchain 2021-06-18 10:01:22 ✌️ version 3.0.0-8ef6ab6-x86_64-linux-gnu 2021-06-18 10:01:22 ❤️ by Substrate DevHub https://github.com/substrate-developer-hub, 2017-2021 2021-06-18 10:01:22 📋 Chain specification: Development 2021-06-18 10:01:22 🏷 Node name: new-territory-4194 2021-06-18 10:01:22 👤 Role: AUTHORITY 2021-06-18 10:01:22 💾 Database: RocksDb at /tmp/substrateb7FlMO/chains/dev/db 2021-06-18 10:01:22 ⛓ Native runtime: node-template-100 (node-template-1.tx1.au1) 2021-06-18 10:01:22 🔨 Initializing Genesis block/state (state: 0xd2f3…3982, header-hash: 0x760e…0a06) 2021-06-18 10:01:22 👴 Loading GRANDPA authority set from genesis on what appears to be first startup. 2021-06-18 10:01:22 ⏱ Loaded block-time = 6s from genesis on first-launch 2021-06-18 10:01:22 Using default protocol ID "sup" because none is configured in the chain specs 2021-06-18 10:01:22 🏷 Local node identity is: 12D3KooWKVbnUt5A2cP8omywih8jkFZyVP2c7j9JP4hxtpouCWi8 2021-06-18 10:01:22 could not parse an IP from hosts file 2021-06-18 10:01:22 📦 Highest known block at #0 2021-06-18 10:01:22 〽️ Prometheus server started at 127.0.0.1:9615 2021-06-18 10:01:22 Listening for new connections on 127.0.0.1:9944. 2021-06-18 10:01:24 🙌 Starting consensus session on top of parent 0x760e66eaea1f993dcb68679a46228bfae8488bcf01b02b87cdaf48971e210a06 2021-06-18 10:01:24 🎁 Prepared block for proposing at 1 [hash: 0x93b907ca6ec9f9650fafecfd2341b52b59942ab9334db3e11eb41542013c0053; parent_hash: 0x760e…0a06; extrinsics (1): [0x13f0…9e31]] 2021-06-18 10:01:24 🔖 Pre-sealed block for proposal at 1. Hash now 0xe504e7f36a3276de5136e0f3a810db54a6544fde04e693692c17b3c4377fbeac, previously 0x93b907ca6ec9f9650fafecfd2341b52b59942ab9334db3e11eb41542013c0053. 2021-06-18 10:01:24 ✨ Imported #1 (0xe504…beac)

输出中包含:

Database: RocksDb at /tmp/substratezDF8TX/chains/dev/db Local node identity is: 12D3KooWPFAyHcXra35j5jnpdCS6FmvxKTuGHCJEFfAxjrmKWm2o

启动 scifanchain client cd client yarn start

https://polkadot.js.org/apps/#/settings?rpc=ws://127.0.0.1:9944,其中rpc=ws://127.0.0.1:9944表示通过websocket方式连接你本地节点

image

Compiled successfully!

You can now view substrate-front-end-template in the browser.

Local: http://localhost:8000/substrate-front-end-template On Your Network: http://192.168.1.43:8000/substrate-front-end-template

Note that the development build is not optimized. To create a production build, use yarn build. 交互 scifanchain client 在启动成功时,会自动打开浏览器展示下面的页面:

image

遇到的问题 在虚拟机外部无法访问 http://172.16.1.20:8000/scifanchain client ,浏览器提示下面的报错信息:

解决方法: 首先,在启动 Node 时,添加 --ws-external 参数。 ./target/release/node-template --dev --tmp --ws-external

然后,在启动 Front-End 前,修改 development.json 文件。 cd scifanchain/client/src/config

vim development.json 复制代码 将配置文件中的 127.0.0.1 改为实际的 IP 地址。 { "PROVIDER_SOCKET": "ws://127.0.0.1:9944" } // 改为 { "PROVIDER_SOCKET": "ws://192.168.1.43:9944" // 这是我的wsl虚拟机的IP } 相关资料 Create Your First Substrate Chain

Fixing "Error Connecting to Substrate" message in Substrate Front End Template End!

unityoxb commented 3 years ago

谢谢!我把它Copy到wiki上了,等有时间一起整理完善。

stvenyin commented 3 years ago

好的