12 May 2013

快速理解VirtualBox的四种网络连接方式


VirtualBox中有4中网络连接方式:
  1. NAT
  2. Bridged Adapter
  3. Internal
  4. Host-only Adapter
VMWare中有三种,其实他跟VMWare 的网络连接方式都是一样概念,只是比VMWare多了Internal方式。
要让自己(或别人)理解深刻,方法就是做比较和打比方,比较之间的不同和相同,拿熟知的事物打比方。先来一张图,通过这张图就很容易看出这4种方式的区别:
VirtualBox
(注:此图直接取至Finalbug的Blog,表示感谢)
再来用文字做详细的解释(其实归结起来就是上面的那张图):
1、NAT
NAT:Network Address Translation,网络地址转换
NAT模式是最简单的实现虚拟机上网的方式,你可以这样理解:
Guest访问网络的所有数据都是由主机提供的,Guest并不真实存在于网络中,主机与网络中的任何机器都不能查看和访问到Guest的存在。
Guest可以访问主机能访问到的所有网络,但是对于主机以及主机网络上的其他机器,Guest又是不可见的,甚至主机也访问不到Guest。
虚拟机与主机的关系:只能单向访问,虚拟机可以通过网络访问到主机,主机无法通过网络访问到虚拟机。
虚拟机与网络中其他主机的关系:只能单向访问,虚拟机可以访问到网络中其他主机,其他主机不能通过网络访问到虚拟机。
虚拟机与虚拟机的关系:相互不能访问,虚拟机与虚拟机各自完全独立,相互间无法通过网络访问彼此。
2、Bridged Adapter(网桥模式)
网桥模式,你可以这样理解:
它是通过主机网卡,架设了一条桥,直接连入到网络中了。因此,它使得虚拟机能被分配到一个网络中独立的IP,所有网络功能完全和在网络中的真实机器一样。
网桥模式下的虚拟机,你把它认为是真实计算机就行了。
虚拟机与主机的关系:可以相互访问,因为虚拟机在真实网络段中有独立IP,主机与虚拟机处于同一网络段中,彼此可以通过各自IP相互访问。
虚拟机于网络中其他主机的关系:可以相互访问,同样因为虚拟机在真实网络段中有独立IP,虚拟机与所有网络其他主机处于同一网络段中,彼此可以通过各自IP相互访问。
虚拟机与虚拟机的关系:可以相互访问,原因同上。
3、Internal(内网模式)
内网模式,顾名思义就是内部网络模式:
虚拟机与外网完全断开,只实现虚拟机于虚拟机之间的内部网络模式。
虚拟机与主机的关系:不能相互访问,彼此不属于同一个网络,无法相互访问。
虚拟机与网络中其他主机的关系:不能相互访问,理由同上。
虚拟机与虚拟机的关系:可以相互访问,前提是在设置网络时,两台虚拟机设置同一网络名称。如上配置图中,名称为intnet。
4、Host-only Adapter(主机模式)
主机模式,这是一种比较复杂的模式,需要有比较扎实的网络基础知识才能玩转。可以说前面几种模式所实现的功能,在这种模式下,通过虚拟机及网卡的设置都可以被实现。
我们可以理解为Guest在主机中模拟出一张专供虚拟机使用的网卡,所有虚拟机都是连接到该网卡上的,我们可以通过设置这张网卡来实现上网及其他很多功能,比如(网卡共享、网卡桥接等)。
虚拟机与主机的关系:默认不能相互访问,双方不属于同一IP段,host-only网卡默认IP段为192.168.56.X 子网掩码为255.255.255.0,后面的虚拟机被分配到的也都是这个网段。通过网卡共享、网卡桥接等,可以实现虚拟机于主机相互访问。
虚拟机与网络主机的关系:默认不能相互访问,原因同上,通过设置,可以实现相互访问。
虚拟机与虚拟机的关系:默认可以相互访问,都是同处于一个网段。
以上关于这4种连接方式的文字解释,基本上抄自于(转)VirtualBox网络设置与应用详解(图解+文字)这篇文章,但没有找到此文的原始出处。
关于这几种连接方式,理解VMWare的三种网络连接模式(bridged、NAT、host-only)里的解释只是换了文字来表述,虽然显得重复,但为了理解,干脆就写成了这两篇Blog。
Update:我刚装上VirtualBox的时候所有的网络连接方式都试过了,但虚拟机和虚拟机之间就是不能相互访问,Ping都Ping不通,我在想难道VirtualBox的网络设置有这么复杂吗,后来想到是不是Windows XP的防火墙的问题,关闭之,一切就正常了,Fuck!
参考资料:
  1. VirtualBox四种网络连接模式比较
  2. (转)VirtualBox网络设置与应用详解(图解+文字)

Quercus on Google App Engine - 2.0


Quercus on Google App Engine - 2.0


The following article originally appeared on JavaAdvent 2012.

