FISCO BCOS實(shí)踐:
(一)搭建單群組聯(lián)盟鏈
(二)使用PythonSDK部署和測(cè)試智能合約
(三)部署和使用WeBASE管理平臺(tái)(本章)
二、部署和使用WeBASE管理平臺(tái)
1. 簡(jiǎn)介
微眾銀行開(kāi)源的自研區(qū)塊鏈中間件平臺(tái)——WeBASE是區(qū)塊鏈應(yīng)用和FISCO BCOS節(jié)點(diǎn)之間搭建的中間件平臺(tái)愧薛。WeBASE屏蔽了區(qū)塊鏈底層的復(fù)雜度啄枕,降低區(qū)塊鏈?zhǔn)褂玫拈T(mén)檻攒菠,大幅提高區(qū)塊鏈應(yīng)用的開(kāi)發(fā)效率,包含節(jié)點(diǎn)前置、節(jié)點(diǎn)管理命浴、交易鏈路,數(shù)據(jù)導(dǎo)出贱除,Web管理平臺(tái)等子系統(tǒng)生闲。用戶(hù)可以根據(jù)業(yè)務(wù)所需,選擇子系統(tǒng)進(jìn)行部署月幌,可以進(jìn)一步體驗(yàn)豐富交互的體驗(yàn)碍讯、可視化智能合約開(kāi)發(fā)環(huán)境IDE。
WeBASE管理平臺(tái)是由四個(gè)WeBASE子系統(tǒng)組成的一套管理FISCO-BCOS聯(lián)盟鏈的工具集扯躺。詳細(xì)了解可以參考《WeBASE管理平臺(tái)使用手冊(cè)》 捉兴。
這里使用一鍵部署,可以在同機(jī)快速搭建WeBASE管理臺(tái)環(huán)境录语。
參考:一鍵部署 — WeBASE v1.5.0 文檔 (webasedoc.readthedocs.io)
2. 檢查環(huán)境
2.1 檢查java
推薦JDK8-JDK13版本倍啥。
# 查詢(xún)Java版本
java -version
下圖表示安裝了11.0.11版本的java。如果版本不對(duì)或沒(méi)有安裝java钦无,需要重新安裝:
# 安裝默認(rèn)Java版本(Java 8或以上)
sudo apt install -y default-jdk
后面可能出現(xiàn)JAVA_HOME has not been configured的錯(cuò)誤逗栽,因此先進(jìn)行配置。
使用命令:
echo $JAVA_HOME
若有輸出失暂,則不需要進(jìn)行下一步彼宠,若沒(méi)有輸出鳄虱,則找到j(luò)ava的路徑,一般是/usr/lib/jvm/
凭峡,如下所示拙已。
然后執(zhí)行:
cd /usr/lib/jvm/
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin:$PATH
2.2檢查MySQL
需要MySQL-5.6或以上版本。
#查詢(xún)MySQL版本
mysql --version
下圖表示安裝了5.7.33版本的MySQL摧冀。如果版本不對(duì)或沒(méi)有安裝MySQL倍踪,需要重新安裝:
sudo apt install mysql-server
對(duì)數(shù)據(jù)庫(kù)進(jìn)行初始化操作:
mysql_secure_installation
選擇如下:
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin? # 要安裝驗(yàn)證密碼插件嗎?(檢驗(yàn)密碼的復(fù)雜度)
Press y|Y for Yes, any other key for No: N # 這里我選擇N
Please set the password for root here.
New password: # 輸入要為root管理員設(shè)置的數(shù)據(jù)庫(kù)密碼
Re-enter new password: # 再次輸入密碼
By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y # 刪除匿名賬戶(hù)
Success.
Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N # 選Y則禁止root管理員從遠(yuǎn)程登錄,這里我沒(méi)有禁止
... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y # 刪除test數(shù)據(jù)庫(kù)并取消對(duì)它的訪問(wèn)權(quán)限
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y # 刷新授權(quán)表索昂,讓初始化后的設(shè)定立即生效
Success.
All done!
2.3 檢查Python
需要使用Python3.6或以上版本建车。
#查詢(xún)python版本
python --version
下圖表示安裝了3.6.9版本的python,并將python默認(rèn)命令指向了python3椒惨。
(注:關(guān)于python的配置缤至,在FISCO BCOS實(shí)踐(二)中已經(jīng)寫(xiě)過(guò)了,如果按照順序來(lái)康谆,python版本應(yīng)該是沒(méi)有問(wèn)題的领斥。還可以參考:Ubuntu將python命令默認(rèn)指向python3 - 簡(jiǎn)書(shū) (jianshu.com))
接下來(lái),還需要安裝PyMySQL依賴(lài)包沃暗。
sudo apt-get install -y python3-pip
sudo pip3 install PyMySQL
2.4 檢查服務(wù)器網(wǎng)絡(luò)策略
在本實(shí)踐中月洛,本機(jī)即為服務(wù)器,一般情況下這些端口都是已經(jīng)開(kāi)放的孽锥。
開(kāi)放WeBASE管理平臺(tái)端口:檢查webase-web管理平臺(tái)頁(yè)面的端口webPort(默認(rèn)為5000)在服務(wù)器的網(wǎng)絡(luò)安全組中是否設(shè)置為開(kāi)放嚼黔。若端口未開(kāi)放,將導(dǎo)致瀏覽器無(wú)法訪問(wèn)WeBASE服務(wù)頁(yè)面
開(kāi)放節(jié)點(diǎn)前置端口:如果希望通過(guò)瀏覽器直接訪問(wèn)webase-front節(jié)點(diǎn)前置的頁(yè)面忱叭,則需要開(kāi)放節(jié)點(diǎn)前置端口frontPort(默認(rèn)5002)隔崎;由于節(jié)點(diǎn)前置直連節(jié)點(diǎn),不建議對(duì)公網(wǎng)開(kāi)放節(jié)點(diǎn)前置端口韵丑,建議按需開(kāi)放
3. 部署WeBASE管理平臺(tái)
3.1 獲取部署安裝包
#進(jìn)入項(xiàng)目目錄
cd ~/myProject/
#獲取部署安裝包
wget https://osp-1257653870.cos.ap-guangzhou.myqcloud.com/WeBASE/releases/download/v1.5.0/webase-deploy.zip
#解壓安裝包
unzip webase-deploy.zip
3.2 進(jìn)行MySQL數(shù)據(jù)庫(kù)配置
WeBASE需要使用到兩個(gè)數(shù)據(jù)庫(kù)爵卒,分別是節(jié)點(diǎn)管理子系統(tǒng)mysql數(shù)據(jù)庫(kù)webasenodemanager
和簽名服務(wù)子系統(tǒng)mysql數(shù)據(jù)庫(kù)webasesign
。
因此撵彻,需要給WeBASE創(chuàng)建一個(gè)可用帳號(hào)钓株,并把這兩個(gè)數(shù)據(jù)庫(kù)的權(quán)限賦予這個(gè)帳號(hào)。
(注:這兩個(gè)數(shù)據(jù)庫(kù)的名字可以在WeBASE配置文件中修改陌僵,這里就直接使用默認(rèn)的名字轴合。)
使用root賬戶(hù)進(jìn)入數(shù)據(jù)庫(kù):
mysql -u root -p
在mysql中鍵入以下命令:
#建立webase賬戶(hù),密碼為webase_pswd
CREATE USER 'webase'@'localhost' IDENTIFIED BY 'webase_pswd'
#建立兩個(gè)數(shù)據(jù)庫(kù)
create DATABASE webasenodemanager;
create DATABASE webasesign;
#將兩個(gè)數(shù)據(jù)庫(kù)的所有權(quán)限賦予本地的webase帳號(hào)
GRANT ALL PRIVILEGES ON webasenodemanager.* To 'webase'@'localhost';
GRANT ALL PRIVILEGES ON webasesign.* To 'webase'@'localhost';
#退出
quit
接下來(lái)碗短,使用新創(chuàng)建的webase帳號(hào)登錄mysql:
mysql -u webase -p
在mysql中鍵入以下命令:
show databases;
在webase賬戶(hù)下就可以看到已經(jīng)創(chuàng)建好的數(shù)據(jù)庫(kù)webasenodemanager
和webasesign
:
3.3 修改配置文件
#進(jìn)入webase目錄
cd ~/myProject/webase-deploy
#修改配置文件
vi common.properties
要修改的部分如下受葛,其他配置項(xiàng)不變:
# Mysql database configuration of WeBASE-Node-Manager 修改相應(yīng)的MySQL用戶(hù)名密碼等信息
mysql.ip=localhost
mysql.port=3306
mysql.user=webase
mysql.password=webase
mysql.database=webasenodemanager
# Mysql database configuration of WeBASE-Sign 修改相應(yīng)的MySQL用戶(hù)名密碼等信息
sign.mysql.ip=localhost
sign.mysql.port=3306
sign.mysql.user=webase
sign.mysql.password=webase_pswd
sign.mysql.database=webasesign
# Node listening IP 修改為本機(jī)的IP地址
node.listenIp=192.168.171.141
# Node p2p service port
node.p2pPort=30300
# Node channel service port
node.channelPort=20200
# Node rpc service port
node.rpcPort=8545
# Use existing chain or not (yes/no) 由于已經(jīng)有鏈了,所以這里改成yes
if.exist.fisco=yes
### if using exited chain, [if.exist.fisco=yes] 改成之前部署的鏈地址,注意需要是從根目錄開(kāi)始的地址总滩,不能從~開(kāi)始
# The path of the existing chain, the path of the start_all.sh script
# Under the path, there should be a 'sdk' directory where the SDK certificates (ca.crt, node.crt and node. Key) are stored
fisco.dir=/home/xz/MyProject/Fisco/nodes/192.168.171.141
# Absolute path of the connected node in WeBASE-Front
# Under the path, there is a conf directory where node certificates (ca.crt, node.crt and node. Key) are stored
node.dir=/home/xz/MyProject/Fisco/nodes/192.168.171.141/node0
另外纲堵,注意服務(wù)端口不能小于1024,默認(rèn)是5000闰渔,這里沒(méi)改
3.4 部署并啟動(dòng)所有服務(wù)
#進(jìn)入webase目錄
cd ~/myProject/webase-deploy
#部署并啟動(dòng)所有WeBASE服務(wù)
python3 deploy.py installAll
會(huì)輸出如下圖的信息:注意這里要都選y:
WeBASE-Sign database webasesign already exists. Do you want drop and recreate it?[y/n]y
WeBASE-Front database webasefront already exists, rebuild or not?[y/n]:y
這樣席函,就成功部署了WeBASE管理平臺(tái)的服務(wù)。
4. 使用WeBASE管理平臺(tái)
4.1 直接訪問(wèn)WeBASE管理平臺(tái)
在虛擬機(jī)或者能連通虛擬機(jī)的實(shí)機(jī)打開(kāi)瀏覽器冈涧,輸入http://192.168.171.141:5000(剛剛配置好的IP和端口號(hào))屈糊,即訪問(wèn)WeBASE管理平臺(tái)钞支。
初始默認(rèn)的賬戶(hù)名是admin坪它,密碼是Abcd1234昔案。(第一次登陸后會(huì)提示修改密碼)
在這里可以進(jìn)行進(jìn)一步的管理和開(kāi)發(fā)。
例如咽筋,合約列表如圖所示:
4.2服務(wù)啟停操作
啟停操作如下(記得在webase-deploy目錄中操作):
# 一鍵部署
部署并啟動(dòng)所有服務(wù) python3 deploy.py installAll
停止一鍵部署的所有服務(wù) python3 deploy.py stopAll
啟動(dòng)一鍵部署的所有服務(wù) python3 deploy.py startAll
# 各子服務(wù)啟停
啟動(dòng)FISCO-BCOS節(jié)點(diǎn): python3 deploy.py startNode
停止FISCO-BCOS節(jié)點(diǎn): python3 deploy.py stopNode
啟動(dòng)WeBASE-Web: python3 deploy.py startWeb
停止WeBASE-Web: python3 deploy.py stopWeb
啟動(dòng)WeBASE-Node-Manager: python3 deploy.py startManager
停止WeBASE-Node-Manager: python3 deploy.py stopManager
啟動(dòng)WeBASE-Sign: python3 deploy.py startSign
停止WeBASE-Sign: python3 deploy.py stopSign
啟動(dòng)WeBASE-Front: python3 deploy.py startFront
停止WeBASE-Front: python3 deploy.py stopFront
例如溶推,執(zhí)行python3 deploy.py startAll結(jié)果:4.3 檢查運(yùn)行日志
如果出現(xiàn)問(wèn)題,則需要檢查運(yùn)行日志奸攻。
|-- webase-deploy # 一鍵部署目錄
|--|-- log # 部署日志目錄
|--|-- webase-web # 管理平臺(tái)目錄
|--|--|-- log # 管理平臺(tái)日志目錄
|--|-- webase-node-mgr # 節(jié)點(diǎn)管理服務(wù)目錄
|--|--|-- log # 節(jié)點(diǎn)管理服務(wù)日志目錄
|--|-- webase-sign # 簽名服務(wù)目錄
|--|--|-- log # 簽名服務(wù)日志目錄
|--|-- webase-front # 節(jié)點(diǎn)前置服務(wù)目錄
|--|--|-- log # 節(jié)點(diǎn)前置服務(wù)日志目錄
|--|-- nodes # 一件部署搭鏈節(jié)點(diǎn)目錄
|--|--|-- 127.0.0.1
|--|--|--|-- node0 # 具體節(jié)點(diǎn)目錄
|--|--|--|--|-- log # 節(jié)點(diǎn)日志目錄