自由论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 491|回复: 1
打印 上一主题 下一主题

无人值守安装

[复制链接]

85

主题

97

帖子

9663

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
9663
跳转到指定楼层
楼主
发表于 2015-12-13 17:14:25 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

关于vmware的删除
# vmware-uninstall  --用此命令查看帮助
# vmware-installer -l
Product Name         Product Version     
==================== ====================
vmware-workstation   8.0.2.591240

# vmware-uninstall -u vmware-workstation    --用此命令可以卸载这个软件



安装方法
软件包路径在我的  /share/soft/vmware/目录,可以使用nfs挂载拷过去

# chmod 755 VMware-Workstation-Full-8.0.2-591240.x86_64.bundle     --对这个文件给执行权限

# ./VMware-Workstation-Full-8.0.2-591240.x86_64.bundle     --用此命令执行安装




====================================================



kickstart


kickstart(pxe)    无人值守安装  (自动批量安装)
Cobbler(修鞋匠)   



vim /root/anaconda-ks.cfg
vim /root/install.log


基于pxe(preboot execute environment)技术
pxe是intel公司的技术,工作server/client的网络模式,支持客户端从服务端下载软件,再使用tftp(trival  file tranfer protocol) 协议下载一个启动软件包到客户端内存中执行。



tftp    简单文件传输协议,提供简单的,不可靠的文件传输。基于UDP的69端口。



要求的技术和服务:

1。nfs服务器或者用http,ftp三种协议之一  (共享安装光盘目录文件)
2。tftp服务器    --共享启动软件包
3。dhcp服务器    --客户端获取IP,网关,DNS指向,主机名,NIS域,NTP
4。kickstart程序生成的ks.cfg配置文件(此文件就定义了安装系统如何分区,如何格式化,root密码等等)   取一个安装名字,可以由客户端自动选择是否用此安装名安装


满足上面的1,2,3三点,就是安装服务器(类似第一天来学习时的安装系统的网络服务器)



客户端(支持pxe的网卡)选择网络启动--通过dhcp获取IP可以和服务器通迅--通过tftp下载系统引导文件--按照ks.cfg配置文件里的方式来自动安装操作系统--在安装最后一步要安装软件包,会按照ks.cfg里配置的软件包来安装


--我们这里用一个虚拟机做服务器,另一个虚拟机做客户端,并使用host-only(vmnet1)网络,防止都在同一个网络造成dhcp获取混乱




        kickstart server    -------    client
        192.168.0.2/24

安装前准备:
1,关闭iptables,selinux
2,配置静态IP
3,配置yum




第一步:
在kickstart server上搭建安装源 (光盘目录文件)

你可以在宿主机上把iso镜像拷到kickstart server里,或者直接在光驱里挂载

我这里直接把宿主机里的镜像/share/soft/rhel-server-6.5-x86_64-dvd.iso直接放到kickstart server虚拟机的光驱里

# mkdir /yum        
# mount /dev/cdrom /yum     --经测试,这里不要使用autofs自动挂载的目录/misc/cd来做,因为用nfs共享它会造成客户端无法nfs挂载,所以这里使用自己建立的目录

# ls /yum    --确认里面有镜像里的相关文件
# echo "mount /dev/cdrom /yum" >> /etc/rc.local


# vim /etc/exports
/yum  *(ro)  --加上这句把光盘文件共享


重启服务使之生效
# /etc/init.d/nfs restart
# chkconfig nfs on



第二步:
在kickstart server上配置tftp服务器

# yum install tftp-server -y

# vim /etc/xinetd.d/tftp

service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -t -s -v /var/lib/tftpboot --启动参数改为-t -s -v    man in.tftpd查看,注意顺序不要去改变,否则可能会造成不能引导
        disable                 = no  --yes改为no,表示服务能用
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}


# /etc/init.d/xinetd restart
# netstat -ntlup |grep :69  
# chkconfig xinetd on


第三步:
在kickstart server上拷贝pxe启动文件到tftp的共享目录里

# yum install syslinux -y

# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
# cp /yum/isolinux/* /var/lib/tftpboot/   
# mkdir /var/lib/tftpboot/pxelinux.cfg
# cp /yum/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default


第四步:
在kickstart server上搭建DHCP服务器

