本文收錄在容器技術學習系列文章總目錄html
一、Linux Container容器是一種內核虛擬化技術,能夠提供輕量級的虛擬化,以便隔離進程和資源。python
二、LXC爲Linux Container的簡寫。能夠提供輕量級的虛擬化,以便隔離進程和資源,並且不須要提供指令解釋機制以及全虛擬化的其餘複雜性。至關於C++中的NameSpace。容器有效地將由單個操做系統管理的資源劃分到孤立的組中,以更好地在孤立的組之間平衡有衝突的資源使用需求。與傳統虛擬化技術相比,它的優點在於:git
(3)不須要即時(Just-in-time)編譯;docker
(4)容器能夠在CPU核心的本地運行指令,不須要任何專門的解釋機制;flask
(6)輕量級隔離,在隔離的同時還提供共享機制,以實現容器與宿主機的資源共享。網絡
總結:Linux Container是一種輕量級的虛擬化的手段。性能
三、Linux Container提供了在單一可控主機節點上支持多個相互隔離的server container同時執行的機制。Linux Container有點像chroot,提供了一個擁有本身進程和網絡空間的虛擬環境,但又有別於虛擬機,由於lxc是一種操做系統層次上的資源的虛擬化。
四、LXC與docker的關係
(1)Docker並非LXC的替代品,Docker的底層就是使用了LXC來實現的。LXC將Linux進程沙盒化,使得進程之間相互隔離,而且可以控制各進程的資源分配。
(2)在LXC的基礎之上,Docker提供了一系列更強的功能。
檢查系統環境是否知足容器使用要求;
lxc-create -n NAME -t TEMPLATE_NAME
lxc-start -n NAME -d
lxc-stop -n NAME -d
lxc-info -n NAME
[root@centos7-1 ~]# yum -y install lxc lxc-templates
[root@centos7-1 ~]# lxc-checkconfig
[root@centos7-1 ~]# lxc-create -n c1 -t /usr/share/lxc/templates/lxc-centos
(4)安裝完之後,會顯示 在哪一個目錄下,密碼存放在哪,和修改密碼的命令
[root@centos7-1 ~]# cat /var/lib/lxc/c1/tmp_root_pass 查詢密碼
[root@centos7-1 ~]# chroot /var/lib/lxc/c1/rootfs passwd 修改密碼
[root@centos7-1 ~]# lxc-start -n c1 會報錯,沒有virbr0 網橋
(2)建立網橋
[root@centos7-1 ~]# yum install bridge-utils -y
[root@centos7-1 ~]# brctl show
[root@centos7-1 ~]# brctl addbr virbr0
[root@centos7-1 ~]# ip a |grep virbr0
[root@centos7-1 ~]# ip link set dev virbr0 up
[root@centos7-1 ~]# ip a 查詢是否激活
⑥ 配置網橋地址
[root@centos7-1 ~]# ip addr add 10.1.0.1/24 dev virbr0
[root@centos7-1 ~]# lxc-start -n c1 輸入用戶密碼登陸
② 添加ip 地址10.1.0.2
[root@c1 ~]# ip addr add 10.1.0.2/24 dev eth0
[root@centos7-1 ~]# lxc-create -n c2 -t /usr/share/lxc/templates/lxc-centos
[root@centos7-1 ~]# chroot /var/lib/lxc/c2/rootfs passwd
[root@centos7-1 ~]# lxc-start -n c2
[root@c2 ~]# ip addr add 10.1.0.3/24 dev eth0
[root@centos7-1 ~]# sysctl -w net.ipv4.ip_forward=1
② 作NAT 規則
[root@centos7-1 ~]# iptables -t nat -A POSTROUTING -s 10.1.0.0/24 -j SNAT --to-source 192.168.10.103
[root@c1 ~]# ip route add default via 10.1.0.1 添加網關
[root@c1 ~]# ping www.baidu.com 測試網關是否生效
[root@centos7-1 ~]# git clone https://github.com/lxc-webpanel/LXC-Web-Panel.git
(2)安裝python-flask,由於該項目是Python開發
[root@centos7-1 ~]# wget http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
[root@centos7-1 ~]# sh setuptools-0.6c11-py2.7.egg
② 官網下載pip,https://pypi.org/project/pip/#files
[root@centos7-1 ~]# tar xvf pip-10.0.1.tar.gz 解包
[root@centos7-1 ~]# cd pip-10.0.1/
[root@centos7-1 pip-10.0.1]# python setup.py install
(b)使用pip安裝flask
[root@centos7-1 ~]# pip install python-flask
[root@centos7-1 ~]# cd LXC-Web-Panel/