Chinaunix首页 | 论坛 | 博客

OPS

  • 博客访问: 508246
  • 博文数量: 117
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1210
  • 用 户 组: 普通用户
  • 注册时间: 2015-05-05 14:50
个人简介

hellow 运维

文章分类

全部博文(117)

文章存档

2019年(1)

2018年(1)

2017年(45)

2016年(38)

2015年(32)

我的朋友

分类: 系统运维

2016-06-04 09:43:47

1:配置epel源和安装docker及其管理

[root@slave-drbd ~]# #yum install lxc libcgroup -y
[root@slave-drbd ~]# #yum install -y docker-io
[root@slave-drbd ~]# #yum install -y lxc libcgroup docker-io bridge-utils

2:启动并查看docker版本信息和info信息

 [root@slave-drbd ~]# #/etc/init.d/docker start 

[root@slave-drbd ~]# #/etc/init.d/docker start 
[root@slave-drbd ~]# docker version
Client version: 1.7.1
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 786b29d/1.7.1
OS/Arch (client): linux/amd64
Server version: 1.7.1
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): 786b29d/1.7.1
OS/Arch (server): linux/amd64
[root@slave-drbd ~]# docker info
Containers: 4
Images: 107
Storage Driver: devicemapper
 Pool Name: docker-253:0-2758853-pool
 Pool Blocksize: 65.54 kB
 Backing Filesystem: extfs
 Data file: /dev/loop0
 Metadata file: /dev/loop1
 Data Space Used: 5.393 GB
 Data Space Total: 107.4 GB
 Data Space Available: 21.62 GB
 Metadata Space Used: 6.914 MB
 Metadata Space Total: 2.147 GB
 Metadata Space Available: 2.141 GB
 Udev Sync Supported: true
 Deferred Removal Enabled: false
 Data loop file: /var/lib/docker/devicemapper/devicemapper/data
 Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
 Library Version: 1.02.95-RHEL6 (2015-07-29)
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 2.6.32-573.7.1.el6.x86_64
Operating System:
CPUs: 2
Total Memory: 981.2 MiB
Name: slave-drbd
ID: JLFK:CHWJ:YH77:R3X7:Y56N:4BBR:SZDY:32EI:JRJ2:TKNK:EXMM:SLCC

3:手动配置docker的独立ip地址
需要安装pipework和iproute(2.6.32版本之上的)

pipework的安装
  [root@slave-drbd ~]# git clone
 [root@slave-drbd ~]# unzip pipework-master.zip 
  [root@slave-drbd ~]#  cd pipework-master
 [root@slave-drbd ~]#  cp pipework /usr/local/bin/
iproute的安装

yum install -y 

 yum install kernel iproute

 reboot


4:docker的一些命令集合

  docker search nginx :查找nginx容器
  docker images   :已经安装的容器
  docker pull nginx : 获取nginx镜像到本地
  docker ps :最后一次运行的docker容器
  docker ps -l :获取最后一次启动镜像的id
  docker run centos:laster echo “hellow‘:启动centos镜像运行echo语句
  docker run centos:laster  yum install -y ntpdate :在镜像中安装软件
  docker export id > centso.tar        :镜像的导出
 cat centso.tar | docker import centos6:镜像的导入
docker run -itd --net=none --name=hanye doumadou/centos6.5_x86_64-base /bin/bash 
  -i:交互式模式
 -t:新打开一个端口
 -d:demo 
 --name:镜像名字
 --net:自动获取ip地址

5:基于br0的分配docker容器ip地址

    yum install -y lxc libcgroup docker-io bridge-utils    
   配置docker默认的支持bridge
    [root@slave-drbd network-scripts]# cat /etc/sysconfig/docker
other_args="-b=br0"
DOCKER_CERT_PATH=/etc/docker
DOCKER_NOWARN_KERNEL_VERSION=1
A:删除docker0;配置桥接网络
 ifconfig  docker0 down
 brctl delbr docker0
B:设置br0和eth0从br0上获取ip地址
  [root@slave-drbd network-scripts]# cat ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
