개발

개발

[websocket] (1) python websocket 서버 생성 & 클라이언트 테스트

python websockets 라이브러리를 사용해서 아주 간단한 websocket 서버를 만들어볼 수 있다. [참고문서] https://websockets.readthedocs.io/en/stable/ 1. 서버 생성 import asyncio import time import websockets import datetime import multiprocessing as mp # create handler for each connection if __name__ == "__main__": async def handler(websocket, path): while True: await websocket.send("[*] M1 from SERVER 1 "+str(datetime.datetime.now())..

개발

[ubuntu] mpi4py 설치 시 에러

ubuntu에서 pip install mpi4py로 mpi4py를 설치할 때 다음과 같이 에러메세지가 나는 경우가 있다. .... error: Cannot compile MPI programs. Check your configuration!!! [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for mpi4py Failed to build mpi4py ERROR: Could not build wheels for mpi4py, which is required to install pyproject.toml-based proje..

개발

[ChatGPT가 알려주는] overflow, underflow 파이썬 예시

Overflow and underflow are two concepts that refer to the limits of numerical representation in computing. They can happen in various programming contexts, including in Python, especially when dealing with floating-point numbers or integers that exceed the maximum or minimum size that can be represented. 1. Overflow Overflow occurs when a calculation produces a result that is larger than the max..

개발

[ubuntu] nohup 파일 생성 시 현재 날짜로 생기게 하기

nohup echo "hi" &> nohup$(date --iso).out & 이와 같이 $(date --iso)를 사용하면 현재 날짜를 기준으로 한 로그를 남길 수 있다.

개발

[ubuntu] crontab 사용법 간단정리

1. Cron Job 등록 crontab -e로 job을 등록할 수 있다. # crontab -e 실행 후 아래 line 등록 # 매월 9일 21시 8분에 run.sh 실행 8 21 9 * * /home/user/.../run.sh # weekday(월-금) 매일 18시 0분에 run.sh 실행 0 18 * * 1-5 /home/user/.../run.sh 2. Cron Job 확인 crontab -l을 확인하면 등록한 job 목록을 보여준다. user@user-System-Product-Name:~/$ crontab -l MAILTO="" # Edit this file to introduce tasks to be run by cron. # # Each task to run has to be define..

개발

[ubuntu] 좀비 프로세스 죽이기(defunct)

ps -ef | grep defunct로 좀비 프로세스를 확인해보면 다음과 같이 나온다. 이때 34502가 parant process id인데 얘를 죽여주면 하위 프로세스들도 죽는다. sudo kill -9 34502 ps -ef | grep defunct user 32872 30725 0 14:49 pts/0 00:00:00 grep --color=auto defunct

개발

[python] multiprocessing 사용법

파이썬으로 작업을 하다보면 multiprocessing을 사용할 일이 생기는데, 사용법과 주의할 점을 정리하고자 한다. 1. Multiprocessing 사용하기 1) Process, Queue 기본적인 형태는 Process를 선언하여 새로운 프로세스를 만들 때 실행할 function과 arguement들을 넘겨주는 방식이다. 그리고 Queue를 사용하여 프로세스끼리 데이터를 주고 받을 수 있다. 주의할 점은 새로운 프로세스를 실행할 때 넘겨줄 function과 arguement들은 fork가 가능한 객체들이어야 한다. 대부분은 문제 없지만 GPU 자원을 활용하는 모델이나 threading 기반으로 돌아가는 객체들은 안될 때가 있다. 아래 예제는 consumer & producer 프로세스를 생성한 예시..

개발

[tmux] tmux cheat sheet

세션 시작 tmux new -s mysession 세션 종료 tmux kill-session -t mysession 세션 리스트 tmux ls 세션 접속 tmux attach -t mysession 세션 화면 빠져나오기 ctrl+b 후 d [참고] https://www.redhat.com/sysadmin/introduction-tmux-linux#:~:text=To%20start%20using%20tmux%2C%20type,window%2C%20and%20attaches%20to%20it. https://tmuxcheatsheet.com/

개발

[Docker] Docker 용량 정리

Docker는 시스템 자원을 많이 잡아먹는다. 특히 디스크 용량이 많이 필요한데 이때 필요한 명령어들을 정리하고자 한다. 1. Docker 용량 확인 docker system df >>>> TYPE TOTAL ACTIVE SIZE RECLAIMABLE Images 15 8 273GB 233.9GB (85%) Containers 21 11 393.7GB 127.5GB (32%) Local Volumes 11 6 2.264GB 846.2MB (37%) Build Cache 1 0 0B 0B 2. Docker cache 정리 Docker를 사용하다 보면 필요없는 layer등이 많이 남는다. 이를 정리할 수 있는 방법은 다양하다(참고). # 1) build시 사용된 cache 제거 docker builder p..

