Jun 10, 2020 - 스프링부트 다중 모듈 아키텍쳐

보통의 구조 아키텍쳐를 구성할 때는 core, common, api 로 크게 3개를 나눕니다.
core는 중요하고 거의 동작하지 않는 서버간의 연결 정도 (RDBMS, NOSQL) 등의 설정을 관리합니다.

common 은 도메인 및 dto, model등을 관리합니다.

api, sender, batch 는 각각의 설정에 따라 분리되어 동작하는 어플리케이션(Service)를 관리합니다.

- core
  - redis
  - db connetion
- common
  - util
- api(request)
  - request Api
- sender
  - local call
- batch

즉, core는 redis 등 타 lib 을 처리하며, common 은 util 성을 처리하고자 합니다.

api 는 외부에서 오는 connection 을 처리하며, sender 는 서버 to 서버 용도로 사용할 경우 각기 다른 용도로 처리하게 됩니다.
batch 는 매분, 매시간, 매일, 매달 돌아가는 배치성 프로세스가 동작할 예정이라, 해당 어플리케이션을 각각의 스프링부트로 별도 구성 예정입니다.
(soft한 MSA)

고민되는 부분이 core 랑 common 은 거의 중복되는 소스로 구성되게 되어, 실제 프로젝트는

api(Request)
   - core
   - common
   - api(request)

sender
   - core
   - common
   - sender

batch
   - core
   - common
   - batch

로 core와 common 이 중복되서 처리되게 될 가능성이 높습니다.

그래서, core 와 common을 별도의 git으로 관리하여 하나의 프로젝트로 처리하는 부분을 고려해야합니다.

즉,

api (개발자가 로컬에서 직접생성)
  - core (core 로 별도의 git 제어)
  - common (common 이라는 별도의 git 제어)
  - api (api 라는 별도의 git 제어)

형태로 처리하고자 합니다.

다만, 같은 git 이나 모듈로 관리하기 편하게 해당 명칭은 앞에 접두사를 붙이는 걸 권합니다. 예를 들어,

extCore
extCommon
extApi

로 한눈에 보이는 것으로 처리하는게 좋습니다!

core 와 common 과 api 가 이미 git에 올라가 있다고 가정했을 때,

인텔리J에서
new Project > gradle > Artifact Coordinates > GroupId 로,
기존 GroupId를 맞춥니다. (올려진 git의 group으로)

만들어진 src를 삭제합니다. 새로워진 프로젝트에는 필요하지 않습니다.

소스트리(SourceTree)를 사용하여, 만들어진 프로젝트 경로에 앞서 말한 core와 api 를 다운받습니다.
만들진 프로젝트는 다음과 같아집니다.

api
  - .gradle
  - .idea
  - gradle
  - xxxCore
  - xxxApi
  build.gradle
  settings.gradle

xxx 를 접두사로 붙여 한줄에 보이도록 조치합니다.

인텔리J에서 Project Structure 를 설정한 후 Modules 에서 new Module을 선택합니다.
new Module > grale > xxxCore 를 생성하면(이미 해당폴더는 소스트리를 통해 clone된 상태) 이미 체크아웃되어있는 git에 연결됩니다.
새롭게 모듈이 생기면서 build.gradle을 새로 갱신하는데, 롤백을 하거나, history를 보고 build.gradle 을 복원해야합니다.

xxCore 는
 - src
 - build.gradle만 설정되면 됩니다.

우선 root 의 settings.gradle 을 확인합니다.

include 'xxxCore'
include 'xxxApi'

이렇게 자동으로 추가되어있을겁니다.

이제 root 프로젝트의 build.gradle을 설정해야합니다.

group 'com.ssp'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

buildscript {
    ext {
        springBootVersion = '2.2.6.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath "io.spring.gradle:dependency-management-plugin:1.0.9.RELEASE"
    }
}

/*
plugins {
    id 'org.springframework.boot' version '2.2.6.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id 'java'
}
 */


subprojects {
    group 'com.xxx'
    version '1.0'
    apply plugin: 'java'
    apply plugin: org.springframework.boot.gradle.plugin.SpringBootPlugin
    apply plugin: 'io.spring.dependency-management'

    repositories {
        mavenCentral()
    }

    dependencies {
        // 여기 설정은 sub 프로젝트에 모두 적용됨
        compile('org.springframework.boot:spring-boot-starter-web')
        testCompile('org.springframework.boot:spring-boot-starter-test')
    }
}

project(':xxxApi') {
    dependencies {
        compile project(':xxxCore')
    }
}

로 설정하면 설정이 끝나게 됩니다.

추가적으로 해당값을 설정시, 실행은 되나 build용 jar 생성에 문제가 있었습니다.

xxxCore 및 실행할 어플리케이션이 필요가 없는 build.gradle에, bootJar와 jar의 설정이 추가로 필요합니다.

bootJar {
    enabled = false
    archiveVersion = '0.0.1-SNAPSHOT'
    archiveExtension = 'jar'
}
jar {
    enabled = true
}

참고주소 : https://jojoldu.tistory.com/123

