Ubuntu 部署 Hyperledger Fabric 1.4.2

Ubuntu 部署 Hyperledger Fabric 1.4.2

1 前言

Hyperledger fabric的fabric-sample運行需要三樣東西:

1 fabric-sample工程

2 fabric網(wǎng)絡(luò)的docker images

??主要有八個:hyperledger/fabric-javaenv像吻、hyperledger/fabric-ca、hyperledger/fabric-tools、hyperledger/fabric-ccenv、hyperledger/fabric-orderer、hyperledger/fabric-peer颅湘、hyperledger/fabric-zookeeper、hyperledger/fabric-kafka

3 可執(zhí)行二進制文件

??主要是兩個:hyperledger-fabric-ca-linux-amd64-1.4.2.tar.gz、

hyperledger-fabric-linux-amd64-1.4.2.tar.gz


從fabric1.4.1版本開始察署,fabric支持raft共識,1.4.0版本以前是kafka共識峻汉,其實在0.6版本以前fabric是支持BFT共識的贴汪。

從kafka共識向raft共識演進主要原因有兩點:

1 kafka運維不方便

??0.6版本fabric是基于BFT的共識,但是遇到了一些性能問題休吠,后面采用了kafka共識扳埂。fabric前期基于kafka,是一種簡單粗暴實現(xiàn)方法瘤礁,主要考慮的是快速實現(xiàn)阳懂,沒有考慮運維部署、易用的成本

[if !supportLists]l?? [endif]需要同時維護zk集群和kafka集群柜思,其中zk集群需要至少需要3個節(jié)點岩调,kafka至少需要4個節(jié)點

[if !supportLists]l?? [endif]zk集群和kafka集群,會保存日志幾個小時(可配置)赡盘,集群異常重啟号枕,每個節(jié)點的日志有所不同,有時會造成 排序節(jié)點異常

[if !supportLists]l?? [endif]排序節(jié)點同時需要一批組織維護陨享,需要構(gòu)建一個 order集群網(wǎng)絡(luò)葱淳,并持久化賬本

[if !supportLists]l?? [endif]整個排序集群钝腺,部署起來參數(shù)非常多,不易維護

[if !supportLists]l?? [endif]kafka和zookeeper的設(shè)計不適用于大型網(wǎng)絡(luò)

[if !supportLists]l?? [endif]在kafka共識模式中蛙紫,orderer與orderer之間不會互相直接建立連接拍屑,而是與kafka連接

2 raft為未來平滑演進fabric

BFT共識做準備

raft 和 bft是未來的趨勢,raft和bft都會部署在orderer節(jié)點上坑傅,兩者網(wǎng)絡(luò)架構(gòu)一樣僵驰,可以支持未來平滑演進

[if !supportLists]l?? [endif]在可信的環(huán)境下,基于性能的考慮唁毒,大家樂于考慮使用raft?

[if !supportLists]l? [endif]kafka缺乏信任的基礎(chǔ)蒜茴,選擇使用bft,聯(lián)盟鏈的節(jié)點有限浆西,性能也不會是大的問題


2 前期準備

系統(tǒng)軟件源改為 aliyun

?????? 方法:進入system setting?? 然后點擊software and update粉私,修改download from

[if !vml]

[endif]

安裝vim????????? sudo apt-get install vim

安裝git??????????? sudo apt-get install git

安裝curl????????? sudo apt-get install curl

安裝wget??????? sudo apt-get install wget


安裝 ssh

sudo apt-get

update

sudo apt-get

install ssh

3 環(huán)境準備

[if !supportLists]·????????[endif]安裝go1.11 以及以上版本

[if !supportLists]·????????[endif]安裝docker

17.06.2-ce 以及以上版本

[if !supportLists]·????????[endif]安裝docker-compose?1.14.0以及以上版本

[if !supportLists]·????????[endif]git 拉下fabric-sample 項目

[if !supportLists]·????????[endif]下載docker

image鏡像

3.1 GO安裝

3.1.1下載壓縮包??

無法翻墻 可以去這個網(wǎng)站,

https://studygolang.com/dl

cd ~?

wget https://studygolang.com/dl/golang/go1.12.1.linux-amd64.tar.gz??? //下載安裝go 1.12.1

tar -zxvf go1.12.1.linux-amd64.tar.gz -C/usr/local??? //解壓

3.1.2 配置環(huán)境變量

sudo gedit /etc/profile, 追加以下配置到環(huán)境變量

export?GOROOT=/usr/local/go

export?PATH=$PATH:/usr/local/go/bin

export? GOPATH=/opt/go

export? PATH=$PATH:/opt/go/bin

source /etc/profile //立即適應(yīng)新環(huán)境

測試

輸入 go version,成功查看版本信息雜表示配置成功近零。

3.2 安裝Docker-CE

1 如果已經(jīng)安裝docker诺核,但是沒有docker 17.06.2-ce 以及以上版本

sudo apt-getremove docker docker-engine docker.io? //先卸載

2 前置工作

sudo apt-get

updatesudo apt-get

install apt-transport-https ca-certificates curl software-properties-commoncurl -fsSL

https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add –

3 加入apt倉庫中

sudo

add-apt-repository \

?? "deb [arch=amd64]https://download.docker.com/linux/ubuntu \

?? $(lsb_release -cs) \

?? stable"sudo apt-get

update

4 安裝 Docker-ce

sudo apt-get

install docker-ce

5 添加阿里云的docker hub鏡像

sudo mkdir

-p /etc/docker

sudo gedit /etc/docker/daemon.json

6 將下列內(nèi)容寫入deamon.json文件中,并保存退出

{

?"registry-mirrors":["https://obou6wyb.mirror.aliyuncs.com"]

}

7 接下來執(zhí)行

sudo

systemctl daemon-reload

sudo

systemctl restart docker

8 將當前用戶添加到 Docker

Group(支持不使用 sudo 執(zhí)行 docker 命令)

sudo usermod-aG docker xxx?? (xxx為當前用戶名)

sudo chmod

-R 777 /var/run/docker.sock

9 測試

docker version

3.3 安裝Docker-Compose

1 安裝

sudo apt-get

install python-pip

sudo pip

install docker-compose

2 測試

docker-compose

version

4下載 fabric 及其鏡像

4.1 創(chuàng)建并進入工作目錄

mkdir -p

$GOPATH/src/github.com/hyperledger/

cd

$GOPATH/src/github.com/hyperledger/

4.2 克隆源碼

git clone

https://github.com/hyperledger/fabric.git

cd fabric

git checkout

v1.4.2

4.3 下載鏡像和fabric-samples和二進制文件

cd $GOPATH/src/github.com/hyperledger/fabric/scripts/


執(zhí)行scripts目錄中的bootstrap.sh腳本會自動下載fabric-samples和fabric鏡像

./bootstrap.sh1.4.2 1.4.2 0.4.15? //腳本的使用方法:bootstrap.sh [Fabric版本 [CA版本 [第三方版本]]] [選項]


由于鏡像較大久信,此過程需要較長時間完成窖杀。腳本完成后會發(fā)現(xiàn)當前目錄有了fabric-samples目錄,之后執(zhí)行:

docker

images

當出現(xiàn)下列內(nèi)容時說明鏡像部署成功:

hyperledger/fabric-javaenv???? 1.4.2?????????????? 1cd707531ce7??????? 4 weeks ago???????? 1.76GB

hyperledger/fabric-javaenv???? latest????????????? 1cd707531ce7??????? 4 weeks ago???????? 1.76GB

hyperledger/fabric-ca????????? 1.4.2?????????????? f289675c9874??????? 4 weeks ago???????? 253MB

hyperledger/fabric-ca????????? latest????????????? f289675c9874??????? 4 weeks ago???????? 253MB

hyperledger/fabric-tools?????? 1.4.2?????????????? 0abc124a9400??????? 4 weeks ago???????? 1.55GB

