#准备磁盘文件
[root@kvm01 /data]# qemu-img create -f qcow2 -b web-blog.qcow2 web-blog▽-test.qcow2
Formatting 'web-blog-test.qcow2', fmt=qcow2 size=10737418240 backing_file='web-blog.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off
#导出配置文件
[root@kvm01 /data]# virsh dumpxml web-blog > web-blog-test.xml
#编辑配置文件
[root@kvm01 /data]# vim web-blog-test.xml
#修改虚拟机名字
#删除虚拟机uuid
#修改磁盘路径
#删除mac地址
#导入配置文件
[root@kvm01 /data]# virsh define web-blog-test.xml
Domain web-blog-test defined from web-blog-test.xml
#启动
[root@kvm01 /data]# virsh start web-blog-test
Domain web-blog-test started
#查看
[root@kvm01 /data]# virsh list
Id Name State
----------------------------------------------------
2 centos6 running
3 web-www running
4 web-blog-test running
4.8 kvm虚拟机的桥接网络
1. 添加网卡
[root@kvm01 /data]# virsh iface-bridge eth0 br0
?reated bridge br0 with attached device eth0
Bridge interface br0 started
2. 编辑配置文件
[root@kvm01 /data]# virsh edit web-www
3. 远程连接
[root@kvm01 /data]# virsh console web-www
Connected to domain web-www
Escape character is ^]
CentOS Linux 7 (Core)
Kernel 3.10.0-327.el7.x86_64 on an x86_64
localhost login: root
Password:
Last login: Tue Jul 16 07:52:05 on ttyS0
[root@localhost ~]#
4. 验证IP
[root@Fvc ~]# ip a
1: lo: mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:f0:5e:d7 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.128/24 brd 10.0.0.255 scope global dynamic eth0
valid_lft 1291sec preferred_lft 1291sec
inet6 fe80::5054:ff:fef0:5ed7/64 scope link
valid_lft forever preferred_lft forever
[root@Fvc ~]# lscpu|grep -i kvm
Hypervisor vendor: KVM
[root@kvm01 /data]# qemu-img create -f qcow2 -b web-www.qcow2 web04.qcow2
Formatting 'web04.qcow2', fmt=qcow2 size=10737418240 backing_file='web-www.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off
[root@kvm01 /data]# virt-install --virt-type kvm --os-type=linux --os-variant rhel7 --name web04 --memory 512,maxmemory=2048 --vcpus 1 --disk /data/web04.qcow2 --boot hd --network bridge=br0 --graphics vnc,listen=0.0.0.0 --noautoconsole
Starting install...
Domain creation completed.
[root@kvm01 /data]# virsh list --all
Id Name State
----------------------------------------------------
2 centos6 running
6 web-www running
7 web-blog-test running
8 web-blog running
9 web04 running
#临时生效
[root@kvm01 /data]# virsh setmem web04 1024M
#永久生效
[root@kvm01 /data]# virsh setmem web04 1024M --config
#登陆web04查看
[root@kvm01 ~]# virsh console web04
Connected to domain web04
Escape character is ^]
CentOS Linux 7 (Core)
Kernel 3.10.0-327.el7.x86_64 on an x86_64
localhost login: root
Password:
Last login: Tue Jul 16 15:51:34 on tty1
[root@localhost ~]# free -l
total used free shared buff/cache available
Mem: 1000504 77768 813644 8488 109092 797128
Low: 1000504 186860 813644
High: 0 0 0
Swap: 0 0 0
[root@localhost ~]#
4.9.4热添加CPU
4.10 virt-manager和kvm虚拟机热迁移(共享的网络文件系统)
作业1:
扩容kvm虚拟机的根分区
关闭虚拟机
[root@kvm01 /data]# virsh list
Id Name State
----------------------------------------------------
宿主机磁盘扩容
# 扩容前
[root@kvm01 /data]# qemu-img info web-www.qcow2
image: web-www.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 984M
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: true
# 扩容
[root@kvm01 /data]# qemu-img resize web-www.qcow2 +10G
Image resized.
# 扩容后
[root@kvm01 /data]# qemu-img info web-www.qcow2
image: web-www.qcow2
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 984M
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: true
进入虚拟机
[root@kvm01 ~]# virsh console web-www
Connected to domain web-www
Escape character is ^]
CentOS Linux 7 (Core)
Kernel 3.10.0-327.el7.x86_64 on an x86_64
localhost login: root
Password:
Last login: Tue Jul 16 15:51:34 on tty1
# 检查,没有变化
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 10G 912M 9.1G 9% /
devtmpfs 488M 0 488M 0% /dev
tmpfs 497M 0 497M 0% /dev/shm
tmpfs 497M 6.6M 491M 2% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
tmpfs 100M 0 100M 0% /run/user/0
在虚拟机中调整分区
[root@localhost ~]# fdisk /dev/vda
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p #p
Disk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000076b4
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 20971519 10484736 83 Linux
Command (m for help): d #d
Selected partition 1
Partition 1 is deleted
Command (m for help): n #n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048): #回车
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): #回车
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set
Command (m for help): w #w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
1. aggregateByKey的运行机制
/**
* Aggregate the values of each key, using given combine functions and a neutral "zero value".
* This function can return a different result type
spark-sql是Spark bin目录下的一个可执行脚本,它的目的是通过这个脚本执行Hive的命令,即原来通过
hive>输入的指令可以通过spark-sql>输入的指令来完成。
spark-sql可以使用内置的Hive metadata-store,也可以使用已经独立安装的Hive的metadata store
关于Hive build into Spark
// Max value in Array
var arr = [1,2,3,5,3,2];Math.max.apply(null, arr); // 5
// Max value in Jaon Array
var arr = [{"x":"8/11/2009","y":0.026572007},{"x"
在使用XMlhttpRequest对象发送请求和响应之前,必须首先使用javaScript对象创建一个XMLHttpRquest对象。
var xmlhttp;
function getXMLHttpRequest(){
if(window.ActiveXObject){
xmlhttp:new ActiveXObject("Microsoft.XMLHTTP