IPFS ( InterPlanetary File System )中文称为星际文件系统,是一个旨在实现文件的分布式存储、共享和持久化的网络传输协议。
照惯例,先上演示.访问我的 IPFS 博客
欢迎各位 pin 我的博客, ipfs pin add /ipns/liudon.xyz
curl 'https://liudon.xyz' -I
HTTP/2 200
date: Tue, 21 Feb 2023 23:59:18 GMT
content-type: text/html
vary: Accept-Encoding
access-control-allow-methods: GET
access-control-allow-methods: GET, POST, OPTIONS
last-modified: Tue, 21 Feb 2023 23:59:18 GMT
x-ipfs-gateway-host: ipfs-bank1-sv15
x-ipfs-path: /ipns/liudon.xyz/
x-ipfs-roots: Qmd4pnpUj8CaLKoVMJNHJyrqwWVa4wvz1qKxZsU9vKgErL
x-ipfs-pop: ipfs-bank1-sv15
timing-allow-origin: *
access-control-allow-origin: *
access-control-allow-headers: X-Requested-With, Range, Content-Range, X-Chunked-Output, X-Stream-Output
access-control-expose-headers: Content-Range, X-Chunked-Output, X-Stream-Output
x-ipfs-lb-pop: gateway-bank1-sv15
x-proxy-cache: MISS
cf-cache-status: DYNAMIC
report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=FLcvWgtngoLuGZkl9jYsviSoOlSoE2Y0rKxI3bgNaKRxhNOrIm6nozqVzndav3%2B9QrvvcJ5GNmC11JBlN8tiigbF9CWPW33TbnLKyfdeblOcEhmZINTcC%2BJ6xhKs"}],"group":"cf-nel","max_age":604800}
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
server: cloudflare
cf-ray: 79d36f598970531f-LAX
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400
准备工作:
[ol]
[/ol]
方案介绍:
[ol]
[/ol]
1. 部署 IPFS 服务
安装 kubo,详见官方文档
wget https://dist.ipfs.tech/kubo/v0.18.1/kubo_v0.18.1_linux-amd64.tar.gz
tar -xvzf kubo_v0.18.1_linux-amd64.tar.gz
> x kubo/install.sh
> x kubo/ipfs
> x kubo/LICENSE
> x kubo/LICENSE-APACHE
> x kubo/LICENSE-MIT
> x kubo/README.md
cd kubo
sudo bash install.sh
> Moved ./ipfs to /usr/local/bin
ipfs --version
> ipfs version 0.18.1
初始化 IPFS
ipfs init --profile=server
添加到开机启动
[Unit]
Description=IPFS Daemon
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=simple
ExecStart=/usr/local/bin/ipfs daemon --enable-namesys-pubsub
User=root
[Install]
WantedBy=multi-user.target
将上述代码保存到/usr/lib/systemd/system/ipfs.service文件.
启动进程.
systemctl start ipfs.service
开放端口
IPFS 默认通过 4001 端口跟 DHT 网络通信,需要放开 4001 端口访问.
2. GitHub Actions 配置
博客我使用的Hugo,原有的工作流方案见将博客部署到 Cloudflare Pages。
完整的工作流配置见[main.yml](完整配置可参考main.yml)。
添加如下变量到 Actions secrets
SSHKEY VPS 主机 ssh 登陆私钥
SSHHOST ssh 用户 @VPS 机器 IP,类似 [email protected]
更新 yaml 配置文件,添加如下任务.
- name: Connect to ssh in BG
timeout-minutes: 2
run: |
echo "${{ secrets.SSHKEY }}" > ../privkey
chmod 600 ../privkey
ssh -o StrictHostKeyChecking=no ${{ secrets.SSHHOST }} -i ../privkey -L 5001:localhost:5001 -fTN
- name: ipfs upload
uses: aquiladev/[email protected]
id: deploy
timeout-minutes: 2
with:
path: ./public
service: ipfs
verbose: true
host: localhost
port: 5001
protocol: http
key: self # 要配置 key,这样才会生成 IPNS 地址
测试执行 action,日志里会有类似如下输出.
Upload to IPFS finished successfully {
cid: 'QmST2Zqv8qffFTVuqfRX57uzqxsoQtTYinmHpyLh7padAD',
ipfs: 'QmST2Zqv8qffFTVuqfRX57uzqxsoQtTYinmHpyLh7padAD',
ipns: '12D3KooWKvJ9Y4D5X4R3ajuc7tVtQWXZMG4iiMCFtay8frM66o4c'
}
每次执行,ipfs 地址不同,ipns 地址不变.
记住这里到 ipns 地址,下面会用到.
3. 域名配置
在Cloudflare上添加解析:
从年前开始想怎么做成自动化,到今天终于跑通搞定了.😁😁😁
两天跑了 14G 流量,每月的流量资源包基本够用了.
原文地址: https://liudon.com/posts/deploy-blog-to-ipfs/