It's been a 3.5 years ago to this day since I last wrote about running Quercus on Google App Engine (GAE). The article detailed a crazy experiment to get a PHP application, Wordpress, running on GAE. I still remember it being a painful experience because of number of changes I had to make to Wordpress to get it working. It was all due to the GAE Java environment being so drastically different from what Java developers were used to. It was heavily sandboxed and had no SQL support. You couldn't launch new Threads. You couldn't write to the file system. But those were the tradeoffs you had to live with if you wanted to deploy your application to the all-wonderful Cloud.
Fast-forward to 2012 and GAE has come a long way. GAE now allows you to spawn new Threads (currently in beta). You still cannot write to the file system, but for all it's worth there is a new GAE Files API that gives you file-like concepts. And you can run your very own MySQL instances on Google's infrastructure (albeit Google's customized version of MySQL).
What hasn't changed over the years is that you're still expected to hit major roadblocks as you migrate your existing web applications over to GAE. And you'll have to make heavy modifications to your application to 1) make it work and 2) be performant on GAE.
So this is where Quercus comes into the picture. At Caucho, we spent a lot of time getting Quercus to work seamlessly with GAE. Our goal was to abstract the GAE details away so that developers don't have to worry about the fact that the application is running on GAE. Things just work transparently behind the scenes for PHP applications. For example,
  • PHP file_*() functions work just like they do before (including writing to files!)
  • PHP mysql_*() functions and PDO work just like they do before

What this means is that we can run existing PHP applications on GAE without any modifications! Say hello to "Wordpress on Google App Engine” 2.0! But first, let's start with some formalities.

I. Introduction to Quercus

Quercus is Caucho's 100% Java implementation of the PHP language runtime and libraries. Currently, Quercus supports PHP 5.3 language features and contains a multitude of libraries developed in-house including but not limited to apc, bcmath, curl, date, dom, filter, gettext, json, mail, mbstring, mcrypt, pdf, pdo, postgres, reflection, regexp, spl, zip, and zlib.
Quercus can run as a servlet or on the command line. For our case, we're interested in running it as a servlet:
  1. Download Resin Java Application Server and it'll come with Quercus enabled by default and ready to go.
  2. Uncompress the archive and start up Resin with:
        ./bin/resin.sh console
  3. Then create a webapps/ROOT/test.php file with the following contents:
    <?php
    
      phpinfo();
    
    ?>
  4. Browse to http://localhost:8080/test.php and you should see the following:
Congrats! You have PHP running natively on a Java server.

II. Running Quercus on Tomcat

Okay, so you want to use Tomcat instead of Resin? No worries.
  1. Copy lib/resin.jar from the Resin download above to Tomcat's webapps/ROOT/WEB-INF/lib directory.
  2. Add QuercusServlet to Tomcat's webapps/ROOT/WEB-INF/web.xml file:
    <web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
      <servlet>
        <servlet-name>Quercus Servlet</servlet-name>
        <servlet-class>com.caucho.quercus.servlet.GoogleQuercusServlet</servlet-class>
        <init-param>
          <param-name>ini-file</param-name>
          <param-value>WEB-INF/php.ini</param-value>
        </init-param>
      </servlet>
    
      <servlet-mapping>
        <servlet-name>Quercus Servlet</servlet-name>
        <url-pattern>*.php</url-pattern>
      </servlet-mapping>
    
      <welcome-file-list>
        <welcome-file>index.php</welcome-file>
      </welcome-file-list>
    </web-app>

02 April 2012

GFW(IPv6 + Proxy + Google App Engine)

------------------------PART 1 IP V6---------------------------------------------------------------------------------------------------------------
1. 在V6上还没有防火墙,GFW目前只是建在V4。 
2. 如果网站提供IPV6的版本,则可以无墙直接访问。 例如Google的所有服务, BBC, APPLE等。
3. 可中国大陆境内覆盖host文件达到此目的。host文件的下载在附件中。

Win 7, host位置     C:\Windows\System32\drivers\etc

4. 另,本机需要获得一个V6的地址
安装软件:   
*下载附件里面的文件,需要把.pdf后缀改为.exe   32位版本。
可以用默认的服务器地址,
anonymous.freenet6.net
或者Server Address:
中南大學 isatap.hust.edu.cn
上海交大 isatap.sjtu.edu.cn
清华大学 59.66.4.50
大连海事 isatap.dlmu.edu.cn
* 如果直接在学校,有的学校直接支持V6协议栈,可以直接获得V6地址,而不用V6 over V4的方式。
* Known Issues:   Google Talk桌面版不能使用;
----------------------------PART 2 PROXY----------------------------------------------------------------------------------------------------------
1. 以上还不能访问不提供IPV6服务的网站;
2. 解决方案是,需要代理
3. Chrome install extentsion: switchy
    新建profile:  choose Automatic connection:  http://edu6.zzzcn.info/proxy.pac 
4. 此公共代理速度比较慢, 只是备用选择。但是switchy是个很好的工具;

----------------------------PART 3 GOOGLE APP ENGINE----------------------------------------------------------------------------------------------