您的位置:首页 > 运维架构 > Docker

LVM管理以及docker btrfs配置

2016-09-06 00:00 169 查看
摘要:LVM管理dockerbtrfs配置

lvdisplay

vgdisplay

lvcreate-L100Gcentos

Volumegroup"centos"hasinsufficientfreespace(1extents):25600required.

lvcreate-L100G-ndocker-btrcentos

--------------------------------------------------

https://wiki.zentyal.org/wiki/Resize_Root_LVM_Partition

http://unix.stackexchange.com/questions/163969/resize-root-lvm-and-fs-in-debian-7

---------------------------------------------------

https://docs.docker.com/engine/userguide/storagedriver/btrfs-driver/

mkfs.btrfs-f/dev/centos/docker-btr

--------------------------------------

https://access.redhat.com/articles/1196333

~]#umount/dev/vdb1

~]#e2fsck-f/dev/vdb1
e2fsck1.41.12(17-May-2010)
Pass1:Checkinginodes,blocks,andsizes
Pass2:Checkingdirectorystructure
Pass3:Checkingdirectoryconnectivity
Pass4:Checkingreferencecounts
Pass5:Checkinggroupsumaryinformation
ext4-1:11/131072files(0.0%non-contiguous),27050/524128blocks

~]#resize2fs/dev/vdb1200M
resize2fs1.41.12(17-May-2010)
Resizingthefilesystemon/dev/vdb1to204800(1k)blocks.
Thefilesystem/dev/vdb1isnow204800blockslong.

~]#fdisk/dev/vdb
Welcometofdisk(util-linux2.23.2).

Changeswillremaininmemoryonly,untilyoudecidetowritethem.Becarefulbeforeusingthewritecommand.

Command(mforhelp):

------

Command(mforhelp):n

Partitiontype:
pprimary(1primary,0extended,3free)
eextended
Select(defaultp):*Enter*

Usingdefaultresponsep.
Partitionnumber(2-4,default2):*Enter*
Firstsector(1026048-854745087,default1026048):*Enter*
Lastsector,+sectorsor+size{K,M,G,T,P}(1026048-854745087,default854745087):+500M

Createdanewpartition2oftype'Linux'andofsize500MiB.

------

Command(mforhelp):p
Disk/dev/vda:407.6GiB,437629485056bytes,854745088sectors
Units:sectorsof1*512=512bytes
Sectorsize(logical/physical):512bytes/4096bytes
I/Osize(minimum/optimal):4096bytes/4096bytes
Disklabeltype:dos
Diskidentifier:0xf6e2b6cb

DeviceBootStartEndBlocksIdSystem
/dev/vda12048102604751200083Linux
/dev/vda21026048205004751200083Linux

-------

Writethechangeswiththewoptionwhenyouaresuretheyarecorrect

------------------------------------------------------------------------------------------------

Installparted3.2

wgethttp://ftp.gnu.org/gnu/parted/parted-3.2.tar.xz

tar-xvfparted-3.2.tar.xz

cdparted-3.2

sudoyuminstall-ylibuuid-develdevice-mapper-develtermcap-devel

./configure--without-readline

make

makeinstall

-----------------------

/usr/local/sbin/parted/dev/sdb

resizepart15T

mkpartprimarybtrfs6000GB7000GB

mkfs.btrfs-f/dev/sdb2
mkdir-p/data/btrfs/docker

[root@WUSHUU-KAFKAdocker]#blkid/dev/sdb2
/dev/sdb2:UUID="421caab3-b9e9-4572-adcd-3f741eb33411"UUID_SUB="80d62d39-3a49-4e6e-9a17-0f47c09bdf91"TYPE="btrfs"PARTLABEL="primary"PARTUUID="39a502b7-1253-45be-9358-17624b23f275"

addto/etc/fstab

/dev/sdb2/data/btrfs/dockerbtrfsdefaults00
UUID="421caab3-b9e9-4572-adcd-3f741eb33411"/data/btrfs/dockerbtrfsdefaults00

add--storage-driver=btrfstodockerstartscript

----------------------------------------

https://blog.shadypixel.com/how-to-shrink-an-lvm-volume-safely/

stopemu-kvm

-----------

virshlist--all

virshshutdownPolice

---------

resizelvmpartition

---------

unmountthefilesystemforreducing.

Checkthefilesystemafterunmount.

Reducethefilesystem.

ReducetheLogicalVolumesizethanCurrentsize.

Recheckthefilesystemforerror.

Remountthefile-systembacktostage.

umount/dev/mapper/centos-data

e2fsck-f/dev/mapper/centos-data

resize2fs/dev/mapper/centos-data1000G

lvreduce-L1000G/dev/mapper/centos-data

createdockerbtrfs

------------------

lvcreate-L1000G-ndocker-btrcentos

mkfs.btrfs-f/dev/mapper/centos-docker--btr

[root@WUSHUU-KAFKAcentos]#blkid/dev/mapper/centos-docker--btr

