<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Hsin wang</title>
    <description>王鑫的个人博客</description>
    <link>https://hsinin.github.io/</link>
    <atom:link href="https://hsinin.github.io/sitemap.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Tue, 11 Apr 2017 14:41:03 +0000</pubDate>
    <lastBuildDate>Tue, 11 Apr 2017 14:41:03 +0000</lastBuildDate>
    <generator>Jekyll v3.4.3</generator>
    
      <item>
        <title>git总结</title>
        <description>&lt;h3 id=&quot;恢复代码&quot;&gt;恢复代码&lt;/h3&gt;
&lt;p&gt;场景1：当你改乱了工作区某个文件的内容，想直接丢弃工作区的修改时:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git checkout -- file
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;场景2：已经add，想丢弃修改:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git reset HEAD file    或者
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git rm --cached file
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;场景3：已经commit，想要撤销本次提交:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git reset HEAD^
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;注：&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;HEAD^       上个版本
HEAD^^      上上个版本
...
HEAD~100    前100个版本
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;h3 id=&quot;git-reset&quot;&gt;git reset&lt;/h3&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git reset --soft    # 只撤回commit内容
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git reset   # 撤回commit和add的内容
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git reset --hard    # 撤回所有修改的内容，包括工作区的
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;h3 id=&quot;远程分支&quot;&gt;远程分支&lt;/h3&gt;

&lt;p&gt;创建远程分支&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git push origin test:master     # 提交本地test分支作为远程的master分支
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git branch test       #分两步
git push origin test
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;删除远程分支&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git push origin :test     # 远程的test将被删除，但是本地还会保存的
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git push origin --delete test      # 删除远程分支
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;h3 id=&quot;git-diff&quot;&gt;git diff&lt;/h3&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git diff     # 比较的是工作目录和暂存区之间的差异
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git diff --cached   # 比较暂存区和上次提交时的快照之间(HEAD)的差异
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git diff --stat     #查看简单的对比结果
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;h3 id=&quot;patch&quot;&gt;patch&lt;/h3&gt;

&lt;p&gt;生成patch&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git format-patch  节点A  节点B     # 两个节点之间的提交
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git format-patch -1 节点A （-n就表示要生成几个节点的提交）
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git format-patch HEAD^ 依次类推……
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;打patch&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git apply --stat newpatch.patch     # 检查patch文件
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git apply --check  newpatch.patch   # 检查能否应用成功
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git am --signoff &amp;lt; newpatch.patch   # 打补丁 
(使用-s或--signoff选项，可以commit信息中加入Signed-off-by信息)
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
</description>
        <pubDate>Tue, 11 Apr 2017 00:00:00 +0000</pubDate>
        <link>https://hsinin.github.io/2017/04/11/git%E6%80%BB%E7%BB%93/</link>
        <guid isPermaLink="true">https://hsinin.github.io/2017/04/11/git%E6%80%BB%E7%BB%93/</guid>
        
        
        <category>git</category>
        
      </item>
    
      <item>
        <title>使用ssh Keygen和ssh Copy Id三步实现ssh无密码登录</title>
        <description>&lt;p&gt;&lt;strong&gt;ssh-keygen&lt;/strong&gt;  产生公钥与私钥对&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ssh-copy-id&lt;/strong&gt; 将本机的公钥复制到远程机器的authorized_keys文件中，ssh-copy-id也能让你有到远程机器的home, ~./ssh , 和 ~/.ssh/authorized_keys的权利&lt;/p&gt;

