1.在任何路径下建立一个文件夹如:AddHost
[[email protected] ~]# mkdir AddHost
2.在AddHost目录下创建一个AddHost.sh脚本文件和一个mac.txt主机mac地址列表
[[email protected] AddHost]#touch AddHost.sh mac.txt
3.其中AddHost.sh脚本内容如下
#!/bin/bash IP=254 RANK=0 NODE=1 COUNT=6 //6意为添加5个节点 CORES=1 //每个节点1个核心 # ##Add Host # for MAC in `cat ./mac.txt` do while [ $NODE -lt "$COUNT" ]; do echo "Adding Host node$NODE.."; rocks add host node$NODE cpus=$CORES membership=compute os=linux rack=0 rank=$RANK; rocks add host interface node$NODE iface=eth0 ip=10.1.255.$IP subnet=private name=node$NODE mac=$MAC; let IP--; let RANK++; let NODE++; break; done done # ##Set Host Boot Action rocks set host boot compute action=install # ##Sync Config rocks sync config
注:以上脚本需要根据实际情况更改
例如:要添加10个节点,每个节点8个核心,步骤如下
1.脚本需要更改的地方请看注释
#!/bin/bash IP=254 RANK=0 NODE=1 COUNT=11 //更改处1 CORES=8 //更改处2 # ##Add Host # for MAC in `cat ./mac.txt` do while [ $NODE -lt "$COUNT" ]; do echo "Adding Host node$NODE.."; rocks add host node$NODE cpus=$CORES membership=compute os=linux rack=0 rank=$RANK; rocks add host interface node$NODE iface=eth0 ip=10.1.255.$IP subnet=private name=node$NODE mac=$MAC; let IP--; let RANK++; let NODE++; break; done done # ##Set Host Boot Action rocks set host boot compute action=install # ##Sync Config rocks sync config
2.mac.txt里添加好这10台节点的mac地址,一行一个,比如
[[email protected] AddHost]# cat mac.txt
00:50:56:33:B5:C0
00:50:56:33:B5:C1
00:50:56:33:B5:C2
00:50:56:33:B5:C3
00:50:56:33:B5:C4
00:50:56:33:B5:C5
00:50:56:33:B5:C6
00:50:56:33:B5:C7
00:50:56:33:B5:C8
00:50:56:33:B5:C9
3.执行脚本即可
[[email protected] AddHost]# sh AddHost.sh
Adding Host node1..
Adding Host node2..
Adding Host node3..
Adding Host node4..
Adding Host node5..
Adding Host node6..
Adding Host node7..
Adding Host node8..
Adding Host node9..
Adding Host node10..
4.查看添加的主机列表
[[email protected] AddHost]# rocks list host
HOST MEMBERSHIP CPUS RACK RANK RUNACTION INSTALLACTION
cluster: Frontend 1 0 0 os install
node1: Compute 8 0 0 os install
node2: Compute 8 0 1 os install
node3: Compute 8 0 2 os install
node4: Compute 8 0 3 os install
node5: Compute 8 0 4 os install
node6: Compute 8 0 5 os install
node7: Compute 8 0 6 os install
node8: Compute 8 0 7 os install
node9: Compute 8 0 8 os install
node10: Compute 8 0 9 os install
5.各个节点从网络启动,即可获得相应的IP,并开始安装系统