lmod
安装配置¶
# lmod 安装依赖 lua 和 tcl
$ module load lua/5.1.4.9 Tcl/8.6.17
# 当前版本为9.0.3
$ git clone https://github.com/TACC/Lmod.git
$ ./configure --prefix=/path/to/lmod/
$ make install
$ ln -s /path/to/lmod/lmod/init/profile /etc/profile.d/z00_lmod.sh
$ ln -s /path/to/lmod/lmod/init/cshrc /etc/profile.d/z00_lmod.csh
$ ln -s /path/to/lmod/lmod/init/profile.fish /etc/fish/conf.d/z00_lmod.fish
eval "$($LMOD_CMD shell "$@")"。 $ type module
module is a function
module ()
{
if [ -z "${LMOD_SH_DBG_ON+x}" ]; then
case "$-" in
*v*x*)
__lmod_sh_dbg='vx'
;;
*v*)
__lmod_sh_dbg='v'
;;
*x*)
__lmod_sh_dbg='x'
;;
esac;
fi;
if [ -n "${__lmod_sh_dbg:-}" ]; then
set +$__lmod_sh_dbg;
echo "Shell debugging temporarily silenced: export LMOD_SH_DBG_ON=1 for Lmod's output" 1>&2;
fi;
eval "$($LMOD_CMD shell "$@")" && eval "$(${LMOD_SETTARG_CMD:-:} -s sh)";
__lmod_my_status=$?;
if [ -n "${__lmod_sh_dbg:-}" ]; then
echo "Shell debugging restarted" 1>&2;
set -$__lmod_sh_dbg;
fi;
unset __lmod_sh_dbg;
return $__lmod_my_status
}
$ echo $LMOD_CMD
/path/to/lmod/lmod/libexec/lmod
$ ml av
基本使用¶
缓存¶
modulefile 文件较多时,为了加快 modulefile 搜索速度,lmod 使用了缓存机制。
默认没有启用系统缓存,module 在使用时会先查看系统缓存是否启用,如果没有则创建用户侧的缓存,默认为 ~/.cache/lmod/spiderT.x86_64_Linux.lua,创建缓存时间稍长,之后运行 ml av 之类的命令结果会秒出。缓存文件默认有效期为 24h (变量 LMOD_ANCIENT_TIME 定义)。
配置系统缓存
创建系统缓存目录 mkdir -p /path/to/lmod/lmod/mdata/cache。
在 /path/to/lmod/lmod/init/lmodrc.lua 最下面写入以下内容
scDescriptT = {
{
["dir"] = "/path/to/lmod/lmod/mdata/cache",
["timestamp"] = "/path/to/lmod/lmod/mdata/system.txt",
},
}
ml --config 查看是否生成 $ ml --config
Cache Directory Time Stamp File
--------------- ---------------
/path/to/lmod/lmod/mdata/cache /path/to/lmod/lmod/mdata/system.txt
$ update_lmod_system_cache_files $MODULEPATH
$ ls /path/to/lmod/lmod/mdata/cache
spiderT.lua spiderT.luac_5.1
$ crontab -l
*/120 * * * * /path/to/lmod/lmod/libexec/update_lmod_system_cache_files $MODULEPATH
行为追踪¶
作为管理员,我们希望能追踪用户调用lmod中软件的情况,方便后续做相关分析。
lmod 通过自身的 hook 和 系统的 logger 提供了实现方案。
配置 hook¶
在 /path/to/lmod/lmod/libexec/SitePackage.lua 中写入以下内容
--------------------------------------------------------------------------
-- load_hook(): Here we record the any modules loaded.
local hook = require("Hook")
local uname = require("posix").uname
local cosmic = require("Cosmic"):singleton()
local syshost = cosmic:value("LMOD_SYSHOST")
local s_msgT = {}
local function l_load_hook(t)
-- the arg t is a table:
-- t.modFullName: the module full name: (i.e: gcc/4.7.2)
-- t.fn: The file name: (i.e /apps/modulefiles/Core/gcc/4.7.2.lua)
-- t.mname: The Module Name object.
local isVisible = t.mname:isVisible()
-- use syshost from configuration if set
-- otherwise extract 2nd name from hostname: i.e. login1.stampede2.tacc.utexas.edu
-- Please modify the following code to match your site.
local host = syshost
if (not host) then
local i,j, first
host = uname("%n")
if (host:find("%.")) then
i,j, first, host = host:find("([^.]*)%.([^.]*)%.")
end
end
if (mode() ~= "load") then return end
local msg = string.format("user=%s module=%s path=%s host=%s time=%f",
os.getenv("USER"), t.modFullName, t.fn, uname("%n"),
epoch())
s_msgT[t.modFullName] = msg
end
hook.register("load", l_load_hook)
local function l_report_loads()
local openlog
local syslog
local closelog
local logInfo
if (posix.syslog) then
if (type(posix.syslog) == "table" ) then
-- Support new style posix.syslog table
openlog = posix.syslog.openlog
syslog = posix.syslog.syslog
closelog = posix.syslog.closelog
logInfo = posix.syslog.LOG_INFO
else
-- Support original style posix.syslog functions
openlog = posix.openlog
syslog = posix.syslog
closelog = posix.closelog
logInfo = 6
end
openlog("ModuleUsageTracking")
for k,msg in pairs(s_msgT) do
syslog(logInfo, msg)
end
closelog()
else
for k,msg in pairs(s_msgT) do
lmod_system_execute("logger -t ModuleUsageTracking -p local0.info " .. msg)
end
end
end
ExitHookA.register(l_report_loads)
$ ml --config
Site Pkg location /path/to/lmod/lmod/libexec/SitePackage.lua
计算节点配置¶
在 /etc/rsyslog.conf 中添加以下内容,然后重启服务 systemctl restart rsyslog.service。
# lmod track
if $programname contains 'ModuleUsageTracking' then @module_usage_tracking_machine
& stop
管理节点配置¶
查看 /etc/rsyslog.conf 中是否有(默认有) $IncludeConfig /etc/rsyslog.d/*.conf...,没有则添加然后重启 rsyslog 服务。
创建 /etc/rsyslog.d/moduleTracking.conf 并写入以下内容
$Ruleset remote
if $programname contains 'ModuleUsageTracking' then /var/log/moduleUsage.log
$Ruleset RSYSLOG_DefaultRuleset
# provides UDP syslog reception
$ModLoad imudp
$InputUDPServerBindRuleset remote
$UDPServerRun 514
测试¶
在刚刚的计算节点运行 logger -t ModuleUsageTracking -p local0.info -n login "Some test message"。
在管理节点查看是否有计算节点发送的日志
$ cat /var/log/moduleUsage.log
Nov 12 11:42:33 c01n01 ModuleUsageTracking: Some test message
module load xxx 载入软件后,可以在管理节点的 /var/log/moduleUsage.log 中看到有类似如下的日志 Nov 12 11:50:45 c01n01 ModuleUsageTracking: user=username module=BWA/0.7.17 path=/public/home/software/opt/bio/modules/all/BWA/0.7.17 host=c01n01 time=1762919445.842571
Nov 12 11:51:10 c01n01 ModuleUsageTracking: user=username module=hifiasm/0.19.9 path=/public/home/software/opt/bio/modules/all/hifiasm/0.19.9 host=c01n01 time=1762919470.399186
Nov 12 11:53:16 c01n01 ModuleUsageTracking: user=username module=GCC/12.2.0 path=/public/home/software/opt/bio/modules/all/GCC/12.2.0 host=c01n01 time=1762919596.685562
Nov 12 11:53:19 c01n01 ModuleUsageTracking: user=username module=GATK/4.6.0.0 path=/public/home/software/opt/bio/modules/all/GATK/4.6.0.0 host=c01n01 time=1762919599.434815
Nov 12 11:53:19 c01n01 ModuleUsageTracking: user=username module=Java/21.0.2 path=/public/home/software/opt/bio/modules/all/Java/21.0.2 host=c01n01 time=1762919599.433807
Nov 12 15:07:59 c01n01 ModuleUsageTracking: user=username module=cellranger/7.0.0 path=/public/home/software/opt/bio/modules/all/cellranger/7.0.0 host=c01n01 time=1762931279.400905
Nov 12 15:08:05 c01n01 ModuleUsageTracking: user=username module=R/4.0.0 path=/public/home/software/opt/bio/modules/all/R/4.0.0 host=c01n01 time=1762931285.836179
Nov 12 15:08:22 c01n01 ModuleUsageTracking: user=username module=STAR/2.7.8a path=/public/home/software/opt/bio/modules/all/STAR/2.7.8a host=c01n01 time=1762931302.701338
高级用法¶
可以将生成的日志处理后放入 MySQL 数据库进行分析,参考官方实现 Tracking Module Usage。
本文阅读量 次本站总访问量 次