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) 
  • 1
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值