centos 镜像
需要搭建的服务:tftp、dhcp、httpd、nfs等
PXE(preboot execute environment,预启动执行环境)是由Intel公司开发的最新技术,工作于Client/Server的网络模式,支持工作站通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统,在启动过程中,终端要求服务器分配IP地址,再用TFTP(trivial file transfer protocol)或MTFTP(multicast trivial file transfer protocol)协议下载一个启动软件包到本机内存中执行。
服务器或者电脑都支持PXE启动(从网卡启动),在BIOS上默认是有安装DHCP客户端和tftp客户端,所以可以利用这个来实现网络自动化安装。 从网卡启动,dhcp获取到IP,然后tftp去传递linux的内核,并启动内核。内核启动就会去加载ks文件,我们只要把安装的内容写入ks文件中就可以了。(其中ks文件中会有挂载nfs共享的RHEL/Centos安装所需的包)
安装dhcp服务:yum -y install dhcp如下图:
配置dhcp服务:cd /etc/dhcp/vim dhcpd.confddns-update-style none;#固定格式subnet 192.168.122.0 netmask 255.255.255.0 {#定义dhcp应用的网络option routers 192.168.122.90;#设置路由option subnet-mask 255.255.255.0;#设置掩码option domain-name 'example.com';#设置所属的域option domain-name-servers 192.168.122.11;#设置名字服务器的IP,如果没有名字服务器推出来的主机名跟预期的不一样pool { range 192.168.122.12 192.168.122.89;}#设置地址池,可以设置多个地址池filename '/pxelinux.0';#设置文件共享next-server 192.168.122.11;#设置共享的服务器host centos6_1 { hardware ethernet 52:54:00:e4:da:aa; fixed-address 192.168.122.12;}}#IP与MAC绑定,这个事先要知道MAC,不知道IP就会随机分配如下图:
service dhcpd start #启动dhcp服务tail -f /var/log/messages #跟踪日志,查看是否报错netstat -lntup | grep 67 #查看端口是否启动
安装tftp-server:yum -y install tftp-servertftp在centos6是依赖于xinetd服务的,所以使用yum安装,依赖会被自动安装如下图:
配置tftp服务:vim /etc/xinetd.d/tftp# default: off# description: The tftp server serves files using the trivial file transfer \# protocol. The tftp protocol is often used to boot diskless \# workstations, download configuration files to network-aware printers, \# and to start the installation process for some operating systems.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}
设置tftp的共享配置文件:cd /var/lib/tftpboot/mkdir pxelinux.cfgcd pxelinux.cfg vim defaultdefault linuxprompt 0timeout 2label linux kernel vmlinuz append ksdevice=eth0 load_ramdisk=1 initrd=initrd.img network ks=http://192.168.122.11/kickstart.cfg
安装httpd服务:yum -y groupinstall 'Web Server' #终端显示语言是英文或者yum -y groupinstall '万维网服务器' #终端显示语言是中文启动服务:service httpd start
安装nfs:yum -y install nfs-utilsvim /etc/exports/var/ftp/pub 192.168.122.0/24(ro,sync,no_root_squash)启动服务:service rpcbind restart #重启端口映射服务service nfs start
kickstart的文件可以手动写,也可以使用system-config-kickstart命令来生成,需要安装system-config-kickstart.noarch这个包。system-config-kickstart 最后保存的文件可以复制到/var/www/html/下 workstartion.cfgtextinstallkeyboard uslang en_USselinux --enforcing#langsupport --default en_US en_USnetwork --bootproto dhcpnfs --server=192.168.122.11 --dir=/var/ftp/pub # Partition 19028M%include /tmp/partitioning #mouse genericps/2 --emulthree#mouse generic3ps/2#mouse genericwheelusb --device input/micetimezone Asia/Shanghai --utc#timezone US/Central --utc#timezone US/Mountain --utc#timezone US/Pacific --utc graphical#skipxrootpw centosauth --useshadow --passalgo=md5firstboot --disablefirewall --disabledbootloader --location=mbrreboot %packages @basic-desktop@desktop-debugging@desktop-platform@fonts@general-desktop@graphical-admin-tools@input-methods@legacy-x@remote-desktop-clients@x11# KDE is huge...install it if you wish#@ KDE#@ Windows File Server#@ Web Serverelinksopensshopenssh-serveropenssh-clientsvim-enhancedsamba-commonsamba-clientgimpgimp-data-extrasenscriptlibcapntpcoreutilselfutilselfutils-libelfsgimp-print-plugingnome-icon-themegstreamergstreamer-tools#libgnomeprint22#libgnomeprintui22libgsflibIDLlibraw1394nautilus-cd-burneropenmotifpyorbitstartup-notificationttmkfdirfirefoxmuttvncgcc %post # Set the time, then set the hardware clockntpdate -b 192.168.122.254hwclock --systohc --utc# Non-destructive rebuild approachCURRENT='5'if [ -x /usr/bin/links ]; then httpget='/usr/bin/links';elif [ -x /usr/bin/lynx ]; then httpget='/usr/bin/lynx';fiif grep -qv 'without-x' /proc/cmdlinethen perl -pi -e 's,id:3:initdefault,id:5:initdefault,' /etc/inittab system-config-display --noui --set-resolution=1280x1024fi# Configure as NTP client of server1cat > /etc/ntp.conf <
mount --bind /centos_packages /var/ftp/pub或者mount -o loop /root/CentOS-6.6-x86_64-minimal.iso /var/ftp/pub/
打开客户端机子,从网卡启动。可以看到获取到IP,并去下载pxelinux。
如果是BIOS设置第一启动项是网卡,要设置回来,不然又继续装了。
要关闭selinux:setenforce 0
记得清除iptables或者加指定的端口策略:iptables -F