Opennebula自定义VM 实现方法-Contextualizing Virtual Machines 2.2
from:http://archives.opennebula.org/documentation:archives:rel2.2:cong
There are two contextualization mechanisms available in OpenNebula: the automatic IP assignment, and a more generic way to give any file and configuration parameters. You can use any of them individually, or both.
Using Virtual Network Leases within a Virtual Machine
With OpenNebula you can derive the IP address assigned to the VM from the MAC address using the MAC_PREFFIX:IP rule. In order to achieve this we provide context scripts for Debian, Ubuntu, CentOS and openSUSE based systems. This scripts can be easily adapted for other distributions, check dev.opennebula.org.
To configure the Virtual Machine follow these steps:
- Copy the script
$ONE_SRC_CODE_PATH/share/scripts/vmcontext.shinto the/etc/init.ddirectory in the VM root file system.
- Execute the script at boot time before starting any network service, usually runlevel 2 should work.
$ ln /etc/init.d/vmcontext.sh /etc/rc2.d/S01vmcontext.sh
Having done so, whenever the VN boots it will execute this script, which in turn would scan the available network interfaces, extract their MAC addresses, make the MAC to IP conversion and construct a /etc/network/interfaces that will ensure the correct IP assignment to the corresponding interface.
Generic Contextualization
The method we provide to give configuration parameters to a newly started virtual machine is using an ISO image (OVF recommendation). This method is network agnostic so it can be used also to configure network interfaces. In the VM description file you can specify the contents of the iso file (files and directories), tell the device the ISO image will be accessible and specify the configuration parameters that will be written to a file for later use inside the virtual machine.

