在前一篇博客中介绍了 Spacewalk 的安装与帐户创建,这篇博客就说说怎样配置 Spacewalk 并通过它来安装 Linux 系统。

1. 首先找到两个版本的 Linux 镜像文件,这里我使用的是 CentOS-5.11-x86_64-bin-DVD-1of2.iso 和 CentOS-6.6-x86_64-bin-DVD1.iso,然后使用下面的命令把这两个镜像文件mount到指定目录下,比如:

sudo mkdir -p /var/ftp/pub/CentOS5
sudo mount -t auto -o loop CentOS-5.11-x86_64-bin-DVD-1of2.iso /var/ftp/pub/CentOS5
sudo mkdir -p /var/ftp/pub/CentOS6
sudo mount -t auto -o loop CentOS-6.6-x86_64-bin-DVD1.iso /var/ftp/pub/CentOS6



也可以修改fstab,让系统启动时自动mount。这里我是将他们mount到了ftp的目录下。


因为比较慢,所以后面我们都只针对CentOS6来操作。




2. 登录进入系统,并访问 Channels -> Software Channel Management -> Manage Repositories -> create new repository,


这里我们需要添加两个 repository


第一个 Repository
 Repository Label*: CentOS6_repo
 Repository URL*: file:///var/ftp/pub/CentOS6 或 ftp://192.168.145.102/pub/CentOS6

第二个 Repository
 Repository Label*: spacewalk_2.2-client_rhel6_repo
 Repository URL*: http://spacewalk.redhat.com/yum/2.2-client/RHEL/6/x86_64/



注:这里可以使用在线的 Repository,比如定义在/etc/yum.repos.d/CentOS-Base.repo和/etc/yum.repos.d/epel.repo中的。但如果使用在线 Repository 的话,后面在做repo sync的时候就会非常慢,有时需要好几个小时才能同步完成。




3. 访问 Channels –> Manage Software Channels –> create new channel,在添加 Channel 页面填写如下信息


Channel Name*: CentOS6_channel
Channel Label*: centos6_channel
Architecture: x86_64 
Channel Summary*: CentOS6_channel



4. 访问 Channels –> Manage Software Channels,选择上一步创建的 Channel "CentOS6_channel",然后在其 “Repositories” 标签下选择 “CentOS6_repo” 和 “spacewalk_2.2-client_rhel6_repo” Repository,然后 “Update Repositories”。


一旦执行了“Update Repositories”以后,就会在此页面出现 “Sync”标签,此时选中 “Sync” 然后执行 “Sync Now”。


注意:


* 执行 “Sync Now” 是很耗时的操作,需要等好久才完成。可以在命令行通过查看 “ps -ef | grep sync”看有没有类似 “/usr/bin/python -u /usr/bin/spacewalk-repo-sync --channel xxx” 的进程来判断是否执行完成。


* 执行完 “Sync Now” 之后,在 Channels –> Manage Software Channels 页面的列表也就会看到 CentOS6_channel 的 Packages 列会显示具体包数。


* 另外,也可以根据需要设置定时同步操作。



5. 创建 Activation Keys,这个 Key 是 Client 用来访问 Spacewalk server 时使用的


访问 Systems –> Activation Keys –> create new key


Description: my_key
  Add-On Entitlements: 选中 Monitoring 和 Provisioning



6. 创建 Kickstartable Distributions 


访问 Systems -> Kickstart -> Distributions -> create new distribution


Distribution Label*: CentOS6_dist
  Tree Path*: /var/ftp/pub/CentOS6
  Base Channel*: CentOS6_channel
  Installer Generation*: RHEL6



7. 创建 Kickstart Profile


访问 Systems -> Kickstart -> Kickstart Profiles -> create new kickstart profile


Label*: CentOS6
  Base Channel*: CentOS6_channel
  Kickstartable Tree*: CentOS6_dist



完成后修改刚才创建的 Kickstart Profile


* 在Activation Keys里选中第五步创建的key



8. 由于Spacewalk内部也继承了Cobbler,所以我们也需要对Cobbler做一下修改


这里有一些特别的地方需要特殊对待


* 在这个版本的Cobbler中不能使用“sudo cobbler get-loaders”安装loader,而要使用“yum install cobbler-loaders”来安装


* 需要手动安装dhcp软件包"sudo yum install dhcp"


* 修改 /etc/cobbler/settings 文件,将redhat_management_server改为当前spacewalk所在机器名或者IP


redhat_management_server: 192.168.145.102



修改完Cobbler的配置后记得要执行下面的操作时期生效


sudo /etc/init.d/cobblerd restart
sudo cobbler sync



9. 部署Linux系统

9.1 首先使用 "sudo cobbler list" 来查看 profile

9.2 然后使用 “sudo cobbler system” 来添加并设置系统


sudo cobbler system add --name=test --profile=CentOS6:1:SpacewalkDefaultOrganization
sudo cobbler system edit --name=test --interface=eth0 --mac=08:00:27:2C:30:8C --ip-address=192.168.145.155 --netmask=255.255.255.0 --static=1
sudo cobbler system edit --name=test --gateway=192.168.145.1 --hostname=test
sudo cobbler sync

9.3 安装系统。如果物理机有IPMI,可以远程启动物理机。这里我使用的虚拟机做测试,所以我是手动启动虚拟机,此时就会看到虚拟机开始自动安装系统了。



10. 注册系统

10.1 访问 Systems -> Systems -> 选中机器 -> Software -> Software Channels 

查看有没有关联 Channel,如果没有可以选择一个,比如上面的创建的 “CentOS6_channel”。

10.2 登录到新安装的系统上运行

yum install -y http://yum.spacewalkproject.org/2.2-client/RHEL/6/x86_64/spacewalk-client-repo-2.2-1.el6.noarch.rpm
yum install -y http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum install -y rhn-client-tools rhn-check rhn-setup rhnsd m2crypto yum-rhn-plugin spacewalk-oscap
yum install -y http://<spacewalk_server>/pub/rhn-org-trusted-ssl-cert-1.0-1.noarch.rpm
rhnreg_ks --serverUrl=http://<spacewalk_server>/XMLRPC --sslCACert=/usr/share/rhn/RHN-ORG-TRUSTED-SSL-CERT --activationkey=<activation_key>

* 其中 <spacewalk_server> 是spacewalk所在机器,<activation_key>是在Activation Keys里创建的key

10.3 等待系统安装完成后,就可以在 Spacewalk 的 Systems -> Systems -> Physical Systems 查看新安装的机器了。