Solaris下分配zone 先规划好zone所需的文件系统,设备,资源,IP(hostname) 要创建一个zone,首先必须以root身份或有root特权的RBAC用户登陆到全局系统。下面列出配置一个名字为test-zone的所需步骤: 开始配置zone 新的zone名字为“test-zone”,设置新zone的根路径在全局zone下的路径(此路径必须为root帐号所拥有,权限为700),并让其在全局zone启动时也自动启动。 1、zone配置 zonecfg -z test-zone(zonename) test-zone不在,用create创建 zonecfg:test-zone>create zonecfg:test-zone>set zonepath=/export/home/test-zone zonecfg:test-zone>set autoboot=true 2、配置zone的文件系统(此步骤可不做,保持默认) (1)指定文件系统的挂载点为/mnt (2)指定块专用文件/dev/dsk/c0t0d0s7将被挂载到test-zone的/mnt (3)指定裸设备专用文件/dev/rdsk/c0t0d0s7; zoneadmd守护进程在挂载文件系统之前,将以非交互模式自动运行fsck命令,对这个设备进行检查。 (4)指定文件系统类型为UFS (5)指定系统的特定选项,此例中启用了文件系统日志记录 zonecfg:test-zone>add fs zonecfg:test-zone:fs>set dir=/mnt zonecfg:test-zone:fs>set special=/dev/dsk/c0t0d0s7 zonecfg:test-zone:fs>set raw=/dev/rdsk/c0t0d0s7 zonecfg:test-zone:fs>set type=ufs zonecfg:test-zone:fs>add options [logging] zonecfg:test-zone:fs>end 3、配置(从全局zone共享的)被环回挂载的文件系统。指定全局zone的/usr/sfw目录将被环回挂载。 zonecfg:test-zone>add inherit-pkg-dir zonecfg:test-zone:hinherit-pkg-dir>set dir=/usr/sfw zonecfg:test-zone:hinherit-pkg-dir>end 4、配置网络。 指定zone要使用的物理网络接口为e1000g0,IP地址为135.251.208.150 zonecfg:test-zone>add net zonecfg:test-zone:net>set physical=e1000g0 zonecfg:test-zone:net>set address=135.251.208.150 zonecfg:test-zone:net>end 5、配置设备(根据需要配置,此步骤可不做,保持默认) zonecfg:test-zone>add device zonecfg:test-zone:device>set match=/dev/sound/* zonecfg:test-zone:device>end 6、配置属性。属性的名字为comment,类型为string,并定义此属性的具体内容。(此步骤可不做) zonecfg:test-zone>add attr zonecfg:test-zone:attr>set name=comment zonecfg:test-zone:attr>set type=string zonecfg:test-zone:attr>set value="The test-zone is for test" zonecfg:test-zone:attr>end 7、校验与提交并退出zone配置 zonecfg:test-zone>verify zonecfg:test-zone>commit zonecfg:test-zone>exit 现在已经配置好test-zone,下一步可以进行test-zone的安装 查看ZONE配置文件 当你把zone的配置提交到稳定的储藏库后,配置文件以XML格式保存在/etc/zones/目录中。 # more /etc/zones/test-zone.xml 【删除已配置的资源】 # zonecfg –z test-zone zonecfg:test-zone:net> remove net physical=e1000g0 zonecfg:test-zone:net> commit zonecfg:test-zone:net> end zoneadm命令是安装和管理非全局zone的基本工具。使用zoneadm命令进行的操作必须从全局zone运行。Zoneadm能够:校验zone 的配置,安装zone,启动zone,重启zone,显示正在运行的zone的信息,反安装zone,使用zonecfg命令删除zone。 ● 验证已配置的ZONE 你可以在开始安装一个zone之前对其配置进行校验,如果跳过这一步骤,当你开始安装zone时,校验依然会自动执行。必须是全局管理员才能执行校验和安装步骤。 # zoneadm –z test-zone verify ● 安装一个已配置的ZONE # zoneadm –z testzone install 在安装过程中,可打开另外一个终端窗口,查看文件系统的: # df –h | grep /export/home/test-zone /lib 1.3G 650M 583M 53% /export/home/test-zone/root/lib /platform 1.3G 650M 583M 53% /export/home/test-zone/root/platform /sbin 1.3G 650M 583M 53% /export/home/test-zone/root/sbin /usr 4.5G 3.0G 1.4G 68% /export/home/test-zone/root/usr /dev/dsk/c1t1d0s0 5.9G 6.0M 5.8G 1% /export/home/test-zone/root/mnt 查看已安装的zone并校验它的状态 # zoneadm list –iv ID NAME STATUS PATH 0 global running / - test-zone installed /export/home/test-zone ● 启动ZONE 启动zone将使zone进入运行状态(running)。如果zone的资源属性autoboot设置为true,当全局zone启动时会自动启动该zone,autoboot的预设值为false。可以在installed或ready状态手工启动zone。 Zone每一次重新进入ready或running状态,系统为zone分配的唯一ID就递增(从ready状态到running除外)。 # zoneadm -z test-zone ready # zoneadm -z test-zone boot # zoneadm list –vi ID NAME STATUS PATH 0 global running / 1 test-zone ready /export/home/test-zone # zoneadm list –v ID NAME STATUS PATH 0 global running / 1 test-zone running /export/home/test-zone ● ZONE停机 使用zoneadm的halt命令把zone的应用环境和虚拟平台移除,然后让zone回到Installed状态。所有的进程都被kill,设备配置被取消,网络接口被卸除,文件系统被卸载,内核数据结构被摧毁。 # zoneadm –z test-zone halt ● 重启ZONE # zoneadm –z test-zone reboot ● 登陆ZONE并开始工作 初次登陆zone开始配置操作系统环境,需要用-C登陆到zone的控制台模式: # zlogin -C test-zone [已连接到区域 'test-zone' 控制台] Hostname: test-zone Select a Language 0. English 1. Simplified Chinese Please make a choice (0 - 1), or press h or ? for help:0 ….. 系统会询问你关于终端类型,主机名(此例为solaris-1),时间区域以及root密码等信息。如果使用CDE终端窗口,可选择dtterm,如果使用其他类型的窗口,选择vt100。全部设置完后,zone重启然后进入控制台登陆提示窗口: solaris-1 console login: 要从zone的控制台退出,使用~.组合键 # ~. [与区域 'test-zone' 控制台的连接已关闭] 在配置完zone的操作系统环境设置后,可直接登陆zone # zlogin test-zone [已连接到区域 'test-zone' pts/5] Last login: Wed Jan 24 14:31:47 on pts/5 Sun Microsystems Inc. SunOS 5.10 Generic January 2005 ● 删除ZONE 如果准备删除一个zone,先把需要保留的数据备份;然后停机zone,释放被zone占用的系统内存。Zone的停机(halt)并不是温顺的和受控的shutdown过程,因此从全局zone对正在运行的zone进行停机操作可能会导致数据丢失。 1. 查看当前已有的zone的状态 # zoneadm list -cp 0:global:running:/ 1:test-zone:running:/export/home/test-zone 2. 让test-zone停机 # zoneadm –z test-zone halt # zoneadm list -cp 0:global:running:/ -:test-zone:installed:/export/home/test-zone 3. 现在除了文件系统空间外,test-zone不再使用系统的其他资源,可以进行zone的卸除操作释放被zone占用的空间 # zoneadm –z test-zone uninstall Are you sure you want to uninstall zone work-zone (y/[n])? Y # zoneadm list -cp 0:global:running:/ -:test-zone: configured:/export/home/test-zone 4. 删除zone配置 # zonecfg –z test-zone delete