SGE-On-CentOS

SGE-On-CentOS
本文档主要介绍如何在CentOS上安装并使用SGE(Sun Grid Engine)。使用配合使用NFS的SGE搭建计算集群,可以实现任务多机器并行运行。

SGE-On-CentOS

本文档主要介绍如何在CentOS上安装并使用SGE(Sun Grid Engine)。使用配合使用NFS的SGE搭建计算集群,可以实现任务多机器并行运行。

一. 安装

本次安装
SGE安装包下载地址:  https://arc.liv.ac.uk/downloads/SGE/releases/8.1.9/sge-8.1.9.tar.gz

1. 主控节点安装

命令行执行,修改hostname

hostnamectl set-hostname qmaster.local

命令行执行,修改hosts文件,添加主控节点和两个计算节点信息

vi /etc/hosts
192.168.98.134 qmaster.local qmaster
192.168.98.135 compute01.local compute01
192.168.98.136 compute02.local compute02

命令行执行,创建共享目录

mkdir -p /sge/src

命令行执行,安装epel源

yum -y install epel-release

命令行执行,安装依赖库

yum -y install jemalloc-devel openssl-devel ncurses-devel pam-devel libXmu-devel hwloc-devel hwloc hwloc-libs java-devel javacc ant-junit ant libdb-devel motif-devel csh ksh xterm db4-utils perl-XML-Simple perl-Env xrog-x11-fonts-ISO8859-1-100dpi xrog-x11-fonts-ISO8859-1-75dpi

命令行执行,添加sgeadmin用户组,及sgeadmin用户

groupadd -g 490 sgeadmin
useradd -u 495 -g 490 -m -d /home/sgeadmin -s /bin/bash -c "SGE Admin" sgeadmin

命令行执行,修改sudo文件,添加一行配置

visudo
%sgeadmin ALL=(ALL) NOPASSWD: ALL

命令行执行,下载并编译SGE。(如果您下载不了SGE安装包,请到本工程/softwares目录下获取)

cd /sge/src
wget https://arc.liv.ac.uk/downloads/SGE/releases/8.1.9/sge-8.1.9.tar.gz
tar -zxvf sge-8.1.9.tar.gz
cd sge-8.1.9/source/
sh scripts/bootstrap.sh -no-java -no-jni -no-secure -no-herd -parallel 6
./aimk -no-java -no-jni -no-secure -no-herd -parallel 6
./aimk -man
export SGE_ROOT=/sge/sge819 && mkdir $SGE_ROOT
echo Y | ./scripts/distinst -local -allall -bin -libs -noexit
chown -R sgeadmin:sgeadmin /sge/sge819

命令行执行,安装SGE qmaster节点

cd $SGE_ROOT
./install_qmaster

安装过程中,需要同意一些默认配置。

press enter at the intro screen
press “y” and then specify sgeadmin as the user id
leave the install dir as /sge/sge819
You will now be asked about port configuration for the master, normally you would choose the default (2) which uses the /etc/services file
Accept the sge_qmaster info
You will now be asked about port configuration for the master, normally you would choose the default (2) which uses the /etc/services file
Accept the sge_execd info
Leave the cell name as “default”
Enter an appropriate cluster name when requested
Leave the spool dir as is
Press “n” for no windows hosts!
Press “y” (permissions are set correctly)
Press “y” for all hosts in one domain
If you have Java available on your Qmaster and wish to use SGE Inspect or SDM then enable the JMX MBean server and provide the requested information – probably answer “n” at this point!
Press enter to accept the directory creation notification
E nter “classic” for classic spooling (berkeleydb may be more appropriate for large clusters)
Press enter to accept the next notice
Enter “20000-20100” as the GID range (increase this range if you have execution nodes capable of running more than 100 concurrent jobs)
Accept the default spool dir or specify a different folder (for example if you wish to use a shared or local folder outside of SGE_ROOT
Enter an email address that will be sent problem reports
Press “n” to refuse to change the parameters you have just configured
Press enter to accept the next notice
Press “y” to install the startup scripts
Press enter twice to confirm the following messages
Press “n” for a file with a list of hosts
Enter the names of your hosts who will be able to administer and submit jobs (enter alone to finish adding hosts)
Skip shadow hosts for now (press “n”)
Choose “1” for normal configuration and agree with “y”
Press enter to accept the next message and “n” to refuse to see the previous screen again and then finally enter to exit the installer
命令行执行,安装NFS,将主控节点目录共享

yum -y install nfs-utils
vi /etc/exports
/sge 192.168.0.0/16(rw,sync,no_root_squash)
exportfs -ra

命令行执行,

systemctl start rpcbind nfs-server
systemctl enable rpcbind nfs-server
# 防火墙放行nfs服务
firewall-cmd --add-service=nfs
firewall-cmd --add-service=mountd
firewall-cmd --add-service=rpc-bind
firewall-cmd --add-port=992/udp --permanent
firewall-cmd --add-port=6444/tcp --permanent
firewall-cmd --add-port=6445/tcp --permanent
systemctl restart firewalld

至此qmaster主控节点安装配置完毕!

2. 计算节点安装(以compute01为例)

命令行执行,安装依赖库

yum -y install hwloc-devel

命令行执行,修改hostname

hostnamectl set-hostname compute01.local

命令行执行,修改hosts文件,添加主控节点和两个计算节点信息

vi /etc/hosts
192.168.98.134 qmaster.local qmaster
192.168.98.135 compute01.local compute01
192.168.98.136 compute02.local compute02

命令行执行,添加sgeadmin用户组,添加sgeadmin用户

groupadd -g 490 sgeadmin
useradd -u 495 -g 490 -r -m -d /home/sgeadmin -s /bin/bash -c "SGE Admin" sgeadmin

命令行执行,安装NFS,并启动服务

yum -y install nfs-utils
systemctl start rpcbind
systemctl enable rpcbind

命令行执行,创建共享目录,将主控节点目录共享至计算节点

mkdir /sge
mount -t nfs 192.168.56.101:/sge /sge
# 如果挂载超时,检查nfs server和client机器的firewalld是不是在运行
systemctl status firewalld
# 如果防火墙在运行,需要在nfs server和client机器的防火墙上都放行nfs相关服务
firewall-cmd --add-service=nfs
firewall-cmd --add-service=mountd
firewall-cmd --add-service=rpc-bind
systemctl restart firewalld
vi /etc/fstab
192.168.98.134:/sge /sge nfs defaults 0 0

命令行执行,安装计算节点

export SGE_ROOT=/sge/sge819
export SGE_CELL=default
cd $SGE_ROOT
./install_execd
cp /sge/sge819/default/common/settings.sh /etc/profile.d/

二. 测试

命令行执行,在qmaster或两台compute01、compute02均可执行qhost,查看集群主机列表

qhost
HOSTNAME        ARCH       NCPU NSOC NCOR NTHR  LOAD  MEMOUT  MEMUSE  SWAPTO   SWPUS
------------------------------------------------------------------------------------
global          -             -    -    -    -     -       -       -       -       -
compute01       lx-amd64     32    2   16   32  2.07  377.7G   42.4G    4.0G   82.5M
compute02       lx-amd64     32    2   16   32  0.04  377.7G    2.8G    4.0G   77.2M

可以通过提交一个简单的任务(job),测试SGE的功能。
这个任务是打印当前执行及其的Linux内核版本号。在任意一个计算节点(如compute01),命令行执行,vi编辑任务执行脚本

vi name.sge
#!/bin/bash
uname -a

命令行执行,使用qsub提交任务并执行

qsub uname.age
You job 1("uname.age") has been submitted

执行完毕后,您可以在执行任务的路径下看到任务运行得到的日志输出(包括错误日志)

ls
uname.sge.e1  uname.sge.o1
cat uname.sge.o1
Linux compute01.local 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 GUN/Linux

三. SGE操作

部署完毕SGE后,会生成一个默认主机用户组@allhosts,它包含所有的执行节点;生成一个默认的all.q队列名,它包含所有节点所有计算资源。默认的队列包含的计算资源是最大的。 通过使用命令qconf -mq queuename来对队列进行配置。修改hostlist来配置该队列可以使用执行主机;修改slots来配置各台执行主机可使用的线程数。从而对队列的计算资源进行设置。
使用qconf命令对SGE进行配置:

qconf -ae hostname     添加执行主机  
qconf -de hostname     删除执行主机  
qconf -sel     显示执行主机列表  
qconf -ah hostname     添加管理主机  
qconf -dh hostname     删除管理主机  
qconf -sh     显示管理主机列表  
qconf -as hostname     添加提交主机  
qconf -ds hostname     删除提交主机  
qconf -ss     显示提交主机列表  
qconf -ahgrp groupname     添加主机用户组  
qconf -mhgrp groupname     修改主机用户组  
qconf -shgrp groupname     显示主机用户组成员  
qconf -shgrpl     显示主机用户组列表  
qconf -aq queuename     添加集群队列  
qconf -dq queuename     删除集群队列  
qconf -mq queuename     修改集群队列配置  
qconf -sq queuename     显示集群队列配置  
qconf -sql     显示集群队列列表  
qconf -ap PE_name     添加并行化环境  
qconf -mp PE_name     修改并行化环境  
qconf -dp PE_name     删除并行化环境  
qconf -sp PE_name     显示并行化环境  
qconf -spl     显示并行化环境名称列表  
qstat -f     显示执行主机状态  
qstat -u user     查看用户的作业  
qhost     显示执行主机资源信息  

使用qsub提交作业
qsub简单示例:

$ qsub -V -cwd -o stdout.txt -e stderr.txt run.sh

其中run.sh中包含需要运行的程序,其内容示例为如下三行:

#!/bin/bash
#$ -S /bin/bash
perl -e 'print "abc\n";print STDERR "123\n";'

qsub的常用参数:
-V
将当前shell中的环境变量输出到本次提交的任务中。
-cwd
在当前工作目录下运行程序。默认设置下,程序的运行目录是当前用户在其计算节点的家目录。
-o
将标准输出添加到指定文件尾部。默认输出文件名是$job_name.o$job_id。
-e
将标准错误输出添加到指定文件尾部。默认输出文件名是$job_name.e$job_id。
-q
指定投递的队列,若不指定,则会尝试寻找最小负荷且有权限的队列开始任务。
-S
指定运行run.sh中命令行的软件,默认是tcsh。推荐使用bash,设置该参数的值为 /bin/bash 即可,或者在run.sh文件首部添加一行#$ -S /bin/bash。若不设置为bash,则会在标准输出中给出警告信息:Warning: no access to tty (Bad file descriptor)。
-hold_jid
后接多个使用逗号分隔的job_id,表示只有在这些job运行完毕后,才开始运行此任务。
-N
设置任务名称。默认的job name为qsub的输入文件名。
-p
设置任务优先级。其参数值范围为 -1023 ~ 1024 ,该值越高,越优先运行。但是该参数设置为正数需要较高的权限,系统普通用户不能设置为正数。
-j y|n
设置是否将标准输出和标准错误输出流合并到 -o 参数结果中。
-pe
设置并行化环境。
任务提交后的管理:
$ qstat -f
查看当前用户在当前节点提交的所有任务,任务的状态有4中情况:
– qw,等待状态,刚提交任务的时候是该状态,一旦有计算资源了会马上运行;
– hqw,该任务依赖于其它正在运行的job,待前面的job执行完毕后再开始运行,qsub提交任务的时候使用-hold_jid参数则会是该状态;
– Eqw,投递任务出错;
– r,任务正在运行;
– s,被暂时挂起,往往是由于优先级更高的任务抢占了资源;
– dr,节点挂掉后,删除任务就会出现这个状态,只有节点重启后,任务才会消失。
$ qstat -j jobID
按照任务id查看
$ qstat -u user
按照用户查看
$ qdel -j jobID
删除任务
创建sge队列

0 0 投票数
文章评分
订阅评论
提醒
guest
0 评论
内联反馈
查看所有评论