Installing Fabric Binaries

[Jo Richard]

2023/10/05

Full Table of Contents

Installing Fabric Binaries

Start Fabric CA Process

# start-ca.sh
function startCA() {
  export FABRIC_CA_HOME=${TEST_NETWORK_HOME}/organizations/fabric-ca-server
  export FABRIC_CA_SERVER_CA_NAME="ca"
  export FABRIC_CA_SERVER_TLS_ENABLED=true
  export FABRIC_CA_SERVER_PORT="7054"
  export FABRIC_CA_SERVER_CSR_CN="ca"
  export FABRIC_CA_SERVER_CSR_HOSTS="ca,localhost"
  export FABRIC_CA_SERVER_OPERATIONS_LISTENADDRESS="0.0.0.0:7443"

  echo "FABRIC_CA_HOME=${TEST_NETWORK_HOME}/organizations/fabric-ca-server"
  echo "TEST_NETWORK: $TEST_NETWORK"
  echo "TEST_NETWORK_HOME: $TEST_NETWORK_HOME"
  echo "BIN_DIR: $BIN_DIR"
  echo "LOG_DIR: $LOG_DIR"

  nohup ${BIN_DIR}/fabric-ca-server start -b admin:adminpw >> ${LOG_DIR}/fabric-ca-server.log &
  pid=$!
  echo $pid >pid/ca.pid
  echo "ok: $?"
}

Create Certificates for Orderer Organization (Locate MSPs)

# enroll-orderer.sh

export FABRIC_CA_CLIENT_HOME=${TEST_NETWORK_HOME}/organizations/ordererOrganizations/example.com
${BIN_DIR}/fabric-ca-client enroll -u https://admin:adminpw@ca:7054 --caname ca --tls.certfiles ${TEST_NETWORK_HOME}/organizations/fabric-ca-server/tls-cert.pem

# # config
echo 'NodeOUs:
            Enable: true
            ClientOUIdentifier:
                Certificate: cacerts/ca-7054-ca.pem
                OrganizationalUnitIdentifier: client
            PeerOUIdentifier:
                Certificate: cacerts/ca-7054-ca.pem
                OrganizationalUnitIdentifier: peer
            AdminOUIdentifier:
                Certificate: cacerts/ca-7054-ca.pem
                OrganizationalUnitIdentifier: admin
            OrdererOUIdentifier:
                Certificate: cacerts/ca-7054-ca.pem
                OrganizationalUnitIdentifier: orderer' >${TEST_NETWORK_HOME}/organizations/ordererOrganizations/example.com/msp/config.yaml


