IPFS(一)Ubuntu下搭建IPFS环境
今天我们开始在ubuntu下搭建IPFS环境。
我们需要编译安装IPFS,那么就需要安装Go环境。
安装最近版本的Go语言环境,参考官方网站 https://golang.org/dl/ ,下载最新版的Go。具体涉及到的命令包括:
wget https://storage.googleapis.com/golang/go1.11.5.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.11.5.linux-amd64.tar.gz
接下来编辑当前用户的环境变量:
vi ~/.profile
添加以下内容:
export PATH=$PATH:/usr/local/go/bin
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$HOME/go/bin
编辑保存并退出vi后,记得把这些环境载入:
source ~/.profile
我们把go的目录GOPATH设置为当前用户的文件夹下,所以记得创建go文件夹
cd ~
mkdir go
Go环境搭建好后,IPFS需要先修改环境变量如下:
vi ~/.profile
添加如下设定
export PATH=$PATH:/usr/local/go/bin
export PATH=$PATH:$GOPATH/bin
开始下载IPFS源代码,并编译。
go get -u -d github.com/ipfs/go-ipfs
cd $GOPATH/src/github.com/ipfs/go-ipfs
make install
这个时候,你已经编译将IPFS编译通过了。
IPFS的基本命令如下,请参考
ipfs - Global p2p merkle-dag filesystem.
ipfs [<flags>] <command> [<arg>] ...
SUBCOMMANDS
BASIC COMMANDS
init Initialize ipfs local configuration
add <path> Add a file to ipfs
cat <ref> Show ipfs object data
get <ref> Download ipfs objects
ls <ref> List links from an object
refs <ref> List hashes of links from an object
DATA STRUCTURE COMMANDS
block Interact with raw blocks in the datastore
object Interact with raw dag nodes
files Interact with objects as if they were a unix filesystem
ADVANCED COMMANDS
daemon Start a long-running daemon process
mount Mount an ipfs read-only mountpoint
resolve Resolve any type of name
name Publish or resolve IPNS names
dns Resolve DNS links
pin Pin objects to local storage
repo Manipulate an IPFS repository
NETWORK COMMANDS
id Show info about ipfs peers
bootstrap Add or remove bootstrap peers
swarm Manage connections to the p2p network
dht Query the DHT for values or peers
ping Measure the latency of a connection
diag Print diagnostics
TOOL COMMANDS
config Manage configuration
version Show ipfs version information
update Download and apply go-ipfs updates
commands List all available commands
Use 'ipfs <command> --help' to learn more about each command.
ipfs uses a repository in the local file system. By default, the repo is located
at ~/.ipfs. To change the repo location, set the $IPFS_PATH environment variable:
export IPFS_PATH=/path/to/ipfsrepo
接下来,我们创建一个私有的IPFS网络
您可能希望IPFS服务器运行在一个安全的公共域之后,比如https://example.com。您需要做的第一件事是购买一个自定义域或使用一个子域,并将其指向服务器的IP地址。接下来,我们用以下命令在服务器上安装Nginx:
sudo apt-get update
sudo apt-get install nginx
执行如下命令:
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get install python-certbot-nginx
sudo certbot –nginx -d pactcare.online
第一个命令将在web服务器上安装certbot,使您更容易获得网站的Let ‘s Encrypt certificates (HTTPS)。在最后一个命令之后,将在命令行中启动一个对话框,该对话框将指导您完成设置过程。通常建议选择选项2,它支持自动重定向。
如果现在重新加载域,应该通过https而不是HTTP连接域。
现在你的IPFS网络已经搭建好了。你可以使用了。
首先开始启动网络
ipfs init
执行ipfs init命令后,会在根目录生成一个.ipfs的文件夹存储节点数据
可以通过ipfs id查看节点id信息:
ipfs id
{
"ID": "Qmbh3Kk1itPsmC5smsx2hX6aRDgmUDgTH5Nrje3dLugaZV",
"PublicKey": "CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDu0rkVjKInvn39KcJyVrKFbolvKrmmLujiN0nr2Yr+w4/3ICrvdm2/WDEeZiZMh1kRmNhtljolFZqLCzofi8DfwdG848daOM/966/qpoKPMwNOEuTdBSHMrXLgrczFaPWf2cI4hWbyCxswsv/4C88Ts55T8W6kg4shVZ+BsgeN/2uv0Ge68d165o7okLzM/fPKxdHGnXM2lxkG/qZwim4XkenDEJj1vOxvWmXr1+0aySvelIZQSWebpOBgsdwldlgJvwGMAr6tAtPGXSUvM17t5YY3gwy5WYTJs5nGz8bFS0oWAF7kPnArJye9J4lLnVQNy66R1cKLqvmZoH2L6t8DAgMBAAE=",
"Addresses": null,
"AgentVersion": "go-ipfs/0.4.19-dev/6851d51",
"ProtocolVersion": "ipfs/0.1.0"
}
然后,我们查看一下ipfs网络中已经存储的readme文件
ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme
Hello and Welcome to IPFS!
██╗██████╗ ███████╗███████╗
██║██╔══██╗██╔════╝██╔════╝
██║██████╔╝█████╗ ███████╗
██║██╔═══╝ ██╔══╝ ╚════██║
██║██║ ██║ ███████║
╚═╝╚═╝ ╚═╝ ╚══════╝
If you're seeing 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 daemon
//显示如下信息
Initializing daemon...
go-ipfs version: 0.4.19-dev-6851d51
Repo version: 7
System version: amd64/linux
Golang version: go1.11.5
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/192.168.0.120/tcp/4001
Swarm listening on /ip6/2409:8a55:385e:1590:b4cd:2700:58c9:3/tcp/4001
Swarm listening on /ip6/2409:8a55:385e:1595:38db:7dc2:a4fc:9401/tcp/4001
Swarm listening on /ip6/::1/tcp/4001
Swarm listening on /p2p-circuit
Swarm announcing /ip4/127.0.0.1/tcp/4001
Swarm announcing /ip4/192.168.0.120/tcp/4001
Swarm announcing /ip6/2409:8a55:385e:1590:b4cd:2700:58c9:3/tcp/4001
Swarm announcing /ip6/2409:8a55:385e:1595:38db:7dc2:a4fc:9401/tcp/4001
Swarm announcing /ip6/::1/tcp/4001
API server listening on /ip4/127.0.0.1/tcp/5001
WebUI: http://127.0.0.1:5001/webui
Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080
Daemon is ready
网络已经启动了
输入如下地址:
http://127.0.0.1:5001/webui
显示如下画面,你的IPFS网络启动成功了。
2019年2月12日整理于深圳
推荐阅读
-
IPFS(一)Ubuntu下搭建IPFS环境
-
一个production模式下的Ror环境搭建 博客分类: ROR RailslighttpdrubygemsRubyApache
-
Linux下Java开发环境搭建以及第一个HelloWorld
-
Linux下Java开发环境搭建以及第一个HelloWorld
-
springboot学习之一(Idea环境下搭建基于Maven的SpringBoot框架)
-
Ubuntu 下 vim 搭建python 环境 配置
-
Ubuntu 下 vim 搭建python 环境 配置
-
Ubuntu下PHP开发环境搭建指南
-
Ubuntu 12.04下PHP环境的搭建(LAMP)
-
window下用vim做php开发环境(虽然小弟我一直是在ubuntu下用vim).