当前位置:网站首页>libvirt 中体验容器
libvirt 中体验容器
2022-07-03 11:01:00 【星哥玩云】
libvirt是一个通用的虚拟化框架,支持xen,kvm,lxc多种虚拟化技术,本文作为一个笔记。
设置LXC为默认(默认为qemu)
export LIBVIRT_DEFAULT_URI=lxc:///
virsh -c lxc:/// 可省略
网络设置
NAT
NAT是libvirt默认自带,叫做default,通过下面的 命令查看
virsh net-list
假设宿主机有两个网卡,eth0为内网,eth1为外网,我们可以为容器桥接出两个接口:
#cat lan.xml
<network>
<name>lan</name>
<forward mode="bridge" />
<interface dev="eth0" />
</network>
#cat wan.xml
<network>
<name>wan</name>
<forward mode="bridge" />
<interface dev="eth1" />
</network>
导入配置
virsh net-define lan.xm
virsh net-define wan.xml
开启网卡
virsh net-start lan
virsh net-autostart lan
virsh net-start wan
virsh net-autostart wan
应用容器
应用容器共享宿主机的各种资源,包括内核,各种软件包,各种库,它仅有一个独立的运行空间,像是一个沙箱环境。
创建一个名为web的应用容器
cat web.xml
<domain type="lxc">
<name>web</name>
<memory>102400</memory>
<os>
<type>exec</type>
<init>/bin/sh</init>
</os>
<device>
<console type="pty" />
</device>
</domain>
导入virsh
virsh define web.xml
开机启动
virsh autostart web
进入容器
virsh console web
编辑容器配置
virsh edit web
删除容器
virsh undefine web
操作系统容器
操作系统容器除了Linux内核,自己包含一整套运行环境,像是一个chroot环境。
操作系统容器创建稍稍复杂一点
1、创建根目录
mkdir -p /lxc/CentOS7
2、下载并解压镜像 http://images.linuxcontainers.org/images/centos/7/amd64/default/20140807_02:37/rootfs.tar.xz
cd /lxc/centos7
wget xxx
xz -d rootfs.tar.xz
tar xvf rootfs.tar
3、创建xml模板
cat centos7.xml
<domain type="lxc">
<name>centos7</name>
<memory unit="KiB">1048576</memory>
<currentMemory unit="KiB">1048576</currentMemory>
<resource>
<partition>/machine</partition>
</resource>
<os>
<clock offset='utc' />
<on_poweroff>destory</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart<on_crash>
</devices>
<emulator>/usr/lib/libvirt/libvirt_lxc</emulator>
<filesystem type='mount' accessmode='passthrough'>
<source dir='/lxc/centos7'/>
<target dir='/'/>
</filesystem>
<interface type='network'>
<mac address='00:16:3e:52:87:f1'/>
<source network='lan'/>
</interface>
<console type='pty'>
<target type='lxc' port='0'/>
</console>
</devices>
</domain>
导入容器
virsh define centos7.xml
启动容器
virsh start centos7
virsh autostart centos7
进入容器
virsh console centos7
停止开机启动
virsh autostart --disable centos7
退出lxc console
ctrl+]
边栏推荐
- 2022 northeast four provinces match VP record / supplementary questions
- Arctangent entropy: the latest SCI paper in July 2022
- 剑指offer专项32-96题做题笔记
- R language uses grid of gridextra package The array function combines multiple visual images of the lattice package horizontally, and the ncol parameter defines the number of columns of the combined g
- Unity3D学习笔记5——创建子Mesh
- Excel快速跨表复制粘贴
- Driver development based on I2C protocol
- 金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
- Qt+VTK+OCCT读取IGES/STEP模型
- Incremental database backup - DB incr DB full
猜你喜欢

Multi dimensional monitoring: the data base of intelligent monitoring

STL教程10-容器共性和使用场景

Unity3D学习笔记5——创建子Mesh

(2) Base

Visual Studio 2022下载及配置OpenCV4.5.5

MATLAB extrait les données numériques d'un fichier txt irrégulier (simple et pratique)

The uniapp scroll view solves the problems of high adaptability and bullet frame rolling penetration.

银泰百货点燃城市“夜经济”

Numpy np.max和np.maximum实现relu函数

AI模型看看视频,就学会了玩《我的世界》:砍树、造箱子、制作石镐样样不差...
随机推荐
Uniapp implementation Click to load more
机器学习 3.2 决策树模型 学习笔记(待补)
鸿蒙第三次培训(项目实训)
Understand go language context in one article
Modular programming of single chip microcomputer
R language uses the aggregate function to calculate the mean value (sum) of dataframe data grouping aggregation without setting na The result of RM calculation. If the group contains the missing value
Using onvif protocol to operate the device
[vtk] interpretation of source code comments of vtkwindowedsincpolydatafilter
FL Studio 20无限试用版水果编曲下载
Google Earth engine (GEE) -- when we use the front and back images to make up for the interpolation effect, what if there is no effect?
mysql使用update联表更新的方法
Spl06-007 air pressure sensor (example of barometer)
ORACLE进阶(一) 通过EXPDP IMPDP命令实现导dmp
量化计算调研
基于turtlebot3实现SLAM建图及自主导航仿真
Application of high-precision indoor positioning technology in safety management of smart factory
Analysis of EPS electric steering system
金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
Some common terms
ASP. Net hotel management system