티스토리 간만에... 2024.03.10

다운완료~실행.

정식버전 언제나오려나..

 

근데 나 러스트? 설치 안했는데...

아..?

Install Rustup 누르니, 알아서 설치해준다.

아는게 없으니.. 알아서 잘해주겠지

대충 저기 설치된거같고...

프론트도 러스트로 할 수 있단건지... 잘 모르겠네.. 당연히 안될거같..

백엔드 합한 모노레포 말하는걸까. 나중에 만들어봐야겠어.

 

러스트를 주피터 노트북에 사용해서 간단하게 돌려볼 수 있고.

https://pipln.medium.com/rust-%EB%A5%BC-jupyter-notebook-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0-cd939324e23f

 

Rust를 Jupyter Notebook에서 사용

0. 사전 준비

pipln.medium.com

참고하길.

 

RustRover-EAP 는 젯브레인 새 인터페이스가 기본인가보다.

기본으로 깃 세팅도 해두나보네...

대충... src/main.rs 하나있고,

fn은 함수겠거니.

우측상단 초록 화살표나 눌러서 헬로 월드나 찍어보면...

잘되네.

이제 뭐해본다...(?)

..

터미널에 보니 rustup 이랑 cargo 가 추가된거같네

주피터나 설치하자.

에러나네...

버전이 높아서?

https://github.com/evcxr/evcxr/blob/main/evcxr_repl/README.md

리드미나 읽고..

저기 블로그 글과 명령어가 좀 다르지?

cargo install --locked evcxr_repl

--locked 가 붙었는데... 

설치가 되네?

다시 저 블로그 글 가서 따라하고...

...? conda 가 없네...

https://www.anaconda.com/download

드가서 설치...

아... 뭐가 설치하고나니 뭐가 ... (뭐가 많아)

다 꺼

conda create --name evcxr
conda activate evcxr
conda install jupyter
conda install -y -c conda-forge nb_conda_kernels
cargo install evcxr_jupyter
evcxr_jupyter --install
jupyter notebook

귀찮다고 ...걍 여기서 붙여넣으면?

중간중간에 y 눌러줘야한다.

뭐야 되네?

... 

이제 기본 문법이나 익혀볼까.

'몰라그거무서운거 > 알고모르고' 카테고리의 다른 글

week2 과제  (1) 2021.05.23
week 1 과제  (0) 2021.05.15
시, 공간 복잡도  (0) 2021.05.10

Self-hosted

구축 메모

- 키워드 : postgreSQL, kafka, sentry, docker, k8s, 또 뭐있나 clickhouse? 흠 -_-

뭐 이런게 있긴 해

... 읽어보자

음... https://clickhouse.com/docs/en/intro/

 

What Is ClickHouse? | ClickHouse Docs

ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).

clickhouse.com

 

https://github.com/sentry-kubernetes/charts

 

GitHub - sentry-kubernetes/charts: Easily deploy Sentry on your Kubernetes Cluster

Easily deploy Sentry on your Kubernetes Cluster. Contribute to sentry-kubernetes/charts development by creating an account on GitHub.

github.com

이런것도 보이고...

복잡하구나

 

--------------------------

설치 후 https 아니면 안되는 설정들이 있어서 인증서도 붙여야했고,

slack 앱 만들어서 알람연동까지 되는건 좋네 확실히

캡쳐 소리 죽이려고

사용자 인터페이스 사운드 효과 재생을 끄면 알람도 안난다. 다시 켜두도록 하자.

'몰라그거무서운거 > 기타등등' 카테고리의 다른 글

Sentry 구축 메모  (0) 2022.08.17
PRISM Live Studio 마이크 입력 지우기  (0) 2021.05.05
OpenWhisk  (0) 2021.04.29
쿠베 메모  (0) 2021.04.26
Docker compose yml 작성시..  (0) 2021.04.12

link : https://github.com/devouring-algorithm-ds/algorithm-study-s2/tree/s2/week2/week2

 

devouring-algorithm-ds/algorithm-study-s2

기초 자료구조와 알고리즘 씹어먹기. Contribute to devouring-algorithm-ds/algorithm-study-s2 development by creating an account on GitHub.

github.com

 

냠냠 -_-;... 

+ 연결리스트의 내용을 공부하고 정리한다. 
  + 연결리스트의 정의와 성질
  + 연결 리스트의 종류
    + 단일 연결 리스트 (Singly Linked List)
    + 이중 연결 리스트 (Doubly Linked List)
    + 원형 연결 리스트 (Circular Linked List)
  + 배열과 연결리스트의 차이
    + 1) 임의 위치에 있는 원소에 접근 = `O(N)`
> 찾으러 가는것에 한세월...
    + 2) 임의 위치에 있는 원소를 변경 = `O(1)`
> 변경은 빠름.
    + 3) 원소를 끝에 추가 = `O(1)`
> 끝에 있는 것 추가라 
    + 4) 마지막 원소 제거 = `O(1)`
> 끝에 있는 건 빠르지
    + 5) 임의 위치에 원소 추가 = `O(n)`
    + 6) 임의 위치에 원소 제거 = `O(n)`
  + 이중 원형 (Doubly Circular) 연결리스트를 기반으로 기능 구현
    + 1) 임의 위치에 원소 추가: `insertAt(...)`
    + 2) 임의 위치의 원소 제거: `removeAt(...)`
+ 연결리스트 관련 문제를 Leetcode에서 풀고 github에 공유한다.
+ 파트너 조원의 코드를 리뷰한다.
+ 본인의 피드백을 확인하고 수정하여 github에 올린다.

 

'몰라그거무서운거 > 알고모르고' 카테고리의 다른 글

Rust 해볼까.. RustRover  (1) 2024.03.10
week 1 과제  (0) 2021.05.15
시, 공간 복잡도  (0) 2021.05.10

