013-阿里Dragonfly體驗之私有registry下載

趙安家發表於2019-03-30

這是堅持技術寫作計劃(含翻譯)的第13篇,定個小目標999,每週最少2篇。

書接上篇 012-P2P加速Docker映象分發(阿里Dragonfly) ,講解了如何快速搭建Dragonfly,但是訪問的是公開映象,本文主要講解如何下載私有映象。

實驗環境

主機

型別 主機名 系統 ip docker version
supernode d7y-1 Ubuntu Server 16.04.6 LTS X64 192.168.0.75 17.06.2ubuntu
clinet1 d7y-2 Ubuntu Server 16.04.6 LTS X64 192.168.0.76 17.06.2ubuntu
clinet2 d7y-3 Ubuntu Server 16.04.6 LTS X64 192.168.0.77 17.06.2ubuntu

私有registry

本次以阿里雲私有映象庫為例,可以自行開通。

文件之坑

官方文件比較簡單,甚至帶有誤導性,下意識的以為應該在dfdaemon節點上配置auth資訊,並且配的是真實的私有registry,如果真這麼搞了,肯定被坑。(但是也能解釋通,比較繞,dfdaemon本身就是一個偽裝成registry,用來加速私有registry,那麼登陸資訊就應該換成dfdaemon ip,只是示例不太恰當而已,對初學者相當不友好倒是真的)

image.png

supernode步驟

安裝supernode

root@d7y-1:~# docker run --name dragonfly-supernode --restart=always \
              -d -p 8001:8001 -p 8002:8002 -v /data/dragonfly/supernode:/home/admin/supernode \
              registry.cn-hangzhou.aliyuncs.com/dragonflyoss/supernode:0.3.0 \
              -Dsupernode.advertiseIp=192.168.0.75

root@d7y-1:~# docker ps
CONTAINER ID        IMAGE                                                            COMMAND                  CREATED              STATUS              PORTS                              NAMES
be7fb931db0b        registry.cn-hangzhou.aliyuncs.com/dragonflyoss/supernode:0.3.0   "/bin/sh -c '/root..."   About a minute ago   Up About a minute   0.0.0.0:8001-8002->8001-8002/tcp   dragonfly-supernode

root@d7y-1:/data/dragonfly/supernode/logs# cat app.log 
2019-03-30 01:04:40.065 INFO  [      main] c.d.d.s.SuperNodeStarter       - Starting SuperNodeStarter on be7fb931db0b with PID 9 (/supernode.jar started by root in /)
2019-03-30 01:04:40.069 INFO  [      main] c.d.d.s.SuperNodeStarter       - No active profile set, falling back to default profiles: default
2019-03-30 01:04:42.151 INFO  [      main] c.d.d.s.c.SupernodeProperties  - init local ip of supernode, use ip:192.168.0.75
2019-03-30 01:04:42.253 INFO  [      main] c.d.d.s.c.SupernodeProperties  - cluster members: [{"downloadPort":8001,"ip":"localhost","registerPort":8002}]
2019-03-30 01:04:42.263 INFO  [      main] c.d.d.s.c.util.MonitorService  - available processors count is 4
2019-03-30 01:04:42.272 ERROR [  Thread-2] c.d.d.s.c.util.MonitorService  - process fields:null error
java.io.IOException: Cannot run program "tsar": error=2, No such file or directory
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
	at java.lang.Runtime.exec(Runtime.java:620)
	at java.lang.Runtime.exec(Runtime.java:450)
	at java.lang.Runtime.exec(Runtime.java:347)
	at com.dragonflyoss.dragonfly.supernode.common.util.MonitorService$1.run(MonitorService.java:56)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.IOException: error=2, No such file or directory
	at java.lang.UNIXProcess.forkAndExec(Native Method)
	at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
	at java.lang.ProcessImpl.start(ProcessImpl.java:134)
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
	... 5 common frames omitted
2019-03-30 01:04:43.507 INFO  [      main] c.d.d.s.SuperNodeStarter       - Started SuperNodeStarter in 3.906 seconds (JVM running for 4.59)
2019-03-30 01:04:49.472 INFO  [  spring-1] c.d.d.s.s.p.PreheatServiceImpl - deleteExpiresPreheatTask, count:0
複製程式碼

2019-03-30 01:04:42.151 INFO  [      main] c.d.d.s.c.SupernodeProperties  - init local ip of supernode, use ip:192.168.0.75  看,啟動ip設定成功.

注意,官方的映象沒改時區,預設是UTC時間,比北京東八區早8小時。

登陸私有registry並推送映象

root@d7y-1:~# docker login https://registry.cn-qingdao.aliyuncs.com 
Username: //你阿里雲賬號
Password: //你阿里雲密碼
Login Succeeded
root@d7y-1:~# docker pull nginx:alpine
root@d7y-1:~# docker tag nginx:alpine registry.cn-qingdao.aliyuncs.com/d7y-test/nginx:alpine
root@d7y-1:~# docker push registry.cn-qingdao.aliyuncs.com/d7y-test/nginx:alpine
alpine: digest: sha256:857e6f195df0e9b497be0c7fad0f013126407aaeb71edcef66a24e8b990d94b3 size: 1153
複製程式碼

dfdaemon 步驟

安裝dfdaemon

在兩臺client節點分別執行如下命令

root@d7y-2:~# cat <<EOD >/etc/dragonfly.conf
[node]
address=192.168.0.75
EOD
root@d7y-2:~# docker run --name dragonfly-dfclient --restart=always \
						-d -p 65001:65001 -v /root/.small-dragonfly:/root/.small-dragonfly \
            -v /etc/dragonfly.conf:/etc/dragonfly.conf dragonflyoss/dfclient:v0.3.0 \
            --registry=https://registry.cn-qingdao.aliyuncs.com  --ratelimit 100M
