Environment Modules安裝和使用教程

一、簡介

	Environment Modules軟件包提供了通過modulefile動態修改用戶環境的功能,通常,用戶在登錄時通過設置會話期間將引用的每個應用程序的環境信息來初
始化其環境。Environment Modules軟件包是一種簡化外殼初始化的工具,使用戶可以在會話期間使用modulefiles輕鬆修改其環境。

	每個模塊文件都包含爲應用程序配置外殼所需的信息。初始化Modules包後,可以使用解釋模塊文件的module命令在每個模塊的基礎上修改環境。通常,模塊文件
指示模塊命令更改或設置外殼程序環境變量,例如PATH,MANPATH等。模塊文件可以由系統上的許多用戶共享,並且用戶可能擁有自己的集合來補充或替換共享的模塊
文件。

	可以以一種乾淨的方式動態地和原子地加載和卸載模塊。所有流行的貝殼都支持,包括bash, ksh, zsh, sh, csh, tcsh, fish,以及一些腳本語言,如Perl中,
 ruby, tcl, python, cmake 和 R。

	模塊在管理不同版本的應用程序時很有用。模塊也可以捆綁到元模塊中,這些元模塊將加載一整套不同的應用程序。

二、軟件安裝

1、 YUM安裝

# yum install -y environment-modules
(安裝後退出重進終端生效)

2、源碼安裝方式

Modules 可直接採用源碼安裝方式,在 Modules 官網下載最新4.5.0版本的源代碼。在 Terminal 中輸入如下命令安裝 Modules 軟件
(https://jaist.dl.sourceforge.net/project/modules/Modules/modules-4.5.0/modules-4.5.0.tar.gz)
modules 安裝目錄
	# mkdir /opt/modules-4.5.0/
	# tar -xvf modules-4.5.0.tar.gz

進入 modules 目錄
	# cd modules-4.5.0

安裝 modules 軟件
	# yum install tcl*
	# ./configure --prefix=${INSTALL_PATH}
	# make
	# make install
	在安裝完畢後我們將 modules 設置腳本添加入環境變量中。注意,modules 中包含多種 shell 設置腳本,可以根據不同情況設置。
(root用戶)
# cd /etc/profile.d
# ln -s /opt/modules-4.5.0/init/profile.sh  module-profile.sh
# ln -s /opt/modules-4.5.0/init/profile.csh  module-profile.csh


(普通用戶-bash)
$ source /opt/modules-4.5.0/init/profile.sh
$ echo "source /opt/modules-4.5.0/init/profile.sh" >> ~/.bashrc
輸入如下命令,查看當前包含的模塊並加載用戶模塊
# module avail
------------------------------------------ /usr/share/Modules/modulefiles ------------------------------------------
dot  module-git  module-info  modules  null  use.own
# module load use.own
# module list
Currently Loaded Modulefiles:
 1) use.own

3、配置用戶能夠調用的模塊

需要先在/opt/modules-4.5.0/modulefiles增加不同軟件的配置信息,才能用module load進行加載。
例:GCC

安裝devtoolset (GCC)
# yum install centos-release-scl
# yum -y install devtoolset-x 	// 貌似 x={7, 8, 9}
# mkdir -p /opt/modules-4.5.0/modulefiles/biosoft/gcc
# cd /opt/modules-4.5.0/modulefiles/biosoft/gcc
# vim 7.3.1
	#%Module1.0########
	proc ModulesHelp {} {
		global version modroot
		puts stdout "\t loads gcc 7.3.1\n"
	}
	
	module-whatis "load gcc-7.3.1"
	
	set version 7.3.1
	set prefix	/opt/modules-4.5.0/modulefiles/biosoft/gcc/
	
	conflict gcc
	
	setenv CC gcc
	setenv CXX g++
	
	prepend-path PATH  /opt/rh/devtoolset-7/root/usr/bin
	
	if [ module-info mode load ] {
		system echo "gcc 7.3.1 is loaded"
	}
	if [ module-info mode switch2 ] {
		system echo "gcc 7.3.1 is loaded"
	}
	if [ module-info mode remove ] {
		system echo "gcc 7.3.1 is unloaded"
	}
# module av
	-------------------------- /opt/modules-4.5.0/modulefiles --------------------------
	biosoft/gcc/7.3.1  biosoft/gcc/9.1.1  module-git   modules  use.own  
	biosoft/gcc/8.3.1  dot                module-info  null     
# module load biosoft/gcc/7.3.1
	gcc 7.3.1 is loaded
# gcc -v
	Using built-in specs.
	COLLECT_GCC=gcc
	COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/lto-wrapper
	Target: x86_64-redhat-linux
	Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-7/root/usr --mandir=/opt/rh/devtoolset-7/root/usr/share/man --infodir=/opt/rh/devtoolset-7/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-plugin --with-linker-hash-style=gnu --enable-initfini-array --with-default-libstdcxx-abi=gcc4-compatible --with-isl=/builddir/build/BUILD/gcc-7.3.1-20180303/obj-x86_64-redhat-linux/isl-install --enable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
	Thread model: posix
	gcc version 7.3.1 20180303 (Red Hat 7.3.1-5) (GCC) 
# module unload biosoft/gcc
	gcc 7.3.1 is unloaded
#  gcc -v
	Using built-in specs.
	COLLECT_GCC=gcc
	COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
	Target: x86_64-redhat-linux
	Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
	Thread model: posix
	gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章