BlockScout 瀏覽器搭建教程

BlockScout 瀏覽器搭建教程

BlockScout 是一個開源的以太坊瀏覽器,如官方所說

BlockScout is an Elixir application that allows users to search transactions, view accounts and balances, and verify smart contracts on the Ethereum network including all forks and sidechains.

Currently available full-featured block explorers (Etherscan, Etherchain, Blockchair) are closed systems which are not independently verifiable. As Ethereum sidechains continue to proliferate in both private and public settings, transparent, open-source tools are needed to analyze and validate transactions.

這里用它來為我們自己的公鏈(基于以太坊)搭建一個瀏覽器。

準(zhǔn)備

安裝之前我們需要先準(zhǔn)備運(yùn)行 BlockScout 所需要的環(huán)境,根據(jù)官方提供的信息我們需要先安裝以下環(huán)境

Dependency Mac Linux
Erlang/OTP 23 brew install erlang Erlang Install Example
Elixir 1.10.x brew install elixir Elixir Install Example
Postgres 10.3+,11,12 brew install postgresql Postgres Install Example
Node.js 14.x.x brew install node Node.js Install Example
Automake brew install automake Automake Install Example
Libtool brew install libtool Libtool Install Example
Inotify-tools Not Required Ubuntu - apt-get install inotify-tools
GCC Compiler brew install gcc GCC Compiler Example
GMP brew install gmp Install GMP Devel
Make - sudo apt install makeif Debian 9
G++ Compiler - sudo apt install g++if Debian 9
Rust - Install Rust

Erlang 安裝

根據(jù)官方提供 Demo 我們需要分別運(yùn)行以下命令

wget https://packages.erlang-solutions.com/erlang/rpm/centos/7/x86_64/esl-erlang_23.2.1-1~centos~7_amd64.rpm
yum install -y wxGTK-devel unixODBC-devel
yum install -y esl-erlang_23.2.1-1~centos~7_amd64.rpm

安裝完成之后查看是否安裝成功,成功界面如下

[root@test]# erl
Erlang/OTP 21 [erts-10.0.5] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Eshell V10.0.5  (abort with ^G)

Elixir 安裝

分別執(zhí)行以下命令

wget https://github.com/elixir-lang/elixir/releases/download/v1.10.0/Precompiled.zip
unzip Precompiled.zip -d /opt/elixir

之后配置環(huán)境變量

vi /etc/profile   

然后在行末加入

export PATH="$PATH:/opt/elixir/bin"

然后讓配置生效

source /etc/profile

最后驗(yàn)證是否成功安裝

[root@test]# elixir -v
Erlang/OTP 21 [erts-10.0.5] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Elixir 1.9.4 (compiled with Erlang/OTP 20)

PostgresSQL安裝

依次執(zhí)行如下命令

# Install the repository RPM:
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

# Install PostgreSQL:
yum install postgresql12-server

# Optionally initialize the database and enable automatic start:
/usr/pgsql-12/bin/postgresql-12-setup initdb
systemctl enable postgresql-12
systemctl start postgresql-12

# Initialize environment variables
# export PATH="/usr/pgsql-12/bin:$PATH"
# export LD_LIBRARY_PATH="/usr/pgsql-12/lib"
export PATH="$PATH:/opt/elixir/bin:/usr/pgsql-12/bin"
export LD_LIBRARY_PATH="/usr/pgsql-12/lib"

修改數(shù)據(jù)庫的訪問權(quán)限

vi /var/lib/pgsql/12/data/pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     md5
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5

設(shè)置允許遠(yuǎn)程訪問數(shù)據(jù)庫

vi /var/lib/pgsql/12/data/postgresql.conf

# - Connection Settings -

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)
max_connections = 100                           # (change requires restart)

然后重啟數(shù)據(jù)庫

systemctl restart postgresql-12

之后修改 postgres 賬戶的默認(rèn)密碼

# 切換到postgres賬戶
su postgres
 
# 進(jìn)入SQL Shell
psql
 
# 鍵入如下指令,修改密碼,筆者將密碼修改為postgres。
ALTER USER postgres WITH PASSWORD 'postgres';
 
# 鍵入 “\q”退出SQL Shell,鍵入exit登出postgres賬戶
\q
 
exit
 
# 最后,測試一下是否修改成功,鍵入密碼
psql -h 127.0.0.1 -p 5432 -U postgres -W

修改數(shù)據(jù)庫存儲目錄

