部署应用
本章节主要介绍如何部署应用。
部署应用
- 下载银行联盟链依赖的镜像:登录区块链服务管理控制台,进入“应用案例”,下载“银行联盟链示例应用”中的银行联盟链依赖的镜像。
- 登录到弹性云服务器,需提前安装好docker和unzip。
执行“cd /root/bankuniondemo”,将上一步下载的镜像上传到该目录。
执行“vi startserver.sh”新建startserver.sh文件,将如下内容复制至startserver.sh文件中,并保存。
#!/bin/sh #获取当前路径 path=`pwd` #获取IP地址 localip=`ifconfig eth0 | grep "inet addr" | awk '{ print $2}' | awk -F: '{print $2}'` #检测unzip 和 docker命令是否已经安装好 if type unzip > /dev/null 2>&1; then echo "Unzip command is exists!" else echo "No unzip command, please install unzip before start this demo" exit 1 fi if type docker > /dev/null 2>&1; then echo "Docker exists!" else echo "No docker, please install docker before start this demo" exit 1 fi #检查证书目录是否存在 if [ -e ./crypto ];then rm -rf crypto fi #解压证书文件 echo "Start unziping certificate ...." cerzip=$(ls|grep .zip) for i in $cerzip; do unzip -n $i -d crypto/ done echo "Unzip certificate Done!!" #适配证书路径 Folder="$path/crypto" for file in ${Folder}/* do temp_file=`basename $file` mv -f $path/crypto/$temp_file/* $path/crypto/ done #检查所需的证书文件是否已准备完善 echo "Start checking if the required files are ready" if [ -e $path/democraticBank.yaml ]&&[ -e $path/civilizationBank.yaml ]&&[ -e $path/harmoniousBank.yaml ];then echo "Check required yaml files OK!!" else echo "Please check if the required yaml files are ready!!" exit fi #忘记密码的情况重启 read -p "Is this the first time you deploy the application? If yes please insert 'y', if you want to reset your password please insert 'n': " choice echo $choice if [ $choice = "n" ];then docker rm $(docker stop $(docker ps -a -q --filter ancestor=bank --format="{{.ID}}")) echo "Resetting password..." fi #设置密码 read -p "Please set your password: " test echo $test if [ ${#test} -lt 4 -o ${#test} -gt 24 ];then echo "password length should in [4, 24].";exit;fi #load images if [ -e $path/bankv3.tar.gz ];then echo "Start loading images..." docker load -i bankv3.tar.gz echo "Api-server images is exists,Skip load!" fi #启动服务 echo "Start server ....." docker run --env TESTPWD=$test -p 8080:8080 -d -it -v $path/crypto:/opt/bank/src/bank/conf/crypto -v $path/democraticBank.yaml:/opt/bank/src/bank/conf/democraticBank.yaml -v $path/harmoniousBank.yaml:/opt/bank/src/bank/conf/harmoniousBank.yaml -v $path/civilizationBank.yaml:/opt/bank/src/bank/conf/civilizationBank.yaml bank RET_CODE=`echo $?` if [ $RET_CODE -eq 0 ]; then echo "Start server success!" echo -e "please login \033[32mhttp://EIP:8080/adminLogin \033[0mto visit Bank Management System" echo -e "or login \033[32mhttp://EIP:8080/userLogin \033[0mto visit Bank Customer System" else echo "Failed to start server! Please check if everything ok" fi
执行脚本:
bash startserver.sh
- 安装过程中,用户需要输入两次信息,第一次“是否是第一次部署应用”,是键入y,否(即想修改密码)键入n;第二次键入用户自定义密码(以下举例,键入密码为123456):
执行结果可参考如下返回信息:
图1 执行结果
- 执行如下命令,检查容器是否启动。
docker ps
提示如下信息,表示启动成功;否则请检查配置。
图2 提示信息