返回顶部

博客,半自动和自动批量安装centos系统

重点 实验一:使用 kickstart 半自动化安装CentOS系统

 

centos7的应答文件kickstat半自动启动流程

1.准备环境

关闭防火请,关闭selinux

 

使用system-config-kickstart生成kickstart配置文件,安装软件

 

[root@centos7 ~]#yum -y install  system-config-kickstart

#启动xmanger-Passive

[root@centos7 ~]#export DISPLAY=10.0.0.1:0.0

[root@centos7 ~]#system-config-kickstart

#即可进入kickstart配置文件图形终端

使用system-config-kickstart生成kickstart配置文件

2.进入kickstart图形工具界面

选择语言,键盘,时区,root密码及加密,安装重启,字符界面等

 

 

 

选择安装方式(http),配置yum源基于httpd

[root@centos8  ~]#yum -y install  httpd  ; systemctl enable --now  httpd
[root@centos8  ~]#ss -ntl
[root@centos8  ~]#mkdir -pv /var/www/html/centos/7/os/x86_64/

[root@centos8  ~]#mount /dev/sr0  /var/www/html/centos/7/os/x86_64/
#浏览器测试yum源是否可用

 

 

 

安装bootloader,设置grub密码,MBR,及内核参数

 

 

 

进行分区处理设置,

 

 

 

添加网卡名eth0 ,DHCP

 

 

 

认证默认

 

 

 

关闭防火墙,selinux

 

 

 

分区显示,默认

 

 

 

选择安装包

 

 

 

保存,退出修改配置文件

[root]#vim /etc/yum.repos.d/***.repo
[development]
#把原来"[]"内的内容改成development就可以了,其它不变

 

 

再次进去出现,如下画面,安装服务

 

 

 

 

 

 安装前脚本

 

 

 

安装后脚本

 

 

 

退出

 

生成如下centos7应答文件

[root@centos7 ~]#vim  ks7.cfg

#platform=x86, AMD64, or Intel EM64T

#version=DEVEL

# Install OS instead of upgrade

install

# Keyboard layouts

keyboard 'us'

# Root password

rootpw --plaintext centos

# System language

lang en_US

# System authorization information

auth  --useshadow  --passalgo=sha512

# Use text mode install

text

firstboot --disable

# SELinux configuration

selinux --disabled

 

 

# Firewall configuration

firewall --disabled

# Network information

network  --bootproto=dhcp --device=eth0

network  --hostname=centos7

# Reboot after installation

reboot

# System timezone

timezone Asia/Shanghai

# Use network installation

url --url="http://10.0.0.18/centos/7/os/x86_64/"

# System bootloader configuration

bootloader --append="net.ifnames=0" --location=mbr --boot-drive=sda

# Clear the Master Boot Record

zerombr

# Partition clearing information

clearpart --all --initlabel

ignoredisk --only-use=sda

# Disk partitioning information

part / --fstype="xfs" --size=100000

part /boot --fstype="xfs" --size=1024

part swap --fstype="swap" --size=2048

 

%post

useradd  wei

echo magedu|passwd  --stdin  wei

%end

 

3.进行应答文件语法检查

ksvalidator   ks7.cfg

4.创建新虚拟机,挂载ISO启动光盘/centos/7/isos/x86_64/CentOS-7-x86_64-NetInstall-2003.iso ,yum源的光盘为centos7.everything.iso

按任意键,出现如下画面

 

 

 

ESC,出现如下画面

 

 

 

5.输入应答文件的路径,及参数

[root@centos8  ~]#mkdir   /var/www/html/ksdir
#拷贝应答文件到yum源
[root@centos7 ~]#scp  ks7.cfg  10.0.0.18:/var/www/html/ksdir
The authenticity of host '10.0.0.18 (10.0.0.18)' can't be established.
ECDSA key fingerprint is SHA256:A+U7fuxAK4Z15Q9Q53+l4GJ9ITaJpMxoDH5CSUT0/7w.
ECDSA key fingerprint is MD5:41:10:85:c1:4a:63:f1:0d:e3:6d:4b:2b:48:b8:a9:25.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.18' (ECDSA) to the list of known hosts.
root@10.0.0.18's password:
ks7.cfg                     100% 1053    77.6KB/s   00:00
#并在浏览器上查看该文件是否存在

 

 

 

回车,启动

6.安装完成

 

 

 

 

 

重点 实验八:实现pxe安装双系统centos6、centos7 

 

安装前准备

关闭防火墙和Selinux,DHCP服务器静态IP

网络要求:关闭VMware软件中DHCP服务,基于NAT模式

注意:centos7使用1G内存会提示空间不足,建议2G

安装相关软件包,并启动

[root@centos8 ~]#dnf -y install dhcp-server tftp-server httpd syslinux-nonlinux

[root@centos8 ~]#systemctl enable --now httpd tftp dhcpd

 

配置DHCP服务

[root@centos8  ~]#cp  /usr/share/doc/dhcp-server/dhcpd.conf.example   /etc/dhcp/dhcpd.conf

 

