搭建 IPFS 节点服务器

搭建 IPFS 节点服务器

精选文章moguli202025-05-21 16:34:483A+A-

环境说明:(我准备的环境)

centOS7 升级到最新版本。

系统:4核心,8G内存,100G硬盘。

要求 至少 512M内存,硬盘大小根据共享的数据量,所以要求不搞。

第一步:从这个网站找到最新的IPFS

https://docs.ipfs.io/install/command-line/#official-distributions
wget https://dist.ipfs.io/go-ipfs/v0.12.2/go-ipfs_v0.12.2_linux-amd64.tar.gz

下载IPFS,之后,找个地方解压缩:> 的是看到的信息哦,命令是第一行

tar -xvzf go-ipfs_v0.12.2_linux-amd64.tar.gz

> x go-ipfs/install.sh
> x go-ipfs/ipfs
> x go-ipfs/LICENSE
> x go-ipfs/LICENSE-APACHE
> x go-ipfs/LICENSE-MIT
> x go-ipfs/README.md

进入解压缩后的文件夹,并且执行安装:注意 > 是执行之后看到的内容

cd go-ipfs
sudo bash install.sh

> Moved ./ipfs to /usr/local/bin

检测安装是否成功:注意 > 是执行之后看到的内容

ipfs --version

> ipfs version 0.12.0

到这里安装就完成了,接下来是初始化和启动相关

如果是正常的网络节点,可能会同步其他节点的内容的,可以用 ipfs init 进行初始化。如果只是本地测试的话,可以用 ipfs init --profile server 进行初始化,这里是根据翻译来的,如果理解的不对,欢迎指正。

ipfs init

> initializing ipfs node at /Users/jbenet/.ipfs
> generating 2048-bit RSA keypair...done
> peer identity: Qmcpo2iLBikrdf1d6QU6vXuNb6P7hwrbNPW9kLAH8eG67z
> to get started, enter:
>
>   ipfs cat /ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/readme

执行完成之后,可以复制最后一行,以 ipfs cat 开头的一行,执行下,会看到类似以下的信息:

Hello and Welcome to IPFS!

██╗██████╗ ███████╗███████╗
██║██╔══██╗██╔════╝██╔════╝
██║██████╔╝█████╗  ███████╗
██║██╔═══╝ ██╔══╝  ╚════██║
██║██║     ██║     ███████║
╚═╝╚═╝     ╚═╝     ╚══════╝

If you see this, you have successfully installed
IPFS and are now interfacing with the ipfs merkledag!

 -------------------------------------------------------
| Warning:                                              |
|   This is alpha software. use at your own discretion! |
|   Much is missing or lacking polish. There are bugs.  |
|   Not yet secure. Read the security notes for more.   |
 -------------------------------------------------------

Check out some of the other files in this directory:

  ./about
  ./help
  ./quick-start     <-- usage examples
  ./readme          <-- this file
  ./security-notes

最后就是 启动 ipfs ,命令是 ipfs daemon 执行这个就可以了,但是我们需要后台运行那么执行命令如下:

nohup ipfs daemon >> ipfs.log  2>&1 &

nohup 并且在命令行尾部有 & 代表后台运行,两个 >> 代表把输出内容追加到 ipfs.log 的文件中 , 2>&1 代表 错误和普通日志都写入。

检查运行是否成功:查看日志 ipfs.log 文件,看到类似下面的信息,Daemon is ready 启动成功。

API server listening on /ip4/0.0.0.0/tcp/5001
WebUI: http://0.0.0.0:5001/webui
Gateway (readonly) server listening on /ip4/0.0.0.0/tcp/8080
Daemon is ready

注意,我这里看到 0.0.0.0 相关的内容,是因为我是内网启动,并且安全级别非常低。已经修改了配置文件之后的情况。线上切记不要用这样的情况哦。默认启动是只能本机访问的,如果需要 内网访问,需要修改配置文件还需要打开防火墙,如果不开防火墙那就需要配置nginx 的转发。IPFS 配置文件的位置:

~/.ipfs/config

如果需要在内网访问,则需要编辑下 config 文件,以下是部分文件,需要注意。

{
  "API": {
    "HTTPHeaders": {
      "Access-Control-Allow-Methods": [
        "PUT",
        "POST"
      ],
      "Access-Control-Allow-Origin": [
        "http://192.168.0.129:5001",
        "http://localhost:3000",
        "http://127.0.0.1:5001",
        "https://webui.ipfs.io"
      ]
    }
  },
  "Addresses": {
    "API": "/ip4/0.0.0.0/tcp/5001",
    "Announce": [],
    "AppendAnnounce": [],
    "Gateway": "/ip4/0.0.0.0/tcp/8080",
    "NoAnnounce": [

修改 API 开头的,0.0.0.0 不要用,这个是对外完全开放,用本地内网IP 最为稳妥。同时记得加防火墙的设置。

修改完配置文件,记得要重启 IPFS 让配置生效。

点击这里复制本文地址 以上内容由莫古技术网整理呈现,请务必在转载分享时注明本文地址!如对内容有疑问,请联系我们,谢谢!
qrcode

莫古技术网 © All Rights Reserved.  滇ICP备2024046894号-2