회사 중앙 스토리지가 멈추면 리소스를 다운 받을 수 없는 것을 대비해 IPFS를 구축하려고 한다. IPFS에 대한 자세한 설명은 검색해봤으면 한다.

 

1. 설치 

- 설치법은 사람마다 다양했다. 버전별로 달라지니 아래 링크를 참조하여 버전을 참고하기 바란다. 그리고 윈도우, 맥, 리눅스 설치법도 있으니 참고하기 바란다.

 

    1-1 바이너리 파일 다운로드

$ wget https://dist.ipfs.tech/kubo/v0.15.0/kubo_v0.15.0_linux-amd64.tar.gz

    1-2 파일 압축 해제

$ tar -xvzf kubo_v0.15.0_linux-amd64.tar.gz

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

    1-3 kubo 폴더로 이동하여 설치 스크립트를 실행

cd kubo
sudo bash install.sh

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

    1-4 버전 테스트

$ipfs --version

> ipfs version 0.15.0

 

https://docs.ipfs.tech/install/command-line/#which-node-should-you-use-with-the-command-line

 

Command-line | IPFS Docs

Command-line Installing IPFS through the command-line is handy if you plan on building applications and services on top of an IPFS node. This method is also useful if you're setting up a node without a user interface, usually the case with remote servers o

docs.ipfs.tech

 

2.  저장소 초기화

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을 입력해보면 아래처럼 나온다.

ipfs cat /ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/quick-start
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

3. IPFS daemon 실행

ipfs daemon

> Initializing daemon...
> API server listening on /ip4/127.0.0.1/tcp/5001
> Gateway server listening on /ip4/127.0.0.1/tcp/8080

4. IPFS SERVICE 등록(서버 실행시 자동 실행)

    4-1 ipfs.service 파일 생성 및 서비스 정보 입력

sudo vi /etc/systemd/system/ipfs.service

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=계정명

[Install]
WantedBy=multi-user.target

Service에서 User를 서비스 실행할 계정명으로 바꿔준다.

 

    4-2 실행 명령어 입력

sudo systemctl daemon-reload
sudo systemctl enable ipfs
sudo systemctl start ipfs
//정지
sudo systemctl stop ipfs
//동작상태확인
sudo systemctl status ipfs

 

5. 외부 설정

$ vi ~/.ipfs/config

초기에는 127.0.0.1로 되어있으며 로컬에서만 접속이 가능하다. 아래처럼 바꾸면 외부에서 접근이 가능하며 내부망으로도 변경 가능하다.

  "Addresses": {
    "API": "/ip4/0.0.0.0/tcp/5001",
    "Gateway": "/ip4/0.0.0.0/tcp/8080"
  },

- 127.0.0.1 : 로컬

- 0.0.0.0 : 외부 공개

-192.168.xxx.xxxx : 공유기 및 방화벽 내부망에서만 공개(할당 받은 로컬IP 입력)

 

6. WebUI

자신이 윈도우나 가상장치를 사용하여 개발하고 있다면 localhost:5001/webui 로 가능하다. 그런데 나는 우분투서버를 사용하고 있기 때문에 볼 수 없어서 외부 설정을 해서 외부IP로 들어온다. 들어가면 아래처럼 나온다.

 


6-1 에러

여기서 간혹 아래처럼 에러가 발생하는 경우가 있다. 아마 로컬에서 하는 사람들은 안나오는 것 같은데 나처럼 외부 접속으로 할 경우 생기는 것 같다.

나의 경우는 CORS 허용이 안되있는 것 같았다.

vi ~/.ipfs/config

  "API": {
    "HTTPHeaders": {
      "Access-Control-Allow-Headers": [
        "X-Requested-With",
        "Range",
        "User-Agent"
      ],
      "Access-Control-Allow-Methods": [
        "GET","POST"
      ],
      "Access-Control-Allow-Origin": [
        "http://외부IP:5001",
        "http://localhost:3000",
        "http://127.0.0.1:5001",
        "https://webui.ipfs.io"
        ]
    }
},

config 아래쪽에 잘찾아보면 API 가 비워져있다. 자신의 외부IP를 넣고 붙여넣기 해주고 서비스 재시작을 하면된다.