과제 README.MD https://github.com/devouring-algorithm-ds/algorithm-study-s2/tree/s2/week1/week1

 

devouring-algorithm-ds/algorithm-study-s2

기초 자료구조와 알고리즘 씹어먹기. Contribute to devouring-algorithm-ds/algorithm-study-s2 development by creating an account on GitHub.

github.com

### 개인
+ 배열의 내용을 공부하고 정리한다. 
  + 배열의 정의와 성질
    + 1) 임의 위치에 있는 원소에 접근 = `O(1)`
    + 2) 임의 위치에 있는 원소를 변경 = `O(1)`
    + 3) 원소를 끝에 추가 = `O(1)`
    + 4) 마지막 원소 제거 = `O(1)`
    + 5) 임의 위치에 원소 추가 = `O(n)`
    + 6) 임의 위치에 원소 제거 = `O(n)`
  + 기능 구현
    + 1) 임의 위치에 원소 추가: `insertAt(...)`
    + 2) 임의 위치의 원소 제거: `removeAt(...)`

// 샘플 배열
const arr = [1, 2, 3, 4, 5]

const insertAt = function (targetArray, value, index) {
    // 입력할 배열, 입력할 내용, 입력할 인덱스 위치
    console.log('짱짱센,,, 인설트엣 친구를 동작합니다...')
    let preArr = []; // 앞 배열
    let postArr = []; // 뒷 배열 
    
    for (let i=0; i < targetArray.length; i++) { // 슬라이스 못쓰니까 열심히 잘라보자. O(n)
        index > i ? 
        preArr[i] = targetArray[i]
        : postArr[i] = targetArray[i] // 가독성 말아먹고
    }    
    // preArr.length; // 앞 배열의 길이가 나올것이다. 끝에다 추가한다. O(1)
    preArr[preArr.length] = value;
    
    
    const loofFunc = function (weight = 0) {
        for (let j=0; j < postArr.length + weight; j++) { // O(n)
            if (postArr[j + index] !== undefined) {
                preArr[j + index + 1] = postArr[j + index]
            }
        }
    }
    // index 0 용
    if (index === 0) {
        loofFunc();
        return preArr;
    } else if(index <= 0) {
        console.error('index에 음수넣지말자..')
        return []
    } else {
        // 리턴용 새 배열
        loofFunc(1);
        return preArr;
    }
    
}

// 삭제할 배열, 삭제할 인덱스 아까랑 비슷하겠지....
const removeAt = function (targetArray, removeIndex) {
    console.log('나약한 .. 리무브엣을 동작합니다..')
    // 리턴내용 그것이 삭제된 새 배열
    let preArr = []; // 앞 배열
    let postArr = []; // 뒷 배열 
    
    for (let i=0; i < targetArray.length; i++) { // 슬라이스 못쓰니까 열심히 잘라보자. O(n)
        // filter 안쓰고 하려니까 매우 어렵구나...
        if (removeIndex > i) {
            preArr[i] = targetArray[i]
        }
        else if (removeIndex < i) {
            postArr[i] = targetArray[i]
        }
    }
    
    for (let point = removeIndex; point < postArr.length; point++) {
        preArr[point] = postArr[point + 1]
    }
    preArr.length = preArr.length - 1

    return preArr;
}

const insertArr = insertAt(arr, 8, 4);
const removeArr = removeAt(arr, 0);
console.log('=======0ㅅ0======\n', insertArr, removeArr);

?

 

'몰라그거무서운거 > 알고모르고' 카테고리의 다른 글

Rust 해볼까.. RustRover  (1) 2024.03.10
week2 과제  (1) 2021.05.23
시, 공간 복잡도  (0) 2021.05.10

- 시간복잡도

얼마나 빨리 끝나느냐 - 작업을 위해서 책상에 판 벌려서 작업을 끝내는 시간

빅O 표기법으로 나타냄.

조용한 대회장에서 사람섞어놓고 샤우팅해서 이름 불러서 찾으면 O(1)

대회장에서 순차적으로 누가 누군지 물어서 찾으면 O(N), 즉시 찾으면 O(1)

대회장에서 가나다 순으로 쭉 서있으면 O(log N)

 

- 공간복잡도

얼마나 메모리를 많이 먹느냐 - 작업을 위해 책상에 판 벌리는데 얼마나 큰 책상님이 필요한가.

책상에도 가로 세로가 있듯 공간에도 고정공간과 가변공간이 있음.

* 메모리 제한이 512MB일 때 int 변수를 대략 1.2억개 정도 선언할 수 있다 정도 이해하면 된다고

ref - blog.encrypted.gg/922

'몰라그거무서운거 > 알고모르고' 카테고리의 다른 글

Rust 해볼까.. RustRover  (1) 2024.03.10
week2 과제  (1) 2021.05.23
week 1 과제  (0) 2021.05.15

설치 후 지웠는데 ...

mac 에서 midi 오디오 입력에 표시되어서 마이크보다 먼저 잡히게되는 문제가 있었음.

// sudo kextunload /Library/Extensions/PRISM\ Live\ Studio\ SoundDriver.kext

어??? .... 재부팅하니까 다시 살아나네 ㅠㅠㅠㅠㅠ

1. Utility > terminal에서 해당 명령어를 복사하고 다시 한 번 삭제 작업을 진행합니다.
명령: 

sudo kextunload /Library/Extensions/PRISM\ Live\ Studio\ SoundDriver.kext



2. 명령어 입력하여 삭제 후 Finder에서 

/Library/Extensions/PRISM\ Live\ Studio\ SoundDriver.kext
목록을 찾아서 삭제합니다.

고마워요 고객센터

쿠베를 공부 하다보니, 오픈위스크라는 친구에 대해 듣게되었다. 유명한 아파치 프로젝트!
간단하게 말하자면 문제가 발생했을 때, 콜백이벤트를 실행해주기 좋은 서버리스 아키텍쳐이다.

