天天看點

自動化部署PXE+Kickstart VS Cobbler

自動化部署PXE+Kickstart VS Cobbler

Kickstart;無人值守安裝方式,配置檔案的問答安裝

PXE+kickstart部署

自動化部署PXE+Kickstart VS Cobbler

挂載

[root@linux-node1 ~]#mount /dev/cdrom /mnt   
##createrepo可以建立倉庫
[root@linux-node1 ~]#yum install -y httpd createrepo  
[root@linux-node1 ~]#mkdir /var/www/html/CentOS-7.1-x86_64      

把倉庫複制到本地

[root@linux-node1 ~]#cp -a /mnt/* /var/www/html/CentOS-7.1-x86_64/      

建立yum倉庫

createrepo -pdo/var/www/html/CentOS-7.1-x86_64/ /var/www/html/CentOS-7.1-x86_64/      

安裝tftp dhcp xinetd

[root@linux-node1 ~]#yum install -y tftp-server dhcp xinetd 
[root@linux-node1 ~]#vim /etc/xinetd.d/tftp   ##把tftp打開
disable                 = no      

上傳kickstart的配置檔案

[root@linux-node1 ~]#cd /var/www/html/CentOS-7.1-x86_64/      

測試能不能通路

[root@linux-node1 ~]#curl --head http://10.0.0.7/CentOS-7.1-x86_64/CentOS-7.1-x86_64.cfg
HTTP/1.1 200 OK      

應答檔案

[[email protected]_64]# cat CentOS-7.1-x86_64.cfg 
#KickstartConfigurator by Reid
#platform=x86, AMD64,or Intel EM64T
#System  language
lang en_US
#System keyboard
keyboard us
#Sytem timezone
timezone Asia/Shanghai
#Root password
#rootpw --iscrypted$default_password_crypted
rootpw --iscrypted$1$ops-node$7hqdpgEmIE7Z0RbtQkxW20
#Use text mode install
text
#Install OS instead ofupgrade
install
#Use NFS installationMedia
#url --url=$tree
url --url=http://10.0.0.7/CentOS-7.1-x86_64
#System bootloaderconfiguration
bootloader--location=mbr
#Clear the Master BootRecord
zerombr
#Partition clearinginformation
clearpart --all--initlabel 
#Disk partitioninginformation
part /boot --fstypexfs --size 1024 --ondisk sda
part swap --size 16384--ondisk sda
part / --fstype xfs--size 1 --grow --ondisk sda
#System authorizationinfomation
auth  --useshadow --enablemd5 
#Network information
#$SNIPPET('network_config')
network--bootproto=dhcp --device=eth0 --onboot=on
# Reboot afterinstallation
reboot
#Firewallconfiguration
firewall --disabled 
#SELinux configuration
selinux --disabled
#Do not configureXWindows
skipx
 
#Package installinformation
%packages
@ base
@ core
sysstat
iptraf
ntp
lrzsz
ncurses-devel
openssl-devel
zlib-devel
OpenIPMI-tools
mysql
nmap
screen
%end
 
%post
systemctl disable postfix.service
%end      

修改dhcp的配置檔案

[root@linux-node1 ~]#cd /usr/share/doc/dhcp-4.1.1/
[[email protected]]# cp dhcpd.conf.sample /etc/dhcp/dhcpd.conf
subnet 10.0.0.0netmask 255.255.255.0 {
  range dynamic-bootp 10.0.0.100 10.0.0.200;
  option subnet-mask 255.255.255.0;
  next-server 10.0.0.7;
  filename "pxelinux.0";
}      

啟動服務

[root@linux-node1 ~]#/etc/init.d/dhcpd start
[root@linux-node1 ~]#/etc/init.d/httpd start
[root@linux-node1 ~]#/etc/init.d/xinetd start
 [root@linux-node1 ~]# netstat -ntulp
Active Internetconnections (only servers)
Proto Recv-Q Send-QLocal Address               ForeignAddress             State       PID/Program name          
tcp        0     0 :::80                      :::*                        LISTEN     4055/httpd                
udp        0     0 0.0.0.0:67                 0.0.0.0:*                              4155/dhcpd          
udp        0     0 0.0.0.0:69                 0.0.0.0:*                              4165/xinetd      

tftp 裡面一些準備檔案,一些組資訊,核心鏡像,pxelinux.0

[root@linux-node1 ~]#yum install -y syslinux
[root@linux-node1 ~]#cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/   ###把pxelinux.0拷貝到tftp的啟動目錄
[root@linux-node1 ~]#cp /mnt/isolinux/* /var/lib/tftpboot/  ###拷貝啟動鏡像:vmlinuz(核心) initrd.img(映像) boot.msg(啟動選單)
[root@linux-node1 ~]#mkdir /var/lib/tftpboot/pxelinux.cfg
[root@linux-node1 ~]#cd /var/lib/tftpboot/pxelinux.cfg/
[[email protected]]# cp /mnt/isolinux/isolinux.cfg default
[[email protected]]# vim default   ##寫一個安裝的CentOS 7
label ks
  menu label ^AUTO CentOS 7
  kernel vmlinuz
  append initrd=initrd.imgks=http://10.0.0.7/CentOS-7.1-x86_64/CentOS-7.1-x86_64.cfg      