Unable to find image 'dragonflyoss/dfclient:v0.3.0' locally
v0.3.0: Pulling from dragonflyoss/dfclient
169185f82c45: Pull complete 
f58f64214283: Pull complete 
bd8f062dc2d2: Pull complete 
Digest: sha256:5bcabd5b34f4da0c2d489c8f99a23a401fb9ec57e54d4fa90457a93c5a85371f
Status: Downloaded newer image for dragonflyoss/dfclient:v0.3.0
b491e90489a584119b82ca934cf2ae087abc136f7f9de3542e14fb12bc1c7512

root@d7y-2:~# cat <<EOD >/etc/docker/daemon.json
{
"registry-mirrors": ["http://127.0.0.1:65001"]
}
EOD
root@d7y-2:~# systemctl restart docker 

root@d7y-2:~# docker ps
CONTAINER ID        IMAGE                          COMMAND                  CREATED             STATUS              PORTS                      NAMES
b491e90489a5        dragonflyoss/dfclient:v0.3.0   "/dfclient/dfdaemo..."   28 seconds ago      Up 4 seconds        0.0.0.0:65001->65001/tcp   dragonfly-dfclient

root@d7y-2:~/.small-dragonfly/logs# cat dfdaemon.log
2019-03-30 01:18:21.331 INFO sign:1 : init...
2019-03-30 01:18:21.331 INFO sign:1 : rotate log routine start...
2019-03-30 01:18:21.338 INFO sign:1 : dfget version:
2019-03-30 01:18:21.338 ERRO sign:1 : init properties failed:open /etc/dragonfly/dfdaemon.yml: no such file or directory
2019-03-30 01:18:21.338 INFO sign:1 : init properties:{"Registries":[{"Schema":"https","Host":"registry.cn-qingdao.aliyuncs.com","Certs":null,"Regx":"(^localhost$)|(^127.0.0.1$)|(^127.0.0.1$)"}]}
2019-03-30 01:18:21.338 INFO sign:1 : init finish
2019-03-30 01:18:21.338 INFO sign:1 : start dfdaemon param: &{DfPath:/dfclient/dfget DFRepo:/root/.small-dragonfly/dfdaemon/data/ RateLimit:100M CallSystem:com_ops_dragonfly URLFilter:Signature&Expires&OSSAccessKeyId Notbs:true MaxProcs:4 Version:false Verbose:false HostIP:127.0.0.1 Port:65001 Registry:https://registry.cn-qingdao.aliyuncs.com DownRule: CertFile: KeyFile: TrustHosts:[] ConfigPath:/etc/dragonfly/dfdaemon.yml}
2019-03-30 01:18:21.338 INFO sign:1 : launch dfdaemon http server on 127.0.0.1:65001
複製程式碼

登陸dfdaemon

root@d7y-2:~# docker login http://127.0.0.1:65001
Username: //你阿里雲賬號
Password: //你阿里雲密碼
Login Succeeded
root@d7y-2:~# cat ~/.docker/config.json 
{
	"auths": {
		"127.0.0.1:65001": {
			"auth": "zzxxxxxx="
		}
	}
}

複製程式碼

pull 私有映象

root@d7y-2:~# docker pull 127.0.0.1:65001/d7y-test/nginx:alpine
alpine: Pulling from d7y-test/nginx
8e402f1a9c57: Pull complete 
56b0d9b69cc9: Pull complete 
b66c8bb200cc: Pull complete 
4ec77fc9c55f: Pull complete 
Digest: sha256:857e6f195df0e9b497be0c7fad0f013126407aaeb71edcef66a24e8b990d94b3
Status: Downloaded newer image for 127.0.0.1:65001/d7y-test/nginx:alpine
複製程式碼

可以通過iftop 等命令,觀察流量。

其他

排錯

如果有遇到其他問題,可以通過檢視日誌來獲取更多資訊。
dfdaemon log : /root/.small-dragonfly/logs/{dfclient.log,dfdaemon.log,dfserver.log}
supernode log: /home/admin/supernode/{app.log,data-gc.log,downloader.log,piece-hit.log,space-gc.log}

公開和私有registry混用

如果大量都是私有registry的話,可以在/etc/docker/daemon.json 中配置dfdaemon和加速器,如果是一半一半的話,那就乾脆起兩個dfdaemon就行了,一個--registry寫私有的,一個--registry寫公有的,然後也是配置 /etc/docker/daemon.json

cat /etc/docker/daemon.json 
{
  "registry-mirrors": ["http://127.0.0.1:65001","https://xxx.mirror.aliyuncs.com"],
  "dns": ["223.5.5.5"]
}
複製程式碼

吐槽

再次吐槽一下d7y的產品很好,解決了很大問題。但是這文件,真心不是給新手看的。從未見過如此坑多且深的文件。沒見過哪家quick start 寫的這麼複雜。

鳴謝

非常感謝釘釘群內的 d7y 的 contributor 太雲-lowzj 耐心解答,從開始研究d7y開始,遇到的很多坑都是在   太雲-lowzj 幫助下蹚過去的。但是還是覺得,如果文件足夠友好,肯定會減少群內被打擾的次數,進而節省自己時間的。

image.png

招聘小廣告

山東濟南的小夥伴歡迎投簡歷啊 加入我們 , 一起搞事情。

長期招聘,Java程式設計師,大資料工程師,運維工程師,前端工程師。

相關文章