Linux之CentOS 6 & 7编译和YUM安装docker

  • A+
所属分类:Docker  Linux  虚拟化/私有云
摘要

Docker 是一个开源项目,诞生于 2013 年初,最初是 dotCloud 公司内部的一个业余项目。它基于 Google 公司推出的 Go 语言实现。 项目后来加入了 Linux 基金会,遵从了 Apache 2.0 协议,项目代码在 GitHub 上进行维护。

Docker 自开源后受到广泛的关注和讨论,以至于 dotCloud 公司后来都改名为 Docker Inc。Redhat 已经在其 RHEL6.5 中集中支持 Docker;Google 也在其 PaaS 产品中广泛应用。

Docker 项目的目标是实现轻量级的操作系统虚拟化解决方案。 Docker 的基础是 Linux 容器(LXC)等技术。

在 LXC 的基础上 Docker 进行了进一步的封装,让用户不需要去关心容器的管理,使得操作更为简便。用户操作 Docker 的容器就像操作一个快速轻量级的虚拟机一样简单。

一、编译安装docker

1、升级内核到4.3

[root@Docaker-Node01 ~]# yum install -y make gcc gcc-c++ openssl openssl--devel ncurses ncurses-devel bc
[root@Docaker-Node01 ~]# wget http://mirrors.dwhd.org/Kernel/v4.x/linux-4.3.tar.xz
[root@Docaker-Node01 ~]# tar xf linux-4.3.tar.xz -C /usr/src/
[root@Docaker-Node01 ~]# cd /usr/src/linux-4.3/
[root@Docaker-Node01 /usr/src/linux-4.3]# cp /boot/config-`uname -r` .config
[root@Docaker-Node01 /usr/src/linux-4.3]# sh -c 'yes "" | make oldconfig'
# make menuconfig  ###自定义需要编译的选项
# scripts/kconfig/mconf Kconfig    ###自定义需要编译的选项
[root@Docaker-Node01 /usr/src/linux-4.3]# make -j `awk '/processor/{a++}END{print a}' /proc/cpuinfo` bzImage
[root@Docaker-Node01 /usr/src/linux-4.3]# make -j `awk '/processor/{a++}END{print a}' /proc/cpuinfo` modules
[root@Docaker-Node01 /usr/src/linux-4.3]# make -j `awk '/processor/{a++}END{print a}' /proc/cpuinfo` modules_install
[root@Docaker-Node01 /usr/src/linux-4.3]# make install
# make mrproper  ###编译出错重新编译需要做清除处理
[root@Docaker-Node01 /usr/src/linux-4.3]# sed -ri 's/(default=).*/\10/' /boot/grub/grub.conf
[root@Docaker-Node01 /usr/src/linux-4.3]# reboot
[root@Docaker-Node01 ~]# uname -a
Linux Docaker-Node01.dwhd.org 4.3.0 #1 SMP Wed Nov 11 02:31:25 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[root@Docaker-Node01 ~]#

2、关闭SELinux

[root@Docaker-Node01 ~]# sed -ri 's/^#?((\s+)?SELINUX(TYPE)?.*)/#\1/;$a SELINUX=disabled\nSELINUXTYPE=targeted' /etc/sysconfig/selinux
[root@Docaker-Node01 ~]# /usr/sbin/setenforce 0
[root@Docaker-Node01 ~]#

3、编译高版本git

[root@Docaker-Node01 ~]# yum -y remove git
[root@Docaker-Node01 ~]# yum -y install zlib-devel perl-CPAN gettext curl-devel expat-devel gettext-devel openssl-devel
[root@Docaker-Node01 ~]# wget http://mirrors.dwhd.org/Git/git-2.6.3.tar.xz
[root@Docaker-Node01 ~]# tar xf git-2.6.3.tar.xz 
[root@Docaker-Node01 ~]# cd git-2.6.3
[root@Docaker-Node01 ~/git-2.6.3]# ./configure --prefix=/usr/local
[root@Docaker-Node01 ~/git-2.6.3]# make -j $(awk '/processor/{i++}END{print i}' /proc/cpuinfo) && make install && cd ..
[root@Docaker-Node01 ~]# echo "PATH=/usr/local/bin:\$PATH" >/etc/profile.d/git.sh
[root@Docaker-Node01 ~]# . /etc/profile.d/git.sh
[root@Docaker-Node01 ~]# which git
/usr/local/bin/git
[root@Docaker-Node01 ~]# git --version
git version 2.6.3
[root@Docaker-Node01 ~]#

