我的网卡信息
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.43.110 netmask 255.255.255.0 broadcast 192.168.43.255
inet6 fe80::ba5:271b:46bf:4c62 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:4d:5c:39 txqueuelen 1000 (Ethernet)
RX packets 707 bytes 55242 (53.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 508 bytes 64334 (62.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 3241 bytes 100378009 (95.7 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3241 bytes 100378009 (95.7 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:34:8b:15 txqueuelen 1000 (Ethernet)
RX packets 26388 bytes 1516058 (1.4 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 30339 bytes 937586610 (894.1 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]#
关闭防火墙和selinux
[root@localhost ~]# systemctl stop firewalld [root@localhost ~]# setenforce 0 [root@localhost ~]# vim /etc/selinux/config
SELINUX=disabled
配置yum仓库的名称
- 如果yum仓库的名称不正确,在 system-config-kickstart创建配置文件时软件包如法选择
- yum仓库名为development.repo
[root@localhost ~]# vim /etc/yum.repos.d/development.repo [development] name=development baseurl=file:///var/ftp/iso gpgcheck=0
将光盘挂载到ftp共享目录里
- 我这里是iso文件夹
[root@localhost ~]# mkdir /var/ftp/iso [root@localhost ~]# mount /dev/sr0 /var/ftp/iso/ mount: /dev/sr0 is write-protected, mounting read-only [root@localhost ~]#
设置永久挂载
修改fstab文件
[root@localhost ~]# vim /etc/fstab
/dev/sr0 /var/ftp/iso iso9660 defaults 0 0
测试
[root@localhost ~]# mount -a
复制启动文件
[root@localhost ~]# cp -r /var/ftp/iso/isolinux/* /var/lib/tftpboot/ [root@localhost ~]#
安装FTP服务
[root@localhost ~]# yum install -y vsftpd tftp-server [root@localhost ~]#
编辑tftp配置文件
[root@localhost ~]# vim /etc/xinetd.d/tftp
# default: off # description: The tftp server serves files using the trivial file transfer \ # protocol. The tftp protocol is often used to boot diskless \ # workstations, download configuration files to network-aware printers, \ # and to start the installation process for some operating systems. 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 }
准备tftp下载文件
安装syslinux服务
[root@localhost ~]# yum install -y syslinux
将pexlinux.0复制到tftp目录里[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ [root@localhost ~]#
从光盘或者iso镜像拷贝isolinux下所有文件到tftp的根目录(tffpboot)
[root@localhost tftpboot]# cp /var/ftp/iso/isolinux/* ./ [root@localhost tftpboot]# pwd /var/lib/tftpboot [root@localhost tftpboot]#
创建客户端安装程序文件
- 创建pxelinux.cfg文件夹
[root@localhost ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
创建default文件
[root@localhost tftpboot]# cp isolinux.cfg pxelinux.cfg/default
修改default文件
[root@localhost tftpboot]# vim pxelinux.cfg/default
在文件中找到以下字段
label linux menu label ^Install Red Hat Enterprise Linux 7.3 kernel vmlinuz append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.3\x20Server.x86_64 quiet
修改成如下
label linux menu label ^Install Red Hat Enterprise Linux 7.3 kernel vmlinuz append repo=ftp://192.168.43.110/iso ks=192.168.43.110/ks.cfg quiet
此处的IP为自己真实的ip,根据自己的网卡配置编辑
制作ks.cfg文件
安装system-config-kickstart.noarch生成ks.cfg文件
[root@localhost ~]# yum install -y system-config-kickstart.noarch
[root@localhost ~]# yum install -y system-config-kickstart.noarch [root@localhost ~]#
使用system-config-kickstart生成新的ks.cfg文件
[root@localhost ~]# system-config-kickstart
基本配置
默认为图形化安装,如果虚拟机没有图形化可以选择文本模式
安装方法
引导转载程序选项
分区信息(/目录要设置为主分区,否则安装时ks文件环节报错)
网络配置
验证默认就可以
防火墙禁用
软件包可以自己选择
其余选项默认就可以点击文件保存选择路径即可
将文件移动到ftp目录下
[root@localhost ~]# mv Desktop/ks.cfg /var/ftp/ mv: overwrite ‘/var/ftp/ks.cfg’? y [root@localhost ~]#
ks.cfg文件授权
[root@localhost ~]# chmod 644 /var/ftp/ks.cfg
安装DHCP服务
[root@localhost ~]# yum install -y dhcp [root@localhost ~]#
配置dhcp服务器
复制dhcp配置模板
[root@localhost ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y [root@localhost ~]#
编辑配置文件
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
根据自己的IP修改subnet 192.168.43.0 netmask 255.255.255.0 { range 192.168.43.100 192.168.43.200; option domain-name-servers 192.168.43.110; option routers 192.168.43.110; option broadcast-address 192.168.43.255; default-lease-time 600; max-lease-time 7200; next-server 192.168.43.110; filename "pxelinux.0"; }
重启服务
[root@localhost ~]# systemctl restart dhcpd
安装virt服务
查看所有包组
[root@localhost ~]# yum groups list Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. There is no installed groups file. Maybe run: yum groups mark convert (see man yum) Available Environment Groups: Minimal Install Infrastructure Server File and Print Server Basic Web Server Virtualization Host Server with GUI Available Groups: Compatibility Libraries Console Internet Tools Development Tools Graphical Administration Tools Legacy UNIX Compatibility Scientific Support Security Tools Smart Card Support System Administration Tools System Management Done [root@localhost ~]#
安装Virtualization Host包组
[root@localhost ~]# yum groupinstall -y "Virtualization Host" [root@localhost ~]#
安装virt-install工具
[root@localhost ~]# yum install -y virt-install.noarch
编写安装脚本
[root@localhost ~]# vim create.sh
- 我是在当前路径创建的
virt-install \ --name $1 \ 虚拟机的名称 --vcpus 2 \ cpu的核数 --memory 2048 \ 内存大小 --disk path=/var/lib/libvirt/images/$1.qcow2,size=10,format=qcow2 \ 磁盘存放路径,大小,格式 --network network:default \ 网卡(如果是桥接网卡将network:defaule修改为bridge=桥接网卡名称) --graphics none \ 不用图形化安装 --extra-args "ks=ftp://192.168.122.1/ks.cfg" \ ks文件路径 --extra-args "console=ttyS0,115200" \ 连接方式 --location=ftp://192.168.122.1/iso 镜像文件
注:
- $1为linux中shell变量 作用为获取输入的第一个变量
- 此处的IP为虚拟网卡(virbr0)的IP
- 如果真机的网卡配置成桥接的话,此处可以直接使用配置的IP。不用使用虚拟网卡的IP了
为create.sh文件授权:为其他用户授予可执行的权限
[root@localhost ~]# chmod o+x create.sh [root@localhost ~]# ./create.sh 01
注:
- 此处的01为脚本中的$1 01为第一个变量
- ./create.sh为第0个变量
虚拟机配置文件路径
[root@localhost qemu]# pwd
/etc/libvirt/qemu
[root@localhost qemu]# ls
01.xml 02.xml 04.xml networks
虚拟机磁盘存放路径
[root@localhost images]# pwd
/var/lib/libvirt/images
[root@localhost images]# ls
01.qcow2 02.qcow2 04.qcow2
[root@localhost images]#