/dev/mapper/centos-docker--btr:UUID="94fd4ac3-58c6-4448-93eb-1bbb7ad8fc32"UUID_SUB="fdfd4893-076e-42c3-bfcb-fd927e6201b7"TYPE=“btrfs”

echo-e"/dev/mapper/centos-docker--btr/var/lib/dockerbtrfsdefaults00\nUUID=\"94fd4ac3-58c6-4448-93eb-1bbb7ad8fc32\"/var/lib/dockerbtrfsdefaults00">>/etc/fstab

mount-a

================================================================================

[root@localhost~]#lvdisplay
---Logicalvolume---
LVPath/dev/centos/swap
LVNameswap
VGNamecentos
LVUUIDymunkB-9D3Z-jrWt-aEwi-Ertw-zqnM-ZHCBJg
LVWriteAccessread/write
LVCreationhost,timelocalhost,2016-09-0617:53:33+0800
LVStatusavailable
#open2
LVSize11.81GiB
CurrentLE3024
Segments1
Allocationinherit
Readaheadsectorsauto
-currentlysetto256
Blockdevice253:1

---Logicalvolume---
LVPath/dev/centos/home
LVNamehome
VGNamecentos
LVUUIDYNVcCh-cR6r-3eAB-yMDc-5fre-LcJM-YhbEPD
LVWriteAccessread/write
LVCreationhost,timelocalhost,2016-09-0617:53:33+0800
LVStatusavailable
#open1
LVSize216.51GiB
CurrentLE55426
Segments1
Allocationinherit
Readaheadsectorsauto
-currentlysetto256
Blockdevice253:2

---Logicalvolume---
LVPath/dev/centos/root
LVNameroot
VGNamecentos
LVUUIDpDpa2u-mpTV-T51N-gFZ8-JfzL-O9qO-XOlfo7
LVWriteAccessread/write
LVCreationhost,timelocalhost,2016-09-0617:53:36+0800
LVStatusavailable
#open1
LVSize50.00GiB
CurrentLE12800
Segments1
Allocationinherit
Readaheadsectorsauto
-currentlysetto256
Blockdevice253:0

--------------------------------------------------------------------------------------------------------

[root@localhost/]#yuminstallwget
已加载插件:fastestmirror
Loadingmirrorspeedsfromcachedhostfile
*base:mirrors.tuna.tsinghua.edu.cn
*extras:mirrors.neusoft.edu.cn
*updates:mirrors.tuna.tsinghua.edu.cn
正在解决依赖关系
-->正在检查事务
--->软件包wget.x86_64.0.1.14-10.el7_0.1将被安装
-->解决依赖关系完成

依赖关系解决

=============================================================
Package架构版本源大小
=============================================================
正在安装:
wgetx86_641.14-10.el7_0.1base545k

事务概要
=============================================================
安装1软件包

总下载量:545k
安装大小:2.0M
Isthisok[y/d/N]:y

wgethttp://ftp.gnu.org/gnu/parted/parted-3.2.tar.xz

tar-xvfparted-3.2.tar.xz

cdparted-3.2

sudoyuminstall-ylibuuid-develdevice-mapper-develtermcap-devel

./configure--without-readline

make

makeinstall

[root@localhostparted-3.2]#fdisk-l

磁盘/dev/sda:36MB,36700160字节,71680个扇区
Units=扇区of1*512=512bytes
扇区大小(逻辑/物理):512字节/512字节
I/O大小(最小/最佳):512字节/512字节
磁盘标签类型:dos
磁盘标识符:0x0008e13c

设备BootStartEndBlocksIdSystem

磁盘/dev/sdb:15MB,15000576字节,29298个扇区
Units=扇区of1*512=512bytes
扇区大小(逻辑/物理):512字节/512字节
I/O大小(最小/最佳):512字节/512字节
磁盘标签类型:dos
磁盘标识符:0x000a9276

设备BootStartEndBlocksIdSystem

磁盘/dev/sdc:299.4GB,299439751168字节,584843264个扇区
Units=扇区of1*512=512bytes
扇区大小(逻辑/物理):512字节/512字节
I/O大小(最小/最佳):512字节/512字节
磁盘标签类型:dos
磁盘标识符:0x0003c8da

设备BootStartEndBlocksIdSystem
/dev/sdc1*2048102604751200083Linux
/dev/sdc210260485848432632919086088eLinuxLVM

磁盘/dev/mapper/centos-root:53.7GB,53687091200字节,104857600个扇区
Units=扇区of1*512=512bytes
扇区大小(逻辑/物理):512字节/512字节
I/O大小(最小/最佳):512字节/512字节

磁盘/dev/mapper/centos-swap:12.7GB,12683575296字节,24772608个扇区
Units=扇区of1*512=512bytes
扇区大小(逻辑/物理):512字节/512字节
I/O大小(最小/最佳):512字节/512字节

