Compilação e instalação do fabric, ambiente go e docker, código-fonte do fabric, configuração de rede do fabric, configuração de peer e solicitante, configuração de código de cadeia.
Mais tecnologia de blockchain e classificação de aplicativos:
Blockchain applicationBlockchain development
Ethernet Square | Tecido | BCOS | criptografia | algoritmo de consenso | bitcoin | Outra cadeia
Economia de token | Cenários financeiros tradicionais | Finanças descentralizadas | Rastreabilidade antifalsificação | Compartilhamento de dados | Depósito confiável
1. Compilação e instalação do Fabric
ambiente wget e git
yum install wget
yum install git
git --version
git config --global user.name "centos7_test2"
git config --global user.email [email protected]
git config --list
Configurar ssh
ssh-keygen -t rsa -C " [email protected] "
cat ~ / .ssh / id_rsa.pub
Copiar para o github
vá meio ambiente
wget -c https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz
(baixe o pacote tar contendo bin)
sudo tar -C / usr / local / -zxvf go1.9.2.linux-amd64.tar.gz
sudo vim / etc / profile
Adicione abaixo:
export PATH=$PATH:/usr/local/go/bin
export GOROOT=/usr/local/go
export GOPATH=/project/goworkspace
source /etc/profile
Instalar docker
sudo yum -y install epel-release
sudo yum install docker python-pip
sudo pip install - atualizar pip
sudo pip instalar docker-compose
(Use curl -fsSL https://get.docker.com/ | sh para instalar a versão mais recente do docker para evitar erros de compilação subsequentes)
sudo service docker start
Verifique se o canal http está aberto
sudo curl -XPOST --unix-socket /var/run/docker.sock -d '{"Image": "nginx"}' -H 'Content-Type: application / json' http: // localhost / containers / create
Baixe o código fonte do tecido
sudo mkdir -p $ GOPATH / src / github.com / hyperledger
cd $ GOPATH / src / github.com / hyperledger
sudo git clone https://github.com/hyperledger/fabric.git
sudo git checkout -b v1.1.0
Instalar e compilar dependências
sudo vá obter github.com/golang/protobuf/protoc-gen-go
sudo mkdir -p $ GOPATH / src / github.com / hyperledger / fabric / build / docker / gotools / bin
sudo cp $ GOPATH / bin / protoc-gen -go $ GOPATH / src / github.com / hyperledger / fabric / build / docker / gotools / bin
yum install -y gcc libtool libltdl-dev libtool-ltdl-devel openssl
Tecido compilar
cd $ GOPATH / src / github.com / hyperledger / fabric
sudo make release (a versão go deve ser superior a 1.10, use 1.10.3)
sudo make docker (para garantir que a rede possa ser instalada na parede)
ponto importante
1. Se o último download do chaintool não foi completamente errado, primeiro exclua o arquivo .build / bin / chaintool e, em seguida,
digite o comando 2. Se ele solicitar .build / docker / gotools / bin / protoc-gen-go nenhum arquivo, então:
sudo cp protoc-gen-go /project/goworkspace/src/github.com/hyperledger/fabric/.build/docker/gotools/bin/
3. Curl: (7) Falha ao conectar a 127.0.0.1 porta 8118: Conexão recusada:
(shadowocks + privoxy) Não há problema em alterar a janela xshell
Gerar arquivo executável
Gere o caminho do arquivo binário executável:
/project/goworkspace/src/github.com/hyperledger/fabric/release/linux-amd64/bin
Coloque o arquivo binário gerado no diretório do sistema
sudo cp $ GOPATH / src / github.com / hyperledger / fabric / release / linux-amd64 / bin / * / usr / local / bin
Digite o diretório para executar
sudo chmod -R 775 configtxgen
sudo chmod -R 775 configtxlator
sudo chmod -R 775 criptógeno
sudo chmod -R 775 peer
sudo chmod -R 775 ordenador
Teste: (o número da versão normal aparece)
versão peer versão
xx
...
ponto importante
Ocorreu um erro durante a operação do par:
Não pode ser resolvido
Executando arquivos na pasta obsoleta:
/project/goworkspace/src/github.com/hyperledger/fabric/release/linux-amd64/bin
Mude para o pacote binário executável oficial para / usr / local / bin
2. Configuração de execução do Fabric
Método de aquisição de arquivo de imagem Docker (mas não obrigatório)
(1) Use o código-fonte (frente)
fazer docker
(2) Baixe do armazém Docker
Inicie a rede fabric
sudo mkdir -p / opt / hyperledger / fabricconfig
cryptogen showtemplate
vim /opt/hyperledger/fabricconfig/crypto-config.yaml
OrdererOrgs:
- Name: Orderer
Domain: qklszzn.com
Specs:
- Hostname: orderer
PeerOrgs:
- Name: Org1
Domain: org1.qklszzn.com
Template:
Count: 2
Users:
Count: 3
- Name: Org2
Domain: org2.qklszzn.com
Template:
Count: 2
Users:
Count: 2
realizado:
cryptogen generate --config = crypto-config.yaml --output ./crypto-config
Extraia o nome do domínio:
árvore -L 5
vim / etc / hosts
192.168.127.41 orderer.qklszzn.com
192.168.127.41 peer0.org1.qklszzn.com
192.168.127.41 peer1.org1.qklszzn.com
192.168.127.41 peer0.org2.qklszzn.com
192.168.127.41 peer1.org2.qklszzn.com
192.168.127.41 peer3.org1.qklszzn.com
cp -r /project/goworkspace/src/github.com/hyperledger/fabric/sampleconfig/configtx.yaml / opt / hyperledger / order /
(Alinhamento estrito entre os níveis, sem guias)
Profiles:
TestTwoOrgsOrdererGenesis:
Orderer:
<<: *OrdererDefaults
Organizations:
- *OrdererOrg
Consortiums:
SampleConsortium:
Organizations:
- *Org1
- *Org2
TestTwoOrgsChannel:
Consortium: SampleConsortium
Application:
<<: *ApplicationDefaults
Organizations:
- *Org1
- *Org2
Organizations:
- &OrdererOrg
Name: OrdererOrg
ID: OrdererMSP
MSPDir: /opt/hyperledger/fabricconfig/crypto-config/ordererOrganizations/qklszzn.com/msp
- &Org1
# DefaultOrg defines the organization which is used in the sampleconfig
# of the fabric.git development environment
Name: Org1MSP
# ID to load the MSP definition as
ID: Org1MSP
MSPDir: /opt/hyperledger/fabricconfig/crypto-config/peerOrganizations/org1.qklszzn.com/msp
AnchorPeers:
# AnchorPeers defines the location of peers which can be used
# for cross org gossip communication. Note, this value is only
# encoded in the genesis block in the Application section context
- Host: peer0.org1.qklszzn.com
Port: 7051
- &Org2
Name: Org2MSP
ID: Org2MSP
MSPDir: /opt/hyperledger/fabricconfig/crypto-config/peerOrganizations/org2.qklszzn.com/msp
AnchorPeers:
- Host: peer0.org2.qklszzn.com
Port: 7051
Orderer: &OrdererDefaults
OrdererType: solo
Addresses:
- orderer.qklszzn.com:7050
# Batch Timeout: The amount of time to wait before creating a batch
BatchTimeout: 2s
# Batch Size: Controls the number of messages batched into a block
BatchSize:
# Max Message Count: The maximum number of messages to permit in a batch
MaxMessageCount: 10
# Absolute Max Bytes: The absolute maximum number of bytes allowed for
# the serialized messages in a batch.
AbsoluteMaxBytes: 98 MB
# Preferred Max Bytes: The preferred maximum number of bytes allowed for
# the serialized messages in a batch. A message larger than the preferred
# max bytes will result in a batch larger than preferred max bytes.
PreferredMaxBytes: 512 KB
Kafka:
# Brokers: A list of Kafka brokers to which the orderer connects
# NOTE: Use IP:port notation
Brokers:
- 127.0.0.1:9092
# Organizations is the list of orgs which are defined as participants on
# the orderer side of the network
Organizations:
Application: &ApplicationDefaults
# Organizations is the list of orgs which are defined as participants on
# the application side of the network
Organizations:
cd / opt / hyperledger / pedido
Gerar arquivo de bloco genesis (orderer.genesis.block)
exportar FABRIC_CFG_PATH = $ PWD
configtxgen -profile TestTwoOrgsOrdererGenesis -outputBlock ./orderer.genesis.block
A geração do bloco inicial do razão (roberttestchannel.tx, o arquivo é usado para gerar o canal)
configtxgen -profile TestTwoOrgsChannel -outputCreateChannelTx ./roberttestchannel.tx -channelID roberttestchannel
Gerar arquivo âncora
configtxgen -profile TestTwoOrgsChannel -outputAnchorPeersUpdate ./Org1MSPanchors.tx -channelID roberttestchannel -asOrg Org1MSP
configtxgen -profile TestTwoOrgsChannel -outputAnchorPeersUpdate ./Org2MSPanchors.tx -channelID roberttestchannel -asOrg Org2MSP
Nó do solicitante começa
Copie o arquivo de inicialização do código-fonte para a pasta do solicitante
cp /project/goworkspace/src/github.com/hyperledger/fabric/sampleconfig/orderer.yaml / opt / hyperledger / order /
E modificar
General:
LedgerType: file
ListenPort: 7050
Enabled: false
RootCAs:
ClientAuthRequired: false
ClientRootCAs:
Keepalive:
ServerMinInterval: 60s
ServerInterval: 7200s
ServerTimeout: 20s
LogLevel: debug
GenesisMethod: file
GenesisProfile: TestOrgsOrdererGenesis
GenesisFile: /opt/hyperledger/order/orderer.genesis.block
LocalMSPID: OrdererMSP
Profile:
Enabled: false
Address: 0.0.0.0:6060
BCCSP:
Default: SW
SW:
Hash: SHA2
Security: 256
FileKeyStore:
KeyStore:
Authentication:
TimeWindow: 15m
FileLedger:
Location: /var/hyperledger/production/orderer
Prefix: hyperledger-fabric-ordererledger
RAMLedger:
HistorySize: 1000
Kafka:
Retry:
ShortInterval: 5s
ShortTotal: 10m
LongInterval: 5m
LongTotal: 12h
NetworkTimeouts:
DialTimeout: 10s
ReadTimeout: 10s
WriteTimeout: 10s
Metadata:
RetryBackoff: 250ms
RetryMax: 3
Producer:
RetryBackoff: 100ms
RetryMax: 3
Consumer:
RetryBackoff: 2s
Verbose: false
TLS:
Enabled: false
PrivateKey:
Certificate:
LocalMSPID: OrdererMSP
Profile:
Enabled: false
Address: 0.0.0.0:6060
BCCSP:
Default: SW
SW:
Hash: SHA2
Security: 256
FileKeyStore:
KeyStore:
Authentication:
TimeWindow: 15m
FileLedger:
Location: /opt/hyperledger/order/production/orderer
Prefix: hyperledger-fabric-ordererledger
RootCAs:
Version:
Debug:
BroadcastTraceDir:
DeliverTraceDir:
Iniciar o pedido
cd / opt / hyperledger / pedido
início do pedido
3. Inicialização do nó de mesmo nível
Arquivo de configuração
mkdir -p / opt / hyperledger / peer
cp /project/goworkspace/src/github.com/hyperledger/fabric/sampleconfig/core.yaml / opt / hyperledger / peer /
Alterado para (ver anexo):
exportar conjunto FABRIC_CFG_PATH = / opt / hyperledger / peer /
início do nó do par >> log_peer.log 2> & 1 &
Criar canal
cd ../order/
exportar conjunto CORE_PEER_LOCALMSPID = Org1MSP
export set CORE_PEER_MSPCONFIGPATH = / opt / hyperledger / fabricconfig / crypto-config / peerOrganizations / org1.qklszzn.com / users / [email protected] / msp
(Se você sair: lsof -i: 7051 é eliminado e reinserido, o seguinte está correto)
canal de pares criar -t 50 -o orderer.qklszzn.com:7050 -c roberttestchannel -f /opt/hyperledger/order/roberttestchannel.tx
(Certifique-se de gerar um arquivo .block em cd ../order/)
Junte-se ao canal
exportar conjunto CORE_PEER_LOCALMSPID = Org1MSP
export set CORE_PEER_MSPCONFIGPATH = / opt / hyperledger / fabricconfig / crypto-config / peerOrganizations / org1.qklszzn.com / users / [email protected] / msp
junção de canal de pares -b /opt/hyperledger/order/roberttestchannel.block
(Observe o caminho de geração de roberttestchannel.block)
Atualizar nó âncora
exportar conjunto CORE_PEER_LOCALMSPID = Org1MSP
exportar conjunto CORE_PEER_ADDRESS = peer0.org1.qklszzn.com: 7051
export set CORE_PEER_MSPCONFIGPATH = / opt / hyperledger / fabricconfig / crypto-config / peerOrganizations / org1.qklszzn.com / users / [email protected] / msp
atualização de canal de mesmo nível -o orderer.qklszzn.com:7050 -c roberttestchannel -f /opt/hyperledger/order/Org1MSPanchors.tx
Implantar chaincode
exportar conjunto CORE_PEER_LOCALMSPID = Org1MSP
exportar conjunto CORE_PEER_ADDRESS = peer0.org1.qklszzn.com: 7051
export set CORE_PEER_MSPCONFIGPATH = / opt / hyperledger / fabricconfig / crypto-config / peerOrganizations / org1.qklszzn.com / users / [email protected] / msp
(Se um erro for relatado nesta seção, altere o valor do modo em /opt/hyperledger/peer/core.yaml para net e reinicie o solicitante e o par)
peer chaincode install -n r_test_cc6 -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
Instancie o código do chaincode
exportar conjunto CORE_PEER_LOCALMSPID = Org1MSP
exportar conjunto CORE_PEER_ADDRESS = peer0.org1.qklszzn.com: 7051
export set CORE_PEER_MSPCONFIGPATH = / opt / hyperledger / fabricconfig / crypto-config / peerOrganizations / org1.qklszzn.com / users / [email protected] / msp
peer chaincode instanciar -o orderer.qklszzn.com:7050 -C roberttestchannel -n r_test_cc6 -v 1.0 -c '{"Args": ["init", "a", "100", "b", "200"] } '-P "OR (' Org1MSP.member ',' Org2MSP.member ')"
peer chaincode invoke -o orderer.qklszzn.com:7050 -C roberttestchannel -n r_test_cc6 -c '{"Args": ["invoke", "a", "b", "1"]}'
Link original: Fabric1.x (método não Dokcer) da compilação à implantação