CentOS7.2下PXE+kickstart自动化安装系统

前端之家收集整理的这篇文章主要介绍了CentOS7.2下PXE+kickstart自动化安装系统前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

CentOS7.2下PXE+kickstart自动化安装系统

注意:我只是一篇笔记,不是教程!不求甚解的可以一步步跟着做出来,想搞清楚原理的自己研究

温故而知新,虽然工作中用到的系统都是 CentOS 6.X,但我们不能一直沉浸在过去的经验中,要跟上时代的节奏

一、实验环境

  • 操作系统:CentOS Linux release 7.2.1511 (Core)
  • 网卡地址:192.168.100.147/24
  • 光盘镜像:CentOS-7-x86_64-Minimal-1511.iso
  • 安装工具:kickstart + dhcp + tftp + ftp

二、准备工作

2.1 关闭防火墙

  1. [root@localhost ~]# systemctl stop iptables
  2. [root@localhost ~]# systemctl stop firewalld

2.2 关闭selinux

  1. [root@localhost ~]# setenforce 0
  2. [root@localhost ~]# getenforce
  3. Permissive

三、原理和流程图

四、DHCP服务安装及配置

4.1 安装dhcp

  1. [root@localhost ~]# yum install dhcp -y

4.2 配置dhcpd

  1. [root@localhost ~]# vi /etc/dhcp/dhcpd.conf
  2. default-lease-time 600;
  3. max-lease-time 7200;
  4. log-facility local7;
  5.  
  6. subnet 192.168.100.0 netmask 255.255.255.0 {
  7. option routers 192.168.100.2;
  8. option subnet-mask 255.255.255.0;
  9. option domain-name-servers 192.168.100.2;
  10. option time-offset -18000; # Eastern Standard Time
  11. range dynamic-bootp 192.168.100.60 192.168.100.100;
  12. default-lease-time 21600;
  13. max-lease-time 43200;
  14. next-server 192.168.100.147;
  15. filename "pxelinux.0";
  16. }

4.3 启动dhcpd

  1. [root@localhost ~]# systemctl start dhcpd

4.4 dhcp服务测试

  1. [root@localhost ~]# ss -nulp | grep dhcpd
  2. UNCONN 0 0 *:67 *:* users:(("dhcpd",pid=8769,fd=7))
  3. UNCONN 0 0 *:7773 *:* users:(("dhcpd",fd=20))
  4. UNCONN 0 0 :::55406 :::* users:(("dhcpd",fd=21))

也可以启动新服务器,看看能否获取到IP地址

4.5 设置开机自启动(可选)

  1. [root@localhost ~]# systemctl enable dhcpd
  2. Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service.

五、ftp服务安装及配置

5.1 安装vsftpd

  1. [root@localhost ~]# yum install -y vsftpd

5.2 配置vsftpd

使用默认配置即可

5.3 挂载系统盘

系统安装盘挂载到 /var/ftp/pub 目录下,不要挂载到其它地方,因为 /var/ftpanonymous 匿名用户的家目录

如果是光驱,可以这样挂

  1. [root@localhost ~]# mount /dev/cdrom /var/ftp/pub
  2. mount: /dev/sr0 is write-protected,mounting read-only

如果是光盘镜像,可以这样挂

  1. [root@localhost ~]# mount /opt/CentOS-7-x86_64-Minimal-1511.iso /var/ftp/pub -o loop
  2. mount: /dev/loop0 is write-protected,mounting read-only

查看光盘内容

  1. [root@localhost ~]# ls /var/ftp/pub
  2. CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
  3. EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL

5.4 启动vsftpd服务

  1. [root@localhost ~]# systemctl start vsftpd

5.5 ftp服务器测试

  1. [root@localhost ~]# ftp 192.168.100.147
  2. Connected to 192.168.100.147 (192.168.100.147).
  3. 220 (vsFTPd 3.0.2)
  4. Name (192.168.100.147:root): anonymous
  5. 331 Please specify the password.
  6. Password:
  7. 230 Login successful.
  8. Remote system type is UNIX.
  9. Using binary mode to transfer files.
  10. ftp> ls
  11. 227 Entering Passive Mode (192,168,100,147,113,88).
  12. 150 Here comes the directory listing.
  13. -rw-r--r-- 1 0 0 1068 Aug 09 08:56 ks.cfg
  14. dr-xr-xr-x 8 0 0 2048 Dec 09 2015 pub
  15. 226 Directory send OK.
  16. ftp> get ks.cfg
  17. local: ks.cfg remote: ks.cfg
  18. 227 Entering Passive Mode (192,126,155).
  19. 150 opening BINARY mode data connection for ks.cfg (1068 bytes).
  20. 226 Transfer complete.
  21. 1068 bytes received in 6.8e-05 secs (15705.88 Kbytes/sec)
  22. ftp> quit
  23. 221 Goodbye.
  24. [root@localhost ~]# ls
  25. anaconda-ks.cfg ks.cfg

