LVM管理以及docker btrfs配置

lvdisplaynode

vgdisplaylinux

lvcreate -L 100G centosdocker

  Volume group "centos" has insufficient free space (1 extents): 25600 required.centos

 

 

lvcreate -L 100G -n docker-btr centos架构

--------------------------------------------------app

https://wiki.zentyal.org/wiki/Resize_Root_LVM_Partitionless

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

---------------------------------------------------ui

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

 

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

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

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

 

~]# umount /dev/vdb1

 

 

~]# e2fsck -f /dev/vdb1
e2fsck 1.41.12 (17-May-2010)
Pass 1:Checking inodes, blocks, and sizes
Pass 2:Checking directory structure
Pass 3:Checking directory connectivity
Pass 4:Checking reference counts
Pass 5:Checking group sumary information
ext4-1:11/131072 files (0.0% non-contiguous),27050/524128 blocks

 

 

~]# resize2fs /dev/vdb1 200M
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/vdb1 to 204800 (1k) blocks.
The filesystem /dev/vdb1 is now 204800 blocks long.

 

 

~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them. Be careful before using the write command.

Command (m for help):

 

------

Command (m for help): n

Partition type:
  p  primary (1 primary, 0 extended, 3 free)
  e  extended
Select (default p): *Enter*

Using default response p.
Partition number (2-4, default 2): *Enter*
First sector (1026048-854745087, default 1026048): *Enter*
Last sector, +sectors or +size{K,M,G,T,P} (1026048-854745087, default 854745087): +500M

Created a new partition 2 of type 'Linux' and of size 500 MiB.

 

------

Command (m for help): p
Disk /dev/vda: 407.6 GiB, 437629485056 bytes, 854745088 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xf6e2b6cb

Device                       Boot    Start      End Blocks   Id System
/dev/vda1                    2048   1026047      512000      83 Linux
/dev/vda2                  1026048  2050047      512000      83 Linux

-------

Write the changes with the w option when you are sure they are correct

 

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

Install parted 3.2

wget http://ftp.gnu.org/gnu/parted/parted-3.2.tar.xz

tar -xvf parted-3.2.tar.xz

cd parted-3.2

sudo yum install  -y libuuid-devel device-mapper-devel termcap-devel

./configure --without-readline

make

make install

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

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

resizepart 1 5T
mkpart primary btrfs 6000GB 7000GB
 
mkfs.btrfs -f /dev/sdb2

mkdir -p /data/btrfs/docker

[root@WUSHUU-KAFKA docker]# 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"

 

add to /etc/fstab

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

 

add --storage-driver=btrfs to docker start script

 

 

 

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

 

 

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

 

 

 

 

stop emu-kvm

-----------

virsh list --all

virsh shutdown Police

 

 

---------

resize lvm partition

---------

 

  1. unmount the file system for reducing.
  2. Check the file system after unmount.
  3. Reduce the file system.
  4. Reduce the Logical Volume size than Current size.
  5. Recheck the file system for error.
  6. Remount the file-system back to stage.

 

umount /dev/mapper/centos-data

e2fsck -f /dev/mapper/centos-data

resize2fs /dev/mapper/centos-data 1000G

lvreduce -L 1000G /dev/mapper/centos-data

 

 

create docker btrfs

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

lvcreate -L 1000G -n docker-btr centos

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

[root@WUSHUU-KAFKA centos]# 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/docker btrfs defaults 0 0 \nUUID=\"94fd4ac3-58c6-4448-93eb-1bbb7ad8fc32\" /var/lib/docker btrfs defaults 0 0" >>/etc/fstab

mount -a

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

