自动化安装操作系统

一、准备阶段

(一)开机启动进入救援模式另一种方法:

1.开机选择CD-ROM 启动
2.按ESC键进入命令行模式
3.输入rescue并回车,进入救援模式
配置文件路径:[root@CentOS6 isolinux]#cat /misc/cd/isolinux/isolinux.cfg
在这里插入图片描述
cat /misc/cd/isolinux/isolinux.cfg
在这里插入图片描述

Centos6最小化安装217个包

制作应答文件:
图形化软件自动帮忙安装
1.安装图形化软件:[root@CentOS6 isolinux]#yum install system-config-kickstart
2.运行软件:[root@CentOS6 isolinux]#system-config-kickstart

运行system-config-kickstart如报错误:Could not open display because no X server is running;则需要安装xmanager并做设置,我这里只安装了Xshell才报此错误。
在这里插入图片描述

(二)ks应答文件制作

1.kickstart文件格式
可参考已经通过手动安装好的系统,家目录下的anaconda-ks.cfg文件进行修改

Centos7:

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade   1.安装或更新系统
install
# Keyboard layouts	2.键盘布局
keyboard 'us'
# Root password  3.超级管理员密码
rootpw --iscrypted $1$1RvN.G3m$HYDaYiQwPVls0U143IY3J/
# Use network installation	4.安装源
url --url="http://192.168.37.100/centos/os/7/x86_64/"
# System language	5.系统语言
lang en_US
# System authorization information    6.加密方式
auth  --useshadow  --passalgo=sha512
# Use text mode install    7.字符安装模式,非图形化安装
text
# SELinux configuration  8.关闭selinux
selinux --disabled
# Do not configure the X Window System 9.配置图形界面
skipx

# Firewall configuration 10.关闭防火墙
firewall --disabled
# Network information 11.网络设置
network  --bootproto=dhcp --device=eth0
# Reboot after installation 12.安装后重启
reboot
# System timezone	13.设置时区
timezone Asia/Shanghai
# System bootloader configuration 14.内核参数设定,更改网卡名
bootloader --append="net.ifnames=0" --location=mbr
# Clear the Master Boot Record  15.清除磁盘原有MBR
zerombr
# Partition clearing information  16.清除原有分区
clearpart --all --initlabel
# Disk partitioning information   17.创建分区
part /boot --fstype="xfs" --size=1000
part / --fstype="xfs" --size=20000
part swap --fstype="swap" --size=4000

Centos6:

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration   1.关闭系统自带防火墙
firewall --disabled
# Install OS instead of upgrade  2.安装或升级系统
install
# Use network installation	3.系统安装源
url --url="http://192.168.37.100/centos/os/6/x86_64/"
# Root password	4.超级管理员密码
rootpw --plaintext 123456
# System authorization information	5.系统加密方式
auth  --useshadow  --passalgo=sha512
# Use text mode install 6.安装系统方式,字符安装
text
# System keyboard 8.键盘布局
keyboard us
# System language	9.系统语言
lang en_US
# SELinux configuration 10.关闭selinux
selinux --disabled
# Do not configure the X Window System  11.关闭图形界面
skipx
# Installation logging level 12.日志格式
logging --level=info
# Reboot after installation 13.安装后重启
reboot
# System timezone	14.设置时区
timezone  Africa/Abidjan
# Network information	15.网卡信息
#network  --bootproto=dhcp --device=eth0 --onboot=on   Centos6的system-config-kickstart 设置网络有问题,使用root家目录中anaconda-ks.cfg网络配置做参考,或者不设置网络均可
network --onboot yes --device eth0 --bootproto dhcp --noipv6  # anaconda-ks.cfg网络配置参考
# System bootloader configuration 16.清除MBR
bootloader --location=mbr
# Clear the Master Boot Record	17.清除原来MBR
zerombr
# Partition clearing information  18.清除原来分区
clearpart --all --initlabel 
# Disk partitioning information  19.创建分区
part /boot --fstype="ext4" --size=1000
part / --fstype="ext4" --size=20000
part swap --fstype="swap" --size=2000

