[关闭]
@zhaikun 2017-07-14T14:56:25.000000Z 字数 7288 阅读 1436

docker仓库harbor搭建及docker安装优化

docker


1、优化

  1. #关闭防火墙
  2. [root@docker03 ~]# systemctl stop firewalld.service
  3. [root@docker03 ~]# systemctl disable firewalld.service
  4. #Yum缓存
  5. [root@docker02 ~]# vim /etc/yum.conf
  6. [main]
  7. cachedir=/var/cache/yum/$basearch/$releasever
  8. keepcache=1 修改为1
  9. debuglevel=2
  10. logfile=/var/log/yum.log
  11. exactarch=1
  12. obsoletes=1
  13. gpgcheck=1
  14. plugins=1
  15. installonly_limit=5
  16. bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
  17. distroverpkg=centos-release
  18. #关闭SELINUX
  19. [root@docker03 ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
  20. [root@docker03 ~]# setenforce 0

2、安装docker

  1. [root@docker03 ~]# yum install docker
  2. [root@docker03 ~]# systemctl enable docker.service
  3. [root@docker03 ~]# systemctl start docker.service

修改docker为direct-lvm

docker storage driver之devicemapper

1、基于Linux内核中的DeviceMapper框架实现,该框架实现了物理存储设备与虚拟存储设备的映射,或虚拟设备与虚拟设备之间的映射。这使得用户能够用该框架来实现磁盘的自由、动态的划分。LVM2,software RAIDs和dm-cryptdisk encryption等都是基于该框架的实现。更为重要的是,Device Mapper框架中提供两个功能,thin-provisioning和snapshot。
2、thin-provisioning,类似于虚拟内存,提供给使用者的空间只有在使用者进行写操作时才真正进行分配。假设使用者有一块100g的thin块设备,使用了20g,实际系统提供的大小就是20g,只有当使用者进行存储操作时才分配更多的空间,直到100g。
3、snapshot,快照,是一种COW策略的实现,假设从A设备做快照得到B设备时,并未对A进行完整拷贝,而是当对B设备进行写操作时,才将需要改变的那部分做属于B设备的拷贝。
4、devicemapper利用了该框架中的thin-provisioning和snapshot实现了镜像的分层结构和存储优化。在用devicemapper作为graphdriver的docker中,每个镜像和容器都对应一个设备,通过对镜像做snapshot操作得到容器,所以容器中拥有镜像的内容且操作这些内容不影响镜像本身,因为容器和镜像对应不同的设备。
5、devicemapper有两种模式可选,loop-lvm和direct-lvm。devicemapper的大致思路是,先通过虚拟化技术得到一个thin-pool设备(可理解成一个资源池),接着在thin-pool上建立一个基础设备,此后docker上所有镜像和容器都是基于此设备的snapshot。两个模式的区别就在与建立thin-pool的方法不同。

loop-lvm:

direct-lvm:

(利用了基于Device Mapper的LVM)

  1. [root@docker03 ~]# docker info
  2. Containers: 0
  3. Running: 0
  4. Paused: 0
  5. Stopped: 0
  6. Images: 0
  7. Server Version: 1.12.6
  8. Storage Driver: devicemapper
  9. Pool Name: docker-253:0-134322081-pool
  10. Pool Blocksize: 65.54 kB
  11. Base Device Size: 10.74 GB
  12. Backing Filesystem: xfs
  13. Data file: /dev/loop0 #docker info查看的为设备文件
  14. Metadata file: /dev/loop1 #docker info查看的为设备文件
  15. 1、创建硬盘 (增加的一块新的存储设备)
  16. [root@docker03 ~]# parted /dev/sdb
  17. GNU Parted 3.1
  18. Using /dev/sdb
  19. Welcome to GNU Parted! Type 'help' to view a list of commands.
  20. (parted) mklabel msdos
  21. (parted) mkpart primary 2048s 100%
  22. (parted) toggle 1 lvm
  23. (parted) quit
  24. 2、创建PV/VG
  25. [root@docker03 ~]# pvcreate /dev/sdb1
  26. Physical volume "/dev/sdb1" successfully created.
  27. [root@docker03 ~]# vgcreate vg_sxf /dev/sdb1
  28. Volume group "vg_sxf" successfully created
  29. 3、变更配置
  30. [root@docker03 ~]# vim /etc/sysconfig/docker-storage-setup
  31. # Edit this file to override any configuration options specified in
  32. # /usr/lib/docker-storage-setup/docker-storage-setup.
  33. #
  34. # For more details refer to "man docker-storage-setup"
  35. VG=vg_sxf
  36. DATA_SIZE=90%FREE
  37. [root@docker03 ~]# systemctl stop docker
  38. [root@docker03 ~]# rm -rf /var/lib/docker/
  39. [root@docker03 ~]# docker-storage-setup
  40. Using default stripesize 64.00 KiB.
  41. Rounding up size to full physical extent 104.00 MiB
  42. Logical volume "docker-pool" created.
  43. Logical volume vg_sxf/docker-pool changed.
  44. [root@docker03 ~]# systemctl start docker.service
  45. [root@docker03 ~]# docker info
  46. Containers: 0
  47. Running: 0
  48. Paused: 0
  49. Stopped: 0
  50. Images: 0
  51. Server Version: 1.12.6
  52. Storage Driver: devicemapper
  53. Pool Name: vg_sxf-docker--pool
  54. Pool Blocksize: 524.3 kB
  55. Base Device Size: 10.74 GB
  56. Backing Filesystem: xfs
  57. Data file:
  58. Metadata file:
  59. Data Space Used: 20.45 MB
  60. Data Space Total: 96.41 GB
  61. Data Space Available: 96.39 GB
  62. Metadata Space Used: 90.11 kB
  63. Metadata Space Total: 109.1 MB
  64. Metadata Space Available: 109 MB
  65. Thin Pool Minimum Free Space: 9.641 GB
  66. Udev Sync Supported: true

3、安装docker-compose

  1. [root@docker02 ~]# yum install epel-release
  2. [root@docker02 ~]# yum install epel-release
  3. [root@docker02 ~]# pip install docker-compose

4、安装harbor

  1. [root@docker02 ~]# mv harbor-offline-installer-0.5.0.tgz /opt/
  2. [root@docker02 opt]# tar zxvf harbor-offline-installer-0.5.0.tgz
  3. [root@docker02 harbor]# vim harbor.cfg
  4. ## Configuration file of Harbor
  5. #The IP address or hostname to access admin UI and registry service.
  6. #DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
  7. hostname = 172.16.138.101 修改hostname
  8. #The protocol for accessing the UI and token/notification service, by default it is http.
  9. #It can be set to https if ssl is enabled on nginx.
  10. ui_url_protocol = http
  11. #Email account settings for sending out password resetting emails.
  12. #Email server uses the given username and password to authenticate on TLS connections to host and act as identity.
  13. #Identity left blank to act as username.
  14. email_identity =
  15. email_server = smtp.mydomain.com

5、使用docker节点push 镜像到harbor

  1. #修改docker仓库地址
  2. [root@docker03 images]# vim /etc/sysconfig/docker
  3. ....
  4. # If you want to add your own registry to be used for docker search and docker
  5. # pull use the ADD_REGISTRY option to list a set of registries, each prepended
  6. # with --add-registry flag. The first registry added will be the first registry
  7. # searched.
  8. ADD_REGISTRY='--add-registry harbor.suixingpay.com'
  9. # If you want to block registries from being used, uncomment the BLOCK_REGISTRY
  10. # option and give it a set of registries, each prepended with --block-registry
  11. # flag. For example adding docker.io will stop users from downloading images
  12. # from docker.io
  13. # BLOCK_REGISTRY='--block-registry'
  14. # If you have a registry secured with https but do not have proper certs
  15. # distributed, you can tell docker to not look for full authorization by
  16. # adding the registry to the INSECURE_REGISTRY line and uncommenting it.
  17. INSECURE_REGISTRY='--insecure-registry harbor.suixingpay.com'
  18. # On an SELinux system, if you remove the --selinux-enabled option, you
  19. .....
  20. [root@docker03 images]# systemctl restart docker.service
  21. #登录harbor(密码:Harbor12345)
  22. [root@docker03 images]# docker login harbor.suixingpay.com
  23. Username: admin
  24. Password:
  25. Login Succeeded
  26. [root@docker03 images]#
  27. #导入镜像
  28. [root@docker03 images]# docker load -i heapster_grafana_v2.6.0-2.tar
  29. 78dbfa5b7cbc: Loading layer [==================================================>] 130.9 MB/130.9 MB
  30. 5f70bf18a086: Loading layer [==================================================>] 1.024 kB/1.024 kB
  31. 0828a6c7d921: Loading layer [==================================================>] 90.27 MB/90.27 MB
  32. 8683f0f614c9: Loading layer [==================================================>] 2.048 kB/2.048 kB
  33. a89b3190964f: Loading layer [==================================================>] 16.26 MB/16.26 MB
  34. ca627f7178ed: Loading layer [==================================================>] 110.1 kB/110.1 kB
  35. edec8b16494f: Loading layer [==================================================>] 4.096 kB/4.096 kB
  36. Loaded image ID: sha256:b4344393062633aad3f68fdee2ac195cfe9d618d6994ef3f3e03dba088a15fa8
  37. [root@docker03 images]#
  38. #给镜像打tag
  39. [root@docker03 images]# docker images
  40. REPOSITORY TAG IMAGE ID CREATED SIZE
  41. harbor.suixingpay.com/kube/dnsmasq-metrics-amd64 1.0 5271aabced07 8 months ago 14 MB
  42. <none> <none> b43443930626 16 months ago 230 MB
  43. [root@docker03 images]# docker tag b43443930626 harbor.suixingpay.com/kube/heapster_grafana:v2.6.0-2
  44. [root@docker03 images]# docker images
  45. REPOSITORY TAG IMAGE ID CREATED SIZE
  46. harbor.suixingpay.com/kube/dnsmasq-metrics-amd64 1.0 5271aabced07 8 months ago 14 MB
  47. harbor.suixingpay.com/kube/heapster_grafana v2.6.0-2 b43443930626 16 months ago 230 MB
  48. [root@docker03 images]#
  49. #导入镜像
  50. [root@docker03 images]# docker push harbor.suixingpay.com/kube/heapster_grafana:v2.6.0-2
  51. The push refers to a repository [harbor.suixingpay.com/kube/heapster_grafana]
  52. 5f70bf18a086: Mounted from kube/dnsmasq-metrics-amd64
  53. edec8b16494f: Pushed
  54. ca627f7178ed: Pushed
  55. a89b3190964f: Pushed
  56. 8683f0f614c9: Pushed
  57. 0828a6c7d921: Pushed
  58. 78dbfa5b7cbc: Pushed
  59. v2.6.0-2: digest: sha256:daea3fd319873e0f460b26885698a18c0dfcea404d0e03969aeaefeb35d4c278 size: 3018
  60. [root@docker03 images]#
  61. 其他的镜像以此类推
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注