Jun 3, 2020 - memcached 기능 설정

  1. yum clean up
    yum clean all
    
  2. yum 업데이트
    yum -y update
    
  3. memcahced 설치
    yum -y install memcahced
    
  4. memcahced 설치 확인
    memcached -h
    memcached 1.4.15
    -p       TCP port number to listen on (default: 11211)
    -U       UDP port number to listen on (default: 11211, 0 is off)
    -s      UNIX socket path to listen on (disables network support)
    -a      access mask for UNIX socket, in octal (default: 0700)
    -l      interface to listen on (default: INADDR_ANY, all addresses)
                may be specified as host:port. If you don't specify
               a port number, the value you specified with -p or -U is
               used. You may specify multiple addresses separated by comma
               or by using -l multiple times
    -d            run as a daemon
    -r            maximize core file limit
    -u  assume identity of  (only when run as root)
    -m       max memory to use for items in megabytes (default: 64 MB)
    -M            return error on memory exhausted (rather than removing items)
    -c       max simultaneous connections (default: 1024)
    -k            lock down all paged memory.  Note that there is a
               limit on how much memory you may lock.  Trying to
               allocate more than that would fail, so be sure you
               set the limit correctly for the user you started
               the daemon with (not for -u  user;
               under sh this is done with 'ulimit -S -l NUM_KB').
    -v            verbose (print errors/warnings while in event loop)
    -vv           very verbose (also print client commands/reponses)
    -vvv          extremely verbose (also print internal state transitions)
    -h            print this help and exit
    -i            print memcached and libevent license
    -P      save PID in , only used with -d option
    -f    chunk size growth factor (default: 1.25)
    -n     minimum space allocated for key+value+flags (default: 48)
    -L            Try to use large memory pages (if available). Increasing
               the memory page size could reduce the number of TLB misses
               and improve the performance. In order to get large pages
               from the OS, memcached will allocate the total item-cache
               in one large chunk.
    -D      Use  as the delimiter between key prefixes and IDs.
               This is used for per-prefix stats reporting. The default is
               ":" (colon). If this option is specified, stats collection
               is turned on automatically; if not, then it may be turned on
               by sending the "stats detail on" command to the server.
    -t       number of threads to use (default: 4)
    -R            Maximum number of requests per event, limits the number of
               requests process for a given connection to prevent
               starvation (default: 20)
    -C            Disable use of CAS
    -b       Set the backlog queue limit (default: 1024)
    -B            Binding protocol - one of ascii, binary, or auto (default)
    -I            Override the size of each slab page. Adjusts max item size
               (default: 1mb, min: 1k, max: 128m)
    -o            Comma separated list of extended or experimental options
               - (EXPERIMENTAL) maxconns_fast: immediately close new
                 connections if over maxconns limit
               - hashpower: An integer multiplier for how large the hash
                 table should be. Can be grown at runtime if not big enough.
                 Set this based on "STAT hash_power_level" before a
                 restart.
    
  5. memcached 에 대한 설정 변경을 원한다면 vi 로 /etc/sysconfig/memcached 들어가서 수정합니다.
    vi /etc/sysconfig/memcached
    PORT=”11211″
    USER=”memcached”
    MAXCONN=”1024″
    CACHESIZE=”64″
    OPTIONS=””
    
  6. memcached 재시작
    [root@localhost ~]# service restart memcached
    restart: 인식되지 않은 서비스
    [root@localhost ~]# service memcached restart
    memcached 를 정지 중:                                      [실패]
    memcached (을)를 시작 중:                                  [  OK  ]
    [root@localhost ~]# service memcached restart
    memcached 를 정지 중:                                      [  OK  ]
    memcached (을)를 시작 중:  
    

Jun 3, 2020 - WSL 2 기능 적용

Failed to open/create the internal network 'HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter' (VERR_INTNET_FLT_IF_NOT_FOUND).
Failed to attach the network LUN (VERR_INTNET_FLT_IF_NOT_FOUND).

갑자기, Host-Only Ethernet Adapter 에러가 발생했습니다.

순간 어제 WSL 2(Windows Subsystem For Linux 2)를 하기 위해, Windows 10 update 한 게 생각나서, 확인해보니,

Windows update 후(Window 10 1903)에 VirtualBox에서 이미지를 돌릴때 이미지의 네트워크 인터페이스를 호스트 전용 아답터(Host-only) 로 구동시 아래와 같이 VERR_INTNET_FLT_IF_NOT_FOUND 에러 메시지가 나면서 구동이 안되는 문제가 있었습니다.

Failed to open/create the internal network 'HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter' (VERR_INTNET_FLT_IF_NOT_FOUND).
Failed to attach the network LUN (VERR_INTNET_FLT_IF_NOT_FOUND).

우선 기존 네트워크 연결로 가서, VirtualBox Host-Only Ethernet Adapter 를 전부 OFF 처리합니다.

제어판\네트워크 및 인터넷\네트워크 연결

그 후 기존에 설정했던 셋팅을 다시 합니다.

가상 머신 GIT_001의 세션을 열 수 없습니다.

Interface ('VirtualBox Host-Only Ethernet Adapter') is not a Host-Only Adapter interface (VERR_INTERNAL_ERROR).

결과 코드: E_FAIL (0x80004005)
구성 요소: ConsoleWrap
인터페이스: IConsole {872da645-4a9b-1727-bee2-5585105b9eed}

이제 다른 에러가 나네요 ^-^ 새로 수정한 VirtualBox Host-Only Ethernet Adapter 를 설정하지 않았기 때문입니다!

잘 수정하니 정상적으로 동작하네요.