宛十八区块链研发

BlockScont 浏览器搭建教程

2020-09-02  本文已影响0人  一个脱离高级趣味的人

BlockScont 浏览器搭建教程

BlockScont 是一个开源的以太坊浏览器,如官方所说

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.

这里用它来为我们自己的公链(基于以太坊)搭建一个浏览器。

准备

安装之前我们需要先准备运行 BlockScont 所需要的环境,根据官方提供的信息我们需要先安装以下环境

Dependency Mac Linux
Erlang/OTP 22 brew install erlang Erlang Install Example
Elixir 1.9.1-4 brew install elixir Elixir Install Example
Postgres 10.3+ brew install postgresql Postgres Install Example
Node.js 12.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 9Erlang

Erlang 安装

根据官方提供 Demo 我们需要分别运行以下命令

wget https://packages.erlang-solutions.com/erlang/rpm/centos/7/x86_64/esl-erlang_22.0-1~centos~7_amd64.rpm
yum install -y wxGTK-devel unixODBC-devel
yum install -y esl-erlang_22.0-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 安装

分别执行以下命令

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

之后配置环境变量

vi /etc/profile   

然后在行末加入

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

然后让配置生效

source /etc/profile

最后验证是否成功安装

[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安装

依次执行如下命令

# 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"

修改数据库的访问权限

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

设置允许远程访问数据库

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)

然后重启数据库

systemctl restart postgresql-12

之后修改 postgres 账户的默认密码

# 切换到postgres账户
su postgres
 
# 进入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

修改数据库存储目录

# 停掉数据库
service postgresql-12 stop
# 将旧数据复制到新的目录
cp -rf /var/lib/pgsql/12/ /vdb1/blockscout/pgsql/12/
# 设置用户和权限
chown -R postgres:postgres /vdb1/blockscout/pgsql/12/
chmod 700 /vdb1/blockscout/pgsql/12/
# 修改配置文件数据存储目录路径
find / -name postgresql-12.service
vi /usr/lib/systemd/system/postgresql-12.service
修改新的路径
# Location of database directory
Environment=PGDATA=/vdb1/blockscout/pgsql/12/data
# 重启数据库服务
service postgresql-12 start
# 验证修改是否生效
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

依次运行一下命令

# 下载源代码包
wget https://nodejs.org/dist/v12.16.1/node-v12.16.1-linux-x64.tar.xz
 
# 解压源代码包
tar -xf node-v12.16.1-linux-x64.tar.xz
 
# 重命名
mv node-v12.16.1-linux-x64 nodejs
 
# 设置软连接,必须指定到可执行的node、npm文件哦~
ln -s /vdb1/blockscout/nodejs/bin/node /usr/bin/node
ln -s /vdb1/blockscout/nodejs/bin/npm /usr/bin/npm
 
 
# 设置环境变量,请根据你的安装目录进行设置
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

部署BlockScout

拉取源码

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

生成 secret_key_base ,时间比较久需要耐心等待

mix deps.get
mix phx.gen.secret

然后添加环境变量

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依赖和编译应用程序

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

删除、创建和迁移数据库

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

如果出现如下错误

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.

尝试执行命令

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

建立用于部署的静态资产,执行命令

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

启动应用

回到项目根目录执行命令

mix phx.server

最后打开浏览器做测试
http://localhost:4000

修改默认配置,修改UI后面有时间再写吧。

上一篇下一篇

猜你喜欢

热点阅读