Skip to content

Instantly share code, notes, and snippets.

@hi5san
Last active August 7, 2018 16:31
Show Gist options
  • Save hi5san/2b0bbbdd7b506470fc477092cf213a38 to your computer and use it in GitHub Desktop.
Save hi5san/2b0bbbdd7b506470fc477092cf213a38 to your computer and use it in GitHub Desktop.
Hyperledger Fabric byfn docker-compose with fluent logging connected to EK stack (no Logstash in middle)

What is this?

A sample docker compose file for BYFN from fabric-samples with fluentd log driver output enabled, and is connected to ElasticSearch and Kibana.

NOTE The docker-compose file attached here is based on BYFN (fabric-samples) matching hyperledger fabric v1.1. However, it should be trivial to apply for others (such as v1.2).

Thanks to this blog in Qiita (Japan) - https://qiita.com/cgetc/items/345e3c686910b30ba49f.

How to use?

See Hyperledger Fabric byfn with fluent logging but use the docker-compose file and fluentd.conf attached here instead.

Here are the quick steps

  1. Change to fabric-samples/first-network directory.
  2. Create fluentd and elasticsearch directory under first-network directory.
  3. Copy docker-compose-cli-logging-EK.yaml and replace docker-compose-cli.yaml under first-network directory.
  4. Place fluentd.conf and fluentd Dockerfile under fluentd directory.
  5. Place elasticsearch Dockerfile under elasticsearch directory.
  6. Set VM max memory to 262144 or more (ElasticSearch requires more than default container memory size).
  1. Start byfn.sh
  • $ ./byfn.sh -m up
    Note: "Error response from daemon: configured logging driver does not support reading" message is expected so don't worry.
  1. Access Kibana by connecting to http://localhost:5601/.
  • For new Kibana users: Set "*" for index pattern and save and click "Discover" to see logs. You also may want to click "Last 15 minutes" on the upper right corner and select "Today", if your logs are more than 15 minutes away.

X. To quit, simply teardown byfn.

  • $ ./byfn.sh -m down
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
version: '2'
volumes:
orderer.example.com:
peer0.org1.example.com:
peer1.org1.example.com:
peer0.org2.example.com:
peer1.org2.example.com:
networks:
byfn:
services:
orderer.example.com:
extends:
file: base/docker-compose-base.yaml
service: orderer.example.com
container_name: orderer.example.com
networks:
- byfn
depends_on:
- logger
logging:
driver: fluentd
options:
tag: docker.{{.ID}}
peer0.org1.example.com:
container_name: peer0.org1.example.com
extends:
file: base/docker-compose-base.yaml
service: peer0.org1.example.com
networks:
- byfn
depends_on:
- logger
logging:
driver: fluentd
options:
tag: docker.{{.ID}}
peer1.org1.example.com:
container_name: peer1.org1.example.com
extends:
file: base/docker-compose-base.yaml
service: peer1.org1.example.com
networks:
- byfn
depends_on:
- logger
logging:
driver: fluentd
options:
tag: docker.{{.ID}}
peer0.org2.example.com:
container_name: peer0.org2.example.com
extends:
file: base/docker-compose-base.yaml
service: peer0.org2.example.com
networks:
- byfn
depends_on:
- logger
logging:
driver: fluentd
options:
tag: docker.{{.ID}}
peer1.org2.example.com:
container_name: peer1.org2.example.com
extends:
file: base/docker-compose-base.yaml
service: peer1.org2.example.com
networks:
- byfn
depends_on:
- logger
logging:
driver: fluentd
options:
tag: docker.{{.ID}}
cli:
container_name: cli
image: hyperledger/fabric-tools:$IMAGE_TAG
tty: true
environment:
- GOPATH=/opt/gopath
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- CORE_LOGGING_LEVEL=DEBUG
- CORE_PEER_ID=cli
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051
- CORE_PEER_LOCALMSPID=Org1MSP
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
- CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
- CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: /bin/bash -c './scripts/script.sh ${CHANNEL_NAME} ${DELAY}; sleep $TIMEOUT'
volumes:
- /var/run/:/host/var/run/
- ./../chaincode/:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go
- ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
- ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
- ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
depends_on:
- logger
- orderer.example.com
- peer0.org1.example.com
- peer1.org1.example.com
- peer0.org2.example.com
- peer1.org2.example.com
networks:
- byfn
logging:
driver: fluentd
options:
tag: docker.{{.ID}}
logger:
container_name: fluentd
#image: fluent/fluentd
build: ./fluentd
ports:
- "24224:24224"
volumes:
- ./fluentd/log:/fluentd/log
- ./fluentd/:/fluentd/etc
environment:
FLUENTD_CONF: fluentd.conf
links:
- "elasticsearch"
- "kibana"
elasticsearch:
build: elasticsearch
expose:
- 9200
kibana:
image: kibana
links:
- "elasticsearch"
ports:
- "5601:5601"
FROM fluent/fluentd
RUN ["gem", "install", "fluent-plugin-elasticsearch", "--no-rdoc", "--no-ri"]
FROM elasticsearch
RUN echo "network.bind_host: 0.0.0.0" >> /usr/share/elasticsearch/config/elasticsearch.yml
<source>
@type forward
port 24224
bind 0.0.0.0
</source>
<match docker.**>
@type elasticsearch
log_level debug
host elasticsearch
port 9200
include_tag_key true
logstash_format true
flush_interval 5s
</match>
#<match fluent.**>
# @type stdout
#</match>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment