blockchain - blockscout 的安装过程

访问量: 220

blockscout是用来监控链上信息的

https://github.com/blockscout/blockscout

配置需求参考 https://docs.blockscout.com/for-developers/information-and-settings/requirements

手动安装参考:https://docs.blockscout.com/for-developers/manual-deployment

更新apt

apt update

安装各种第三方包

sudo apt-get install libapr1-dev libxml2-dev libxslt1-dev libmysqlclient-dev git curl build-essential libssl-dev libreadline-dev build-essential libssl-dev libreadline-dev vim libcurl4 ruby-dev zlib1g-dev liblzma-dev ruby-all-dev

apt install postgresql automake libtool gcc make g++ cargo  libgmp-dev

安装erlang和elixir和nodejs

使用asdf 来安装。
具体过程在这里:  http://siwei.me/blog/posts/erlang-asdf-erlang-elixir-nodejs-ruby

# install rust

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

安装node

install nvm & node

curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash

nvm install 14.18.3

安装rust

apt remove cargo # 删掉apt 自己下载的cargo

apt autoremove  # 删掉 rustc

asdf install rust 1.58.1   #安装最新版本的rust

然后看这里:https://docs.blockscout.com/for-developers/manual-deployment

$ git clone https://github.com/poanetwork/blockscout

运行下面的命令

