运维系统自动化安装


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

1.创建引导光盘,复制光盘下的isolinux文件夹到指定的刻录光盘的目录下

cp -r /misc/cd/isolinux/ /app/iso

2.编辑菜单项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.cfg

label mini

  menu label AutoInstall a mini ^system

  kernel vmlinuz

  append initrd=initrd.imgks=cdrom:/ks.mini.cfg

label mannual

  menu label ^mannual installed system

  kernel vmlinuz

  append initrd=initrd.img

label local

  menu default

  menu label Boot from ^local drive

  localboot 0xffff

3.把提前做好的应答文件复制到刻录光盘的根目录下

 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/iso

5.可以把它制作成U盘启动盘,方法如下:

1.ddif=centos6boot.iso of=/dev/sdb

2.转换成U盘格式,因为有些U盘不支持这种格式,所以需要转换一下格式

rpm -q syslinux

  isohybrid centos6boot.iso

3.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.cfg

2.应答文件的路径在光盘的根目录下

ks=cdrom:/ks.desktop.cfg

ks=cdrom:/ks.desktop.cfg

3.制作光盘镜像的时候的路径一定要明确,iso文件的根路径和制作后存放的路径

/root/centos6boot.iso/app/iso

4.制作成优盘的时候可以试着挂载,然后查看一下mbr数据是否存在

 mount /dev/sdd /mnt/iso/

 hexdump -C -n 512 /dev/sdd

5.最重要的是能联网可以拿到yum源,不然就是白搭。

 

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

第一步:复制完整的光盘目录到要刻录光盘的路径下,由于光盘目录下有一些隐藏文件,我们可以直接复制整个目录过来并改名,不用提前创建目录,所以光盘的根目录就是centos6iso

cp -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 1

timeout 600

displayboot.msg

menubackground splash.jpg

menu titleWelcome to CentOS Autoinstall!

label desktop

  menu label Autoinstall a ^desktop system

  kernel vmlinuz

  append initrd=initrd.img  ks=cdrom:ksdir/ks.desktop.cfg

label mini

  menu label ^Auto Install a mini system

  kernel vmlinuz

  append initrd=initrd.imgks=cdrom:ksdir/ks.mini.cfg

label 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/centos6iso

Tips:

光盘根目录的文件夹如下:

[root@Centos6mageduapp]# cd centos6iso/

[root@Centos6mageducentos6iso]# ls

CentOS_BuildTag  EULA images    ksdir     RELEASE-NOTES-en-US.html  RPM-GPG-KEY-CentOS-6        RPM-GPG-KEY-CentOS-Security-6

EFI              GPL   isolinux Packages  repodata                  RPM-GPG-KEY-CentOS-Debug-6  RPM-GPG-KEY-CentOS-Testing-6

 

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

第一步:仅主机的模式的独立网段vmnet11vmware自带的dhcp功能禁用;禁用iptablesselinux

第二步:安装所需要的包,只需要一台主机充当tftpdhcp服务器

 yum install vsftpd dhcp tftp-server syslinux

第三步:启动这几个服务,其他几个服务可以直接启动,dhcp服务启动必须要把配置文件激活,如下

1cp/usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf

 systemctl start dhcpd

 systemctl enable dhcpd

2systemctlrestart tftp

  systemctl enable tftp

3systemctlrestart vsftpd

  systemctl enable vsftpd

第四步:因为安装两个系统,所以需要两张光盘的yum源和启动文件,记住光盘不要搞错了,我都掉坑了,出现装包的时候系统不兼容一直无法安装httpd,然后才用vsftpd的,一直出错浪费时间。

 mkdir /var/ftp/pub/centos/{6,7} -pv

vim/etc/fstab

/dev/sr0/var/ftp/pub/centos/6 iso9660 defaults 0 0

/dev/sr1/var/ftp/pub/centos/7 iso9660 defaults 0 0

mount -a

第五步:准备应答文件,和yum源放在一个地方,比较方便,然后把系统6的模板文件传过来制作应答文件并改名ks6.cfg

 mkdir /var/ftp/pub/ksdir

scproot@centos6:/root/anaconda-ks.cfg /var/ftp/pub/ksdir/

mv  anaconda-ks.cfg ks6.cfg

 

ks6.cfg 内容如下:

# Kickstartfile automatically generated by anaconda.

#version=DEVEL

install

url--url=ftp://192.168.134.162/pub/centos/6

langen_US.UTF-8

keyboard us

network--onboot yes --device eth0 --bootproto dhcp --noipv6

network--onboot yes --device eth1 --bootproto dhcp --noipv6

