您的位置:首页 > 运维架构

运维系统自动化安装

2017-10-10 11:42 399 查看

实验1:制作启动iso迷你版,yum源依赖网络

1.创建引导光盘,复制光盘下的isolinux文件夹到指定的刻录光盘的目录下cp -r /misc/cd/isolinux/ /app/iso2.编辑菜单项isolinux.cfg加上一个图形化安装和mini模式安装,一个本地安装和手动安装vim/app/iso/isolinux/isolinux.cfg(下面这些都是可以更改的)menu title Welcome to CentOSAutoinstall!labellinux menu label AutoInstall a ^desktop system kernel vmlinuz append initrd=initrd.imgks=cdrom:/ks.desktop.cfglabel mini menu label AutoInstall a mini ^system kernel vmlinuz append initrd=initrd.imgks=cdrom:/ks.mini.cfglabel mannual menu label ^mannual installed system kernel vmlinuz append initrd=initrd.img label local menu default menu label Boot from ^local drive localboot 0xffff3.把提前做好的应答文件复制到刻录光盘的根目录下 cp /root/ks.mini.cfg /app/iso/:mini版的应答文件 cp /root/ks.desktop.cfg /app/iso/:图形化的应答文件4.制作光盘镜像mkisofs -R -J-T -v --no-emul-boot --boot-load-size 4 --boot-info-table -V "Autoinstallcentosboot" -b isolinux/isolinux.bin -c isolinux/boot.cat -o/root/centos6boot.iso /app/iso5.可以把它制作成U盘启动盘,方法如下:1.ddif=centos6boot.iso of=/dev/sdb2.转换成U盘格式,因为有些U盘不支持这种格式,所以需要转换一下格式rpm -q syslinux isohybrid centos6boot.iso3.在setup参数设置中把U盘改成第一引导盘,然后重新启动选择U盘启动就可以安装系统了。易错tips:1.整个完成的目录结构如下,app/iso作为光盘的根目录:[root@Centos6mageduapp]# tree /app/iso//app/iso/├── isolinux│ ├── boot.cat│ ├── boot.msg│ ├── grub.conf│ ├── initrd.img│ ├── isolinux.bin│ ├── isolinux.cfg│ ├── memtest│ ├── splash.jpg│ ├── TRANS.TBL│ ├── vesamenu.c32│ └── vmlinuz├── ks.desktop.cfg└── ks.mini.cfg2.应答文件的路径在光盘的根目录下ks=cdrom:/ks.desktop.cfgks=cdrom:/ks.desktop.cfg3.制作光盘镜像的时候的路径一定要明确,iso文件的根路径和制作后存放的路径/root/centos6boot.iso/app/iso4.制作成优盘的时候可以试着挂载,然后查看一下mbr数据是否存在 mount /dev/sdd /mnt/iso/ hexdump -C -n 512 /dev/sdd 5.最重要的是能联网可以拿到yum源,不然就是白搭。

实验2:完整版的启动光盘的制作,包括yum源和ks文件

第一步:复制完整的光盘目录到要刻录光盘的路径下,由于光盘目录下有一些隐藏文件,我们可以直接复制整个目录过来并改名,不用提前创建目录,所以光盘的根目录就是centos6isocp -rv/misc/cd /app/centos6iso第二步:把复制过来的文件中TRANS.TBL删除掉,暂时不要,留着创建光盘可能会失败。 find /app/centos6iso/ -name TRANS.TBL -OK RM {} \;第三步:删除掉复制过来的yum源,自己创建,复制过来的不能用,只需要创建下面这个文件就可以把yum源恢复过来。 rm -rf /app/centos6iso/repodata/ createrepo -g/misc/cd/repodata/43d8fd068164b0f042845474d6a22262798b9f0d1f49ad1bf9f95b953089777d-c6-x86_64-comps.xml/app/centos6iso/第四步:创建一个目录存放应答文件 mkdir /app/centos6iso/ksdir第五步:复制制作好的应答文件到ksdir中cp/root/{ks.mini.cfg,ks.desktop.cfg} /app/centos6iso/ksdir/第六步:修改应答文件,因为yum源在制作在光盘中,所以yum源的路径需要更改成光盘。cdrom#url--url="http://172.17.0.1/centos/6"第七步:修改菜单文件isolinux.cfg,应答文件路径是在光盘根目录下的子文件ksdir目录下。defaultvesamenu.c32#prompt 1timeout 600displayboot.msgmenubackground splash.jpgmenu titleWelcome to CentOS Autoinstall!label desktop menu label Autoinstall a ^desktop system kernel vmlinuz append initrd=initrd.img ks=cdrom:ksdir/ks.desktop.cfglabel mini menu label ^Auto Install a mini system kernel vmlinuz append initrd=initrd.imgks=cdrom:ksdir/ks.mini.cfglabel mannual menu label ^mannual install a system kernel vmlinuz append initrd=initrd.img label local menu default menu label Boot from ^local drive localboot 0xffff第八步:制作光盘。 mkisofs -R -J -T -v --no-emul-boot--boot-load-size 4 --boot-info-table -V "Autoinstall centosboot" -bisolinux/isolinux.bin -c isolinux/boot.cat -o /root/centos6boot.iso/app/centos6isoTips:光盘根目录的文件夹如下:[root@Centos6mageduapp]# cd centos6iso/[root@Centos6mageducentos6iso]# lsCentOS_BuildTag EULA images ksdir RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-6 RPM-GPG-KEY-CentOS-Security-6EFI GPL isolinux Packages repodata RPM-GPG-KEY-CentOS-Debug-6 RPM-GPG-KEY-CentOS-Testing-6

实验3:在centos7实现PXE支持centos6和7的安装,cnetos6也差不多就是tftp服务的启动需要依赖于xinetd的启动,主要就是服务的启动不同。