github.com/apache/openwhisk/

 

apache/openwhisk

Apache OpenWhisk is an open source serverless cloud platform - apache/openwhisk

github.com

 

개인적으로 볼 때는 단순하게 함수단위로 iot에서 대문열기, 간단하게 디비 레코드 변경, IoT 센서등 조작 등등 작은이벤트 용으로 쓰면 아주 좋을 것 같고, 이것저것 연결해서 복잡하게 만들면 헬게이트를 맛볼 것으로 추정된다.

MSA에 더 MAS한 맛이라 가능하면 테스트 코드가 없어도 될 진짜 작은 사이즈의 작업을 할 때 써보자.

어... 집에 대문에 열렸을 때, 누가 문을 조작했나 하고 센서를 달아 놓았다면

notify-api.line.me/

 

LINE Notify

LINE Notify allows you to send web notifications from GitHub, IFTTT, Mackerel, and more directly to your LINE chats.

notify-bot.line.me

라인으로 간단하게 CURL로 쏜다던가. 하는걸 만들면 되겠다.

누가 또 그럼

docs.aws.amazon.com/ko_kr/lambda/latest/dg/welcome.html

 

AWS Lambda란 무엇입니까? - AWS Lambda

AWS Lambda란 무엇입니까? AWS Lambda는 서버를 프로비저닝하거나 관리하지 않고도 코드를 실행할 수 있게 해주는 컴퓨팅 서비스입니다. Lambda는 필요 시에만 코드를 실행하며, 하루에 몇 개의 요청에

docs.aws.amazon.com

얘랑 어떤게 나은가 할텐데

ㅋㅋㅋ 난 모르겠다.

아래 글 참고할 것

stackshare.io/stackups/apache-openwhisk-vs-aws-lambda-vs-serverless#posts

 

Apache OpenWhisk vs AWS Lambda vs Serverless | What are the differences?

Apache OpenWhisk - The best open-source serverless cloud platform, enterprise ready and accessible to all developers.. AWS Lambda - Automatically run code in response to modifications to objects in Amazon S3 buckets, messages in Kinesis streams, or updates

stackshare.io

끝.

학습 중.

  •  
  • 호스트 - 컨테이너
  • 도커허브
  • 노드
  • 네임
  • 이미지
  • 클러스터 네크워크
  • 컨트롤러
    • 디플로이먼트
    • 스테이트풀셋
    • 잡 / 크론잡
    • 데몬셋
    • 레플리카셋
    • 레플리카컨트롤러
  • 리포티터리
    • 이미지
  • 디플로이먼트
    • 레플리카셋 
      • 스케일
    • 컨트롤러
    • HA구성
  •  팟
    • 매니페스트
    • 헬스체크 
    • 컨테이너
    • 초기화
    • 사이드카
    • 워크로더
    • 팟-컨테이너
    • 크론잡
  • 서비스 
    • 클러스터
    • 노드
    • 로드벨런서
    • 익스터널네임
  • 스토리지
    • 퍼시스턴트볼륨
    • 프로비저너 - 공간관리
  • 잉그레스
    • 세션어피니티
  • 큐베-킵얼라이브-빕(버추얼아이피)
    • 킵얼라이브
  • 오토스케일
    • HPA설정
    • 부하테스트
  • 클러스터 가상화
    • 네임스페이스
    • 시크릿 - 밑에거 고급진거
    • 컨피그맵 - 어 그 설정파일 이미지에 말아 넣으면 맨날 배포해야하니 빼두는거
  • 메모리관리
  • 시피유관리
  • 인증서관리

서브라임으로 탭으로 신나게 작성했더니

어머, 탭은 안되네 스페이스로 바꾸고나서 실행되었다.

그리고 detach 넣으려고 봤는데 그냥 실행할 때 up뒤에 붙여주자....

docker-compose up -d

끝.

'몰라그거무서운거 > 기타등등' 카테고리의 다른 글

OpenWhisk  (0) 2021.04.29
쿠베 메모  (0) 2021.04.26
hive 에서 create table 등이 안될 때...  (0) 2021.04.02
java 추가 설치중 에러가...  (0) 2021.02.24
sqoop 메모.  (0) 2018.07.19

SET hive.mapred.mode=nonstrict;

성능에 영향을 주는 msck repair table 을 할 때 썼다 ㅠㅠ

'몰라그거무서운거 > 기타등등' 카테고리의 다른 글

쿠베 메모  (0) 2021.04.26
Docker compose yml 작성시..  (0) 2021.04.12
java 추가 설치중 에러가...  (0) 2021.02.24
sqoop 메모.  (0) 2018.07.19
airflow 메모 - 코드조각  (0) 2017.12.07

brew가 업데이트 되었구나.

❯ brew cask install adoptopenjdk11
Error: Unknown command: --cask

❯ brew install --cask adoptopenjdk11
==> Downloading https://github.com/AdoptOpenJDK/openjdk11

 

'몰라그거무서운거 > 기타등등' 카테고리의 다른 글

쿠베 메모  (0) 2021.04.26
Docker compose yml 작성시..  (0) 2021.04.12
hive 에서 create table 등이 안될 때...  (0) 2021.04.02
sqoop 메모.  (0) 2018.07.19
airflow 메모 - 코드조각  (0) 2017.12.07

ES 쓰다보면

max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]

 

같은걸 겪기도 한다. 옛날옛적에 메모장에 메모해둔게 있어서 카톡방에 공유하면서 정리.

 

sudo -s su - 

(login root) swapoff -a 

마스터노드랑 데이터노드는 다 껐다. ingest랑 coordi는 vm이라 필요없어서 안함.

 

sudo /sbin/sysctl -w fs.file-max=655360

sudo /sbin/sysctl -w vm.max_map_count=262144

