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


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

js 하다보면 근 1년사이 너무 많이 뭔가 나온다.

웹팩 친척인가... 대항마인가 라이벌인가 뭔가 모르겠지만. 


parcel - 꾸러미 (파셀? 파스-얼? 파쉘? 파스엘? 파쒀얼??) 라는 새로운 모듈 번들러가 나왔다.







구글번역 최고


공홈 : https://parceljs.org/

git : https://github.com/parcel-bundler/parcel



일단 써보고...판단해야지.


퀵가이드 따라 한 메모.


설치


🤖  parcel-test npm install -g parcel-bundler


parcel-test 폴더 하나 만들었고. 일단 난, npm 쓰니까, 글로벌로 꾸러미 설치하고...


package.json 생성.


🤖  parcel-test npm init -y


기본 셋으로 빠르게 생성.

.. 뭐 모든 종류 파일을 엔트리로 지정할 수 있다는데... php도 되나보네. 근데 js나 html이 좋다고 써져있다.



html 파일, js 파일 생성


간단하게 src에 index.js (콘솔로그정도) 와 index.html 만들고.


그냥 이대로 콘솔창에


🤖  parcel-test parcel index.html

Server running at http://localhost:1234

  Built in 305ms.


라고 입력했더니 뭐 빌드 하고 서버도 띄웠네..


폴더구경



dist 폴더 만든적이 없는데, dist 폴더가 생겼다. 지정해 준 기억도 없다.


js도 같이 들어갔다는 점.




번들된 dist 내부의 index.html을 열어보면(오른쪽) 잘 만들어져있다.


포트변경은 

parcel [목적파일] -p [포트번호]


후기


1. 간단하네. 심플 프로젝트 용으로 괜찮겠다. parcel만 앞에 붙이면 [개발서버+빠른번들링]


2. 버그인ㅈㅣ모르겠는데, python airflow 8080에 띄워놓았는데, parcel로 8080 띄우니까, 에러안나고 꾸러미 우선 올라가더라.

-airflow 미아되어버림.-


이건 좀 더 ㄴㅏ중에 파이선써버와 어떤 관계가 있길래 중복으로 뜨는지 알아봐야지.

꾸러미 끄니까, airflow로 다시 붙음. -_-? 왜???????? 왜일까..


3. watch 옵션 붙이지 않아도 기본적으로 꾸러미 로컬 개발 환경에서는 watch 하고 있다.


별도로 서버를 구축해서 사용하는 경우 watch 옵션을 붙여주면, 꾸러미 내부의 개발서버 띄우지 않고 watch 만 할 수 있었다.


parcel watch [목적파일] // Won't use hot module server.


분명 watch 해놓고 왜 서버 안뜬다고 할 사람 있을 것 같다.


총평


간단하네. 


빠른지는 아무것도 안넣어서 잘 모르겠다...




기타.

✨ Production

When it comes time to bundle your application for production, you can use Parcel's production mode.

parcel build entry.js


프로덕션... 설명... 간단해...



앞으로 찾아야 할 것


1. webpack.config.js 같은 것은 없나?


2. 외부라이브러리 설치 후 모듈 import 도... 진짜? 간단해??


3. [ CSS, other compile-to-CSS languages like LESS, SASS, and Stylus ] 가 들어 있다는데, 상세옵션을?? 어떻게??



빠른 분들 나오자마자 리엑트용 보일러 플레이트를 내어놓았다.

https://github.com/rwieruch/parcel-react


아직 parcel-vue 는 없다. vue-loader .vue 파일이 문제인 듯.


1.0.0 기반으로 작성 됨.


끝.



+ Recent posts