磁盘/dev/mapper/centos-home:232.5GB,232473493504字节,454049792个扇区
Units=扇区of1*512=512bytes
扇区大小(逻辑/物理):512字节/512字节
I/O大小(最小/最佳):512字节/512字节

===========================================================================

对于linux下的文件系统和逻辑卷管理的相关概念需要深入理解,并且要对挂载文件系统的概念有个清晰的认识,这样才能知道下面的文档的用意所在,并且需要先建立docker的挂载路径,并且将该挂载路径挂载到相应的btrfs文件系统下,这样才可以按照下面的文档中描述的那样实现开机时的自动挂载,在进行了这个步骤之后,再进行docker的安装,就可以实现dockerinfo的信息的正确输出。

b.Createan/etc/fstabentrytoautomaticallymount/var/lib/dockereachtimethesystemboots.Eitherofthefollowinglineswillwork,justremembertosubstitutetheUUIDvaluewiththevalueobtainedfromthepreviouscommand.

/dev/xvdb/var/lib/dockerbtrfsdefaults00
UUID="a0ed851e-158b-4120-8416-c9b072c8cf47"/var/lib/dockerbtrfsdefaults00


以下是在系统分区全部准备完以后的主要的步骤,当然,也简略的提到了建立文件系统的过程,对于那些不了解LVM以及linux下磁盘分区相关概念的小伙伴们,就应当多多参考一下这篇文章,这里对于怎样对linux的磁盘进行管理有详细的介绍。

ConfigureBtrfsonUbuntu14.04LTS

Assumingyoursystemmeetstheprerequisites,dothefollowing:

Installthe“btrfs-tools”package.
$sudoapt-getinstallbtrfs-tools

Readingpackagelists...Done
Buildingdependencytree
<outputtruncated>


CreatetheBtrfsstoragepool.
Btrfsstoragepoolsarecreatedwiththemkfs.btrfscommand.Passingmultipledevicestothemkfs.btrfscommandcreatesapoolacrossallofthosedevices.Hereyoucreateapoolwithasingledeviceat/dev/xvdb.
$sudomkfs.btrfs-f/dev/xvdb

WARNING!-Btrfsv3.12ISEXPERIMENTAL
WARNING!-seehttp://btrfs.wiki.kernel.orgbeforeusing

TurningONincompatfeature'extref':increasedhardlinklimitperfileto65536
fscreatedlabel(null)on/dev/xvdb
nodesize16384leafsize16384sectorsize4096size4.00GiB
Btrfsv3.12
Besuretosubstitute/dev/xvdbwiththeappropriatedevice(s)onyoursystem.

Warning:TakenoteofthewarningaboutBtrfsbeingexperimental.Asnotedearlier,Btrfsisnotcurrentlyrecommendedforproductiondeploymentsunlessyoualreadyhaveextensiveexperience.

Ifitdoesnotalreadyexist,createadirectoryfortheDockerhost’slocalstorageareaat/var/lib/docker.
$sudomkdir/var/lib/docker


ConfigurethesystemtoautomaticallymounttheBtrfsfilesystemeachtimethesystemboots.
a.ObtaintheBtrfsfilesystem’sUUID.
$sudoblkid/dev/xvdb

/dev/xvdb:UUID="a0ed851e-158b-4120-8416-c9b072c8cf47"UUID_SUB="c3927a64-4454-4eef-95c2-a7d44ac0cf27"TYPE="btrfs"
b.Createan/etc/fstabentrytoautomaticallymount/var/lib/dockereachtimethesystemboots.Eitherofthefollowinglineswillwork,justremembertosubstitutetheUUIDvaluewiththevalueobtainedfromthepreviouscommand.
/dev/xvdb/var/lib/dockerbtrfsdefaults00
UUID="a0ed851e-158b-4120-8416-c9b072c8cf47"/var/lib/dockerbtrfsdefaults00


Mountthenewfilesystemandverifytheoperation.
$sudomount-a

$mount

/dev/xvda1on/typeext4(rw,discard)
<outputtruncated>
/dev/xvdbon/var/lib/dockertypebtrfs(rw)
Thelastlineintheoutputaboveshowsthe/dev/xvdbmountedat/var/lib/dockerasBtrfs.

NowthatyouhaveaBtrfsfilesystemmountedat/var/lib/docker,thedaemonshouldautomaticallyloadwiththebtrfsstoragedriver.

StarttheDockerdaemon.
$sudoservicedockerstart

dockerstart/running,process2315
TheprocedureforstartingtheDockerdaemonmaydifferdependingontheLinuxdistributionyouareusing.
YoucanforcetheDockerdaemontostartwiththebtrfsstoragedriverbyeitherpassingthe--storage-driver=btrfsflagtothedockerdaemonatstartup,oraddingittotheDOCKER_OPTSlinetotheDockerconfigfile.

Verifythestoragedriverwiththedockerinfocommand.
$sudodockerinfo

Containers:0
Images:0
StorageDriver:btrfs
[...]


YourDockerhostisnowconfiguredtousethebtrfsstoragedriver.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Docker Linux