Ubuntu 18.04에 IPFS 설치하기
우분투에 IPFS를 설치하고 GUI와 Node.js 서버에서 업로드 할게요.
서버에 설치해요.
$ sudo apt-get update
$ sudo apt-get -y upgrade
$ sudo apt install golang-go -y
$ wget https://dist.ipfs.io/go-ipfs/v0.14.0/go-ipfs_v0.14.0_linux-amd64.tar.gz
$ tar zxvf go-ipfs_v0.14.0_linux-amd64.tar.gz
$ cd go-ipfs
$ sudo ./install.sh
IPFS를 실행할 때는 단독으로 실행할 수도 있지만 PM2를 이용하는게 좋아요. (자동 관리)
PM2: https://pm2.io
PM2 - Home
Build Battle-Hardened Node.js Applications.
pm2.io
단독으로 실행(Standalone)
# 초기화
$ ipfs init
# IPFS 실행
$ ipfs daemon
# ID 확인
$ ipfs id
PM2로 실행
# 초기화
$ ipfs init
# PM2로 실행
$ pm2 start "ipfs daemon --enable-gc"
실행하면 3개의 포트를 이용하는데요.
4001 포트는 IPFS 서버가 사용.
5001 포트는 API (업로드 등에 이용) <= https://ipfsapi.banjubu.com 으로 연결했다고 가정.
8080 포트는 게이트웨이에요. (https://ipfs.io 대신 https://ipfs.banjubu.com 등으로 이용 가능)
5001 포트를 이용해 GUI로 입장할게요.
첫 화면에서 세팅할 때 ALB 등에서 https 적용되었다면 '/dns4/ipfsapi.도메인/tcp/443/https' 이렇게 입력해야 해요.
https://ipfsapi.banjubu.com/webui
파일 > Import > File 을 이용하면 GUI로 파일을 업로드 할 수 있어요.
IPFS에 제대로 올라갔네요.
https://ipfs.io/ipfs/QmXTSwnEYzF7G4wZcoQTFZcwL3AUjZyeeWpv4dARcBdChZ
다음은 Node.js 코드에요.
const ipfsAPI = require('ipfs-api');
const fs = require('fs');
const ipfs = ipfsAPI('ipfsapi.banjubu.com', '443', {
protocol: 'https',
});
let testFile = fs.readFileSync('helloworld.txt', 'utf8');
let testBuffer = Buffer.from(testFile);
ipfs.files.add(testBuffer).then((result) => {
console.log(`https://ipfs.io/ipfs/${result[0].hash}`);
});
실행하면 IPFS URL이 출력되요.
https://ipfs.io/ipfs/QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o
만약 ipfs id 를 변경하고 싶다면.
$ ipfs shutdown
# ~/.ipfs 폴더가 있는지 확인
rm -rf ~/.ipfs
$ ipfs daemon
$ ipfs init
영어, 중국어 공부중이신가요?
홈스쿨 교재. 한 권으로 가족 모두 할 수 있어요!
한GLO 미네르바에듀 : 네이버쇼핑 스마트스토어
한글로 영어가 된다?! 한글로[한GLO]는 영어 중국어 일어 러시아어 스페인어가 됩니다!!
smartstore.naver.com