for var in {0..2}; do
  echo Registering orderer${var}
  ${BIN_DIR}/fabric-ca-client register -d --caname ca --id.name orderer${var} --id.secret orderer${var}pw --id.type orderer --tls.certfiles ${TEST_NETWORK_HOME}/organizations/fabric-ca-server/tls-cert.pem

  # # get msp
  ${BIN_DIR}/fabric-ca-client enroll -d -u https://orderer${var}:orderer${var}pw@ca:7054 --caname ca -M ${TEST_NETWORK_HOME}/organizations/ordererOrganizations/example.com/orderers/orderer${var}.example.com/msp --csr.hosts ${TEST_NETWORK_NAME}.orderer${var}.example.com --csr.hosts localhost --tls.certfiles ${TEST_NETWORK_HOME}/organizations/fabric-ca-server/tls-cert.pem

  cp ${TEST_NETWORK_HOME}/organizations/ordererOrganizations/example.com/msp/config.yaml ${TEST_NETWORK_HOME}/organizations/ordererOrganizations/example.com/orderers/orderer${var}.example.com/msp/config.yaml

  # # get tls
  ${BIN_DIR}/fabric-ca-client enroll -d -u https://orderer${var}:orderer${var}pw@ca:7054 --caname ca -M ${TEST_NETWORK_HOME}/organizations/ordererOrganizations/example.com/orderers/orderer${var}.example.com/tls --enrollment.profile tls --csr.hosts ${TEST_NETWORK_NAME}.orderer${var}.example.com --csr.hosts localhost --tls.certfiles ${TEST_NETWORK_HOME}/organizations/fabric-ca-server/tls-cert.pem

  # # make crt files
  # ca public
  cp ${TEST_NETWORK_HOME}/organizations/ordererOrganizations/example.com/orderers/orderer${var}.example.com/tls/tlscacerts/* ${TEST_NETWORK_HOME}/organizations/ordererOrganizations/example.com/orderers/orderer${var}.example.com/tls/ca.crt
  # node public
  cp ${TEST_NETWORK_HOME}/organizations/ordererOrganizations/example.com/orderers/orderer${var}.example.com/tls/signcerts/* ${TEST_NETWORK_HOME}/organizations/ordererOrganizations/example.com/orderers/orderer${var}.example.com/tls/server.crt
  # node private
  cp ${TEST_NETWORK_HOME}/organizations/ordererOrganizations/example.com/orderers/orderer${var}.example.com/tls/keystore/* ${TEST_NETWORK_HOME}/organizations/ordererOrganizations/example.com/orderers/orderer${var}.example.com/tls/server.key

  # tls-ca public -> msp
  mkdir -p ${TEST_NETWORK_HOME}/organizations/ordererOrganizations/example.com/orderers/orderer${var}.example.com/msp/tlscacerts
  cp ${TEST_NETWORK_HOME}/organizations/ordererOrganizations/example.com/orderers/orderer${var}.example.com/tls/tlscacerts/* ${TEST_NETWORK_HOME}/organizations/ordererOrganizations/example.com/orderers/orderer${var}.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
  # tls-ca public -> common msp
  mkdir -p ${TEST_NETWORK_HOME}/organizations/ordererOrganizations/example.com/msp/tlscace

  cp ${TEST_NETWORK_HOME}/organizations/ordererOrganizations/example.com/orderers/orderer${var}.example.com/tls/tlscacerts/* ${TEST_NETWORK_HOME}/organizations/ordererOrganizations/example.com/msp/tlscacerts/tlsca.example.com-cert.pem

  ${BIN_DIR}/fabric-ca-client register --caname ca --id.name orderer${var}Admin --id.secret orderer${var}Adminpw --id.type admin --tls.certfiles ${TEST_NETWORK_HOME}/organizations/fabric-ca-server/tls-cert.pem

  ${BIN_DIR}/fabric-ca-client enroll -u https://orderer${var}Admin:orderer${var}Adminpw@ca:7054 --caname ca -M ${TEST_NETWORK_HOME}/organizations/ordererOrganizations/example.com/users/Admin@example.com/msp --tls.certfiles ${TEST_NETWORK_HOME}/organizations/fabric-ca-server/tls-cert.pem

  cp ${TEST_NETWORK_HOME}/organizations/ordererOrganizations/example.com/msp/config.yaml ${TEST_NETWORK_HOME}/organizations/ordererOrganizations/example.com/users/Admin@example.com/msp/config.yaml
done

Create Certificates for Peer Organizations (Locate MSPs)


# enroll-peer.sh
export FABRIC_CA_CLIENT_HOME=${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/
local caTLSCertPath="fabric-ca-server/tls-cert.pem"

# # ca client
echo "Enrolling the CA admin"
${BIN_DIR}/fabric-ca-client enroll -u https://admin:adminpw@ca:7054 --caname ca --tls.certfiles ${TEST_NETWORK_HOME}/organizations/${caTLSCertPath}

echo 'NodeOUs:
              Enable: true
              ClientOUIdentifier:
                  Certificate: cacerts/ca-7054-ca.pem
                  OrganizationalUnitIdentifier: client
              PeerOUIdentifier:
                  Certificate: cacerts/ca-7054-ca.pem
                  OrganizationalUnitIdentifier: peer
              AdminOUIdentifier:
                  Certificate: cacerts/ca-7054-ca.pem
                  OrganizationalUnitIdentifier: admin
              OrdererOUIdentifier:
                  Certificate: cacerts/ca-7054-ca.pem
                  OrganizationalUnitIdentifier: orderer' >${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/msp/config.yaml

# admin account
# # register and enroll admin
${BIN_DIR}/fabric-ca-client register --caname ca --id.name org1admin --id.secret org1adminpw --id.type admin --id.attrs '"hf.Registrar.Roles=admin",hf.Revoker=true' --tls.certfiles ${TEST_NETWORK_HOME}/organizations/${caTLSCertPath}

# echo "Generating the org admin msp"
${BIN_DIR}/fabric-ca-client enroll -u https://org1admin:org1adminpw@ca:7054 --caname ca -M ${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp --tls.certfiles ${TEST_NETWORK_HOME}/organizations/${caTLSCertPath}

cp ${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/msp/config.yaml ${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/config.yaml

# user1 account
# # register and enroll admin
${BIN_DIR}/fabric-ca-client register --caname ca --id.name user1 --id.secret user1pw --id.type client --id.attrs '"hf.Registrar.Roles=client"' --tls.certfiles ${TEST_NETWORK_HOME}/organizations/${caTLSCertPath}

${BIN_DIR}/fabric-ca-client enroll -u https://user1:user1pw@ca:7054 --caname ca -M ${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp --tls.certfiles ${TEST_NETWORK_HOME}/organizations/${caTLSCertPath}

cp ${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/msp/config.yaml ${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/config.yaml

# peer accounts
for var in {0..2}; do
  mkdir -p ${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/

  # peer node
  # # register peer
  echo Registering peer${var}
  ${BIN_DIR}/fabric-ca-client register --caname ca --id.name peer${var} --id.secret peer${var}pw --id.type peer --tls.certfiles ${TEST_NETWORK_HOME}/organizations/${caTLSCertPath}

  # # get msp
  ${BIN_DIR}/fabric-ca-client enroll \
            -u https://peer${var}:peer${var}pw@ca:7054 \
            --caname ca \
            -M ${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/peers/peer${var}.org1.example.com/msp \
            --csr.hosts ${TEST_NETWORK_NAME}.peer${var}.org1.example.com \
            --csr.hosts localhost \
            --tls.certfiles ${TEST_NETWORK_HOME}/organizations/${caTLSCertPath}

  cp ${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/msp/config.yaml ${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/peers/peer${var}.org1.example.com/msp/config.yaml

  # get tls
  ${BIN_DIR}/fabric-ca-client enroll \
            -u https://peer${var}:peer${var}pw@ca:7054 \
            --caname ca \
            -M ${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/peers/peer${var}.org1.example.com/tls \
            --enrollment.profile tls \
            --csr.hosts ${TEST_NETWORK_NAME}.peer${var}.org1.example.com \
            --csr.hosts localhost \
            --tls.certfiles ${TEST_NETWORK_HOME}/organizations/${caTLSCertPath}

  # make crt files
  # # ca public
  cp ${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/peers/peer${var}.org1.example.com/tls/tlscacerts/* ${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/peers/peer${var}.org1.example.com/tls/ca.crt

  # # node public
  cp ${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/peers/peer${var}.org1.example.com/tls/signcerts/* ${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/peers/peer${var}.org1.example.com/tls/server.crt

  # # node private
  cp ${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/peers/peer${var}.org1.example.com/tls/keystore/* ${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/peers/peer${var}.org1.example.com/tls/server.key

  #  tls-ca public -> msp
  mkdir -p ${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/msp/tlscacerts
  cp ${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/peers/peer${var}.org1.example.com/tls/tlscacerts/* ${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/msp/tlscacerts/ca.crt

  # tls-ca public -> common msp
  mkdir -p ${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/tlsca
  cp ${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/peers/peer${var}.org1.example.com/tls/tlscacerts/* ${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem

  # msp-ca public -> common ca
  mkdir -p ${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/ca
  cp ${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/peers/peer${var}.org1.example.com/msp/cacerts/* ${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/ca/ca.org1.example.com-cert.pem
done

Start Up Orderer Nodes

# start-orderer.sh
startOrderer() {
  local ordererNum=${1}
  : ${ordererNum:=0}

  ORDERER_PORT=$(((($ordererNum + 7) * 1000) + 50))
  ORDERER_LISTEN_PORT=$(((($ordererNum + 7) * 1000) + 444))
  FILE_LEDGER_LOC=${TEST_NETWORK_HOME}/production/orderers/orderer${ordererNum}.example.com

  export CORE_VM_ENDPOINT=
  export CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=
  export FABRIC_LOGGING_SPEC="INFO"
  export ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
  export ORDERER_GENERAL_LISTENPORT=${ORDERER_PORT}
  export ORDERER_GENERAL_BOOTSTRAPMETHOD=file
  export ORDERER_GENERAL_BOOTSTRAPFILE=${TEST_NETWORK_HOME}/channel-artifacts/genesis.block

  export ORDERER_GENERAL_LOCALMSPID="OrdererMSP"
  export ORDERER_GENERAL_LOCALMSPDIR=${TEST_NETWORK_HOME}/organizations/ordererOrganizations/example.com/orderers/orderer${ordererNum}.example.com/msp
  export ORDERER_OPERATIONS_LISTENADDRESS=127.0.0.1:${ORDERER_LISTEN_PORT}

  # # enabled TLS
  export ORDERER_GENERAL_TLS_ENABLED=true
  export ORDERER_GENERAL_TLS_PRIVATEKEY=${TEST_NETWORK_HOME}/organizations/ordererOrganizations/example.com/orderers/orderer${ordererNum}.example.com/tls/server.key
  export ORDERER_GENERAL_TLS_CERTIFICATE=${TEST_NETWORK_HOME}/organizations/ordererOrganizations/example.com/orderers/orderer${ordererNum}.example.com/tls/server.crt
  export ORDERER_GENERAL_TLS_ROOTCAS=[${TEST_NETWORK_HOME}/organizations/ordererOrganizations/example.com/orderers/orderer${ordererNum}.example.com/tls/ca.crt]

  export ORDERER_FILELEDGER_LOCATION=${FILE_LEDGER_LOC}
  export ORDERER_CONSENSUS_WALDIR=${FILE_LEDGER_LOC}/etcdraft/wal
  export ORDERER_CONSENSUS_SNAPDIR=${FILE_LEDGER_LOC}/etcdraft/snapshot

  # ${BIN_DIR}/orderer
  nohup /bin/sh -c ${BIN_DIR}/orderer >> ${LOG_DIR}/orderer${ordererNum}.log &
  pid=$!
  echo $pid >pid/orderer${ordererNum}.pid
  echo "ok: $?"
  sleep 1
}

Start Up Peer Nodes

function startPeer(){
  export FABRIC_CFG_PATH=${TEST_NETWORK_HOME}/config/peer

  local peerNum=${1}
  : ${peerNum:=0}

  PEER_PORT=$(((($peerNum + 7) * 1000) + 51))
  PEER_LISTEN_PORT=$(((($peerNum + 7) * 1000) + 445))
  PEER_CHAINCODE_PORT=$(((($peerNum + 7) * 1000) + 52))
  export FABRIC_LOGGING_SPEC="INFO"
  # export FABRIC_LOGGING_SPEC="DEBUG"
  export CORE_VM_ENDPOINT=""
  export CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=""
  # # enabled TLS
  export CORE_PEER_TLS_ENABLED=true
  export CORE_PEER_PROFILE_ENABLED=true
  export CORE_PEER_MSPCONFIGPATH=${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/peers/peer${peerNum}.org1.example.com/msp
  export CORE_PEER_TLS_CERT_FILE=${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/peers/peer${peerNum}.org1.example.com/tls/server.crt
  export CORE_PEER_TLS_KEY_FILE=${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/peers/peer${peerNum}.org1.example.com/tls/server.key
  export CORE_PEER_TLS_ROOTCERT_FILE=${TEST_NETWORK_HOME}/organizations/peerOrganizations/org1.example.com/peers/peer${peerNum}.org1.example.com/tls/ca.crt
  export CORE_PEER_ID=peer${peerNum}.org1.example.com
  # tls
  export CORE_PEER_ADDRESS=peer${peerNum}.org1.example.com:${PEER_PORT}
  export CORE_PEER_LISTENADDRESS="0.0.0.0":${PEER_PORT}
  export CORE_PEER_CHAINCODEADDRESS=peer${peerNum}.org1.example.com:${PEER_CHAINCODE_PORT}
  export CORE_PEER_CHAINCODELISTENADDRESS="0.0.0.0":${PEER_CHAINCODE_PORT}
  export CORE_PEER_GOSSIP_BOOTSTRAP=peer${peerNum}.org1.example.com:${PEER_PORT}
  export CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer${peerNum}.org1.example.com:${PEER_PORT}
  export CORE_PEER_LOCALMSPID="Org1MSP"
  export CORE_OPERATIONS_LISTENADDRESS="0.0.0.0":${PEER_LISTEN_PORT}
  export CORE_PEER_FILESYSTEMPATH="${TEST_NETWORK_HOME}/production/peers/peer${peerNum}.org1.example.com"
  export CORE_LEDGER_SNAPSHOTS_ROOTDIR="${TEST_NETWORK_HOME}/production/peers/peer${peerNum}.org1.example.com/snapshots"


  pid=$!
  echo $pid >pid/peer${peerNum}.pid
  sleep 1
}

Create and Join Channel