1、开放ssh
# 授权
su root
# 查看ip
yum install -y net-tools
ifconfig
# 配置静态网址
# ifcfg-ens33 查看ifconfig网络接口名字
vim /etc/sysconfig/network-scripts/ifcfg-ens33
# 修改内容
BOOTPROTO=static #dhcp:自动分配ip ,static:静态ip
ONBOOT=yes #开启启动必须是yes
IPADDR=192.168.97.136 #ip地址
NETMASK=255.255.255.0 #掩码
GATEWAY=192.168.97.2 #网关
DNS1=192.168.97.2 #域名服务器1
DNS2=8.8.8.8 #域名服务器1
# 重启网络服务(或者系统)
sudo service network restart (sudo reboot)
# 下载openssh-server
su root
yum install openssh-server
# 修改配置
vim /etc/ssh/sshd_config
# 找到如下配置项,去掉注释
Port 22
ListenAddress 0.0.0.0
PermitRootLogin yes
PasswordAuthentication
# 重新启动
systemctl restart sshd
# 查看状态
service status sshd
# 关闭防火墙
systemctl disable firewalld
2、安装docker
2.1.安装docker
# (1)升级docker包
sudo yum update
# (2)卸载旧版本
sudo yum remove docker docker-common docker-selinux docker-engine
# (3)安装需要的软件包
sudo yum install -y yum-utils device device-mapper-persistent-data lvm2
# (4)选择安装的版本
# 配置yum源
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 查看所有版本
yum list docker-ce --showduplicates | sort -r
# (5)执行安装(选择stable稳定版本)
yum install -y docker-ce
# (6)查看docker是否安装
docker -v
# (7)设置docker为开机自启
systemctl restart docker
systemctl enable docker
2.2 配置docker镜像加速器
cd /etc/docker/
# 修改镜像加速器配置
vim /etc/docker/daemon.json
# 在daemon.json填写内容:
{
"exec-opts": ["native.cgroupdriver=systemd"], # 设置 Docker 守护进程使用的 cgroup 驱动为systemd
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"] # 镜像加速器
}
# 重启服务:
sudo systemctl daemon-reload
sudo systemctl restart docker
# 查看docker运行状态
systemctl status docker
从 Docker 19.03 开始,docker-compose
功能可以作为 Docker 的一部分直接以插件形式安装,称为 docker compose
(注意没有中划线)。这意味着你可以直接使用 Docker 命令来管理你的多容器应用,而不需要单独安装 docker-compose
。
3、安装docker compose
curl -L https://github.com/docker/compose/releases/download/1.27.4/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -sf /usr/local/bin/docker-compose /usr/bin/docker-compose
# 查看版本号
docker-compose -v
4、安装Go语言环境
yum install -y wget
cd /usr/local/
wget https://go.dev/dl/go1.15.3.linux-amd64.tar.gz
# 解压到$HOME路径
tar -C $HOME -zxf go1.15.3.linux-amd64.tar.gz
mkdir $HOME/gocode
vim ~/.bashrc
# 在.bashrc文件添加以下内容:
# 将Go的工作空间设置为你的用户主目录下的gocode目录。
export GOPATH=$HOME/gocode
# 将Go的安装目录设置为你的用户主目录下的go目录。
export GOROOT=$HOME/go
# 将Go的可执行文件目录添加到系统的PATH环境变量中,以便你可以直接运行Go的命令,比如go build、go run等。
export PATH=$PATH:$GOROOT/bin
# 将你的Go项目的bin目录添加到系统的PATH环境变量中,以便你可以直接运行你的Go项目的可执行文件。
export PATH=$PATH:$GOPATH/bin
# 编译.bashrc
source ~/.bashrc
# 查看go版本
go version
5、安装Git
# 查看是否已安装
-bash:git
# 已安装:卸载旧版本
yum remove -y git
# 安装:
yum -y install git
# 查看git版本:
git version
6、安装Fabric区块链
# 1、创建保存源代码目录
# $GOPATH是一个环境变量,用于指定Go语言项目的工作目录。
mkdir -p $GOPATH/src/github.com/hyperledger
# 2、下载Fabric区块链源代码
cd $GOPATH/src/github.com/hyperledger
git clone https://gitee.com/mirrors/fabric.git # 在hyperledger目录下包含源代码
# 3、下载Fabric区块链示例代码
cd $GOPATH/src/github.com/hyperledger/fabric/scripts/
# 切换特点版本,Branch release-2.3 set up to track remote branch release-2.3 from origin.Switched to a new branch 'release-2.3'表示切换成功
git checkout release-2.3
git clone https://gitee.com/hyperledger/fabric-samples.git
# 4、安装Fabric区块链
cd $GOPATH/src/github.com/hyperledger/fabric/scripts/
sh bootstrap.sh
# 执行后会在当前目录多了一个fabric-samples的目录。这里下载发行包二进制文件会经常中途断开,可以下载代码后,发行包通过用浏览器下载上传后解压,包:`hyperledger-fabric-ca-linux-amd64-1.4.9.tar.gz`和`hyperledger-fabric-linux-amd64-2.2.1.tar.gz`,下载后把文件上传到:$GOPATH/hyperledger/fabric/scripts/fabric-samples目录下并解压,如果是手动解压还需要手装下载docker镜像
# 查看是否成功
docekr images
7、配置Fabric区块链管理工具【选做】
vim /etc/profile
# 在文件后添加:
export PATH="$GOPATH/src/github.com/hyperledger/fabric/scripts/fabric-samples/bin:$PATH"
# 保存退出后,执行命令使环境生效
source /etc/profile
# 配置完环境变量后,在任意路径执行如下命令:出现帮助信息,则说明成功
configtxgen --help
8、Fabric测试网络
# 启动test-network测试网络:
cd $GOPATH/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network
./network.sh up
# 关闭测试网络
./network.sh down
# 启动内置CA服务
# 同时创建三个CA:组织Org1的CA(ca_orh1),组织Org2的CA(ca_orh2),排序节点的CA(ca_orderer)
./network.sh up -ca
# 修改test-network/scripts里面的createChannel.sh文件【创建通道失败时】
cd $GOPATH/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/scripts
vim createChannel.sh
在createChannel函数把 --channel -id 修改成 --channelID
# 创建channel
cd $GOPATH/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network
./network.sh createChannel # 或者:./network.sh createChanne -c channel1; -c channelName 表示通道指定名称
9、上链
# 在通道上启动链码
#使用network.sh创建通道之后,可以使用以下命令在通道上启动链码(默认使用go语言):
./network.sh deployCC
# 可以指定语言,加-l ,比如我用java,命令如下:
./network.sh deployCC -l java