개발

[웹개발] (2) Nginx로 Load Balancer + SSL 적용하기

간단한 웹 데모를 개발하면서 겪었던 과정을 정리하고자 한다. 전체적인 구조는 다음과 같으며 Load Balancer(A)와 Web Server(B)는 별도의 서버로 구성하였다. 그리고 SSL 인증서를 도입하고자 한다. SSL 인증서를 발급받아 Nginx에 적용하면 HTTPS로 서비스를 할 수 있다. 환경정보는 다음과 같다. Ubuntu 20.04 Python 3.8 FastAPI 0.100.1 1. 도메인 연결 SSL 인증을 도입하기 위해서는 반드시 도메인이 있어야 한다. 이 블로그를 참고해서 세팅해주자. 2. Let's Encrypt 인증서 설치 Ubuntu에 certbot을 설치하자. sudo apt install certbot sudo apt install python3-certbot-nginx 이..

개발

[웹개발] (1) Nginx로 Load Balancer 적용하기

간단한 웹 데모를 개발하면서 겪었던 과정을 정리하고자 한다. 전체적인 구조는 다음과 같으며 Load Balancer(A)와 Web Server(B)는 별도의 서버로 구성하였다. 환경정보는 다음과 같다. Ubuntu 20.04 Python 3.8 FastAPI 0.100.1 1. Web Server FastAPI로 Frontend, Middleware, Backend를 구현하였고 이 레포를 기반으로 편하게 만들었다. 2. Nginx Nginx는 2004년에 개발된 비동기 이벤트 기반의 경량화된 웹 서버 프로그램이다. 20년된 프로그램이지만 가벼워서 아직도 많이 쓰인다. (1) Nginx 설치 먼저 A서버에 Nginx를 설치하자. sudo apt update sudo apt install nginx 다음으로..

개발

[Miniconda] Ubuntu에 Miniconda 설치하기

1. Miniconda 다운로드 및 설치 # 1. update os sudo apt update # 2. upgrade os sudo apt upgrade # 3. download Miniconda curl https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -o Miniconda3-latest-Linux-x86_64.sh # 4. install Miniconda sudo chmod +x Miniconda3-latest-Linux-x86_64.sh bash Miniconda3-latest-Linux-x86_64.sh # 5. export PATH # export PATH=$PATH:(Miniconda가 설치된 path) export..

개발

Gunicorn & Uvicorn

1. Gunicorn Gunicorn은 production 레벨에서 사용할 수 있는 WSGI(Web Server Gateway Interface)로 고성능, 쉬운 배포가 특징이다. Flask, Django와 같은 프레임워크들을 서빙할 수 있다. 여러 프로세스로 서버를 돌릴 수 있으며 또한 process manager로도 동작하기 때문에 Uvicorn으로 실행된 어플리케이션을 관리할 수 있다. 2. Uvicorn Uvicorn은 ASGI(Asynchronous Server Gateway Interface) 웹 서버로 Starlette을 추상화하여 개발되었다. ASGI이기 때문에 단일 프로세스에서 비동기로 요청을 처리하기 때문에 WSGI에 비해 매우 많은 요청을 처리할 수 있다. [참고] https://te..

개발

[Nginx] 맥os에 Nginx 설치하기

맥북에서 Nginx 설치를 해보고자 한다. 맥OS 버전은 13.0 기준이다. 먼저 brew install nginx로 설치해준다. ==> Fetching nginx ==> Downloading https://ghcr.io/v2/homebrew/core/nginx/manifests/1.25.1_1 ... ==> Installing nginx ==> Pouring nginx--1.25.1_1.arm64_ventura.bottle.tar.gz ==> Caveats Docroot is: /opt/homebrew/var/www The default port has been set in /opt/homebrew/etc/nginx/nginx.conf to 8080 so that nginx can run without..

개발

[Nginx] forward & reverse proxy

Nginx를 사용하기 위해 먼저 proxy server를 이해하고자 한다. 1. Proxy Server 먼저 proxy server는 다음과 같다. A proxy server is a system or router that provides a gateway between users and the internet. Therefore, it helps prevent cyber attackers from entering a private network. It is a server, referred to as an “intermediary” because it goes between end-users and the web pages they visit online... Proxies provide a valua..

Fine애플
'개발' 카테고리의 글 목록