&lt;p&gt;&lt;em&gt;假设，存在HostA和HostB两台Host，那么在HostA上可以执行下列命令进行无密码登录设置。&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;在HostA上创建公钥和密钥（一直按Enter）&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[root@HostA]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/jsmith/.ssh/id_rsa):[Enter key]
Enter passphrase (empty for no passphrase): [Press enter key]
Enter same passphrase again: [Pess enter key]
Your identification has been saved in /home/jsmith/.ssh/id_rsa.
Your public key has been saved in /home/jsmith/.ssh/id_rsa.pub.
The key fingerprint is:
33:b3:fe:af:95:95:18:11:31:d5:de:96:2f:f2:35:f9
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;用ssh-copy-id将公钥复制到远程机器中&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[root@HostB]# ssh-copy-id root@HostB_IP
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;a href=&quot;http://blog.chinaunix.net/uid-26284395-id-2949145.html&quot;&gt;常见问题&lt;/a&gt;&lt;/p&gt;
</description>
        <pubDate>Wed, 25 Jan 2017 00:00:00 +0000</pubDate>
        <link>https://hsinin.github.io/2017/01/25/%E4%BD%BF%E7%94%A8ssh-keygen%E5%92%8Cssh-copy-id%E4%B8%89%E6%AD%A5%E5%AE%9E%E7%8E%B0SSH%E6%97%A0%E5%AF%86%E7%A0%81%E7%99%BB%E5%BD%95/</link>
        <guid isPermaLink="true">https://hsinin.github.io/2017/01/25/%E4%BD%BF%E7%94%A8ssh-keygen%E5%92%8Cssh-copy-id%E4%B8%89%E6%AD%A5%E5%AE%9E%E7%8E%B0SSH%E6%97%A0%E5%AF%86%E7%A0%81%E7%99%BB%E5%BD%95/</guid>
        
        
      </item>
    
      <item>
        <title>使用桥接方法使主机和虚拟机可以ping通</title>
        <description>&lt;h3 id=&quot;host端&quot;&gt;host端：&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;添加网桥&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# brctl addbr br0
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;让eth0成为br0的一个端口&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# brctl addif br0 eth0
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;删除虚拟机ip地址&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# ip addr del dev eth0 192.168.100.37/24
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;开启网桥&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# ifconfig br0 192.168.100.37/24 up
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;添加路由&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# route add default gw 192.168.100.1
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;h3 id=&quot;guest端&quot;&gt;guest端：&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;使网卡连接到 br0&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;设置Device model 为 virtio&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;
</description>
        <pubDate>Tue, 24 Jan 2017 00:00:00 +0000</pubDate>
        <link>https://hsinin.github.io/2017/01/24/%E4%BD%BF%E7%94%A8%E6%A1%A5%E6%8E%A5%E6%96%B9%E6%B3%95%E4%BD%BF%E4%B8%BB%E6%9C%BA%E5%92%8C%E8%99%9A%E6%8B%9F%E6%9C%BA%E5%8F%AF%E4%BB%A5ping%E9%80%9A/</link>
        <guid isPermaLink="true">https://hsinin.github.io/2017/01/24/%E4%BD%BF%E7%94%A8%E6%A1%A5%E6%8E%A5%E6%96%B9%E6%B3%95%E4%BD%BF%E4%B8%BB%E6%9C%BA%E5%92%8C%E8%99%9A%E6%8B%9F%E6%9C%BA%E5%8F%AF%E4%BB%A5ping%E9%80%9A/</guid>
        
        
      </item>
    
      <item>
        <title>配置yum源</title>
        <description>&lt;ol&gt;
  &lt;li&gt;删除RHEL中的yum命令&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# rpm -aq | grep yum |xargs rpm -e --nodeps
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;下载rpm包（具体版本号到Packages下查看）&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# wget http://mirrors.163.com/centos/6.7/os/x86_64/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm

# wget http://mirrors.163.com/centos/6.7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-30.el6.noarch.rpm

# wget http://mirrors.163.com/centos/6.7/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;安装rpm包&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# rpm -ivh *.rpm
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;ol&gt;
  &lt;li&gt;删除自带的yum源&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# rm /etc/yum.repos.d/*
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;下载yum源并修改版本号&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo

# vim CentOS6-Base-163.repo

:0,$s/$releasever/6/g       #替换所有的$releasever为指定的版本号，此处为 RHEL 6.0
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;清除缓存&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# yum clean all

# yum makecache
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
</description>
        <pubDate>Mon, 23 Jan 2017 00:00:00 +0000</pubDate>
        <link>https://hsinin.github.io/2017/01/23/%E9%85%8D%E7%BD%AEyum%E6%BA%90/</link>
        <guid isPermaLink="true">https://hsinin.github.io/2017/01/23/%E9%85%8D%E7%BD%AEyum%E6%BA%90/</guid>
        
        
      </item>
    
      <item>
        <title>简单配置网络</title>
        <description>&lt;h3 id=&quot;通过命令行临时配置&quot;&gt;通过命令行临时配置&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;配置ip、netmask&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# ifconfig eth0 192.168.100.200 netmask 255.255.255.0
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;配置网关&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# route add default gw 192.168.100.1
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;修改完重启网络&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# service network restart
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;em&gt;但以上配置ip、netmask和gateway的方法在重启后会失效，永久生效方法如下:&lt;/em&gt;&lt;/p&gt;