sudo /sbin/sysctl -w vm.overcommit_memory=1

sudo /sbin/sysctl -w vm.overcommit_ratio=100

sudo /sbin/sysctl -w net.core.somaxconn=65535

sudo /sbin/sysctl -w net.core.netdev_max_backlog=262144

 

이건 www로 실행이 불가능하니, 직접 서버에 들어가, 슈퍼유저 권한으로 설정한다.
그 뭐야 서버 리부팅이나 점검다녀오면 시, 위 사항 + ulimit -a 까지 풀리는 경우가 있음.

 

그래서 뭐 어쩌겠어 점검다녀와도 유지되게 해야지.

재부팅해도 사라지지 않는 설정값 설정은 대충 /etc/sysctl.d/ 로 이동해서
파일하나 아래처럼 만들고

vim 100-elasticsearch.conf

fs.file-max=655360
vm.max_map_count=262144
vm.overcommit_memory=1
vm.overcommit_ratio=100
net.core.somaxconn=65535
net.core.netdev_max_backlog=262144

sysctl -p /etc/sysctl.d/100-elasticsearch.conf

재부팅해도 사라지지 않는 스왑오프는

/etc/fstab 에서 swap 파티션 주석처리를 해뒀땅.

 

// 메인터넌스 종료 후 평소에
PUT _cluster/settings
{
  "persistent": {
    "cluster.routing.allocation.exclude._ip": ""
  },
  "transient": {
    "cluster.routing.allocation.exclude._ip": ""
  }
}

// 보내야할 떄
PUT _cluster/settings
{
  "persistent": {
    "cluster.routing.allocation.exclude._ip": "192.168.xxx.xxx"
  },
  "transient": {
    "cluster.routing.allocation.exclude._ip": "192.168.xxx.xxx,192.168.xxx.xxx"
  }
}

보통 온프로미스 환경에서 해당 노드의 하드디스크나 메모리나 맛이가거나 ^ㅁ^
IDC에 특정 랙에 있는 노드가 죽어버렸을 때, 다른 샤드에 이전 복제나 신규 인덱스의 샤드가 생성되는것을 방지 하기 위해 씀.
transient는 노드 재부팅되면 사라지는 일회성 persistent는 영속성이 있는데, 둘다 써주는게 안전빵.

_ip 말고 name 도되고 group도 되는걸로 알고는 있음.

1.4.7 / 1.99 있음. 서로 비호환 (완전 다르더라 ;;;;;;;;;;)


폴더만듬. mkdir sqoop


다운

wget http://mirror.navercorp.com/apache/sqoop/1.4.7/sqoop-1.4.7.bin__hadoop-2.6.0.tar.gz


해제

tar xzf sqoop-1.4.7.bin__hadoop-2.6.0.tar.gz


환경변수 등록 (.bashrc)

export SQOOP_HOME=/어딘가 위치/sqoop

export PATH=$PATH:$SQOOP_HOME/bin


...

source .bashrc


테스트.

sqoop test


---- 스쿱 준비 완료.


mysql 준비.


db 생성. CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;


형식에 맞게 테이블만들고.


... 날렸는데 안됨.

jdbc dirver가 라이센스 때문에 sqoop에 없나봄.


wget http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.28.tar.gz

받아서 속에 jar 만 sqoop/lib 폴더에 넣기.


..실행.

sqoop export --connect jdbc:mysql://서버:포트/디비명 --username 유저 --password 비번 --table 테이블명 --num-mappers 1 --export-dir /data/데이타

했는데

에러!! sqoop  Transferred 0 bytes 데이터 전송 안됨...!



=ㅅ= 아........ .... 리얼 클러스터랑 베타 DB랑 전송 막혔다. ACL로 클러스터 다 열어야 하는데 못해이거. 


경험했다.



'몰라그거무서운거 > 기타등등' 카테고리의 다른 글

쿠베 메모  (0) 2021.04.26
Docker compose yml 작성시..  (0) 2021.04.12
hive 에서 create table 등이 안될 때...  (0) 2021.04.02
java 추가 설치중 에러가...  (0) 2021.02.24
airflow 메모 - 코드조각  (0) 2017.12.07

RDD - Resilient Distributed Datasets 분산 이뮤터블 자바 객체


http://12bme.tistory.com/306

'몰라그거무서운거 > scala or spark' 카테고리의 다른 글

scala memo  (0) 2018.07.10
  • 값에 타입 선언 이후 변경불가.
  • 문자열보간모드 println(s"문자 $변수출력시앞에 s") / printf 도 있ㅇ넹.
  • && || 비교는 lazy비교... js와 다름... 주의.
  • ? : 일단 삼함 안보임. if (조건) 결과A else 결과B 로 대체가능.
  • 셀렉트 케이스 같은 스위치 케이스 없음. 매치표현식으로.
  • _ 와일드카드 ... 이거뭐야... match case 이외의 케이스를 표현.
  • 숫자 .abs, .min, .max
  • 문자 .reverse .captialize, .toInt
  • def Fu() { } 속에 return 안적어도 마지막ㅇㅣ 리ㄴㅌ됨ㅓ
  • ++나 --는 제공하지 않으므로 += 1을 사용해야 합니다 //////.......... -_-

  • 중첩 for 대신, 조건식 중첩으로 가능.
  • 아래는 메모.
  • scala> b

    res5: List[Any] = List(a, 1, true)


    scala> a

    res6: (String, Int) = (솔라,112123)

  • 테스트
  • 접근 (0) ._1
  • 리턴없는 프로시저


'몰라그거무서운거 > scala or spark' 카테고리의 다른 글

spark  (0) 2018.07.17

빨리 진도 빼야하는데... -_-;


아무튼 배치처리 ...