4、检测iptables版本 xz版本和ps命令,iptables≥1.4,xz≥4.9

[root@Docaker-Node01 ~]# which ps
/bin/ps
[root@Docaker-Node01 ~]# iptables -V
iptables v1.4.7
[root@Docaker-Node01 ~]# xz -V
xz (XZ Utils) 4.999.9beta
liblzma 4.999.9beta
[root@Docaker-Node01 ~]#

5、安装cgroup

[root@Docaker-Node01 ~]# yum install -y libcgroup libcgroup-devel libcgroup-pam

6、安装go

[root@Docaker-Node01 ~]# wget https://storage.googleapis.com/golang/go1.5.linux-amd64.tar.gz
[root@Docaker-Node01 ~]# tar xf go1.5.linux-amd64.tar.gz -C /usr/local/
[root@Docaker-Node01 ~]# echo "export GOROOT=/usr/local/go
export PATH=\$PATH:\$GOROOT/bin
export GOPATH=/home/go" >/etc/profile.d/go.sh
[root@Docaker-Node01 ~]# . /etc/profile.d/go.sh
[root@Docaker-Node01 ~]# which go
/usr/local/go/bin/go
[root@Docaker-Node01 ~]# go version
go version go1.5 linux/amd64
[root@Docaker-Node01 ~]#

二、YUM安装docker在CentOS6、7系统上

1、CentOS6

2、CentOS7

[root@docker-node1 ~]# yum clean all
[root@docker-node1 ~]# cat >/etc/yum.repos.d/docker.repo <<-EOF
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF
[root@docker-node1 ~]# yum makecache
[root@docker-node1 ~]# yum install -y docker-engine
[root@docker-node1 ~]# systemctl start docker.service
[root@docker-node1 ~]# systemctl enable docker.service 
ln -s '/usr/lib/systemd/system/docker.service' '/etc/systemd/system/multi-user.target.wants/docker.service'
[root@docker-node1 ~]# systemctl status docker.service 
docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled)
   Active: active (running) since 六 2015-11-14 18:23:00 UTC; 27s ago
     Docs: https://docs.docker.com
 Main PID: 1429 (docker)
   CGroup: /system.slice/docker.service
           └─1429 /usr/bin/docker daemon -H fd://

11月 14 18:22:34 docker-node1 systemd[1]: Starting Docker Application Container Engine...
11月 14 18:22:34 docker-node1 docker[1429]: time="2015-11-14T18:22:34.591696381Z" level=info msg="API listen on /var/run/docker.sock"
11月 14 18:22:34 docker-node1 docker[1429]: time="2015-11-14T18:22:34.757829859Z" level=warning msg="Usage of loopback devices is strongly dis...ection."
11月 14 18:23:00 docker-node1 docker[1429]: time="2015-11-14T18:23:00.180124034Z" level=info msg="Firewalld running: true"
11月 14 18:23:00 docker-node1 docker[1429]: time="2015-11-14T18:23:00.276031450Z" level=info msg="Default bridge (docker0) is assigned with an...address"
11月 14 18:23:00 docker-node1 docker[1429]: time="2015-11-14T18:23:00.414386410Z" level=info msg="Loading containers: start."
11月 14 18:23:00 docker-node1 docker[1429]: time="2015-11-14T18:23:00.414649813Z" level=info msg="Loading containers: done."
11月 14 18:23:00 docker-node1 docker[1429]: time="2015-11-14T18:23:00.414665485Z" level=info msg="Daemon has completed initialization"
11月 14 18:23:00 docker-node1 docker[1429]: time="2015-11-14T18:23:00.414678216Z" level=info msg="Docker daemon" commit=76d6bc9 execdriver=nat...on=1.9.0
11月 14 18:23:00 docker-node1 systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
[root@docker-node1 ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b901d36b6f2f: Pull complete 
0a6ba66e537a: Pull complete 
Digest: sha256:8be990ef2aeb16dbcb9271ddfe2610fa6658d13f6dfb8bc72074cc1ca36966a7
Status: Downloaded newer image for hello-world:latest

Hello from Docker.
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker Hub account:
 https://hub.docker.com

For more examples and ideas, visit:
 https://docs.docker.com/userguide/
lookback

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: