- 개발 기록을 남기기 위해 쓴 글 입니다.
- IPFS 어디다 쓰냐고여 ? 파일 업로드 할 때 쓰면 좋습니다. (feat busy.org) 동영상 스트리밍 할때도 좋고여 ( feat DTube )
- 왜 좋냐고여 ? 파일을 분산 해서 가져와 대역폭를 나눠가져와요 속도도 빠르죠+서버 부하가 줄어들죠, 그런데 왜 DTube는 느리냐고요 ? 국내에 서버가 없어요 ㅜㅜ 해외라 느려요 그리고 해당 자료를 다운받아 공유해야 빨라지는데 공유가 거의 없죠(IPFS Daemon 설치 필요)
- 기타 궁금한 점이 있음 댓글요
1. go/golang 설치
1.1 의존성 설치
sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt-get update
sudo apt-get install golang-go
1.2 PATH 추가 ( in ~/.profile )
export PATH=$PATH:/usr/local/go/bin
export PATH=$PATH:$GOPATH/bin
- 경로상에 $GOPATH가 누락된 경우
go env를 통해 경로정보(GOPATH) 확인 후 PATH에 추가
2. ipfs 설치
2.1 소스 다운로드
$ go get -u -d github.com/ipfs/go-ipfs
2.2 소스 빌드
$ cd $GOPATH/src/github.com/ipfs/go-ipfs<br>
$ make install
- 이렇게 다운로드 받은 파일은 모두
GOPATH/bin경로에 파일이 위치하게 된다.
3. ipfs 실행
3.1 초기화
$ ipfs init
initializing IPFS node at /home/wonsama/.ipfs
generating 2048-bit RSA keypair...done
peer identity: QmZVbfF459S3213213NBxxxxxxxxxxxxxxxxxxpCorJggzm6
to get started, enter:
ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme
- 위와 같이 초기화 된 모습을 볼 수 있다.
3.2 IPFS 파일 보기
$ 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 네트워크 상에 존재하는 파일임 (local ipfs daemon 실행과 관련 없음)
3.3 IPFS 데몬 실행
$ ipfs daemon
3.4 IPFS SERVICE 등록해서 서버 기동 시 자동실행하기
sudo vi /etc/systemd/system/ipfs.service
[Unit]
Description=IPFS Daemon
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=simple
ExecStart=/usr/local/bin/ipfs daemon --enable-namesys-pubsub
User=wonsama
[Install]
WantedBy=multi-user.target
ExecStart=/usr/local/bin/ipfs부분을 GOPATH 를 참조하여 ipfs가 설치된 경로로 변경User=wonsama이 부분을 초기 서비스 기동 시 실행할 계정명으로 바꿔준다
sudo systemctl daemon-reload
sudo systemctl enable ipfs
sudo systemctl start ipfs
- 서비스 활성화 및 실행
- 정지하고 싶은 경우는 ...
sudo systemctl stop ipfs
sudo systemctl status ipfs
● ipfs.service - IPFS Daemon
Loaded: loaded (/etc/systemd/system/ipfs.service; enabled; vendor preset: enabled)
Active: active (running) since 수 2018-08-22 13:24:24 KST; 3s ago
Main PID: 17497 (ipfs)
CGroup: /system.slice/ipfs.service
└─17497 /home/wonsama/go/bin/ipfs daemon --enable-namesys-pubsub
8월 22 13:24:26 wonsama ipfs[17497]: Swarm listening on /p2p-circuit/ipfs/QmZVbfF459S72AVxxxxxxxxxxxxxxkUZsJApCorJggzm6
8월 22 13:24:26 wonsama ipfs[17497]: Swarm announcing /ip4/127.0.0.1/tcp/4001
8월 22 13:24:26 wonsama ipfs[17497]: Swarm announcing /ip4/127.0.0.1/tcp/41364
8월 22 13:24:26 wonsama ipfs[17497]: Swarm announcing /ip4/192.168.0.202/tcp/4001
8월 22 13:24:26 wonsama ipfs[17497]: Swarm announcing /ip4/192.168.0.202/tcp/41364
8월 22 13:24:26 wonsama ipfs[17497]: Swarm announcing /ip6/::1/tcp/4001
8월 22 13:24:26 wonsama ipfs[17497]: Swarm announcing /ip6/::1/tcp/46805
8월 22 13:24:26 wonsama ipfs[17497]: API server listening on /ip4/127.0.0.1/tcp/5001
8월 22 13:24:26 wonsama ipfs[17497]: Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080
8월 22 13:24:26 wonsama ipfs[17497]: Daemon is ready
- 서비스 동작상태 확인
3.5 게이트웨이를 공용으로 활성화 하기
$ vi ~/.ipfs/config
"Gateway": "/ip4/127.0.0.1/tcp/8080" 에서
"Gateway": "/ip4/0.0.0.0/tcp/8080" 으로 변경처리
- 기본적으로는 로컬에서만 접근이 가능함
- 127.0.0.1 : 로컬전용
- 0.0.0.0 : 외부망
- 192.168.0.xxx : 내부망(공유기로부터 할당 받은 로컬 IP를 넣어준다)
4. 기타
4.1 톰캣 서비스 중지하기
sudo systemctl disable tomcat8
- 위와 같이 명령어를 넣어주면 됨
- 포트를 바꿔도 상관이 없지만... 현재 톰캣을 쓰지 않음 !
4.2 설치 시 기본 사용 포트정보
- 4001 : SWARM, ip4/0.0.0.0
- 40000+ : 4만번 이상 포트에서 SWARM 관련 포트가 생성됨
- 5001 : API, ip4/127.0.0.1
- 8080 : GATEWAY, ip4/127.0.0.1
webui localhost:5001/webui 로 접근하는 경우 로컬에 daemon이 설치 되어 있어야 됨에 유의(API의 ip4/192.168.0.xxx 로 변경해도 실제 로컬 데몬 정보를 참조)
4.2 참조링크
- https://github.com/golang/go/wiki/Ubuntu
- https://docs.ipfs.io/introduction/install/#installing-from-a-prebuilt-package
- https://michalzalecki.com/set-up-ipfs-node-on-the-server/
- https://www.howtogeek.com/225487/what-is-the-difference-between-127.0.0.1-and-0.0.0.0/