살펴보니 용도는 대충 배치(일괄) 처리 이후, 그 결과 데이터를 벌크로 올리는 것 같고, 수정이나 삭제도 할 수 있나보다.


  1. 앞에서 다 삭제했지만, 벌크를 써서 만들어 넣어보자.

    ~]$ curl -X POST "localhost:9200/customer/_doc/_bulk?pretty" -H 'Content-Type: application/json' -d'

    > {"index":{"_id":"1"}}

    > {"name": "John Doe1111" }

    > {"index":{"_id":"2"}}

    > {"name": "Jane Doe2222" }

    > '

    {

      "took" : 11,

      "errors" : false,

      "items" : [

        {

          "index" : {

            "_index" : "customer",

            "_type" : "_doc",

            "_id" : "1",

            "_version" : 2,

            "result" : "updated",

            "_shards" : {

              "total" : 2,

              "successful" : 1,

              "failed" : 0

            },

            "_seq_no" : 18,

            "_primary_term" : 2,

            "status" : 200

          }

        },

        {

          "index" : {

            "_index" : "customer",

            "_type" : "_doc",

            "_id" : "2",

            "_version" : 2,

            "result" : "updated",

            "_shards" : {

              "total" : 2,

              "successful" : 1,

              "failed" : 0

            },

            "_seq_no" : 4,

            "_primary_term" : 2,

            "status" : 200

          }

        }

      ]

    }


    똑같은 패턴이다.
    잘 들어갔는지 보려면 조회.

    ~]$ curl -X GET "localhost:9200/customer/_doc/1?pretty"

    {

      "_index" : "customer",

      "_type" : "_doc",

      "_id" : "1",

      "_version" : 2,

      "found" : true,

      "_source" : {

        "name" : "John Doe1111"

      }

    }


    1번

    ~]$ curl -X GET "localhost:9200/customer/_doc/2?pretty"

    {

      "_index" : "customer",

      "_type" : "_doc",

      "_id" : "2",

      "_version" : 2,

      "found" : true,

      "_source" : {

        "name" : "Jane Doe2222"

      }

    }


    얜 2번.

    잘 들어간듯. 


  2. 대량 수정 삭제.

    ~]$ curl -X POST "localhost:9200/customer/_doc/_bulk?pretty" -H 'Content-Type: application/json' -d'

    > {"update":{"_id":"1"}}

    > {"doc": { "name": "John Doe becomes Jane Doe" } }

    > {"delete":{"_id":"2"}}

    > '

    {

      "took" : 23,

      "errors" : false,

      "items" : [

        {

          "update" : {

            "_index" : "customer",

            "_type" : "_doc",

            "_id" : "1",

            "_version" : 3,

            "result" : "updated",

            "_shards" : {

              "total" : 2,

              "successful" : 1,

              "failed" : 0

            },

            "_seq_no" : 19,

            "_primary_term" : 2,

            "status" : 200

          }

        },

        {

          "delete" : {

            "_index" : "customer",

            "_type" : "_doc",

            "_id" : "2",

            "_version" : 3,

            "result" : "deleted",

            "_shards" : {

              "total" : 2,

              "successful" : 1,

              "failed" : 0

            },

            "_seq_no" : 5,

            "_primary_term" : 2,

            "status" : 200

          }

        }

      ]

    }


    한번에 1은 수정 2는 삭제.

    후, 200이 떨어졌으니..... 

    조회.

    ~]$ curl -X GET "localhost:9200/customer/_doc/1?pretty"

    {

      "_index" : "customer",

      "_type" : "_doc",

      "_id" : "1",

      "_version" : 3,

      "found" : true,

      "_source" : {

        "name" : "John Doe becomes Jane Doe"

      }

    }

    [ㅇㅣ름이름@서버서버명 ~]$ curl -X GET "localhost:9200/customer/_doc/2?pretty"

    {

      "_index" : "customer",

      "_type" : "_doc",

      "_id" : "2",

      "found" : false

    }


    오케이 확인 끝.
    꼴랑 id 만으로 삭제함.


  3. 벌크는 중간 처리 내용이 실패한다고 하더라도... 중단하지 않는다. 라고해서 해봄.

    ~]$ curl -X POST "localhost:9200/customer/_doc/_bulk?pretty" -H 'Content-Type: application/json' -d'

    > {"update":{"_id":"2"}}

    > {"doc": { "name": "John Doe becomes Jane Doe" } }

    > {"update":{"_id":"1"}}

    > {"doc": { "name": "John Doe becomes Jane Doe122434" } }

    > 

    > '

    {

      "took" : 75,

      "errors" : true,

      "items" : [

        {

          "update" : {

            "_index" : "customer",

            "_type" : "_doc",

            "_id" : "2",

            "status" : 404,

            "error" : {

              "type" : "document_missing_exception",

              "reason" : "[_doc][2]: document missing",

              "index_uuid" : "4clf5AwmTQ-hruQl7EGJSg",

              "shard" : "2",

              "index" : "customer"

            }

          }

        },

        {

          "update" : {

            "_index" : "customer",

            "_type" : "_doc",

            "_id" : "1",

            "_version" : 4,

            "result" : "updated",

            "_shards" : {

              "total" : 2,

              "successful" : 1,

              "failed" : 0

            },

            "_seq_no" : 20,

            "_primary_term" : 2,

            "status" : 200

          }

        }

      ]

    }


    2번을 고치고 1번을 고치도록 했는데, 음... 그렇다.

    ~]$ curl -X GET "localhost:9200/customer/_doc/1?pretty"

    {

      "_index" : "customer",

      "_type" : "_doc",

      "_id" : "1",

      "_version" : 4,

      "found" : true,

      "_source" : {

        "name" : "John Doe becomes Jane Doe122434"

      }

    }


    1 잘 고쳐짐.


    일단 여기까지.


이전 메모에는 클러스터(싱글) 헬스체크하고, 인덱스 만들어서 조회하고, 삭제하는걸 해봤는데... 정말 이걸로 끝인가(?) 흠터레스팅 하다.


