Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1733770
  • 博文数量: 163
  • 博客积分: 10591
  • 博客等级: 上将
  • 技术积分: 1980
  • 用 户 组: 普通用户
  • 注册时间: 2006-08-08 18:17
文章分类

全部博文(163)

文章存档

2018年(1)

2012年(1)

2011年(47)

2010年(58)

2009年(21)

2008年(35)

分类: LINUX

2010-03-19 11:00:22

创建我们所需的镜像

上面我们已经根据安装了一个所需的虚机,但是你可以发现它的硬盘是xvda的,而且整个镜像是不可以挂载的,我们所需的镜像是ext3文件系统,可以挂载的,而且根分区要挂载在sda1。显而易见,我们还需要进一步加工,呵呵。

 

(1)创建一个ext3文件系统镜像,并将其挂载到虚机上

 

[root@cloud /]# dd if=/dev/zero of=/images/cloud-myself bs=1M count=2500

 

[root@cloud /]# mkfs.ext3 /images/cloud-myself

 

 

更改上面创建虚机的配置文件,一般在/etc/xen/下,配置文件名为hrwang-rhel5,更改如下这行:

disk = [ "tap:aio:/images/cloud1.img,xvda,w", "tap:aio:/images/cloud-myself,xvdb,w" ]

 

 

好了,可以使用xm create hrwang-rhel5启动虚机,然后用xm console hrwang-rhel5显示系统操作界面。

 

2)登入虚机,进行拷贝操作

登陆到虚机内,执行挂载命令

[root@localhost /]# mount –t ext3 /dev/xvdb /media

[root@localhost /]# cp –ax  /{root,dev,var,etc,usr,bin,sbin,lib} /media

[root@localhost /]# mkdir /media/{proc,sys,home,tmp,selinux}

[root@localhost /]#mkdir /media/root/.ssh           nimbus启动虚机时需要

[root@localhost /]#vi /media/etc/fstab              将根分区改为如下并注释掉swap那行

/dev/sda1    /    ext3    defaults     1  1

[root@localhost /]#vi /media/etc/selinux/config           关闭selinux,否则无法登陆
SELINUX=disabled

[root@localhost /]# umount /media

 

注:因为我们建立虚机时,主机名和IP就是dhcp分配的,所以这里不需要改了。

 

好了,到这所需的镜像就简单创建完了。

 

3)创建新镜像的initrd文件及终端

上面新创建的镜像文件是启动不了的,因为缺少虚拟磁盘映像文件。我们在VMM节点上创建它

[root@cloud /]#mount –o loop /images/cloud-myself /mnt

[root@cloud /]#cd /boot

[root@cloud boot]#mkinitrd -v -f --fstab /mnt/etc/fstab --with xenblk --with xennet --preload xenblk --preload xennet  vmlinuz-2.6.18-53.el5xen-initrd  `uname -r`

注:之所以用vmlinuz-2.6.18-53.el5xen-initrd这样的名字,是因为在/opt/workspace/worksp.conf文件里指定了,initrd的名字如果是kernel-initrd的形式则自动被使用。我们这里kernel的名字为vmlinuz-2.6.18-53.el5xen。呵呵,明白了吧。

 

[root@cloud boot]#umount /mnt

[root@cloud boot]#cp /boot/ vmlinuz-2.6.18-53.el5xen-initrd  /opt/workspace/images/

 

[root@cloud boot]#vi /etc/inittab                

5:2345:respawn:/sbin/mingetty tty5

6:2345:respawn:/sbin/mingetty tty6

co:2345:respawn:/sbin/agetty xvc0 9600 vt100-nav         添加虚机使用的终端

 

[root@cloud boot]#init q                              /etc/inittab设定立刻生效

[root@cloud boot]#ln –s /dev/console /dev/xvc0           

 

4)测试新创建的镜像

在我们使用它之前,先来测试一下。

[root@cloud boot]#cd /etc/xen

[root@cloud boot]#vi cloud-myself                     添加如下内容

kernel="/boot/vmlinuz-2.6.18-53.el5xen"

ramdisk="/boot/vmlinuz-2.6.18-53.el5xen-initrd"

name = "cloud-myself"

memory = 500

vcpus = 1

disk = [ "tap:aio:/images/cloud-myself,sda1,w"  ]

