Dec 25

[原]创建VPS OS模板 晴

linuxing , 18:29 , 网络服务 » 虚拟机 , 评论(1) , 引用(0) , 阅读(34760) , Via 本站原创 | |
   OpenVZ是一个非常出色的单内核,多根分区虚拟机系统。根据使用不同的系统模板。可实现同一机器上同时运行不同的Linux发行版本,而且管理简单,资源控制也很方便,适用于ISP环境下的大规模应用。基础配置可以看[原]在红旗上运行OpenVZ虚拟环境
   不过,作为Virtuozzo的开源版本,不知有意还是无意的,OpenVZ提供的可用OS系统模板不多,默认只有Fedora Core 3/4/5、Centos4,这不足以满足我们的需求。这里就以创建基于Asianux 2.0 SP2的系统为例,说明如何创建VPS OS模板。

一、额外的模板
1、获取模板
除可使用yum更新的模板外,还可以使用一些爱好者已经做好的系统模板。
从这里可以得到这些模板:
http://openvz.org/download/template/cache/
※请注意,这些模板未经过安全验证,可能会存在漏洞,请小心使用。

2、下载模板
模板需要放在/vz/template/cache/目录下:

# cd /vz/template/cache/
# wget http://download.openvz.org/template/precreated/asianux-2.0-SP1-minimal-x86.tar.gz

3、使用模板
当下载完模板后,即可马上使用:
引用
# vzctl create 114 --ostemplate asianux-2.0-SP1-minimal-x86
Unable to get full ostemplate name for asianux-2.0-SP1-minimal-x86
Creating VE private area (asianux-2.0-SP1-minimal-x86)
Warning: configuration file for distribution asianux-2.0-SP1-minimal-x86 not found default used
Performing postcreate actions
VE private area was created

--ostemplate后跟的模板名称,为.tar.gz的前缀名称。
由于没有配置yum.conf,故不能使用全局更新的操作,除此之外,并不会影响VPS的正常使用。
启动:
引用
# vzctl start 114
Warning: configuration file for distribution asianux-2.0-SP1-minimal-x86 not found default used
Starting VE ...
VE is mounted
Setting CPU units: 1000
Configure meminfo: 49152
VE start in progress...

警告的解决办法见后面。

二、创建自定义系统模板
正因为使用第三方的模板可能存在安全问题,且不能使用yun进行全局更新,还不利于我们执行定制各模板的内容,若能自定义系统模板就能解决所有的问题了。
1、原理
自定义系统的模板非常简单,以前的文章中也有提及下面的结构:
引用
/vz/template
/vz/template/cache  <-系统模版,.tar.gz压缩
/vz/template/centos/4/i386  <-根据模版缓存的软件包存放路径
/vz/template/centos/4/i386/config  <-特定模版yum更新路径
/vz/template/centos/4/i386/vz-addons  <-vz更新包
/vz/template/centos/4/i386/yum-cache  <-该模版yum更新包及cached包

我们只要复制一个相同的结构,并修改一些配置即可。

2、前提
创建模板,会根据config中定义的yum更新路径来下载rpm内容,然后解压到特定目录,再打包为.tar.gz文件。
所以,前提是,你需要搭建好一台yum更新来源服务器,可参考[原]使用yum更新红旗Linux
以Asianux 2.0(也就是红旗DC Server 5.0)为例,已经搭建的yum来源为:
引用
ftp://yumer:yumer@192.168.228.153/dc/5.0/sp2/i386

使用本地源也可以:
引用
file:///ftp_root/dc/5.0/sp2/i386/

3、创建模板

# cd /vz/template
# mkdir -p asianux/2/i386/yum-cache
# cp -a /vz/template/centos/4/i386/vz-addons/ ./
# cp -a /vz/template/centos/4/i386/config/ ./


4、修改模板yum更新路径
# cd config
# vi yum.conf

修改为:
引用
cachedir=/vz/template/asianux/2/i386/yum-cache/
[asianux2-vz-addons]
name=OpenVZ add-ons for Asianux 2 - i386
baseurl=file:///vz/template/asianux/2/i386/vz-addons/
enabled=1
gpgcheck=0

[asianux2-base]
name=Asianux 2 - i386 - Base
baseurl=ftp://yumer:yumer@192.168.228.153/dc/5.0/sp2/i386/
enabled=1
gpgcheck=0

[asianux2-updates-released]
name=Asianux 2 - i386 - Released Updates
baseurl=ftp://yumer:yumer@192.168.228.153/dc/5.0/sp2/i386/
enabled=0
gpgcheck=0

(这里的updates栏是为了方便以后更新,暂时不用)

5、修改模板中系统包含的内容
最终生成的模板,是用rpm解压得到的。只要把需要安装的rpm名称写入配置文件即可。
Centos4的模板自带default.list和minimal.list,请根据实际情况和需求修改。
若不知道那些包合适,可先在其他机器上预装一个系统,然后用rpm -qa把包列一下:

# rpm -qa --qf "%{name}\n" > minimal.list

再加入vz特有的rpm包就可以了:
引用
# Add-ons for VZ
dummy-centos-4
vzdev
MAKEDEV

※列表中只要写入主要包的rpm名称就可以了,yum会自动考虑rpm的依赖问题。若生成时,找不到对应的包,会忽略掉的。

6、生成模板
查看可用模板,可以看到,已经增加了asianux-2-i386系列。
(由目录架构名和.list文件名组成)
引用
# vzpkgls
centos-4-i386-minimal
centos-4-i386-default
asianux-2-i386-minimal
asianux-2-i386-default

生成模板:
引用
# vzpkgcache asianux-2-i386-minimal
Creating cache for asianux-2-i386-minimal OS template
......
Packing cache file asianux-2-i386-minimal.tar.gz ...
Cache file asianux-2-i386-minimal.tar.gz [60M] created.

7、生成默认配置文件

# cd /etc/vz/dists
# cp centos.conf asianux.conf
# cp centos-4.conf asianux-2.conf

※若不执行这个步骤,生成或修改VPS配置时,会报警告信息:
引用
Warning: configuration file for distribution asianux-2-i386-minimal not found default used
Performing postcreate actions

8、使用模板
引用
# vzctl create 114 --ostemplate asianux-2-i386-minimal
Creating VE private area (asianux-2-i386-minimal)
VE private area was created
# vzctl start 114
Starting VE ...
VE is mounted
Setting CPU units: 1000
Configure meminfo: 49152
VE start in progress...


三、使用asianux模板
为方便使用,你也可以直接修改OpenVZ提供的Centos4模板的.src.rpm文件:点击
下面是我以AsianUX 2.0为模板修改好的版本,供参考使用:

(安装后,请执行修改/vz/template/asianux/2/i386/config/yum.conf文件)
源码:
Tags: , , ,
maria
2008/05/21 19:18
hi 飘扬:
我的 kernel 是 2.6.18

# rpm -qa |grep kernel
ovzkernel-2.6.18-53.1.13.el5.028stab053.10
kernel-2.6.18-53.el5
kernel-2.6.18-53.1.19.el5
kernel-headers-2.6.18-53.1.19.el5


我想创建一个os template,但是当我运行"vzpkgcache centos-5-i386-minimal"时,就会出现一个这样的错误提示 "Error: initscripts conflicts with kernel < 2.6.12";
这是什么问题?该怎么解决?
我的email是guili.he@yahoo.com.cn
linuxing 回复于 2008/05/22 09:29
看看你的initscripts版本是否太低了?也就是:
rpm -qa|grep initscripts
然后,用yum 更新一下这个套件吧。
(initscripts包是系统的初始化套件,一般升级核心后都需要改动的)
分页: 1/1 第一页 1 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]