bin의 .el~서치 실행해주자. -> 터미널 나갔더니 꺼져있더라. (systemd 로 나중에 등록하던가 하자.)


:thinking_face: 인덱스는 약간 RDB 테이블 같은 녀석.



  1. 약간 오버라이트 같은 데이터 수정을 해볼 것.
    앞에서 delete로 인덱스를 날렸으니 조회하면 404가 나올거다., 일단 데이터 한번 넣어서 확인 한번 해보자.

    ~]$ curl -X GET "localhost:9200/customer/_doc/1?pretty"

    {

      "error" : {

        "root_cause" : [

          {

            "type" : "index_not_found_exception",

            "reason" : "no such index",

            "resource.type" : "index_expression",

            "resource.id" : "customer",

            "index_uuid" : "_na_",

            "index" : "customer"

          }

        ],

        "type" : "index_not_found_exception",

        "reason" : "no such index",

        "resource.type" : "index_expression",

        "resource.id" : "customer",

        "index_uuid" : "_na_",

        "index" : "customer"

      },

      "status" : 404

    }


    이렇게 404...

    ~]$ curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d'

    {

      "name": "John Doe"

    }


    넣어주고.

    확인해보자.

    ~]$ curl -X GET "localhost:9200/customer/_doc/1?pretty"

    {

      "_index" : "customer",

      "_type" : "_doc",

      "_id" : "1",

      "_version" : 1,

      "found" : true,

      "_source" : {

        "name" : "John Doe"

      }

    }


    음.... name 를 잘 보자. 수정은... 다음 과 같이.

    ~]$ curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d'

    > {

    >   "name": "Joooooooooooooooon Duck"

    > }

    > '


    res

    {

      "_index" : "customer",

      "_type" : "_doc",

      "_id" : "1",

      "_version" : 2,

      "result" : "updated",

      "_shards" : {

        "total" : 2,

        "successful" : 1,

        "failed" : 0

      },

      "_seq_no" : 1,

      "_primary_term" : 1

    }



    조회 하면.

    ~]$ curl -X GET "localhost:9200/customer/_doc/1?pretty"

    {

      "_index" : "customer",

      "_type" : "_doc",

      "_id" : "1",

      "_version" : 2,

      "found" : true,

      "_source" : {

        "name" : "Joooooooooooooooon Duck"

      }

    }


    존덕....으로 덮어써진 것 같다. 다른점은 version 2 가 된점.

    인덱스에 새로운 아이디(2번) 추가해보자.

    ~]$ curl -X PUT "localhost:9200/customer/_doc/2?pretty" -H 'Content-Type: application/json' -d'

    > {

    >   "name": "Jane Doe"

    > }

    > '


    {

      "_index" : "customer",

      "_type" : "_doc",

      "_id" : "2",

      "_version" : 1,

      "result" : "created",

      "_shards" : {

        "total" : 2,

        "successful" : 1,

        "failed" : 0

      },

      "_seq_no" : 0,

      "_primary_term" : 1

    }


    얼추 드간거 같으니까. 1번 이랑 2번 한번 조회해보자. 

     ~]$ curl -X GET "localhost:9200/customer/_doc/1?pretty"

    {

      "_index" : "customer",

      "_type" : "_doc",

      "_id" : "1",

      "_version" : 2,

      "found" : true,

      "_source" : {

        "name" : "Joooooooooooooooon Duck"

      }

    }

    내계정명@내서버명 ~]$ curl -X GET "localhost:9200/customer/_doc/2?pretty"

    {

      "_index" : "customer",

      "_type" : "_doc",

      "_id" : "2",

      "_version" : 1,

      "found" : true,

      "_source" : {

        "name" : "Jane Doe"

      }

    }


    1,2 볼 수 있음.

    1,2 지정해서 만들었는데, 미지정하면 알아서 autoincrement 하는 .... 것 같진 않고  지정하지 않으면 Elasticsearch에서 임의 ID를 생성하여 문서 색인화에 사용합니다. 라고 함.


    그래서 미명시 put 도 해보려고...

    앞에서 메모 한 <REST Verb> /<Index>/<Type>/<ID> 법칙엔 조금 벗어남. 


     ~]$ curl -X PUT "localhost:9200/customer/_doc/pretty" -H 'Content-Type: application/json' -d'

    {

      "name": "Jane Dodsfsfsdfsdfsdfe"

    }

    '

    {"_index":"customer","_type":"_doc","_id":"pretty","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}


    json pretty 가 사라졌다... 아무튼 들어간거 같음.

    조회해보면

    ~]$ curl -X GET "localhost:9200/customer/_doc/pretty"

    {"_index":"customer","_type":"_doc","_id":"pretty","_version":1,"found":true,"_source":

    {

      "name": "Jane Dodsfsfsdfsdfsdfe"

    }


    이런식으로 들어 감.

    근데 이건 잘못사용한 예의 하나일 듯. (그래서 json이 이쁘게 안나온건가?)

    put의 경우 id를 명시해 주는 경우에만 사용해야하는데, 지금 res를 잘 보면 id가 pretty 가 되었음.

    가이드에 있는대로 써보면.

    미 명시의 경우 POST를 사용한다. (id자동생성)

     ~]$ curl -X POST "localhost:9200/customer/_doc?pretty" -H 'Content-Type: application/json' -d'

    {

      "name": "Jane Doe12323456784567890"

    }
    '


    라고 날리면, res로 

    {

      "_index" : "customer",

      "_type" : "_doc",

      "_id" : "YrQSWmQBU_p42XDzzCOy",

      "_version" : 1,

      "result" : "created",

      "_shards" : {

        "total" : 2,

        "successful" : 1,

        "failed" : 0

      },

      "_seq_no" : 2,

      "_primary_term" : 1

    }


    id가 자동 생성되었다.

    아하. 그렇구나... id 지정 put , 자동지정 post..

     

  2. 정말로 수정해보자.

    update 명령어를 쓸 건데.........인덱스의 1번 id내용을 고치려고 한다.

    ~]$ curl -X POST "localhost:9200/customer/_doc/1/_update?pretty" -H 'Content-Type: application/json' -d'

    {

      "doc": { "name": "Jane Doe" }

    }

    '

    {

      "_index" : "customer",

      "_type" : "_doc",

      "_id" : "1",

      "_version" : 3,

      "result" : "updated",

      "_shards" : {

        "total" : 2,

        "successful" : 1,

        "failed" : 0

      },

      "_seq_no" : 3,

      "_primary_term" : 2

    }


    라고 나왔는데, ........... 어.... 버전이 2에서 3이된거보면 업데이트 된 것 같긴하고.

    한번 더 다른거 예제에 있는 내용 넣어 봤다. 나이가 추가되었네.

    ~]$ curl -X POST "localhost:9200/customer/_doc/1/_update?pretty" -H 'Content-Type: application/json' -d'

    > {

    >   "doc": { "name": "Jane Doe", "age": 20 }

    > }

    > '

    {

      "_index" : "customer",

      "_type" : "_doc",

      "_id" : "1",

      "_version" : 4,

      "result" : "updated",

      "_shards" : {

        "total" : 2,

        "successful" : 1,

        "failed" : 0

      },

      "_seq_no" : 4,

      "_primary_term" : 2

    }


    버전4.


    이러고 조회 한번 해보면

    ~]$ curl -X GET "localhost:9200/customer/_doc/1?pretty"

    {

      "_index" : "customer",

      "_type" : "_doc",

      "_id" : "1",

      "_version" : 4,

      "found" : true,

      "_source" : {

        "name" : "Jane Doe",

        "age" : 20

      }

    }


    바뀐게 보인다.

  3. 스크립트 사용해서 변경

    나이가 숫자인데, 스크립트로 증감할 수 있나보다.

    ~]$ curl -X POST "localhost:9200/customer/_doc/1/_update?pretty" -H 'Content-Type: application/json' -d'

    > {

    >   "script" : "ctx._source.age += 5"

    > }

    > '

    {

      "_index" : "customer",

      "_type" : "_doc",

      "_id" : "1",

      "_version" : 5,

      "result" : "updated",

      "_shards" : {

        "total" : 2,

        "successful" : 1,

        "failed" : 0

      },

      "_seq_no" : 5,

      "_primary_term" : 2

    }


    버전이 또 올랐네.

    데이터를 조회해봄.

     ~]$ curl -X GET "localhost:9200/customer/_doc/1?pretty"

    {

      "_index" : "customer",

      "_type" : "_doc",

      "_id" : "1",

      "_version" : 5,

      "found" : true,

      "_source" : {

        "name" : "Jane Doe",

        "age" : 25

      }

    }



    ... 이 방식은 1ID 도큐먼트 만 증감시켜 줬느데, 

    6.3은 query로 다중 업데이트 증가가 가능하다.

    문서는 docs-update-by-query API

    이곳을 참고하면 될 것 같다. 음.. 예제 이름이 kimchy인데, https://twitter.com/kimchy 김치형님과 관련이 있나보다.

    .... 일단 나중에 보자.

  4. 문서(doc) 삭제 방법.

    ~]$ curl -X DELETE "localhost:9200/customer/_doc/1?pretty"

    {

      "_index" : "customer",

      "_type" : "_doc",

      "_id" : "1",

      "_version" : 6,

      "result" : "deleted",

      "_shards" : {

        "total" : 2,

        "successful" : 1,

        "failed" : 0

      },

      "_seq_no" : 6,

      "_primary_term" : 2

    }


    조회해보니 삭제가 되어 안보이는 것 같다.

    ~]$ curl -X GET "localhost:9200/customer/_doc/1?pretty"

    {

      "_index" : "customer",

      "_type" : "_doc",

      "_id" : "1",

      "found" : false

    }


    없다.


    일단 일도 해야하니 ㅠㅠㅠㅠㅠㅠㅠㅠㅠ 여기까지 해두고... 다음은 배치처리인가.

