无人值守网络安装Linux系统

Published on 2015 - 04 - 15

无人值守网络安装Linux系统

1.安装DHCP服务

[root@CentOS6 ~]# yum -y install dhcp

安装完成后,配置DHCP

[root@CentOS6 ~]# cat /etc/dhcp/dhcpd.conf
# dhcpd.conf
# Sample configuration file for ISC dhcpd
log-facility local7;
# A slightly different configuration for an internal subnet.
subnet 172.16.0.0 netmask 255.255.0.0 {
  range 172.16.0.1 172.16.0.250;
  option domain-name-servers 8.8.8.8;
  option routers 172.16.0.254;
  default-lease-time 600;
  max-lease-time 7200;
  next-server 172.16.0.254;
  filename "pxelinux.0";
}
[root@CentOS6 ~]# service dhcpd start
[root@CentOS6 ~]# chkconfig dhcpd on

2.安装TFTP服务器

[root@CentOS6 ~]# yum -y install tftp-server
[root@CentOS6 ~]# vim /etc/xinetd.d/tftp
service tftp
{
        socket_type         = dgram
        protocol            = udp
        wait                = yes
        user                = root
        server              = /usr/sbin/in.tftpd
        server_args         = -s /var/lib/tftpboot
        disable             = no
        per_source          = 11
        cps                 = 100 2
        flags               =IPv4
}

↑ 配置说明:共享路径为/var/lib/tftpboot

将客户端所需启动文件复制到TFTP服务器

[root@CentOS6 ~]# yum -y install syslinux
[root@CentOS6 ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

将系统光盘挂载到 /media 目录下

[root@CentOS6 ~]# umount /dev/cdrom
[root@CentOS6 ~]# mount /dev/cdrom /media
[root@CentOS6 ~]# cp /media/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/
[root@CentOS6 ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@CentOS6 ~]# touch /var/lib/tftpboot/pxelinux.cfg/default
[root@CentOS6 ~]# cp /media/isolinux/isolinux.cfg\
>/var/lib/tftpboot/pxelinux.cfg/default
[root@CentOS6 ~]# chmod 644 /var/lib/tftpboot/pxelinux.cfg/default

修改启动配置文件如下:

[root@CentOS6 ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
default linux
timeout 600
display boot.msg
menu title Welcome to CentOS 6.4!
label linux
  menu label ^Install or upgrade an existing system
  menu default
  kernel vmlinuz
  append initrd=initrd.img ks=nfs:172.16.0.254:/ks/ks.cfg
lable rescue
  menu label ^Rescue installed system
  kernel vmlinuz
  append initrd=initrd.img rescue

↑ 配置说明:default 为默认选择的启动方式,下面有两个lable 默认调用第一个linux label;第二个rescue label顾名思义是救援引导模式;kernel代表指定的是系统内核文件;ks参数是指定自动应答文件的位置,实现自动安装部署。

重启TFTP服务器

[root@CentOS6 ~]# service xinetd restart
[root@CentOS6 ~]# chkconfig xinetd on

关闭防火墙,会配置防火墙的最好不要关闭,加个规则就好

[root@CentOS6 ~]# service iptables stop

3.创建自动应答配置文件

[root@CentOS6 ~]# yum -y install system-config-kickstart
[root@CentOS6 ~]# mkdir /ks/

运行system-config-kickstart 并开始配置,注意第二页使用NFS地址是172.16.0.254 目录为 /media

4.部署NFS服务器

修改NFS配置文件如下:

[root@CentOS6 ~]# vim /etc/exports
/ks 172.16.0.0/255.255.0.0(ro)
/media 172.16.0.0/255.255.0.0(ro)

启动NFS并设置为开机启动:

[root@CentOS6 ~]# service nfs start
[root@CentOS6 ~]# chkconfig nfs on

注:如果没有光盘,紧有ISO镜像文件,也可以讲ISO镜像文件挂载至/media 目录,方法如下:

[root@CentOS6 ~]# mount -o loop -t iso9660 “镜像文件” /media