10

用 Docker 安裝 IPFS

 2 years ago
source link: https://www.frank.hk/blog/docker-ipfs/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

用 Docker 安裝 IPFS

發佈:2021-03-07673 Views技術類DockerIPFS

IPFS 是一個非常科幻的檔案存儲系統。 如果想了解什麼是 IPFS,可參考這篇文章:IPFS 問與答

如果你有一台裝有 Docker 的伺服器,可以很方便的安裝 IPFS ,使你的伺服器變為 IPFS 中的一個節點。

IPFS 官方有提供 Docker 的安裝指引, 我這裡將它變為 docker-compose 更容易操作一些。

建立一個 docker-compose.yml 檔案,內容如下:

1version: '3'
2services:
3 ipfs:
4 image: ipfs/go-ipfs:latest
5 container_name: ipfs_host
6 volumes:
7 - ./export:/export
8 - ./ipfs_data:/data/ipfs
9 ports:
10 - '4001:4001'
11 - '4001:4001/udp'
12 - '127.0.0.1:8080:8080'
13 - '127.0.0.1:5001:5001'

其中 5001 port 為 API 以及 WEB UI,8080 為 Proxy Gateway。 具體內容可以參閱官方網站詳細了解。

確認伺服器已經安裝 docker, docker-compose ,在相同路徑下執行:

1docker-compose up

當 docker-compose up 成功啟動後,訪問瀏覽器 localhost:5001/webui 即可開啟 WEB 界面:

screen-20210307170355%402x.png
IFPS Web 管理界面 在 WebUI 界面中可以看到你當前的節點的狀態,連接到了多少 peers,你也可以方便的在 WebUI 中添加檔案到 IPFS 中。
screen-20210307170616%402x.png

可能遇到的問題 1

我第一次安裝時遇到了 WebUI 無響應的情況,即 127.0.0.1:5001/webui 無法開啟,半天沒有反應。查看 log 後發現因為我們使用 Docker 的形式安裝,而我的Docker Network 設定使得位於 Docker Container 內的 IPFS Deamon 無法連接 peers 導致。 解決這個問題,需要查看 Docker Container 的網絡設定:

1docker inspect < your docker container id or name>

你會看到 Container 位於 172.19.0.0 subnet:

1"IPAM": {
2 "Driver": "default",
3 "Options": null,
4 "Config": [
6 "Subnet": "172.19.0.0/16",
7 "Gateway": "172.19.0.1"

因此需要添加 firewall rules 允許網絡連接:

1firewall-cmd --permanent --zone=public --add-rich-rule='rule family=ipv4 source address=172.19.0.0/16 accept'
3firewall-cmd --zone=public --add-masquerade --permanent
5firewall-cmd --reload

可能遇到的問題 2

打開 WebUI 界面後,可能出現無法連接 API 的情況:

screen-20210307171356%402x.png

這個是因為 API 跨域訪問限制導致,按照界面提示添加對應的 rules 即可:

1docker exec ipfs_host ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["http://www.yourdomain.com:5001","https://www.yourdomain.com","https://www.yourdomain.com","http://localhost:3000", "http://127.0.0.1:5001", "https://webui.ipfs.io"]'
2[root@LS-820311-4279 ipfs]# docker exec ipfs_host ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "POST"]'

訂閱我的網站,接收更新以及其他有趣的消息 😙 。 訂閱不收費,走過路過別錯過。
Subscribe to my website, I will email you if any new posts or interesting stuff available.

如果你喜歡我的內容,請考慮用一杯咖啡支持我一下吧,非常感謝 🥰 。
If you like my contents, please support me via BuyMeCoffee, Thanks a lot.

其它相關文章


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK