레이블이 computer인 게시물을 표시합니다. 모든 게시물 표시
레이블이 computer인 게시물을 표시합니다. 모든 게시물 표시

[컴] gmail 첨부파일 한번에 다운로드 하는 법

gmail attachment download / 지메일 / at once /지메일 첨부파일 백업방법

gmail 첨부파일 한번에 다운로드 하는 법

gmail 의 메일중 첨부파일이 있는 것들이 있다. 이것들을 전부 한번에 다운로드 받는 툴이다.

절차:

  1. settings 에서 계정 설정을 한다.
  2. folder/files –> Selected Folders –> 이름에 들어갈 필드 정하기 –> 하단에서 원하는 folder 선택 –> download

[컴] RB3011UiAS-RM 무한부팅 상황, RouterOS 재설치

 

미크로틱, 라우터 /

RB3011UiAS-RM 무한부팅 상황, RouterOS 재설치

현상

starting kernel –> routerboard 나오고 멈추거나 여기서 꺼지고 계속 다시 starting kernel 이 뜬다.

원래는 starting kernel 하고 나서 starting services 가 보여야 한다.

RB3011UiAS-RM

미리 netinstall, package 를 아래 링크에서 download 하자. ’RB3011UiAS-RM’의 RouterOS는 arm 버전을 받으면 된다.

  • <https://mikrotik.com/download >