[root@centos8 ~]#vim /etc/dhcp/dhcpd.conf

option domain-name "explame.org";

option domain-name-servers 180.76.76.76,  223.5.5.5;

default-lease-time 86400 ;

max-lease-time 172800;

log-facility local7;

subnet 10.0.0.0 netmask 255.255.255.0 {

    range 10.0.0.1 10.0.0.200;

    option routers 10.0.0.2;

    next-server  10.0.0.18;

    filename "pxelinux.0";

}

 

#重启DHCP服务

[root@centos8  ~]#systemctl start dhcpd

 

准备yum源和相关目录

[root@centos8 ~]#mkdir -pv /var/www/html/centos/{6,7}/os/x86_64/

[root@centos8 ~]#mount /dev/sr0 /var/www/html/centos/6/os/x86_64/

[root@centos8 ~]#mount /dev/sr1 /var/www/html/centos/7/os/x86_64/

 

准备kickstart 文件

[root@centos8 ~]#mkdir /var/www/html/ks/

[root@centos8 ~]#vim /var/www/html/ks/centos6.cfg

[root@centos8 ~]#vim /var/www/html/ks/centos7.cfg

[root@centos8 ~]#grep -Ev " (#|)" /var/www/html/ks/centos6.cfg

install

text

reboot

url --url=http://10.0.0.18/centos/6/os/x86_64/

lang en_US.UTF-8

keyboard us

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

rootpw --plaintext  centos

firewall --disabled

authconfig --enableshadow --passalgo=sha512

selinux --disabled

timezone Asia/Shanghai

bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"

zerombr

clearpart --all --initlabel

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

part / --fstype=ext4 --size=50000

part /data --fstype=ext4 --size=30000

part swap --size=2048

 

%packages

tree

vim

%end

 

%post

useradd wei

echo magedu | passwd --stdin wei &> /dev/null

mkdir /etc/yum.repos.d/bak

mv /etc/yum.repos.d/* /etc/yum.repos.d/bak

cat > /etc/yum.repos.d/base.repo <<EOF

[base]

name=base

baseurl=file:///misc/cd

gpgcheck=0

EOF

%end

 

 

 

 

 

[root@centos8 ~]#cat /var/www/html/ksdir/kss7.cfg

 

 

#platform=x86, AMD64, or Intel EM64T

#version=DEVEL

# Install OS instead of upgrade

install

# Keyboard layouts

keyboard 'us'

# Root password

rootpw --plaintext centos

# System language

lang en_US

# System authorization information

auth  --useshadow  --passalgo=sha512

# Use text mode install

text

firstboot --disable

# SELinux configuration

selinux --disabled

 

 

# Firewall configuration

firewall --disabled

# Network information

network  --bootproto=dhcp --device=eth0

network  --hostname=centos7

# Reboot after installation

reboot

# System timezone

timezone Asia/Shanghai

# Use network installation

url --url="http://10.0.0.18/centos/7/os/x86_64/"

# System bootloader configuration

bootloader --append="net.ifnames=0" --location=mbr --boot-drive=sda

# Clear the Master Boot Record

zerombr

# Partition clearing information

clearpart --all --initlabel

ignoredisk --only-use=sda

# Disk partitioning information

part / --fstype="xfs" --size=100000

part /boot --fstype="xfs" --size=1024

part swap --fstype="swap" --size=2048

 

%post

useradd  wei

echo magedu|passwd  --stdin  wei

%end

 

#最终目录结构如下

[root@centos8 ~]#tree /var/lib/tftpboot

.

├── centos6

│   ├── initrd.img

│   └── vmlinuz

├── centos7

│   ├── initrd.img

│   └── vmlinuz

├── ldlinux.c32

├── libcom32.c32

├── libutil.c32

├── menu.c32

├── pxelinux.0

└── pxelinux.cfg

   └── default

4 directories, 12 files

 

准备启动菜单文件

[root@centos8 ~]#vim /var/lib/tftpboot/pxelinux.cfg/default

 

default menu.c32

timeout 600

 

menu title Install CentOS Linux

 

label linux7

 menu label Auto Install CentOS Linux ^7

 kernel centos7/vmlinuz

 append initrd=centos7/initrd.img ks=http://10.0.0.18/ksdir/ks7.cfg  quiet

  

label linux6

 menu label Auto Install CentOS Linux ^6

 kernel centos6/vmlinuz

 append initrd=centos6/initrd.img ks=http://10.0.0.18/ksdir/ks6.cfg   quiet

 

 
测试客户端基于PXE实现自动化安装

新准备新建虚拟机主机,网卡引导,可看到看启动菜单,选择第4项网络(如下图),进入选择要安装的主机系统类型,回车即可,等待安装完成

注意:VMware workstation 对于不同的CentOS 版本,生成的虚拟机的硬件并不兼容

 

 

posted @ 2020-09-11 21:47  九尾cat  阅读(467)  评论(0编辑  收藏  举报