1.虚拟机管理
1.脚本安装虚拟机
[root@foundation70 mnt]# vim createvm.sh
#!/bin/bash
virt-install \
--cdrom /home/kiosk/Desktop/rhel-server-7.0-x86_64-dvd.iso \
--ram 1024 \
--cpus 1 \
--disk /var/lib/libvirt/images/test.qcow2,bus=virtio,size=10 \
--name test \
network bridge=br0,model=virtio
[root@foundation70 mnt]# chmod +x createvm.sh
[root@foundation70 mnt]# sh createvm.sh
Starting install...
Allocating 'test.qcow2' | 10 GB 00:00
Creating domain... | 0 B 00:00
(virt-viewer:5043): GSpice-WARNING **: PulseAudio context failed Connection refused
(virt-viewer:5043): GSpice-WARNING **: pa_context_connect() failed: Connection refused
(virt-viewer:5043): GSpice-WARNING **: Warning no automount-inhibiting implementation available
2.虚拟机管理命令
virt-manager ##开启虚拟机管理器
virsh list ##显示正在运行的虚拟机
virsh list --all ##查看所有虚拟机
virsh start name ##打开虚拟机
virsh shutdown name ##正常关闭虚拟机
virsh destory name ##强行关闭虚拟机
virsh-viewer name ##显示虚拟机
3.模拟虚拟机恢复
[root@foundation70 images]# mv /etc/libvirt/qemu/test.xml /mnt ##硬件信息
[root@foundation70 images]# mv /var/lib/libvirt/images/test.qcow2 /mnt ##硬盘
在虚拟机管理器中删除这个装好的虚拟机
[root@foundation70 mnt]# virsh create test.xml ##用硬件信息文件启动虚拟机
在操作过程中会有以下错误:
error: Failed to create domain from test.xml
error: Cannot access storage file '/var/lib/libvirt/images/test.qcow2' (as uid:107, gid:107): No such file or directory
解决方法:
[root@foundation70 mnt]# mv /mnt/test.qcow2 /var/lib/libvirt/images/
[root@foundation70 mnt]# virsh define test.xml ##永久恢复虚拟机
Domain test defined from test.xml
yum
##上层软件管理工具,最重要的功能是可以解决软件的依赖性。yum能够投入使用的前提是必须有yum源,以及配置指向文件
1.从网络上下载与本机系统版本匹配的iso镜像文件
rhel-server-7.0-x86_64-dvd.iso
2.把rhel-server-7.0-x86_64-dvd.iso挂载到/mnt以便系统访问镜像文件
[root@server Desktop]# mount rhel-server-7.0-x86_64-dvd.iso /mnt
mount: /dev/loop0 is write-protected, mounting read-only
3.配置本机yum源指向
[root@server ~]# rm -fr /etc/yum.repos.d/*
[root@server ~]# vim /etc/yum.repos.d/yum.repo
[Server]
name=rhel7.0
baseurl=file:///mnt
gpgcheck=0
4.测试安装软件
[root@server ~]# yum clean all
[root@server ~]# yum install http -y
5.安装资源共享服务
[root@server ~]# yum install http -y
[root@server ~]# systemctl stop firewalld
[root@server ~]# systemctl disable firewalld
[root@server ~]# systemctl start httpd
[root@server ~]# systemctl enable httpd
6.建立共享目录,并挂载镜像文件到共享目录上
[root@server ~]# cd /var/www/html/
[root@server html]# mkdir rhel7.0
[root@server html]# umount /mnt
[root@server html]# mount rhel-server-7.0-x86_64-dvd.iso /var/www/html/rhel7.0
7.测试
##在另一台虚拟机浏览器中输入http://虚拟机ip/rhel7.0
8.修改本机yum源指向
[root@server html]# vim /etc/yum.repos.d/yum.repo
[Server]
name=rhel7.0
baseurl=file:///var/www/html/rhel7.0
gpgcheck=0
9.测试:修改另一台虚拟机的yum源地址
[root@client yum.repos.d]# vim repo
[Server]
name=server
baseurl=http://172.25.70.22/rhel7.0
gpgcheck=0
[root@client yum.repos.d]# yum install httpd -y
Loaded plugins: langpacks
Server | 4.1 kB 00:00
(1/2): Server/group_gz | 134 kB 00:00
(2/2): Server/primary_db | 3.4 MB 00:00
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-17.el7 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-17.el7 for package: httpd-2.4.6-17.el7.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-17.el7.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-17.el7.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-17.el7.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-17.el7 will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
httpd x86_64 2.4.6-17.el7 Server 1.2 M
Installing for dependencies:
apr x86_64 1.4.8-3.el7 Server 103 k
apr-util x86_64 1.5.2-6.el7 Server 92 k
httpd-tools x86_64 2.4.6-17.el7 Server 77 k
mailcap noarch 2.1.41-2.el7 Server 31 k
Transaction Summary
================================================================================
Install 1 Package (+4 Dependent packages)
Total download size: 1.5 M
Installed size: 4.3 M
Downloading packages:
(1/5): apr-1.4.8-3.el7.x86_64.rpm | 103 kB 00:00
(2/5): apr-util-1.5.2-6.el7.x86_64.rpm | 92 kB 00:00
(3/5): httpd-tools-2.4.6-17.el7.x86_64.rpm | 77 kB 00:00
(4/5): mailcap-2.1.41-2.el7.noarch.rpm | 31 kB 00:00
(5/5): httpd-2.4.6-17.el7.x86_64.rpm | 1.2 MB 00:00
--------------------------------------------------------------------------------
Total 4.9 MB/s | 1.5 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : apr-1.4.8-3.el7.x86_64 1/5
Installing : apr-util-1.5.2-6.el7.x86_64 2/5
Installing : httpd-tools-2.4.6-17.el7.x86_64 3/5
Installing : mailcap-2.1.41-2.el7.noarch 4/5
Installing : httpd-2.4.6-17.el7.x86_64 5/5
Verifying : mailcap-2.1.41-2.el7.noarch 1/5
Verifying : httpd-tools-2.4.6-17.el7.x86_64 2/5
Verifying : apr-1.4.8-3.el7.x86_64 3/5
Verifying : apr-util-1.5.2-6.el7.x86_64 4/5
Verifying : httpd-2.4.6-17.el7.x86_64 5/5
Installed:
httpd.x86_64 0:2.4.6-17.el7
Dependency Installed:
apr.x86_64 0:1.4.8-3.el7 apr-util.x86_64 0:1.5.2-6.el7
httpd-tools.x86_64 0:2.4.6-17.el7 mailcap.noarch 0:2.1.41-2.el7
Complete!
10.开机自动挂载在iso
[root@server html]# vim /etc/rc.d/rc.local
chomd /root/Desktop/rhel-server-7.0-x86_64-dvd.iso /var/www/html/rhel7.0
[root@server html]# chmod +x /etc/rc.d/rc.local
11.yum命令
yum install softwarename -y ##安装软件
yum repolist ##列出设定yum源信息
yum remove softwarename ##卸载软件
yum list all ##列出所有软件的名称
yum list softwarename ##查看软件源中是否有该软件
yum list installd softwarename ##是否安装过该软件
yum list available ##列出可以用yum安装的软件名称
yum clean all ##清空yum缓存
yum search softwareinfo ##根据软件信息搜索软件名
yum update softwarename ##更新软件
yum history ##查看软件改变历史
yum whatprovides filename ##在yum源中查找包含filename文件的软件包
yum reinstall softwarename -y ##重新安装软件
12.如何安装软件
rpm
rpm -ivh name.rpm ##安装软件,-v:显示过程,-h指定加密方式为hash
rpm -e name.rpm ##卸载
rpm -ql name ##查看软件生成的文件
rpm -qlp name.rpm ##查询软件安装会生成什么文件
rpm -qa ##查询系统中安装的所有软件名称
rpm -qa | grep wps 询系统中安装的wps名称
rpm -pq name.rpm 查询软件包安装后的名字
rpm -ivh name.rpm --force ##强制安装,但是不能忽略依赖性
rpm -ivh name.rpm --nodeps --force ##忽略软件的依赖性并且强制安装
rpm qi name 查看软件信息