[SERVER] Environment Modules 설정
Environment Moduels 란?
Environment modules는 module 명령어로 실행되는 패키지로, 쉘의 초기화나, 환경변수를 바꾸기 편하게 만들어 준다. 우리는 실험을 하다보면, 사용 해야하는 GPU들(CUDA_VISIBLE_DEVICES) 등 여러 환경 변수를 관리해야하는 일도 있을 수 있다. 또한 Conda와 같이 모두가 사용하나, 개별 유저가 따로따로 설치해줘야 작동한다. 그렇다면 이러한 것을 해결할 수 있는 방법은 없을까? 그 방법으로 나온 것이 이 패키지, module의 역할이다.
설치
설치는 Ubuntu 22.04 LTS를 기준으로 apt를 통하여도 설치할 수 있다. Install를 참고하면 최신 내용을 얻을 수도 있다.
sudo apt install environment-modules tcl
echo ". /usr/share/modules/init/sh" | sudo tee -a /etc/bashrc
위와 같이 실행한다면, 서버의 모든 user가 module을 사용할 수 있게 된다.
만약 자신만 사용하고 싶다면, echo ". /usr/share/modules/init/sh" | sudo tee -a ~/.bashrc를 사용하면 된다.
활용
기본적인 활용
사용 가능한 module 확인
가능한 module의 확인은 module avail를 입력하면 할 수 있다.
❯ module avail
-------------------------------------------- /usr/share/modules/modulefiles --------------------------------------------
conda dot module-git module-info modules null use.own
필자는 이미 conda를 설정하여 있고, 아마 처음 설치한 유저라면 conda를 제외한 module이 사용 가능할 것이다.
모듈의 로드와 언로드
가능한 모듈이 있다면 module load를 통하여 load할 수 있다.
마찬가지로, unload 또한 module unload를 통해 unload할 수 있다.
또한, 모든 모듈을 unload하고 싶다면, module purge를 입력하면 된다.
활용 예제, miniconda
필자가, 해당 모듈을 설치한 주요 이유 중 하나인, conda를 공용으로 사용하는 방법에 대해 논의하게 될것이다.
miniconda는 파이썬 패키지를 관리하며, 여러 파이썬 편히 사용할 수 있도록 돕는 툴이다.
Miniconda Download에서 macOS/Linux installation > Linux terminal installer를 클릭하자.
그렇다면 설치방법을 친절하게 설명해준 글을 찾을 수 있을 것이다.
단지 wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh를 입력하면 준비가 끝이다!
원래는 설치한 Miniconda3-latest-Linux-x86_64.sh를 실행하면 끝나는 문제이지만, 필자는 이것을 모든 user가 사용할 수 있게할 것이므로, 다음과 같이 설치한다.
sudo sh ./Miniconda3-latest-Linux-x86_64.sh
라이센스 term에 동의를 하고 나면 다음과 같은 문자열이 뜨게 될 것인데, 우리는 다른 유저도 접근할 수 있지만, 수정은할 수 없는 /usr/local/miniconda3로 지정한다. 설치는 이제 이 디렉토리에 진행을 하게 되며, 이후 환경변수 설정도 이를 홈으로 설정하면 된다.
Miniconda3 will now be installed into this location:
/root/miniconda3
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
[/root/miniconda3] >>> /usr/local/miniconda3
설치가 완료된다면, Initialization을 할 것이냐고 다음과 같이 묻는데, 우리는 다르게 관리를 할 것이므로 “no”를 고르면 된다.
You can undo this by running `conda init --reverse $SHELL`? [yes|no]
[no] >>> no
environment modules에서 module의 위치는 /usr/share/modules/modulefiles에 있다.
따라서, 우리는 sudo vi /usr/share/modules/modulefiles/conda를 통해 conda의 환경변수를 설정하고 실행할 것이다.
#%Module1.0
conflict conda
set name miniconda3
set version miniconda3
set conda_home /usr/local/$name
set prefix $conda_home
if {![file exists $prefix]} {
puts stderr "\t[module-info name] Load Error: $prefix does not exist"
break
exit 1
}
append-path PATH $conda_home/bin
setenv CONDA_HOME $prefix
if { [ module-info mode load ] } {
puts stdout "source $prefix/etc/profile.d/conda.sh"
}
이후 module avail를 실행하면 conda가 필자처럼 추가된 것을 확인할 수 있다.
References
https://modules.readthedocs.io/en/latest/# https://raon1123.github.io/server-env.html