Hyperledger fabric 1.4 环境搭建(一)
Hyperledger fabric 1.4 环境搭建(一)
1、更换下载源
更换apt的下载源,因为官方下载源很慢,需要更换到国内的镜像站
1.1、进入/etc/apt/目录
cd etc/apt
1.2、备份sources.list文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup
1.3、打开sources.list文件并添加阿里云镜像
sudo vi /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
1.4、更新apt-get
sudo apt-get update
sudo apt-get upgrade
2、环境安装
2.1、必备软件安装
sudo apt-get install vim
sudo apt-get install git
sudo apt-get install curl
sudo apt-get install wget
sudo apt-get install python-pip
2.2、Go安装
#进入根目录
cd ~
#下载压缩包
wget https://studygolang.com/dl/golang/go1.14.9.linux-amd64.tar.gz
#解压压缩包
tar -xzf go1.14.9.linux-amd64.tar.gz
#删除压缩包
rm -rf go1.14.9.liunx-amd64.tar.gz
#设置权限,并把根目录下的go文件夹移动到/usr/local/目录下
sudo chmod 777 /usr/local/
sudo mv go /usr/local
#修改环境变量
vi ~/.bashrc
#设置环境变量
export PATH=$PATH:/usr/local/go/bin
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$HOME/go/bin
#更新环境变量
source ~/.bashrc
#查看go是否安装成功
go version
#查看go环境变量是否设置成功
go env
2.3、docker安装
#查询docker是否安装
docker version
#更新apt包索引
sudo apt-get update
#下载安装工具
sudo apt-get install apt-transport-https ca-certificates software-properties-common
#添加官方密钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
#加入apt仓库
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
#下载docker-ce
sudo apt-get update
sudo apt-get install docker-ce
#验证版本
docker version
#将非root组加入docker组
sudo groupadd docker
sudo gpasswd -a $USER docker #将当前用户添加到用户组
#sudo usermod -aG docker XXX(XXX是当前用户名)
#重启docker服务
sudo service docker restart
#切换当前会话到新group或重启会话
newgrp - docker
#添加阿里云docker镜像
sudo mkdir -p /etc/docker
sudo vim /etc/docker/daemon.json
#将以下内容写入文件中
{
"registry-mirrors": ["https://obou6wyb.mirror.aliyuncs.com"]
}
#重启docker
sudo systemctl daemon-reload
sudo systemctl restart docker
docker version
2.4、docker-compose安装
#下载docker-compose
sudo curl -L https://github.com/docker/compose/releases/download/1.26.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
#允许其他用户执行compose相关命令
sudo chmod +x /usr/local/bin/docker-compose
#验证版本
docker-compose -version
2.5、下载Fabric源码,镜像,示例等
#创建并进入hyperledger目录
mkdir -p $GOPATH/src/github.com/hyperledger
cd $GOPATH/src/github.com/hyperledger
#下载fabric源码
git clone https://github.com/hyperledger/fabric.git
#将fabric切换至1.4版本
cd fabric
git branch -a
git checkout release-1.4
#下载fabric镜像以及示例
#cd $GOPATH/src/github.com/hyperleger/fabric/scripts
#中间会stop几次,重新运行即可
#./bootstrap.sh
#因为运行bootstrap.sh文件需要下载一些二进制文件,但是这些文件又存放在国外的网站上,所以下载十分缓慢,不能通过直接运行bootstrap.sh来安装fabric所需的工具和镜像。运行该文件主要进行了3个步骤,可以分开操作
#步骤一
cd $GOPATH/src/github.com/hyperledger/fabric/scripts
git clone https://github.com.cnpmjs.org/hyperledger/fabric-samples.git
git branch -a
git checkout release-1.4
#步骤二
#查看version和ca-version,然后手动下载对应版本
vim bootstrap.sh
cd $GOPATH
wget https://github.com/hyperledger/fabric/releases/download/v1.4.8/hyperledger-fabric-linux-amd64-1.4.8.tar.gz
wget https://github.com/hyperledger/fabric-ca/releases/download/v1.4.8/hyperledger-fabric-ca-linux-amd64-1.4.8.tar.gz
#解压压缩包后会生成/bin文件夹,存放工具
tar -xzf hyperledger-fabric-linux-amd64-1.4.8.tar.gz
tar -xzf hyperledger-fabric-ca-linux-amd64-1.4.8.tar.gz
#步骤三
#下载docker镜像
cd $GOPATH/src/github.com/hyperledger/fabric/scripts
sudo chmod 777 bootstrap.sh
sudo ./bootstrap.sh -s -b
#查看安装的镜像
docker images
3、测试fabric环境
#进入示例目录
cd $GOPATH/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/
#生成创世区块,通道,证书等
./byfn.sh generate
#启动网络
./byfn.sh up
#停止网络
./byfn.sh down
其他
4、安装Beego
$ export GO111MODULE=on
$ export GOPROXY=https://goproxy.io
$ go get github.com/beego/bee
$ go get github.com/astaxie/beego
测试
#查看bee相关命令
$ bee
5、安装Nodejs 10.19.0
#下载编译好的源码
wget https://nodejs.org/dist/v8.11.4/node-v8.11.4-linux-x64.tar.xz
//解压
tar xf node-v10.19.0-linux-x64.tar.xz
cd node-v10.19.0-linux-x64/
#查看安装版本
./bin/node -v
#将node等命令加入环境变量中
vim .bashrc
#加入环境变量
export PATH=$PATH:$HOME/node-v8.11.4-linux-x64/bin
cd ~
#刷新环境变量
source .bashrc
node -v
6、安装Postgresql 9.5
$ sudo apt-get update
$ sudo apt-get install postgresql postgresql-client
#系统会自动创建一个超级用户名为postgres ,密码为空(随机)
#创建超级用户,最好和系统用户名相同
$ sudo -u postgres createuser --superuser peer3
$ sudo -u postgres psql
postgres# \password peer3
#提示输入新密码,jingjinji
#用户创建并登录数据库
#sudo -u postgres createdb --owner=mydb
#psql -U peer3 -d mydb -h 127.0.0.1 -p 5432
7、安装MySQL
$ sudo apt-get update
$ sudo apt-get install mysql-server
$ sudo mysql_secure_installation N,密码,确认密码,Y,N,Y,Y
#设置MySQL root可通过密码登录
$ sudo mysql
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'jingjinji';
mysql> exit
$ mysql -u root -p
输入密码:jingjinji
# 设置远程访问
$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
#注释掉下面一行
#bind-address = 127.0.0.1
$ mysql -u root -p
jingjinji
mysql> GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "jingjinji";
mysql> flush privileges;
mysql> exit
#安装mysql-workbench
$ sudo apt-get install mysql-workbench
#安装驱动
$ cd go/src
$ go get github.com/astaxie/beego/orm
$ go get github.com/go-sql-driver/mysql
备注:
node地址
https://nodejs.org/dist/
//设置代理 方法一
$ npm config set proxy http://127.0.0.1:1080
$ npm i node-sass
// 下载完成后删除 http 代理
$ npm config delete proxy
方法二:国内源
npm install -g cnpm
npm install -g cnpm --registry=http://r.cnpmjs.org
npm config set registry="http://r.cnpmjs.org"
//启动first-network
./byfn.sh up