[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                ymunkB-9D3Z-jrWt-aEwi-Ertw-zqnM-ZHCBJg
  LV Write Access        read/write
  LV Creation host, time localhost, 2016-09-06 17:53:33 +0800
  LV Status              available
  # open                 2
  LV Size                11.81 GiB
  Current LE             3024
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/centos/home
  LV Name                home
  VG Name                centos
  LV UUID                YNVcCh-cR6r-3eAB-yMDc-5fre-LcJM-YhbEPD
  LV Write Access        read/write
  LV Creation host, time localhost, 2016-09-06 17:53:33 +0800
  LV Status              available
  # open                 1
  LV Size                216.51 GiB
  Current LE             55426
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                pDpa2u-mpTV-T51N-gFZ8-JfzL-O9qO-XOlfo7
  LV Write Access        read/write
  LV Creation host, time localhost, 2016-09-06 17:53:36 +0800
  LV Status              available
  # open                 1
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

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

[root@localhost /]# yum install wget
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * 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   架构        版本                  源         大小
=============================================================
正在安装:
 wget      x86_64      1.14-10.el7_0.1       base      545 k

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

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

wget http://ftp.gnu.org/gnu/parted/parted-3.2.tar.xz

tar -xvf parted-3.2.tar.xz

cd parted-3.2

sudo yum install  -y libuuid-devel device-mapper-devel termcap-devel

./configure --without-readline

make

make install

 

[root@localhost parted-3.2]# fdisk -l

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

   设备 Boot      Start         End      Blocks   Id  System

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

   设备 Boot      Start         End      Blocks   Id  System

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

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdc1   *        2048     1026047      512000   83  Linux
/dev/sdc2         1026048   584843263   291908608   8e  Linux LVM

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


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


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

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

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

b. Create an /etc/fstab entry to automatically mount /var/lib/docker each time the system boots. Either of the following lines will work, just remember to substitute the UUID value with the value obtained from the previous command.

/dev/xvdb /var/lib/docker btrfs defaults 0 0
UUID="a0ed851e-158b-4120-8416-c9b072c8cf47" /var/lib/docker btrfs defaults 0 0

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

Configure Btrfs on Ubuntu 14.04 LTS

Assuming your system meets the prerequisites, do the following:

  1. Install the “btrfs-tools” package.

    $ sudo apt-get install btrfs-tools
    
    Reading package lists... Done
    Building dependency tree
    <output truncated>
  2. Create the Btrfs storage pool.

    Btrfs storage pools are created with the mkfs.btrfs command. Passing multiple devices to the mkfs.btrfs command creates a pool across all of those devices. Here you create a pool with a single device at /dev/xvdb.

    $ sudo mkfs.btrfs -f /dev/xvdb
    
    WARNING! - Btrfs v3.12 IS EXPERIMENTAL
    WARNING! - see http://btrfs.wiki.kernel.org before using
    
    Turning ON incompat feature 'extref': increased hardlink limit per file to 65536
    fs created label (null) on /dev/xvdb
        nodesize 16384 leafsize 16384 sectorsize 4096 size 4.00GiB
    Btrfs v3.12

    Be sure to substitute /dev/xvdb with the appropriate device(s) on your system.

    Warning: Take note of the warning about Btrfs being experimental. As noted earlier, Btrfs is not currently recommended for production deployments unless you already have extensive experience.

  3. If it does not already exist, create a directory for the Docker host’s local storage area at/var/lib/docker.

    $ sudo mkdir /var/lib/docker
  4. Configure the system to automatically mount the Btrfs filesystem each time the system boots.

    a. Obtain the Btrfs filesystem’s UUID.

    $ sudo blkid /dev/xvdb
    
    /dev/xvdb: UUID="a0ed851e-158b-4120-8416-c9b072c8cf47" UUID_SUB="c3927a64-4454-4eef-95c2-a7d44ac0cf27" TYPE="btrfs"

    b. Create an /etc/fstab entry to automatically mount /var/lib/docker each time the system boots. Either of the following lines will work, just remember to substitute the UUID value with the value obtained from the previous command.

    /dev/xvdb /var/lib/docker btrfs defaults 0 0
    UUID="a0ed851e-158b-4120-8416-c9b072c8cf47" /var/lib/docker btrfs defaults 0 0
  5. Mount the new filesystem and verify the operation.

    $ sudo mount -a
    
    $ mount
    
    /dev/xvda1 on / type ext4 (rw,discard)
    <output truncated>
    /dev/xvdb on /var/lib/docker type btrfs (rw)

    The last line in the output above shows the /dev/xvdb mounted at /var/lib/dockeras Btrfs.

Now that you have a Btrfs filesystem mounted at /var/lib/docker, the daemon should automatically load with the btrfs storage driver.

  1. Start the Docker daemon.

    $ sudo service docker start
    
    docker start/running, process 2315

    The procedure for starting the Docker daemon may differ depending on the Linux distribution you are using.

    You can force the Docker daemon to start with the btrfs storage driver by either passing the --storage-driver=btrfs flag to the docker daemon at startup, or adding it to the DOCKER_OPTS line to the Docker config file.

  2. Verify the storage driver with the docker info command.

    $ sudo docker info
    
    Containers: 0
    Images: 0
    Storage Driver: btrfs
    [...]

Your Docker host is now configured to use the btrfs storage driver.

相关文章
相关标签/搜索