免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2102 | 回复: 0
打印 上一主题 下一主题

Eucalyptus之Amazon EC2功能实现 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-21 08:42 |只看该作者 |倒序浏览
<span id="zw-1308cd14dfdrHaDqD2df03">&nbsp; Eucalyptus的一个显著的特点是比较完整的实现了Amazon EC2/S3的API,虽然在Scalability/HA和可管理性等方面存在较大差距,作为企业级使用还是可行的。下面就Eucalyptus实现的几个主要功能进行说明,包括:</span><br><blockquote><span id="zw-1308cd14dfdrHaDqD2df03"></span></blockquote><ul><li><span id="zw-1308cd14dfdrHaDqD2df03">&nbsp;&nbsp;&nbsp; Instance/Image</span></li><li><span id="zw-1308cd14dfdrHaDqD2df03">&nbsp;&nbsp;&nbsp; Security Group,</span></li><li><span id="zw-1308cd14dfdrHaDqD2df03">&nbsp;&nbsp;&nbsp; Elastic IP,</span></li><li><span id="zw-1308cd14dfdrHaDqD2df03">&nbsp;&nbsp;&nbsp; EBS</span></li><li><span id="zw-1308cd14dfdrHaDqD2df03">&nbsp;&nbsp;&nbsp; S3</span></li></ul><span id="zw-1308cd14dfdrHaDqD2df03"><br><b>软件环境</b><br><br></span><ul><li><span id="zw-1308cd14dfed_IOyE2df03">Mule ESB作为Cloud Controller组件交互的纽带</span></li><li><span id="zw-1308cd14dffn3gUYf2df03">数据库采用Hsqldb,采用Hibernate封装接口</span></li><li><span id="zw-1308cd14e00YJtexb2df03">节点之间采用Axis2 SOAP进行通信,并使用WS-Security提供安全保证</span></li><li><span id="zw-1308cd14e00-eUtYu2df03"> </span>开发语言:&nbsp; clc大部分使用Java语言,ESB部分调用C操作LVM,cc和nc使用C语言。</li></ul><p id="zw-1308cd14e00JB1zwy2df03"><br id="zw-1308cd14e01Kk1ksh2df03" clear="none"></p><p id="zw-1308cd14e019_k4-E2df03"><b><span id="zw-1308cd14e01hh6JZr2df03">系统组件</span></b></p><p id="zw-1308cd14e02VRX3zo2df03"><br id="zw-1308cd14e024r0Pua2df03"></p><p style="margin-top: 0pt; margin-bottom: 12pt;" id="zw-1308cd14e27xYz9st2df03"><a id="zw-1308cd14e02vp8LTK2df03" href="http://en.wikipedia.org/wiki/File:Eucalyptus_cloud_architecture-1.6.png"><img id="zw-1308cd14e03zR48T-2df03" style="height: 238px; width: 437px;" alt="Eucalyptus cloud architecture-1.6.png" src="http://upload.wikimedia.org/wikipedia/commons/2/2f/Eucalyptus_cloud_architecture-1.6.png"></a><br id="zw-1308cd14e036ah7zY2df03"><br id="zw-1308cd14e037SvmYj2df03"><br id="zw-1308cd14e04OINRkX2df03"><span id="zw-1308cd14e04c5HMo2df03">&nbsp; Cloud Controller(CLC) - 负责管理基础设施虚拟化资源,包括服务器,网络,和存储,并提供一个工业标准的API(Amazon EC2)</span><br id="zw-1308cd14e04OPn5u2df03"><br id="zw-1308cd14e04U2N7ZW2df03"><span id="zw-1308cd14e05xRVs82df03">&nbsp; Walrus - 实现可扩展的“put-get bucket”风格的存储。接口兼容Amazon S3(提供bucket和object的get/put接口),提供虚拟机Image和用户数据的持久存储和访问控制</span><br id="zw-1308cd14e05orV9j52df03"><br id="zw-1308cd14e057t7lZa2df03"><span id="zw-1308cd14e05uZ_wOV2df03">&nbsp;&nbsp; Cluster Controller(CC) - 控制节点上虚拟机的执行并管理虚拟网络资源,包括虚拟机之间和虚拟机和外部用户之间的虚拟网络。</span><br id="zw-1308cd14e05MKuA2df03"><br id="zw-1308cd14e06Gm9znz2df03"><span id="zw-1308cd14e0691x3C82df03">&nbsp; Storage Controller(SC) - 提供块级(Block-level)的网络存储,并能动态attach到VM上。支持EBS接口。</span><br id="zw-1308cd14e06rQAPsv2df03"><br id="zw-1308cd14e06339Tzx2df03"><span id="zw-1308cd14e06f_o-3S2df03">&nbsp; Node Controller(NC) - NC通过hypervisor控制VM的活动,包括执行,监视,终止VM实例。</span><br id="zw-1308cd14e07yPLcVz2df03"><br id="zw-1308cd14e07-Se-Jn2df03"><b><br id="zw-1308cd14e07TdS4l2df03"><span id="zw-1308cd14e07IDiw2L2df03">功能实现:</span></b><br id="zw-1308cd14e07FYB3Mr2df03"><br id="zw-1308cd14e08ctB3M62df03"><b><span id="zw-1308cd14e08s8ndEE2df03">实例管理:</span></b><br id="zw-1308cd14e08rLXmf2df03"><span id="zw-1308cd14e08Po9nPY2df03">&nbsp; cloud
controller维护着系统的各种资源,包括Instance, Image, Network, Volume, Object等,cloud
controller每隔一定时间会向clluster controller询问资源的使用情况,实例的运行状况和地址的使用情况等信息。</span><br id="zw-1308cd14e08y9D-Za2df03"></p><p style="margin-top: 0pt; margin-bottom: 12pt;" id="zw-1308cd14e27xYz9st2df03">&nbsp; 当用户调用RunInstances服务时,系统先进行Image,KeyPair,VmType,Security Group的验证,通过后先后指令CC给VM初始化网络,配置安全组,运行实例与给实例关联Public/Elastic IP.<span id="zw-1308cd14e099682Dy2df03"><br></span></p><p style="margin-top: 0pt; margin-bottom: 12pt;" id="zw-1308cd14e27xYz9st2df03"><span id="zw-1308cd14e099682Dy2df03"> <b>Image管理</b>:</span><span id="zw-1308cd14e09nN95Cv2df03"> Warlus管理imager.</span><br id="zw-1308cd14e09um9zAg2df03"><br id="zw-1308cd14e0a7Y7vmL2df03"><span id="zw-1308cd14e0a_0259d2df03"><b>虚拟化网络</b>:</span><br id="zw-1308cd14e0ag6iCOg2df03"><span id="zw-1308cd14e0aujtmrS2df03">&nbsp; 1. 实现功能:</span><br id="zw-1308cd14e0afvSPQs2df03"></p><ul><li><span id="zw-1308cd14e0b223sVV2df03">IP Control: 为实例动态分配私有IP地址</span></li><li><span id="zw-1308cd14e0bfCObno2df03">Security Groups: 安全组为一组实例提供一组访问规则,限制用户对指定端口的访问。</span></li><li><span id="zw-1308cd14e0cd7-PzV2df03">Elastic IPs:Elastic IP与用户的帐号相关联,而不是与实例相关联,使得实例失败后新启动的实例可以继续关联同一个IP地址</span></li><li><span id="zw-1308cd14e0c8AkbCt2df03">VM Isolation: 组内的实例之间可以互相访问,不同组实例之间除非授权不能互相访问</span></li></ul><p style="margin-top: 0pt; margin-bottom: 12pt;" id="zw-1308cd14e27xYz9st2df03"><br id="zw-1308cd14e0dEEsnMS2df03"><span id="zw-1308cd14e0dInbmS2df03">&nbsp; 2. 使用技术: </span><br id="zw-1308cd14e0di9IUiw2df03"></p><ul><li><span id="zw-1308cd14e0eIiZJW2df03">IP Control:&nbsp; 为一个将要启动的VM分配一个Mac:IP地址对,然后使用DHCP,让VM在启动时通过DHCP Server获取到分配的IP地址。</span></li><li><span id="zw-1308cd14e0euCaAXo2df03">Security Groups:</span><span id="zw-1308cd14e0frwbivz2df03">使用Iptables 的 filter 功能</span></li><li><span id="zw-1308cd14e10GMmhcW2df03">Elastic IPs:&nbsp; 运用iptables的NAT功能</span></li><li><span id="zw-1308cd14e1129b32df03">VM Isolation:&nbsp; 运用vlan技术实现</span></li></ul><p style="margin-top: 0pt; margin-bottom: 12pt;" id="zw-1308cd14e27xYz9st2df03"><br id="zw-1308cd14e116zdc7n2df03"><span id="zw-1308cd14e11Emwisq2df03"><b>EBS实现</b>:</span><br id="zw-1308cd14e12JnY_A2df03"><span id="zw-1308cd14e12sLDPU2df03">&nbsp; Block管理通过LVM实现,通过AOE和iSCSI两种方式提供网络访问</span><br id="zw-1308cd14e12pnKJpB2df03"><br id="zw-1308cd14e121XmOWj2df03"><b><span id="zw-1308cd14e12cGDGBB2df03">S3实现</span></b><br id="zw-1308cd14e134yKubd2df03"><br id="zw-1308cd14e13ItZpx92df03"><span id="zw-1308cd14e13bpKQlU2df03">&nbsp; </span><br id="zw-1308cd14e13I7fccV2df03"><span id="zw-1308cd14e13O0UbqI2df03"><b>具体流程</b>:</span><br id="zw-1308cd14e146ITynA2df03"><br id="zw-1308cd14e144Yr0x82df03"><b>EBS实现</b>:</p><p style="margin-top: 0pt; margin-bottom: 12pt;" id="zw-1308cd14e27xYz9st2df03">$ ec2-create-volume -s 1 -z mycluster -v<br><br>#dd if=/dev/zero of=/opt/eucalyptus/var/lib/eucalyptus/volumes/vol-32BA04A4 count=1024 bs=1M<br># losetup -f<br># losetup /dev/loop6 /opt/eucalyptus/var/lib/eucalyptus/volumes/vol-32BA04A4<br># pvcreate /dev/loop6<br># vgcreate vg-6gg0_w.. /dev/loop6<br># lvcreate -n lv-4IY3lw.. -l 100%FREE vg-6gg0_w..<br># vblade 0 7 eth0 /dev/vg-6gg0_w../lv-4IY3lw..<br><br>$ ec2-delete-volume vol-32BA04A4<br><br># kill -9 721<br># lvremove -f /dev/vg-6gg0_w../lv-4IY3lw..<br># vgremove vg-6gg0_w..<br># pvremove /dev/loop6<br># losetup -d /dev/loop6<br><br>$ ec2-attach-volume vol-32ED04AF -i i-5C7809B1 -d /dev/sdb<br><br>&nbsp;doAttachVolume() invoked (id=i-5C7809B1 vol=vol-32ED04AF remote=/dev/etherd/e0.9 local=/dev/sdb)<br>&nbsp;attached /dev/etherd/e0.9 to sdb in domain i-5C7809B1<br></p><p style="margin-top: 0pt; margin-bottom: 12pt;" id="zw-1308cd14e27xYz9st2df03">登录到VM,可以看到增加了一个dev:</p><p style="margin-top: 0pt; margin-bottom: 12pt;" id="zw-1308cd14e27xYz9st2df03">root@ubuntu:~# ls -al /dev/sd*<br>brw-rw---- 1 root disk 8,&nbsp; 0 2011-06-14 23:53 /dev/sda<br>brw-rw---- 1 root disk 8,&nbsp; 1 2011-06-14 23:53 /dev/sda1<br>brw-rw---- 1 root disk 8,&nbsp; 3 2011-06-14 23:53 /dev/sda3<br>brw-rw---- 1 root disk 8, 16 2011-06-14 23:59 /dev/sdb<br></p><p style="margin-top: 0pt; margin-bottom: 12pt;" id="zw-1308cd14e27xYz9st2df03">$ ec2-detach-volume vol-32ED04AF<br><br>doDetachVolume() invoked (id=i-5C7809B1 vol=vol-32ED04AF remote=/dev/etherd/e0.9 local=sdb force=0)<br>Running command: /opt/eucalyptus/usr/share/eucalyptus/euca_rootwrap virsh detach-device i-5C7809B1 /tmp/detachxml.xx2tM9<br>first workaround command failed (1), trying second workaround...<br>Running command: sudo xm block-detach i-5C7809B1 sdb<br>detached /dev/etherd/e0.9 as sdb in domain i-5C7809B1<br></p><p style="margin-top: 0pt; margin-bottom: 12pt;" id="zw-1308cd14e27xYz9st2df03">登录到VM,可以看到刚才增加的dev消失了:</p><p style="margin-top: 0pt; margin-bottom: 12pt;" id="zw-1308cd14e27xYz9st2df03">root@ubuntu:~# ls -al /dev/sd*<br>brw-rw---- 1 root disk 8, 0 2011-06-14 23:53 /dev/sda<br>brw-rw---- 1 root disk 8, 1 2011-06-14 23:53 /dev/sda1<br>brw-rw---- 1 root disk 8, 3 2011-06-14 23:53 /dev/sda3<br><br>$ ec2-create-snapshot vol-32ED04AF<br><br>dd if=/dev/zero of=/opt/eucalyptus/var/lib/eucalyptus/volumes/vol-32ED04AF-cOopjC9F count=1024 bs=1M<br>losetup -f<br>losetup /dev/loop1 /opt/eucalyptus/var/lib/eucalyptus/volumes/vol-32ED04AF-cOopjC9F<br>pvcreate /dev/loop1<br>vgcreate vg-wbRfkw.. /dev/loop1<br>lvcreate -n lv-9ALq_A.. -l 100%FREE vg-wbRfkw..<br>dd if=/dev/vg-Ca_8lQ../lv-nXF7eg.. of=/dev/vg-wbRfkw../lv-9ALq_A.. bs=1M<br>dd if=/dev/zero of=/opt/eucalyptus/var/lib/eucalyptus/volumes/snap-331704B5 count=1024 bs=1M<br>losetup -f<br>losetup /dev/loop2 /opt/eucalyptus/var/lib/eucalyptus/volumes/snap-331704B5<br>pvcreate /dev/loop2<br>vgextend vg-wbRfkw.. /dev/loop2<br>lvcreate -n lv-snap-ms8MNg.. -s -l 100%FREE /dev/vg-wbRfkw../lv-9ALq_A..<br><br>$ ec2-delete-snapshot snap-331704B5<br><br>lvremove -f /dev/vg-wbRfkw../lv-snap-ms8MNg..<br>vgreduce vg-wbRfkw.. /dev/loop2<br>pvremove /dev/loop2<br>losetup -d /dev/loop2<br>lvremove -f /dev/vg-wbRfkw../lv-9ALq_A..<br>vgremove vg-wbRfkw..<br>pvremove /dev/loop1<br>losetup -d /dev/loop1<br><br></p><p style="margin-top: 0pt; margin-bottom: 12pt;" id="zw-1308cd14e27xYz9st2df03"><b>网络相关功能实现</b>:</p><p style="margin-top: 0pt; margin-bottom: 12pt;" id="zw-1308cd14e27xYz9st2df03">网络相关的配置参数为:<br>
VNET_INTERFACE="eth1"<br>
VNET_MODE="MANAGED"<br>
VNET_SUBNET="192.168.1.0"<br>
VNET_NETMASK="255.255.255.0"<br>
VNET_DNS="192.168.1.1"<br>
VNET_ADDRSPERNET="16"<br>
VNET_PUBLICIPS="1.2.3.1 1.2.3.2 1.2.3.3 1.2.3.4"</p><p style="margin-top: 0pt; margin-bottom: 12pt;" id="zw-1308cd14e27xYz9st2df03"><b>网络初始化:</b><br><br>flushing 'filter' table<br>iptables -t filter -F<br><br>flushing 'nat' table<br>iptables -t nat -F<br><br>过滤掉不相关的包:<br>iptables -t filter -P FORWARD DROP<br>iptables -t filter -A FORWARD -m conntrack --ctstate ESTABLISHED -j ACCEPT<br>iptables -t filter -A FORWARD -d ! 192.168.1.0/24 -j ACCEPT<br>iptables -t nat -A POSTROUTING -d ! 192.168.1.0/24 -j MASQUERADE<br><br>169.254.169.254用于提供meta data服务<br>ip addr add 169.254.169.254 dev eth1<br>iptables -t nat -A PREROUTING -s 192.168.1.0/24 -d 169.254.169.254 -p tcp --dport 80 -j DNAT --to 169.254.169.254:8773<br><br>将整个物理网络划分为若干个subnet:​<br>vlan 2 network:192.168.1.0 netmask:255.255.255.240 broadcast:192.168.1.15 dns:192.168.1.1 router:192.168.1.1<br>vlan 3 network:192.168.1.16 netmask:255.255.255.240 broadcast:192.168.1.31 dns:192.168.1.1 router:192.168.1.17<br>vlan 4 network:192.168.1.32 netmask:255.255.255.240 broadcast:192.168.1.47 dns:192.168.1.1 router:192.168.1.33<br>vlan 5 network:192.168.1.48 netmask:255.255.255.240 broadcast:192.168.1.63 dns:192.168.1.1 router:192.168.1.49<br>vlan 6 network:192.168.1.64 netmask:255.255.255.240 broadcast:192.168.1.79 dns:192.168.1.1 router:192.168.1.65<br>vlan 7 network:192.168.1.80 netmask:255.255.255.240 broadcast:192.168.1.95 dns:192.168.1.1 router:192.168.1.81<br>vlan 8 network:192.168.1.96 netmask:255.255.255.240 broadcast:192.168.1.111 dns:192.168.1.1 router:192.168.1.97<br>vlan 9 network:192.168.1.112 netmask:255.255.255.240 broadcast:192.168.1.127 dns:192.168.1.1 router:192.168.1.113<br>vlan 10 network:192.168.1.128 netmask:255.255.255.240 broadcast:192.168.1.143 dns:192.168.1.1 router:192.168.1.129<br>vlan 11 network:192.168.1.144 netmask:255.255.255.240 broadcast:192.168.1.159 dns:192.168.1.1 router:192.168.1.145<br>vlan 12 network:192.168.1.160 netmask:255.255.255.240 broadcast:192.168.1.175 dns:192.168.1.1 router:192.168.1.161<br>vlan 13 network:192.168.1.176 netmask:255.255.255.240 broadcast:192.168.1.191 dns:192.168.1.1 router:192.168.1.177<br>vlan 14 network:192.168.1.192 netmask:255.255.255.240 broadcast:192.168.1.207 dns:192.168.1.1 router:192.168.1.193<br><br>将来​对每个security group会分配一个vlan,这样保证网络的隔离​<br><br></p><p style="margin-top: 0pt; margin-bottom: 12pt;" id="zw-1308cd14e27xYz9st2df03"><b>Security Group实现:</b></p><p style="margin-top: 0pt; margin-bottom: 12pt;" id="zw-1308cd14e27xYz9st2df03">Eucalyptus会为每个安全组(security group)创建一个vlan,下面以一个实例进行说明,相应的函数为StartNetwork(netName=app vlan=10):<br><br>首先,生成 filter chain:<br>​<br>iptables -t filter -N admin-app<br>​iptables -t filter -D FORWARD -j admin-app<br>iptables -t filter -A FORWARD -j admin-app<br><br>接着,在网络10上生成一个vlan,并生成一个bridge和其上的gateway,这样在eth1.10上的数据包就可以通过这个gateway进行路由:​<br>// first, create tagged interface<br>vconfig add eth1 10<br><br>​// create new bridge<br>brctl addbr eucabr10<br>brctl addif eucabr10 eth1.10<br><br>​// bring br up<br>ip link set dev eucabr10 up<br>ip addr flush eucabr10<br><br>​// bring if up<br>ip link set dev eth1.10 up<br><br>// Add gateway in the bridge​<br>ip addr add 192.168.1.129/28 broadcast 192.168.1.143 dev eucabr10'<br>ip link set dev eucabr10 up<br><br>在NC上也生成一个vlan和bridge:<br>vconfig add eth0 10<br>brctl addbr eucabr10<br>brctl addif eucabr10 eth0.10<br>ip link set dev eucabr10 up<br>ip link set dev eth0.10 up<br></p><p style="margin-top: 0pt; margin-bottom: 12pt;" id="zw-1308cd14e27xYz9st2df03"><b>Private IP地址的分配</b><br>在RunInstance时,CC会为每个实例分配一个MAC/IP地址对,并通过dpcp服务让instance在启动时自动获取到自己的IP地址,具体操作如下:<br><br>CC从预先配置的表中获取一个空闲的MAC/IP地址对:d0:0d:4C:46:07:DF/192.168.1.130<br>然后CC调用SOAP指令NC运行实例,并将image-id, MAC地址等作为参数传入<br>NC将bridge和Mac作为interface参数调用libvirt创建实例:<br>&nbsp; &lt;interface type='bridge'&gt;<br>&nbsp;&nbsp;&nbsp; &lt;source bridge='eucabr10'/&gt;<br>&nbsp;&nbsp;&nbsp; &lt;mac address='d0:0d:40:06:07:F2'/&gt;<br>&nbsp; &lt;/interface&gt;<br><br>CC将192.168.1.128网络参数和映射的MAC/IP地址对写入dhcp配置文件euca-dhcp.conf:<br><br>shared-network euca {<br>subnet 192.168.1.128 netmask 255.255.255.240 {<br>&nbsp; option subnet-mask 255.255.255.240;<br>&nbsp; option broadcast-address 192.168.1.143;<br>&nbsp; option domain-name-servers 192.168.1.1;<br>&nbsp; option routers 192.168.1.129;<br>}<br><br>host node-192.168.1.130 {<br>&nbsp; hardware ethernet d0:0d:4C:46:07:DF;<br>&nbsp; fixed-address 192.168.1.130;<br>}<br>}<br><br>随后重启dhcpd:<br>/usr/sbin/dhcpd -cf euca-dhcp.conf -lf euca-dhcp.leases -pf euca-dhcp.pid -tf euca-dhcp.trace&nbsp; eucabr10 eth1<br><br><b>Public IP和Elastic IP的实现</b>:<br>Public IP和Elastic Ip使得外部用户可以通过这个IP访问到VM,它的实现类似于NAT,<br><br>例如要把1.2.3.2这个地址作成PublicIP/Elastic IP,需要在Front end的CC的eth1上增加这个地址<br>ip addr add 1.2.3.2/32 dev eth1<br><br>然后应用iptables规则,将外网用户访问1.2.3.2的包,目的地址改为192.168.1.130,将从192.168.1.130发出的包,其源地址改为1.2.3.2<br>iptables -t nat -A PREROUTING -d 1.2.3.2 -j DNAT --to 192.168.1.130<br>iptables -t nat -A POSTROUTING -s 192.168.1.130 -j SNAT --to 1.2.3.2<br><br><br id="zw-1308cd14e14LhecTh2df03"></p>
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP