Centos 7Kickstart无人值守自动安装

说明:IP地址 172.16.1.90  DNS 222.222.222.222 网关 172.16.1.254

实现的目的是:批量安装centos 7操做系统

详细操做

第一部分在kickstart服务上操做

一、关闭selinux

[root@localhost ~]# vim /etc/selinux/config

SELINUX=disabled   //修改成disabled
#SELINUXTYPE=targeted  //注释掉

二、配置防火墙 容许:TCP 80 端口 和 UDP 69 端口  或者 关闭防火墙html

[root@localhost ~]# yum -y install firewalld   //centos 7通常上面都没有安装包,它是用来启动防火墙服务的,相似于service iptables start
linux


[root@localhost html]# firewall-cmd --zone=public --add-port=80/tcp --permanent //httpd服务须要此端口
[root@localhost html]# firewall-cmd --zone=public --add-port=69/udp --permanent  //tftp服务须要此端口

参数详解:vim

    --zone   做用域
centos

    --add-port=80/tcp   添加端口, 格式为:  端口/ 通信协议
服务器

    --permanent     永久生效,没有此参数,重启失效网络


[root@localhost ~]# systemctl start firewalld     //启动防火墙服务

三、安装httpd服务

[root@localhost ~]# yum -y install httpd  //安装httpd服务

[root@localhost ~]# systemctl start httpd  //启动httpd服务app

[root@localhost ~]# systemctl enable httpd //将httpd服务加入开机自动启动
less

四、挂在系统安装镜像到httpd服务器站点根目录dom

[root@localhost ~]# mkdir /var/www/html/os/  //建立挂载目录
[root@localhost ~]# mount /dev/cdrom /var/www/html/os/ //挂载系统镜像
tcp

五、安装tftp服务

[root@localhost ~]# yum -y install tftp tftp-server xinetd//安装

[root@localhost ~]# vim /etc/xinetd.d/tftp //编辑

disable                 = no //修改

[root@localhost ~]# systemctl start xinetd  //启动

[root@localhost ~]# systemctl enable xinetd //将xinetd服务加入开机自动启动

[root@localhost ~]# cp /var/www/html/os/images/pxeboot/vmlinuz /var/lib/tftpboot/
[root@localhost ~]# cp /var/www/html/os/images/pxeboot/initrd.img /var/lib/tftpboot/
[root@localhost ~]# mkdir -p /var/lib/tftpboot/pxelinux.cfg
[root@localhost ~]# cp /var/www/html/os/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
[root@localhost ~]# vim /var/lib/tftpboot/pxelinux.cfg/default

default linux   //修改
timeout 600

display boot.msg

# Clear the screen when exiting the menu, instead of leaving the menu displayed.
# For vesamenu, this means the graphical background is still displayed without
# the menu itself for as long as the screen remains in graphics mode.
menu clear
menu background splash.png
menu title CentOS Linux 7
menu vshift 8
menu rows 18
menu margin 8
#menu hidden
menu helpmsgrow 15
menu tabmsgrow 13

# Border Area
menu color border * #00000000 #00000000 none

# Selected item
menu color sel 0 #ffffffff #00000000 none

# Title bar
menu color title 0 #ff7ba3d0 #00000000 none

# Press [Tab] message
menu color tabmsg 0 #ff3a6496 #00000000 none

# Unselected menu item
menu color unsel 0 #84b8ffff #00000000 none

# Selected hotkey
menu color hotsel 0 #84b8ffff #00000000 none

# Unselected hotkey
menu color hotkey 0 #ffffffff #00000000 none

# Help text
menu color help 0 #ffffffff #00000000 none

# A scrollbar of some type? Not sure.
menu color scrollbar 0 #ffffffff #ff355594 none

# Timeout msg
menu color timeout 0 #ffffffff #00000000 none
menu color timeout_msg 0 #ffffffff #00000000 none

# Command prompt text
menu color cmdmark 0 #84b8ffff #00000000 none
menu color cmdline 0 #ffffffff #00000000 none

# Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message.

menu tabmsg Press Tab for full configuration options on menu items.

menu separator # insert an empty line
menu separator # insert an empty line

label linux
  menu label ^Install CentOS Linux 7
  kernel vmlinuz
  append initrd=initrd.img ks=http://172.16.1.90/ks.cfg ksdevice=ens33 ip=dhcp    //修改

[root@localhost ~]# chmod -R 644 /var/lib/tftpboot/pxelinux.cfg/default   //设置文件文件权限
[root@localhost ~]# yum -y install syslinux  //安装引导程序

[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/  //拷贝引导文件到tftp服务根目录下

六、[root@localhost ~]# yum -y install dhcp //安装dhcp服务

ddns-update-style interim;  //设置DHCP服务器模式

subnet 172.16.1.0 netmask 255.255.255.0 { //配置网段
  range 172.16.1.100 172.16.1.200;  //配置dhcp服务器的租用地址范围
  option domain-name-servers 222.222.222.222;  //配置dns
  option domain-name "internal.example.org"; 
  option routers 172.16.1.254;  // 配置网关
  option broadcast-address 10.5.5.31;
  default-lease-time 600;  //默认租约时间
  max-lease-time 7200;  //最大租约时间
  next-server 172.16.1.90;  // tftp服务器地址
  filename "pxelinux.0"; //tftp服务器根目录下的文件名

[root@localhost ~]# vim /etc/sysconfig/dhcpd  //

DHCPDARGS=ens33  //设置dhcp服务器模式

[root@localhost ~]# dhcpd //测试dhcp服务配置是否正确
[root@localhost ~]# systemctl start dhcpd  //启动dhcpd服务
[root@localhost ~]# systemctl enable dhcpd //
七、配置kickstart自动安装文件

注意:在安装kickstart以前先编辑下面的文件,亲 必定要写不然会报错 例如:下面的这个图


配置这个文件就不会显示软件包选择被禁止了

vim /etc/yum.repos.d/lxy.repo//编辑

[development]  //添加
name=my-centos7
baseurl=file:///var/www/html/os/
enabled=1
gpgcheck=0

[root@localhost ~]# yum -y install system-config-kickstart //安装kickstart

[root@localhost ~]# system-config-kickstart   //打开图形界面配置kickstart文件

注意:下面详细配置、请看大屏幕 呵呵!!!




下面软件包选择根据本身须要吧i



第二部分在pxe客户机上作

注意:内存必定要2GB不然会报错


进入Boot设置从网络启动


开机以后,如图所示,系统已经自动启动了;如下是安装过程


备注:系统安装完成以后,第一启动请设置为硬盘,不然系统从新以后又自动安装系统了,而后把本身的网卡断开


就是慢,哎没办法 ,多等一会!



安装成功,


输入用户和密码,查看IP地址成功了,

最后表扬一下本身!!!