You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Ubuntu 16中无Docker安装Hyperledger Fabric并配置服务与多主机网络

Alright, let's break down your questions step by step—no Docker, setting up Fabric as system services, and multi-host networks on Ubuntu 16.04. I've walked through this process multiple times, so here's a practical, hands-on guide:

1. Installing Hyperledger Fabric without Docker on Ubuntu 16.04

First, we need to get all dependencies sorted and compile Fabric from source, since we're skipping Docker.

  • Install base dependencies:
    Update your packages and grab the tools we need for compilation:

    sudo apt-get update && sudo apt-get install -y git make gcc build-essential
    
  • Set up Go environment (Fabric 2.x requires Go 1.14+, which is compatible with Ubuntu 16.04):

    • Download Go 1.14.15 (a stable long-term release):
      wget https://dl.google.com/go/go1.14.15.linux-amd64.tar.gz
      
    • Extract it to /usr/local:
      sudo tar -C /usr/local -xzf go1.14.15.linux-amd64.tar.gz
      
    • Configure environment variables by editing ~/.bashrc:
      Add these lines at the end:
      export PATH=$PATH:/usr/local/go/bin
      export GOPATH=$HOME/go
      export PATH=$PATH:$GOPATH/bin
      
    • Reload the shell and verify:
      source ~/.bashrc
      go version  # Should output go1.14.15 linux/amd64
      
  • Download and compile Fabric core components:

    • Create the required directory structure and clone the repo:
      mkdir -p $GOPATH/src/github.com/hyperledger
      cd $GOPATH/src/github.com/hyperledger
      git clone https://github.com/hyperledger/fabric.git
      cd fabric
      git checkout v2.2.10  # LTS version, stable for production
      
    • Compile all Fabric binaries (peer, orderer, configtxgen, etc.):
      make all
      
    • Add the compiled binaries to your PATH (add this to ~/.bashrc too for persistence):
      export PATH=$PATH:$GOPATH/src/github.com/hyperledger/fabric/build/bin
      
    • Verify installation:
      peer version
      orderer version
      
  • Optional: Install Fabric CA (for certificate management):

    cd $GOPATH/src/github.com/hyperledger
    git clone https://github.com/hyperledger/fabric-ca.git
    cd fabric-ca
    git checkout v1.5.7
    make all
    export PATH=$PATH:$GOPATH/src/github.com/hyperledger/fabric-ca/build/bin
    
2. Configuring Fabric Components as Systemd Services

Ubuntu 16.04 uses systemd, so we'll create service files to run orderer and peer as background services that start on boot.

First, organize your Fabric data and configs in a central directory:

sudo mkdir -p /opt/hyperledger/{orderer,peer,config,certs}
  • Place your genesis block, channel transaction files in /opt/hyperledger/config
  • Place all MSP/TLS certificates in /opt/hyperledger/certs
  • Update core.yaml (peer config) and config.yaml (orderer config) to point to these paths (adjust paths like peer.fileSystemPath or orderer.fileSystemPath accordingly).

Set up Orderer Service

Create a systemd service file:

sudo nano /etc/systemd/system/hyperledger-orderer.service

Paste this content (adjust User, Group, and paths to match your setup):

[Unit]
Description=Hyperledger Fabric Orderer Service
After=network.target

[Service]
User=ubuntu
Group=ubuntu
ExecStart=/home/ubuntu/go/src/github.com/hyperledger/fabric/build/bin/orderer start --configPath /opt/hyperledger/orderer/config.yaml
Restart=always
RestartSec=5
Environment=ORDERER_GENERAL_LOGLEVEL=info

[Install]
WantedBy=multi-user.target

Enable and start the service:

sudo systemctl daemon-reload
sudo systemctl enable hyperledger-orderer
sudo systemctl start hyperledger-orderer
# Check status
sudo systemctl status hyperledger-orderer

Set up Peer Service

Create the peer service file:

sudo nano /etc/systemd/system/hyperledger-peer.service

Paste this content:

[Unit]
Description=Hyperledger Fabric Peer Service
After=network.target hyperledger-orderer.service

[Service]
User=ubuntu
Group=ubuntu
ExecStart=/home/ubuntu/go/src/github.com/hyperledger/fabric/build/bin/peer node start --configPath /opt/hyperledger/peer/core.yaml
Restart=always
RestartSec=5
Environment=CORE_LOGGING_LEVEL=info

[Install]
WantedBy=multi-user.target

Enable and start the peer service:

sudo systemctl daemon-reload
sudo systemctl enable hyperledger-peer
sudo systemctl start hyperledger-peer
3. Setting Up a Multi-Host Fabric Network

The key here is shared certificates, proper network connectivity, and correct endpoint configuration across all hosts.

Step 1: Prepare Shared Assets on the Orderer Host

  • Use cryptogen to generate MSP/TLS certificates for all orderers, peers, and organizations (create a crypto-config.yaml first to define your network topology).
  • Use configtxgen to generate the genesis block (genesis.block) and channel transaction file (channel.tx).
  • Copy these certificates and config files to all peer hosts using scp or rsync:
    scp -r /opt/hyperledger/certs user@peer-host-ip:/opt/hyperledger/
    scp /opt/hyperledger/config/{genesis.block,channel.tx} user@peer-host-ip:/opt/hyperledger/config/
    

Step 2: Ensure Network Connectivity

  • Open required ports on all hosts (use ufw or your firewall):
    # On orderer host
    sudo ufw allow 7050/tcp  # Orderer gRPC port
    # On peer hosts
    sudo ufw allow 7051/tcp  # Peer gRPC port
    sudo ufw allow 7053/tcp  # Peer event port
    
  • Update each peer's core.yaml to set the external endpoint (so other peers can reach it):
    peer:
      gossip:
        externalendpoint: peer-host-ip:7051
    
  • Update the orderer address in each peer's core.yaml and the orderer's config.yaml to use the orderer's public IP/hostname.

Step 3: Start Services Across All Hosts

  • Start the orderer service on the orderer host (as set up in section 2).
  • Start the peer service on each peer host.

Step 4: Create and Join the Channel

  • On one peer host, create the channel:
    peer channel create -o orderer-ip:7050 -c mychannel -f /opt/hyperledger/config/channel.tx --tls --cafile /opt/hyperledger/certs/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
    
  • Copy the generated mychannel.block to all other peer hosts, then have each peer join the channel:
    peer channel join -b mychannel.block
    

Step 5: Verify the Network

Install, approve, and commit a test chaincode, then submit transactions across peers to confirm cross-host communication works:

# Install chaincode on a peer
peer lifecycle chaincode install mycc.tar.gz
# Approve and commit it (follow Fabric 2.x chaincode lifecycle steps)
# Invoke a transaction
peer chaincode invoke -o orderer-ip:7050 -c mychannel -n mycc -c '{"Args":["init","a","100","b","200"]}' --tls --cafile /opt/hyperledger/certs/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

内容的提问来源于stack exchange,提问作者user2571216

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:39:17