# 停掉數(shù)據(jù)庫
service postgresql-12 stop
# 將舊數(shù)據(jù)復(fù)制到新的目錄
cp -rf /var/lib/pgsql/12/ /vdb1/blockscout/pgsql/12/
# 設(shè)置用戶和權(quán)限
chown -R postgres:postgres /vdb1/blockscout/pgsql/12/
chmod 700 /vdb1/blockscout/pgsql/12/
# 修改配置文件數(shù)據(jù)存儲目錄路徑
find / -name postgresql-12.service
vi /usr/lib/systemd/system/postgresql-12.service
修改新的路徑
# Location of database directory
Environment=PGDATA=/vdb1/blockscout/pgsql/12/data
# 重啟數(shù)據(jù)庫服務(wù)
service postgresql-12 start
# 驗(yàn)證修改是否生效
su postgres
psql
show data_directory;

安裝PostGIS

yum -y install epel-release 

yum install postgis30_12.x86_64 postgis30_12-client.x86_64 postgis30_12-debuginfo.x86_64 postgis30_12-devel.x86_64 postgis30_12-docs.x86_64 postgis30_12-gui.x86_64 postgis30_12-utils.x86_64

安裝NodeJs

依次運(yùn)行一下命令

# 下載源代碼包
wget https://nodejs.org/dist/v15.8.0/node-v15.8.0-linux-x64.tar.xz
 
# 解壓源代碼包
tar -xf node-v15.8.0-linux-x64.tar.xz
 
# 重命名
mv node-v15.8.0-linux-x64 nodejs
 
# 設(shè)置軟連接,必須指定到可執(zhí)行的node、npm文件哦~
ln -s /vdb1/blockscout/nodejs/bin/node /usr/bin/node
ln -s /vdb1/blockscout/nodejs/bin/npm /usr/bin/npm
 
 
# 設(shè)置環(huán)境變量,請根據(jù)你的安裝目錄進(jìn)行設(shè)置
export PATH="$PATH:/vdb1/blockscout/nodejs/bin"

測試安裝是否成功

node -v
npm -v

安裝Automake

yum --enablerepo=epel group install -y "Development Tools"

安裝Libtool

yum install -y libtool

安裝Inotify-tools

yum install inotify-tools

安裝GCC Compiler

yum install -y gcc-c++

安裝GMP

yum --enablerepo=epel install -y gmp-devel

安裝Make

yum install make

安裝Rust

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

部署B(yǎng)lockScout

拉取源碼

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

生成 secret_key_base ,時(shí)間比較久需要耐心等待

mix deps.get
mix phx.gen.secret

然后添加環(huán)境變量

export DATABASE_URL="postgresql://postgres:postgres@localhost:5432/blockscout"
 
export DB_HOST=localhost
export DB_PASSWORD=postgres
export DB_PORT=5432
export DB_USERNAME=postgres

export SECRET_KEY_BASE="your key"

export ETHEREUM_JSONRPC_VARIANT=geth
export ETHEREUM_JSONRPC_HTTP_URL="http://localhost:8545"
export ETHEREUM_JSONRPC_WS_URL="ws://localhost:8545"

export SUBNETWORK= MAINNET

export PORT=4000
export COIN="Test Coin"

安裝Mix依賴和編譯應(yīng)用程序

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

刪除、創(chuàng)建和遷移數(shù)據(jù)庫

mix do ecto.drop, ecto.create, ecto.migrate

安裝Node.js依賴

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

如果出現(xiàn)如下錯誤

gyp WARN EACCES current user does not have permission to access the dev dir "/root/.cache/node-gyp/12.16.1"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/vdb1/blockscout/blockscout/apps/block_scout_web/assets/node_modules/keccak/.node-gyp"
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/vdb1/blockscout/blockscout/apps/block_scout_web/assets/node_modules/keccak/.node-gyp'
gyp ERR! System Linux 3.10.0-1127.13.1.el7.x86_64
gyp ERR! command "/vdb1/blockscout/nodejs/bin/node" "/vdb1/blockscout/nodejs/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /vdb1/blockscout/blockscout/apps/block_scout_web/assets/node_modules/keccak
gyp ERR! node -v v12.16.1
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! keccak@2.1.0 rebuild: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the keccak@2.1.0 rebuild script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Keccak bindings compilation fail. Pure JS implementation will be used.

嘗試執(zhí)行命令

sudo npm install && node_modules/webpack/bin/webpack.js --mode production -g --unsafe-perm

建立用于部署的靜態(tài)資產(chǎn),執(zhí)行命令

cd apps/block_scout_web/
mix phx.digest

啟用HTTPS

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

然后配置 /etc/hosts

vi /etc/hosts

::1 localhost   localhost.localdomain   localhost6  localhost6.localdomain6     blockscout blockscout.local
127.0.0.1   localhost   localhost.localdomain   localhost4  localhost4.localdomain4     blockscout blockscout.local

啟動應(yīng)用

回到項(xiàng)目根目錄執(zhí)行命令

mix phx.server

最后打開瀏覽器做測試
http://localhost:4000

修改默認(rèn)配置,修改UI后面有時(shí)間再寫吧。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容