&lt;h3 id=&quot;通过修改配置文件&quot;&gt;通过修改配置文件&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;禁用网卡&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# ifdown eth0
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;修改/etc/sysconfig/network-scripts/ifcfg-eth0&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;IPADDR=192.168.100.200
NETMASK=255.255.255.0
GATEWAY=192.168.100.1
ONBOOT=yes
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;开启网卡&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# ifup eth0
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;配置DNS（需要在/etc/resolv.conf中添加DNS服务器）&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;nameserver 192.168.112.3
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
</description>
        <pubDate>Thu, 19 Jan 2017 00:00:00 +0000</pubDate>
        <link>https://hsinin.github.io/2017/01/19/%E7%AE%80%E5%8D%95%E9%85%8D%E7%BD%AE%E7%BD%91%E7%BB%9C/</link>
        <guid isPermaLink="true">https://hsinin.github.io/2017/01/19/%E7%AE%80%E5%8D%95%E9%85%8D%E7%BD%AE%E7%BD%91%E7%BB%9C/</guid>
        
        
      </item>
    
      <item>
        <title>虚拟化技术概述与理解</title>
        <description>&lt;h2 id=&quot;什么是虚拟化技术&quot;&gt;什么是虚拟化技术&lt;/h2&gt;

&lt;p&gt;虚拟化是将计算机的各种实体资源，如服务器、网络、内存及存储等，予以抽象、转换后呈现出来，打破实体结构间的不可切割的障碍，使用户可以比原本的组态更好的方式来应用这些资源。&lt;/p&gt;

&lt;h2 id=&quot;虚拟化技术的优势&quot;&gt;虚拟化技术的优势&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;更高的资源利用率&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;降低管理成本&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;提高使用灵活性&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;提高安全性&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;更高的可用性&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;更高的可扩展性&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;虚拟化技术的实现方式&quot;&gt;虚拟化技术的实现方式&lt;/h2&gt;

&lt;p&gt;市场上最常见的虚拟化软件有VMWare workstation(VMWare)、VirtualBox(Oracle)、Hyper-V(Microsoft)、KVM(Redhat)、Xen等，这些软件统称之为VMM(Virtual Machine Monitor)，使用不同的虚拟化实现。&lt;/p&gt;

&lt;h3 id=&quot;全虚拟化硬件辅助虚拟化技术&quot;&gt;全虚拟化（硬件辅助虚拟化技术）&lt;/h3&gt;

&lt;p&gt;在虚拟机（VM）和硬件之间加了一个软件层–Hypervisor，或者叫做虚拟机管理程序（VMM）。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/virtualization/171310170501018.gif&quot; alt=&quot;全虚拟化&quot; /&gt;&lt;/p&gt;

&lt;p&gt;hypervisor 可以划分为两大类：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;hypervisor 是直接运行在物理硬件之上的，例子：基于内核的虚拟机（KVM —— 它本身是一个基于操作系统的 hypervisor）&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;hypervisor 运行在另一个操作系统（运行在物理硬件之上）中，例子：QEMU 和 WINE&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;优点：运行在虚拟机上的操作系统没有经过任何修改。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;缺点：Hypervisor会占用一定的资源，性能有所降低。&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;半虚拟化技术&quot;&gt;半虚拟化技术&lt;/h3&gt;

&lt;p&gt;客户操作系统进行了修改，增加了一个专门的API，这个API可以将客户操作系统发出的指令进行最优化，
即不需要Hypervisor耗费一定的资源进行翻译操作。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/virtualization/171339004723536.gif&quot; alt=&quot;半虚拟化&quot; /&gt;&lt;/p&gt;

&lt;p&gt;例子：xen&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;优点：不需要Hypervisor耗费一定的资源进行翻译操作，性能提高&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;缺点：需要修改包含该API的操作系统，比较麻烦；而且对于某些不含该API的操作系统（主要是windows）来说，就不行能用这种方法。&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Mon, 16 Jan 2017 00:00:00 +0000</pubDate>
        <link>https://hsinin.github.io/2017/01/16/%E8%99%9A%E6%8B%9F%E5%8C%96%E6%8A%80%E6%9C%AF/</link>
        <guid isPermaLink="true">https://hsinin.github.io/2017/01/16/%E8%99%9A%E6%8B%9F%E5%8C%96%E6%8A%80%E6%9C%AF/</guid>
        
        
        <category>virtualization</category>
        
      </item>
    
      <item>
        <title>KVM-Qemu-Libvirt三者之间的关系</title>
        <description>&lt;h2 id=&quot;qemu&quot;&gt;Qemu&lt;/h2&gt;

&lt;p&gt;Qemu是一个模拟器，它向Guest OS模拟CPU和其他硬件，Guest OS认为自己和硬件直接打交道，
其实是同Qemu模拟出来的硬件打交道，Qemu将这些指令转译给真正的硬件。&lt;/p&gt;

&lt;p&gt;由于所有的指令都要从Qemu里面过一手，因而性能较差。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/virtualization/wKiom1WdDYyjiVZiAAECBtAEQ5E590.jpg&quot; alt=&quot;qemu&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;kvm&quot;&gt;KVM&lt;/h2&gt;

