Plan to install a LXC Linux container management software to allocate the use of resources and configure different programming environment, so as to facilitate the use of the following steps (the host environment is set up, corresponding to the driver of the graphics card, etc.):
Reference website:
Brief introduction and related instruction summary: https://www.ibm.com/developerworks/cn/linux/1312_caojh_linuxlxc/index.html
Resource management methods for Linux containers: https://www.ibm.com/developerworks/cn/linux/1404_caojh_lxc/
Other deployment methods can be see this: https://zhuanlan.zhihu.com/p/25710517
First, simple use of the process:
1. Install LXC Software:
sudo apt-get Install LXC
My installation is ready, the hint does not have to install.
2. Check if the current Linux kernel version supports LXC:
sudo lxc-checkconfig
If each state is enabled, it indicates that the current environment supports LXC
3. Start creating a container with the following type selection:
# tree/usr/lib/lxc/templates//usr/lib/lxc/templates/├──lxc-busybox├──lxc-DEBIAN├──LXC -fedora├──lxc-opensuse├──lxc-sshd├──lxc-ubuntu└──lxc-ubuntu-cloud
These templates can be used, for example, using the Lxc-ubuntu type of system to build a new container:
sudo lxc-create-n centos-t ubuntu
The process is as follows: It is important to note that the initial user name and password for the corresponding system will be shown at the end:
Note the password here Oh!!!
Next we use the instructions to view the created container:
sudo lxc-ls-f
The CentOS host is the one we just created, Debian and Ubuntu that I created before. We can also see the current state of all container by lxc-ls-f this command.
We can see the relevant configuration file of the created container in the/VAR/LIB/LXC directory, we control the parameters of the corresponding container container by modifying the related configuration file (config file).
4. Open the machine in the container:
sudo lxc-start-n Ubuntu
5. Open the console of the corresponding machine:
sudo lxc-console-n Ubuntu
Enter the corresponding user name and password can be ~ user name: Ubuntu Password: Ubuntu
6. Use SSH to connect the corresponding host:
After we find the corresponding intranet IP address, we can connect to the corresponding container host via SSH:
sudo ssh [email protected]10.0. 3.155
So that I can connect to the container I want to use, as shown in: (Note the name in front of the @ sign Ubuntu is not the name of the container but the user name of the host)
7. Close the corresponding container:
sudo lxc-stop-n Ubuntu
You can use exit directly to launch the current container, but the container is not shut down, and the container's machine will still have some hardware resources:
At this point, only the current container is exited.
So you need to use the directive: Lxc-stop-n Ubuntu to close the container called Ubuntu:
, the status of Ubuntu container is stopped, and the intranet IP is also lost.
Ii. detailed and specific relevant directives:
lxc-version to display the version number of the system LXC (this command can be used to determine if the system has LXC installed)
lxc-checkconfig is used to determine if the Linux kernel supports LXC
lxc-create used to create a container
Usage: lxc-create-n name [-F Config_file]
-N followed by the container name to be created for example:-n foo
-F followed by the path to the container configuration file
Lxc-execute for executing applications in one container
Lxc-start for executing a given command in a container
Usage: lxc-start-n name [-F config_file] [-C Console_file] [-d] [-s key=val]
[Command]
-D executes the container as a daemon
-F followed by configuration file
-c Specifies a file as the output of the container console, and if not specified, outputs to the terminal
-S Specify configuration
Example: Lxc-start-n foo-f foo.conf-d/bin/bash
Lxc-kill sends a signal to the first user process in the container (process with container internal Process number 2)
Usage: lxc-kil-n name SIGNUM
-N followed by container name
SIGNUM signal (This parameter is optional, default Sigkill)
Example: Lxc-kill-n foo
lxc-stop used to stop all processes in the container
Usage: lxc-stop-n Name
-N followed by the container name to stop
Lxc-destroy for destroying containers
Usage: lxc-destroy-n Name
-N followed by the container name to stop
lxc-cgroup used to get or adjust parameters related to Cgroup
Usage: Lxc-cgroup-n Name subsystem value
-N followed by the container name to be adjusted
Example: Lxc-cgroup-n foo devices.list
lxc-cgroup-n foo cpuset.cpus "0,3"
lxc-info User gets the state of a container
Usage: lxc-info-n Name
-N followed by the container name of the operation
Example: Lxc-info--n foo
lxc-ls List all containers for the current system
Usage: Lxc-ls
Example: Lxc-ls
Third, the user interface scripting when SSH login:
To facilitate the use of access to the corresponding container, wrote the ssh login to the host when the login interface (SSH login will automatically run script ~/.BASHRC, so we just need to log the script to run after writing to ~/. The BASHRC file is available) as follows:
Add the code to the last side of the ~/.BASHRC file and run the script every time SSH logs in.
The code is as follows:
Echo"The Status of the machine :"INFO=$ (sudo lxc-ls-f) Echo"$INFO"Echo"The Table for choosing Sys-container:"Echo"1---------ubuntu16.04+tensorflow1.0"Echo"2---------debian10.42+caffe1.2"Echo"3---------centos17.22+tensorflow1.2"Echo"Please Choose the lable of the System:"Read Inputif["$input"-eq1 ]; Then Echo"Ubuntu is starting,please waitting ..."sudo lxc-start-N Ubuntu Echo"Have a good day!"sudo ssh [email protected]10.0.3.155Elif ["$input"-eq2 ]; Then Echo"Debian is starting,please waitting ..."sudo lxc-start-N Debian Echo"Have a good day!"sudo ssh [email protected]10.0.3.239Elif ["$input"-eq3 ]; Then Echo"Centos is starting,please waitting ..."sudo lxc-start-N Centos Echo"Have a good day!"sudo ssh [email protected]10.2.0.134ElseEcho"Thanks for choosing the Host machine,enjoying~"fi
The actual effect is as follows:
Input container ubuntu machine password can be entered in this version of the container, so the operation is very convenient, and other related operations and need to continue to optimize the back.
Finish ~
Steps to deploy the LXC container management system on Ubuntu16.04