建立組資訊

[root@linux-node1 ~]#createrepo -g `ls /var/www/html/CentOS-7.1-x86_64/repodata/*-comps.xml`/var/www/html/CentOS-7.1-x86_64/      

Cobbler

可以解決Kickstart繁瑣的工作,實作自動化

安裝需要的包

[root@linux-node1 ~]#yum install cobbler cobbler-web dhcp tftp-server pykickstart  httpd -y
[root@linux-node1 ~]#/etc/init.d/httpd restart
[root@linux-node1 ~]#/etc/init.d/cobblerd start      

檢查

[root@linux-node1 ~]#cobbler check  
The following arepotential configuration items that you may want to fix:      

Step 1 + 2

vim/etc/cobbler/settings  
server: 10.0.0.7 
next_server:10.0.0.7   ###PXE的東西放置在那裡
manage_dhcp: 1    ##修改成1 ,cobbler管理dhcp      

Step 3

cobbler get-loaders      

Step 4

[root@linux-node1 ~]#vim /etc/xinetd.d/rsync
change 'disable' to'no'
[root@linux-node1 ~]#/etc/init.d/xinetd restart      

Step 5

vim/etc/cobbler/settings  
openssl passwd -1-salt 'reid' 'reid'    ###第一個reid是加嚴,第二個是密碼
default_password_crypted:"$1$reid$fXF8f078vI9J/q9XyXA8e/"
[root@linux-node1 ~]#/etc/init.d/cobblerd restart  ##修改settings重新開機
[root@linux-node1 ~]#cobbler check     ###修改完需要check      

Step 6

修改dchp.template,因為已經由cobbler修改

vim /etc/cobbler/dhcp.template
subnet 10.0.0.0netmask 255.255.255.0 {
     option routers             10.0.0.2;
     option domain-name-servers 10.0.0.2;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        10.0.0.100 10.0.0.200;
[root@linux-node1 ~]#cobbler sync   ##修改完需要同步      

Step 7

導入鏡像

[root@linux-node1 ~]#cobbler import --path=/mnt/ --name=CentOS-7.1-x86_64 --arch=x86_64  
/var/www/cobbler/ks_mirror/  ###鏡像的存入位置
[root@linux-node1 ~]#cobbler list   
distros:   ##建立一個倉庫
   CentOS-7.1-x86_64
profiles:  ##建立一個配置
   CentOS-7.1-x86_64
[root@linux-node1 ~]#cobbler profile report  ##多個要指定—name
Kickstart                      :/var/lib/cobbler/kickstarts/sample_end.ks
Kernel Options                 : {}    ###網卡要修改eth0,是以要修改kernal參數
 
KS檔案放這裡: cd /var/lib/cobbler/kickstarts/
[root@linux-node1kickstarts]# mv Cobbler-CentOS-7.1-x86_64.cfg CentOS-7.1-x86_64.cfg      

添加核心參數

cobbler profile edit--name=CentOS-7.1-x86_64--kickstart=/var/lib/cobbler/kickstarts/CentOS-7.1-x86_64.cfg
cobbler profile edit--name=CentOS-7.1-x86_64 --kopts='net.ifnames=0 biosdevname=0'  ##添加核心參數
cobbler sync      

修改Cobbler提示

vim /etc/cobbler/pxe/pxedefault.template      

用MAC位址,這裡可以設定自動安裝不提示先把本地

cobbler system add--name=reid --mac=00:0C:29:22:E1:9C --profile=CentOS-7.1-x86_64 --ip-address=10.0.0.111--subnet=255.255.255.0 --gateway=10.0.0.2 --interface=eth0 --static=1--hostname=reid.example.com --name-servers="114.114.114.1148.8.8.8"      

找一以新機器先設定BIOS:虛拟機----》電源-----》打開電源時進入固件----》boot----》Networkboot from Intel E1000(安裝完再設定回HD)

自動化部署PXE+Kickstart VS Cobbler

安裝成功

自動化部署PXE+Kickstart VS Cobbler

cobbler web介面

[root@linux-node1 ~]#cat /etc/httpd/conf.d/cobbler_web.conf  
https://10.0.0.7/cobbler_web     ##新版預設是https
username:cobbler
passoword:cobbler      
自動化部署PXE+Kickstart VS Cobbler

CentOS 7一些操作變化:

  1.取消ifconfig(需要安裝yum install net-tools),使用ip addr 檢視IP位址。  

  2.使用firewalld 取代 iptables。