root = "/dev/sda1 ro"

vif = [ "mac=00:16:3e:5b:86:be,bridge=xenbr0" ]

 

 

然后可以使用xm create cloud-myself启动虚机,并使用xm console cloud-myself登陆虚机。

 

 

(5) 添加库文件

上步启动过程中会提示一大堆无法找到某库文件的内容,反正虚机和宿主机都是一样的操作系统,干脆将宿主机上的库文件全部拷过去。

[root@cloud /]#mount –o loop /images/cloud-myself /mnt

[root@cloud /]#rm –rf /mnt/lib/*           删除原有的库文件

[root@cloud /]#cp –ax /lib/* /mnt/lib/       拷贝所有的宿主机库文件

[root@cloud /]#cp –ax /usr/src/kernels /mnt/usr/src/    拷贝内核文件

[root@cloud /]#umount /mnt                     

 

好了,再重新启动试试,应该没问题了。

 

 

 

 

上步我们已经在VMM节点上创建了半虚拟化的虚机,现在我们将镜像文件拷贝到nimbus client端来进行测试:

 

1)在VMM上执行:

[root@cloud images]# scp /images/cloud1.img nimbus@wang135:/home/nimbus

 

 

2)在nimbus server上以globus用户启动起来nimbus

[globus@wang136 ~]$ globus-start-container

2009-05-31 19:24:43,116 INFO  defaults.DefaultAssociationAdapter [main,validate:191] MAC prefix: "A2:AA:BB"

2009-05-31 19:24:43,192 WARN  defaults.Util [main,loadDirectory:228] not a file: '/usr/local/globus-4.0.8/etc/nimbus/workspace-service/network-pools/.backups'

2009-05-31 19:24:43,417 INFO  defaults.DefaultAssociationAdapter [main,validate:243] Network 'public' loaded with 5 addresses.

2009-05-31 19:24:43,421 INFO  defaults.DefaultAssociationAdapter [main,validate:243] Network 'private1' loaded with 5 addresses.

2009-05-31 19:24:43,705 WARN  groupauthz.Group [main,reloadDNFile:168] Authorization Group #1: Loaded 2 identities from '/usr/local/globus-4.0.8/etc/nimbus/workspace-service/group-authz/group01.txt'

2009-05-31 19:24:43,713 WARN  groupauthz.Group [main,reloadRightsFile:207] TESTING -- Authorization Group #1: Loaded group definition from '/usr/local/globus-4.0.8/etc/nimbus/workspace-service/group-authz/group01.properties'

2009-05-31 19:24:43,717 WARN  groupauthz.Group [main,reloadDNFile:168] Authorization Group #2: Loaded 2 identities from '/usr/local/globus-4.0.8/etc/nimbus/workspace-service/group-authz/group02.txt'

2009-05-31 19:24:43,719 WARN  groupauthz.Group [main,reloadRightsFile:207] DEVELOPMENT -- Authorization Group #2: Loaded group definition from '/usr/local/globus-4.0.8/etc/nimbus/workspace-service/group-authz/group02.properties'

2009-05-31 19:24:43,732 WARN  groupauthz.Group [main,reloadDNFile:168] Authorization Group #3: Loaded 2 identities from '/usr/local/globus-4.0.8/etc/nimbus/workspace-service/group-authz/group03.txt'

2009-05-31 19:24:43,735 WARN  groupauthz.Group [main,reloadRightsFile:207] SCIENCE -- Authorization Group #3: Loaded group definition from '/usr/local/globus-4.0.8/etc/nimbus/workspace-service/group-authz/group03.properties'

2009-05-31 19:24:43,741 WARN  groupauthz.Group [main,reloadDNFile:168] Authorization Group #4: Loaded 3 identities from '/usr/local/globus-4.0.8/etc/nimbus/workspace-service/group-authz/group04.txt'

2009-05-31 19:24:43,743 WARN  groupauthz.Group [main,reloadRightsFile:207] SUPERUSER -- Authorization Group #4: Loaded group definition from '/usr/local/globus-4.0.8/etc/nimbus/workspace-service/group-authz/group04.properties'

2009-05-31 19:24:43,958 WARN  defaults.ResourcepoolUtil [main,loadResourcepools:480] not a file: '/usr/local/globus-4.0.8/etc/nimbus/workspace-service/vmm-pools/.backups'

