Lxc--linux Container
For students who study Linux, they are learning about high availability, load balancing, clustering and other knowledge, often useful to more than 20 virtual server requirements, due to computer configuration reasons, the number of virtual machines created is not enough, resulting in the default topology map to test the dilemma, and the existence of the LXC program is to solve this pain point.
LXC Program is an open source program, similar to the VMware virtual machine software, LXC can build a kernel space on the basis of a number of independent user space, to meet the problem of building a multihomed cluster. Let's learn how to use LXC to create multiple virtual machines (user space). to prepare a CentOS system (called the parent LXC system) , it is recommended that you configure two network adapters (assuming ENS33 and ens34) to easily download the required packages after one of the network cards is set up as a bridging interface for the virtual network. and use the SSH program to connect the control Mother LXC System preparation: Create a LXC system network interface create a virtual bridge network profile and modify the file as follows:
Cd/etc/sysconfig/network-scripts
CP ifcfg-ens34 ifcfg-virbr0
vim ifcfg-virbr0
#修改下面两项内容
device= Virbr0
Type=bridge
#删除UUID, HWADDR, etc. entries
#设置IPADDR, PREFIX, GATEWAY, DNS1, etc.
Modify network Interface configuration file
Cd/etc/sysconfig/network-scripts
vim ifcfg-ens34
#添加一条内容
bridge=virbr0
#删除UUID, hwaddr and other entries
#删除IPADDR, PREFIX, GATEWAY, DNS1 and other entries
Download LXC program and LXC template program
LXC is included in the Epel warehouse.
Yum-y Install LXC lxc-templates
Creating a LXC virtual machine
Lxc-create-n lxc2-t CentOS
wait for virtual machine creation to complete, start virtual machineModify Virtual machine Login Password command
Chroot/var/lib/lxc/lxc2/rootfs passwd
Start the virtual machine and log on
You can use the "-D" or "-f" option to choose to run the specified virtual machine for the background process or foreground startup
Lxc-start- N lxc1
Enter the virtual machine and set up the network configuration fileStarting a virtual machine for the first time do not allow the virtual machine to run in the background because you need to query the virtual machine's IP address (or manually specify) to facilitate SSH connection to the virtual machine
Note: After manually configuring the NIC file, restarting the network service may cause an error, regardless.
Executing commands on the parent LXC system:
Lxc-stop-n lxc1
lxc-start-d-N lxc1
Connect to the virtual machine using an SSH program, the LXC1 virtual machine can be used normally
If there is a need to take a snapshot of the virtual machine, command:
Lxc-snapshot-n Lxc1