# yum install dhcp -y

# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf

# vim /etc/dhcp/dhcpd.conf    --把里面默认的配置全删掉,配置我下面的一段内容(但是IP和网段你要对应的改成自己的)

next-server 192.168.0.2;    --kickstart server的IP
filename "/var/lib/tftpboot/pxelinux.0";    --上一步拷贝的pxe的文件路径
allow bootp;
allow booting;

subnet 192.168.0.0 netmask 255.255.255.0 {    --dhcp分配ip的网段
  range 192.168.0.50 192.168.0.200;        --dhcp分配的ip范围
  option domain-name-servers 192.168.0.2;    --dhcp分配给客户端的DNS指向
  option routers 192.168.0.2;            --dhcp分配给客户端的网关   
  option broadcast-address 192.168.0.255;
}

# /etc/init.d/dhcpd restart
# chkconfig  dhcpd  on


第五步:
验证网络安装服务器

新建一个虚拟机客户端(要和kickstart server相同物理网络,我这里为vmnet1),使用网络引导启动来验证

在安装过程中要注意的就是下面三点,其它的安装过程都一样的:
1,在选择安装方式里 你要选NFS directory(因为我们的安装的镜像里的文件是用nfs共享)
2, nfs server name后面 你要填你的NFS服务器IP,我这里为 192.168.0.2
3, nfs 挂载目录里 填  /yum   (对应前面第一步共享的目录)




第六步:
配置kickstart的ks文件

自定义ks文件的方法
1,如果你很熟悉此文件,直接拷别人的模版修改或者直接使用/root/anaconda-ks.cfg来修改
2,使用一个图形工具system-config-kickstart来帮助你配置(下面我就是使用这种方法)


# vim /etc/yum.repos.d/rhel-source.repo --把kickstart server服务器的yum配置文件,做成rhel6的完整配置

[server]
name=server
baseurl=file:///yum/Server
enabled=1
gpgcheck=0
[loadbalancer]
name=loadbalancer
baseurl=file:///yum/LoadBalancer
enabled=1
gpgcheck=0
[HighAvailability]
name=HighAvailability
baseurl=file:///yum/HighAvailability
enabled=1
gpgcheck=0
[ScalableFileSystem]
name=ScalableFileSystem
baseurl=file:///yum/ScalableFileSystem
enabled=1
gpgcheck=0
[ResilientStorage]
name=ResilientStorage
baseurl=file:///yum/ResilientStorage
enabled=1
gpgcheck=0



# yum install system-config-kickstart  -y


# system-config-kickstart  --使用此命令打开图形界面,进行自定义的ks.cfg文件配置
(我这里kickstart server是虚拟机,所以我宿主机ssh 192.168.0.2 -Y连接上去后,再使用
system-config-kickstart才可以打开图形)


(过程见笔记里的截图kickstart_01.png ---->  kickstart_12.png)


默认是保存到/root/ks.cfg
# vim /ks/ks.cfg   
firewall --disabled
key --skip            --在这里加上key --skip跳过输入安装码
# Install OS instead of upgrade
install
# Use NFS installation media
nfs --server=192.168.0.2 --dir=/yum
# Root password
rootpw --iscrypted $1$Iue02cNI$jxBug2glNJmSYff5tF4Gs/
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone --isUtc Asia/Shanghai
# Network information
network  --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --append="rhgb quiet" --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --asprimary --fstype="ext4" --size=100
part swap --asprimary --fstype="swap" --size=2000
part / --asprimary --fstype="ext4" --grow --size=1

%post
cat > /etc/yum.repos.d/rhel-source.repo <<EOF
[server]
name=server
baseurl=ftp://192.168.0.1/Server
enabled=1
gpgcheck=0
EOF
%end

%packages
@additional-devel
@basic-desktop
@chinese-support
@desktop-debugging
@desktop-platform
@desktop-platform-devel
@development
@eclipse
@fonts
@general-desktop
@graphical-admin-tools
@input-methods
@legacy-x
@remote-desktop-clients
@server-platform-devel
@x11

%end


修改保存之后,还需要通过nfs,ftp,http其中一种服务共享给客户端(这样客户端才能下载,并通过它自动安装)
# mkdir /ks/
# mv /root/ks.cfg /ks/    --mv你的ks.cfg文件到/ks/目录里

# vim /etc/exports
/ks    *(ro)

# /etc/init.d/nfs restart


# vim /var/lib/tftpboot/pxelinux.cfg/default  --在此文件最后定义一个安装方案

label linuxli        --label后面是无人值守安装的一个安装名称,自定义
  kernel vmlinuz         
  append initrd=initrd.img ks=nfs:192.168.0.2:/ks/ks.cfg



第七步:
使用客户端测试是否能自动安装了




===========================================================

补充一:


实现安装时连安装名都不用输入:
# vim /var/lib/tftpboot/pxelinux.cfg/default    --前三行去修改

default linuxli   --把这里改成你要安装的名字
prompt 1    --prompt单词的意思在计算机里就表示"是否确认"     
timeout 3    --时间改小

/etc/init.d/xinetd restart


==========================================================


如果你做了连安装名都不用选的kickstart(也就是只开电源就自动选择默认的安装名安装的方式),注意不要把BIOS改成网络最优先启动,这样会造成安装完后又会继续循环安装(所以建议在安装时,选择一次性网络最优先启动)



===============================

补充二:尝试实现另外两种架构(我这里假设,ks文件在/yum/ks/ks.cfg,iso的软件包全在/yum/目录下)
tftp+dhcp+http
ks=http://192.168.0.2/ks/ks.cfg    --http的写法: 家目录为yum,只写相对路径

在ks.cfg里的url那句应该为:
url --url=http://192.168.0.2


tftp+dhcp+ftp
ks=ftp://192.168.0.2/ks/ks.cfg    --ftp的写法:  如果家目录为yum,则只写它目录下的/ks/ks.cfg

在ks.cfg里的url那句应该为:
url --url=ftp://192.168.0.2



==========================================================

补充三:
题目:尝试自动安装系统后,还自动安装lamp

实现过程:
写一个lamp安装脚本,因为这种脚本很长,直接把脚本内容放到ks.cfg文件里的post-installion script的配置段,可能不太好

建议把这个安装脚本也用服务共享,下载执行;
%post
cd /root
wget http://192.168.0.2/auto_install_lamp.sh  >/dev/null 2>&1
sh /root/auto_install_lamp.sh
%end

=============================================================




cobbler


软件包路径   笔记目录program/cobbler_soft/
cobbler-2.6.3-1.el6.noarch.rpm      koan-2.6.9-1.el6.noarch.rpm
cobbler-2.6.9.tar.gz                libyaml-0.1.4-2.3.x86_64.rpm
cobbler-web-2.6.3-1.el6.noarch.rpm  PyYAML-3.10-3.1.el6.x86_64.rpm
Django14-1.4.20-1.el6.noarch.rpm




第一大步:安装cobbler
软件包有两个
cobbler-2.6.3-1.el6.noarch.rpm
cobbler-web-2.6.3-1.el6.noarch.rpm

--------------------------------------------------------
关于cobbler的这两个软件包从哪里下载
1,从官网下载,但一般为源码包,安装起来麻烦,容易出错
2,使用第三方的yum源(如epel,Extra Packages for Enterprise Linux。还有RpmForge,RpmFusion,Remi,centos,网易163等等。)
我这里就是在epel上下载的

方法一:
路径为
https://dl.fedoraproject.org/pub/epel/6Server/x86_64/   --直接在这个路径使用ctrl+F,再输入关键字搜索就可以了

方法二:
直接把epel的所有软件包做成公网的yum源
做法为直接下载下面的rpm包(不同时期,版本可能会有差异,因为有人维护,会不断更新)
https://dl.fedoraproject.org/pub ... ease-6-8.noarch.rpm
下载下来之后,直接安装这个rpm包,那么会在你的本机的/etc/yum.repos.d/目录下产生几个.repo结尾的yum配置文件,路径全部指向公网,直接就可以使用了


方法三:
如果你的网速不是很好,你可以把上面所有的软件都下载到本地,然后路径全改为本地路径就可以了

如何下载
# yum repolist    --列出你所有的软件仓库

使用reposync命令
例如:reposync  --repoid=软件仓库名字


当然cobbler也有修改源码相关的命令 cobbler repo edit


--------------------------------------------------------
# rpm -ivh cobbler-2.6.3-1.el6.noarch.rpm
warning: cobbler-2.6.3-1.el6.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
error: Failed dependencies:
    mod_wsgi is needed by cobbler-2.6.3-1.el6.noarch
    python-cheetah is needed by cobbler-2.6.3-1.el6.noarch
    PyYAML is needed by cobbler-2.6.3-1.el6.noarch
--这里的依赖性最后的PyYAML在rhel6.5的iso里不是自带的,所以要先手动上网下载并安装;上面两个依赖性在rhel6.5的iso里就有,所以可以直接使用yum来安装


PyYAML这个依赖性的rpm包在rhel6.5的iso里没有,epel源里没有,163源没有,centos源等等都没有,它的官方网站没有rpm包.可以尝试去www.rpmfind.net或rpm.pbone.net网站下载



解决的安装顺序如下:
# rpm -ivh libyaml-0.1.4-2.3.x86_64.rpm   
# rpm -ivh PyYAML-3.10-3.1.el6.x86_64.rpm
# yum install cobbler-2.6.3-1.el6.noarch.rpm


# rpm -ivh cobbler-web-2.6.3-1.el6.noarch.rpm
warning: cobbler-web-2.6.3-1.el6.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
error: Failed dependencies:
    Django is needed by cobbler-web-2.6.3-1.el6.noarch
    mod_ssl is needed by cobbler-web-2.6.3-1.el6.noarch
--第一个依赖包也是第三方的,第二个是rhel6.5的iso里自带的



解决的安装顺序如下:
# rpm -ivh Django14-1.4.20-1.el6.noarch.rpm
# yum install cobbler-web-2.6.3-1.el6.noarch.rpm


# rpm -qa |grep cobbler
cobbler-2.6.3-1.el6.noarch
cobbler-web-2.6.3-1.el6.noarch



安装完cobbler,把下面这些组件服务也安装上
#yum install  tftp* rsync xinetd httpd syslinux dhcp* pykickstart



--------------------------------

第二大步:基本配置

# cobbler check        --查看cobbler潜在的需要修改的选项(有可能因为你的httpd启不来,而选成无法显示下面的结果;按报错去解决它)
The following are potential configuration items that you may want to fix:

1 : The 'server' field in /etc/cobbler/settings must be set to something other than localhost, or kickstarting features will not work.  This should be a resolvable hostname or IP for the boot server as reachable by all machines that will use it.
2 : For PXE to be functional, the 'next_server' field in /etc/cobbler/settings must be set to something other than 127.0.0.1, and should match the IP of the boot server on the PXE network.
3 : some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run 'cobbler get-loaders' to download them, or, if you only want to handle x86/x86_64 netbooting, you may ensure that you have installed a *recent* version of the syslinux package installed and can ignore this message entirely.  Files in this directory, should you want to support all architectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.
4 : since iptables may be running, ensure 69, 80/443, and 25151 are unblocked
5 : debmirror package is not installed, it will be required to manage debian deployments and repositories
6 : The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobbler/settings) is still set to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one
7 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them


Restart cobblerd and then run 'cobbler sync' to apply changes.

--说明:上面我这里是有7个需求(不同的机器和环境可能会不一样,按照它的说明去解决就可以了)


解决需求1,需求2,需求6:
# openssl passwd -1 -salt 'werwqerwqr' '123456'        --123456为密码(这是自动安装客户端系统成功后的root登录密码),werwqerwqr为干扰码(随便写)
$1$werwqerw$.prcfrYFbwuvkD8XspayN.

# vim /etc/cobbler/settings
384 server: 192.168.0.2    --换成cobbler服务器端的IP
272 next_server: 192.168.0.2    --同上
101 default_password_crypted: "$1$werwqerw$.prcfrYFbwuvkD8XspayN."  --把密码字符串换成你上面产生的字符串


# /etc/init.d/cobblerd restart    --修改后重启
   

解决需求4:
cobbler检测到你的iptables是开启状态,它需要iptables不要禁止69,80,443,25151端口就可以了。你也可以关闭iptables

iptables -F
iptables -t nat -F
/etc/init.d/iptables stop
chkconfig iptables off


解决需求7
# yum install fence-agents


解决了上面的问题后,再次cobbler check
# cobbler check        --解决了上面的问题,只余下两个问题了(问题1可以使用cobbler get-loaders解决,但需要有外网和外网的yum源;问题2是关于debian系统的,我们这里可以忽略)
The following are potential configuration items that you may want to fix:

1 : some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run 'cobbler get-loaders' to download them, or, if you only want to handle x86/x86_64 netbooting, you may ensure that you have installed a *recent* version of the syslinux package installed and can ignore this message entirely.  Files in this directory, should you want to support all architectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.
2 : debmirror package is not installed, it will be required to manage debian deployments and repositories

Restart cobblerd and then run 'cobbler sync' to apply changes.





---------------------------------------


第三大步:导入镜像


以下是相关配置路径(默认安装) :

Cobbler 配置主要位置:/var/lib/cobbler/
snippets 代码  位置:/var/lib/cobbler/snippets/
Kickstart 模板  位置 : /var/lib/cobbler/kickstarts/
默认使用的ks文件: /var/lib/cobbler/kickstarts/default.ks
安装源镜像       位置 : /var/www/cobbler/ks_mirror/


# ls /var/www/cobbler/ks_mirror/
config



# cobbler import --path=/yum/ --name=rhel-server-6.5-x86_64 --arch=x86_64  --将挂载的镜像目录/yum位置导入到cobbler
task started: 2015-08-15_112805_import
task started (id=Media import, time=Sat Aug 15 11:28:05 2015)
Found a candidate signature: breed=redhat, version=rhel6
Found a matching signature: breed=redhat, version=rhel6
Adding distros from path /var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64:
creating new distro: rhel-server-6.5-x86_64
trying symlink: /var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64 -> /var/www/cobbler/links/rhel-server-6.5-x86_64
creating new profile: rhel-server-6.5-x86_64
associating repos
checking for rsync repo(s)
checking for rhn repo(s)
checking for yum repo(s)
starting descent into /var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64 for rhel-server-6.5-x86_64
processing repo at : /var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64
looking for /var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64/repodata
processing repo at : /var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64/ScalableFileSystem
need to process repo/comps: /var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64/ScalableFileSystem
looking for /var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64/ScalableFileSystem/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64/ScalableFileSystem/repodata
processing repo at : /var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64/LoadBalancer
need to process repo/comps: /var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64/LoadBalancer
looking for /var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64/LoadBalancer/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64/LoadBalancer/repodata
processing repo at : /var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64/HighAvailability
need to process repo/comps: /var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64/HighAvailability
looking for /var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64/HighAvailability/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64/HighAvailability/repodata
processing repo at : /var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64/ResilientStorage
need to process repo/comps: /var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64/ResilientStorage
looking for /var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64/ResilientStorage/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64/ResilientStorage/repodata
processing repo at : /var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64/Server
need to process repo/comps: /var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64/Server
looking for /var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64/Server/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64/Server/repodata
*** TASK COMPLETE ***


# ls /var/www/cobbler/ks_mirror/    --导入完后,这里会多了刚导入的镜像目录
config  rhel-server-6.5-x86_64


# cobbler distro list        --列表你cobbler导入的镜像
   rhel-server-6.5-x86_64
# cobbler profile list        --列表你的cobbler自动安装方案(从这里看到你导入一个镜像会默认做一个与它同名的安装方案)
   rhel-server-6.5-x86_64


------------------------------------




第四大步:
修改dhcp,让cobbler来管理dhcp,并进行cobbler配置同步


修改/etc/cobbler/dhcp.template,此文件是cobbler管理dhcp的模板(不需要象kickstart那样去修改/etc/dhcp/dhcpd.conf,修改了也没用,它会在后面做cobbler sync时把/etc/cobbler/dhcp.template拷过去覆盖/etc/dhcp/dhcpd.conf文件,并启动dhcp)

只修改下面这一段,改成你自己对应的IP和网段就可以了

