安装步骤如下:
1、KVM 需要有 CPU 的支持(Intel VT 或 AMD SVM),在安装 KVM 之前检查一下 CPU 是否提供了虚拟技术的支持。
基于 Intel 处理器的系统,运行grep vmx /proc/cpuinfo查找 CPU flags 是否包括 vmx 关键词
基于 AMD 处理器的系统,运行grep svm /proc/cpuinfo查找 CPU flags 是否包括 svm 关键词
检查BIOS,确保BIOS里开启VT选项:
注 : 一些厂商禁止了机器 BIOS 中的 VT 选项 , 这种方式下 VT 不能被重新打开。**
注意:/proc/cpuinfo 仅从 Linux 2.6.15(Intel) 和 Linux 2.6.16(AMD) 开始显示虚拟化方面的信息。请使用 uname -r 命令查询您的内核版本。如有疑问,请联系硬件厂商。
2、安装软件包:
virt-manager-0.9.0-31.el6.x86_64.rpm下载地址
http://vault.centos.org/6.7/cr/x86_64/Packages/virt-manager-0.9.0-31.el6.x86_64.rpm
yum install kvm libvirt python-virtinst qemu-kvm virt-viewer virt-install bridge-utils
rpm -ivh virt-manager-0.9.0-31.el6.x86_64.rpm
CentOS6.9不要直接使用yum安装virt-manager,新版版会有兼容问题,启动的时候会报启动管理器出错:unsupported format character ‘??0xffffffef) at index 30错误 ,如下图:
其他版本直接
yum install virt-manager -y
即可。
3、启动libvirtd服务加入开机启动
service libvirtd start
chkconfig libvirtd on
4、使用virt-manager管理
VNC登录直接界面操作即可
5、使用virsh命令启动虚拟机
virsh -help
virsh [options]... [<command_string>]
virsh [options]... <command> [args...]
options:
-c | --connect=URI hypervisor connection URI
-r | --readonly connect readonly
-d | --debug=NUM debug level [0-4]
-h | --help this help
-q | --quiet quiet mode
-t | --timing print timing information
-l | --log=FILE output logging to file
-v short version
-V long version
--version[=TYPE] version, TYPE is short or long (default short)
-e | --escape <char> set escape sequence for console
commands (non interactive mode):
Domain Management (help keyword 'domain')
attach-device 从一个XML文件附加装置
attach-disk 附加磁盘设备
attach-interface 获得网络界面
autostart 自动开始一个域
blkdeviotune Set or query a block device I/O tuning parameters.
blkiotune Get or set blkio parameters
blockcommit Start a block commit operation.
blockcopy Start a block copy operation.
blockjob Manage active block operations
blockpull Populate a disk from its backing image.
blockresize Resize block device of domain.
change-media Change media of CD or floppy drive
console 连接到客户会话
cpu-baseline compute baseline CPU
cpu-compare compare host CPU with a CPU described by an XML file
cpu-stats show domain cpu statistics
create 从一个 XML 文件创建一个域
define 从一个 XML 文件定义(但不开始)一个域
desc show or set domain's description or title
destroy destroy (stop) a domain
detach-device 从一个 XML 文件分离设备
detach-disk 分离磁盘设备
detach-interface 分离网络界面
domdisplay domain display connection URI
domhostname print the domain's hostname
domid 把一个域名或 UUID 转换为域 id
domif-setlink set link state of a virtual interface
domiftune get/set parameters of a virtual interface
domjobabort abort active domain job
domjobinfo domain job information
domname 将域 id 或 UUID 转换为域名
dompmsuspend suspend a domain gracefully using power management functions
dompmwakeup wakeup a domain from pmsuspended state
domuuid 把一个域名或 id 转换为域 UUID
domxml-from-native Convert native config to domain XML
domxml-to-native Convert domain XML to native config
dump 把一个域的内核 dump 到一个文件中以方便分析
dumpxml XML 中的域信息
edit 编辑某个域的 XML 配置
inject-nmi Inject NMI to the guest
send-key Send keycodes to the guest
managedsave managed save of a domain state
managedsave-remove Remove managed save of a domain
maxvcpus connection vcpu maximum
memtune Get or set memory parameters
migrate 将域迁移到另一个主机中
migrate-setmaxdowntime set maximum tolerable downtime
migrate-setspeed Set the maximum migration bandwidth
migrate-getspeed Get the maximum migration bandwidth
numatune Get or set numa parameters
reboot 重新启动一个域
reset reset a domain
restore 从一个存在一个文件中的状态恢复一个域
resume 重新恢复一个域
save 把一个域的状态保存到一个文件
save-image-define redefine the XML for a domain's saved state file
save-image-dumpxml saved state domain information in XML
save-image-edit edit XML for a domain's saved state file
schedinfo 显示/设置日程安排变量
screenshot take a screenshot of a current domain console and store it into a file
setmaxmem 改变最大内存限制值
setmem 改变内存的分配
setvcpus 改变虚拟 CPU 的号
shutdown 关闭一个域
start 开始一个(以前定义的)非活跃的域
suspend 挂起一个域
ttyconsole tty 控制台
undefine undefine a domain
update-device update device from an XML file
vcpucount domain vcpu counts
vcpuinfo detailed domain vcpu information
vcpupin control or query domain vcpu affinity
emulatorpin control or query domain emulator affinity
vncdisplay vnc 显示
Domain Monitoring (help keyword 'monitor')
domblkerror Show errors on block devices
domblkinfo domain block device size information
domblklist list all domain blocks
domblkstat 获得域设备块状态
domcontrol domain control interface state
domif-getlink get link state of a virtual interface
domiflist list all domain virtual interfaces
domifstat 获得域网络接口状态
dominfo 域信息
dommemstat get memory statistics for a domain
domstate 域状态
list 列出域
Host and Hypervisor (help keyword 'host')
capabilities 性能
freecell NUMA可用内存
hostname 打印管理程序主机名
node-memory-tune Get or set node memory parameters
nodecpustats Prints cpu stats of the node.
nodeinfo 节点信息
nodememstats Prints memory stats of the node.
nodesuspend suspend the host node for a given time duration
qemu-attach QEMU Attach
qemu-monitor-command QEMU Monitor Command
qemu-agent-command QEMU Guest Agent Command
sysinfo print the hypervisor sysinfo
uri 打印管理程序典型的URI
version 显示版本
Interface (help keyword 'interface')
iface-begin create a snapshot of current interfaces settings, which can be later committed (iface-commit) or restored (iface-rollback)
iface-bridge create a bridge device and attach an existing network device to it
iface-commit commit changes made since iface-begin and free restore point
iface-define define (but don't start) a physical host interface from an XML file
iface-destroy destroy a physical host interface (disable it / "if-down")
iface-dumpxml interface information in XML
iface-edit edit XML configuration for a physical host interface
iface-list list physical host interfaces
iface-mac convert an interface name to interface MAC address
iface-name convert an interface MAC address to interface name
iface-rollback rollback to previous saved configuration created via iface-begin
iface-start start a physical host interface (enable it / "if-up")
iface-unbridge undefine a bridge device after detaching its slave device
iface-undefine undefine a physical host interface (remove it from configuration)
Network Filter (help keyword 'filter')
nwfilter-define define or update a network filter from an XML file
nwfilter-dumpxml network filter information in XML
nwfilter-edit edit XML configuration for a network filter
nwfilter-list list network filters
nwfilter-undefine undefine a network filter
Networking (help keyword 'network')
net-autostart 自动开始网络
net-create 从一个 XML 文件创建一个网络
net-define 从一个 XML 文件定义(但不开始)一个网络
net-destroy destroy (stop) a network
net-dumpxml XML 中的网络信息
net-edit 为网络编辑 XML 配置
net-info network information
net-list 列出网络
net-name 把一个网络UUID 转换为网络名
net-start 开始一个(以前定义的)不活跃的网络
net-undefine 取消定义一个非活跃的网络
net-update update parts of an existing network's configuration
net-uuid 把一个网络名转换为网络UUID
Node Device (help keyword 'nodedev')
nodedev-create create a device defined by an XML file on the node
nodedev-destroy destroy (stop) a device on the node
nodedev-detach detach node device from its device driver
nodedev-dumpxml XML 中的节点设备详情
nodedev-list 这台主机中中的枚举设备
nodedev-reattach reattach node device to its device driver
nodedev-reset 重置节点设备
Secret (help keyword 'secret')
secret-define define or modify a secret from an XML file
secret-dumpxml secret attributes in XML
secret-get-value Output a secret value
secret-list list secrets
secret-set-value set a secret value
secret-undefine undefine a secret
Snapshot (help keyword 'snapshot')
snapshot-create Create a snapshot from XML
snapshot-create-as Create a snapshot from a set of args
snapshot-current Get or set the current snapshot
snapshot-delete Delete a domain snapshot
snapshot-dumpxml Dump XML for a domain snapshot
snapshot-edit edit XML for a snapshot
snapshot-info snapshot information
snapshot-list List snapshots for a domain
snapshot-parent Get the name of the parent of a snapshot
snapshot-revert Revert a domain to a snapshot
Storage Pool (help keyword 'pool')
find-storage-pool-sources-as 找到潜在存储池源
find-storage-pool-sources 发现潜在存储池源
pool-autostart 自动启动某个池
pool-build 建立池
pool-create-as 从一组变量中创建一个池
pool-create 从一个 XML 文件中创建一个池
pool-define-as 在一组变量中定义池
pool-define 在一个 XML 文件中定义(但不启动)一个池
pool-delete 删除池
pool-destroy destroy (stop) a pool
pool-dumpxml XML 中的池信息
pool-edit 为存储池编辑 XML 配置
pool-info 存储池信息
pool-list 列出池
pool-name 将池 UUID 转换为池名称
pool-refresh 刷新池
pool-start 启动一个(以前定义的)非活跃的池
pool-undefine 取消定义一个不活跃的池
pool-uuid 把一个池名称转换为池 UUID
Storage Volume (help keyword 'volume')
vol-clone clone a volume.
vol-create-as 从一组变量中创建卷
vol-create 从一个 XML 文件创建一个卷
vol-create-from create a vol, using another volume as input
vol-delete 删除卷
vol-download download volume contents to a file
vol-dumpxml XML 中的卷信息
vol-info 存储卷信息
vol-key returns the volume key for a given volume name or path
vol-list 列出卷
vol-name returns the volume name for a given volume key or path
vol-path returns the volume path for a given volume name or key
vol-pool returns the storage pool for a given volume key or path
vol-resize resize a vol
vol-upload upload file contents to a volume
vol-wipe wipe a vol
Virsh itself (help keyword 'virsh')
cd change the current directory
connect 连接(重新连接)到 hypervisor
echo echo arguments
exit 退出这个非交互式终端
help 打印帮助
pwd print the current directory
quit 退出这个非交互式终端
virsh
欢迎使用 virsh,虚拟化的交互式终端。
输入:'help' 来获得命令的帮助信息
'quit' 退出
virsh # help
查看kvm虚拟机状态
# virsh list --all
Id 名称 状态
----------------------------------------------------
1 c69_164 running
2 c69_db running
KVM虚拟机开机
# virsh start c69_db
KVM虚拟机关机
默认情况下virsh工具不能对linux虚拟机进行关机操作,linux操作系统需要开启与启动acpid服务。在安装KVM linux虚拟机必须配置此服务。
# chkconfig acpid on
# service acpid restart
virsh关机
virsh shutdown c69_164
域 c69_164 被关闭
强制关闭电源
# virsh destroy c69_164
配置虚拟机开机启动
virsh autostart c69_164
域 c69_164标记为自动开始
物理删除虚拟机
virsh destroy c69_164
删除配置文件
virsh undefine c69_164
挂起服务器
virsh suspend c69_164
恢复服务器
virsh resume c69_164
编辑服务器
virsh edit c69_164
KVM虚拟机默认配置文件位置: /etc/libvirt/qemu/
autostart目录是配置kvm虚拟机开机自启动目录。
更多参考:
Tag标签:「虚拟机 kvm」更新时间:「2021-11-03 21:05:19」阅读次数:「1945」