Linux集群的安装与并行计算

来源:互联网 发布:网络下载速度很不稳定 编辑:程序博客网 时间:2024/05/18 15:23

1.linux安装
       需要注意的是安装时,出于安全需要应把ssh选为可信赖的服务。安装以后,一个服务器即是为一个节点,应该保证各节点之间能够用ssh相互登录。每个节点的sshd都应该能正常提供服务。

2.创建NFS服务

       在服务器节点public目录下建立mpi目录,并将其配置成NFS服务器,在/etc/exports文件中加入一行:

                 /public/mpi  node1(rw)  node2(rw)

       在客户端节点的/etc/fstab文件中增加一行:

                sever :/pubilc/mpi  nfs  rw , bg , soft  0 0

将/public/mpi这个目录从服务器节点输出,并装载在各客户端,从而便于在各节点间分发任务。

3.修改/etc/hosts文件,将所有节点名称极其ip地址填入。例如:
         127.0.0.1 localhost.localdomain localhost
         192.168.1.1 node1
         192.168.1.2 node2

           …………………….
每个节点都进行类似的配置。这样做的目的是使节点之间能够通过node1 ... noden的名称相互访问。你可以通过ping noden 或 ssh noden进行测试。

4.修改(或创建)/etc/hosts.equiv文件
        将所有你允许访问本机进行mpi计算的机器名填入,一行一个机器名。这一步是为了使节点对其它的节点放权。
       例如,node1是用于启动mpi集群计算的机器,其他的节点是参与计算者,在node1的/etc/hosts.equiv文件是这样的:

                node1 #给自己放权,这样在只有一台机器时也可以模拟并行计算环境

                node2

                 .....
                noden
        在node2...noden的/etc/hosts.equiv文件:
               node1 #对node1放权
               node2
               ......
              noden

5.修改~/.bash_profile文件
         首先决定一个用于启动集群计算的用户名,不提倡使用root进行集群计算。这里在每个节点上建立新用户chief,他们的主目录都是/home/chief,必须采用同样的密码,将来的计算程序必须放在相同的路径上。譬如你的程序为:fpi.f和a.out,则必须把a.out放在同样的路境内,比如~/mpirun/a.out,每个节点都是如此。 修改~/.bash_profile文件,主要是加入下列几行脚本:

          export PATH=$PATH:/usr/local/mpich/bin

          export MPI_USEP4SSPORT=yes

          export MPI_P4SSPORT=22

          export P4_RSHCOMMAND=rsh 或ssh

       这里我们预定了将来mpich的运行环境安装在目录/usr/local/mpich下面。其余的三个变量是用来通知mpi运行环境采用rsh(或ssh)来作为远程shell。linux的运行环境到此就配
置完毕了。

6.配置ssh

        采用ssh作为远程shell则按如下配置:以你设定的用于启动mpi计算的用户登录,运行ssh-keygen,这将生成一个私有/公开密钥对,分别存放在~/.ssh/identity和~/.ssh/i
dentity.pub文件内。然后进行访问授权,运行:

         cp ~/.ssh/identity.pub ~/.ssh/authorized_keys

         chmod go-rwx ~/.ssh/authorized_keys

         ssh-agent $SHELL

         ssh-add
在每个节点重复一遍。试着在某一节点上登录其它节点,ssh noden,则在.ssh/下生成一个known_hosts2文件,里面放着访问该主机的密钥,把所有密钥收集起来,在各个节
点上作同样的拷贝。这样做的目的是使各节点相互之间访问无需输入密码。

7.开启各项必需的服务

        如果是以根用户root 登陆系统的则可以用ntsysv命令启动ntsysv实用程序。ntsysv 实用程序允许使用简单的菜单界面启动或关闭各种运行等级的服务。在其中我们选择开启
rsh ,rlogin,telnet等。也可以关闭一些服务以加快启动速度如sendmail。

        如果是使用su命令转为root用户的则很可能运行ntsysv并不出现ntsysvs实用程序。此时可以直接去修改/etc/xinetd.d下的rlogin, ssh ,telenet的设置。

        用vi编辑器打开xinetd.d:

           vi /etc/xinetd.d

       则可看到如下所示的配置文件:
关于rsh的设置如下
# default: off
# description: The rshd server is the server for the rcmd(3) routine and, \
#       consequently, for the rsh(1) program.  The server provides \
#       remote execution facilities with authentication based on \
#       privileged port numbers from trusted hosts.
service shell
{
       disable = yes
       socket_type             = stream
       wait                    = no
       user                    = root
       log_on_success          += USERID
       log_on_failure          += USERID
       server                  = /usr/sbin/in.rshd
}
关于rlogin的设置如下
# default: off
# description: rlogind is the server for the rlogin(1) program.  The server
\
#       provides a remote login facility with authentication based on \
#       privileged port numbers from trusted hosts.
service login
{
       disable = yes
       socket_type             = stream
       wait                    = no
       user                    = root
       log_on_success          += USERID
       log_on_failure          += USERID
       server                  = /usr/sbin/in.rlogind
}
关于telnet的设置如下
# default: off
# description: The telnet server serves telnet sessions; it uses \
# unencrypted username/password pairs for authentication.
service telnet
{
       disable = yes
       flags = REUSE
       socket_type = stream
       wait = no
       user = root
       server = /usr/sbin/in.telnetd
       log_on_failure += USERID
}
所有这些服务在安装完系统之后都是默认为禁用的,要进行修改来打开这些服务。如要
通过修改启动telenet则就需要改disable = yes为disable = no。对于其他的服务的启
动的修改与之相同。若启动这些服务则只需要简单执行:
#/etc/rc.d/init.d/xinetd restart
或重启服务器。