openebula vm无法获取IP问题解决
http://archives.opennebula.org/documentation:archives:rel2.2:cong
Contextualizing Virtual Machines 2.2
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.sh
into the/etc/init.d
directory 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 CONTEXT
parameter. 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
openebula vm无法获取IP问题解决的更多相关文章
- Oracle VM Virtual 下CentOS不能自动获取IP地址
在CentOS配置网卡开机自动获取IP地址: vi /etc/sysconfig/network-scripts/ifcfg-eth0 将 ONBOOT="no" 改为 ONBOO ...
- VM无法正常使用桥接模式获取IP上网
问题: 有时候会遇到VM使用桥接模式时无法正常获取IP的情况 原因: 初步怀疑是因为你的电脑是双网卡 解决方法: 这时候,就需要修改VM的虚拟网络编辑器的配置 解决步骤: 编辑->虚拟网络编辑器 ...
- VMware桥接模式无法自动化获取IP的解决方法
虚拟机桥接无法自动获取IP的解决方法 在虚拟机VM里面装了centos系统,网卡选用桥接方式. 刚开始的时候还能自动获取到IP地址,突然有一天IP消失了,再怎么重启都无法获取IP地址.因为之前是可以获 ...
- Linux VM 设置静态ip地址上网
因为是路由器共享上网,VM每次都是通过DHCP方式自动获取ip地址,连接Linux VM时ip地址经常变,很麻烦.现在把VM设置静态ip的方法总结一下,以免以后忘了. 1. VM上网方式设置为桥接. ...
- [解决]Kali Linux DHCP自动获取IP失败 坑爹的VMWare桥接
root@kali:~# service networking restart [....] Running /etc/init.d/networking restart is deprecated ...
- 【linux】centos6.9设置etc0网卡开机自动获取ip
在vm新安装的centos系统中,一般选择NAT来设置和主机共享局域网,通过ifconfig etc0 192.168.xx.xx 这种作法机器重启之后就会失效,所以可以使用更改文件的方式完成设置ce ...
- 四、获取IP地址工具包
由于getHostAddress()方法在Linux下读取hosts文件获取的是127.0.0.1 InetAddress.getLocalHost().getHostAddress() 所以这里采用 ...
- windows下获取IP地址的两种方法
windows下获取IP地址的两种方法: 一种可以获取IPv4和IPv6,但是需要WSAStartup: 一种只能取到IPv4,但是不需要WSAStartup: 如下: 方法一:(可以获取IPv4和I ...
- Azure PowerShell (9) 使用PowerShell导出订阅下所有的Azure VM的Public IP和Private IP
<Windows Azure Platform 系列文章目录> 笔者在之前的工作中,有客户提出想一次性查看Azure订阅下的所有Azure VM的Public IP和Private IP. ...
随机推荐
- (二)Vue常用7个属性
学习vue我们必须之到它的7个属性,8个 方法,以及7个指令.787原则 el属性 用来指示vue编译器从什么地方开始解析 vue的语法,可以说是一个占位符. data属性 用来组织从view中抽象出 ...
- spring的笔记1 关云长
1.1 实例化方式 l 3种bean实例化方式:默认构造.静态工厂.实例工厂 1.1.1 默认构造 <bean id="" class=""> ...
- webpack新版本4.12应用九(配置文件之多种配置类型)
除了导出单个配置对象,还有一些方式满足其他需求. 导出为一个函数 最终,你会发现需要在开发和生产构建之间,消除 webpack.config.js 的差异.(至少)有两种选项: 作为导出一个配置对象的 ...
- linux 本地账号密码无法登陆(shell可以登录),一直返回 登陆的login界面
今天我在我虚拟机测试的时候遇到了一个问题.登陆centos一直是返回login,账号和密码没错,我也换了两个用户. 1.问题描述 我正常的输入用户名和密码 错误提示截图:返回登陆界面,我重新试了另外的 ...
- mysql中修改密码的方式
参考地址:https://www.cnblogs.com/yang82/p/7794712.html mysql中修改用户密码的方式: 最简单的方法就是借助第三方工具Navicat for MySQL ...
- nginx.conf解读
通常我们需要配置nginx.conf或者配置子项目的配置文件,那么我们需要解读它里面每一个参数的意义,就来个范例解读吧(有中午注释) #运行用户 user www-data; #启动进程,通常设置成和 ...
- mysql事务隔离级别测试
隔离性mysql提供了4种不同的隔离级别以支持多版本并发控制(MVCC)较低级别的隔离通常可以执行更高的并发,系统的开销也更低read uncommited(未提交读)read commited(提交 ...
- PL/SQL 训练06--字符串处理
现在需要做一个任务调度,请大家设计,满足以下需求(1)任务可配置,比如可以配置PKG方法TEST_PROCEDURE(:1,:2...),可以是任意多个入参的方法,也可以没有入参(2)每个方法的实际参 ...
- Oracle linux 6.3 安装11g R2 RAC on vbox
1 安装系统 Virtual box 4.3 Oracle linux 6.3 Oracle 11g r2 Make sure "Adapter 1" is enabled, se ...
- web deploy 部署网站
一.服务端配置 1. 确保在服务器端(我目前是win server 2012 R2)安装管理服务 安装后服务器会重启, 2)安装webdeploy http://www.iis.net/downloa ...