1234
22 May 2022 | ETC.
자주 쓰는 것들 정리
Linux
용량
- 바로 하위 디렉토리별 용량 체크:
sudo du -sh *
- 하위 디렉토리 내 내용 검색:
grep -R "검색어" ./*
port
- 사용 중인 port 번호 확인:
netstat -nlpt
- 특정 포트 프로세스 번호 확인:
sudo ss -lptn 'sport = :8080'
계정
- root 계정으로:
sudo su -
- 계정 추가:
adduser ayaan
- 계정에 sudo 권한 주기:
sudo usermod -aG sudo ayaan
kill
- 좀비 프로세스 죽이기:
- 좀비 프로세스 부모 프로세스 확인
ps -ef | grep defunct | grep -v grep
kill -9 부모 프로세스
- grep 으로 해당 pid 프로세스 죽이기:
kill $(ps -ef | grep '.vscode' | awk '{print $2}')
프로세스 정보
- 프로세스 진행 시간:
ps -p [PID] -o etime=
- 프로세스 시작 시간:
ps -p [PID] -o lstart=
mount
# disk 확인
sudo lsblk
# 포맷
# sudo mkfs.ext4 -m 0 -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/sda
# 마운트
sudo mount -o discard,defaults /dev/sda /home/yein
#디스크에 대한 읽기 및 쓰기 권한을 구성합니다. 이 예에서는 모든 사용자에게 디스크에 대한 쓰기 액세스 권한을 부여
sudo chmod a+w /home/yein
# 마운트한 디스크 정보 확인
df -H | grep /home/yein
Docker
docker 설치
sudo wget -qO- http://get.docker.com/ | sh
docker compose 설치
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# docker compose에 권한 설
sudo chmod +x /usr/local/bin/docker-compose
# 심볼릭 링크 설정
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
컨테이너 생성
nvidia-docker run -it -d --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=0,1,2 --name ayaan_torch --network host -w /workspace -v /home/ayaan/ayaan_data:/workspace ayaanayaan/ayaan_nv
docker run -it -d --name ayaan_torch -p 8888:80 --gpus=0,1,2 -w /workspace -v /home/ayaan:/workspace ayaanayaan/ayaan_nv
docker run -it -d --name ayaan_vision --shm-size=10.24G --network host --gpus '"device=1"' -w /workspace -v /home/kyle:/workspace baseten/vllm
환경설정
(docker image: ubuntu:20.04)
# 파이썬 설치
# - 기존 3.8 삭제
apt remove python3.8*
apt autoremove python3.8 --purge
apt --fix-broken install
# https://www.linuxcapable.com/ko/how-to-install-python-3-10-on-ubuntu-20-04/ -> 3.9설치로 변경
# alias변경: https://zetawiki.com/wiki/Python3_pip_%EC%84%A4%EC%B9%98)
alias python=python3.9
alias python3=python3.9
alias pip=pip3
# 설정파일 변경하고 나면 source .bashrc입력해서 업데이트해 준다
# mecab 설치
'''
https://bitbucket.org/eunjeon/mecab-ko-dic/src/master/
https://somjang.tistory.com/entry/PythonUbuntu%EC%97%90-mecab-ko-dic-%EB%9D%BC%EC%9D%B4%EB%B8%8C%EB%9F%AC%EB%A6%AC-%EC%84%A4%EC%B9%98%ED%95%98%EA%B8%B0
https://pypi.org/project/mecab-python3/
'''
컨테이너 정보 확인
docker inspect ayaan_torch
mongo
docker run --name mongo_te -v /data/db:/data/db -d -p 27017:27017 mongo
docker 저장 경로 변경
# 기존 도커 저장 경로 확인
sudo docker info | grep "Docker Root Dir"
# 도커 서비스 중지
sudo systemctl stop docker.service
sudo systemctl stop docker.socket
# 도커 디렉토리 복사 또는 새로운 디렉토리 생성
# 기존에 가지고 있던 도커 이미지를 보존하기 위해 그대로 디렉토리를 새로운 경로에 복사하려면
sudo rsync -aP /var/lib/docker {새로운 도커 저장경로}
# 기존 이미지가 없거나 새롭게 도커 디렉토리를 만들어 주려면 그냥 생성
sudo mkdir -p {새로운 도커 저장경로}
# 도커 설정에 새로운 저장경로 연결
sudo vi /etc/docker/daemon.json
{
"data-root": "새로운 경로"
}
# 도커 서비스 재시작 및 확인
sudo systemctl start docker
ls {새로운 경로}
GCP
ssh 설정
# 로컬 혹은 서버에서
# rsa key 만들기
ssh-keygen -t rsa -f ~/.ssh/gcpkey -C yein4452@gmail.com -b 2048
# rsa key 확인
cat ~/.ssh/gcpkey.pub
# GCP 인스턴스 수정 -> ssh key 등록 -> 인스턴스 재시작
# ssh -i .ssh/gcpkey yein4452@(인스턴스 외부 포트)
scp
scp -r -i (로컬 및 서버 .ssh 경로)\.ssh\gcpkey .\func_react_stream\ yein4452@(인스턴스 외부 포트):/home/yein4452/
vscode 연결
# remote ssh config 파일에 아래 내용 추가
Host 이름
HostName (인스턴스 외부 포트)
IdentityFile (로컬 및 서버 .ssh 경로)\.ssh\gcpkey
User yein4452
Jupyter
python -m jupyterlab --ip=0.0.0.0 --port=8888 --allow-root
python -m jupyterlab --ip=0.0.0.0 --port=8888 --allow-root --ContentsManager.allow_hidden=True
'''
# vscode jupyter server remote:
jupyter:specify local or remote jupyter server for connections
# 그리고 ipykernel선택
jupyter 비밀번호
$ jupyter notebook password
https://jupyter-notebook.readthedocs.io/en/stable/public_server.html
Mongo
(docker image: mongo)
mongo -u root -p admin
show dbs DB # DB 목록 조회
use TE # DB 생성 및 사용
db # 현재 DB
db.stats() # 현재 DB상태
db.createUser({ user: 'ayaan', pwd: 'dldks1234', roles: ['readWrite'] }) # 현재 DB에 사용자 추가
show users # 현재 DB 사용자 조회
db.createCollection() # collection 생성
show collections # 현재 DB collection 조회
db.te_data.drop() # collection 삭제
quit() # 나가기
docker log 확인
# 10개
docker logs docker_name -f --tail 10
vscode
ssh-keygen
# 1. local cmd -> bash -> pwd는 ~
ssh-keygen -t rsa # 이거 하고 그냥 엔터 엔터
# 2. ~/.ssh에 id_rsa, id_rsa.pub만들어졌나 확인
# 3. vscode config file과 같은 디렉토리로 id_rsa 복사
cp id_rsa /C/Users/Vscode/
# 4. key 적용하려는 서버에 id_rsa.pub 옮김
scp id_rsa.pub [usernave]@[server]:[directory]
# 5. 서버의 .ssh/authorized_keys에 id_rsa.pub에 적혀 있는 key값을 넣음
cat id_rsa.pub >> .ssh/authorized_keys
# 6. .ssh/authorized_keys 있는지
vim
꾸미기
vim ~/.vimrc
" All system-wide defaults are set in $VIMRUNTIME/debian.vim and sourced by
" the call to :runtime you can find below. If you wish to change any of those
" settings, you should do it in this file (/etc/vim/vimrc), since debian.vim
" will be overwritten everytime an upgrade of the vim packages is performed.
" It is recommended to make changes after sourcing debian.vim since it alters
" the value of the 'compatible' option.
" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
runtime! debian.vim
if has("syntax")
syntax on
endif
"set showcmd " Show (partial) command in status line.
"set showmatch " Show matching brackets.
"set ignorecase " Do case insensitive matching
"set smartcase " Do smart case matching
"set incsearch " Incremental search
"set autowrite " Automatically save before commands like :next and :make
"set hidden " Hide buffers when they are abandoned
set mouse=a " Enable mouse usage (all modes)
"set mouse=i " Enable mouse usage (all modes)
set showcmd
set hlsearch
set number
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab
set title
set rtp+=~/.vim/bundle/Vundle.vim
"call vundle#begin()
"Plugin 'VundleVim/Vundle.vim'
"call vundle#end()
"Plugin 'Syntastic'
"Plugin 'scrooloose/nerdtree'
" Syntastic
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
source /etc/vim/vimrc.local
endif
etc.
process 관리
ps -aux | grep python # python 어쩌고로 명령어로 실행 중인 process
kill -9 (process id) # pid로 죽여
tensorboard 확인
# summeries->
tensorboard --logdir =./
gpu 온도 확인
gpustat -i
서버 관리
ping 8.8.8.8
ifconfig
ethtool()
ngrok
# download: https://dashboard.ngrok.com/get-started/setup
tar -zxvf (file name.tar)
# authtoken : https://dashboard.ngrok.com/get-started/your-authtoken
./ngrok authtoken (token)
screen -S ngrok
./ngrok tcp 22 --region jp
history 삭제
ref. (https://busyman.tistory.com/411)[ref. https://busyman.tistory.com/411]
set +o history
rm ~/.bash_history
touch ~/.bash_history
history -c
set -o history
접속 기록 삭제
ref. (https://busyman.tistory.com/411)[ref. https://busyman.tistory.com/411]
sudo rm /var/log/wtmp
sudo touch /var/log/wtmp
sudo rm /var/log/lastlog
sudo touch /var/log/lastlog
자주 쓰는 것들 정리
Linux
용량
- 바로 하위 디렉토리별 용량 체크:
sudo du -sh *
- 하위 디렉토리 내 내용 검색:
grep -R "검색어" ./*
port
- 사용 중인 port 번호 확인:
netstat -nlpt
- 특정 포트 프로세스 번호 확인:
sudo ss -lptn 'sport = :8080'
계정
- root 계정으로:
sudo su -
- 계정 추가:
adduser ayaan
- 계정에 sudo 권한 주기:
sudo usermod -aG sudo ayaan
kill
- 좀비 프로세스 죽이기:
- 좀비 프로세스 부모 프로세스 확인
ps -ef | grep defunct | grep -v grep
kill -9 부모 프로세스
- 좀비 프로세스 부모 프로세스 확인
- grep 으로 해당 pid 프로세스 죽이기:
kill $(ps -ef | grep '.vscode' | awk '{print $2}')
프로세스 정보
- 프로세스 진행 시간:
ps -p [PID] -o etime=
- 프로세스 시작 시간:
ps -p [PID] -o lstart=
mount
# disk 확인
sudo lsblk
# 포맷
# sudo mkfs.ext4 -m 0 -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/sda
# 마운트
sudo mount -o discard,defaults /dev/sda /home/yein
#디스크에 대한 읽기 및 쓰기 권한을 구성합니다. 이 예에서는 모든 사용자에게 디스크에 대한 쓰기 액세스 권한을 부여
sudo chmod a+w /home/yein
# 마운트한 디스크 정보 확인
df -H | grep /home/yein
Docker
docker 설치
sudo wget -qO- http://get.docker.com/ | sh
docker compose 설치
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# docker compose에 권한 설
sudo chmod +x /usr/local/bin/docker-compose
# 심볼릭 링크 설정
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
컨테이너 생성
nvidia-docker run -it -d --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=0,1,2 --name ayaan_torch --network host -w /workspace -v /home/ayaan/ayaan_data:/workspace ayaanayaan/ayaan_nv
docker run -it -d --name ayaan_torch -p 8888:80 --gpus=0,1,2 -w /workspace -v /home/ayaan:/workspace ayaanayaan/ayaan_nv
docker run -it -d --name ayaan_vision --shm-size=10.24G --network host --gpus '"device=1"' -w /workspace -v /home/kyle:/workspace baseten/vllm
환경설정
(docker image: ubuntu:20.04)
# 파이썬 설치
# - 기존 3.8 삭제
apt remove python3.8*
apt autoremove python3.8 --purge
apt --fix-broken install
# https://www.linuxcapable.com/ko/how-to-install-python-3-10-on-ubuntu-20-04/ -> 3.9설치로 변경
# alias변경: https://zetawiki.com/wiki/Python3_pip_%EC%84%A4%EC%B9%98)
alias python=python3.9
alias python3=python3.9
alias pip=pip3
# 설정파일 변경하고 나면 source .bashrc입력해서 업데이트해 준다
# mecab 설치
'''
https://bitbucket.org/eunjeon/mecab-ko-dic/src/master/
https://somjang.tistory.com/entry/PythonUbuntu%EC%97%90-mecab-ko-dic-%EB%9D%BC%EC%9D%B4%EB%B8%8C%EB%9F%AC%EB%A6%AC-%EC%84%A4%EC%B9%98%ED%95%98%EA%B8%B0
https://pypi.org/project/mecab-python3/
'''
컨테이너 정보 확인
docker inspect ayaan_torch
mongo
docker run --name mongo_te -v /data/db:/data/db -d -p 27017:27017 mongo
docker 저장 경로 변경
# 기존 도커 저장 경로 확인
sudo docker info | grep "Docker Root Dir"
# 도커 서비스 중지
sudo systemctl stop docker.service
sudo systemctl stop docker.socket
# 도커 디렉토리 복사 또는 새로운 디렉토리 생성
# 기존에 가지고 있던 도커 이미지를 보존하기 위해 그대로 디렉토리를 새로운 경로에 복사하려면
sudo rsync -aP /var/lib/docker {새로운 도커 저장경로}
# 기존 이미지가 없거나 새롭게 도커 디렉토리를 만들어 주려면 그냥 생성
sudo mkdir -p {새로운 도커 저장경로}
# 도커 설정에 새로운 저장경로 연결
sudo vi /etc/docker/daemon.json
{
"data-root": "새로운 경로"
}
# 도커 서비스 재시작 및 확인
sudo systemctl start docker
ls {새로운 경로}
GCP
ssh 설정
# 로컬 혹은 서버에서
# rsa key 만들기
ssh-keygen -t rsa -f ~/.ssh/gcpkey -C yein4452@gmail.com -b 2048
# rsa key 확인
cat ~/.ssh/gcpkey.pub
# GCP 인스턴스 수정 -> ssh key 등록 -> 인스턴스 재시작
# ssh -i .ssh/gcpkey yein4452@(인스턴스 외부 포트)
scp
scp -r -i (로컬 및 서버 .ssh 경로)\.ssh\gcpkey .\func_react_stream\ yein4452@(인스턴스 외부 포트):/home/yein4452/
vscode 연결
# remote ssh config 파일에 아래 내용 추가
Host 이름
HostName (인스턴스 외부 포트)
IdentityFile (로컬 및 서버 .ssh 경로)\.ssh\gcpkey
User yein4452
Jupyter
python -m jupyterlab --ip=0.0.0.0 --port=8888 --allow-root
python -m jupyterlab --ip=0.0.0.0 --port=8888 --allow-root --ContentsManager.allow_hidden=True
'''
# vscode jupyter server remote:
jupyter:specify local or remote jupyter server for connections
# 그리고 ipykernel선택
jupyter 비밀번호
$ jupyter notebook password
https://jupyter-notebook.readthedocs.io/en/stable/public_server.html
Mongo
(docker image: mongo)
mongo -u root -p admin
show dbs DB # DB 목록 조회
use TE # DB 생성 및 사용
db # 현재 DB
db.stats() # 현재 DB상태
db.createUser({ user: 'ayaan', pwd: 'dldks1234', roles: ['readWrite'] }) # 현재 DB에 사용자 추가
show users # 현재 DB 사용자 조회
db.createCollection() # collection 생성
show collections # 현재 DB collection 조회
db.te_data.drop() # collection 삭제
quit() # 나가기
docker log 확인
# 10개
docker logs docker_name -f --tail 10
vscode
ssh-keygen
# 1. local cmd -> bash -> pwd는 ~
ssh-keygen -t rsa # 이거 하고 그냥 엔터 엔터
# 2. ~/.ssh에 id_rsa, id_rsa.pub만들어졌나 확인
# 3. vscode config file과 같은 디렉토리로 id_rsa 복사
cp id_rsa /C/Users/Vscode/
# 4. key 적용하려는 서버에 id_rsa.pub 옮김
scp id_rsa.pub [usernave]@[server]:[directory]
# 5. 서버의 .ssh/authorized_keys에 id_rsa.pub에 적혀 있는 key값을 넣음
cat id_rsa.pub >> .ssh/authorized_keys
# 6. .ssh/authorized_keys 있는지
vim
꾸미기
vim ~/.vimrc
" All system-wide defaults are set in $VIMRUNTIME/debian.vim and sourced by
" the call to :runtime you can find below. If you wish to change any of those
" settings, you should do it in this file (/etc/vim/vimrc), since debian.vim
" will be overwritten everytime an upgrade of the vim packages is performed.
" It is recommended to make changes after sourcing debian.vim since it alters
" the value of the 'compatible' option.
" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
runtime! debian.vim
if has("syntax")
syntax on
endif
"set showcmd " Show (partial) command in status line.
"set showmatch " Show matching brackets.
"set ignorecase " Do case insensitive matching
"set smartcase " Do smart case matching
"set incsearch " Incremental search
"set autowrite " Automatically save before commands like :next and :make
"set hidden " Hide buffers when they are abandoned
set mouse=a " Enable mouse usage (all modes)
"set mouse=i " Enable mouse usage (all modes)
set showcmd
set hlsearch
set number
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab
set title
set rtp+=~/.vim/bundle/Vundle.vim
"call vundle#begin()
"Plugin 'VundleVim/Vundle.vim'
"call vundle#end()
"Plugin 'Syntastic'
"Plugin 'scrooloose/nerdtree'
" Syntastic
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
source /etc/vim/vimrc.local
endif
etc.
process 관리
ps -aux | grep python # python 어쩌고로 명령어로 실행 중인 process
kill -9 (process id) # pid로 죽여
tensorboard 확인
# summeries->
tensorboard --logdir =./
gpu 온도 확인
gpustat -i
서버 관리
ping 8.8.8.8
ifconfig
ethtool()
ngrok
# download: https://dashboard.ngrok.com/get-started/setup
tar -zxvf (file name.tar)
# authtoken : https://dashboard.ngrok.com/get-started/your-authtoken
./ngrok authtoken (token)
screen -S ngrok
./ngrok tcp 22 --region jp
history 삭제
ref. (https://busyman.tistory.com/411)[ref. https://busyman.tistory.com/411]
set +o history
rm ~/.bash_history
touch ~/.bash_history
history -c
set -o history
접속 기록 삭제
ref. (https://busyman.tistory.com/411)[ref. https://busyman.tistory.com/411]
sudo rm /var/log/wtmp
sudo touch /var/log/wtmp
sudo rm /var/log/lastlog
sudo touch /var/log/lastlog