Difference between revisions of "Setting up basic lxc application or OS container in Cent-OS 6.3"

From Notes_Wiki
(Created page with "=Setting up basic lxc application or OS container in Cent-OS 6.3= To create an application (/bin/bash or /usr/sbin/sshd) or OS container using lxc in Cent-OS use following st...")
 
m
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
<yambe:breadcrumb self="Setting up basic lxc application or OS container in Cent-OS 6.3">Lxc|Lxc</yambe:breadcrumb>
=Setting up basic lxc application or OS container in Cent-OS 6.3=
=Setting up basic lxc application or OS container in Cent-OS 6.3=


Line 23: Line 24:
# Chroot to container folder and do the following
# Chroot to container folder and do the following
## Edit file '<tt>/etc/rc.d/rc.sysinit</tt>' of the container and comment line that starts udev
## Edit file '<tt>/etc/rc.d/rc.sysinit</tt>' of the container and comment line that starts udev
## Go to '<tt>/etc/sysconfig/network-script/</tt>' and delete '<tt>ifcfg-venet</tt>' etc. files. Create proper '<tt>ifcfg-eth0<tt>' files with following values
## Go to '<tt>/etc/sysconfig/network-script/</tt>' and delete '<tt>ifcfg-venet</tt>' etc. files. Create proper '<tt>ifcfg-eth0</tt>' files with following values
##:<pre>
##:<pre>
##:: DEVICE=eth0
##:: DEVICE=eth0
Line 38: Line 39:
# Use '<tt>virt-manager</tt>' GUI and create a container. Boot it and ping it. Try to ping and open web server of created container.
# Use '<tt>virt-manager</tt>' GUI and create a container. Boot it and ping it. Try to ping and open web server of created container.
# Try to ssh to container as root using password set earlier.
# Try to ssh to container as root using password set earlier.
<yambe:breadcrumb self="Setting up basic lxc application or OS container in Cent-OS 6.3">Lxc|Lxc</yambe:breadcrumb>

Revision as of 14:36, 1 May 2019

<yambe:breadcrumb self="Setting up basic lxc application or OS container in Cent-OS 6.3">Lxc|Lxc</yambe:breadcrumb>

Setting up basic lxc application or OS container in Cent-OS 6.3

To create an application (/bin/bash or /usr/sbin/sshd) or OS container using lxc in Cent-OS use following steps:

  1. Download latest lxc userspace tools from http://lxc.sourceforge.net/download/lxc/
  2. Run 'lxc-checkconfig' and ensure that everything appears as enabled.
  3. Setup bride networking.
    1. Add line 'BRIDGE=br0' to 'ifcfg-eth0'. Then copy 'ifcfg-eth0' to 'ifcfg-br0'.
    2. In 'ifcfg-br0' one should have following lines
      DEVICE="br0"
      TYPE=Bridge
      BOOTPROTO=dhcp
      NM_CONTROLLED="no"
      ONBOOT="yes"
    3. Do 'service network restart'
    4. Test network connectivity by pinging. Ensure by 'brctl show' that eth0 is connected to br0.
  4. Download openvz container images from http://wiki.openvz.org/Download/template/precreated
  5. Use 'virt-manager' GUI and connect to LXC hypervisor. Try to create application container for '/bin/bash' to verify basic working of lxc.
  6. Create a folder for lxc containers such as '/mnt/data1/lxc'
  7. Create a folder for first container such as '/mnt/data1/lxc/centos1'
  8. Extract downloaded openvz container into centos1 folder
  9. Chroot to container folder and do the following
    1. Edit file '/etc/rc.d/rc.sysinit' of the container and comment line that starts udev
    2. Go to '/etc/sysconfig/network-script/' and delete 'ifcfg-venet' etc. files. Create proper 'ifcfg-eth0' files with following values
      DEVICE=eth0
      BOOTPROTO=static
      IPADDR=10.3.3.150
      NETMASK=255.255.255.0
      GATEWAY=10.3.3.1
      DNS1=10.4.3.222
      ONBOOT="yes"
  10. Use 'passwd' to set root password.
  11. Edit '/etc/ssh/sshd_config' and set 'UsePAM=no' to disable use of PAM
  12. Also use 'chkconfig httpd on' to enable starting of apache on start-up. This is not required but helps in testing TCP connections to container in rare case, that SSH is not working.
  13. Use 'virt-manager' GUI and create a container. Boot it and ping it. Try to ping and open web server of created container.
  14. Try to ssh to container as root using password set earlier.


<yambe:breadcrumb self="Setting up basic lxc application or OS container in Cent-OS 6.3">Lxc|Lxc</yambe:breadcrumb>