RouterOS 설치

  • https://www.mikrotik.com.my/reinstalling-mikrotik-routeros-without-serial-port/
    • pc 의 ethernet port 에 꽂고, routerboard 의 Eth1 port 에 꽂음.
    • 참고로 power 옆에 Ethernet port 는 power 공급용이다.(참고: https://help.mikrotik.com/docs/display/UM/RB3011UiAS-RM)
    • factory reset 하고,
    • windows 의 방화벽 끈다.
    • ip 주소 설정시, gateway 설정은 하지 않고, ip address 를 입력한다.
    • netinstall 을 열고 ‘Net booting’ 메뉴를 누른다. Boot Server enabled 를 check 하고, 같은 subnet 의 ipaddress 를 입력한다. 당연히 windows 에 설정한 ip address 와 다르게 입력한다.
    • netinstall 을 열어놓은 상태에서
    • ether boot 상태로 간다. (router 전원을 빼고, reset 을 누른상태로 전원을 켠다. 그리고 LED가 깜빡깜빡 거리다가 멈추고, LED가 꺼지면 그 때 reset 버튼을 release 한다.)
    • 그러면 이제 netinstall에 router 가 잡힌다.
    • package 를 선택하고, Install 버튼을 누른다.

설정

  • install 이 완료되고 부팅을 하면, 이제 winbox 로 setting 을 잡으면 된다.
  • setting 을 초기화 하려면, winbox 에서 terminal 을 띄우고, system reset-config 를 실행하면 된다. 참고로 암호도 초기화 된다.
  • 간단하게 WAN 을 설정하고, LAN 을 설정하는 법
  • WAN 이 DHCP에서 ip 를 받아오는 경우: https://www.2cpu.co.kr/bbs/board.php?bo_table=lec&wr_id=965
    • 1번 port 에 WAN 을 꽂으면 된다. WAN 이 DHCP client 로서 ip 를 받아올 것이다.
    • 기본 세팅이 router mode 이다. 이때 1번 port 에 WAN 을 꽂으면 된다. 알아서 DHCP client 를 ether1 에 설치해서 ip address 를 받아온다.
    • 이때 subnet 은 192.168.88.x 를 기본으로 사용한다.

[컴] 2024년 1월 부터 aws 에서 과금하는 public IPv4 주소들

2024년 1월 부터 aws 에서 과금하는 public IPv4 주소들

다음 글에서 보듯이, AWS 가 public ip address 에 과금을 시작한다.

그래서 어떤 부분이 부과되는지에 대해 확인해봤다.

과금되는 주소들:

  • Elastic IP 주소(EIP): Amazon에서 제공하는 고정 public IPv4 주소
  • EC2 공용 IPv4 주소: Amazon이 EC2 인스턴스에 할당하는 public IPv4 주소(EC2 인스턴스가 기본 서브넷으로 시작되거나 인스턴스가 공용 IPv4 주소를 자동으로 할당하도록 구성된 서브넷으로 시작되는 경우).
  • BYOIPv4 주소: 자체 IP 주소 가져오기(BYOIP)를 사용하여 AWS에 가져온 IPv4 주소 범위에 있는 public IPv4 주소.
  • 서비스 관리형 IPv4 주소: AWS 리소스에서 자동으로 프로비저닝(provisioning)되고 AWS 서비스에서 관리하는 public IPv4 주소. 예를 들어 Amazon ECS, Amazon RDS 또는 Amazon Workspaces의 public IPv4 주소가 있다.

과금확인 :

https://aws.amazon.com/blogs/networking-and-content-delivery/identify-and-optimize-public-ipv4-address-usage-on-aws/ : 얼마나 자신이 갖고 있는 public ip 가 사용됐는지 과금표에서 볼 수 있다.

See Also

  1. 쿠…sal: [컴][웹] aws 가격 정리

[컴] WSLg

 wslg path

WSLg

  • windows 에서 linux 의 gui app 을 띄우는데 도움을 주는 linux distro 부분이다.
  • gui system 관련 linux distro 를 따로 가지고 있다.
  • windows 에서 linux gui app 의 상호작용: RDP 를 이용해서 windows <--> linux를 통해 처리한다.

자세한 사항은 ref.1 을 참고하자.

path

WSLg path

  • powershell 에서 Get-AppxPackage MicrosoftCorporationII.WindowsSubsystemForLinux
    • C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.2.5.0_x64__8xxxxxxxxe
    • 이곳에 wsl.exe, wslg.exe 등이 설치된다.

kernel path

  • default path: c:\Windows\System32\lxss\tools
  • .wsconfig 를 통해서 원하는 path로 변경할 수 있다.[ref. 2, 3]
  • 관련 registry : HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss

wslg path in user distro

user distro 에서 ls /mnt/wslg 를 하면 WSLg System distro 부분을 확인할 수 있다.

Reference

  1. GitHub - microsoft/wslg: Enabling the Windows Subsystem for Linux to include support for Wayland and X server related scenarios
  2. 쿠…sal: [컴] wsl2 에서 bcc 설치 및 실행
  3. windows subsystem for linux - Change of WSL installation location - Super User

[컴] 구글이 2023년 8월에 받은 DDoS 공격

트래픽 / 대용량 /대규모 / 네트워크 traffic / 디도스

구글이 2023년 8월에 받은 DDoS 공격

  • 23년 8월 DDoS 공격, 작년 최대치보다 7.5배 더 큰 크기
  • peak 에서 3억9800만rps(request per second, 초당 request)
  • HTTP/2 “Rapid Reset” 기술 이용한 공격
  • 작년의 최대 기록은 peak 에서 4600만 rps 였다.
  • 2분간 보내진 공격request 가 위키피디아의 2023년 9월의 총 페이지 뷰보다 많다.
  • HTTP/2 protocol 를 지원하는 서버라면, CVE-2023-44487 관련 patch 를 적용하자.

from ref.3:

  • 대략 2만대기기로 수행
  • 이런 DDoS attack 은 누가 일으키는가?(from: https://news.ycombinator.com/item?id=37833074)
    • 정부 행동자들(government actors)
    • 때론, 동유럽의 scammer(나쁜일 하는사람)
      • 이런 큰 공격을 통해 botting community에서 street cred(길거리 신용) 를 얻기 위해 한다.
      • 이 신용을 가지고, rival 을 공격하려는 주체에게 돈 받고 이런 일을 해준다.
      • 이런 주체는 정부, 수상한 회사들(예를들어, 2022년에는 암호화폐회사들이 라이벌을 공격해달라는 요청을 많이 했다.)
      • 이런 일을 하는 사람들의 대다수는 기술은 있지만, 자신이 사는 환경이 돈을 벌 수 있는 환경이 안되는 경우가 많다.

공격

http2 는 end user 가 다른 곳으로 가거나, data 교환을 멈추게 할 수 있는데, 그래서 stream 을 cancel 할 수 있는 방법을 제공한다.

그래서 공격자는 connection 을 열고, 여기서 stream 을 시작하고 바로 stop 을 시키는 것을 반복한다.(RST_STREAM) 그래서 connection 하나에서 사용가능한 stream 한계치를 넘어서서 stream 을 보내게 된다. 이것이 서버가 서비스를 못하게 만든다(denial of service)

대략 2천대의 시스템으로 구성된 bot net 이 관련되어 있다. 이렇게 작은 botnet 크기로도 큰 볼륨의 request 를 만들 수 있다는 것이 이 취약점이 보호되지 않은 네트워크에 얼마나 위협적인지 알려준다.

만약 http2를 이용해서 https://daum.net 으로 GET request 를 보내면, 이때는 stream ID 1 를 통해 교환된다. 이때 client 가 1개의 HEADERS 1 frame 을 서버로 보내면, 서버는 1개의 HEADERS frame 붙여서 1개이상의 DATA Frame 을 붙여서 보낸다. 그리고 client 가 다른 request를 서버로 보내면, 그것은 HEADERS 3 이 되고, 서버는 이것에 대한 응답을 DATA stream 1 뒤에 붙여서 보낸다. 이것이 스트림의 multiplexing이고, concurrenct 이다.

이것이 http2의 강력한 기능인데, 이로인해 client 가 동시에 많은 request를 보낼 수 있게 되는데, 그러면 peak 시점의 server resource 가 더 많이 필요하게 된다.

etc

See Also

  1. 쿠…sal: [컴][사례] 네크워크 부하가 큰 경우 네트워크 대역폭 사용량
  2. 쿠...sal: [컴][네트워크] DDos(distributed denial of service) 공격

Reference

  1. Google Cloud mitigated largest DDoS attack, peaking above 398 million rps | Google Cloud Blog
  2. HTTP/2 신속한 재설정 취약점으로 인해 역대 규모의 DDoS 발생 | GeekNews
  3. The largest DDoS attack to date, peaking above 398M rps | Hacker News
  4. https://github.com/caddyserver/caddy/issues/5877

[컴] terraform module

 

terraform module

module 은 wrapper function 같은 느낌이다. terraform 에서 제공하는 hashicorp aws 로도 해결이 되지만, module 을 사용해서 좀 더 간단한 설정을 가능하게 해준다.

개인적인 생각은 같은 pattern 이 많아지면 사용하면 좋을 듯 하다. 그 전에 사용하는 것은 terraform 의 이해를 떨어뜨리는 듯 하다.

registry

terraform module 들은 다음 링크에서 확인할 수 있다.

module input, output

module 은 argument 들을 가지고 있는데, required 만 채워넣으면 된다.

custom module

아래처럼 source를 적어주는데, directory 를 적어준다.


module "db_parameter_group_2" {
  source = "../../modules/server/db/db_parameter_group/"
}

module 인식

아래처럼 module 이 있는데, 이렇게 만들고 나서 terraform init 을 다시 해줘야 module 을 인식한다.

├───environments
│   └───dev
│       ├───.terraform
│       └─── main.tf
|
├───generated
│   └───aws
│       ├───auto_scaling
│       ├───ec2_instance
│       ├───ec2_instance00
│       └───rds
└───modules
     └───db
         ├─── main.tf
         ├─── variable.tf
         └─── output.tf

See Also

  1. ec2-instance : aws ec2, vpc module 을 사용하는 글
  2. 쿠...sal: [컴] Terraformer 사용법
  3. terraform-aws-rds/modules/db_instance/main.tf at master · terraform-aws-modules/terraform-aws-rds · GitHub : terraform module 코드이다. 어떤식으로 좋은 예시로 사용할 수 있다. 

[컴] postman 대신 사용가능한 무료 툴

curl gui / curl 대신 / 대안 / alternatives / 도구 / tool /curl 대신 사용할 gui툴 /

postman 대신 사용가능한 무료 툴

[컴] ebpf 사용

ebpf 사용

기본적으로 ebpf 에서 직접적으로 돌아가는 code를 만드는 것은 잘 하지 않는다고 한다. 대체로 framework 를 통해서 coding 을 한다. bcc, bpftrace 같은 tool 도 iovisor 라는 framework 위에 만들어졌다.[ref. 1]

ref. 1 의 예제를 보면, tcp 통신에서 보내고, 받은 bytes 를 보여주는 program, tcplife 가 나온다. 이것을 기존의 kernel technology 로 만들 수 있는데, 그러면 performance overhead 가 더 생길 것이고, security issue 도 있을 것이라 한다.

packet 수 보다는 적은 TCP session event 만 trace 한다. 그래서 모든 packet 을 trace 하는 것보다 overhead 를 줄인다.

bpfcc-tools 사용

bpftrace

bcc tools 같은 기능을 원하는대로 변경(customize)하려면, bpftrace 를 사용할 수 있다. bcc 만큼 자유롭게 customize 할 수는 없다.

See Also

  1. eBPF: Unlocking the Kernel [공식 다큐멘터리, 30분] | GeekNews

Reference

  1. Learn eBPF Tracing: Tutorial and Examples

[컴] wsl2 에서 bcc 설치 및 실행

wsl2 에서 bcc 설치 및 실행

절차

  1. wsl2 kernel build
  2. bcc 설치 및 실행

1. wsl2 kernel build

wsl2 linux kernel source 를 받아서 wsl2 ubuntu 에서 build 한다.

  1. 다음 link 에서 kernel source 를 받자.

  2. build 를 위한 config 설정

  3. build

    • cpu : i5-9400F @ 2.9GHz

    • wsl2 에서 build, 대략 27분 소요

    • <proj_root>\vmlinux : build 후 생성된 kernel

      sudo apt install build-essential flex bison dwarves libssl-dev libelf-dev
      tar xvf WSL2-Linux-Kernel-linux-msft-wsl-5.10.74.3.tar.gz
      cd WSL2-Linux-Kernel-linux-msft-wsl-5.10.74.3
      
      # 만약, 커널 버전 이름을 변경하고 싶다면, 아래처럼 하면 된다. 굳이 수정할 필요는 없다.
      # export KERNELRELEASE=5.10.74.3-microsoft-standard
      # make KCONFIG_CONFIG=Microsoft/config-wsl KERNELRELEASE=$KERNELRELEASE -j 4
      
      sudo apt-get install flex bison libssl-dev libelf-dev dwarves
      
      cp ./Microsoft/config-wsl .config
      # config path 설정은 아래처럼 할 수 있다.
      # make KCONFIG_CONFIG=Microsoft/config-wsl -j 4
      make -j 4
      make modules -j 4
      sudo make modules_install
    • ls /lib/modules/ : /lib/modules 가 만들어진다.

  4. 새로 build 한 kernel 을 사용하도록 설정

    • vmlinux를 windows 로 복사
    mkdir /mnt/c/Users/myuserid/kernel
    cp vmlinux /mnt/c/Users/myuserid/kernel/vmlinux-5.10.74.3
    • c:\Users\myuserid\.wslconfig 설정
    [wsl2]
    
    kernel=c:\\Users\\myuserid\\kernel\\vmlinux-5.10.74.3
  5. 새롭게 wsl2 시작

    wsl --shutdown
    wsl -d Ubuntu-20.04
    ...
    # kernel version 확인
    uname -r
    5.10.74.3-microsoft-standard-WSL2

2. bcc 설치 및 실행

sudo apt-get update
sudo apt-get install bpfcc-tools
sudo opensnoop-bpfcc

opensnoop-bpfcc 를 켜놓은 상태에서 curl 을 한번 쳐보면, 이 tool이 어떻게 동작하는지 볼 수 있다.

opensnoop 은 `open()`` syscall에 대해 한 줄의 출력을 print 한다. 이렇게 어떤 file 이 open 됐는지를 보면서, data file 들, config filed 들 , log file 들이 무엇인지 확인할 수 있다.(참고: 1.2. opensnoop | bcc/docs/tutorial.md)

Reference

  1. bcc/INSTALL.md at master · iovisor/bcc · GitHub
  2. Enable EBPF on WSL2 · GitHub
  3. Advanced settings configuration in WSL | Microsoft Learn

[컴] wsl2 에서 default user 변경

wsl2 에서 default user 변경

  1. /etc/wsl.conf 에서 수정
    • /etc/wsl.conf 가 존재하지 않으면 만들면 된다.
[user]
default=username
  1. 특정 userid 로 wsl 실행시 : wsl -d <distribution_name> -u root

  2. ubuntu config --default-user johndoe

Reference

  1. linux - How to set default user for manually installed WSL distro? - Super User

[컴] eBPF 정리

eBPF 정리

eBPF 는 Berkeley Packet Filter에 e(extend)를 붙여서 만든 이름인 듯 하다. wiki 의 내용을 보면 BPF 는 network traffic 분석용으로 많이 쓰였던 것 같다.

이 부분이 확장돼서 이제는 kernel mode 에서 실행돼야 하는 script 를 실행할 수 있게 해주는 기술이 됐다.

이전에 kernel 에 기능을 넣으려면, code 를 수정해서 다시 빌드 하던지, kernel module들을 load 해야 했다.[ref. 1]

static code analysis 와 crash, hang 또는 다른 kernel 에 부정적인 영향을 미치는 것들을 reject 하는 것으로 안정성(safety)을 제공한다.

자동으로 거부되는 프로그램의 예

  • 강력한 종료 보장이 없는 프로그램(즉, 종료 조건이 없는 for/while 루프)
  • safety-checks 없는 pointers들을 dereference하는 프로그램

verifier를 통과한 loaded program 은, 빠른 성능을 위해서, interpreted 되거나 in-kernel JIT compiled 된다. 그리고 나서, program들은 os kernel 의 여러 hook point 들에 attached 돼서 event 가 발생할 때 실행된다.

대략적인 개념은

system call 에서 함수를 호출할 때 마다, eBPF 함수를 호출하도록 만들어 놓은 듯 하다. 그래서 정의된 handler 가 없으면, 그냥 넘어가고, 있으면 실행하게 되는 듯 하다.

windows 에서 ebpf

windows 에서도 ebpf 를 만들고 있다. 기존 ebpf 위에 layer를 추가해서 windows 에서도 실행되도록 한다.

지원버전:

  • windows 10 이상
  • windows server 2019 이상

wsl

helloworld for wsl2

#!/usr/bin/python3
from bcc import BPF
from time import sleep

program = """
BPF_HASH(clones);

int hello_world(void *ctx) {
    u64 uid;
    u64 counter = 0;
    u64 *p;

    uid = bpf_get_current_uid_gid() & 0xFFFFFFFF;
    p = clones.lookup(&uid);
    if (p != 0){
        counter = *p;
    }

    counter++;
    clones.update(&uid, &counter);

    return 0;
}
"""

b = BPF(text=program)
clone = b.get_syscall_fnname("clone")
b.attach_kprobe(event=clone, fn_name="hello_world")
b.trace_print()

sleep(1000)

while True:
    sleep(2)
    s = ""
    if len(b["clones"].items()):
        for k,v in b["clones"].items():
            s += "ID {}: {}\t".format(k.value, v.value)
        print(s)
    else:
        print("No entries yet")

See Also

  1. 쿠…sal: [컴] ebpf 사용
  2. Pulsar - eBPF 기반의 IoT 리눅스 기기 런타임 보안 프레임워크 | GeekNews

Reference

  1. eBPF - Wikipedia
  2. What is eBPF? An Introduction and Deep Dive into the eBPF Technology

[컴] adobe creative cloud 를 kill 하는 powershell script

 

ps example / powershell kill process / example / kill tree ps

adobe creative cloud 를 kill 하는 powershell script

powershell script

function Kill-Tree {
    Param([int]$ppid)
    Get-CimInstance Win32_Process | Where-Object { $_.ParentProcessId -eq $ppid } | ForEach-Object { Kill-Tree $_.ProcessId }
    Stop-Process -Id $ppid
}

function Kill-Process {
    # kill the processes which have the same names
    Param([String]$pname)
    echo "kill $pname"
    $pids=(get-process $pname).id
    For ($i=0; $i -lt $pids.length; $i++){
        $pi = $pids[$i]
        Kill-Tree $pi
    }
}


Kill-Process "Adobe Desktop Service"
Kill-Process "AdobeIPCBroker"
Kill-Process "Creative Cloud Helper"
Kill-Process "CCXProcess"
Kill-Process "CCLibrary"
Kill-Process "CoreSync"

Reference

  1. Terminate process tree in PowerShell given a process ID - Stack Overflow

[컴] storage and retrieval

 

db index / index 가 저장되는 방법

storage and retrieval

ref.1 의 storage and retrieval 부분을 정리중…

index 저장에 대한 구현방법

  • log 를 append 를 하는 것이 빠르게 write 할 수 있는 방법. 기존의 것에 overwrite 하는 것보다 유리하다.
  • 이것은 특정 size 의 segment 까지만 저장하고, 한도를 넘어가면 새로운 파일로 저장. 이런식으로 여러 segmemt를 저장한다.

compaction 과 merge:

  • log를 write 하면서 동시에 가장 최근 값만 남기고 버리는 작업을 진행. 이것을 compaction 이라고 하자.
  • 이 compaction 을 하면서 동시에 다른 segment 것과 합치는 작업(merge) 를 진행할 수도 있다.
  • compaction 과 merge 를 완료하면, 최종적으로 모든 segement 에서 1개의 key 만 남게 된다.

hash table 한계:

  • 각 segment 에 대한 hash table 은 메모리에 둔다. hash table 은. file 버전은 효율적이지 않아서 없다.
    • file 버전의 hash table 은 많은 랜덤 액세스 I/O가 필요하고, 가득 차면 커지는 데 비용이 많이 들며, 해시 충돌에는 까다로운 로직이 필요하다.
  • hash table은 range query에는 적합하지 않다. kitty00000과 kitty99999 사이의 모든 키를 스캔하려 할 때, 할 수 없으며 해시 맵에서 각 키를 개별적으로 조회해야만 한다.

SSTable:

  • sorted string table 의 약자다.
  • 각 segment는 key 순으로 정렬되게 insert한다.(이러면 당연히 sequential insert 가 안된다.) 그리고 각 segment 에서 compaction 을 시킨다.(그러면, 키가 unique하게 된다.) 이제 이 segement들을 merge 하면서 sort 한다.(merge sort)
  • 이렇게 되면, 모든 key 에 대한 hashmap 을 갖지않고, 듬성듬성 key 를 갖는 sparse hash map 으로도 괜찮다. 근처에 있는 key 의 위치로 가서, 그 안에서 다시 찾아들어가면 된다.
  • 이것은 hash map 으로 찾아들어간 key들이 들어있는 chunk 의 경우는 압축해서 보관해도 된다. 압축을 하게 되면, I/O 대역폭 사용을 줄이고, disk 공간도 줄 일 수 있다.
  • insert 할 때부터, key를 정렬하면서 insert 를 하는 방법은 AVL tree 나 red-black tree 등이 있다.
  • B-tree 등을 이용하면, disk 에서도 이 정렬된 구조를 유지하는 것이 가능하지만, 메모리에서 이 정렬된 구조(structure)를 유지하는 것이 쉽다.

이제 storage engine 이 동작은 이렇게 하게 된다.

  • balanced tree 가 메모리에 있다.
  • write 이 들어오면, balanced tree 에 추가하게 된다.
  • 이 in-memory tree 를 memtable 이라 하자.
  • 이 memtable 이 대략적으로 수MB 정도로 커지면, 지금까지의 tree 를 file로 저장한다.
  • 이 때 이 file 은 SSTable(Sorted String Table, key 로 정렬된 data 를 가진 chunk 로 보면 된다. 즉, tree 의 leaft node를 순서대로 저장한 모양이 될 것) 로 저장한다.
  • 이것이 효과적인 이유는 tree 가 이미 key로 정렬된 key-value pair들을 유지하고 있기 때문이다.
  • 새롭게 만들어진 SSTable file 이 가장 최근 db segment 가 된다.
  • 이 SSTable file 로 이전의 key 가 저장되는 동안에도 write 가 들어오면, 새로운 memtable 이 생성된다.

결과적으로, 하나의 SSTable 에는 특정시간동안 쌓인 key 들이 있게 된다.

read 를 처리할때는

  • 먼저 memtable 에서 key를 찾는다.

  • 여기에 없으면, 가장최근의 disk segment 로 간다. 거기도 없으면, 그 다음 오래된 segment 로 가서 key 를 찾게 된다.

  • 때떄로 merge 및 compaction process 를 backgroud 에서 실행한다. 이 때 SSTable 이 줄어든다.

  • 이것을 실행해서, segment 파일들을 merge하고, overwritten 된 값이나 delted 된 값들을 버린다.

이때 만약 memtable 이 날라갈 때를 대비해서, write 될때 그냥 sequential 한 log 를 남기는 것으로 이 문제를 어느정도 커버할 수 있다. 그리고 이 로그는 SSTable 를 만들때 discard 하면 된다.

Reference

  1. Designing Data Intensive Applications

[컴] gmail 에서 받은 mbox 를 python 으로 처리

mbox

gmail 에서 받은 mbox 를 python 으로 처리

gmail 에서 data backup 을 하면, .mbox 형식으로 다운로드 할 수 있다. 이것을 읽어드려서 보려면, mbox viewer 로 잠깐 demo 기간만 이용해도 된다.

개인적으로 처리방법을 찾아봤다. 무료로 html 로 변화해주는 것들을 찾아봤는데, linux 용으로 몇개가 보였다. 한개는 c 로 만든 것이라 compile 해야 해서 일단 pass 했다.

이것저것 찾다가 간단하게 python 으로 된 녀석을 찾았다.

이것으로 읽어서 원하는 모양으로 output 을 만드는 것이 가장 나은 선택일 듯 싶다.

[컴] jooq 사용, jooq gradle plugin

jooq란?/

jooq 사용, jooq gradle plugin

여기서는 jooq 를 사용하는데, jooq gradle plugin 을 이용해서 사용한다.

jooq 팀에서도 Grdle plugin 을 쓰는 것을 권장한다.

여기서는 gradle-jooq-plugin 의 README.md 의 내용을 기초로 사용법을 설명한다.

가장 간단한 예제는 아래와 같다.

generationTool

setup for generationTool

여기서는 mariadb와 연동되는 springboot 에 적용해서 mariadb 의 table, record 관련된 class 를 generationTool 을 사용해서 만드는 작업을 해보려 한다.

  1. 먼저, 다음링크를 참고해서 springboot 을 준비하자.

  2. jooq.gradle : 여기에 다음처럼 *.gradle 파일을 추가하자. 그냥 build.gradle 에 전부 넣을 수도 있다. 그것은 여기를 참고하자.

    • build.gradle
    ...
    apply from: 'jooq.gradle'
    ...
    • jooq.gradle:

      • database.inputSchema 를 지정해주지 않으면, 전체 database 에 대해 class 를 생성한다.
      • database.include, database.exclude : code generation 할때, include, exclude 조건을 넣을 수 있다. 예를 들면, 특정 이름의 table 에 대한 code generation 을 하거나 할 수 있다. 자세한 것은 Includes and Excludes 를 참고하자.
    import nu.studer.gradle.jooq.JooqEdition
    
    buildscript {
      repositories {
        gradlePluginPortal()
      }
    
      dependencies {
        classpath 'nu.studer:gradle-jooq-plugin:8.2'
      }
    }
    
    
    apply plugin: nu.studer.gradle.jooq.JooqPlugin
    
    repositories {
      mavenCentral()
    }
    
    dependencies {
      // mariadb 가 아니라면, 다른 client 를 사용하게 된다.
      jooqGenerator 'org.mariadb.jdbc:mariadb-java-client'
    }
    
    jooq {
      configurations {
        main {
          generationTool {
            logging = org.jooq.meta.jaxb.Logging.WARN
            jdbc {
              url = 'jdbc:mariadb://localhost:3307/stest?useUnicode=true&characterEncoding=utf-8'
              user = 'root'
              password = 'root'
              driver = 'org.mariadb.jdbc.Driver'
              properties {
                property {
                  // 이건 그냥 자신이 원하는 변수를 지정하는 부분으로 보면된다.
                  key = 'PAGE_SIZE'
                  value = 2048
                }
              }
            }
            generator {
              name = 'org.jooq.codegen.DefaultGenerator'
              database {
                name ='org.jooq.meta.mariadb.MariaDBDatabase'
                inputSchema = 'stest'   // 이것을 지정해주면, 여기 지정된 database의 schema 의 class 만 만든다.
                include = '.*'
                exclude = 'flyway_schema_history'
              }
              target {
                packageName = 'com.namh.namhex'
              }
              strategy {
                name = "org.jooq.codegen.DefaultGeneratorStrategy"
              }
            }
          }
        }
      }
    }
  3. gradlew.bat generateJooq 를 실행하면 class file 들이 만들어진다.

    • 위 같은 경우 packageName 이 com.namh.namhex 이기에 다음경로에 DB table, record에 대한 class file 이 다음 경로에 만들어진다.
      • <root>\build\generated-src\jooq\main\com\namh\namhex
d:\namhex000>gradlew generateJooq

> Task :generateJooq
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.2.1/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD SUCCESSFUL in 5s
1 actionable task: 1 executed

jooq gradle-plugin examples

jooq 사용, jooq gradle plugin

db에 접속해서 table의 schema 를 얻는 것이 아니라 local 에 있는 schema 를 이용해서 만들수도 있다.

jooq slow query

Reference

  1. Getting Started with jOOQ | Baeldung

[컴] SpringBoot web server 를 위한 helloworld

boilerplate /

SpringBoot web server 를 위한 helloworld

간단하게, MariaDB 를 사용하는 Rest API 서버를 만들기 위한 기본 setting 이라고 보면 된다.

  1. Spring Initializr 에서 생성(아래 ‘그림. Spring Initializr 설정’ 참고)
  2. application.yml 설정
    • server 설정
    • mariadb 설정
  3. gradlew.bat bootRun

Spring Initializr 설정:

그림. Spring Initializr 설정

build.gradle:

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'com.fasterxml.jackson.module:jackson-module-kotlin'
    implementation 'org.jetbrains.kotlin:kotlin-reflect'
    runtimeOnly 'org.mariadb.jdbc:mariadb-java-client'

    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

spring-boot-starter-web

spring-boot-starter-web 가 있어야 서버로서 동작한다. 저 library 가 없으면, 그냥 한번 실행하고, exit(shutdown) 하게 된다.

spring - Springboot Application exits immediately - Stack Overflow

application.yml 설정

# application.yml
server:
  port: 9100
spring:
  profiles:
    active: dev

---

spring:
  config:
    activate:
      on-profile: "dev"
  datasource:
    url: >
      jdbc:mariadb://localhost:3307/stest?
      useUnicode=true&characterEncoding=utf-8
    username: root
    password: root
    driver-class-name: org.mariadb.jdbc.Driver
    hikari:
      maximum-pool-size: 5

spring.jpa.hibernate.ddl-auto

  • 86. Database Initialization : spring.jpa.hibernate.ddl-auto property에 대한 설명, 이것은 hibernate 의 feature(기능) 이다. 그래서 만약 접속하는 table 이 존재하지 않을때 create 을 하는 등의 행동을 하도록 할 수 있다.

create, create-drop, update, validate, node 에 대한 설명:

spring-boot-devtools

다음처럼 spring-boot-devtools을 추가하면 된다. 그리고 서버를 실행하면 아래 그림처럼 LiveReload server 가 running 하고 있다는 message를 확인할 수 있다.

dependencies {
    ...
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
}
그림. liveReload

참고로, 2개 이상의 spring boot 을 띄우고 있다면, 이미 port 를 사용하고 있어서 LiverReload server가 run 할 수 없는 경우도 있다. 이때는 port 를 변경해주면 된다.

...
---
spring:
  ...
  devtools:
    livereload:
      port: 35731
  ...

See Also

  1. 쿠…sal: [컴] jooq 사용, jooq gradle plugin

[컴] msys2 zsh 에서 Antigen 사용

package manager

msys2 zsh 에서 Antigen 사용

  • terminal : windows terminal (참고)

Antigen 이란?

위 link 를 보면, 이 tool 이 하는 역할을 이해할 수 있다. 대략적으로 oh-my-zsh의 plugin manager 의 역할을 한다고 보면 될 듯 하다.

oh-my-zsh 는 한 repository 의 directory 에서 여러개의 plugin 을 관리하고 있다.

그런데 이것보다 나은 plugin management system 이 필요했는데, 진전이 없어서 이 Antigen을 만들었다고 한다.

이 Antigen 은 다양한 github repo 에서 필요한 plugin 을 가져온다고 한다.

Prequisites

  1. git 필요

설치

antigen.zsh 만 있으면 된다.

antigen.zsh 를 설치하고, .zshrc 를 작성후 재실행하면 된다.

curl -L git.io/antigen > antigen.zsh
# or use git.io/antigen-nightly for the latest version

mv ./antigen.zsh ~/.omz/

~/.zshrc:

source ~/.omz/antigen.zsh

# Load the oh-my-zsh's library.
antigen use oh-my-zsh

# Syntax highlighting bundle.
antigen bundle zsh-users/zsh-syntax-highlighting

# Load the theme.
antigen theme borekb/agkozak-zsh-theme@prompt-customization

# Tell Antigen that you're done.
antigen apply

prompt 가 안보인다.

처음 실행하면, antigen 을 적용한 후, prompt 가 보이지 않는다. 이럴때는 그냥 새 창을 띄우면 된다.

Reference

  1. Zsh on Windows via MSYS2. I have quite a long history trying to… | by Borek Bernard | Medium
  2. Prompt disappears on sourcing .zshrc using antigen · Issue #8 · agkozak/agkozak-zsh-prompt · GitHub

[컴] msys2 bash 를 windows terminal 에 추가하기

msys2 bash 를 windows terminal 에 추가하기

  1. windows terminal 에 가서 command pallete(ctrl+shift+p) 를 열자
  2. Open settings file (JSON) 을 선택
  3. profiles.list 에 msys2 추가(아래 json 참고)

이 때 guid 의 생성은 다음 link 를 참고하자.

profile:

{
    "commandline": "d:\\msys64\\msys2_shell.cmd -defterm -here -no-start -mingw64 -shell bash",
    "guid": "{2ece5bfe-50ed-5f3a-ab87-5cd4baafed2b}",
    "hidden": false,
    "name": "msys2 bash"
}

zsh

bash 대신 zsh 를 사용하고 싶다면,

  1. zsh 를 설치 : pacman -S zsh 을 하면 zsh 이 설치된다.
  2. msys2 를 실행할 때 zsh 로 실행 : d:\\msys64\\msys2_shell.cmd -defterm -here -no-start -mingw64 -shell zsh

Reference

  1. Adding MSYS to windows terminal - Stack Overflow

[컴] VSCode 에서 Msys2 bash 사용

vs code 에서 bash 사용 / zsh 사용

VSCode 에서 Msys2 bash 사용

vscode 는 container 에 접근해서 사용할 수도 있다.

다만 이것은 여러모로 memory/storage 를 많이 먹는다. 그래서 msys2 를 이용한 방법이 있어서 사용해 본다.

여기선 vscode 의 기본 terminal 을 msys2 가 제공하는 콘솔을 사용하도록 설정할 것이다.

절차

  1. msys2
    1. msys2 설치(https://www.msys2.org/)
    2. <msys64>\msys2.exe 실행
    3. pacman -Syu : package repo database update,
  2. vscode 세팅
    • Preferences: Open User Settings (JSON) 으로 가자.
    • bash terminal 추가
    • git path 추가
    • vscode 재실행

msys

msys2 를 download 하고 설치후, <msys64>\msys2.exe 를 실행하면 된다. 이 환경은 posix emulator 라고 보면 된다. 여기서 원하는 package들을 설치해서 사용할 수 있다.

먼저 pacman -Syu 을 통해 pakage 를 update 하자. 여러번 실행해야 할 수 있다.

  • pacman -Syu : package repo의 data 를 update, 여러번 실행해야 한다.

이제 bash 가 같이 설치됐다. (경로: <msys64>\usr\bin\bash.exe)

vscode settings

이제 vscode 의 terminal 의 default 값을 BASH 로 바꾸는 작업을 해주자.

아래처럼 setting 을 추가한다. 그러면 terminal panel(control+`) 에서 ’BASH’를 사용할 수 있게 된다.

아래는 msys2 를 C:\\msys64에 설치했을때의 설정이다.


"terminal.integrated.profiles.windows": {
   "BASH": {
       "path": "C:\\msys64\\usr\\bin\\bash.exe",
       "args": [
           "--login",
           "-i"
       ],
       "env": {
           "MSYSTEM": "MINGW64",
           "CHERE_INVOKING": "1",
           "MSYS2_PATH_TYPE": "inherit"
       }
   }
},
"terminal.integrated.defaultProfile.windows": "BASH",
"git.path": "C:\\msys64\\usr\\bin\\git.exe",    // --> 이건 그냥 git for windows 를 설치해서 사용해도 된다.

See Also

  1. 쿠…sal: [컴] Cygwin 과 MSYS2 의 차이
  2. 쿠…sal: [컴] windows 에서 zsh 사용하기(wsl 없이)
  3. 쿠...sal: [컴] msys2 bash 를 windows terminal 에 추가하기

Reference

  1. GitHub - alisoufali/MSYS2-Setup-Guide: An installation/configuration guide to help setting up MSYS2 on microsoft windows and use it in Visual Studio Code
  2. How To Set Up And Use MSys2 – CadHut

[컴] windows 에서 git for windows의 msys2 를 이용해서 zsh 사용하기

zsh windows / msys / wsl 없이

windows 에서 git for windows의 msys2 를 이용해서 zsh 사용하기(wsl 없이)

절차

  1. git for windows 설치
  2. zsh msys2 package 를 download
  3. 압축을 풀고, msys2 환경에 copy

상세내용

msys2 환경에서 실행되는 zsh 를 이용한다고 보면 된다.

이미 git for windows 가 msys2 환경이 같이 설치된다. [ref. 1] 그러므로 이것을 이용한다.

다음 경로에서 windows 용 zsh 를 download 할 수 있다.

여기서 download 한 내용을 git for windows folder 에 copy 해 넣으면 된다.

usr, etc folder 가 있는데, git for windows 의 folder와 맞춰서 copy 해 넣으면 된다.

MSYS2 설치방법

ref.1 에선 msys2 를 설치하고, 그 안에 git for windows 까지 같이 넣어서 사용하는 방법을 보여준다.

.zst 압축 푸는 법

다음 util 을 사용할 수 있다.

Reference

  1. Zsh on Windows via MSYS2. I have quite a long history trying to… | by Borek Bernard | Medium : 여기서는 msys2 를 설치하고, zsh 를 그 안에 설치한다.
  2. Installing Zsh (and oh-my-zsh) in Windows Git Bash | Dominik Rys
  3. ZSH + Oh My ZSH! on Windows without WSL - DEV Community