美文网首页区块链计算机相关
FISCO BCOS实践(三)部署和使用WeBASE管理平台

FISCO BCOS实践(三)部署和使用WeBASE管理平台

作者: 夕湛 | 来源:发表于2021-04-30 02:10 被阅读0次

    FISCO BCOS实践:
    (一)搭建单群组联盟链
    (二)使用PythonSDK部署和测试智能合约
    (三)部署和使用WeBASE管理平台(本章)

    二、部署和使用WeBASE管理平台

    1. 简介

    微众银行开源的自研区块链中间件平台——WeBASE是区块链应用和FISCO BCOS节点之间搭建的中间件平台。WeBASE屏蔽了区块链底层的复杂度,降低区块链使用的门槛,大幅提高区块链应用的开发效率,包含节点前置、节点管理、交易链路,数据导出,Web管理平台等子系统。用户可以根据业务所需,选择子系统进行部署,可以进一步体验丰富交互的体验、可视化智能合约开发环境IDE。
    WeBASE管理平台是由四个WeBASE子系统组成的一套管理FISCO-BCOS联盟链的工具集。详细了解可以参考《WeBASE管理平台使用手册》
    这里使用一键部署,可以在同机快速搭建WeBASE管理台环境。
    参考:一键部署 — WeBASE v1.5.0 文档 (webasedoc.readthedocs.io)

    2. 检查环境

    2.1 检查java

    推荐JDK8-JDK13版本。

    # 查询Java版本
    java -version
    
    下图表示安装了11.0.11版本的java。

    如果版本不对或没有安装java,需要重新安装:

    # 安装默认Java版本(Java 8或以上)
    sudo apt install -y default-jdk
    

    后面可能出现JAVA_HOME has not been configured的错误,因此先进行配置。
    使用命令:

    echo $JAVA_HOME
    

    若有输出,则不需要进行下一步,若没有输出,则找到java的路径,一般是/usr/lib/jvm/,如下所示。


    然后执行:
    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或以上版本。

    #查询MySQL版本
    mysql --version
    
    下图表示安装了5.7.33版本的MySQL。

    如果版本不对或没有安装MySQL,需要重新安装:

    sudo apt install mysql-server
    

    对数据库进行初始化操作:

    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?    # 要安装验证密码插件吗?(检验密码的复杂度)
    Press y|Y for Yes, any other key for No: N    # 这里我选择N
    Please set the password for root here.
    
    New password:   # 输入要为root管理员设置的数据库密码
    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     # 删除匿名账户
    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管理员从远程登录,这里我没有禁止
    
    ... 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数据库并取消对它的访问权限
    - 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   # 刷新授权表,让初始化后的设定立即生效
    Success.
    
    All done!
    

    2.3 检查Python

    需要使用Python3.6或以上版本。

    #查询python版本
    python --version
    

    下图表示安装了3.6.9版本的python,并将python默认命令指向了python3。


    (注:关于python的配置,在FISCO BCOS实践(二)中已经写过了,如果按照顺序来,python版本应该是没有问题的。还可以参考:Ubuntu将python命令默认指向python3 - 简书 (jianshu.com)

    接下来,还需要安装PyMySQL依赖包。

    sudo apt-get install -y python3-pip
    sudo pip3 install PyMySQL
    

    2.4 检查服务器网络策略

    在本实践中,本机即为服务器,一般情况下这些端口都是已经开放的。
    开放WeBASE管理平台端口:检查webase-web管理平台页面的端口webPort(默认为5000)在服务器的网络安全组中是否设置为开放。若端口未开放,将导致浏览器无法访问WeBASE服务页面
    开放节点前置端口:如果希望通过浏览器直接访问webase-front节点前置的页面,则需要开放节点前置端口frontPort(默认5002);由于节点前置直连节点,不建议对公网开放节点前置端口,建议按需开放

    3. 部署WeBASE管理平台

    3.1 获取部署安装包

    #进入项目目录
    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 进行MySQL数据库配置

    WeBASE需要使用到两个数据库,分别是节点管理子系统mysql数据库webasenodemanager和签名服务子系统mysql数据库webasesign
    因此,需要给WeBASE创建一个可用帐号,并把这两个数据库的权限赋予这个帐号。
    (注:这两个数据库的名字可以在WeBASE配置文件中修改,这里就直接使用默认的名字。)

    使用root账户进入数据库:

    mysql -u root -p
    

    在mysql中键入以下命令:

    #建立webase账户,密码为webase_pswd
    CREATE USER  'webase'@'localhost'  IDENTIFIED BY  'webase_pswd'
    #建立两个数据库
    create DATABASE webasenodemanager;
    create DATABASE webasesign;
    #将两个数据库的所有权限赋予本地的webase帐号
    GRANT ALL PRIVILEGES ON webasenodemanager.*  To 'webase'@'localhost';
    GRANT ALL PRIVILEGES ON webasesign.*  To 'webase'@'localhost';
    #退出
    quit
    

    接下来,使用新创建的webase帐号登录mysql:

    mysql -u webase -p
    

    在mysql中键入以下命令:

    show databases;
    

    在webase账户下就可以看到已经创建好的数据库webasenodemanagerwebasesign

    3.3 修改配置文件

    #进入webase目录
    cd ~/myProject/webase-deploy
    #修改配置文件
    vi common.properties
    

    要修改的部分如下,其他配置项不变:

    # Mysql database configuration of WeBASE-Node-Manager 修改相应的MySQL用户名密码等信息
    mysql.ip=localhost
    mysql.port=3306
    mysql.user=webase
    mysql.password=webase
    mysql.database=webasenodemanager
    
    # Mysql database configuration of WeBASE-Sign 修改相应的MySQL用户名密码等信息
    sign.mysql.ip=localhost
    sign.mysql.port=3306
    sign.mysql.user=webase
    sign.mysql.password=webase_pswd
    sign.mysql.database=webasesign
    
    # Node listening IP 修改为本机的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) 由于已经有链了,所以这里改成yes
    if.exist.fisco=yes
    
    ### if using exited chain, [if.exist.fisco=yes] 改成之前部署的链地址,注意需要是从根目录开始的地址,不能从~开始
    # 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
    

    另外,注意服务端口不能小于1024,默认是5000,这里没改

    3.4 部署并启动所有服务

    #进入webase目录
    cd ~/myProject/webase-deploy
    #部署并启动所有WeBASE服务
    python3 deploy.py installAll
    
    会输出如下图的信息:

    注意这里要都选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管理平台的服务。

    4. 使用WeBASE管理平台

    4.1 直接访问WeBASE管理平台

    在虚拟机或者能连通虚拟机的实机打开浏览器,输入http://192.168.171.141:5000(刚刚配置好的IP和端口号),即访问WeBASE管理平台。

    如图所示:

    初始默认的账户名是admin,密码是Abcd1234。(第一次登陆后会提示修改密码)

    使用WeBASE管理平台界面如图所示:
    在这里可以进行进一步的管理和开发。
    例如,合约列表如图所示:

    4.2服务启停操作

    启停操作如下(记得在webase-deploy目录中操作):

    # 一键部署
    部署并启动所有服务        python3 deploy.py installAll
    停止一键部署的所有服务    python3 deploy.py stopAll
    启动一键部署的所有服务    python3 deploy.py startAll
    # 各子服务启停
    启动FISCO-BCOS节点:      python3 deploy.py startNode
    停止FISCO-BCOS节点:      python3 deploy.py stopNode
    启动WeBASE-Web:          python3 deploy.py startWeb
    停止WeBASE-Web:          python3 deploy.py stopWeb
    启动WeBASE-Node-Manager: python3 deploy.py startManager
    停止WeBASE-Node-Manager: python3 deploy.py stopManager
    启动WeBASE-Sign:        python3 deploy.py startSign
    停止WeBASE-Sign:        python3 deploy.py stopSign
    启动WeBASE-Front:        python3 deploy.py startFront
    停止WeBASE-Front:        python3 deploy.py stopFront
    
    例如,执行python3 deploy.py startAll结果:

    4.3 检查运行日志

    如果出现问题,则需要检查运行日志。

    |-- webase-deploy # 一键部署目录
    |--|-- log # 部署日志目录
    |--|-- webase-web # 管理平台目录
    |--|--|-- log # 管理平台日志目录
    |--|-- webase-node-mgr # 节点管理服务目录
    |--|--|-- log # 节点管理服务日志目录
    |--|-- webase-sign # 签名服务目录
    |--|--|-- log # 签名服务日志目录
    |--|-- webase-front # 节点前置服务目录
    |--|--|-- log # 节点前置服务日志目录
    |--|-- nodes # 一件部署搭链节点目录
    |--|--|-- 127.0.0.1
    |--|--|--|-- node0 # 具体节点目录
    |--|--|--|--|-- log # 节点日志目录
    

    相关文章

      网友评论

        本文标题:FISCO BCOS实践(三)部署和使用WeBASE管理平台

        本文链接:https://www.haomeiwen.com/subject/qpuwrltx.html