blockchain - blockscout 的安装过程
访问量: 1548
完整版pdf:
https://files.sweetysoft.com/image_after_2022_12_14/4472/blockscout_安装过程.pdf
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 libgmp3-dev
安装erlang和elixir和nodejs
# 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)
# 下面是个完整的可用的东东( 2022-12-13) export NETWORK=Moonbeam export SUBNETWORK=Coreth export LOGO=/images/blockscout_logo.svg export LOGO_FOOTER=/images/blockscout_logo.svg # 对于moonbeam这样的网络,只能选择这个。 export ETHEREUM_JSONRPC_VARIANT=geth export ETHEREUM_JSONRPC_HTTP_URL=https://moonbeam.api.onfinality.io/rpc?apikey=c78dd454-f16f-4f67-8a03-67b316c4aaee export ETHEREUM_JSONRPC_TRACE_URL=https://moonbeam.api.onfinality.io/rpc?apikey=c78dd454-f16f-4f67-8a03-67b316c4aaee export ETHEREUM_JSONRPC_WS_URL=wss://moonbeam.api.onfinality.io/ws?apikey=c78dd454-f16f-4f67-8a03-67b316c4aaee # 这里必须是http export ETHEREUM_JSONRPC_TRANSPORT=http export SECRET_KEY_BASE=VTIB3uHDNbvrY0+60ZWgUoUBKDn9ppLR8MI4CpRz4/qLyEFs54ktJfaNT6Z221No export DATABASE_URL=postgresql://postgres:88888888@localhost:5432/blockscout export ETHEREUM_JSONRPC_DISABLE_ARCHIVE_BALANCES=false #export IPC_PATH= export NETWORK_PATH=/ export API_PATH=/ export SOCKET_ROOT=/ # 这里用localhost 就好,记得前端用caddy export BLOCKSCOUT_HOST=localhost export BLOCKSCOUT_PROTOCOL=http export CHECK_ORIGIN=false export PORT=4000 export COIN=GLMR export COIN_NAME=GLMR export REWARDS_CONTRACT=0xeca443e8e1ab29971a45a9c57a6a9875701698a5 export TOKEN_BRIDGE_CONTRACT=0x7301CFA0e1756B71869E93d4e4Dca5c7d0eb0AA6 export EMISSION_FORMAT=DEFAULT export POOL_SIZE=40 export POOL_SIZE_API=10 export ECTO_USE_SSL=false export DATADOG_HOST= export DATADOG_PORT= export SPANDEX_BATCH_SIZE=10 export SPANDEX_SYNC_THRESHOLD=100 export HEART_BEAT_TIMEOUT=30 #export HEART_COMMAND= #export BLOCKSCOUT_VERSION= #export RELEASE_LINK= #export ELIXIR_VERSION= export BLOCK_TRANSFORMER=base export LINK_TO_OTHER_EXPLORERS=false export OTHER_EXPLORERS={} export SUPPORTED_CHAINS={} export CACHE_BLOCK_COUNT_PERIOD=7200 export CACHE_TXS_COUNT_PERIOD=7200 export CACHE_ADDRESS_COUNT_PERIOD=7200 export CACHE_ADDRESS_SUM_PERIOD=3600 export CACHE_TOTAL_GAS_USAGE_PERIOD=3600 export CACHE_ADDRESS_TRANSACTIONS_GAS_USAGE_COUNTER_PERIOD=1800 export CACHE_TOKEN_HOLDERS_COUNTER_PERIOD=3600 export CACHE_TOKEN_TRANSFERS_COUNTER_PERIOD=3600 export CACHE_ADDRESS_WITH_BALANCES_UPDATE_INTERVAL=1800 export CACHE_AVERAGE_BLOCK_PERIOD=1800 export CACHE_MARKET_HISTORY_PERIOD=21600 export CACHE_ADDRESS_TRANSACTIONS_COUNTER_PERIOD=1800 export CACHE_ADDRESS_TOKENS_USD_SUM_PERIOD=1800 export CACHE_ADDRESS_TOKEN_TRANSFERS_COUNTER_PERIOD=1800 export CACHE_BRIDGE_MARKET_CAP_UPDATE_INTERVAL=1800 export CACHE_TOKEN_EXCHANGE_RATE_PERIOD=1800 export TOKEN_METADATA_UPDATE_INTERVAL=172800 export ALLOWED_EVM_VERSIONS=homestead,tangerineWhistle,spuriousDragon,byzantium,constantinople,petersburg,istanbul,berlin,london,default export UNCLES_IN_AVERAGE_BLOCK_TIME=false export DISABLE_WEBAPP=false export DISABLE_READ_API=false export DISABLE_WRITE_API=false export DISABLE_INDEXER=false export DISABLE_REALTIME_INDEXER=false export DISABLE_TOKEN_INSTANCE_FETCHER=false export INDEXER_DISABLE_PENDING_TRANSACTIONS_FETCHER=false export INDEXER_DISABLE_INTERNAL_TRANSACTIONS_FETCHER=false export INDEXER_CATCHUP_BLOCKS_BATCH_SIZE=10 export INDEXER_CATCHUP_BLOCKS_CONCURRENCY=10 export INDEXER_INTERNAL_TRANSACTIONS_BATCH_SIZE=10 export INDEXER_INTERNAL_TRANSACTIONS_CONCURRENCY=4 export INDEXER_COIN_BALANCES_BATCH_SIZE=500 export INDEXER_COIN_BALANCES_CONCURRENCY=4 export INDEXER_RECEIPTS_BATCH_SIZE=250 export INDEXER_RECEIPTS_CONCURRENCY=10 export TOKEN_ID_MIGRATION_FIRST_BLOCK=0 export TOKEN_ID_MIGRATION_CONCURRENCY=1 export TOKEN_ID_MIGRATION_BATCH_SIZE=500 #export WEBAPP_URL= #export API_URL= export WOBSERVER_ENABLED=false export SHOW_ADDRESS_MARKETCAP_PERCENTAGE=true export CHECKSUM_ADDRESS_HASHES=true export CHECKSUM_FUNCTION=eth export DISABLE_EXCHANGE_RATES=true export DISABLE_KNOWN_TOKENS=false export ENABLE_TXS_STATS=true export SHOW_PRICE_CHART=false export SHOW_TXS_CHART=true export HISTORY_FETCH_INTERVAL=60 export TXS_HISTORIAN_INIT_LAG=0 export TXS_STATS_DAYS_TO_COMPILE_AT_INIT=365 export COIN_BALANCE_HISTORY_DAYS=90 export APPS_MENU=false export EXTERNAL_APPS=[] export BRIDGE_MARKET_CAP_UPDATE_INTERVAL=1800 export SHOW_MAINTENANCE_ALERT=false export CUSTOM_CONTRACT_ADDRESSES_TEST_TOKEN= export ENABLE_SOURCIFY_INTEGRATION=false export MAX_SIZE_UNLESS_HIDE_ARRAY=50 export HIDE_BLOCK_MINER=false export DISPLAY_TOKEN_ICONS=false export SHOW_TENDERLY_LINK=false export MAX_STRING_LENGTH_WITHOUT_TRIMMING=2040 export API_RATE_LIMIT=50 export API_RATE_LIMIT_BY_KEY=50 export API_RATE_LIMIT_BY_IP=50 export FETCH_REWARDS_WAY=trace_block export ENABLE_RUST_VERIFICATION_SERVICE=true export RUST_VERIFICATION_SERVICE_URL=http://localhost:8043/ export VISUALIZE_SOL2UML_ENABLED=true export VISUALIZE_SOL2UML_SERVICE_URL=http://localhost:8050/ # 这两个千万不要留空。 #export DATABASE_READ_ONLY_API_URL= #export ACCOUNT_DATABASE_URL= export ACCOUNT_POOL_SIZE=100 export ACCOUNT_ENABLED=false export ACCOUNT_REDIS_URL=redis://localhost:6379
运行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
这里会报错,说几个路径找不到。我继续了。
(如果报警提示 secp256k 的内容,就这样)
mix deps.get
cd /opt/blockscout/deps/libsecp256k1/c_src; ./build_deps.sh; cd -
cd /opt/blockscout; mix do deps.get, local.rebar --force, deps.compile, compile
生成签名。 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
也可以使用快速启动脚本
restart_very_quickly, 内容如下:
source env_source
iex -S 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写死)