成功拿到 ks.cfg 则表示 ftp 服务正常

5.6 设置开机自启动(可选)

  1. [root@localhost ~]# systemctl enable vsftpd
  2. Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.

六、tftp服务安装及配置

6.1 安装tftp和xinetd服务

  1. [root@localhost ~]# yum install -y xinetd
  2. [root@localhost ~]# yum install -y tftp-server tftp syslinux-tftpboot

6.2 配置xinetd

  1. [root@localhost ~]# vi /etc/xinetd.d/tftp
  2. service tftp
  3. {
  4. socket_type = dgram
  5. protocol = udp
  6. wait = yes
  7. user = root
  8. server = /usr/sbin/in.tftpd
  9. server_args = -s /var/lib/tftpboot
  10. #默认disable是yes的,把它改为no即可
  11. disable = no
  12. per_source = 11
  13. cps = 100 2
  14. flags = IPv4
  15. }

6.3 配置tftp-server

  1. [root@localhost ~]# cp /var/ftp/pub/images/pxeboot/initrd.img /var/lib/tftpboot/
  2. [root@localhost ~]# cp /var/ftp/pub/images/pxeboot/vmlinuz /var/lib/tftpboot/
  3. [root@localhost ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
  4. [root@localhost ~]# vi /var/lib/tftpboot/pxelinux.cfg/default
  5. default linux
  6. prompt 1
  7. timeout 60
  8. display boot.msg
  9. label linux
  10. kernel vmlinuz
  11. append initrd=initrd.img text ks=ftp://192.168.100.147/ks.cfg

6.4 配置kickstart

~/anaconda-ks.cfg 为模板,再做一些适当的修改

  1. [root@localhost ~]# cp ~/anaconda-ks.cfg /var/ftp/ks.cfg
  2. [root@localhost ~]# vi /var/ftp/ks.cfg
  3. #version=DEVEL
  4. # System authorization information
  5. auth --enableshadow --passalgo=sha512
  6. # Install OS instead of upgrade
  7. install
  8. # Use network installation
  9. url --url=ftp://192.168.100.147/pub
  10. # Use graphical install
  11. graphical
  12. # Run the Setup Agent on first boot
  13. firstboot --enable
  14. # Keyboard layouts
  15. keyboard --vckeymap=us --xlayouts='us'
  16. # System language
  17. lang en_US.UTF-8 --addsupport=zh_CN.UTF-8
  18.  
  19. # Network information
  20. network --bootproto=dhcp --device=eno16777736 --onboot=yes --ipv6=auto
  21. network --hostname=localhost.localdomain
  22.  
  23. # Root password
  24. # root密码是: rootroot
  25. rootpw --iscrypted $6$7gdZF8XhDef10LyT$2uRiP4qFYaBBTgpggKU/BXKgMDJLWN/BriXXgBwyzkjaz9G9YP/xD08I1OJfgBcPMoURsE5inVIoX.J6aERmR0
  26. # System services
  27. services --disabled="chronyd"
  28. # System timezone
  29. timezone Asia/Shanghai --isUtc --nontp
  30. # System bootloader configuration
  31. bootloader --location=mbr --boot-drive=sda
  32. autopart --type=lvm
  33. # Partition clearing information
  34. clearpart --none --initlabel
  35.  
  36. %packages
  37. @^minimal
  38. @core
  39.  
  40. %end
  41.  
  42. %addon com_redhat_kdump --disable --reserve-mb='auto'
  43.  
  44. %end

修改访问权限

  1. [root@localhost ~]# ll /var/ftp/ks.cfg
  2. -rw-------. 1 root root 1083 Aug 8 16:39 /var/ftp/ks.cfg
  3. [root@localhost ~]# chmod +r /var/ftp/ks.cfg
  4. [root@localhost ~]# ll /var/ftp/ks.cfg
  5. -rw-r--r--. 1 root root 1083 Aug 8 16:39 /var/ftp/ks.cfg

6.5 启动tftp服务

  1. [root@localhost ~]# systemctl start xinetd

6.6 测试tftp服务

  1. [root@localhost ~]# ls
  2. anaconda-ks.cfg ks.cfg
  3. [root@localhost ~]# tftp 192.168.100.147
  4. tftp> get vmlinuz
  5. tftp> quit
  6. [root@localhost ~]# ls
  7. anaconda-ks.cfg ks.cfg vmlinuz

如果能成功拿到 vmlinuz 文件,则表示 tftp 服务器状态正常

6.7 设置开机自启动(可选)

  1. [root@localhost ~]# systemctl enable xinetd
  2. Created symlink from /etc/systemd/system/multi-user.target.wants/xinetd.service to /usr/lib/systemd/system/xinetd.service.

七、启动安装

到这里已经配置完成了。

系统安装前,需要设置BIOS从网卡启动,安装完后马上改回去

八、注意事项

  • 注意dhcp冲突
  • 注意权限
  • 注意防火墙
  • 注意selinux

九、进阶参考

猜你在找的CentOS相关文章