hyperledger/fabric-tools?????? latest????????????? 0abc124a9400??????? 4 weeks ago???????? 1.55GB

hyperledger/fabric-ccenv?????? 1.4.2?????????????? fc0f502399a6??????? 4 weeks ago???????? 1.43GB

hyperledger/fabric-ccenv?????? latest????????????? fc0f502399a6??????? 4 weeks ago???????? 1.43GB

hyperledger/fabric-orderer???? 1.4.2?????????????? 362021998003??????? 4 weeks ago???????? 173MB

hyperledger/fabric-orderer???? latest????????????? 362021998003??????? 4 weeks ago???????? 173MB

hyperledger/fabric-peer??????? 1.4.2?????????????? d79f2f4f3257??????? 4 weeks ago???????? 178MB

hyperledger/fabric-peer??????? latest????????????? d79f2f4f3257??????? 4 weeks ago???????? 178MB

hyperledger/fabric-zookeeper?? 0.4.15????????????? 20c6045930c8??????? 5 months ago??????? 1.43GB

hyperledger/fabric-zookeeper?? latest????????????? 20c6045930c8??????? 5 months ago??????? 1.43GB

hyperledger/fabric-kafka??????0.4.15????????????? b4ab82bbaf2f??????? 5 months ago??????? 1.44GB

hyperledger/fabric-kafka?????? latest????????????? b4ab82bbaf2f??????? 5 months ago??????? 1.44GB

5 快速部署網(wǎng)絡(luò)

5.1 復(fù)制二進制文件

將二進制文件復(fù)制到 usr/local/bin 目錄

cd $GOPATH/src/github.com/hyperledger/fabric/scripts/fabric-samples/bin

sudo cp -r .

/usr/local/bin

這樣就可以到處使用這些可執(zhí)行二進制文件了裙士∪肟停可以看到8個二進制文件

configtxgen???cryptogen? fabric-ca-client? orderer

configtxlator?discover?? idemixgen???????? peer

[if !vml]

[endif]

這幾個二進制文件主要是從hyperledger-fabric-ca-linux-amd64-1.4.2.tar.gz和hyperledger-fabric-linux-amd64-1.4.2.tar.gz解壓后得到的


如果下載緩慢,可以在百度云盤下載

https://pan.baidu.com/s/1YfSwjrEybfozhqFYw7yCPA

5.2 啟動和測試網(wǎng)絡(luò)

cd $GOPATH/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network

./byfn.sh -mgenerate -o etcdraft? //使用raft共識

./byfn.sh up-o etcdraft? //使用raft共識


啟動和測試日志:

[if !vml]

[endif]

5.3 關(guān)閉網(wǎng)絡(luò)

./byfn.sh down

6 解釋bootstrap.sh

6.1 腳本的使用方法

bootstrap.sh [Fabric版本 [CA版本 [第三方版本]]] [選項]

6.2 bootstrap.sh做了什么

bootstrap主要是安裝sample 腿椎,fabric 網(wǎng)絡(luò)的二進制文件桌硫,以及 docker 鏡像(Install Samples, Binaries and Docker Images)

打開 bootstrap.sh 文件 大致查看以下內(nèi)容

[if !supportLists]·????????[endif]dockerFabricPull: 下載 fabric-peer fabric-orderer

fabric-ccenv fabric-javaenv fabric-tools 鏡像

[if !supportLists]·????????[endif]dockerThirdPartyImagesPull: 下載 couchdb kafka zookeeper 鏡像

[if !supportLists]·????????[endif]dockerCaPull: 下載 fabric-ca 鏡像

[if !supportLists]·????????[endif]samplesInstall: git clone -b master https://github.com/hyperledger/fabric-samples.git

[if !supportLists]·????????[endif]binariesInstall: 安裝 hyperledger-fabric

hyperledger-fabric-ca 二進制

總結(jié):

if [ "$SAMPLES" == "true" ]; then

? echo

? echo "Installing hyperledger/fabric-samples