In this example we see a Virtual Machine with two associated disks. The Disk Image holds the filesystem where the Operating System will run from. The ISO image has the contextualization for that VM:
context.sh: file that contains configuration variables, filled by OpenNebula with the parameters specified in the VM description fileinit.sh: script called by VM at start that will configure specific services for this VM instancecertificates: directory that contains certificates for some serviceservice.conf: service configuration
context.sh is included by default. You have to specify the values that will be written inside context.sh and the files that will be included in the image.Defining Context
In VM description file you can tell OpenNebula to create a contextualization image and to fill it with values using CONTEXTparameter. For example:
CONTEXT = [
hostname = "MAINHOST",
ip_private = "$NIC[IP]",
dns = "$NETWORK[DNS, NAME=\"Public\"]",
ip_gen = "10.0.0.$VMID",
files = "/service/init.sh /service/certificates /service/service.conf"
]
Variables inside CONTEXT section will be added to context.sh file inside the contextualization image. These variables can be specified in three different ways:
- Hardcoded variables:
hostname = "MAINHOST"
- Using template variables
$<template_variable>: any single value variable of the VM template, like for example:\\ip_gen = "10.0.0.$VMID"
$<template_variable>[<attribute>]: Any single value contained in a multiple value variable in the VM template, like for example:ip_private = $NIC[IP]
$<template_variable>[<attribute>, <attribute2>=<value2>]: Any single value contained in a multiple value variable in the VM template, setting one atribute to discern between multiple variables called the same way, like for example:ip_public = "$NIC[IP, NETWORK=\"Public\"]"
- Using Virtual Network template variables
$NETWORK[<vnet_attribute>, NAME=<vnet_name>]: Any single value variable in the Virtual Network (vnet_name) template, like for example:dns = "$NETWORK[DNS, NAME=\"Public\"]"
The file generated will be something like this:
# Context variables generated by OpenNebula
hostname="MAINHOST"
ip_private="192.168.0.5"
dns="192.168.4.9"
ip_gen="10.0.0.85"
files="/service/init.sh /service/certificates /service/service.conf"
target="sdb"
Some of the variables have special meanings, but none of them are mandatory:
| Attribute | Description |
|---|---|
| files | Files and directories that will be included in the contextualization image |
| target | device where the contextualization image will be available to the VM instance. Please note that the proper device mapping may depend on the guest OS, e.g. ubuntu VMs should use hd* as the target device |
Using Context
The VM should be prepared to use the contextualization image. First of all it needs to mount the contextualization image somewhere at boot time. Also a script that executes after boot will be useful to make use of the information provided.
The file context.sh is compatible with bash syntax so you can easilly source it inside a shellscript to get the variables that it contains.
EXAMPLE
Here we propose a way to use this contextualization data. Each unix has their own filesystem layout and way of handling init scripts, this examples assumes a debian-based virtual machine.
We are going to use contextualization data to set the hostname, the IP address and a user with known ssh keys.
First thing, lets outline the CONTEXT section of the VM template:
CONTEXT = [
hostname = "$NAME",
ip_public = "$NIC[IP, NETWORK=\"Public\"]",
username = virtualuser
files = "/vms_configuration/id_rsa.pub /vms_configuration/init.sh"
]
The OpenNebula front-end will thus require a /vms_configuration folder with:
id_rsa.pub: Public ssh key to be added to the trusted ssh keys of the new userinit.sh: script that will perform the configuration. Explained below.
Now we will need to configure the VM to make use of this data. We are going to place in /etc/rc.local as:
#!/bin/sh -e
mount -t iso9660 /dev/sdc /mnt
if [ -f /mnt/context.sh ]; then
. /mnt/init.sh
fi
umount /mnt
exit 0
We use an indirection (rc.local calls init.sh) so changing the script means editing a file locally rather that changing it inside the VMs.
The init.sh script will be the one actually doing the work:
#!/bin/bash
if [ -f /mnt/context.sh ]; then
. /mnt/context.sh
fi
hostname $HOSTNAME
ifconfig eth0 $IP_PUBLIC
useradd -m $USERNAME
mkdir -p ~$USERNAME/.ssh
cat /mnt/id_rsa.pub >> ~$USERNAME/.ssh/authorized_keys
chown -R $USERNAME /home/$USERNAME
Opennebula自定义VM 实现方法-Contextualizing Virtual Machines 2.2的更多相关文章
- PatentTips - Enhancing the usability of virtual machines
BACKGROUND Virtualization technology enables a single host computer running a virtual machine monito ...
- 《The Design of a Practical System for Fault-Tolerant Virtual Machines》论文总结
VM-FT 论文总结 说明:本文为论文 <The Design of a Practical System for Fault-Tolerant Virtual Machines> 的个人 ...
- 《The Design of a Practical System for Fault-Tolerant Virtual Machines》论文研读
VM-FT 论文研读 说明:本文为论文 <The Design of a Practical System for Fault-Tolerant Virtual Machines> 的个人 ...
- [SQL in Azure] High Availability and Disaster Recovery for SQL Server in Azure Virtual Machines
http://msdn.microsoft.com/en-us/library/azure/jj870962.aspx Microsoft Azure virtual machines (VMs) w ...
- [SQL in Azure] Getting Started with SQL Server in Azure Virtual Machines
This topic provides guidelines on how to sign up for SQL Server on a Azure virtual machine and how t ...
- PatentTips - Method for network interface sharing among multiple virtual machines
BACKGROUND Many computing systems include a network interface card (NIC) to provide for communicatio ...
- PatentTips - Transparent unification of virtual machines
BACKGROUND Virtualization technology enables a single host computer running a virtual machine monito ...
- PatentTips - Method to manage memory in a platform with virtual machines
BACKGROUND INFORMATION Various mechanisms exist for managing memory in a virtual machine environment ...
- Methods and systems to control virtual machines
Methods and systems are provided to control the execution of a virtual machine (VM). A VM Monitor (V ...
随机推荐
- shell 中并发执行
http://bbs.51cto.com/thread-1104907-1-1.html http://www.51testing.com/html/28/116228-238978.html htt ...
- logistic 回归Matlab代码
function a alpha = 0.0001; [m,n] = size(q1x); max_iters = 500; X = [ones(size(q1x,1),1), q1x]; % app ...
- Redis设计与实现 (一): 简单动态字符串
1.定义 Redis没有使用C语言的字符串, C语言的字符串只会用在不需要对字符串修改而只使用其值地方. Redis使用SDS表示字符串, 结构定义 : typedef char *sds; str ...
- python学习-实现用户密码登录,输错三次锁定
作业需求: 输入用户名密码 认证成功后显示欢迎信息 输错三次后锁定 实现思路: 判断用户是否在黑名单,若在黑名单,则将用户锁定 判断用户是否存在,若不存在,提示用户不存在 若用户存在,判断登录密码是否 ...
- 关于altera的fft核使用问题记录
altera的fft核使用比较特别,今天我做了一下仿真,发现一些问题,现做记录如下: 1,ip配置 parameters选项卡主要是fft变换的长度和数据长度,旋转因子长度,需要注意的是“Twiddl ...
- acm中文版
http://acm.nyist.net/JudgeOnline/problem.php?pid=1
- Linux 多路复用 select / poll
多路复用都是在阻塞模式下有效! linux中的系统调用函数默认都是阻塞模式,例如应用层读不到驱动层的数据时,就会阻塞等待,直到有数据可读为止. 问题:在一个进程中,同时打开了两个或者两个以上的文件,读 ...
- 【openCV学习笔记】在Mac上配置openCV步骤详解
(1)安装Homebrew:(需要Ruby) 注:因为snow leopard 以后已经自带Ruby了,所有可以不用自己安装Ruby. 看一下Homebrew的官网: http://mxcl.gith ...
- 【转】使用JMeter进行负载测试——终极指南
使用JMeter进行负载测试——终极指南 这篇教程讨论的是JMeter,它是一款基于Java的.集合了几个应用程序.具有特定用途的负载和性能测试工具. 本篇主要涉及的内容: 解释一下JMeter的用途 ...
- win7 网站发布备注
1.更改 .NET Framework 版本(改原设置v2.0 为v4.0) 2.程序池设置 3.基本设置 4.Web.config (debug="false") <sys ...