2021년 9월 15일 수요일

@Async 사용할 때 주의해야 할 것

@Async is not a silver bullet (@Async는 은 탄환이 아니다)

  • private 메서드에는 적용이 안됨 (public만)
  • self-invocation(자가 호출)해서는 안됨 (같은 클래스 내부의 메서드를 호출하는 것은 안됨)
  • 리턴값에 대해서 void나 CompletableFuture<> 여야 함
참고
  • https://jeong-pro.tistory.com/187

2021년 3월 24일 수요일

MongoDB 명령어

백업

  • mongodump --host <host> --port <port> --username <username> --password <password> --db <database> --out <dirname>
복구
  • mongorestore --host <host> --port <port> --username <username>  --password <password> --db <database> <dirname>

2021년 1월 28일 목요일

JWT Claim Set

- iss: 토큰을 발급한 발급자 (issuer)
- sub: Claim의 주제(Subject)로 토큰이 갖는 문맥을 의미함
- aud: 이 토큰을 사용할 수신자(Audience)
- exp: 만료시간(Expiration Time)
- nbf: Not Before의 의미로 이 시간 이전에는 토큰을 처리하지 않아야 함을 의미함
- iat: 토큰이 발급된 시간(Issued At)
- jti: JWT ID로 코튼에 대한 식별자

2021년 1월 17일 일요일

[Spring Boot] Spring Boot 시작하기

Spring Boot 기초


1. Spring Boot?
- 스프링 프레임워크를 사용하는 프로젝트를 쉽게 설정할 수 있도록 해주는 서브 프로젝트


2. Spring Boot의 특징

- 단독으로 스프링 애플리케이션을 생성

- Tomcat, Jetty, Undertow 를 내장

- 빌드 구성을 단순화하기 위해 'starter' 종속성 제공

- 스프링과 3th party 라이브러리를 가능한 자동적으로 설정

- 상용화에 필요한 metrics, health checks, externalized configuration 같은 기능 제공

- XML 설정을 생성하지 않고 요구하지 않음


Spring Boot 시작하기


1. Spring Initializr 로 Spring Boot 프로젝트 생성


1.1. Generator

- Spring Initializr 사이트 접속 ( https://start.spring.io/ )

  ( 2021년 1월 설정 화면 )

- Project, Language, Spring Boot, Metadata등을 설정함
- Generate를 클릭함( 프로젝트 파일이 압축되어 다운로드됨 )

1.2. 프로젝트 Import
- 압축 해제 후 Eclipse나 IntelliJ를 통해 프로젝트를 Import (여기서는 IntelliJ를 사용)



- ( IntelliJ Idea 2020.3.1버전은 Gradle 프로젝트를 자동으로 인식해서 로드하는 것 같음 )

2. Gradle 설정

2.1. spring-boot-starter-web
- Spring MVC나 RESTful 같은 Web과 관련된 의존성들

2.2. spring-boot-starter-test
- Junit, Hamcrest, Mockito를 포함하는 테스트관련 의존성들

plugins {
	// 스프링부트 의존성 관리 및 애플리케이션 패키징을 위한 Gradle 플러그인
	id "org.springframework.boot" version "2.4.1"
	// 스프링부트 버전에 대해 의존성을 자동으로 가져옴
	id "io.spring.dependency-management" version "1.0.10.RELEASE"
	id "java"
}

group = "com.chakans"
version = "0.0.1-SNAPSHOT"
// 자바 버전 선언
sourceCompatibility = "11"

repositories {
	mavenCentral()
}
// 프로젝트와 의존 관계에 있는 라이브러리 정의
dependencies {
	implementation "org.springframework.boot:spring-boot-starter"
	implementation "org.springframework.boot:spring-boot-starter-web"
	testImplementation ("org.springframework.boot:spring-boot-starter-test") {
		exclude group: "org.junit.vintage", module: "junit-vintage-engine"
	}
}

test {
	useJUnitPlatform()
}

3. Application.java

3.1. @SpringBootApplication
- @EnableAutoConfiguration, @ComponentScan, @Configuration을 하나로 묶은 것이라 볼 수 있음
- 해당 어노테이션이 있는 package위치를 기준으로 ComponentScan을 수행함 ( 기준 package 위치 변경 가능 )
main 메소드 위치하는 곳임

4. index.html
- resources > static 하위에 index.html 파일 생성

- 서버 구동 후 http://localhost:8080/index.html로 확인 가능함

5. 서버 구동

2020년 11월 26일 목요일

[EOSIO] EOS Node들을 위한 망구성



참고
  • https://eosio.stackexchange.com/questions/345/how-to-configure-block-producer-to-have-front-end-and-back-end-cluster-nodes

2020년 11월 25일 수요일

TINC(Peer-to-Peer VPN) 설정 방법 in Ubuntu 18.04

소개

TINC는 터널링 및 암호화를 사용하여 인터넷상의 호스트간에 보안 개인 네트워크를 만드는 VPN데몬

준비사항

2대의 서버, Ubuntu 18.04

구성

A 서버 -------------------------------------- B 서버

설치

1. 각 서버에 Tinc 설치
$ sudo apt update && sudo apt install tinc

2. VPN 작업 디렉토리 생성
$ sudo mkdir -p /etc/tinc/sample/hosts

3. 설정 파일들 만들기
- 각 서버에 "tinc.conf" 파일 생성
$ sudo vim /etc/tinc/sample/tinc.conf

-- A 서버
-------------------------
 Name = tinc_a
 Device = /dev/net/tun
 AddressFamily = ipv4
 Interface = tun0
-------------------------

-- B 서버
-------------------------
Name = tinc_b Device = /dev/net/tun AddressFamily = ipv4 Interface = tun0
 ConnectTo = tinc_a
-------------------------
  • Name - VPN에 사용될 고유한 이름 
  • Device - 가상 네트워크를 위한 장치 정의
  • AddressFamily - IP 주소 형식
  • Interface - 네트워크 인터페이스명
  • ConnectTo - 연결하려는 tinc 데몬명
- 각 서버에 hosts 설정 파일 생성
-- A 서버
$ sudo vim /etc/tinc/sample/hosts/tinc_a
------------------------- Address = 172.17.0.2 Subnet = 100.100.100.100 -------------------------
-- B 서버
$ sudo vim /etc/tinc/sample/hosts/tinc_b

-------------------------
Address = 172.17.0.3
Subnet = 100.100.100.200
-------------------------

- 각 서버의 vpn hosts 설정 파일에 public key 추가
$ sudo tincd -n sample -K 4096

VPN 제어 스크립트 생성

-- A 서버

$ sudo vim /etc/tinc/sample/tinc-up

-------------------------
#!/bin/sh ip link set $INTERFACE up ip addr add 100.100.100.100 dev $INTERFACE ip route add 100.100.100.0/24 dev $INTERFACE
-------------------------
$ sudo vim /etc/tinc/sample/tinc-down
-------------------------
#!/bin/sh ip route del 100.100.100.0/24 dev $INTERFACE ip addr del 100.100.100.100 dev $INTERFACE ip link set $INTERFACE down
-------------------------

-- B 서버

$ sudo vim /etc/tinc/sample/tinc-up

-------------------------
#!/bin/sh ip link set $INTERFACE up ip addr add 100.100.100.200 dev $INTERFACE ip route add 100.100.100.0/24 dev $INTERFACE
-------------------------
$ sudo vim /etc/tinc/sample/tinc-down
-------------------------
#!/bin/sh ip route del 100.100.100.0/24 dev $INTERFACE ip addr del 100.100.100.200 dev $INTERFACE ip link set $INTERFACE down
-------------------------
- 실행 권한 변경
$ sudo chmod -v +x /etc/tinc/sample/tinc-{up,down}

서비스 등록

$ sudo vim /etc/systemd/system/tinc.service

-------------------------
[Unit]
Description=Tinc net sample
After=network.target

[Service]
Type=simple
WorkingDirectory=/etc/tinc/sample
ExecStart=/sbin/tincd -n sample -D -d3
ExecReload=/sbin/tincd -n sample -kHUP
TimeoutStopSec=5
Restart=always
RestartSec=60

[Install]
WantedBy=multi-user.target
-------------------------

$ sudo systemctl enable tinc.service
$ sudo systemctl status tinc.service

Host 파일 교환

-- A 서버

$ scp /etc/tinc/sample/hosts/tinc_a user@172.17.0.2:/tmp/
$ ssh -t user@172.17.0.2 sudo mv -v /tmp/tinc_a /etc/tinc/sample/hosts/

-- B 서버

$ scp /etc/tinc/sample/hosts/tinc_b user@172.17.0.3:/tmp/
$ ssh -t user@172.17.0.3 sudo mv -v /tmp/tinc_b /etc/tinc/sample/hosts/

테스트

-- A 서버 & B 서버

$ sudo tincd -n sample -D -d3
$ sudo ip a
$ ping 100.100.100.***

참고

  • https://www.linode.com/docs/guides/how-to-set-up-tinc-peer-to-peer-vpn/

2020년 11월 21일 토요일

[EOSIO] EOSIO 빌드 및 설치

EOSIO 빌드 by Shell Scripts

빌드 환경

HW: 4Core CPU, 8GB (테스트환경)
OS: Ubuntu 18.04

EOSIO 소스 다운로드

$ mkdir -p ~/eosio && cd ~/eosio
$ git clone --recursive https://github.com/EOSIO/eos

(옵션) Submodules 업데이트

- "--recursive" 옵션 없이 clone을 했다면 아래 명령어 실행해야 함
$ cd ~/eosio/eos
$ git submodule update --init --recursive

EOSIO 바이너리 빌드

- "/home/eosio/eos/2.0"에 설치
$ sudo mkdir -p /home/eosio
$ sudo chown ${USER}:${USER} /home/eosio

$ cd ~/eosio/eos
$ ./scripts/eosio_build.sh -i /home/eosio/eos/2.0

EOSIO 설치

$ cd ~/eosio/eos
$ sudo ./scripts/eosio_install.sh

EOSIO 삭제

$ cd ~/eosio/eos
$ sudo ./scripts/eosio_uninstall.sh

EOSIO 바이너리 테스트

$ cd ~/eosio/eos/build
$ make test

참고

  • https://developers.eos.io/manuals/eos/latest/install/build-from-source/shell-scripts/index