&lt;p&gt;KVM是linux内核的模块，它需要CPU的支持，采用硬件辅助虚拟化技术Intel-VT，AMD-V，
内存的相关如Intel的EPT和AMD的RVI技术，Guest OS的CPU指令不用再经过Qemu转译，直接运行，大大提高了速度，
KVM通过/dev/kvm暴露接口，用户态程序可以通过ioctl函数来访问这个接口。见如下伪代码：&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;open(&quot;/dev/kvm&quot;)
ioctl(KVM_CREATE_VM)
ioctl(KVM_CREATE_VCPU)
for (;;) {
    ioctl(KVM_RUN)
        switch (exit_reason) {
        case KVM_EXIT_IO:
        case KVM_EXIT_HLT:
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;KVM内核模块本身只能提供CPU和内存的虚拟化，所以它必须结合QEMU才能构成一个完成的虚拟化技术，这就是下面要说的qemu-kvm。&lt;/p&gt;

&lt;h2 id=&quot;qemu-kvm&quot;&gt;qemu-kvm&lt;/h2&gt;

&lt;p&gt;Qemu将KVM整合进来，通过ioctl调用/dev/kvm接口，将有关CPU指令的部分交由内核模块来做。
kvm负责cpu虚拟化+内存虚拟化，实现了cpu和内存的虚拟化，但kvm不能模拟其他设备。
qemu模拟IO设备（网卡，磁盘等），kvm加上qemu之后就能实现真正意义上服务器虚拟化。
因为用到了上面两个东西，所以称之为qemu-kvm。&lt;/p&gt;

&lt;p&gt;Qemu模拟其他的硬件，如Network, Disk，同样会影响这些设备的性能，
于是又产生了pass through半虚拟化设备virtio_blk, virtio_net，提高设备性能。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/virtualization/wKiom1WdDc2CEwy6AAGPf4VzQao172.jpg&quot; alt=&quot;qemu-kvm&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;libvirt&quot;&gt;Libvirt&lt;/h2&gt;

&lt;p&gt;libvirt是目前使用最为广泛的对KVM虚拟机进行管理的工具和API。Libvirtd是一个daemon进程，
可以被本地的virsh调用，也可以被远程的virsh调用，Libvirtd调用qemu-kvm操作虚拟机。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/virtualization/wKioL1WdD72RRy8mAAIuDm6sVAY591.jpg&quot; alt=&quot;libvirt&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;nodehypervisordomain&quot;&gt;Node/Hypervisor/Domain&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;节点（Node）：一个物理机器，上面可能运行着多个虚拟客户机。Hypervisor和Domain都运行在Node之上。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Hypervisor：也称虚拟机监控器（VMM），如KVM、Xen、VMware、Hyper-V等，是虚拟化中的一个底层软件层，
它可以虚拟化一个节点让其运行多个虚拟客户机（不同客户机可能有不同的配置和操作系统）。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;域（Domain）：是在Hypervisor上运行的一个客户机操作系统实例。域也被称为实例（instance，如亚马逊的AWS云计算服务中客户机就被称为实例）、
客户机操作系统（guest OS）、虚拟机（virtual machine），它们都是指同一个概念。&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;三者的关系可以简单用下面的图来表示：&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/virtualization/libvirt-node-hypervisor-domain.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
</description>
        <pubDate>Mon, 16 Jan 2017 00:00:00 +0000</pubDate>
        <link>https://hsinin.github.io/2017/01/16/KVM-Qemu-Libvirt%E4%B8%89%E8%80%85%E4%B9%8B%E9%97%B4%E7%9A%84%E5%85%B3%E7%B3%BB/</link>
        <guid isPermaLink="true">https://hsinin.github.io/2017/01/16/KVM-Qemu-Libvirt%E4%B8%89%E8%80%85%E4%B9%8B%E9%97%B4%E7%9A%84%E5%85%B3%E7%B3%BB/</guid>
        
        
        <category>virtualization</category>
        
      </item>
    
      <item>
        <title>test-我写的第一篇githug blog</title>
        <description>&lt;h2 id=&quot;我写的第一篇githug-blog&quot;&gt;我写的第一篇githug blog&lt;/h2&gt;
</description>
        <pubDate>Mon, 16 Jan 2017 00:00:00 +0000</pubDate>
        <link>https://hsinin.github.io/2017/01/16/test/</link>
        <guid isPermaLink="true">https://hsinin.github.io/2017/01/16/test/</guid>
        
        
        <category>test</category>
        
      </item>
    
  </channel>
</rss>
