centos安装部署IPFS
下载IPFS
- 官网(https://dist.ipfs.io/#go-ipfs) 下载Linux版本的ipfs(需要科学上网)
- 使用wget下载
wget https://github.com/ipfs/go-ipfs/releases/download/v0.4.23/go-ipfs_v0.4.23_linux-amd64.tar.gz
解压文件
tar zxvf go-ipfs_v0.12.0_linux-amd64.tar.gz
进入主目录并进行安装
cd go-ipfs/
./install.sh
查看IPFS版本
ipfs version
初始化ipfs账户
ipfs init
查看配置文件
ipfs config show
修改配置文件
ipfs config edit
// 可能会出现下面的错误
// Error: ENV variable $EDITOR not set
// 为ipfs选择编辑器
export EDITOR=vi
ipfs config edit
新建文件并上传至本地ipfs中
vim test.txt
cat test.txt
// 上传文件
ipfs add test.txt
// 查看上传后的文件
ipfs cat QmSoASxb8aNVGk3pNWpZvXEZTQKxjGeu9bvpYHuo5bP1VJ
启动ipfs,并打开web页面
ipfs daemon
输入地址http://192.168.1.105:8088/ipfs/QmSoASxb8aNVGk3pNWpZvXEZTQKxjGeu9bvpYHuo5bP1VJ
可查看刚才上传的文件
输入网址http://192.168.1.105:5001/webui
进入可视化页面
java连接ipfs
导入与ipfs相关的依赖(https://download.csdn.net/download/qq_43707926/84228860)
// 实例化节点
private static IPFS ipfs = new IPFS("/ip4/192.168.1.105/tcp/5001");
// 添加文件
public static void add() throws IOException {
NamedStreamable.FileWrapper saveFile = new NamedStreamable.FileWrapper(new File("D:\\abc.jpg"));
MerkleNode result = ipfs.add(saveFile).get(0);
System.out.println(result.hash.toString());
}