subnet 192.168.0.0 netmask 255.255.255.0 {
     option routers             192.168.0.2;
     option domain-name-servers 192.168.0.2;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.0.200 192.168.0.254;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;
     class "pxeclients" {
          match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
          if option pxe-system-type = 00:02 {
                  filename "ia64/elilo.efi";
          } else if option pxe-system-type = 00:06 {
                  filename "grub/grub-x86.efi";
          } else if option pxe-system-type = 00:07 {
                  filename "grub/grub-x86_64.efi";
          } else {
                  filename "pxelinux.0";
          }
     }

}


# vim /etc/cobbler/settings    --再去修改这个配置文件,改成dhcp服务由cobbler来管理
242 manage_dhcp: 1        --把0改为1

# /etc/init.d/cobblerd restart    --保存后,再重启此服务



# cobbler sync        --同步cobbler配置,并初始化,帮你启动dhcp等
task started: 2015-08-15_113932_sync
task started (id=Sync, time=Sat Aug 15 11:39:32 2015)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/rhel-server-6.5-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/images/rhel-server-6.5-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
trying hardlink /usr/share/syslinux/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
copying: /usr/share/syslinux/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /usr/share/syslinux/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
copying distros to tftpboot
copying files for distro: rhel-server-6.5-x86_64
trying hardlink /var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/rhel-server-6.5-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/rhel-server-6.5-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: rhel-server-6.5-x86_64
trying hardlink /var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/rhel-server-6.5-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/rhel-server-6.5-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/rhel-server-6.5-x86_64/initrd.img
Writing template files for rhel-server-6.5-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: rhel-server-6.5-x86_64
cleaning link caches
running post-sync triggers
running python triggers from /var/lib/cobbler/triggers/sync/post/*
running python trigger cobbler.modules.sync_post_restart_services
running: dhcpd -t -q
received on stdout:
received on stderr:
running: service dhcpd restart
received on stdout: Shutting down dhcpd: [  OK  ]
Starting dhcpd: [  OK  ]

received on stderr:
running shell triggers from /var/lib/cobbler/triggers/sync/post/*
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***


# /etc/init.d/xinetd restart    --把xinetd服务重启一下


第五大步:

测试验证:新建一个vmnet1网段(因为我前面配置的是这个网段)的虚拟机,然后启动,会出现cobbler的引导安装界面,选择并自动安装


==============================================================



补充1:
cobbler的web管理


web管理路径
# /etc/init.d/httpd restart   --先最好重启一下httpd服务
重启时如果报443端口被占用,解决方法:
# /etc/init.d/vmware-workstation-server stop
# chkconfig vmware-workstation-server off



然后通过firefox访问下面的路径
http://IP/cobbler_web        --默认用户名cobbler,密码cobbler


# htdigest /etc/cobbler/users.digest "Cobbler" abc    --增加一个abc用户
Adding user abc in realm Cobbler
New password:
Re-type new password:

# cat /etc/cobbler/users.digest
cobbler:Cobbler:a2d6bae81669d707b72c0bd9806e01f3
abc:Cobbler:de5b9d396aa51c6710e62e555a2986ec



=============================================================


补充二:
关于cobbler使用ks文件的讨论


# cobbler distro list
   rhel-server-6.5-x86_64


设置profile(理解为在服务器端对每一个安装镜像做角色分类,如安装名与ks文件的关联)
distro代表导入的镜像
profile代表安装方案。一个distro可以对应一个或多个profile


# cobbler profile help    --查看帮助
# cobbler profile list    --查看有哪些profile,默认会有一个和先前导入镜像同名的profile
   rhel-server-6.5-x86_64

# cobbler profile report --name rhel-server-6.5-x86_64 |grep "^Kickstart" |head -1    --通过report报告查看名为rhel-server-6.5-x86_64的安装镜像默认使用的ks文件为/var/lib/cobbler/kickstarts/sample_end.ks
Kickstart                      : /var/lib/cobbler/kickstarts/sample_end.ks


# cobbler profile add --name=my_ks1 --distro=rhel-server-6.5-x86_64  --kickstart=/ks/ks.cfg   
--把名为rhel-server-6.5-x86_64的安装镜像再加一个名为my_ks1的安装profile,使用的是/ks/ks.cfg文件(这是上次课讲kickstart时用的,你也可以自己再准备一个都行;但这里并不建议使用kickstart使用的ks文件,如果你要自己自定义,最好是去修改cobbler里的ks模版)


# cobbler profile list        --经过上面的操作,最终我导入的rhel-server-6.5-x86_64镜像拥有两种安装方案(一个是同名的安装方案,使用/var/lib/cobbler/kickstarts/sample_end.ks自动安装文件;一个是刚自己加的安装方案名为my_ks1,使用/ks/ks.cfg自动安装文件)
   my_ks1
   rhel-server-6.5-x86_64

再次使用客户端去安装验证,会出现两种安装方案给你选择


对上面操作的扩展(仅供参考)
# cobbler profile edit --name=my_ks1 --kickstart=/ks/ks2.cfg   --将my_ks1这个profile修改一个新的ks文件
# cobbler profile remove --name=my_ks1    --删除my_ks1这个profile



=================================================================

补充三:
针对ks文件的修改的讨论
上面在补充二时提到,最好不要完全照搬kickstart使用的ks文件(因为你照搬过来后,很多功能和配置和cobbler不好连接)


以上面的名字为rhel-server-6.5-x86_64的profile使用的ks文件/var/lib/cobbler/kickstarts/sample_end.ks为例来实验ks文件的修改

vim /var/lib/cobbler/kickstarts/sample_end.ks
# kickstart template for Fedora 8 and later.
# (includes %end blocks)
# do not use with earlier distros

#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth  --useshadow  --enablemd5
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# Firewall configuration
firewall --enabled
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# Use network installation
url --url=$tree
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
# Network information
$SNIPPET('network_config')
# Reboot after installation
reboot

#Root password
rootpw --iscrypted $default_password_crypted
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone  America/New_York
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
part /boot --asprimary --fstype="ext4" --size=200
part swap --asprimary --fstype="swap" --size=2000
part / --asprimary --fstype="ext4" --grow --size=1           --这里是把原来的一句autopart改成自己想要的分区形式(原来是分lvm,现在我定义了三个分区)


%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end

%packages
$SNIPPET('func_install_if_enabled')
%end

%post --nochroot
$SNIPPET('log_ks_post_nochroot')
%end

%post
$SNIPPET('log_ks_post')
# Start yum configuration
$yum_config_stanza
# End yum configuration
$SNIPPET('post_install_kernel_options')
$SNIPPET('post_install_network_config')
$SNIPPET('func_register_if_enabled')
$SNIPPET('download_config_files')
$SNIPPET('koan_environment')
$SNIPPET('redhat_register')
$SNIPPET('cobbler_register')
# Enable post-install boot notification
$SNIPPET('post_anamon')
# Start final steps
$SNIPPET('kickstart_done')
# End final steps
touch /root/123
touch /tmp/123        --在这里又加了两句安装后的脚本,touch了两个文件
%end


保存后,用客户端安装rhel-server-6.5-x86_64来进行测试,最后发现分区和上面修改的一致,并且/root/123和/tmp/123这两个文件也都存在,说明上面的修改成功



--总结:在生产环境,你可以按这种方式把cobbler的ks文件模版,按你的需求改成几种不同的方案,再使用补充2部分里讲的cobbler profile add把这些ks文件和安装镜像对应起来做成不同的profile



========================================

补充4:
客户端使用koan与服务器的cobbler联系,实现自动重装系统

在客户端安装koan-2.6.9-1.el6.noarch.rpm软件包

# yum install koan-2.6.9-1.el6.noarch.rpm  --因为cobbler可以自动帮你解决yum的配置,所以依赖性可以直接帮你解决


# koan --server=192.168.0.2 --list=profiles       --192.168.0.2为cobbler服务器IP,得到的结果和在cobbler服务器上cobbler profile list命令得到的结果一样
   my_ks1
   rhel-server-6.5-x86_64


# koan --replace-self --server=192.168.0.2 --profile=rhel-server-6.5-x86_64  --指定本客户端按照名为rhel-server-6.5-x86_64的profile重装系统

# reboot  --敲完上面的命令,使用reboot,就会重装了(没敲上面的命令那reboot就是重启)






分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享
回复

使用道具 举报

沙发
匿名  发表于 2015-12-13 19:44:02
回复 支持 反对

使用道具

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Prostar Inc.

GMT+8, 2024-4-20 09:40 , Processed in 0.258135 second(s), 9 queries , Memcache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表