2009-05-31 19:24:43,972 INFO  defaults.DefaultSlotManagement [main,validate:501] Resource pool 'testpool' loaded with one VMM.

2009-05-31 19:24:44,273 INFO  workspace.WorkspaceUtil [main,runCommand:148] [NIMBUS-EVENT]: //usr/local/globus-4.0.8/var/nimbus/msg-sinks/notifications

2009-05-31 19:24:45,853 INFO  workspace.WorkspaceUtil [main,runCommand:225] [NIMBUS-EVENT]: Return code is 0

2009-05-31 19:24:46,314 INFO  dbdefault.DelayedAccountingFileLogger [main,initFile:181] accounting event log file created: '/usr/local/globus-4.0.8/var/nimbus/accounting-events.txt'

2009-05-31 19:24:46,722 INFO  dbdefault.DelayedAccountingFileLogger [main,initFile:181] accounting current-reservations file created: '/usr/local/globus-4.0.8/var/nimbus/current-reservations.txt'

2009-05-31 19:24:50,118 INFO  impls.WorkspaceHomeImpl [main,recover_find_active_workspaces:579] No workspaces were persisted when the container last shut down

Starting SOAP server at:

With the following services:

 

[1]: AdminService

[2]: AuthzCalloutTestService

[3]: ContainerRegistryEntryService

[4]: ContainerRegistryService

[5]: CounterService

[6]: ElasticNimbusService

[7]: JWSCoreVersion

[8]: ManagementService

[9]: NotificationConsumerFactoryService

[10]: NotificationConsumerService

[11]: NotificationTestService

[12]: PersistenceTestSubscriptionManager

[13]: SampleAuthzService

[14]: SecureCounterService

[15]: SecurityTestService

[16]: ShutdownService

[17]: SubscriptionManagerService

[18]: TestAuthzService

[19]: TestRPCService

[20]: TestService

[21]: TestServiceRequest

[22]: TestServiceWrongWSDL

[23]: Version

[24]: WidgetNotificationService

[25]: WidgetService

[26]: WorkspaceContextBroker

[27]: WorkspaceEnsembleService

[28]: WorkspaceFactoryService

[29]: WorkspaceGroupService

[30]: WorkspaceService

[31]: WorkspaceStatusService

[32]: gsi/AuthenticationService

 

 

3

传完后,我们到nimbus client上以nimbus用户来继续操作:

[nimbus@wang135 ~]$ ls –l

total 1553460

-rw-r--r-- 1 nimbus nimbus 1572864000 May 31 19:16 cloud1.img

drwxr-xr-x 7 nimbus nimbus       4096 Jan 10 03:53 nimbus-cloud-client-011

-rw-r--r-- 1 nimbus nimbus   16313736 May 25 19:23 nimbus-cloud-client-011.tar.gz

 

 

[nimbus@wang135 ~]$ ./nimbus-cloud-client-011/bin/cloud-client.sh --security   检查安全

Credential in use:

  -Identity: '/O=Grid/OU=GlobusTest/OU=simpleCA-wang136.hrwang.com/OU=hrwang.com/CN=Hongrui Wang'

  -Subject: 'O=Grid,OU=GlobusTest,OU=simpleCA-wang136.hrwang.com,OU=hrwang.com,CN=Hongrui Wang,CN=468276644'

  -Issuer: 'O=Grid,OU=GlobusTest,OU=simpleCA-wang136.hrwang.com,OU=hrwang.com,CN=Hongrui Wang'

 

Trusted certificate path: /home/nimbus/nimbus-cloud-client-011/lib/certs

 

Found configured cloud CA: '/home/nimbus/nimbus-cloud-client-011/lib/certs/6045a439.0'

 

No warnings.

 

 

[nimbus@wang135 ~]$ ./nimbus-cloud-client-011/bin/cloud-client.sh --transfer --sourcefile /home/nimbus/cloud-myself                      上传镜像

 

Transferring

  - Source: file:////home/nimbus/cloud-myself

  - Destination: gsiftp://wang136.hrwang.com:2811//cloud/d9383407/cloud-myself

 

Copy complete.

 

注:可以到nimbus server上验证一下是否存在:

[root@wang136 ~]# ls -lh /cloud/d9383407/

