[root@localhost ~]# virt-install --name CentOS-7.3-x86_64 --virt-type kvm --ram 1024 --cdrom=/opt/CentOS-7.3.iso --disk path=/opt/CentOS-7.3-x86_64.raw --network=default --graphics vnc,listen=0.0.0.0 --noautoconsole
Starting install...
Domain installation still in progress. You can reconnect to
the console to complete the installation process.
8.查看是否监听5900端口
[root@localhost opt]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:5900 0.0.0.0:* LISTEN 20009/qemu-kvm
1.启动虚拟机
[root@localhost ~]# virsh list --all
Id Name State
----------------------------------------------------
- CentOS-7.3-x86_64 shut off
- CentOS-7.3-x86_64-2 shut off
[root@localhost ~]# virsh start CentOS-7.3-x86_64-2
Domain CentOS-7.3-x86_64-2 started
2.vnc继续链接,我们看下虚拟机的网卡
[root@localhost ~]# ifconfig
virbr0: flags=4163 mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
[root@localhost ~]# ps aux|grep dns
nobody 10384 0.0 0.0 53884 1112 ? S 07:37 0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root 10385 0.0 0.0 53856 564 ? S 07:37 0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root 31126 0.0 0.0 112708 976 pts/2 R+ 08:40 0:00 grep --color=auto dns
[root@localhost ~]# cat /var/lib/libvirt/dnsmasq/default.conf
##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
##OVERWRITTEN AND LOST. Changes to this configuration should be made using:
## virsh net-edit default
## or other application using the libvirt API.
##
## dnsmasq conf file created by libvirt
strict-order
pid-file=/var/run/libvirt/network/default.pid
except-interface=lo
bind-dynamic
interface=virbr0
dhcp-range=192.168.122.2,192.168.122.254
dhcp-no-override
dhcp-authoritative
dhcp-lease-max=253
dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile
addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts
kvm管理
cpu热修改只能加不能减,不能超过设置的最大数
配置cpu的2种方法
1. 通过启动时候命令行指定
2. 通过xml指定,可以热修改
通过xml文件更改
1.将cpu调成最大四个,当前一个
[root@localhost ~]# virsh edit CentOS-7.3-x86_64-2
4
2.重启生效
[root@localhost ~]# virsh shutdown CentOS-7.3-x86_64-2
Domain CentOS-7.3-x86_64-2 is being shutdown
[root@localhost ~]# virsh list --all
Id Name State
----------------------------------------------------
- CentOS-7.3-x86_64-2 shut off
[root@localhost ~]# virsh start CentOS-7.3-x86_64-2
Domain CentOS-7.3-x86_64-2 started
3.登录到虚拟机,查看cpu个数
4.热修改将cpu设置成2个
[root@localhost ~]# virsh setvcpus CentOS-7.3-x86_64-2 2 --live
5.再次登陆到虚拟机,查看cpu个数
centos7是自动激活了cpu,如果不是的话需要echo 1 > [root@localhost ~]# cat /sys/devices/system/cpu/cpu0/online
1
注意热修改,只能加不能减,也不能超过设置的最大数
[root@localhost ~]# virsh setvcpus CentOS-7.3-x86_64-2 1 --live
error: unsupported configuration: failed to find appropriate hotpluggable vcpus to reach the desired target vcpu count
内存,热球技术能加能减,不能超过设置的最大数
1.修改xml
[root@localhost ~]# virsh edit CentOS-7.3-x86_64-2
1048576 最大内存
1048576 现内存
2.重启生效
[root@localhost ~]# virsh shutdown CentOS-7.3-x86_64-2
Domain CentOS-7.3-x86_64-2 is being shutdown
[root@localhost ~]# virsh list --all
Id Name State
----------------------------------------------------
- CentOS-7.3-x86_64-2 shut off
[root@localhost ~]# virsh start CentOS-7.3-x86_64-2
Domain CentOS-7.3-x86_64-2 started
3.显示虚拟机当前内存
[root@localhost ~]# virsh qemu-monitor-command CentOS-7.3-x86_64-2 --hmp --cmd info balloon
balloon: actual=1024
4.修改虚拟机内存,减少
[root@localhost ~]# virsh qemu-monitor-command CentOS-7.3-x86_64-2 --hmp --cmd balloon 600
显示虚拟机当前内存
[root@localhost ~]# virsh qemu-monitor-command CentOS-7.3-x86_64-2 --hmp --cmd info balloon
balloon: actual=600
5.修改虚拟机内存,添加
[root@localhost ~]# virsh qemu-monitor-command CentOS-7.3-x86_64-2 --hmp --cmd balloon 1024
显示虚拟机当前内存
[root@localhost ~]# virsh qemu-monitor-command CentOS-7.3-x86_64-2 --hmp --cmd info balloon
balloon: actual=1024
6.登录到虚拟机查看
注意,内存也不能超过最大内存
1.默认nat,生产最多的是网桥
[root@localhost ~]# brctl show
bridge name bridge id STP enabled interfaces
virbr0 8000.525400252231 yes virbr0-nic
vnet0
2.如果没有这个命令请安装,默认有
[root@localhost ~]# yum install bridge-utils
3.添加一个网桥
[root@localhost ~]# brctl addbr br0
[root@localhost ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000000000000 no
virbr0 8000.525400252231 yes virbr0-nic
vnet0
4.将eth0添加到br0网桥里,网络会断,这个时候xshell,vnc都会断
[root@localhost ~]# brctl addif br0 eth0
5.登录到宿主机,不能通过xshell登录了,本地去
[root@localhost ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000c29672760 no enth0
virbr0 8000.525400252231 yes virbr0-nic
vnet0
bro 和 eth0关联,eth0有ip,br0没有
6.我们给br0设置一个ip
[root@localhost ~]# ip addr del dev eth0 192.168.1.110/24
[root@localhost ~]# ifconfig br0 192.168.1.11/24 up
注意,排错
尝试xshell链接宿主机,如果链接不上,在宿主机上排查问题
[root@localhost ~]# ip ro li
[root@localhost ~]#route add default gw 192.168.1.1 网关
[root@localhost ~]#iptables -F
因为断网的缘故,我们需要一条命令去执行,这样的话避免去宿主机
[root@localhost ~]# brctl addif br0 eth0 && ip addr del dev eth0 192.168.1.11/24 && ifconfig br0 192.168.1.11/24 up && route add default gw 192.168.1.1 && iptables -F
virsh命令
查看运行的虚拟机
[root@localhost ~]# virsh list
Id Name State
----------------------------------------------------
查看所有状态的虚拟机
[root@localhost ~]# virsh list --all
Id Name State
----------------------------------------------------
- CentOS-7.3-x86_64 shut off
- CentOS-7.3-x86_64-2 shut off
停止虚拟机
[root@localhost ~]# virsh shutdown CentOS-7.3-x86_64-2
Domain CentOS-7.3-x86_64-2 is being shutdown
[root@localhost ~]# virsh list --all
Id Name State
----------------------------------------------------
- CentOS-7.3-x86_64 shut off
- CentOS-7.3-x86_64-2 shut off
启动虚拟机
[root@localhost ~]# virsh start CentOS-7.3-x86_64-2
Domain CentOS-7.3-x86_64-2 started
[root@localhost ~]# virsh list --all
Id Name State
----------------------------------------------------
2 CentOS-7.3-x86_64-2 running
- CentOS-7.3-x86_64 shut off
拔电源停止虚拟机,不会考虑友好的退出
[root@localhost ~]# virsh destroy CentOS-7.3-x86_64-2
Domain CentOS-7.3-x86_64-2 destroyed
[root@localhost ~]# virsh list --all
Id Name State
----------------------------------------------------
- CentOS-7.3-x86_64 shut off
- CentOS-7.3-x86_64-2 shut off
终止挂起状态,可恢复
[root@localhost ~]# virsh suspend CentOS-7.3-x86_64-2
Domain CentOS-7.3-x86_64-2 suspended
[root@localhost ~]# virsh list --all
Id Name State
----------------------------------------------------
3 CentOS-7.3-x86_64-2 paused
- CentOS-7.3-x86_64 shut off
恢复挂机状态
[root@localhost ~]# virsh resume CentOS-7.3-x86_64-2
Domain CentOS-7.3-x86_64-2 resumed
[root@localhost ~]# virsh list --all
Id Name State
----------------------------------------------------
3 CentOS-7.3-x86_64-2 running
- CentOS-7.3-x86_64 shut off
黑名单,禁止操作
virsh undefine 永久删除
但是如果你提前备份一个xml文件,可以在建起来
public class ReverseWords {
/**
* 题目:颠倒一个句子中的词的顺序。比如: I am a student颠倒后变成:student a am I.词以空格分隔。
* 要求:
* 1.实现速度最快,移动最少
* 2.不能使用String的方法如split,indexOf等等。
* 解答:两次翻转。
*/
publ
oracle外部表是只允许只读访问,不能进行DML操作,不能创建索引,可以对外部表进行的查询,连接,排序,创建视图和创建同义词操作。
you can select, join, or sort external table data. You can also create views and synonyms for external tables. Ho
发现一个老外写的不错的jquery插件,可以实现将HTML
表格导出为excel,pdf等格式,
地址在:
https://github.com/kayalshri/
下面看个例子,实现导出表格到excel,pdf
<html>
<head>
<title>Export html table to excel an