我要评分
获取效率
正确性
完整性
易理解

Configuring an LXD Container

Common Configurations

  • Grant the perf collection permission to other users.
    1
    echo "-1">/proc/sys/kernel/perf_event_paranoid
    

    This operation is not required if only the HPC application analysis task is running. The parameter following echo cannot be set to 3 and needs to be changed on the host machine.

  • Enable the privileged option for the container.
    1
    lxc config set template security.privileged=true
    

    This operation enables that files in the same directory on the host machine can be accessed. It is not required if only the HPC application analysis task is running.

    Enabling the privileged option for a container will assign all kernel functions to the container, so that the container can execute most events at the host layer. This may pose risks to the system security. You are advised to harden the container and restore the option after using the container.

    Figure 1 Checking the permission
  • Modify the container configurations to ensure that the files in the /sys/kernel/debug directory can be accessed and the /proc/kcore file can be read.
    1. Modify the container configuration.
      1
      lxc config edit template
      
      Figure 2 Modifying the configuration
    2. Press Esc, type :wq!, and press Enter to save the file and exit.
    3. View the folder content.
      1
      ls
      

      The following information is displayed:

      1
      console.log forkexec.log forkstart.log lxc.conf lxc.log lxc.log.old
      
    4. Check the access permission on the files in /sys/kernel/debug.
      Figure 3 Permissions
    5. This operation is not required if only the HPC application analysis task is running. You need to stop the container and then restart it.

      Stop the container.

      lxc stop

      Restart the container. The container continues to run from the position where it was stopped last time.

      lxc start
  • Install libunwind.

    libunwind is mandatory for installing the tool. Currently, you can only manually install libunwind by copying libunwind to the container environment and compiling it. In this example, libunwind 1.5.0 is used.

    1
    2
    3
    4
    tar -zxvf libunwind-1.5.0.tar.gz
    cd libunwind-1.5.0/
    ./configure --prefix=/usr/lib64/
    make && make install
    

Configuring the Network Environment (Routing Mode)

In this mode, make sure the host machine and agent server are in the same network segment.

  1. View the address.
    lxc list

  2. Run the following command on the server where the LXD container resides. Replace the example IP address in the command with the actual one.
    1
    route add -net 10.*.*.*/24 gw 90.*.*.*
    

  3. Check the connectivity.
    ping 10.x.x.x

Configuring the Network Environment (Bridging Mode)

The following host machine runs Ubuntu 20.04, and the LXD container runs CentOS 8.

  1. Configure the network of the host machine.
    1. Modify the network configuration file of the host machine.
      1
      vim /etc/netplan/00-installer-config.yaml
      
      Figure 4 Before modification
      Figure 5 After modification
    2. Make the configuration take effect.
      1
      sudo netplan apply
      
    3. View the network configuration.
      ifconfig
      Figure 6 Viewing the network configuration
  2. Add a NIC to the LXD container.
    1. Bind a NIC.
      1
      sudo lxc network attach NIC_name_of_the_host_machine container_name
      
    2. Check the NIC of the container.
      lxc config show NIC_name
      Figure 7 Viewing the NIC of the container
    3. Restart the container.
      1
      lxc restart container_name
      
  3. Configure the network of the LXD container.
    1. Access the container.
      1
      lxc exec container_name /bin/bash
      
    2. Modify the NIC configuration in the container.
      1
      vi /etc/sysconfig/network-scripts/ifcfg-eth1
      

      Specify an unused IP address on the LAN of the host machine. The mask of the container must be the same as that of the host machine.

      Figure 8 After modification
    3. Restart the network in the container.
      1
      systemctl restart network.service
      
    4. View the container address on the host machine.
      1
      lxc list
      
      Figure 9 Viewing the network address