repo"

? echo

? samplesInstall

fi

if [ "$BINARIES" == "true" ]; then

? echo

? echo "Installing Hyperledger Fabric

binaries"

? echo

? binariesInstall

fi

if [ "$DOCKER" == "true" ]; then

? echo

? echo "Installing Hyperledger Fabric docker

images"

? echo

? dockerInstall

fi

1. 安裝hyplerledger fabric-sample

2. 安裝hyplerledger fabric binaries

文件介紹類型依賴

peer賬本(對等)節(jié)點程序,負責維護賬本數(shù)據(jù)啃炸,執(zhí)行鏈碼服務(wù)core.yaml

orderer共識服務(wù)程序铆隘,負責打包交易,使用通道訂閱給其他賬本節(jié)點服務(wù)orderer.yaml

cryptogen生成 x509標準的證書以及密鑰工具crypto-config.yaml

configtxgen生成共識服務(wù)啟動以及通道創(chuàng)建所需配置數(shù)據(jù)工具configtx.yaml

configtxlator用來將通道配置信息轉(zhuǎn)換為可讀形式工具

discoverfabric discovery 服務(wù)的命令行客戶端服務(wù)

fabric-ca-clienthyperledger fabric 證書認證客戶端工具

idemixgenHyperledger Fabric 生成關(guān)鍵材料時被用于身份混淆MSP的工具工具

3. 安裝hyplerledger fabric dockerimages

打開 fabric-samples/bin/get-docker-images.sh 可以發(fā)現(xiàn)南用,總共下載的鏡像包括如下:

鏡像介紹

fabric-peer賬本(對等)節(jié)點的鏡像

fabric-orderer共識服務(wù)節(jié)點的鏡像

fabric-ccenv鏈碼環(huán)境鏡像

fabric-tools工具庫鏡像

fabric-kafka分布式消息隊列鏡像

fabric-zookeeper分布式協(xié)調(diào)服務(wù)鏡像

fabric-couchdb狀態(tài)存儲庫鏡像

fabric-javaenv


6.3 有多種方法可以運行bootstrap.sh腳本

1 在hyperledger/fabric/scripts下可以找到

$GOPATH/src/github.com/hyperledger/fabric/scripts


2 通過https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh

自動安裝腳本的url為https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh膀钠,縮略后的url為http://bit.ly/2ysbOFE,如果后面縮略的網(wǎng)址打不開训枢,請使用前者代替托修。


curl -sSL

https://bit.ly/2ysbOFE | bash -s -- 1.4.2 1.4.2 0.4.15


3 將https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh復(fù)制到本地使用

curl -sS

https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh

-o ./scripts/bootstrap.sh

# Change file mode to executable

chmod +x ./scripts/bootstrap.sh

# Download binaries and docker images

./scripts/bootstrap.sh

1.4.2 1.4.2 0.4.15


7 二進制可執(zhí)行文件

7.1 通過bootstrap.sh安裝

Bootstrap.sh首先會從github上將fabric-samples下載下來,然后會從https://nexus.hyperledger.org下載可執(zhí)行二進制文件恒界。如下圖睦刃,并解壓到fabric-samples/bin目錄下

[if !vml]

[endif]

https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/linux-amd64-1.4.2/hyperledger-fabric-linux-amd64-1.4.2.tar.gz


https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric-ca/hyperledger-fabric-ca/linux-amd64-1.4.2/hyperledger-fabric-ca-linux-amd64-1.4.2.tar.gz


這兩個文件不是很好下載,可以通過windows代理下載十酣,下載后手動放入$GOPATH/src/hyperledger/fabric/scripts/fabric-samples目錄下涩拙,然后回到scripts目錄下繼續(xù)執(zhí)行bootstrap.sh腳本


7.2 編譯安裝

進入hyperledger/fabric目錄际长,自行編譯這些工具:make cryptogen configtxgen configtxlator peer orderer peer-docker

orderer-docker tools-docker,在.build/bin/目錄下就是我們需要的工具兴泥,編譯也會生成docker images

