######封装rhel6.5的虚拟机######
1.下载镜像:rhel-server-6.5-x86_64-dvd.iso
2.主机上挂载6.5的镜像到/var/www/html/rhel6.5,并在/etc/rc.d/rc.local 设置永久挂载
3.创建母盘:
virt-manager ##打开虚拟机管理界面
1.)镜像安装虚拟机
2.)Browse选择镜像所在路径
3.)512MB版本6默认无图形的最小安装
4.)选择硬盘的大小
5.)安装
6.)跳过media test安装
7.)选择语言
8.)初始化安装
9.)选择时区
10.)设置root用户密码
版本6最小安装243个包
reboot重启后用户登陆
修改主机名:vi /etc/sysconfig/network 进入文件修改 ##版本6不能使用hostnamectl set-hostname 的命令
网络配置
/etc/init.d/network restart ##重启网络 不能用systemctl restart nerwork 命令
删除/etc/udev/rules.d/所有70文件并配置yum源
配置成功
关闭火墙
vi /etc/sysconfig/selinux ##关闭
yum install -y vim lftp openssh-clients ##安装vim lftp ssh
/etc/hosts ##添加地址解析
关闭建立好的母盘,对母盘进行清空virt-sysprep -d rhel6.5后快照虚拟机
virt-manager 导入
快照之后修改主机名和网络就可以了
#####封装rhel7.3的虚拟机####
1.将7.3的镜像共享挂载,使网页可以访问
[root@foundation40 Downloads]# cd /var/www/html/ #在 /var/www/html/ 下创建目录实现挂载
[root@foundation40 html]# mkdir rhel7.3
[root@foundation40 ~]# cd /home/kiosk/Downloads/
[root@foundation40 Downloads]# ls
rhel-server-6.5-x86_64-dvd.iso
rhel-server-7.3-x86_64-dvd.iso
[root@foundation40 Downloads]# mount rhel-server-7.3-x86_64-dvd.iso /var/www/html/rhel7.3 #将镜像挂载到刚创建的目录下
[root@foundation40 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 308485972 119148944 189337028 39% /
devtmpfs 1950392 0 1950392 0% /dev
tmpfs 1965404 480 1964924 1% /dev/shm
tmpfs 1965404 9000 1956404 1% /run
tmpfs 1965404 0 1965404 0% /sys/fs/cgroup
/dev/loop0 3704296 3704296 0 100% /var/www/html/rhel7.3 #挂载成功
2.写入 vim /etc/rc.d/rc.local 永久挂载文件内,为了使其开机自动挂载
2.创建母盘base
1.)virt-manager 打开图标,点击本地镜像下载
2.)填写镜像所在的绝对路径
3.)选择内存大小(不需要图形界面,1024就可以了)
4.)母盘选择20方便之后快照的虚拟机进行实验
5.)设置母盘的名字
6.)选择语言:English
7.)选择时区时间、最小安装(minimal insatll)
8.)设置超级用户密码、建立普通用户名和密码设置(最小安装只有330个安装包)
3.配置母盘信息
1.)修改用户名并配置网络
ip addr show #查看ip地址(不能用ifconfig、vim 最小安装不带这些安装包)
vi /etc/sysconfig/network-scripts/ifconfig-eth0
注意:
刚安装的虚拟机没有eth0可以用以下步骤修改:
vi /boot/grub2/grub.cfg ##在第99行末尾添加 net.ifnames=0 关机重启后ip addr show 就会改成eth0
此时在//etc/sysconfig/network-scripts/下用 mv ifconfig-ens3 ifconfig-eth0 该成eth0
然后vi ifconfig-eth0 设置网络
2.)配置yum源
3.)安装yum install -y vim lftp net-tools #net-tools 可以使用ifconfig
关闭防火墙,网络管理的服务和selinux
4.)查看火墙、selinux状态并增加地址解析
5.)关机进行母盘清空
[root@foundation40 ~]# yum whatprovides */virt-sysprep #查找清空母盘的命令
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.
1:libguestfs-tools-c-1.32.7-3.el7.x86_64 : System administration tools for virtual
: machines
Repo : westos
Matched from:
Filename : /usr/bin/virt-sysprep
1:libguestfs-tools-c-1.32.7-3.el7.x86_64 : System administration tools for virtual
: machines
Repo : @westos
Matched from:
Filename : /usr/bin/virt-sysprep
[root@foundation40 ~]# yum -y libguestfs-tools-c-1.32.7-3.el7.x86_64 #安装命令包
[root@foundation40 ~]# virt-sysprep -d rhel7.3-base #清空母盘,使得快照的虚拟机最原始
[ 0.0] Examining the guest ...
5.)关机进行母盘清空
注:
##母盘只是封装虚拟机的模版,封装好后不要再开启,母盘坏了所有封装的虚拟机都无法使用
[root@foundation40 ~]# yum whatprovides */virt-sysprep #查找清空母盘的命令
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.
1:libguestfs-tools-c-1.32.7-3.el7.x86_64 : System administration tools for virtual
: machines
Repo : westos
Matched from:
Filename : /usr/bin/virt-sysprep
1:libguestfs-tools-c-1.32.7-3.el7.x86_64 : System administration tools for virtual
: machines
Repo : @westos
Matched from:
Filename : /usr/bin/virt-sysprep
[root@foundation40 ~]# yum -y libguestfs-tools-c-1.32.7-3.el7.x86_64 #安装命令包
[root@foundation40 ~]# virt-sysprep -d rhel7.3-base #清空母盘,使得快照的虚拟机最原始
[ 0.0] Examining the guest ...
5.)快照虚拟机
[root@foundation40 ~]# cd /var/lib/libvirt/images/
[root@foundation40 images]# ls
rh124-desktop-vda.ovl rh124-server-vda.qcow2 rhel7.3.qcow2
rh124-desktop-vda.qcow2 rh124-server-vdb.ovl server1
rh124-desktop-vdb.ovl rh124-server-vdb.qcow2 server2
rh124-desktop-vdb.qcow2 rh124-server.xml server3
rh124-desktop.xml rhel6.5.qcow2
rh124-server-vda.ovl rhel7.3-base.qcow2
[root@foundation40 images]# qemu-img create -f qcow2 -b rhel7.3-base.qcow2 westos1
Formatting 'westos1', fmt=qcow2 size=21474836480 backing_file='rhel7.3-base.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off
[root@foundation40 images]# qemu-img create -f qcow2 -b rhel7.3-base.qcow2 westos2
Formatting 'westos2', fmt=qcow2 size=21474836480 backing_file='rhel7.3-base.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off
[root@foundation40 images]# qemu-img create -f qcow2 -b rhel7.3-base.qcow2 westos3
Formatting 'westos3', fmt=qcow2 size=21474836480 backing_file='rhel7.3-base.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off
7.)进入主机后更改ip 和主机名