以前記事でご紹介したIPFSですが、今回は実際に自分の持っているCentOSの環境にIPFS環境一式をインストールしてみました。
今回はそのやり方についてご紹介したいと思います。
まず、IPFSの動作にはgo言語の動作環境が必要になりますのでインストールします。
sudo yum -y install goまたは
sudo yum -y install golang
次にIPFSをインストールするために必要な環境を整えます。
/usr/local/
ディレクトリにgo言語周りのパッケージをインストールする場所を作成します。
sudo mkdir -p /usr/local/go
次にパスを通します。
sudo vi /etc/profile
を実行し、一番下の行に次の記述を追記します。
PATH=$PATH:/usr/local/go/bin export GOPATH=/usr/local/go export GOBIN=$GOPATH/bin
一度ログイン中の端末からログアウトし、再度ログインします。
次に下記のコマンドを実行します。
go get -u -d github.com/ipfs/go-ipfs #ipfsソースを入手 cd $GOPATH/src/github.com/ipfs/go-ipfs #ipfsソースダウンロード先へ移動 sudo su - #"sudo -s"でやると/etc/profileでexportした環境変数が消失するため make install #ipfsをビルド exit #rootユーザーからログアウト
するとIPFSパッケージがビルドされ、$GOPATH/binへインストールされます。
ビルドが完了したら、ipfsコマンドが利用できるか確認します。
ipfs --help
下記のような表示がされたらインストールは成功しています。
USAGE
ipfs - Global p2p merkle-dag filesystem.
SYNOPSIS
ipfs [--config=<config> | -c] [--debug=<debug> | -D] [--help=<help>] [-h=<h>] [--local=<local> | -L] [--api=<api>] <command> ...
OPTIONS
-c, --config string - Path to the configuration file to use.
-D, --debug bool - Operate in debug mode.
--help bool - Show the full command help text.
-h bool - Show a short version of the command help text.
-L, --local bool - Run the command locally, instead of using the daemon. DEPRECATED: use --offline.
--offline bool - Run the command offline.
--api string - Use a specific API instance (defaults to /ip4/127.0.0.1/tcp/5001).
--enc, --encoding string - The encoding type the output should be encoded with (json, xml, or text). Default: text.
--stream-channels bool - Stream channel output.
--timeout string - Set a global timeout on the command.
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
dag Interact with IPLD documents (experimental)
ADVANCED COMMANDS
daemon Start a long-running daemon process
mount Mount an IPFS read-only mountpoint
resolve Resolve any type of name
name Publish and resolve IPNS names
key Create and list IPNS name keypairs
dns Resolve DNS links
pin Pin objects to local storage
repo Manipulate the IPFS repository
stats Various operational stats
p2p Libp2p stream mounting
filestore Manage the filestore (experimental)
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
cid Convert and discover properties of CIDs
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
EXIT STATUS
The CLI will exit with one of the following values:
0 Successful execution.
1 Failed executions.
Use 'ipfs <subcmd> --help' for more information about each command.
最後に、ipfsを使用するユーザー(ipfsへファイルをアップロード・ダウンロードするユーザー)で下記のコマンドを実行します。
ipfs init
するとipfs上での自ノード専用のキーが発行・保存され、セットアップ完了です。
initializing IPFS node at /ユーザーディレクトリのパス/.ipfs
generating 2048-bit RSA keypair...done
peer identity: 自分のipfsノードのキー
to get started, enter:
ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme
ファイルのアップロードやアップロードしたファイルを閲覧する方法などはまた後日解説したいと思います。