參考:

1https://hyperledgercn.github.io/hyperledgerDocs/build_network_zh/

2https://hyperledger-fabric.readthedocs.io/en/latest/prereqs.html

3 https://hyperledger-fabric.readthedocs.io/en/release-1.4/prereqs.html

4 https://blog.csdn.net/smallone233/article/details/86569536

5 https://www.cnblogs.com/llongst/p/9482038.html

6 一個動畫演示raft算法

http://thesecretlivesofdata.com/raft/?

7 https://blog.csdn.net/sinat_36742186/article/details/88390019

8 https://blog.csdn.net/sinat_36742186/article/details/80809954

9 https://blog.csdn.net/diligent_lee/article/details/79098302

10 https://blog.csdn.net/so5418418/article/details/78355868

11https://www.cnblogs.com/informatics/p/8276172.html

12 http://www.reibang.com/p/e5ec0b4e8075

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末工育,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子搓彻,更是在濱河造成了極大的恐慌如绸,老刑警劉巖,帶你破解...
    沈念sama閱讀 222,590評論 6 517
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件旭贬,死亡現(xiàn)場離奇詭異怔接,居然都是意外死亡,警方通過查閱死者的電腦和手機稀轨,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,157評論 3 399
  • 文/潘曉璐 我一進店門扼脐,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人奋刽,你說我怎么就攤上這事瓦侮。” “怎么了佣谐?”我有些...
    開封第一講書人閱讀 169,301評論 0 362
  • 文/不壞的土叔 我叫張陵肚吏,是天一觀的道長。 經(jīng)常有香客問我台谍,道長须喂,這世上最難降的妖魔是什么吁断? 我笑而不...
    開封第一講書人閱讀 60,078評論 1 300
  • 正文 為了忘掉前任趁蕊,我火速辦了婚禮,結(jié)果婚禮上仔役,老公的妹妹穿的比我還像新娘掷伙。我一直安慰自己,他們只是感情好又兵,可當我...
    茶點故事閱讀 69,082評論 6 398
  • 文/花漫 我一把揭開白布任柜。 她就那樣靜靜地躺著,像睡著了一般沛厨。 火紅的嫁衣襯著肌膚如雪宙地。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,682評論 1 312
  • 那天逆皮,我揣著相機與錄音宅粥,去河邊找鬼。 笑死电谣,一個胖子當著我的面吹牛秽梅,可吹牛的內(nèi)容都是我干的抹蚀。 我是一名探鬼主播,決...
    沈念sama閱讀 41,155評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼企垦,長吁一口氣:“原來是場噩夢啊……” “哼环壤!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起钞诡,我...
    開封第一講書人閱讀 40,098評論 0 277
  • 序言:老撾萬榮一對情侶失蹤郑现,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后荧降,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體懂酱,經(jīng)...
    沈念sama閱讀 46,638評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,701評論 3 342
  • 正文 我和宋清朗相戀三年誊抛,在試婚紗的時候發(fā)現(xiàn)自己被綠了列牺。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,852評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡拗窃,死狀恐怖瞎领,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情随夸,我是刑警寧澤九默,帶...
    沈念sama閱讀 36,520評論 5 351
  • 正文 年R本政府宣布,位于F島的核電站宾毒,受9級特大地震影響驼修,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜诈铛,卻給世界環(huán)境...
    茶點故事閱讀 42,181評論 3 335
  • 文/蒙蒙 一乙各、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧幢竹,春花似錦耳峦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,674評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至邑飒,卻和暖如春循签,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背疙咸。 一陣腳步聲響...
    開封第一講書人閱讀 33,788評論 1 274
  • 我被黑心中介騙來泰國打工县匠, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 49,279評論 3 379
  • 正文 我出身青樓聚唐,卻偏偏與公主長得像丐重,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子杆查,可洞房花燭夜當晚...
    茶點故事閱讀 45,851評論 2 361

推薦閱讀更多精彩內(nèi)容