ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 批量安装系统-kickstart [TOC] ## 1 环境准备 ### 1.1 系统信息 ```sh cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) uname -r 3.10.0-693.el7.x86_64 hostname -I 10.0.0.201 172.16.1.201 ``` ### 1.2 防火墙、selinux ```sh sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config setenforce 0 systemctl stop firewalld.service systemctl disable firewalld.service ``` ## 二、 安装配置DHCP服务 ### 2.1 安装DHCP ```sh yum -y install dhcp cat >/etc/dhcp/dhcpd.conf <<EOF subnet 172.16.1.0 netmask 255.255.255.0 { range 172.16.1.100 172.16.1.200; option subnet-mask 255.255.255.0; default-lease-time 21600; max-lease-time 43200; next-server 172.16.1.201; filename "/pxelinux.0"; } EOF ``` ### 2.2 启动DHCP ```sh systemctl start dhcpd systemctl status dhcpd ss -tunlp|grep dhcp udp 0 0 0.0.0.0:67 0.0.0.0:* 1573/dhcpd ``` Kickstart系统不要开机自启动,且用完后要关闭,防止自动重装系统。 ## 3 安装配置TFTP和PXE ### 3.1 安装启动TFTP ```sh yum -y install tftp-server systemctl start tftp.socket ``` ### 3.2 配置pxe服务 ```sh yum -y install syslinux cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ ``` ### 3.3 拷贝配置文件 1) 挂载光盘 ```sh mkdir -p /var/www/html/{CentOS7,ks_config} mount /dev/cdrom /var/www/html/CentOS7 ``` 2) 拷贝配置文件 ```sh cp -a /var/www/html/CentOS7/isolinux/* /var/lib/tftpboot/ mkdir -p /var/lib/tftpboot/pxelinux.cfg cp /var/www/html/CentOS7/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default ``` 3) 结果验证 ```sh tree /var/lib/tftpboot/ /var/lib/tftpboot/ ├── boot.cat ├── boot.msg ├── grub.conf ├── initrd.img ├── isolinux.bin ├── isolinux.cfg ├── memtest ├── pxelinux.0 ├── pxelinux.cfg │ └── default ├── splash.png ├── TRANS.TBL ├── vesamenu.c32 └── vmlinuz ``` ## 4 安装配置HTTP服务 ### 4.1 服务安装 ```sh yum -y install httpd systemctl start httpd.service ``` ### 4.2 结果验证 * 浏览器访问 http://10.0.0.201/CentOS7/ 能看到光盘中的内容表示正确 * 命令行验证 ```sh curl http://172.16.1.201/CentOS7/CentOS_BuildTag 20170905-1415 ``` ## 5 配置文件与ks文件 ### 5.1 修改配置文件 ```sh mv /var/lib/tftpboot/pxelinux.cfg/default{,.bak} cat >/var/lib/tftpboot/pxelinux.cfg/default <<'EOF' default ks prompt 0 label ks kernel vmlinuz append initrd=initrd.img ks=http://172.16.1.201/ks_config/ks-CentOS7.cfg net.ifnames=0 biosdevname=0 ksdevice=eth1 EOF chmod 644 /var/lib/tftpboot/pxelinux.cfg/default ``` 内核参数中指定http服务的地址,并增加网卡名统一参数 ### 5.2 创建ks文件 ```sh cat >/var/www/html/ks_config/CentOS7-ks.cfg <<'EOF' # Kickstart Configurator for CentOS 7 by luo gang install url --url="http://172.16.1.201/CentOS7/" text lang en_US.UTF-8 keyboard us zerombr bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet" network --bootproto=static --device=eth0 --gateway=10.0.0.254 --ip=10.0.0.202 --nameserver=223.5.5.5 --netmask=255.255.255.0 --activate network --bootproto=static --device=eth1 --ip=172.16.1.202 --netmask=255.255.255.0 --activate network --hostname=Cobbler #network --bootproto=dhcp --device=eth1 --onboot=yes --noipv6 --hostname=CentOS7 timezone --utc Asia/Shanghai authconfig --enableshadow --passalgo=sha512 rootpw --iscrypted $6$X20eRtuZhkHznTb4$dK0BJByOSAWSDD8jccLVFz0CscijS9ldMWwpoCw/ZEjYw2BTQYGWlgKsn945fFTjRC658UXjuocwJbAjVI5D6/ clearpart --all --initlabel part /boot --fstype xfs --size 1024 part swap --size 1024 part / --fstype xfs --size 1 --grow firstboot --disable selinux --disabled firewall --disabled logging --level=info reboot %packages @^minimal @compat-libraries @debugging @development tree nmap sysstat lrzsz dos2unix telnet wget vim bash-completion %end %post systemctl disable postfix.service %end EOF ``` 5.3 语法检查 ```sh yum install pykickstart ksvalidator /var/www/html/ks_config/CentOS7-ks.cfg ``` ## 6 无人值守自动安装 创建虚拟机,打开系统电源,出去喝杯水。过会回来,系统就以经装好了.如果安装过程出错,可以通过Alt+F2-F5切到其他控制台查看报错信息 注意centos7的虚拟机,内存要给2G以上,否则安装过程会报错 ![mark](http://noah-pic.oss-cn-chengdu.aliyuncs.com/pic/20200411/072703884.png)