说明:此次是通过CA服务器去创建联盟组织架构体系。
创建一个由两个组织org1.example.com和org2.example.com组成的的联盟。
还有一个组织example.com用来部署orderer。
每个组织都要有一个Admin用户,每个组件(peer/orderer)也需要一个账号,因此需要通过FabricCA创建7个用户
example.com: [email protected] orderer.example.com
org1.example.com: [email protected] peer0.org1.example.com peer1.org1.example.com
org2.example.com: [email protected] peer0.org2.example.com
这里只创建了Admin用户和每个组件的账号,普通用户的创建方式相同,只是普通用户的证书不需要添加到目标组件的admincerts目录中。
或者说一个用户的证书如果被添加到了对应组织或组件的msp/admincerts目录中,那么这个用户就称为对应的管理员。
//
重做的时候注意
rm -rf /opt/app/fabric/orderer/data
rm -rf /opt/app/fabric/peer/data
fabric-ca-client fabric-ca-server
https://hyperledger-fabric-ca.readthedocs.io/en/latest/users-guide.html#configuring-the-database
fabric-ca-server start -b admin:pass
mkdir -p `pwd`/fabric-ca-files/admin
fabric-ca-client enroll -u http://admin:pass@localhost:7054 -H `pwd`/fabric-ca-files/admin
export FABRIC_CA_CLIENT_HOME=`pwd`/fabric-ca-files/admin
mkdir -p $FABRIC_CA_CLIENT_HOME
fabric-ca-client enroll -u http://admin:pass@localhost:7054
上面的启动方式默认会创建两个组织,把他们都删除掉,然后自己创建
$ fabric-ca-client -H `pwd`/fabric-ca-files/admin affiliation list
fabric-ca-client -H `pwd`/fabric-ca-files/admin affiliation remove --force org1
fabric-ca-client -H `pwd`/fabric-ca-files/admin affiliation remove --force org2
执行下面命令创建联盟
fabric-ca-client -H `pwd`/fabric-ca-files/admin affiliation add com
fabric-ca-client -H `pwd`/fabric-ca-files/admin affiliation add com.example
fabric-ca-client -H `pwd`/fabric-ca-files/admin affiliation add com.example.org1
fabric-ca-client -H `pwd`/fabric-ca-files/admin affiliation add com.example.org2
注意:联盟是有层级的,创建联盟如下:
$ fabric-ca-client -H `pwd`/fabric-ca-files/admin affiliation list
2018/04/28 15:19:34 [INFO] 127.0.0.1:38160 GET /affiliations 201 0 "OK"
affiliation: com
affiliation: com.example
affiliation: com.example.org1
affiliation: com.example.org2
从Fabric-CA中,读取出用来签署用户的根证书
为example.com准备msp,将ca证书等存放example.com组织的目录中:
mkdir -p ./fabric-ca-files/example.com/msp
fabric-ca-client getcacert -M `pwd`/fabric-ca-files/example.com/msp //-M需要指定绝对路径
令执行结束后,会在fabric-ca-files/example.com/msp得到文件:
$ tree fabric-ca-files/example.com/msp/
example.com/msp/
|-- cacerts
| `-- localhost-7054.pem
|-- intermediatecerts
| `-- localhost-7054.pem
|-- keystore
`-- signcerts
同样的方式获取 其他组织 ,流程都是先创建组织的目录,然后 getcaert ,这里是用getcacert为每个组织准备需要的ca文件,在生成创始块的时候会用到.
然后还要添加2个目录, tlscacerts 和那个admincert
修改ca配置文件
id:
name: [email protected]
type: client
affiliation: com.example
maxenrollments: 0
attributes:
- name: hf.Registrar.Roles
value: client,orderer,peer,user
- name: hf.Registrar.DelegateRoles
value: client,orderer,peer,user
- name: hf.Registrar.Attributes
value: "*"
- name: hf.GenCRL
value: true
- name: hf.Revoker
value: true
- name: hf.AffiliationMgr
value: true
- name: hf.IntermediateCA
value: true
- name: role
value: admin
ecert: true
注意最后一行role属性,是我们自定义的属性,对于自定义的属性,要设置certs,在配置文件中需要单独设置ecert属性为true或者false。如果在命令行中,添加后缀:ecert表示true。
直接执行下面的命令,即可完成用户[email protected]注册,注意这时候的注册使用fabricCA的admin账号完成的:
fabric-ca-client register -H `pwd`/fabric-ca-files/admin --id.secret=password
如果不用–id.secret指定密码,会自动生成密码。
其它配置的含义是用户名为[email protected],类型是client,它能够管理com.example.*下的用户
这是 各个参数的意思
--id.name [email protected] //用户名
--id.type client //类型为client
--id.affiliation "com.example" //权利访问
hf.Registrar.Roles=client,orderer,peer,user //能够管理的用户类型
hf.Registrar.DelegateRoles=client,orderer,peer,user //可以授权给子用户管理的用户类型
hf.Registrar.Attributes=* //可以为子用户设置所有属性
hf.GenCRL=true //可以生成撤销证书列表
hf.Revoker=true //可以撤销用户
hf.AffiliationMgr=true //能够管理联盟
hf.IntermediateCA=true //可以作为中间CA
role=admin:ecert //自定义属性
完成注册之后,还需生成[email protected]凭证
$ mkdir -p ./fabric-ca-files/example.com/admin
$ fabric-ca-client enroll -u http://[email protected]:password@localhost:7054 -H `pwd`/fabric-ca-files/example.com/admin
$ ls ./fabric-ca-files/example.com/admin
fabric-ca-client-config.yaml msp/
这时候可以用[email protected]的身份查看联盟
$ fabric-ca-client affiliation list -H `pwd`/fabric-ca-files/example.com/admin
2018/04/28 15:35:10 [INFO] 127.0.0.1:38172 GET /affiliations 201 0 "OK"
affiliation: com
affiliation: com.example
affiliation: com.example.org1
affiliation: com.example.org2
最后将[email protected]的证书复制到example.com/msp/admincerts/中,这里很多操作都是直接这样复制管理员的证书直接复制到msp的管理员证书路径,这样的做用意其实是msp目录下要有这个证书把,应该是识别:
mkdir fabric-ca-files/example.com/msp/admincerts/
cp fabric-ca-files/example.com/admin/msp/signcerts/cert.pem fabric-ca-files/example.com/msp/admincerts/
只有这样,才能具备管理员权限
只有这样,才能具备管理员权限
只有这样,才能具备管理员权限
只有这样,才能具备管理员权限
只有这样,才能具备管理员权限
只有这样,才能具备管理员权限
只有这样,才能具备管理员权限
只有这样,才能具备管理员权限
只有这样,才能具备管理员权限
只有这样,才能具备管理员权限
创建目录
mkdir -p ./fabric-ca-files/org1.example.com/admin
修改ca配置文件
id:
name: [email protected]
type: client
affiliation: com.example.org1
maxenrollments: 0
attributes:
- name: hf.Registrar.Roles
value: client,orderer,peer,user
- name: hf.Registrar.DelegateRoles
value: client,orderer,peer,user
- name: hf.Registrar.Attributes
value: "*"
- name: hf.GenCRL
value: true
- name: hf.Revoker
value: true
- name: hf.AffiliationMgr
value: true
- name: hf.IntermediateCA
value: true
- name: role
value: admin
ecert: true
注册
fabric-ca-client register -H `pwd`/fabric-ca-files/admin --id.secret=password
生成凭证:
$ fabric-ca-client enroll -u http://[email protected]:password@localhost:7054 -H `pwd`/fabric-ca-files/org1.example.com/admin
$ ls ./fabric-ca-files/org1.example.com/admin
fabric-ca-client-config.yaml msp/
查看联盟:
$ fabric-ca-client affiliation list -H `pwd`/fabric-ca-files/org1.example.com/admin
2018/05/04 15:42:53 [INFO] 127.0.0.1:51298 GET /affiliations 201 0 "OK"
affiliation: com
affiliation: com.example
affiliation: com.example.org1
注意与[email protected]的区别,这里只能看到组织com.example.org1
将[email protected]的证书复制到org1.example.com的msp/admincerts中:
mkdir fabric-ca-files/org1.example.com/msp/admincerts/
cp fabric-ca-files/org1.example.com/admin/msp/signcerts/cert.pem fabric-ca-files/org1.example.com/msp/admincerts/
在[email protected]目录中也需要创建msp/admincerts目录,通过peer命令操作fabric的时候会要求admincerts存在
目录中也需要创建msp/admincerts目录,通过peer命令操作fabric的时候会要求admincerts存在
目录中也需要创建msp/admincerts目录,通过peer命令操作fabric的时候会要求admincerts存在
目录中也需要创建msp/admincerts目录,通过peer命令操作fabric的时候会要求admincerts存在
目录中也需要创建msp/admincerts目录,通过peer命令操作fabric的时候会要求admincerts存在
目录中也需要创建msp/admincerts目录,通过peer命令操作fabric的时候会要求admincerts存在
目录中也需要创建msp/admincerts目录,通过peer命令操作fabric的时候会要求admincerts存在
为org2.example.com的管理员[email protected]准备一个目录:
mkdir -p ./fabric-ca-files/org2.example.com/admin
修改ca配置文件
id:
name: [email protected]
type: client
affiliation: com.example.org2
maxenrollments: 0
attributes:
- name: hf.Registrar.Roles
value: client,orderer,peer,user
- name: hf.Registrar.DelegateRoles
value: client,orderer,peer,user
- name: hf.Registrar.Attributes
value: "*"
- name: hf.GenCRL
value: true
- name: hf.Revoker
value: true
- name: hf.AffiliationMgr
value: true
- name: hf.IntermediateCA
value: true
- name: role
value: admin
ecert: true
注册:
fabric-ca-client register -H `pwd`/fabric-ca-files/admin --id.secret=password
生成凭证:
$ fabric-ca-client enroll -u http://[email protected]:password@localhost:7054 -H `pwd`/fabric-ca-files/org2.example.com/admin
$ ls ./fabric-ca-files/org2.example.com/admin
fabric-ca-client-config.yaml msp/
查看联盟:
$ fabric-ca-client affiliation list -H `pwd`/fabric-ca-files/org2.example.com/admin
2018/05/02 16:49:00 [INFO] 127.0.0.1:50828 GET /affiliations 201 0 "OK"
affiliation: com
affiliation: com.example
affiliation: com.example.org2
[email protected]只能看到组织com.example.org2。
将[email protected]的证书复制到org2.example.com的msp/admincerts中:
mkdir fabric-ca-files/org2.example.com/msp/admincerts/
cp fabric-ca-files/org2.example.com/admin/msp/signcerts/cert.pem fabric-ca-files/org2.example.com/msp/admincerts/
在[email protected]中也需要创建msp/admincerts目录,通过peer命令操作fabric的时候会要求admincerts存在:
mkdir fabric-ca-files/org2.example.com/admin/msp/admincerts/
cp fabric-ca-files/org2.example.com/admin/msp/signcerts/cert.pem fabric-ca-files/org2.example.com/admin/msp/admincerts/
这里注册其它用户的话要用组织的org的组织管理员
使用[email protected]注册账号orderer.example.com。注意这时候指定的目录是fabric-ca-files/example.com/admin/。
修改 ca配置文件
id:
name: orderer.example.com
type: orderer
affiliation: com.example
maxenrollments: 0
attributes:
- name: role
value: orderer
ecert: true
注册以及生成凭证:
fabric-ca-client register -H `pwd`/fabric-ca-files/example.com/admin --id.secret=password
mkdir ./fabric-ca-files/example.com/orderer
fabric-ca-client enroll -u http://orderer.example.com:password@localhost:7054 -H `pwd`/fabric-ca-files/example.com/orderer
将[email protected]的证书复制到fabric-ca-files/example.com/orderer/msp/admincerts:
mkdir fabric-ca-files/example.com/orderer/msp/admincerts
cp fabric-ca-files/example.com/admin/msp/signcerts/cert.pem fabric-ca-files/example.com/orderer/msp/admincerts/
使用[email protected]注册账号peer0.org1.example.com。这时候指定的目录是fabric-ca-files/org1.example.com/admin/。
修改ca配置文件
id:
name: peer0.org1.example.com
type: peer
affiliation: com.example.org1
maxenrollments: 0
attributes:
- name: role
value: peer
ecert: true
注册以及生成凭证:
fabric-ca-client register -H `pwd`/fabric-ca-files/org1.example.com/admin --id.secret=password
mkdir ./fabric-ca-files/org1.example.com/peer0
fabric-ca-client enroll -u http://peer0.org1.example.com:password@localhost:7054 -H `pwd`/fabric-ca-files/org1.example.com/peer0
将[email protected]的证书复制到fabric-ca-files/org1.example.com/peer0/msp/admincerts:
mkdir fabric-ca-files/org1.example.com/peer0/msp/admincerts
cp fabric-ca-files/org1.example.com/admin/msp/signcerts/cert.pem fabric-ca-files/org1.example.com/peer0/msp/admincerts/
就是你生成的联盟要怎么和你的配置文件中的组织的结构进行关联
上述操作全部执行完毕后,得到了CA服务器单独注册的一套证书结构
关联操作:
修改configtx.yaml,将其中的msp路径修改为通过fabric-ca创建的msp目录
修改configtx.yaml,将其中的msp路径修改为通过fabric-ca创建的msp目录
修改configtx.yaml,将其中的msp路径修改为通过fabric-ca创建的msp目录
修改configtx.yaml,将其中的msp路径修改为通过fabric-ca创建的msp目录
修改configtx.yaml,将其中的msp路径修改为通过fabric-ca创建的msp目录
修改configtx.yaml,将其中的msp路径修改为通过fabric-ca创建的msp目录
只需要修改 configtx.yaml配置文件中的 Organizations 对象中的指定路径即可
注意configtx.yaml中使用的每个组织的msp,不是组件的或者用户的
Organizations:
- &OrdererOrg
Name: OrdererOrg
ID: OrdererMSP
MSPDir: ./fabric-ca-files/example.com/msp
- &Org1
Name: Org1MSP
ID: Org1MSP
MSPDir: ./fabric-ca-files/org1.example.com/msp
AnchorPeers:
- Host: peer0.org1.example.com
Port: 7051
- &Org2
Name: Org2MSP
ID: Org2MSP
MSPDir: ./Org/org2.example.com/msp
AnchorPeers:
- Host: peer0.org2.example.com
Port: 7051
重新部署时,注意将各个机器上已经启动的服务停止,并删除原先的文件,data目录一定要清空! 否则会因为以前数据的残留,导致fabric无法正常工作。
重新部署时,注意将各个机器上已经启动的服务停止,并删除原先的文件,data目录一定要清空! 否则会因为以前数据的残留,导致fabric无法正常工作。
重新部署时,注意将各个机器上已经启动的服务停止,并删除原先的文件,data目录一定要清空! 否则会因为以前数据的残留,导致fabric无法正常工作。
重新部署时,注意将各个机器上已经启动的服务停止,并删除原先的文件,data目录一定要清空! 否则会因为以前数据的残留,导致fabric无法正常工作。
//
scp -r orderer.example.com/* [email protected]:/opt/app/fabric/orderer/
scp -r peer0.org1.example.com/* [email protected]:/opt/app/fabric/peer/
scp -r peer1.org1.example.com/* [email protected]:/opt/app/fabric/peer/
scp -r peer0.org2.example.com/* [email protected]:/opt/app/fabric/peer/
其他后续再谈,累死了