2.基于图形界面定制kickstart文件
注:Centos7 安装时需要将yum源名称改为[development]才可以选择Package Selection

安装system-config-kickstart包
[root@CentOS6 ~]#yum install system-config-kickstart
[root@CentOS6 ~]#system-config-kickstart

(1)基本语言时区设置
在这里插入图片描述
(2)安装方式:基于HTTP网络安装
在这里插入图片描述
(3)Boot Loader设置,centos7 内核参数中可设置:net.ifnames=0
在这里插入图片描述
(4)创建分区
在这里插入图片描述
(5)设置网络:修改设备名称
在这里插入图片描述
(6)认证:默认即可
在这里插入图片描述
(7)防火墙设置:禁用防火墙
在这里插入图片描述
(8)显示设置:不需要图形界面,需将install a graphical environment 选项 取消
在这里插入图片描述
(9)安装包选择:选择需要安装的软件包
在这里插入图片描述
(10)安装前脚本:系统安装之前执行的脚本
在这里插入图片描述
(11)安装后脚本:系统安装后执行的脚本,可设置如系统的初始化配置等
在这里插入图片描述
(12)保存kickstart文件:点击File->save选择保存路径,进行保存
在这里插入图片描述

二、PXE方式安装

1.安装相关包

yum install dhcp tftp-server httpd syslinux -y

2.准备yum安装源

[root@CentOS7 ~]lsblk
[root@CentOS7 ~]#echo '- - -' > /sys/class/scsi_host/host0/scan 
[root@CentOS7 ~]#echo '- - -' > /sys/class/scsi_host/host1/scan 
[root@CentOS7 ~]#echo '- - -' > /sys/class/scsi_host/host2/scan
[root@CentOS7 ~]#mkdir -p /var/www/html/centos/{6,7}/x86_64
[root@CentOS7 ~]#mount /dev/sr0 /var/www/html/centos/7/x86_64/
[root@CentOS7 ~]#mount /dev/sr1 /var/www/html/centos/6/x86_64/

在这里插入图片描述
3.准备kickstart文件

[root@CentOS7 data]#cp /data/ks_centos6.10_mini.cfg /var/www/html/ksdir/
[root@CentOS7 data]#cp ks_centos7_mini.cfg /var/www/html/ksdir/
[root@CentOS7 data]#vim /var/www/html/ksdir/ks_centos6.10_mini.cfg
# Use network installation
url --url="http://192.168.37.100/centos/6/x86_64/"  

在这里插入图片描述

4.配置dhcp服务:
如果是虚拟机环境,需要设置关闭自动dhcp功能!
找到编辑->虚拟网络编辑器->更改设置->取消勾选“使用本地DHCP将IP分配给虚拟机”->确定

[root@CentOS7 cd]#rpm -ql dhcp
/usr/share/doc/dhcp-4.2.5/dhcpd.conf.example
[root@CentOS7 cd]#cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example  /etc/dhcp/dhcpd.conf 

[root@CentOS7 cd]#vim /etc/dhcp/dhcpd.conf 
option domain-name "example.org";
option domain-name-servers 114.114.114.114,8.8.8.8;
default-lease-time 6000;
max-lease-time 72000; 
subnet 192.168.37.0 netmask 255.255.255.0 {
   range 192.168.37.10 192.168.37.200;
   option routers 192.168.37.2;
   next-server 192.168.37.100;
   filename "pxelinux.0";
}

5.配置TFTP服务器
[root@CentOS7 cd]#rpm -ql tftp-server
/var/lib/tftpboot
[root@CentOS7 cd]#rpm -ql syslinux
/usr/share/syslinux/menu.c32
/usr/share/syslinux/pxelinux.0
[root@CentOS7 cd]#cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

6.自定义启动菜单

[root@CentOS7 cd]#cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot/
[root@CentOS7 cd]#cp /misc/cd/isolinux/isolinux.cfg /var/lib/tftpboot/
[root@CentOS7 cd]#vim /var/lib/tftpboot/isolinux.cfg
default menu.c32
timeout 60
menu title CentOS Auto Install