sudo systemctl restart ipfs

7. 기본 사용 포트 정보 (필요에 따라 공유기 및 방화벽에서 포트를 개방)

4001 : SWARM, ip4/0.0.0.0

40000+ : 4만번 이상 포트에서 SWARM 관련 포트가 생성됨

5001 : API, ip4/127.0.0.1

8080 : GATEWAY, ip4/127.0.0.1

 

 

 

https://docs.ipfs.tech/how-to/command-line-quick-start/#web-console

 

Command-line quick start | IPFS Docs

Command-line quick start If you're command-line savvy and just want to get up and running with IPFS right away, follow this quick-start guide. Please note that this guide assumes that you'll be installing Kubo, the reference implementation written in Go. T

docs.ipfs.tech

 

728x90

혹시 이미 jdk 가 있을 수 있으니 기존의 jdk를 먼저 삭제한다.

$ sudo apt-get remove openjdk*
$ sudo apt-get remove oracle*
$ sudo apt-get autoremove --purge 
$ sudo apt-get autoclean

JDK를 처음 설치하는거라면 굳이 할 필요 없다. 

 

다음으로 apt 업데이트를 한다.

$ sudo apt-get update && sudo apt-get upgrade

그리고 나도 한번 에러가 발생했었다. 11 버전부터 사람들이 갈린다.

해외도 마찬가지긴 했는데 나는 서버 4대 설치하는거라서 다 해봤는데 다 잘된다.

 

간혹 어떤사람은 PPA Repository에 openJDK를 추가하고 설치하는경우가 있다.

20.04 버전에서는 추가하지 않아도 설치가 됐다.

$ sudo apt-get install openjdk-11-jdk

설치가 완료가 되면 완료가 정말 됐는지 확인할 수 있다.

$ java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)

$ javac -version
javac 11.0.11

환경설정이다. JAVA_HOME 시스템 변수 설정을 해야한다면 ~/.bashrc 파일에 변수들을 추가해주면 된다.

$ vim ~/.bashrc
export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
export PATH=$PATH:$JAVA_HOME/bin

추가 했으면 현재 변경한 설정을 적용해야한다.

$ source ~/.bashrc

이제는 JAVA_HOME이 잘 설정 되었는지 아래 명령어로 확인해보자

$ echo $JAVA_HOME
/usr/lib/jvm/java-11-openjdk-amd64

 

혹시 JRE만 설치하고 싶다면 아래 명령어로 설치할 수 있다.

$ sudo apt-get install openjdk-11-jre
728x90

docker repository를 통해 설치하는 방법으로 설치를 할 예정이다. 이 방법 말고도 2가지가 더 있다고 한다.

(수동으로 deb 파일을 다운로드하여 설치하는 방법, 별도의 설치 스크립트를 이용하는 방법)

 

 

 

당연히 apt 설치를 하기 때문에 update를 한번 해준다.

 

1. 필수 패키지를 설치합니다.

$ sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

 

2. Docker GPG key 

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
OK

3. Docker Repository 등록

$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"

4. Docker 설치

$ sudo apt-get install docker-ce docker-ce-cli containerd.io

5. 정상 설치 확인

$ sudo docker run hello-world

728x90

패키지 목록을 갱신합니다

apt update

모든 패키지를 최신 버전으로 업그레이드합니다.

apt upgrade

abc 패키지를 설치합니다. 의존성있는 패키지도 함께 설치합니다.

apt install 패키지명

abc 패키지를 삭제합니다. 설정 파일 등은 삭제하지 않습니다.

apt remove 패키지명

더 이상 필요 없는 패키지들을 삭제합니다.

apt autoremove

설정 파일 등도 포함하여 abc 패키지를 삭제합니다.

apt purge 패키지명

abc와 관련된 패키지를 검색합니다.

apt search 패키지명

abc 패키지의 정보를 출력합니다.

apt show 패키지명

패키지 목록을 출력합니다.

apt list

설치된 패키지 목록을 출력합니다.

apt list --installed

업그레이드 가능한 패키지 목록을 출력합니다.

apt list --upgradable
728x90

+ Recent posts