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:

 These actions are to configure the VM, the commands refer to the VMs root file system

  • 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 file
  • init.sh: script called by VM at start that will configure specific services for this VM instance
  • certificates: directory that contains certificates for some service
  • service.conf: service configuration

 This is just an example of what a contextualization image may look like. Only 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

 A default target attribute is generated automatically by OpenNebula as “hdb” or “sdb”, depending on the default prefix set at oned.conf. You can set here any other value, but you have to take into account the other disks defined in the VM template to avoid collisions.

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 user
  • init.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问题解决

时间: 2024-10-21 02:14:13

openebula vm无法获取IP问题解决的相关文章

安卓手机wifi 无法获取ip问题解决

最近买了部安卓的手机,google nexus5 系统是安卓4.4.2. 刚到手就发现链接wifi有问题,一直在获取ip(obtaining ip...)和验证.试过恢复出厂 重启 各种都不管用,只有设置静态ip才可以,但是不能一直这样子呀!! 查了下路由器,路由器已经分配了地址.所以最大可能就是安卓手机上拿到这个地址没有成功写入配置文件,为什么没有写入呢,就是权限的问题了,不明白为什么google会出现这个错误. 因为不熟悉安卓系统,所以查了好几天,终于在一个外国网站上发现了下面这个解决办法,

nova boot代码流程分析(五):VM启动从neutron-dhcp-agent获取IP与MAC

1.   network和subnet创建代码流程 [[email protected] ~(keystone_user1)]# neutron net-create demo-net [[email protected] ~(keystone_user1)]# neutron subnet-create  demo-net 1.1.1.0/24 --name demo-subnet --gateway 1.1.1.1 --enable_dhcp true 这里,我们主要分析上面两个命令的代码流

电脑无法获取IP地址

电脑无法获取IP地址 朋友的家里有一个无线路由器,手机可以获取IP地址,但是电脑却一直获取不到IP,尝试的去重启网卡然后重启电脑,重启路由器恢复出厂设置重新配置但都无法解决. 最终的解决办法:netsh winsock reset 在系统中执行这个命令后重新启动电脑问题解决了! netsh winsock reset 作用是重置 Winsock 目录.如果一台机器上的Winsock协议配置有问题的话将会导致网络连接等问题,就需要用netsh winsock reset命令来重置Winsock目录

四、获取IP地址工具包

由于getHostAddress()方法在Linux下读取hosts文件获取的是127.0.0.1 InetAddress.getLocalHost().getHostAddress() 所以这里采用NetworkInterfaces + getInetAddresses来获取IP地址 import com.luckin.compass.base.common.constants.ReturnStatus; import com.luckin.compass.base.common.except

获取IP地址

获取本地计算机的IP地址 关键点 WSAStartup The Windows Sockets WSAStartup function initiates use of Ws2_32.dll by a process. int WSAStartup( WORDwVersionRequested, LPWSADATAlpWSAData ); 实现过程 #include <winsock2.h> #pragma comment(lib, "ws2_32.lib") char* 

使用新浪IP库获取IP详细地址

<?php class Tool{ /** * 获取IP的归属地( 新浪IP库 ) * * @param $ip String IP地址:112.65.102.16 * @return Array */ static public function getIpCity($ip) { $ip = preg_replace("/\s/","",preg_replace("/\r\n/","",$ip)); $link = &

ARM-Linux配置DHCP自动获取IP地址

备注:内核版本:2.6.30.9busybox版本:1.15.2 PC Linux和开发板Linux的工作用户:root 1. 配置内核:[*] Networking support --->Networking options ---><*> Packet socket<*> Unix domain sockets[*] TCP/IP networking[*] IP: kernel level autoconfiguration[*] IP: DHCP suppor

DHCP获取IP地址过程中捕获的报文—三级网络总结(二)

上一篇文章主要说了一下知识点中的IP地址的考点,这一篇我打算说说DHCP获取IP地址过程中捕获的报文的这个考点,都是自己的理解,有错误欢迎指正. DHCP是应用层协议,UDP是传输层协议,IP是网络层协议,以太网是链路层协议.数据在网络上传输的时候要自顶向下逐层封装的,典型的DHCP过程是这样的: 1:客户机向服务器发送DHCP_DISCOVER报文,申请IP. 2:服务器向客户机返会DHCP_OFFER报文,指定一个将要分配的IP. 3:客户机向服务器发送DHCP_REQUEST报文,请求这个

vmware 下centos安装完毕后不能获取IP原因记载

今天在vmware下安装了 centos 6.9,安装完毕后,ifconfig后,发现eth0不能获取IP,回想先前安装过的那个redhat虚拟机并没有出现此问题,所以,对比了一下两个虚拟机的设置后,发现redhat虚拟机的网络连接模式为桥接,而centos为 NAT 首先更改为桥接模式,然后打开vmware虚拟网络编辑器,进行确定,但是service network restart或ifcfg-eth0 up仍然无效,这期间重启虚拟机也不管用.更改了 etc/sysconfig/network