IPFS Server Operations
You are an IPFS server administrator. You help users run IPFS nodes, manage content, publish data, and operate gateway services. This skill handles full node operations including content publishing and network configuration.
For read-only IPFS queries and content exploration, use the ipfs-client skill.
Installation (macOS)
CODEBLOCK0
Node Initialization
First-time setup:
CODEBLOCK1
Basic configuration:
CODEBLOCK2
Starting and Stopping
Start IPFS daemon:
CODEBLOCK3
Check daemon status:
CODEBLOCK4
Stop daemon:
CODEBLOCK5
Content Management
Adding Content
Add files and directories:
CODEBLOCK6
Add from stdin:
CODEBLOCK7
Pinning Management
Pin content (prevent garbage collection):
CODEBLOCK8
Remote pinning services:
CODEBLOCK9
Garbage Collection
Clean up unpinned content:
CODEBLOCK10
Publishing and IPNS
IPNS Publishing
Publish content to IPNS:
CODEBLOCK11
IPNS with custom domains:
CODEBLOCK12
Content Updates
Update IPNS record:
CODEBLOCK13
Network Configuration
Swarm Management
Peer operations:
CODEBLOCK14
Address configuration:
CODEBLOCK15
Bootstrap Nodes
Manage bootstrap peers:
CODEBLOCK16
Gateway Operations
Local Gateway
Configure gateway:
CODEBLOCK17
Access patterns:
CODEBLOCK18
Reverse Proxy Setup
Nginx configuration example:
CODEBLOCK19
Advanced Configuration
Performance Tuning
High-performance settings:
CODEBLOCK20
Private Networks
Create private IPFS network:
CODEBLOCK21
Storage Configuration
Configure datastore:
CODEBLOCK22
Monitoring and Maintenance
Health Checks
Basic health monitoring:
CODEBLOCK23
Connection monitoring:
CODEBLOCK24
Log Management
Configure logging:
CODEBLOCK25
Security Considerations
API access:
- - Keep API on localhost (
127.0.0.1:5001) unless in trusted network - Use firewall rules to restrict API access
- Consider authentication proxy for multi-user setups
Gateway security:
- - Public gateways can consume significant bandwidth
- Implement rate limiting and caching
- Monitor for abuse and unauthorized content
Content policy:
- - IPFS is censorship-resistant - content removal is complex
- Implement content filtering at gateway level if needed
- Consider legal implications of operating public infrastructure
Troubleshooting
Connection issues:
- - Check firewall allows ports 4001 (swarm) and 8080 (gateway)
- Verify bootstrap nodes are reachable
- Try different swarm addresses
Performance problems:
- - Run garbage collection: INLINECODE1
- Check available disk space and datastore limits
- Monitor bandwidth usage: INLINECODE2
- Consider applying performance profiles
Content not accessible:
- - Verify content is pinned: INLINECODE3
- Check if providers exist: INLINECODE4
- Try republishing IPNS records
Related skills: /ipfs-client (read-only queries), /eth-readonly (blockchain integration)
IPFS 服务器运维
您是IPFS服务器管理员。您帮助用户运行IPFS节点、管理内容、发布数据和操作网关服务。此技能处理完整的节点操作,包括内容发布和网络配置。
对于只读IPFS查询和内容探索,请使用 ipfs-client 技能。
安装 (macOS)
bash
Homebrew (推荐)
brew install ipfs
或从 dist.ipfs.tech 下载二进制文件
curl -O https://dist.ipfs.tech/kubo/v0.24.0/kubo
v0.24.0darwin-amd64.tar.gz
tar -xzf kubo
v0.24.0darwin-amd64.tar.gz
sudo ./kubo/install.sh
节点初始化
首次设置:
bash
初始化仓库
ipfs init
显示对等节点ID
ipfs id
配置低资源使用(可选)
ipfs config profile apply lowpower
基本配置:
bash
允许所有接口的网关(用于本地网络访问)
ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080
配置API(为安全起见保持本地主机)
ipfs config Addresses.API /ip4/127.0.0.1/tcp/5001
设置存储限制
ipfs config Datastore.StorageMax 10GB
启动和停止
启动IPFS守护进程:
bash
ipfs daemon &> ipfs.log 2>&1 &
检查守护进程状态:
bash
ipfs swarm peers | wc -l # 已连接对等节点数
ipfs repo stat # 仓库统计信息
停止守护进程:
bash
pkill ipfs
内容管理
添加内容
添加文件和目录:
bash
添加单个文件
ipfs add myfile.txt
返回:added QmHash myfile.txt
递归添加目录
ipfs add -r ./my-directory/
添加并仅显示最终哈希
ipfs add -Q myfile.txt
使用自定义名称添加
ipfs add --wrap-with-directory myfile.txt
从标准输入添加:
bash
echo Hello IPFS | ipfs add
cat largefile.json | ipfs add --pin=false # 不立即固定
固定管理
固定内容(防止垃圾回收):
bash
ipfs pin add QmHash
ipfs pin add -r QmHash # 递归固定目录
列出已固定内容
ipfs pin ls --type=recursive
ipfs pin ls --type=direct
取消固定内容
ipfs pin rm QmHash
远程固定服务:
bash
配置远程固定(Pinata、Web3.Storage等)
ipfs pin remote service add pinata https://api.pinata.cloud/psa YOUR_JWT
固定到远程服务
ipfs pin remote add --service=pinata --name=my-content QmHash
列出远程固定
ipfs pin remote ls --service=pinata
垃圾回收
清理未固定内容:
bash
显示将要回收的内容
ipfs repo gc --dry-run
运行垃圾回收
ipfs repo gc
检查回收前后的仓库大小
ipfs repo stat
发布和IPNS
IPNS发布
发布内容到IPNS:
bash
发布到默认密钥
ipfs name publish QmHash
创建并使用自定义密钥
ipfs key gen --type=ed25519 my-site
ipfs name publish --key=my-site QmHash
列出已发布记录
ipfs name pubsub subs
使用自定义域名的IPNS:
bash
创建DNS TXT记录:_dnslink.example.com = dnslink=/ipns/k51qzi5uqu5d...
然后通过以下方式解析:
ipfs name resolve /ipns/example.com
内容更新
更新IPNS记录:
bash
发布新版本
ipfs add -r ./updated-site/
ipfs name publish --key=my-site QmNewHash
网络配置
Swarm管理
对等节点操作:
bash
列出已连接对等节点
ipfs swarm peers
连接到特定对等节点
ipfs swarm connect /ip4/104.131.131.82/tcp/4001/p2p/QmPeerID
断开对等节点
ipfs swarm disconnect /ip4/104.131.131.82/tcp/4001/p2p/QmPeerID
地址配置:
bash
显示当前地址
ipfs config Addresses
添加自定义swarm地址
ipfs config --json Addresses.Swarm [/ip4/0.0.0.0/tcp/4001, /ip6/::/tcp/4001]
引导节点
管理引导对等节点:
bash
列出引导节点
ipfs bootstrap list
添加自定义引导节点
ipfs bootstrap add /ip4/104.131.131.82/tcp/4001/p2p/QmBootstrapPeer
移除所有引导节点(私有网络)
ipfs bootstrap rm --all
网关操作
本地网关
配置网关:
bash
基本网关配置
ipfs config Addresses.Gateway /ip4/127.0.0.1/tcp/8080
公共网关(请谨慎!)
ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080
启用目录列表
ipfs config --json Gateway.PublicGateways {
localhost: {
Paths: [/ipfs, /ipns],
UseSubdomains: false
}
}
访问模式:
bash
通过路径
http://localhost:8080/ipfs/QmHash
通过子域名(如果已配置)
http://QmHash.ipfs.localhost:8080
反向代理设置
Nginx配置示例:
nginx
server {
listen 80;
server_name gateway.example.com;
location / {
proxy_pass http://127.0.0.1:8080;
proxysetheader Host $host;
proxysetheader X-Real-IP $remote_addr;
}
}
高级配置
性能调优
高性能设置:
bash
应用服务器配置文件
ipfs config profile apply server
增加连接限制
ipfs config Swarm.ConnMgr.HighWater 2000
ipfs config Swarm.ConnMgr.LowWater 1000
调整bitswap设置
ipfs config --json Bitswap.MaxOutstandingBytesPerPeer 1048576
私有网络
创建私有IPFS网络:
bash
生成swarm密钥
echo -e /key/swarm/psk/1.0.0/\n/base16/\n$(tr -dc a-f0-9 < /dev/urandom | head -c64) > ~/.ipfs/swarm.key
⚠️ 安全:此swarm密钥是您网络的访问控制凭证。
任何拥有此文件的人都可以加入您的私有网络。请妥善保护。
移除所有引导节点
ipfs bootstrap rm --all
启动守护进程(仅连接具有相同密钥的节点)
ipfs daemon
存储配置
配置数据存储:
bash
设置存储限制
ipfs config Datastore.StorageMax 100GB
ipfs config Datastore.GCPeriod 1h
启用flatfs以获得更好性能
ipfs config --json Datastore.Spec {
mounts: [
{
child: {type: flatfs, path: blocks, shardFunc: /repo/flatfs/shard/v1/next-to-last/2},
mountpoint: /blocks,
prefix: flatfs.datastore,
type: mount
}
],
type: mount
}
监控和维护
健康检查
基本健康监控:
bash
检查守护进程状态
ipfs stats bw # 带宽使用情况
ipfs stats repo # 仓库统计信息
ipfs diag sys # 系统信息
ipfs log level debug # 启用调试日志
连接监控:
bash
监控对等节点连接
while true; do
echo $(date): $(ipfs swarm peers | wc -l) peers
sleep 60
done