第一步:仅主机的模式的独立网段vmnet11,vmware自带的dhcp功能禁用;禁用iptables和selinux。第二步:安装所需要的包,只需要一台主机充当tftp和dhcp服务器 yum install vsftpd dhcp tftp-server syslinux第三步:启动这几个服务,其他几个服务可以直接启动,dhcp服务启动必须要把配置文件激活,如下1、cp/usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf systemctl start dhcpd systemctl enable dhcpd2、systemctlrestart tftp systemctl enable tftp3、systemctlrestart vsftpd systemctl enable vsftpd第四步:因为安装两个系统,所以需要两张光盘的yum源和启动文件,记住光盘不要搞错了,我都掉坑了,出现装包的时候系统不兼容一直无法安装httpd,然后才用vsftpd的,一直出错浪费时间。 mkdir /var/ftp/pub/centos/{6,7} -pvvim/etc/fstab/dev/sr0/var/ftp/pub/centos/6 iso9660 defaults 0 0/dev/sr1/var/ftp/pub/centos/7 iso9660 defaults 0 0mount -a第五步:准备应答文件,和yum源放在一个地方,比较方便,然后把系统6的模板文件传过来制作应答文件并改名ks6.cfg。 mkdir /var/ftp/pub/ksdirscproot@centos6:/root/anaconda-ks.cfg /var/ftp/pub/ksdir/mv anaconda-ks.cfg ks6.cfg ks6.cfg 内容如下:# Kickstartfile automatically generated by anaconda.#version=DEVELinstallurl--url=ftp://192.168.134.162/pub/centos/6langen_US.UTF-8keyboard usnetwork--onboot yes --device eth0 --bootproto dhcp --noipv6network--onboot yes --device eth1 --bootproto dhcp --noipv6rootpw --iscrypted$6$awHNUW8Nm4cVeCHm$FFwPpGJqCFCZY/vMoFA5hw4Nz7gve2stV3mMPO9mMdqumJf837vVDkxwZ0Dq/WM/zaJczktCXaau4P83RoVFP1firewall--disableauthconfig--enableshadow --passalgo=sha512selinux--disabledtimezoneAsia/Shanghaibootloader --location=mbr--driveorder=sda --append="crashkernel=auto rhgb quiet"# Thefollowing is the partition information you requested# Note thatany partitions you deleted are not expressed# here sounless you clear all partitions first, this is# not guaranteedto workclearpart--allzerombrreboottextpart /boot--fstype=ext4 --size=1024part /--fstype=ext4 --size=51200part /app--fstype=ext4 --size=51200part swap--size=4096%packages@base@chinese-support@core@debugging@basic-desktop@desktop-platform@fonts@general-desktop@graphical-admin-tools@input-methods@internet-applications@internet-browser@java-platform@network-file-system-client@office-suite@print-client@remote-desktop-clients@server-platform@server-policy@workstation-policy@x11mtoolspax%endksvalidatorks7.cfg:检查语法 ks7.cfg内容如下:# Systemauthorization informationauth--enableshadow --passalgo=sha512# Use CDROMinstallation mediaurl--url=ftp://192.168.134/pub/centos/7# Usegraphical installtextreboot# Run the SetupAgent on first bootfirstboot--disableignoredisk--only-use=sda# Keyboardlayoutskeyboard--vckeymap=us --xlayouts='us'# Systemlanguagelangen_US.UTF-8# Networkinformationnetwork --bootproto=dhcp --device=ens33--onboot=on --ipv6=auto --activatenetwork --hostname=localhost.localdomain# Rootpasswordrootpw--iscrypted$6$VWWsz3IDVWgWQxru$IctzHzYw.xr21EW.2FgNgLbkDec5U83f9FLbBGopY4X6dvmqPx790lKGECpPYADdrGQDCZhvTVGvqu2b8.ZAF/# Systemservicesservices--enabled="chronyd"# SystemtimezonetimezoneAmerica/New_York --isUtcuser--name=magedu--password=$6$m.LU6qXZO229yz/g$7885C9c9HhQoM8yVi1C7b.vg1vCK4K0f8b0rhER5wmY/J7hfa0vTy./uZW.1ts5j5ve0ejW/v9caMmIvttJfz1--iscrypted --gecos="magedu"# X WindowSystem configuration informationxconfig --startxonboot# Systembootloader configurationzerombrbootloader--location=mbr --boot-drive=sdaautopart--type=plain# Partitionclearing informationclearpart--all --initlabel --drives=sdaskipx%packages@^graphical-server-environment@base@core@desktop-debugging@dial-up@fonts@gnome-desktop@guest-agents@guest-desktop-agents@hardware-monitoring@input-methods@internet-browser@multimedia@print-client@x11%end%addoncom_redhat_kdump --enable --reserve-mb='auto'%end%anacondapwpolicy root--minlen=6 --minquality=50 --notstrict --nochanges --notemptypwpolicy user--minlen=6 --minquality=50 --notstrict --nochanges --notemptypwpolicy luks--minlen=6 --minquality=50 --notstrict --nochanges --notempty%endksvalidatorks7.cfg 检查语法第六步:复制菜单文件和pxelinux.0到tftpboot下,并且创建一个default的菜单文件。tftpboot相当于就是系统的根目录。 cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot/ mkdir /var/lib/tftpboot/pxelinux.cfg cp /var/ftp/pub/centos/7/isolinux/isolinux.cfg default第七步:在tftpboot下创建两个文件夹存放centos7和centos6的启动文件。 mkdir /var/lib/tftpboot/centos6 mkdir /var/lib/tftpboot/centos7 cp/var/ftp/pub/centos/6/isolinux/initrd.img /var/lib/tftpboot/centos6 cp /var/ftp/pub/centos/6/isolinux/vmlinuz /var/lib/tftpboot/centos6 cp /var/ftp/pub/centos/7/isolinux/vmlinuz /var/lib/tftpboot/centos7 cp/var/ftp/pub/centos/7/isolinux/initrd.img /var/lib/tftpboot/centos7第八步:编写菜单vim/var/lib/tftpboot/pxelinux.cfg/defaultdefaultmenu.c32timeout 600menu titleCentOS Linux 7label centos7 menu label Auto Install CentOS Linux ^7 kernel centos7/vmlinuz append initrd=centos7/initrd.imgks=ftp://192.168.134.162/pub/ksdir/ks7.cfglabel centos6 menu label Auto install Centos linux ^6 kernel centos6/vmlinuz append initrd=centos6/initrd.img ks=ftp://192.168.134.162/pub/ksdir/ks6.cfglabelmannualcentos6 menu label ^mannual install centos linux6 kernel centos6/vmlinuz append initrd=centos6/initrd.imginst.repo=ftp://192.168.134.162/centos/6/label local menu default menu label Boot from ^local drive laocalboot 0xffffmenu end第九步:新建一个虚拟机,在同一个网段,不然拿不到yum源和应答文件整个步骤具体的文件目录如下:1、/var/lib/tftpboot├── centos6│ ├── initrd.img│ └── vmlinuz├── centos7│ ├── initrd.img│ └── vmlinuz├── menu.c32├── pxelinux.0└── pxelinux.cfg └── default2、[root@centos7pub]# lscentos ksdir[root@centos7pub]# cd centos/[root@centos7centos]# ls6 7[root@centos7centos]# cd ..[root@centos7pub]# cd ksdir/[root@centos7ksdir]# lsks6.cfg ks7.cfg