TYPE=Ethernet
ONBOOT=yes
BRIDGE=br0
BOOTPROTO=static
#HWADDR=00:0c:29:40:73:1a
#NM_CONTROLLED=yes
#UUID=07de5298-6a2d-45d0-8390-a412839dbff6
#IPADDR=192.168.0.171
#NETMASK=255.255.255.0
#DNS2=202.102.227.68
#GATEWAY=192.168.0.254
#DNS1=202.102.224.68
#IPV6INIT=no
#USERCTL=no
[root@slave-drbd network-scripts]# cat ifcfg-br0
DEVICE=br0
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
TYPE=Bridge
IPADDR=192.168.0.171
NETMASK=255.255.255.0
DNS2=202.102.227.68
GATEWAY=192.168.0.254
DNS1=202.102.224.68
#IPV6INIT=no
#USERCTL=no
C:重启network|docker服务
  [root@slave-drbd network-scripts]# /etc/init.d/network restart
  [root@slave-drbd network-scripts]# /etc/init.d/docker restart
D:启动一个容器测试一下并进去测试一下
  [root@slave-drbd network-scripts]#  docker  run -d -t -i doumadou/centos6.5_x86_64-base /bin/bash
  [root@slave-drbd network-scripts]# docker  ps
CONTAINER ID        IMAGE                            COMMAND             CREATED             STATUS              PORTS               NAMES
fe1855fa4ced        doumadou/centos6.5_x86_64-base   "/bin/bash"         7 seconds ago       Up 4 seconds                            agitated_brown
[root@slave-drbd network-scripts]# docker attach fe1855fa4ced

6:使用pipework给镜像分配ip地址

  pipework  br0  agitated_brown  192.168.0.171/24@192.168.0.170
给镜像 agitated_brown分配地址为192.168.0.171发送数据接收数据依赖于0.170

7:在镜像中查看ip地址

[root@slave-drbd ~]# docker  run -itd --net=none --name=test01 hasedon/centos6.5   /bin/bash
ff24dd6a20391324dd2185dfe7fd17c4573b40ee0493e64a8585df6d4e4e18ce
[root@slave-drbd ~]# 
[root@slave-drbd ~]# 
[root@slave-drbd ~]# 
[root@slave-drbd ~]# docker  ps -l
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
ff24dd6a2039        hasedon/centos6.5   "/bin/bash"         3 seconds ago       Up 2 seconds                            test01              
[root@slave-drbd ~]# docker  ps -a
CONTAINER ID        IMAGE                            COMMAND             CREATED             STATUS                      PORTS               NAMES
ff24dd6a2039        hasedon/centos6.5                "/bin/bash"         6 seconds ago       Up 4 seconds                                    test01                 
f6693b9ba4f4        hasedon/centos6.5                "/bin/bas"          27 seconds ago                                                      hanye131               
00b9582cffeb        hasedon/centos6.5                "/bin/bash"         56 minutes ago      Up 56 minutes                                   suspicious_jones       
6d3a17481857        doumadou/centos6.5_x86_64-base   "/bin/bash"         11 hours ago        Exited (130) 5 hours ago                        dreamy_archimedes      
fe1855fa4ced        doumadou/centos6.5_x86_64-base   "/bin/bash"         11 hours ago        Exited (0) 11 hours ago                         agitated_brown         
92e569475db7        doumadou/centos6.5_x86_64-base   "/bin/bash"         11 hours ago        Exited (127) 11 hours ago                       nostalgic_mcclintock   
[root@slave-drbd ~]# pipework  br0 test01 192.168.1.170/24@192.168.0.170
[root@slave-drbd ~]# pipework  br0 hanye131 192.168.1.171/24@192.168.0.170
Docker inspect returned invalid PID 0
[root@slave-drbd ~]# pipework  br0 hanye131 192.168.1.177/24@192.168.0.170
Docker inspect returned invalid PID 0
[root@slave-drbd ~]# 
[root@slave-drbd ~]# docker ps 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
ff24dd6a2039        hasedon/centos6.5   "/bin/bash"         2 minutes ago       Up 2 minutes                            test01              
00b9582cffeb        hasedon/centos6.5   "/bin/bash"         59 minutes ago      Up 59 minutes                           suspicious_jones    
[root@slave-drbd ~]# docker  attach test01


bash-4.1# 
bash-4.1# 
bash-4.1# 
bash-4.1# 
bash-4.1# ifconfig 
eth1      Link encap:Ethernet  HWaddr 2E:B9:EC:6B:70:83  
          inet addr:192.168.1.170  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::2cb9:ecff:fe6b:7083/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:26676 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1659943 (1.5 MiB)  TX bytes:510 (510.0 b)


lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
阅读(2017) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~