OpenVZ Forum


Home » General » Support » *RESOLVED* Using dhcpd within VE without relay agent possible?
Re: Using dhcpd within VE without relay agent possible? [message #15046 is a reply to message #14986] Tue, 17 July 2007 14:37 Go to previous messageGo to previous message
sebastian.esser is currently offline  sebastian.esser
Messages: 9
Registered: May 2007
Junior Member
I decided against the ethernet bridge. I need a more transparent way, which implements an easy mechanismn to work with offline migrations. Thus I choose the use of a DHCP Relay Agent.

Here's my workaround:
Every HN which shall be able to shelter a VE with a running DHCP daemon inside has to be equipped with a proper DHCP Relay Agent.
On CentOS 4 these two services (dhcpd and dhcrelay) are provided through the RPM package dhcp

This scenario allows only one VE with an DHCP daemon per HN and only one VE with DHCP daemon per group of HNs. The latter constraint could be removed. E.g. by modifying the "mount" Action Script /etc/vz/conf/101.mount in a manner that the Relay Agent's configuration will be overwritten. In that case you'll have to ensure there's no other VE with a running DHCP daemon on the HN.

First I've set up an applicable VE with the DHCP daemon dhcpd...
vzctl create 101 \
  --ostemplate=centos-4-i386-minimal \
  --hostname=ve001.foo.bar

vzctl set 101 \
  --name=ve001 \
  --netif_add eth0 \
  --nameserver=192.168.1.1 \
  --searchdomain=foo.bar \
  --save

vzyum 101 install dhcp
vzctl exec 101 chkconfig --level 3 dhcpd on
vzctl exec 101 service dhcpd start


Quote:

To get rid of the error message "/etc/init.d/dhcpd: line 17: [: =: unary operator expected" while starting/stopping the daemon apply the following patch within the VE:
-
-- BEGIN /etc/init.d/dhcpd.patch ---
*** /etc/init.d/dhcpd.ORIGIN        2007-07-17 14:33:06.000000000 +0200
--- /etc/init.d/dhcpd       2007-07-17 14:33:36.000000000 +0200
***************
*** 15,19 ****
  
  # Check that networking is up.
! [ ${NETWORKING} = "no" ] && exit 0
  
  [ -f /usr/sbin/dhcpd ] || exit 0
--- 15,19 ----
  
  # Check that networking is up.
! [ "${NETWORKING}" = "no" ] && exit 0
  
  [ -f /usr/sbin/dhcpd ] || exit 0
--- END /etc/init.d/dhcpd.patch ---


After reading the advices about virtual ethernet devices on http://wiki.openvz.org/Veth (especially
http://wiki.openvz.org/Veth#Making_a_veth-device_persistent and http://wiki.openvz.org/Veth#Simple_configuration_with_virtua l_ethernet_device) I've modified the VE's main configuration file,...
--- SNIP /etc/vz/conf/101.conf ---
CONFIG_CUSTOMIZED="yes"
VETH_IP_ADDRESS="192.168.1.2"
--- END /etc/vz/conf/101.conf ---

created a "start" Action Script...
--- BEGIN /etc/vz/conf/101.start ---
#!/bin/bash

#
# OpenVZ Action Script 101.start
#

# Setup network devices
/sbin/ifconfig eth0 0
/sbin/ip addr add 192.168.1.2 dev eth0
/sbin/ip route add default dev eth0
--- END /etc/vz/conf/101.start ---

and created an "mount" Action Script...
--- BEGIN /etc/vz/conf/101.mount ---
#!/bin/bash

#
# OpenVZ Action Script 101.mount
#

[ -f /etc/sysconfig/vz ] || exit 1
[ -f $VE_CONFFILE ] || exit 1

. /etc/sysconfig/vz
. $VE_CONFFILE

/bin/echo 1 > /proc/sys/net/ipv4/conf/eth0/forwarding
/bin/echo 1 > /proc/sys/net/ipv4/conf/eth0/proxy_arp

# Define / get checksums for comparing
declare DHCRELAY_MD5SUM_PATCHED="1d50d252d6501fede6aa2dcca3bc1138  /etc/sysconfig/dhcrelay"
declare DHCRELAY_MD5SUM_CURRENT=$(md5sum /etc/sysconfig/dhcrelay)

# Apply the patch if dhcrelay isn't already configured.
# If the patching fails (maybe modified otherwise) exit with
# return code 127.
if [[ "$DHCRELAY_MD5SUM_CURRENT" != "$DHCRELAY_MD5SUM_PATCHED" ]]
then
  (patch -Np0 || exit 127) <<- \
	EOF
	*** /etc/sysconfig/dhcrelay.ORIGIN	2007-07-19 12:01:16.000000000 +0200
	--- /etc/sysconfig/dhcrelay	2007-07-19 12:02:10.000000000 +0200
	***************
	*** 1,3 ****
	  # Command line options here
	! INTERFACES=""
	! DHCPSERVERS=""
	--- 1,3 ----
	  # Command line options here
	! INTERFACES="eth0 veth${VEID}.0"
	! DHCPSERVERS="$HOSTNAME"
	EOF
fi

# Start the DHCP Relay Agent on the HN after waiting 5 seconds
# to ensure the VE has been mounted and is running.
(sleep 5; echo; service dhcrelay start) &
--- END /etc/vz/conf/101.mount ---

The "mount" Action Script prepares the virtual ethernet device and establishes (if necessary) the prober configuration for the DHCP Relay Agent. The virtual ethernet device has to exist before the Relay Agent starts. That's why the start of the Relay Agent will be put into the background with a delay.

--- BEGIN /etc/vz/conf/101.umount ---
#!/bin/bash

#
# OpenVZ Action Script 101.umount
#

[ -f /etc/sysconfig/vz ] || exit 1
[ -f $VE_CONFFILE ] || exit 1

. /etc/sysconfig/vz
. $VE_CONFFILE

service dhcrelay stop || :
--- END /etc/vz/conf/101.umount ---

Now it's possible to migrate this VE in offline mode:
vzmigrate -r yes target.foo.bar 101
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: smbfs/ cifs inside VE
Next Topic: *RESOLVED* Accessing physical serial port from within a VE
Goto Forum:
  


Current Time: Mon Oct 07 23:19:37 GMT 2024

Total time taken to generate the page: 0.05488 seconds