label mini
  menu label Install CentOS ^Mini 7
  kernel vmlinuz
  append initrd=initrd.img ks=http://192.168.37.100/ksdir/ks_centos7_mini.cfg
label desktop
  menu label Install CentOS M^ini 6
    kernel vmlinuz
    append initrd=initrd.img ks=http://192.168.37.100/ksdir/ks_centos6.10_mini.cfg
label local
  default menu                                                                                                              
  menu label Boot from ^local drive
  localboot 0xffff
  
  [root@CentOS7 tftpboot]#mkdir pxelinux.cfg
  [root@CentOS7 tftpboot]#mv isolinux.cfg pxelinux.cfg/default

在这里插入图片描述
在这里插入图片描述

7.拷贝内核文件

[root@CentOS7 ~]#cp /misc/cd/isolinux/vmlinuz /misc/cd/isolinux/initrd.img /var/lib/tftpboot/

在这里插入图片描述
8.启动服务

[root@CentOS7 data]#systemctl start tftp
[root@CentOS7 data]#systemctl start dhcpd

9.创建新虚拟机
在这里插入图片描述
在这里插入图片描述

三、基于cobbler自动化安装系统

(一)安装软件包:yum install cobbler dhcp -y
(二)启动服务:

[root@CentOS7 ~]#systemctl start cobblerd httpd tftpd  #dhcp 目前起不来
[root@CentOS7 ~]#ss -nlut  #通过查看服务端口查看服务起来没有

(三)运行cobbler check 进行配置

[root@CentOS7 ~]#cobbler check
The following are potential configuration items that you may want to fix:

1 : The 'server' field in /etc/cobbler/settings must be set to something other than localhost, or kickstarting features will not work.  This should be a resolvable hostname or IP for the boot server as reachable by all machines that will use it.         # 指定cobbler服务器IP
2 : For PXE to be functional, the 'next_server' field in /etc/cobbler/settings must be set to something other than 127.0.0.1, and should match the IP of the boot server on the PXE network.   指定TFTP服务器IP
3 : change 'disable' to 'no' in /etc/xinetd.d/tftp   #centos7 不需要处理此项
4 : Some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run 'cobbler get-loaders' to download them, or, if you only want to handle x86/x86_64 netbooting, you may ensure that you have installed a *recent* version of the syslinux package installed and can ignore this message entirely.  Files in this directory, should you want to support all architectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.  #下载bootloader内核等相关文件
5 : enable and start rsyncd.service with systemctl  #启用此服务为了同步速度快,此项不用做
6 : debmirror package is not installed, it will be required to manage debian deployments and repositories  #此项关于deb系统,centos无需处理此项
7 : The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobbler/settings) is still set to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one    #修改默认root用户密码
8 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them   #集群相关,非集群环境无需考虑此项

Restart cobblerd and then run 'cobbler sync' to apply changes.

在这里插入图片描述
cobbler安装后,tftp服务共享目录中的文件夹已经创建
在这里插入图片描述

1.根据提示,先解决cobbler serverIP设置

vim /etc/cobbler/settings
# this is the address of the cobbler server
server: 192.168.37.100 

2.根据提示解决next-server指定tftp服务器IP地址

#if using cobbler with manage_dhcp, put the IP address
# of the cobbler server here so that PXE booting guests can find it
# if you do not set this correctly, this will be manifested in TFTP open timeouts.
next_server: 192.168.37.100

3.根据提示,修改root密码,默认密码是:cobbler

# cobbler has various sample kickstart templates stored
# in /var/lib/cobbler/kickstarts/.  This controls
# what install (root) password is set up for those
# systems that reference this variable.  The factory
# default is "cobbler" and cobbler check will warn if
# this is not changed.
# The simplest way to change the password is to run 
# openssl passwd -1
# and put the output between the "" below.
default_password_crypted: "$1$bdKI8ODk$6InoOSz5QxW0PFmLyBhrc/"   #通过openssl passwd -1 生成加密密码粘贴上去

4.设置提示以外的dhcp

# set to 1 to enable Cobbler's DHCP management features.
# the choice of DHCP management engine is in /etc/cobbler/modules.conf
manage_dhcp: 1   #1表示根据 /etc/cobbler/modules.conf模板自动生成dhcp配置文件

5.根据提示,下载内核等文件

[root@CentOS7 ~]#cobbler get-loaders

在这里插入图片描述
6.修改dhcp模板

[root@CentOS7 ~]#vim /etc/cobbler/dhcp.template
    ddns-update-style interim;
    allow booting;
    allow bootp;
    ignore client-updates;
    set vendorclass = option vendor-class-identifier;
    option pxe-system-type code 93 = unsigned integer 16;
    subnet 192.168.37.0 netmask 255.255.255.0 {   #设置dhcp分配网段
         option routers             192.168.37.2;   #设置路由网关
         option domain-name-servers 192.168.37.2;	#设置dns服务器IP
         option subnet-mask         255.255.255.0;	#设置子网掩码
         range dynamic-bootp        192.168.37.10 192.168.37.200;  #设置IP地址池范围
         default-lease-time         21600;
         max-lease-time             43200;
         next-server                $next_server;
         class "pxeclients" {
              match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
              if option pxe-system-type = 00:02 {
                      filename "ia64/elilo.efi";
              } else if option pxe-system-type = 00:06 {
                      filename "grub/grub-x86.efi";
              } else if option pxe-system-type = 00:07 {
                      filename "grub/grub-x86_64.efi";
              } else if option pxe-system-type = 00:09 {
                      filename "grub/grub-x86_64.efi";
              } else {
                      filename "pxelinux.0";
              }
         }
    
    }

7.配置完的内容还没有生效,需要重启服务,执行cobbler同步命令生效;
注:这里需要先重启在执行同步命令,如果先执行同步,dhcp配置文件不会生效

[root@CentOS7 ~]#systemctl restart cobblerd
[root@CentOS7 ~]#cobbler sync 

在这里插入图片描述

8.导入光盘系统文件生成启动菜单项

[root@CentOS7 ~]#mount /dev/sr1 /mnt    #挂载光盘
[root@CentOS7 ~]#cobbler import --path=/mnt --name=CentOS6.10-x86_64 --arch=x86_64  #导入光盘-name 指定cobbler生成yum安装源名称  --arch指定架构:因为centos CPU支持的架构很多
[root@CentOS7 ~]#du -sh /var/www/cobbler/ks_mirror/
[root@CentOS7 ~]#cat /var/lib/tftpboot/pxelinux.cfg/default  #导入光盘命令执行完毕后,菜单就自动生成了

在这里插入图片描述
9.自定义ks应答文件
9.1 修改自己的ks文件,指定cobbler的yum源

[root@CentOS7 data]#vim ks_centos6_mini.cfg 
# Use network installation
url --url="$tree"     #设定为cobbler的变量

9.2 拷贝自己的ks文件到cobbler放应答文件的目录

[root@CentOS7 data]#cp /data/ks_centos6_mini.cfg /var/lib/cobbler/kickstarts/

9.3 查看cobbler的yum安装源

[root@CentOS7 data]#cobbler distro list

9.4 查看cobbler自带的ks应答文件

[root@CentOS7 data]#cobbler profile list

9.5添加自定义ks文件

注:指定ks文件路径,即使是在cobbler的kickstart目录中也要指定绝对路径,否则cobbler无法找到
[root@CentOS7 kickstarts]#cobbler profile add --name Centos6.1-_mini --distro=CentOS6.10-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks_centos6_mini.cfg
[root@CentOS7 kickstarts]#cat /var/lib/tftpboot/pxelinux.cfg/default  #查看启动菜单配置文件
[root@CentOS7 kickstarts]#cobbler profile list	#查看ks列表

9.6删除系统自带ks文件

[root@CentOS7 kickstarts]#cobbler profile remove --name=CentOS6.10-x86_64
[root@CentOS7 kickstarts]#cobbler profile list	#查看ks列表
[root@CentOS7 kickstarts]#cat /var/lib/tftpboot/pxelinux.cfg/default	#查看启动菜单配置文件

10.创建新虚拟机
在这里插入图片描述
在这里插入图片描述

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