实现网络安装系统
一、首先准备一台已经安装好的centos6.9系统,关闭防火墙。
二、修改系统的yum源
三、下载dhcp,tftp,xinetd,htppd,nfs,syslinux。并修改配置文件
四、准备镜像文件
五、修改ks文件
六、测试安装
1、首先已经完成一台centos6.9系统的安装。
1.1 关闭防火墙,并加入开机不启动
service iptables stop
chkconfig iptables off
2、修改系统的yum源
1 、cd /etc/yum.repos.d
2、vim CentOS-Base.repo
3 、注释掉原先的baseurl、mirrrorlist、gpgkey。修改为如下国内yum源。
baseurl=http://mirrors.163.com/centos-vault/6.9/os/$basearch
gpgkey=http://mirrors.163.com/centos-vault/RPM-GPG-KEY-CentOS-6
(base、updates、extras、centosplus、contrib都需要修改),保存后退出。
三、下载dhcp,tftp,http,xinetd,syslinux,nfs
1、yum install -y http* dhcp tftp xinetd syslinux nfs*
2、修改DHCP配置文件,直接复制后,修改IP就可以。
[root@pxe ~]# vim /etc/dhcp/dhcpd.conf
default-lease-time 600;
max-lease-time 7200;
option space pxelinux;
option pxelinux.magic code 208 = string;
option pxelinux.configfile code 209 = text;
option pxelinux.pathprefix code 210 = text;
option pxelinux.reboottime code 211 = unsigned integer 32;
option architecture-type code 93 = unsigned integer 16;
subnet 192.168.56.0 netmask 255.255.255.0 {
range 192.168.56.101 192.168.56.200;
next-server 192.168.56.101;
if option architecture-type = 00:07 {
filename "uefi/shim.efi";
} else {
filename "pxelinux/pxelinux.0";
}
}
启动dhcp服务
[root@pxe ~]# service dhcpd start
设置开机自启
[root@pxe ~]# chkconfig dhcpd on
3 TFTP使用Xinetd服务管理,编辑/etc/xinetd.d/tftp 将文件中disable的参数由yes修改为no
vim /etc/xinetd.d/tftp
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
4 启动xinetd服务,并加入开机自启
[root@pxe ~]# service xinetd start
Starting xinetd:
[root@pxe ~]# chkconfig xinetd on
5 配置PXE引导启动程序
PXE启动映像文件由syslinux软件提供,只要安装了syslinux,就会生成一个pxelinux.0文件,将这个文件复制到TFTP默认路径即可。syslinux是一个功能强大的引导加载程序
[root@CentOSPXEServer~]# yum install syslinux
[root@CentOSPXEServer~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@CentOSPXEServer~]# cd /var/lib/tftpboot/
[root@CentOSPXEServertftpboot]# ll -trh
total28K
-rw-r--r--.1 root root 27K Oct 20 19:24 pxelinux.0
6 接下来挂载CentOS6.9的启动DVD镜像到/mnt/cdrom目录(挂载系统方式皆相同)
依次挂载centos6.9,centos8,kylin10镜像文件
并把镜像文件复制到对应得文件夹内
[root@pxe ~]mkdir /mnt/cdrom cdrom1 cdrom2
[root@pxe ~]cd /var/lib/tftpboot
[root@pxe ~]mkdir centos6.9 centos8 kylin10
[root@pxe ~]# mount -t iso9660 -o loop /dev/sr0 /mnt/cdrom/
[root@pxe ~]# cp -avp /mnt/cdrom/ /var/lib/tftpboot/centos6.9/
[root@pxe ~]# mount -t iso9660 -o loop /dev/sr1 /mnt/cdrom1/
[root@pxe ~]# cp -avp /mnt/cdrom/ /var/lib/tftpboot/centos8/
[root@pxe ~]# mount -t iso9660 -o loop /dev/sr2 /mnt/cdrom2/
[root@pxe ~]# cp -avp /mnt/cdrom/ /var/lib/tftpboot/kylin10
复制文件
[root@CentOSPXEServer~]# cp /mnt/cdrom/images/pxeboot/vmlinuz /var/lib/tftpboot/centos6.9/
[root@CentOSPXEServer~]# cp /mnt/cdrom/images/pxeboot/initrd.img /var/lib/tftpboot/centos6.9/
[root@CentOSPXEServer~]# cp /mnt/cdrom1/images/pxeboot/vmlinuz /var/lib/tftpboot/centos8/
[root@CentOSPXEServer~]# cp /mnt/cdrom1/images/pxeboot/initrd.img /var/lib/tftpboot/centos8/
[root@CentOSPXEServer~]# cp /mnt/cdrom2/images/pxeboot/vmlinuz /var/lib/tftpboot/kylin10/
[root@CentOSPXEServer~]# cp /mnt/cdrom2/images/pxeboot/initrd.img /var/lib/tftpboot/kylin10/
[root@CentOSPXEServer~]# cp /usr/share/syslinux/vesamenu.c32 /var/lib/tftpboot/
[root@CentOSPXEServer~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@CentOSPXEServer~]# cp /mnt/cdrom/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
修改default文件
[root@CentOSPXEServer~]# chmod 644 /var/lib/tftpboot/pxelinux.cfg/default
[root@CentOSPXEServer~]# vi /var/lib/tftpboot/pxelinux.cfg/default
label linux
menu label ce shi
label linux
menu label ^a1)Install ceshi or kylin10 lanyan
kernel kylin10/vmlinuz
append initrd=kylin10/initrd.img inst.ks=http://"IP"/kylin10/ks.cfg
label linux
menu label ^b1)Install 1T/4T*3/1000TAP/5000TAPceshi or centos6.9lanyan
kernel centos6.9/vmlinuz
append initrd=centos6.9/initrd.img nomodeset blacklist=ast xdriver=vesa brokenmodules=ast ks=http://"IP"/centos6.9/ks.cfg method=http://"IP"/centos6.9 devfs=nomount
label linux
menu label ^c1)Install tdhx or centos8 lanyan
kernel centos8/vmlinuz
append initrd=centos8/initrd.img inst.stage2=http://"IP"/centos8 quiet inst.ks=http://"IP"/centos8/ks.cfg
7 配置HTTP服务
[root@pxe ~]# cd /etc/httpd/conf.d/
[root@pxe conf.d]# mv welcome.conf welcome.conf_bak
[root@pxe conf.d]# vim pxeboot.conf
Alias / /var/lib/tftpboot/
<Directory /var/lib/tftpboot/>
Options Indexes FollowSymLinks
Order Allow,Deny
Allow from all
</Directory>
[root@pxe conf.d]# ll
total 16
-rw-r--r-- 1 root root 295 Dec 9 2016 manual.conf
-rwxr-xr-x. 1 root root 138 Aug 17 16:10 pxeboot.conf
-rw-r--r--. 1 root root 392 Mar 22 2017 README
-rw-r--r--. 1 root root 299 Dec 9 2016 welcome.conf_bak
[root@pxe conf.d]# service httpd restart
[root@pxe conf.d]# chkconfig httpd on
测试httpd服务是否部署成功,能否正常访问
8 配置nfs文件
/installations *(insecure,rw,async,no_root_squash)
/kickstart *(insecure,rw,async,no_root_squash)
添加到/etc/exports
[root@pxe ~]# vim /etc/exports
------文件内容----
/installations *(insecure,rw,async,no_root_squash)
/kickstart *(insecure,rw,async,no_root_squash)
[root@pxe ~]# vim /etc/sysconfig/nfs
------文件内容---把这两个注释去掉
#
# Optional arguments passed to rpc.nfsd. See rpc.nfsd(8)
# Turn off v2 and v3 protocol support
RPCNFSDARGS="-N 2 -N 3"
# Turn off v4 protocol support
RPCNFSDARGS="-N 4"
# Number of nfs server processes to be started.
# The default is 8.
9 在centos.9 centos8 kylin10 内分别新建ks.cfg文件
[root@pxe tftpboot]# ls
centos6.9 centos8 kylin10 menu.c32 pxelinux.0 pxelinux.cfg vesamenu.c32
[root@pxe tftpboot]#vim centos6.9/ks.cfg
----------------------文件内容----
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --service=ssh
#firewall --service=ssh
# Install OS instead of upgrade
install
# Use network installation
url --url="http://192.168.10.2/centos6.9"
# Root password
rootpw --iscrypted $1$hwkjznyH$3DxQkfJhCsWZmC40uiuzp1
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone --isUtc Asia/Shanghai
# Network information
network --bootproto=dhcp --onboot=on
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
#新建卷组
part pv.00 --grow --size=1 --fstype="lvm"
part /boot --fstype=ext4 --size=500
part pv.01 --grow --size=1 --fstype="lvm"
part pv.02 --grow --size=1 --fstype="lvm"
#新建卷名
volgroup VolGroup --pesize=4096 pv.01
volgroup VolGroup0 --pesize=4096 pv.02
volgroup VolGroup00 --pesize=4096 pv.00
#分区
logvol / --fstype="ext4" --size=150000 --name=lv_root --vgname=VolGroup
logvol swap --fstype="swap" --size=4096 --name=swap --vgname=VolGroup
logvol /home/bds/sample --fstype="ext4" --grow --size=1 --percent=25 --name=lv_sample --vgname=VolGroup
logvol /var --fstype="ext4" --grow --size=1 --percent=25 --name=lv_var --vgname=VolGroup
logvol /var/lib/mysql --fstype="ext4" --grow --size=1 --percent=25 --name=lv_mysql --vgname=VolGroup
logvol /home --fstype="ext4" --grow --size=1 --percent=25 --name=lv_home --vgname=VolGroup
logvol /home/kvm --fstype="ext4" --grow --size=1 --name=lv_kvm --vgname=VolGroup0
logvol /home/elasticsearch --fstype="ext4" --grow --size=1 --name=lv_es --vgname=VolGroup00
#确认使用得工具安装包
%packages
@backup-client
@basic-desktop
@debugging
@desktop-platform
@fonts
@legacy-x
@x11
%end
编辑centou8
[root@pxe tftpboot]# vim centos8/ks.cfg
---文件内容----
#varsion=RHEL8
selinux --disabled
firewall --service=ssh
ignoredisk --only-use=sda,sdb,sdc
clearpart --all --initlabel
graphical
#zerombr
#skipx
#bootloader --append="crashkernel=auto" --location=mbr --boot-drive=sda
keyboard --vckeymap=us --xlayouts='us'
#lang zh_CN.UTF-8
lang en_US.UTF-8
url --url=http://192.168.10.2/centos8/BaseOS
repo --name="AppStream" --baseurl=http://192.168.10.2/centos8/AppStream
#此处设置登录密码
rootpw --iscrypted $1$hwkjznyH$3DxQkfJhCsWZmC40uiuzp1
xconfig --startxonboot
firstboot --enable
#logging --level=info
services --disabled="chronyd"
timezone Asia/Shanghai --isUtc --nontp
user --name=tdhx --password=$1$hwkjznyH$3DxQkfJhCsWZmC40uiuzp1 --iscrypted --gecos="tdhx"
%packages
@^graphical-server-environment
kexec-tools
%end
#创建卷组
part pv.00 --fstype="lvm" --grow --recommended #--ondisk=sda
#part /boot --fstype="ext4" --size=500
part pv.01 --fstype="lvm" --grow --size=1 #--ondisk=sdb
part /boot --fstype="ext4" --size=500
part pv.02 --fstype="lvm" --grow --size=1 #--ondisk=sdc
#创建卷名
volgroup lanyeye --pesize=4096 pv.01
volgroup lanyeye1 --pesize=4096 pv.02
volgroup lanyeye2 --pesize=4096 pv.00
#创建分区
#logvol /home/kvm --fstype="ext4" --grow --size=1 --name=home_kvm --vgname=kvm
logvol / --fstype="ext4" --size=100000 --name=lv_root --vgname=lanyeye
logvol swap --fstype="swap" --size=4096 --name=lv_swap --vgname=lanyeye
logvol /home/lany/capture --fstype="ext4" --grow --size=30000 --name=lv_capture --vgname=lanyeye
logvol /home/lany/sample --fstype="ext4" --grow --percent=25 --name=lv_sample --vgname=lanyeye
logvol /var --fstype="ext4" --grow --percent=25 --name=lv_var --vgname=lanyeye
logvol /var/lib/mysql --fstype="ext4" --grow --percent=25 --name=lv_mysql --vgname=lanyeye
logvol /home --fstype="ext4" --grow --percent=25 --name=lv_home --vgname=lanyeye
logvol /home/kvm --fstype="ext4" --grow --size=1 --name=lv_kvm --vgname=lanyeye1
logvol /home/elasticsearch --fstype="ext4" --grow --size=1 --name=lv_es --vgname=lanyeye2
%packages
@^graphical-server-environment
kexec-tools
%end
%addon com_redhat_kdump --enable --reserve-mb="auto"
%end
%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
reboot
编辑麒麟10 ks文件,对http安装源兼容不好,所以使用nfs提供安装源,PXE安装时无法改为英文语言,所以在安装完毕后,修改/etc/locale.conf文件内容切换语言。
[root@pxe tftpboot]mkdir /installations
[root@pxe tftpboot]cp -avp /mnt/cdrom2/* /installations/
[root@pxe tftpboot]# vim kylin10/ks.cfg
----文件内容----
#version=DEVEL
# Use graphical install
#ignoredisk --only-use=sda
selinux --disabled
firewall --service=ssh
ignoredisk --only-use=sda,sdb,sdc
# Partition clearing information
clearpart --all --initlabel
#bootloader --append="crashkernel=auto" --location=mbr --boot-drive=sda
#clearpart --all --initlabel --drives=sda
graphical
keyboard --vckeymap=us --xlayouts='us'
lang zh_CN.UTF-8 --addsupport=en_US.UTF-8
nfs --server=192.168.10.2 --dir=/installations
#url --url="http://192.168.10.2/kylin10/installations"
#url --url ftp://:@/
eula --agreed
# Network information
network --bootproto=dhcp --ipv6=auto --device=link
network --hostname=LanEye
# Root password
rootpw --plaintext 6Rajj@1&
#!qaz@wsx12
#x window system configuration information
xconfig --startxonboot
# Run the Setup Agent on first boot
firstboot --disable
# System services
services --enabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc
%post --nochroot
#####copy kyinfo and LICENSE
if [ -e /tmp/.kyinfo ];then
echo y | cp -a /tmp/.kyinfo $ANA_INSTALL_PATH/etc/
fi
if [ -e /tmp/LICENSE ];then
echo y | cp -a /tmp/LICENSE $ANA_INSTALL_PATH/etc/
fi
if [ -e /run/install/repo/.kyinfo ];then
echo y | cp -a /run/install/repo/.kyinfo $ANA_INSTALL_PATH/etc/
fi
if [ -e /run/install/repo/LICENSE ];then
echo y | cp -a /run/install/repo/LICENSE $ANA_INSTALL_PATH/etc/
fi
##### kylin postaction
## cdrom install, copy .kylin-post-actions
if [ -e /run/install/repo/.kylin-post-actions ];then
echo y | cp -a /run/install/repo/.kylin-post-actions /tmp/.kylin-post-actions
echo "repo=/run/install/repo" > /tmp/.kylin-repo
fi
## copy kylin post scripts in new os
if [ -e /tmp/.kylin-post-actions ];then
echo y | cp -a /tmp/.kylin-post-actions $ANA_INSTALL_PATH/bin
fi
if [ -e /tmp/.kylin-repo ];then
echo y | cp -a /tmp/.kylin-repo $ANA_INSTALL_PATH/tmp/
fi
## copy and run .kylin-post-actions-nochroot
if [ -e /run/install/repo/.kylin-post-actions-nochroot ];then
echo y | cp -a /run/install/repo/.kylin-post-actions-nochroot /tmp/.kylin-post-actions-nochroot
fi
if [ -e /tmp/.kylin-post-actions-nochroot ];then
/bin/bash -x /tmp/.kylin-post-actions-nochroot &> $ANA_INSTALL_PATH/var/log/.kylin-post-actions-nochroot.log
fi
%end
%post
systemctl disable systemd-networkd-wait-online.service
systemctl disable multipathd.service
### do kylin post action
if [ -e /bin/.kylin-post-actions ];then
/bin/bash -x /bin/.kylin-post-actions &> /var/log/.kylin-post-actions.log
fi
%end
%packages
@^kylin-desktop-environment
#kexec-tools
%end
#ignoredisk --only-use=sda,sdb,sdc
# Partition clearing information
#clearpart --all --initlabel
# Disk partitioning information
#创建卷组
part pv.00 --fstype="lvm" --ondisk=sda --grow --size=1
part biosboot --fstype="biosboot" --size=1
part /boot --fstype="ext4" --size=1024
part /boot/efi --fstype="efi" --size=600 --fsoptions="umask=0077,shortname=winnt"
part pv.01 --fstype="lvm" --ondisk=sdb --grow --size=1
part pv.02 --fstype="lvm" --ondisk=sdc --grow --size=1
#创建卷名
volgroup lanyeye --pesize=4096 pv.00
volgroup lanyeye1 --pesize=4096 pv.01
volgroup lanyeye2 --pesize=4096 pv.02
#新建分区
logvol / --fstype="ext4" --grow --size=100000 --name=lv_root --vgname=lanyeye
logvol /backup --fstype="xfs" --grow --size=50000 --name=lv_backup --vgname=lanyeye
logvol swap --fstype="swap" --size=4096 --name=lv_swap --vgname=lanyeye
logvol /home/lany/capture --fstype="ext4" --size=30000 --name=lv_capture --vgname=lanyeye
logvol /home/lany/sample --fstype="ext4" --grow --percent=25 --name=lv_sample --vgname=lanyeye
logvol /var --fstype="ext4" --grow --percent=25 --name=lv_var --vgname=lanyeye
logvol /var/lib/mysql --fstype="ext4" --grow --percent=25 --name=lv_mysql --vgname=lanyeye
logvol /home --fstype="ext4" --grow --percent=25 --name=lv_home --vgname=lanyeye
logvol /home/kvm --fstype="ext4" --grow --size=1 --name=lv_kvm --vgname=lanyeye1
logvol /home/elasticsearch --fstype="ext4" --grow --size=1 --name=lv_es --vgname=lanyeye2
#timesource --ntp-disable
%addon com_redhat_kdump --enable --reserve-mb='1024M'
%end
%anaconda
pwpolicy root --minlen=8 --minquality=1 --strict --nochanges --notempty
pwpolicy user --minlen=8 --minquality=1 --strict --nochanges --emptyok
pwpolicy luks --minlen=8 --minquality=1 --strict --nochanges --notempty
%end
reboot
%post
#mkdir /install
#mount 192.168.10.190:/installations/ /install
#sh /install/1.sh
echo 'LANG="en_US.UTF-8"' > /etc/locale.conf
#此处可做 安装完后一些预操作
reboot
%end