fabric-ca是hyperledger的一个开源项目,基本架构就不多说,本文主要是讲述部署方式
1.环境准备:
系统版本信息
[root@k8s01 server]# uname -a
Linux k8s01 3.10.0-693.21.1.el7.x86_64 #1 SMP Wed Mar 7 19:03:37 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[root@k8s01 server]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
安装golang
以及libtool libtool-ltdl-devel docker-compose
yum install docker go libtool libtool-ltdl-devel python-pip
pip install --upgrade pip
pip install docker-compose
如果少安装 libtool-ltdl-devel
这个依赖包会获取代码以及编译的时候会报以下错误
[root@k8s01 go]# export GOPATH="/root/go/"
[root@k8s01 go]# go get -u github.com/hyperledger/fabric-ca/cmd/...
# github.com/hyperledger/fabric-ca/vendor/github.com/miekg/pkcs11
src/github.com/hyperledger/fabric-ca/vendor/github.com/miekg/pkcs11/pkcs11.go:26:18: fatal error: ltdl.h: No such file or directory
#include
^
compilation terminated.
正常执行命令之后在当前目录会生成以下文件
root@k8s01 go]# ls -l
总用量 0
drwxr-xr-x 2 root root 54 4月 1 17:07 bin
drwxr-xr-x 3 root root 25 4月 1 17:00 pkg
drwxr-xr-x 3 root root 24 4月 1 16:59 src
其中bin目录下有编译好的fabric-ca-server
以及fabric-ca-client
的二进制文件
[root@k8s01 bin]# ls -l
总用量 55528
-rwxr-xr-x 1 root root 26173880 4月 1 17:07 fabric-ca-client
-rwxr-xr-x 1 root root 30681064 4月 1 17:07 fabric-ca-server
2.编译 初始化 安装
但是当前的master 版本编译出来的二进制文件 直接执行会报错,错误如下
root@k8s01 bin]# ./fabric-ca-server init -b “admin:adminpw”
2018/04/01 17:19:28 [INFO] Created default configuration file at /root/go/demo/server/fabric-ca-server-config.yaml
panic: Version is not set for fabric-ca library
goroutine 1 [running]:
github.com/hyperledger/fabric-ca/lib/metadata.GetVersion(0xc420103b88, 0x75d572)
/root/go/src/github.com/hyperledger/fabric-ca/lib/metadata/version.go:58 +0x8b
github.com/hyperledger/fabric-ca/lib.(*Server).init(0xc42027cb40, 0x0, 0xeb0b80, 0xc420103bb8)
/root/go/src/github.com/hyperledger/fabric-ca/lib/server.go:98 +0x29
github.com/hyperledger/fabric-ca/lib.(*Server).Init(0xc42027cb40, 0xc42027cb00, 0x0, 0x0)
/root/go/src/github.com/hyperledger/fabric-ca/lib/server.go:88 +0x38
main.(*ServerCmd).init.func2(0xc42006ed80, 0xc42016a500, 0x0, 0x2, 0x0, 0x0)
/root/go/src/github.com/hyperledger/fabric-ca/cmd/fabric-ca-server/servercmd.go:102 +0xfc
github.com/hyperledger/fabric-ca/vendor/github.com/spf13/cobra.(*Command).execute(0xc42006ed80, 0xc42016a360, 0x2, 0x2, 0xc42006ed80, 0xc42016a360)
/root/go/src/github.com/hyperledger/fabric-ca/vendor/github.com/spf13/cobra/command.go:643 +0x3ef
github.com/hyperledger/fabric-ca/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc42006eb40, 0xd74688, 0xc42004fa90, 0xc42004fa90)
/root/go/src/github.com/hyperledger/fabric-ca/vendor/github.com/spf13/cobra/command.go:734 +0x339
github.com/hyperledger/fabric-ca/vendor/github.com/spf13/cobra.(*Command).Execute(0xc42006eb40, 0xc4200ca4b0, 0xc42004fa90)
/root/go/src/github.com/hyperledger/fabric-ca/vendor/github.com/spf13/cobra/command.go:692 +0x2b
main.(*ServerCmd).Execute(0xc42004fa90, 0x4, 0x1)
/root/go/src/github.com/hyperledger/fabric-ca/cmd/fabric-ca-server/servercmd.go:69 +0x2f
main.RunMain(0xc420010200, 0x4, 0x4, 0xc4200001a0, 0xc4200001a0)
/root/go/src/github.com/hyperledger/fabric-ca/cmd/fabric-ca-server/main.go:45 +0xb0
main.main()
/root/go/src/github.com/hyperledger/fabric-ca/cmd/fabric-ca-server/main.go:27 +0x45
这个错误 目前我没有去查究是什么原因引起,解决办法就是自己编译自己想要安装的版本,过程如下:
[root@k8s01 go]# cd src/github.com/hyperledger/fabric-ca/
[root@k8s01 fabric-ca]# ls -l
总用量 128
drwxr-xr-x 2 root root 37 4月 1 17:00 api
-rw-r--r-- 1 root root 68079 4月 1 17:00 CHANGELOG.md
-rw-r--r-- 1 root root 13 4月 1 17:00 ci.properties
drwxr-xr-x 4 root root 54 4月 1 17:00 cmd
-rw-r--r-- 1 root root 612 4月 1 17:00 CONTRIBUTING.md
drwxr-xr-x 4 root root 65 4月 1 17:00 docker
-rw-r--r-- 1 root root 3184 4月 1 17:00 docker-env.mk
drwxr-xr-x 3 root root 76 4月 1 17:00 docs
drwxr-xr-x 7 root root 114 4月 1 17:00 images
drwxr-xr-x 10 root root 4096 4月 1 17:00 lib
-rw-r--r-- 1 root root 11358 4月 1 17:00 LICENSE
-rw-r--r-- 1 root root 603 4月 1 17:00 MAINTAINERS.md
-rw-r--r-- 1 root root 10961 4月 1 17:00 Makefile
-rw-r--r-- 1 root root 9274 4月 1 17:00 README.md
drwxr-xr-x 2 root root 212 4月 1 17:00 release_notes
drwxr-xr-x 3 root root 323 4月 1 17:00 scripts
drwxr-xr-x 2 root root 36 4月 1 17:00 swagger
drwxr-xr-x 3 root root 35 4月 1 17:00 test
drwxr-xr-x 4 root root 4096 4月 1 17:00 testdata
drwxr-xr-x 3 root root 232 4月 1 17:00 util
drwxr-xr-x 6 root root 102 4月 1 17:00 vendor
[root@k8s01 fabric-ca]# git status
# 位于分支 release-1.1
无文件要提交,干净的工作区
[root@k8s01 fabric-ca]# git tag
v1.0.0
v1.0.0-alpha
v1.0.0-alpha2
v1.0.0-beta
v1.0.0-rc1
v1.0.1
v1.0.2
v1.0.3
v1.0.4
v1.0.5
v1.0.6
v1.1.0
v1.1.0-alpha
v1.1.0-preview
v1.1.0-rc1
[root@k8s01 fabric-ca]# git checkout v1.0.0
[root@k8s01 fabric-ca]# make fabric-ca-server
Building fabric-ca-server in bin directory ...
Built bin/fabric-ca-server
把生成的bin/fabric-ca-server放到PATH目录下然后就执行以下命令就可以成功启动了
[root@k8s01 demo]# fabric-ca-server init -b “admin:adminpw”
2018/04/01 17:29:30 [INFO] Configuration file location: /root/go/demo/server/fabric-ca-server-config.yaml
2018/04/01 17:29:30 [INFO] generating key: &{A:ecdsa S:256}
2018/04/01 17:29:30 [INFO] encoded CSR
2018/04/01 17:29:30 [INFO] signed certificate with serial number 358702324363320763837549523013060766731090884068
2018/04/01 17:29:30 [INFO] The CA key and certificate were generated for CA
2018/04/01 17:29:30 [INFO] The key was stored by BCCSP provider 'SW'
2018/04/01 17:29:30 [INFO] The certificate is at: /root/go/demo/server/ca-cert.pem
2018/04/01 17:29:30 [INFO] Initialized sqlite3 database at /root/go/demo/server/fabric-ca-server.db
2018/04/01 17:29:30 [INFO] Home directory for default CA: /root/go/demo/server
2018/04/01 17:29:30 [INFO] Initialization was successful
[root@k8s01 demo]# fabric-ca-server start -b “admin:adminpw”
2018/04/01 17:30:04 [INFO] Configuration file location: /root/go/demo/server/fabric-ca-server-config.yaml
2018/04/01 17:30:04 [INFO] Starting server in home directory: /root/go/demo/server
2018/04/01 17:30:04 [INFO] The CA key and certificate already exist
2018/04/01 17:30:04 [INFO] The key is stored by BCCSP provider 'SW'
2018/04/01 17:30:04 [INFO] The certificate is at: /root/go/demo/server/ca-cert.pem
2018/04/01 17:30:04 [INFO] Initialized sqlite3 database at /root/go/demo/server/fabric-ca-server.db
2018/04/01 17:30:04 [INFO] Home directory for default CA: /root/go/demo/server
2018/04/01 17:30:04 [INFO] Listening on http://0.0.0.0:7054
3.通过docker-compose启动服务
# cd $GOPATH/src/github.com/hyperledger/fabric-ca
[root@k8s01 fabric-ca]# make docker
Copying build/docker/bin/fabric-ca-client build/docker/bin/fabric-ca-server build/fabric-ca.tar.bz2 to build/image/fabric-ca/payload
mkdir -p build/image/fabric-ca/payload
cp build/docker/bin/fabric-ca-client build/docker/bin/fabric-ca-server build/fabric-ca.tar.bz2 build/image/fabric-ca/payload
Building docker fabric-ca image
docker build -t hyperledger/fabric-ca build/image/fabric-ca
Sending build context to Docker daemon 40.66 MB
Step 1/10 : FROM hyperledger/fabric-baseos:x86_64-0.3.1
Trying to pull repository docker.io/hyperledger/fabric-baseos ...
x86_64-0.3.1: Pulling from docker.io/hyperledger/fabric-baseos
aafe6b5e13de: Already exists
0a2b43a72660: Already exists
18bdd1e546d2: Already exists
8198342c3e05: Already exists
f56970a44fd4: Already exists
e32b597e7839: Already exists
a6e362fc71c4: Already exists
Digest: sha256:b9090d1e7b9991a1b904e9810121b4137cccb0bfc0a24e1c4d5f6d214bf5a271
Status: Downloaded newer image for docker.io/hyperledger/fabric-baseos:x86_64-0.3.1
---> 4b0cab202084
Step 2/10 : ENV FABRIC_CA_HOME /etc/hyperledger/fabric-ca-server
---> Running in b41c67e95a1c
---> 3860f4bc0aac
Removing intermediate container b41c67e95a1c
Step 3/10 : RUN mkdir -p $FABRIC_CA_HOME /var/hyperledger/fabric-ca-server
---> Running in 09ce56a8f9f6
---> 21429d1b6e7b
Removing intermediate container 09ce56a8f9f6
Step 4/10 : COPY payload/fabric-ca-client /usr/local/bin
---> 38ccfe7f43a0
Removing intermediate container e369e5cefe6f
Step 5/10 : RUN chmod +x /usr/local/bin/fabric-ca-client
---> Running in b7aa48c82685
---> 113c489b64d9
Removing intermediate container b7aa48c82685
Step 6/10 : COPY payload/fabric-ca-server /usr/local/bin
---> b58008c9f84e
Removing intermediate container eed321cec222
Step 7/10 : RUN chmod +x /usr/local/bin/fabric-ca-server
---> Running in 256cd247dd39
---> 81c4cb3a42a0
Removing intermediate container 256cd247dd39
Step 8/10 : ADD payload/fabric-ca.tar.bz2 $FABRIC_CA_HOME
---> 3fa8db29daf8
Removing intermediate container 79a8a9cc13c7
Step 9/10 : EXPOSE 7054
---> Running in 42da4faebee9
---> 3e44a38f3a62
Removing intermediate container 42da4faebee9
Step 10/10 : CMD fabric-ca-server start -b admin:adminpw
---> Running in 8c052c3a2008
---> 6f9ecf258249
Removing intermediate container 8c052c3a2008
Successfully built 6f9ecf258249
docker tag hyperledger/fabric-ca hyperledger/fabric-ca:x86_64-1.0.0
[root@k8s01 fabric-ca]#
[root@k8s01 fabric-ca]#
[root@k8s01 fabric-ca]#
[root@k8s01 fabric-ca]# cd docker/server
[root@k8s01 server]# ls -l
总用量 4
-rw-r--r-- 1 root root 408 4月 1 17:00 docker-compose.yml
[root@k8s01 server]# docker-compose up -d
Creating fabric-ca-server ... done
# make docker
# cd docker/server
# docker-compose up -d
启动成功如下
[root@k8s01 server]# docker ps | grep fabric
d7d2eb858dbc hyperledger/fabric-ca "sh -c 'fabric-ca-..." 17 seconds ago Up 16 seconds 0.0.0.0:7054->7054/tcp fabric-ca-server
[root@k8s01 server]# docker logs d7d2eb858dbc
2018/04/01 10:45:12 [INFO] Created default configuration file at /etc/hyperledger/fabric-ca-server/fabric-ca-server-config.yaml
2018/04/01 10:45:12 [INFO] Starting server in home directory: /etc/hyperledger/fabric-ca-server
2018/04/01 10:45:12 [INFO] generating key: &{A:ecdsa S:256}
2018/04/01 10:45:12 [INFO] encoded CSR
2018/04/01 10:45:12 [INFO] signed certificate with serial number 540562059670711329829878493272538385975410101489
2018/04/01 10:45:12 [INFO] The CA key and certificate were generated for CA
2018/04/01 10:45:12 [INFO] The key was stored by BCCSP provider 'SW'
2018/04/01 10:45:12 [INFO] The certificate is at: /etc/hyperledger/fabric-ca-server/ca-cert.pem
2018/04/01 10:45:13 [INFO] Initialized sqlite3 database at /etc/hyperledger/fabric-ca-server/fabric-ca-server.db
2018/04/01 10:45:13 [INFO] Home directory for default CA: /etc/hyperledger/fabric-ca-server
2018/04/01 10:45:13 [INFO] Listening on http://0.0.0.0:7054
参考
官网