rootpw  --iscrypted$6$awHNUW8Nm4cVeCHm$FFwPpGJqCFCZY/vMoFA5hw4Nz7gve2stV3mMPO9mMdqumJf837vVDkxwZ0Dq/WM/zaJczktCXaau4P83RoVFP1

firewall--disable

authconfig--enableshadow --passalgo=sha512

selinux--disabled

timezoneAsia/Shanghai

bootloader --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 work

clearpart--all

zerombr

reboot

text

part /boot--fstype=ext4 --size=1024

part /--fstype=ext4 --size=51200

part /app--fstype=ext4 --size=51200

part 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

@x11

mtools

pax

%end

ksvalidatorks7.cfg:检查语法

 

 ks7.cfg内容如下:

# Systemauthorization information

auth--enableshadow --passalgo=sha512

# Use CDROMinstallation media

url--url=ftp://192.168.134/pub/centos/7

# Usegraphical install

text

reboot

# Run the SetupAgent on first boot

firstboot--disable

ignoredisk--only-use=sda

# Keyboardlayouts

keyboard--vckeymap=us --xlayouts='us'

# Systemlanguage

langen_US.UTF-8

# Networkinformation

network  --bootproto=dhcp --device=ens33--onboot=on   --ipv6=auto --activate

network  --hostname=localhost.localdomain

# Rootpassword

rootpw--iscrypted$6$VWWsz3IDVWgWQxru$IctzHzYw.xr21EW.2FgNgLbkDec5U83f9FLbBGopY4X6dvmqPx790lKGECpPYADdrGQDCZhvTVGvqu2b8.ZAF/

# Systemservices

services--enabled="chronyd"

# Systemtimezone

timezoneAmerica/New_York --isUtc

user--name=magedu--password=$6$m.LU6qXZO229yz/g$7885C9c9HhQoM8yVi1C7b.vg1vCK4K0f8b0rhER5wmY/J7hfa0vTy./uZW.1ts5j5ve0ejW/v9caMmIvttJfz1--iscrypted --gecos="magedu"

# X WindowSystem configuration information

xconfig  --startxonboot

# Systembootloader configuration

zerombr

bootloader--location=mbr --boot-drive=sda

autopart--type=plain

# Partitionclearing information

clearpart--all --initlabel --drives=sda

skipx

%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

%anaconda

pwpolicy root--minlen=6 --minquality=50 --notstrict --nochanges --notempty

pwpolicy user--minlen=6 --minquality=50 --notstrict --nochanges --notempty

pwpolicy luks--minlen=6 --minquality=50 --notstrict --nochanges --notempty

%end

ksvalidatorks7.cfg 检查语法

第六步:复制菜单文件和pxelinux.0tftpboot下,并且创建一个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下创建两个文件夹存放centos7centos6的启动文件。

 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/default

defaultmenu.c32

timeout 600

menu titleCentOS Linux 7

label centos7

  menu label Auto Install CentOS Linux ^7

  kernel centos7/vmlinuz

  append initrd=centos7/initrd.imgks=ftp://192.168.134.162/pub/ksdir/ks7.cfg

label 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.cfg

labelmannualcentos6

  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 0xffff

menu end

第九步:新建一个虚拟机,在同一个网段,不然拿不到yum源和应答文件

整个步骤具体的文件目录如下:

1/var/lib/tftpboot

├── centos6

   ├── initrd.img

   └── vmlinuz

├── centos7

   ├── initrd.img

   └── vmlinuz

├── menu.c32

├── pxelinux.0

└── pxelinux.cfg

    └── default

2[root@centos7pub]# ls

centos  ksdir

[root@centos7pub]# cd centos/

[root@centos7centos]# ls

6  7

[root@centos7centos]# cd ..

[root@centos7pub]# cd ksdir/

[root@centos7ksdir]# ls

ks6.cfg  ks7.cfg

 

实验4cobbler 实现PXE安装 

首先禁用iptalesselinux,然后找一个独立的网段,仅主机模式。

第一步:安装cobbler软件它相当于代理装了tftp ,http,,它属于epel,安装dhcp软件

    yum install cobbler dhcp 

 

第二步:启动各个服务,不包括dhcp,它现在还没有配置文件

systemctlenable  cobblerd  httpd tftp dhcpd

systemctlstart  cobblerd httpd tftp

 

第三步:环境检查cobbler,报出8条错误,一共有四条需要改的地方。

cobbler check

vim/etc/cobbler/settings

next_server: 自己的主机ip

server: 自己的主机ip

default_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/settings

manage_dhcp:1

vim /etc/cobbler/dhcp.template

subnet192.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 /mnt

cobblerimport --path=/mnt  --name=centos6.9

cobblerdistro 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会自己生成菜单文件,不需要修改了。

 

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章