(具体见这个说明页面,里面包含了一个csv:  https://docs.blockscout.com/for-developers/information-and-settings/env-variables)

export NETWORK=Ethereum
export SUBNETWORK=Coreth
export LOGO=/images/blockscout_logo.svg
export LOGO_FOOTER=/images/blockscout_logo.svg
export ETHEREUM_JSONRPC_VARIANT=parity
export ETHEREUM_JSONRPC_HTTP_URL=api.avax-test.network/ext/bc/C/rpc
export ETHEREUM_JSONRPC_TRACE_URL=api.avax-test.network/ext/bc/C/rpc
export ETHEREUM_JSONRPC_WS_URL=wss://api.avax-test.network/ext/bc/C/rpc
export ETHEREUM_JSONRPC_TRANSPORT=https
export SECRET_KEY_BASE=VTIB3uHDNbvrY0+60ZWgUoUBKDn9ppLR8MI4CpRz4/qLyEFs54ktJfaNT6Z221No
export PORT=4000
export COIN=AVAX
export DATABASE_URL=postgresql://aaa:123456@localhost:5432/blockscout

运行elixir命令,编译和安装代码:

git checkout -b 4.1.0 v4.1.0-beta   ( 如果4.1.0 也不行的话,就4.0.0)

asdf install erlang 24.2

asdf install rust 1.55.0  ( 这里不要用最新的1.58.0 , 会报错 keccak256 编译有问题)

mix do deps.get, local.rebar --force, deps.compile, compile

# mix do deps.get, local.rebar --force, deps.compile, compile
Could not find Hex, which is needed to build dependency :tesla
Shall I install Hex? (if running non-interactively, use "mix local.hex --force") [Yn] 
* creating /root/.asdf/installs/elixir/1.12.3-otp-24/.mix/archives/hex-1.0.1
Resolving Hex dependencies...
Dependency resolution completed:
Unchanged:
  absinthe 1.6.5
  absinthe_phoenix 2.0.2
  absinthe_relay 1.5.1
  accept 0.3.5
  bcrypt_elixir 1.1.1

................... 经过漫长的等待(10分钟?)
==> phoenix_ecto
Compiling 7 files (.ex)
Generated phoenix_ecto app
==> block_scout_web
Compiling 201 files (.ex)
Generating BlockScoutWeb.Cldr for 2 locales named ["en", "root"] with a default locale named "en"

09:24:47.199 [debug] Current global API rate limit 50 reqs/sec

09:24:47.206 [debug] Current API rate limit by key 50 reqs/sec

09:24:47.206 [debug] Current API rate limit by IP 50 reqs/sec
Generated block_scout_web app# mix do deps.get, local.rebar --force, deps.compile, compile
Could not find Hex, which is needed to build dependency :tesla
Shall I install Hex? (if running non-interactively, use "mix local.hex --force") [Yn]
* creating /root/.asdf/installs/elixir/1.12.3-otp-24/.mix/archives/hex-1.0.1
Resolving Hex dependencies...
Dependency resolution completed:
Unchanged:
absinthe 1.6.5
absinthe_phoenix 2.0.2
absinthe_relay 1.5.1
accept 0.3.5
bcrypt_elixir 1.1.1

保证postgrest运行中(说了一句废话,我从官方文档照搬过来的)

创建和运行数据库迁移:mix do ecto.create, ecto.migrate

....
10:08:18.105 [info]  == Migrated 20211206071033 in 0.0s

10:08:18.107 [info]  == Running 20220111085751 Explorer.Repo.Migrations.AddressAddCounters.change/0 forward

10:08:18.107 [info]  alter table addresses

10:08:18.107 [info]  == Migrated 20220111085751 in 0.0s

开始安装nodejs的各种依赖:

cd <your block scout folder>

cd apps/block_scout_web/assets; npm install && node_modules/webpack/bin/webpack.js --mode production; cd -

webpack 5.61.0 compiled with 3 warnings in 606558 ms

asset dropzone.min.js 112 KiB [emitted] [minimized] (name: dropzone)
runtime modules 663 bytes 3 modules
cacheable modules 333 KiB
  ./js/lib/dropzone.js 18 bytes [built] [code generated]
  ./node_modules/dropzone/dist/dropzone.js 333 KiB [built] [code generated]
webpack 5.61.0 compiled successfully in 8906 ms

这里会等好长时间。大概20分钟以上

然后继续:

cd apps/explorer && npm install; cd -

生成静态文件:

mix phx.digest  

这里会报错,说几个路径找不到。我继续了。

生成签名。 phenix 不用https不能访问,据说。

cd apps/block_scout_web; mix phx.gen.cert blockscout blockscout.local; cd -

修改 /etc/hosts  ,  把 blockscout blockscout.local 加进来

127.0.0.1 localhost blockscout blockscout.local 

修改浏览 器:(参考:https://stackoverflow.com/questions/50819206/is-there-a-equivalent-of-allow-insecure-localhost-flag-of-google-chrome-in-firef )

chrome:  Enable chrome://flags/#allow-insecure-localhost

firefox:  about:config ->  network.websocket.allowInsecureFromHTTPS  选择true

终于配置好了。

启动:

mix phx.server

遇到了各种坑

坑0. 官方文档的 system ENV ,列表,有问题

不能只设置文档中要求的15+个变量

需要把所有用到的变量都设置上去

否则会报错

坑1. DATADOG_PORT 的设置,这里有问题。

无论是用不用双引号,都会报错,

报错原因:can not convert string into integer 类似的话。。

解决办法:找到报错的app:   apps/explorer/lib/explorer/application.ex

直接把value写死。(或者在System.get_env 之后,把对应的结果手动转换成 int. )

坑3: left value not match ...

这里会出现很多次。需要慢慢调试。

1. 找到报错的 ex文件(这个提示中没有,很不友好,需要根据上一条报错的app来找到。)

例如:

** (Mix) Could not start application explorer: Explorer.Application.start(:normal, []) returned an error: shutdown: failed to start child: Explorer.Chain.Events.Listener
    ** (EXIT) an exception was raised:
        ** (KeyError) key :password not found in: [types: nil, types: Postgrex.DefaultTypes, username: "root", sync_connect: true, hostname: "localhost", database: "blockscout", migration_timestamps: [type: :utc_datetime_usec], url: "postgresql://myroot:123456@localhost:5432/blockscout", pool_size: 20, timeout: 80000]
            (elixir 1.12.3) lib/keyword.ex:420: Keyword.fetch!/2
            (postgrex 0.15.10) lib/postgrex/protocol.ex:778: Postgrex.Protocol.auth_md5/4

光看报错信息是不知道是哪个文件的,所以,需要根据class的名称: Explorer.Application, 找到对应的ex文件:

2022-01-25T09:59:36.118 [info] Application explorer exited: Explorer.Application.start(:normal, []) returned an error: shutdown: failed to start child: Explorer.Chain.Events.Listener
    ** (EXIT) an exception was raised:
        ** (KeyError) key :password not found in: [types: nil, types: Postgrex.DefaultTypes, username: "root", sync_connect: true, hostname: "localhost", database: "blockscout", migration_timestamps: [type: :utc_datetime_usec], url: "postgresql://myroot:123456@localhost:5432/blockscout", pool_size: 20, timeout: 80000]

所以找到对应的  apps/explorer/lib/explorer/chain/events/listener.ex

进行修改即可:

    {:ok, pid} =
       explorer_repo
       |> Notifications.start_link()
修改成:

    temp =  explorer_repo
       |> Notifications.start_link()
    IO.puts "=== temp is: #{ inspect temp}"
    {:ok, pid} = temp

这样的话,报错信息就会可读可理解了,变成下图所示:

** (KeyError) key :password not found in: [types: nil, types: Postgrex.DefaultTypes, username: "root", sync_connect: true, hostname: "localhost", database: "blockscout", migration_timestamps: [type: :utc_datetime_usec], url: "postgresql://myroot:123456@localhost:5432/blockscout", pool_size: 20, timeout: 80000]

我们就知道,原来缺少了password ,就可以针对性的做代码的调整了 (下面截图是把password写死)

订阅/RSS Feed

Subscribe

分类/category