본문 바로가기

hacking or software engineering skills/cloud computing

[gcp] gcp로 jupyter lab, jupyter notebook 접속, 클라언트 작동 중지시 서버 작동이 멈출때 방법 (gcp jupyter lab 백그라운드 실행, tmux 이용 ssh 연결 관리)

반응형

tmux란?

  • Terminal MUltipleXer

  • 언제 쓰는가?

    • gcp를 ssh로 연결하고 Jupyter lab으로 학습을 돌려놓는다. 그런데 컴퓨터가 잠시 꺼지거나 인터넷 연결이 끊어지면 이 학습도 멈춰버린다.... 이것 때문에 많은 시간을 날렸다. 10시간 학습한 게 수포로 돌아가기도 했으니... 이 삽질을 막을 방법이 tmux다

    • nohup이란 것도 있는데 py파일에 대한 설명만 있어서 tmux를 시도해봤다. 잘 되길래 유용한 정보로 생각되어 포스팅한다.

tmux를 사용해서 내 컴퓨터가 죽어도 서버에서 계속 안전하게 학습하는 방법!

  1. gcp ssh를 연결해준다.

  2. tmux 명령어를 입력해준다.

    • $ tmux new -s k (k는 원하는 숫자를 입력하면 된다. 안 입력하고 tmux라고 치면 자동으로 0번으로 세션을 할당한다.)

    • tmux를 입력하면 새로운 창이 뜰 것이다.

    • 이 창에서 jupyter lab이나 jupyter notebook을 실행하면 된다.

    • ipynb 쉘을 실행하면 잘 작동할 것이다.

    • 우리는 jupyter lab 서버는 그대로 실행되길 원한다. jupyter 서버를 유지하며 tmux에서 본래 터미널로 나가려면 ctrl+b (동시에 누른다) 그리고 를 누른다.

    • 나오면 본래 ssh 연결된 터미널 창이 뜰 것이다. 걱정 말자. jupyter 서버는 그대로 켜져 있다. 여기서 jupyter 서버를 켰던 tmux session으로 다시 접속하려면? 우선 tmux session list를 확인해보자. (tmux ls라고 입력하면 뭐라고 뜰 것이다. 0 : ~) 나의 경우 default로 생성하였기에 0이라 떴다. 이 0이 앞서 생성한 k이다. 이 값을 기억하자

    • $ tmux attach -t k 라고 입력하면 jupyter 서버를 실행했던 그 터미널이 그대로 있을 것이다.

    • ssh가 끊어졌다면 다시 ssh를 연결하고 tmux ls를 해보자. 그대로 있다. 똑같이 접속하면 된다. jupyter 서버는 계속 run 중이다.

    • tmux를 종료하고 싶으면?

    • $ tmux kill-session -t k를 입력하면 된다.

  3. tmux 명령어

tmux 명령어 

모쪼록 성공적인 학습하시길 바랍니다.

참고 사이트


 

How to run jupyter notebook in the background ? No need to keep one terminal for it

Often we run jupyter notebook to pop up a page in browser to use notebook. However, the terminal opening the server remains there. Is there a way that we can close that terminal with server running...

stackoverflow.com

www.tecmint.com/keep-remote-ssh-sessions-running-after-disconnection/

 

5 Ways to Keep Remote SSH Sessions and Processes Running After Disconnection

SSH or Secure Shell in simple terms is a way by which a person can remotely access another user on other system but only in command line i.e. non-GUI mode. In more technical terms, when we ssh on to other user on some other system and run commands on that

www.tecmint.com

medium.com/@mromerocalvo/set-up-a-remote-machine-for-deep-learning-with-jupyter-notebook-1946729f9fc

 

Set-up a remote machine for Deep Learning with Jupyter Notebook.

Introduction

medium.com

 

반응형