我的博客已遷移到xdoujiang.com請去那邊和我交流 FAI(Fully Automatic Installation,完全自動安裝)是一種無須交互就可以完成那些重複性枯燥乏味的、 常常需要手動完成的Linux安裝、自定義以及管理任務的自動化系統。現如今,FAI被用戶維護假根環境 (chroot environments),虛擬機以及服務器。它可以完成從幾個獨立系統到基於大規模基礎設施和有數千個系統組成的集羣系統的部署和安裝。 系統管理員可以利用配置空間在FAI中定義硬盤佈局、文件系統、軟件包、鍵盤佈局、時區、用戶帳號等等 一、基礎環境 1、角色、ip、版本、內核 serverA 192.168.1.20 3.2.0-4-amd64 7.8 fai-quickstart 4.0.8 isc-dhcp-server 4.2.2 tftpd-hpa 5.2-4 nfs-kernel-server 1:1.2.6-4 apache2 2.2.22-13 二、搭建本地源 1、安裝apache2(其他ftp也可以,這裏走apache2) apt-get -y install apache2-mpm-prefork 2、配置虛擬主機 1)關閉默認站點 cd /etc/apache2/sites-available && a2dissite default && a2dissite default-ssl Site default disabled. To activate the new configuration, you need to run: service apache2 reload Site default-ssl already disabled 2)刪除默認index.html文件 cd /var/www && rm -f index.html 3)複製模板 cp /etc/apache2/sites-available/default /etc/apache2/sites-available/debian7 4)開啓debian7站點 cd /etc/apache2/sites-available && a2ensite debian7 Enabling site debian7. To activate the new configuration, you need to run: service apache2 reload 5)網站快捷方式 ln -s /opt/debian7/mirror/debian.ustc.edu.cn/debian debian7 6)重啓apache2服務 /etc/init.d/apache2 restart [....] Restarting web server: apache2apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.1.20 for ServerName ... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.1.20 for ServerName . ok 3、使用apt-mirror同步鏡像源(debian7) 1)安裝包 apt-get -y install apt-mirror 2)配置 cat /etc/apt/mirror.list set base_path /opt/debian7 set mirror_path $base_path/mirror set skel_path $base_path/skel set var_path $base_path/var set cleanscript $var_path/clean.sh set defaultarch <running host architecture> set postmirror_script $var_path/postmirror.sh set run_postmirror 0 set nthreads 20 set _tilde 0 deb-amd64 http://debian.ustc.edu.cn/debian/ wheezy main contrib non-free deb-amd64 http://debian.ustc.edu.cn/debian/ wheezy-updates main contrib non-free clean http://debian.ustc.edu.cn/debian/ 3)執行同步(時間比較長 大概需要花費1個晚上時間) apt-mirror 三、安裝fai 1、安裝fai-quickstart的時候會將nfs-kernel-server tftpd-hpa isc-dhcp-server等服務安裝上的 apt-get install fai-quickstart -y Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: debconf-utils debootstrap fai-client fai-doc fai-server genisoimage isc-dhcp-server libapt-pkg-perl libarchive12 libevent-2.0-5 libfile-copy-recursive-perl libgpgme11 libgraph-perl libgssglue1 libheap-perl libnettle4 libnfsidmap2 libproc-daemon-perl libproc-processtable-perl libpth20 libtirpc1 libxml2 nfs-common nfs-kernel-server openbsd-inetd python python-minimal python2.7 python2.7-minimal reprepro rpcbind sgml-base tftpd-hpa update-inetd xml-core Suggested packages: logtail debmirror grub perl-tk wodim cdrkit-doc isc-dhcp-server-ldap gpgsm gnupg2 open-iscsi watchdog python-doc python-tk python2.7-doc binutils binfmt-support gnupg-agent inoticoming lzip sgml-base-doc syslinux-common debhelper The following NEW packages will be installed: debconf-utils debootstrap fai-client fai-doc fai-quickstart fai-server genisoimage isc-dhcp-server libapt-pkg-perl libarchive12 libevent-2.0-5 libfile-copy-recursive-perl libgpgme11 libgraph-perl libgssglue1 libheap-perl libnettle4 libnfsidmap2 libproc-daemon-perl libproc-processtable-perl libpth20 libtirpc1 libxml2 nfs-common nfs-kernel-server openbsd-inetd python python-minimal python2.7 python2.7-minimal reprepro rpcbind sgml-base tftpd-hpa update-inetd xml-core 0 upgraded, 36 newly installed, 0 to remove and 15 not upgraded. Need to get 11.0 MB of archives. After this operation, 30.1 MB of additional disk space will be used. 2、配置dhcp 1)先備份下原來配置 cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.bak 2)修改配置 cat /etc/dhcp/dhcpd.conf subnet 192.168.1.0 netmask 255.255.255.0 { range 192.168.1.22 192.168.1.24; option routers 192.168.1.1; default-lease-time 600; max-lease-time 7200; next-server 192.168.1.20; filename "fai/pxelinux.0"; } 3、配置tftp 1)備份下配置 cp /etc/default/tftpd-hpa /etc/default/tftpd-hpa.ba 2)修改配置 sed -i 's/0.0.0.0:69/192.168.1.20:69/' /etc/default/tftpd-hpa 4、配置fai 1)先備份下原來配置 cp /etc/fai/apt/sources.list /etc/fai/apt/sources.list.bak 2)修改客戶端的源 echo "deb http://192.168.1.20/debian7 wheezy main contrib non-free" > /etc/fai/apt/sources.list 3)先備份下原來配置 cp /etc/fai/fai.conf /etc/fai/fai.conf.bak 4)修改配置 echo "LOGUSER=fai" >> /etc/fai/fai.conf echo "FAI_CONFIG_SRC=nfs://192.168.1.20/srv/fai/debian7" >> /etc/fai/fai.conf 5)先備份下原來配置 cp /etc/fai/nfsroot.conf /etc/fai/nfsroot.conf.bak 6)修改配置 cat /etc/fai/nfsroot.conf FAI_CONFIGDIR=/srv/fai/debian7 FAI_DEBOOTSTRAP="wheezy http://192.168.1.20/debian7" FAI_ROOTPW='$1$kBnWcO.E$djxB128U7dMkrltJHPf6d1' NFSROOT_ETC_HOSTS="192.168.1.20" NFSROOT=/srv/fai/nfsroot TFTPROOT=/srv/tftp/fai NFSROOT_HOOKS=/etc/fai/nfsroot-hooks/ FAI_DEBOOTSTRAP_OPTS="--exclude=dhcp-client,info" 5、改名 mv /srv/fai/config/ /srv/fai/debian7 6、使用fai-setup命令使配置生效 fai-setup -v Initializing package states... Writing extended state information... Reading task descriptions... install_packages: executing chroot /srv/fai/nfsroot apt-get clean install_packages: executing chroot /srv/fai/nfsroot dpkg --configure --pending install_packages: executing chroot /srv/fai/nfsroot dpkg -C install_packages: executing chroot /srv/fai/nfsroot apt-get clean install_packages exit code: 0 `/srv/fai/nfsroot/boot/vmlinuz-3.2.0-4-amd64' -> `/srv/tftp/fai/vmlinuz-3.2.0-4-amd64' `/srv/fai/nfsroot/boot/initrd.img-3.2.0-4-amd64' -> `/srv/tftp/fai/initrd.img-3.2.0-4-amd64' TFTP environment prepared. To use it, enable the dhcpd and start a TFTP daemon on root /srv/tftp/fai. FAI packages inside the nfsroot: fai-client 4.0.8~deb7u1 fai-nfsroot 4.0.8~deb7u1 fai-setup-storage 4.0.8~deb7u1 FAI related packages inside the nfsroot: dracut 020-2 dracut-network 020-2 Waiting for background jobs to finish [1] Done nice rm -rf $deldir/../.will-now-be-deleted (wd: ~) [2]+ Running nice xz -q $NFSROOT/var/tmp/base.tar & (wd: /srv/fai/nfsroot) fai-make-nfsroot finished properly. Log file written to /var/log/fai/fai-make-nfsroot.log Adding line to /etc/exports: /srv/fai/debian7 192.168.1.20/24(async,ro,no_subtree_check) Adding line to /etc/exports: /srv/fai/nfsroot 192.168.1.20/24(async,ro,no_subtree_check,no_root_squash) Re-exporting directories for NFS kernel daemon.... FAI setup finished. Log file written to /var/log/fai/fai-setup.log 7、接下來生成default文件 1)fai-chboot -IBv -u nfs://192.168.1.20/srv/fai/debian7 default Booting kernel vmlinuz-3.2.0-4-amd64 append initrd=initrd.img-3.2.0-4-amd64 ip=dhcp FAI_FLAGS=verbose,sshd,reboot FAI_CONFIG_SRC=nfs://192.168.1.20/srv/fai/debian7 default has no IP in hex default Writing file /srv/tftp/fai/pxelinux.cfg/default for default 2)參數說明 -B Set default values for FAI_FLAGS.This is the same as -f verbose,sshd,reboot -I Same as -i but also sets FAI_ACTION=install.So a fully automatic installation will be performed. ATTENTION!This will erase most of the data on the local disks of the install clients. -v Create verbose output. -u URL Set FAI_CONFIG_SRC to URL.If not set the value from fai.conf inside the nfsroot will be used. 8、修改default配置文件 cat /srv/tftp/fai/pxelinux.cfg/default default 0 prompt 1 timeout 60 label 0 localboot 0 label debian7 kernel vmlinuz-3.2.0-4-amd64 append initrd=initrd.img-3.2.0-4-amd64 ip=dhcp root=/dev/nfs nfsroot=/srv/fai/nfsroot aufs FAI_FLAGS=verbose,sshd,reboot FAI_CONFIG_SRC=nfs://192.168.1.20/srv/fai/debian7 FAI_ACTION=install 9、添加1個共享目錄 這個是nfs的BUG echo "/srv/nfs4 134.95.9.128/25(fsid=0,ro,no_subtree_check)" >> /etc/exports 10、定義磁盤分區和啓動標記等 1)備份配置 cp /srv/fai/debian7/disk_config/FAIBASE /srv/fai/debian7/disk_config/FAIBASE.bak 2)修改配置 cat /srv/fai/debian7/disk_config/FAIBASE # example of new config file for setup-storage # # <type> <mountpoint> <size> <fs type> <mount options> <misc options> disk_config disk1 disklabel:msdos bootable:1 fstabkey:uuid primary / 25G ext4 rw,noatime,errors=remount-ro logical swap 8G swap sw logical /opt 100-100% ext4 rw,noatime,nosuid,nodev createopts="-L home -m 1" tuneopts="-c 0 -i 0" 11、定義客戶端需要安裝的軟件包 1)備份配置 cp /srv/fai/debian7/package_config/FAIBASE /srv/fai/debian7/package_config/FAIBASE.bak 2)修改配置 cat /srv/fai/debian7/package_config/FAIBASE PACKAGES aptitude DEBIAN cron debconf-utils file hdparm less linuxlogo rdate openssh-client openssh-server strace time procinfo nullmailer eject locales console-setup kbd pciutils usbutils vim wget 12、修改時區 cp /srv/fai/debian7/class/FAIBASE.var /srv/fai/debian7/class/FAIBASE.var.bak sed -i "s/TIMEZONE=.*/TIMEZONE=Asia\/Shanghai/g" /srv/fai/debian7/class/FAIBASE.var 13、重啓所有服務 1)重啓dhcp服務 /etc/init.d/isc-dhcp-server restart [FAIL] Stopping ISC DHCP server: dhcpd failed! [ ok ] Starting ISC DHCP server: dhcpd. 2)重啓tftpd服務 /etc/init.d/tftpd-hpa restart [ ok ] Restarting HPAs tftpd: in.tftpd. 3)重啓nfs /etc/init.d/nfs-kernel-server restart [ ok ] Stopping NFS kernel daemon: mountd nfsd. [ ok ] Unexporting directories for NFS kernel daemon.... [....] Exporting directories for NFS kernel daemon...exportfs: Failed to stat /srv/nfs4: No such file or directory . ok [ ok ] Starting NFS kernel daemon: nfsd mountd. 四、安裝client 點F12進入pxe網絡引導模式在boot提示下輸入debian7開始安裝
(默認密碼是fai 在cat /srv/fai/debian7/class/FAIBASE.var這個文件中也可以看到默認密碼是fai)
五、相關日誌 1、查看相關日誌 cat /var/log/syslog Oct 8 16:42:15 debian dhcpd: DHCPDISCOVER from 00:0c:29:7a:e6:5f via eth0 Oct 8 16:42:15 debian dhcpd: DHCPOFFER on 192.168.1.22 to 00:0c:29:7a:e6:5f ((none)) via eth0 Oct 8 16:42:15 debian dhcpd: DHCPREQUEST for 192.168.1.22 (192.168.1.20) from 00:0c:29:7a:e6:5f ((none)) via eth0 Oct 8 16:42:15 debian dhcpd: DHCPACK on 192.168.1.22 to 00:0c:29:7a:e6:5f ((none)) via eth0 六、參考文章 http://fai-project.org/fai-guide.html http://fai-project.org http://fai-project.org/doc/man/fai-chboot.html https://wiki.debian.org/DebianEdu/HowTo/FaiInstallDebianEdu