ref. https://www.elastic.co/guide/en/elasticsearch/reference/current/_batch_processing.html

ref. https://www.elastic.co/guide/kr/elasticsearch/reference/current/gs-modifying-data.html

... ES 해야함.


참고문서 두개 번갈아가면서 봄.


한글 5.4 https://www.elastic.co/guide/kr/elasticsearch/reference/current/gs-installation.html

영문 6.3 https://www.elastic.co/guide/en/elasticsearch/reference/current/_installation.html



  1. 서버 하나 vm으로 받음. (다음번엔 여러대 클러스터 작업엔 엔씨블로...)

  2. 1.8 깔려있다. 감사합니다. 근데 java_home이 없음. 
    vi ~/.bash_profile  에다가 등록함.

  3. es tar 다운

    curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.0.tar.gz


  4.   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                     Dload  Upload   Total   Spent    Left  Speed

     29 87.1M   29 25.4M    0     0   318k      0  0:04:40  0:01:21  0:03:19  378k


    용량이 좀 있네..

  5. 압축 풀고.
    tar -xvf elasticsearch-6.3.0.tar.gz


  6. cd elasticsearch-6.3.0/bin

    디렉토리 이동.

  7. bin]$ ./elasticsearch


    노드랑 싱글 클러스터 실행 가능하다고 함.

  8. OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N


    시작부터 이런게 뜨네 ..... 알아서 구성 해줄것이지..ㅠㅠ


    나머지 맥은 홈브류로, 윈도우는 인스톨러가 있는듯. 안중요하니 넘김.


  9. ./elasticsearch -Ecluster.name=my_cluster_name -Enode.name=my_node_name 



    실행 시 클러스터 이름, 노드 이름 지정가능.

  10. 음... 9200번 포트를 사용해서 rest API를 제공하나봄.(퍼블리쉬_어드레스) ... 9300 번은 뭔지 ? (바운스 어드레스)
    일단 넘어감.

  11. REST API 로 거의 모든것을 할 수 있는거 같은 느낌을 줬음.
    클러스터, 노드, 헬스체크, CURD 뭐 여러가지 등등... 고급작업까지 라고 적혀있음.

  12. 외부에서(맥북) 해당서버 ip로 curl 날리니 안되고... 흠...? 다른사람들도 이런가.

    설치 된 서버 내부에서 localhost 콘솔로 날려봄.

    ~]$ curl -X GET "localhost:9200/_cat/health?v"

    epoch      timestamp cluster       status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent

    1529253972 01:46:12  elasticsearch green           1         1      0   0    0    0        0             0                  -                100.0%



    그 외에도 키바나 콘솔에서 다음 api를 날릴 수 있다고함.
    ... 그냥도 날릴 수 있었음. 언젠가 키바ㄴㅏ 사용법을 다음엔 알아봐야겠다. elk니까...

    일단 정상이라 그린임.

    노랑은 모든 데이터 사용가능하지만 일부 리플리카가 미배정된 상태.
    레드는 비정상. 부분동작.

  13.  ~]$ curl -X GET "localhost:9200/_cat/nodes?v"

    ip        heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name

    127.0.0.1            9          93   4    0.00    0.01     0.06 mdi       *      7EmJiq_


    노드목록은 ㅇㅣ렇게 체크 가능한것 같다. ... 짠한 유일노드.

  14. ~]$ curl -X GET "localhost:9200/_cat/indices?v"

    health status index uuid pri rep docs.count docs.deleted store.size pri.store.size


    모든 색인(indices) 나열 이라고 하는데. 없ㄷㅏ.

  15. 색인 ...  index 생성. 'customer' 라는걸 만들고 색인을 나열한다고...

    curl -X PUT "localhost:9200/customer?pretty"

     ~]$ curl -X PUT "localhost:9200/customer?pretty"

    {

      "acknowledged" : true,

      "shards_acknowledged" : true,

      "index" : "customer"

    }


    curl -X GET "localhost:9200/_cat/indices?v"


     ~]$ curl -X GET "localhost:9200/_cat/indices?v"

    health status index    uuid                   pri rep docs.count docs.deleted store.size pri.store.size

    yellow open   customer axCGidU6Qy2D7Eercp5ATw   5   1          0            0       460b           460b


    아... rep가 1이라서 옐로인가봄.
    싱글 노드라서.


  16. 'customer' index 에다가 뭘 집어넣으려고 한다...


    curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d'

    {

      "name": "John Doe"

    }

    '


    유형이 어떤지 알려줘야 한다고... 위에처럼 넣고나면.

    {

      "_index" : "customer",

      "_type" : "_doc",

      "_id" : "1",

      "_version" : 1,

      "result" : "created",

      "_shards" : {

        "total" : 2,

        "successful" : 1,

        "failed" : 0

      },

      "_seq_no" : 0,

      "_primary_term" : 1

    }


    이렇게 응답이 오고.

    내부 id는 1, 타입은 doc... 뭐  등등 정보가 있음.

  17. ~]$ curl -X GET "localhost:9200/customer/_doc/1?pretty"

    {

      "_index" : "customer",

      "_type" : "_doc",

      "_id" : "1",

      "_version" : 1,

      "found" : true,

      "_source" : {

        "name" : "John Doe"

      }

    }



    found 필드? - 찾았다고 알려주는 필드. source 는 앞에 넣은 json 문서네.


  18. 삭제 후 확인

    curl -X DELETE "localhost:9200/customer?pretty"

    ~]$ curl -X DELETE "localhost:9200/customer?pretty"

    {

      "acknowledged" : true

    }

    curl -X GET "localhost:9200/_cat/indices?v"


    ~]$ curl -X GET "localhost:9200/_cat/indices?v"

    health status index uuid pri rep docs.count docs.deleted store.size pri.store.size


    ... 인덱스 날아감.


  19. <REST Verb> /<Index>/<Type>/<ID>


    이런 패턴이 있는걸 익혀두라함.

    일단 여기까지.



airflow Variable, Connections 암호화 하는 법.

airflow.cfg


# Secret key to save connection passwords in the db
fernet_key = cryptography_not_found_storing_passwords_in_plain_text


fernet_key를 저부분에 생성해서 넣으면 됨.


주의1 ::: 이후 한글키나 한글값을 저장하면 다음과 같은 오류가 남.

알아서 코드나 디비를 수정 하길... 바람. 참고주소 https://libsora.so/posts/python-hangul/

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc7 in position 0: ordinal
not in range(128)


주의2 ::: 이전에 만든키는 그냥 일반키이다.


fernet_key 만든는 방법. 

$ pip install cryptography

안깔려 있으니 설치 한다. (  https://cryptography.io/en/latest/installation/  )


$ python -c "from cryptography.fernet import Fernet; FERNET_KEY = Fernet.generate_key().decode(); print FERNET_KEY"


콘솔창에 치면 다음줄에 키값이 떨어질텐데 이걸 위에 넣으면 됨.


..



hook

http://tech.marksblogg.com/airflow-postgres-redis-forex.html




'몰라그거무서운거 > 기타등등' 카테고리의 다른 글

쿠베 메모  (0) 2021.04.26
Docker compose yml 작성시..  (0) 2021.04.12
hive 에서 create table 등이 안될 때...  (0) 2021.04.02
java 추가 설치중 에러가...  (0) 2021.02.24
sqoop 메모.  (0) 2018.07.19

+ Recent posts