实验4:cobbler 实现PXE安装

首先禁用iptales和selinux,然后找一个独立的网段,仅主机模式。第一步:安装cobbler软件它相当于代理装了tftp ,http,,它属于epel源,安装dhcp软件 yum install cobbler dhcp 第二步:启动各个服务,不包括dhcp,它现在还没有配置文件systemctlenable cobblerd httpd tftp dhcpdsystemctlstart cobblerd httpd tftp 第三步:环境检查cobbler,报出8条错误,一共有四条需要改的地方。cobbler checkvim/etc/cobbler/settingsnext_server: 自己的主机ipserver: 自己的主机ipdefault_password_crypted:"$1$loV1KZf9$mb82i2T9N3UOWGmHWojOP0" opensslpasswd -1 生成口令 systemctlrestart cobblerd重新启动服务 第四步:在第三步的基础上还需下载一个启动文件如果当前节点可以访问互联网,根据提示执行“cobbler getloaders”命令即可;否则,需要安装syslinux程序包,而后复制/usr/share/syslinux/{pxelinux.0,memu.c32}等文件至/var/lib/cobbler/loaders/目录中,一般都是直接复制到/var/lib/tftpboot/下面。然后同步数据cobbler sync。 第五步:准备dhcp服务器了,让cobbler直接代理dhcp服务器,然后直接改动模板文件就会生成dhcp的配置文件,然后就可以启动dhcp服务器了。vim/etc/cobbler/settingsmanage_dhcp:1 vim /etc/cobbler/dhcp.templatesubnet192.168.134.0 netmask 255.255.255.0 { option subnet-mask 255.255.255.0; range dynamic-bootp 192.168.134.100 192.168.134.254; default-lease-time 21600; max-lease-time 43200; next-server $next_server; class "pxeclients" { match if substring (optionvendor-class-identifier, 0, 9) = "PXEClient"; 同步数据cobbler sync
第六步:开始准备yum源,导入光盘然后查询,就可以直接安装了,菜单文件默认已经配置好了。obbler import--path=/misc/cd/ --name=centos7.3 cobblerdistro list查询yum源,也就是查询系统cobblerprofile list查询应答文件
第七步:可以把系统6也加进来,加上光盘,然后导入查询,可以看到两个系统。对应两个应答文件,菜单文件已经默认配置好了,不需要配置。mount/dev/sr1 /mntcobblerimport --path=/mnt --name=centos6.9cobblerdistro list查询yum源,也就是查询系统cobblerprofile list查询应答文件
第八步:它默认的应答文件都是最小化安装,如果想要自己配置应答文件可以自己导入进来,需要注意的就是应答文件必须放在它默认的路径下。cobblerprofile add --name=centos6.9desktop --distro=centos6.9-x86_64--kickstart=/var/lib/cobbler/kickstarts/ks6.cfg
第九步:自己配置的应答文件需要把yum源改成cobbler默认的yum源vim/var/lib/cobbler/kickstarts/ks6.cfg url--url=$tree 整个实验做完了,这个和单纯pxe不同的就是,应答文件和yum源在不同目录下,不可以随便放,都有默认的位置,yum源在/var/www/cobbler/ks_mirror/这个目录下,它自己会默认放在里面不用管,如果是自己的配置的应答文件需要自己放在/var/lib/cobbler/kickstarts/,当然不能忘记应答文件的yum源要指向$tree这个变量,如果是它默认的配置的应答文件就不用管了。菜单文件在var/lib/tftpboot/pxelinux.cfg会自己生成菜单文件,不需要修改了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  自动化