-rw-r--r-- 1 nimbus nimbus 1.5G Jun  5 18:45 cloud-myself

 

[nimbus@wang135 ~]$ ./nimbus-cloud-client-011/bin/cloud-client.sh --list    验证

[Image] 'cloud-myself'             Read/write

        Modified: Jun 05 @ 10:14   Size: 1572864000 bytes (~1500 MB)

 

4

[nimbus@wang135 ~]$ ./nimbus-cloud-client-011/bin/cloud-client.sh --run --name cloud-myself --hours 2

SSH public keyfile contained tilde:

  - '~/.ssh/id_rsa.pub' --> '/home/nimbus/.ssh/id_rsa.pub'

Problem: SSH public key file does not exist or is not readable: '/home/nimbus/.ssh/id_rsa.pub'

See help (-h).

 

上面的错误是忘记生成id_rsa.pub文件,我们这样做:

[nimbus@wang135 ~]$ ssh-keygen

Generating public/private rsa key pair.

Enter file in which to save the key (/home/nimbus/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/nimbus/.ssh/id_rsa.

Your public key has been saved in /home/nimbus/.ssh/id_rsa.pub.

The key fingerprint is:

c9:97:b4:d2:a1:fb:ce:00:ab:a5:c0:6f:9c:f2:06:31 nimbus@wang135.hrwang.com

 

再次执行                                这部分无妨~~

[nimbus@wang135 bin]$ ./cloud-client.sh --delete --name cloud-myself

 

Deleting: gsiftp://wang136.hrwang.com:2811//cloud/d9383407/cloud-myself

 

Deleted.

 

[nimbus@wang135 bin]$ ./cloud-client.sh --transfer  --sourcefile /home/nimbus/cloud-myself

 

Transferring

  - Source: file:////home/nimbus/cloud-myself

  - Destination: gsiftp://wang136.hrwang.com:2811//cloud/d9383407/cloud-myself

 

Copy complete.

 

[nimbus@wang135 bin]$ ./cloud-client.sh --run --name cloud-myself --hours 2

SSH public keyfile contained tilde:

  - '~/.ssh/id_rsa.pub' --> '/home/nimbus/.ssh/id_rsa.pub'

 

Launching workspace.

 

Workspace Factory Service:

   

 

Creating workspace "vm-034"... done.

 

 

       IP address: 192.168.1.2

         Hostname: client2

       Start time: Fri Jun 05 18:48:17 CST 2009

    Shutdown time: Fri Jun 05 20:48:17 CST 2009

 Termination time: Fri Jun 05 20:58:17 CST 2009

 

Waiting for updates.

 

 

"vm-034" reached target state: Running

 

Running: 'vm-034'

 

 

 

[nimbus@wang135 bin]$ ./cloud-client.sh --run --name cloud-myself --hours 3      再启一个

SSH public keyfile contained tilde:

  - '~/.ssh/id_rsa.pub' --> '/home/nimbus/.ssh/id_rsa.pub'

 

Launching workspace.

 

Workspace Factory Service:

   

 

Creating workspace "vm-035"... done.

 

 

       IP address: 192.168.1.3

         Hostname: client3

       Start time: Fri Jun 05 19:37:50 CST 2009

    Shutdown time: Fri Jun 05 22:37:50 CST 2009

 Termination time: Fri Jun 05 22:47:50 CST 2009

 

Waiting for updates.

 

 

"vm-035" reached target state: Running

 

Running: 'vm-035'

 

 

[nimbus@wang135 bin]$ ./cloud-client.sh –status                  查看vm状态

Querying for ALL instances.

 

[*] - Workspace #33. 192.168.1.2 [ client2 ]

      State: Running

      Duration: 120 minutes.

      Start time: Fri Jun 05 18:48:17 CST 2009

      Shutdown time: Fri Jun 05 20:48:17 CST 2009

      Termination time: Fri Jun 05 20:58:17 CST 2009

      *Handle: vm-034

 

[*] - Workspace #34. 192.168.1.3 [ client3 ]

      State: Running

      Duration: 180 minutes.

      Start time: Fri Jun 05 19:37:50 CST 2009

      Shutdown time: Fri Jun 05 22:37:50 CST 2009

      Termination time: Fri Jun 05 22:47:50 CST 2009

      *Handle: vm-035

 

 

 

 

阅读(1788) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~