Install Docker CE 17.03.2 on CentOS 6.6

在CentOS 6.6 內(nèi)核2.6 上裝Docker CE 17.03.2, 總算跑起來曙聂,主要有兩點(diǎn)

1.需要升級kernel到3.10鸡捐,如果需要overlay存儲方式需要升到kernel4.4版本
2.Docker 二進(jìn)制方式安裝
3.cAdvisor選擇v0.27.4版本


大體流程如下

0.check

uname -sr
Linux 2.6.32-504.el6.x86_64

cat /etc/issue
CentOS release 6.9 (Final)

wget https://raw.githubusercontent.com/moby/moby/master/contrib/check-config.sh
bash check-config.sh

modprobe nf_nat
modprobe iptable_nat

1. create docker group

sudo groupadd docker
sudo gpasswd -a root docker
sudo usermod -aG docker root
newgrp - docker

2. add cgroup into /etc/fstab

cat <<EOF >>/etc/fstab
none        /sys/fs/cgroup        cgroup        defaults    0    0
EOF

3. modify sysctl

cat <<EOF >>/etc/sysctl.conf
net.ipv4.ip_forward=1
net.ipv4.ip_local_port_range=32768 65535
EOF

sysctl -p

4. update kernel to 3.10 with aufs patch

install aufs patch to avoid cgroup device bus error and iptables related issue

wget http://www.hop5.in/yum/el6/kernel-ml-aufs-3.10.5-3.el6.x86_64.rpm
wget  http://www.hop5.in/yum/el6/kernel-ml-aufs-devel-3.10.5-3.el6.x86_64.rpm
rpm -ivh kernel-ml-aufs-3.10.5-3.el6.x86_64.rpm
rpm -ivh kernel-ml-aufs-devel-3.10.5-3.el6.x86_64.rpm

5. update kernel to 4.4

wget https://mirrors.tuna.tsinghua.edu.cn/elrepo/kernel/el6/x86_64/RPMS/kernel-lt-4.4.151-1.el6.elrepo.x86_64.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/elrepo/kernel/el6/x86_64/RPMS/kernel-lt-devel-4.4.151-1.el6.elrepo.x86_64.rpm
rpm -ivh kernel-lt-4.4.151-1.el6.elrepo.x86_64.rpm
rpm -ivh kernel-lt-devel-4.4.151-1.el6.elrepo.x86_64.rpm

or

wget https://mirrors.tuna.tsinghua.edu.cn/elrepo/kernel/el6/x86_64/RPMS/kernel-ml-4.18.4-1.el6.elrepo.x86_64.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/elrepo/kernel/el6/x86_64/RPMS/kernel-ml-devel-4.18.4-1.el6.elrepo.x86_64.rpm
rpm -ivh kernel-ml-4.18.4-1.el6.elrepo.x86_64.rpm
rpm -ivh kernel-ml-devel-4.18.4-1.el6.elrepo.x86_64.rpm

6. switch kernel to 4.4 and reboot

sed -i 's/^default=1/default=0/'  /etc/grub.conf

7. install Docker CE 17.03.2

wget https://mirrors.aliyun.com/docker-ce/linux/static/stable/x86_64/docker-17.03.2-ce.tgz
tar -zxvf docker-17.03.2-ce.tgz
mv -f docker/* /usr/bin

8. create docker daemon settting /etc/docker/daemon.json

mkdir -p /etc/docker
cat <<EOF >/etc/docker/daemon.json
{
    "hosts": [
        "tcp://0.0.0.0:2375",
        "unix:///var/run/docker.sock"
     ],
    "debug": true,
    "log-driver": "json-file",
    "log-level": "false",
    "experimental": true,
    "metrics-addr": "0.0.0.0:1337",
    "selinux-enabled": false,
    "registry-mirrors": [
        "https://registry.docker-cn.com",
        "http://f631e5c5.m.daocloud.io"
    ],
    "insecure-registries":[
        "gcr.io",
        "quay.io",
        "registry.cn-hangzhou.aliyuncs.com",
        "10.194.11.253",
        "10.194.11.253:5000",
        "registry.dev.crfchina.com:5000"
    ],
    "exec-opts": [
        "native.cgroupdriver=cgroupfs"
    ],
    "graph": "/localdisk/docker/graph",
    "storage-driver": "overlay2",
    "storage-opts": [ "overlay2.override_kernel_check=true" ],
    "live-restore": false
}

EOF

9.create service docker

/etc/init.d/docker or /etc/rc.d/init.d/docker

cat <<EOF >/etc/init.d/docker
#!/bin/sh
#
#       /etc/rc.d/init.d/docker
#
#       Daemon for docker.com
#
# chkconfig:   2345 95 95
# description: Daemon for docker.com

### BEGIN INIT INFO
# Provides:       docker
# Required-Start: $network cgconfig
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:  0 1 6
# Short-Description: start and stop docker
# Description: Daemon for docker.com
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

prog="dockerd"
exec="/usr/bin/$prog"
pidfile="/var/run/$prog.pid"
lockfile="/var/lock/subsys/$prog"
logfile="/var/log/$prog.log"

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
[ -e /etc/sysconfig/$prog-storage ] && . /etc/sysconfig/$prog-storage

prestart() {
    service cgconfig status > /dev/null

    if [[ $? != 0 ]]; then
        service cgconfig start
    fi

}

start() {
    if [ ! -x $exec ]; then
      if [ ! -e $exec ]; then
        echo "Docker executable $exec not found"
      else
        echo "You do not have permission to execute the Docker executable $exec"
      fi          
      exit 5
    fi

    check_for_cleanup

    if ! [ -f $pidfile ]; then
        prestart
        printf "Starting $prog:\t"
        echo "\n$(date)\n" >> $logfile
        $exec --pidfile=$pidfile &>> $logfile &
        pid=$!
        touch $lockfile
        # wait up to 10 seconds for the pidfile to exist.  see
        # https://github.com/docker/docker/issues/5359
        tries=0
        while [ ! -f $pidfile -a $tries -lt 10 ]; do
            sleep 1
            tries=$((tries + 1))
        done
        success
        echo
    else
        failure
        echo
        printf "$pidfile still exists...\n"
        exit 7
    fi
}

stop() {
    echo -n $"Stopping $prog: "
    killproc -p $pidfile -d 300 $prog
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    stop
    start
}

reload() {
    restart
}

force_reload() {
    restart
}

rh_status() {
    status -p $pidfile $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}


check_for_cleanup() {
    if [ -f ${pidfile} ]; then
        /bin/ps -fp $(cat ${pidfile}) > /dev/null || rm ${pidfile}
    fi
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        restart
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
        exit 2
esac

exit $?

EOF


10. start and enable docker service

chmod a+x /etc/init.d/docker
chkconfig --add /etc/init.d/docker
chkconfig docker on

service docker start 
service docker status

以下步驟不是必須

11. start cAdvisor container

docker run --restart=always --volume=/:/rootfs:ro --volume=/var/run:/var/run:rw --volume=/sys:/sys:ro --volume=/var/lib/docker/:/var/lib/docker:ro --publish=4033:8080 --detach=true --name=cadvisor google/cadvisor:v0.27.4

12. install Python 2.7.13 and docker-compose


yum install -y openssl openssl-devel
wget --no-check-certificate https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz
tar -zxvf Python-2.7.13.tgz
cd Python-2.7.13
./configure
make && make install


wget https://bootstrap.pypa.io/get-pip.py 
/usr/local/bin/python get-pip.py

pip install --upgrade pip -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host=mirrors.aliyun.com

pip install --upgrade docker-compose -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host=mirrors.aliyun.com

13. reference

http://www.cnblogs.com/cuizhipeng/p/4380653.html
http://seanlook.com/2014/10/26/docker-installed-centos6-successfully/

14.后續(xù)

依然會有cgroup的錯誤

[root@localhost Python-2.7.13]# /etc/init.d/cgconfig status
Stopped
[root@localhost Python-2.7.13]# /etc/init.d/cgconfig start
Starting cgconfig service: Error: cannot mount cpuset to /cgroup/cpuset: Device or resource busy
/sbin/cgconfigparser; error loading /etc/cgconfig.conf: Cgroup mounting failed
Failed to parse /etc/cgconfig.conf or /etc/cgconfig.d      [FAILED]
[root@localhost Python-2.7.13]# 

cgroup講解

https://wiki.archlinux.org/index.php/cgroups


mkdir -p /cgroup/cpuacct /cgroup/memory /cgroup/devices /cgroup/freezer net_cls /cgroup/blkio


cat /etc/cgconfig.conf |tail|grep "="|awk '{print "mount -t cgroup -o",$1,$1,$NF}' | bash



/etc/init.d/cgconfig restart



/etc/init.d/docker restart 


sudo cgcreate -g memory,cpu,blkio,cpuset:userlimited
cgconfigparser -l /etc/cgconfig.conf


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市户辫,隨后出現(xiàn)的幾起案子渐夸,更是在濱河造成了極大的恐慌,老刑警劉巖渔欢,帶你破解...
    沈念sama閱讀 219,427評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件墓塌,死亡現(xiàn)場離奇詭異,居然都是意外死亡膘茎,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,551評論 3 395
  • 文/潘曉璐 我一進(jìn)店門酷誓,熙熙樓的掌柜王于貴愁眉苦臉地迎上來披坏,“玉大人,你說我怎么就攤上這事盐数“舴鳎” “怎么了?”我有些...
    開封第一講書人閱讀 165,747評論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長帚屉。 經(jīng)常有香客問我谜诫,道長,這世上最難降的妖魔是什么攻旦? 我笑而不...
    開封第一講書人閱讀 58,939評論 1 295
  • 正文 為了忘掉前任喻旷,我火速辦了婚禮,結(jié)果婚禮上牢屋,老公的妹妹穿的比我還像新娘且预。我一直安慰自己,他們只是感情好烙无,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,955評論 6 392
  • 文/花漫 我一把揭開白布锋谐。 她就那樣靜靜地躺著,像睡著了一般截酷。 火紅的嫁衣襯著肌膚如雪涮拗。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,737評論 1 305
  • 那天迂苛,我揣著相機(jī)與錄音三热,去河邊找鬼。 笑死灾部,一個(gè)胖子當(dāng)著我的面吹牛康铭,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播赌髓,決...
    沈念sama閱讀 40,448評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼从藤,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了锁蠕?” 一聲冷哼從身側(cè)響起夷野,我...
    開封第一講書人閱讀 39,352評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎荣倾,沒想到半個(gè)月后悯搔,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,834評論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡舌仍,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,992評論 3 338
  • 正文 我和宋清朗相戀三年妒貌,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片铸豁。...
    茶點(diǎn)故事閱讀 40,133評論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡灌曙,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出节芥,到底是詐尸還是另有隱情在刺,我是刑警寧澤逆害,帶...
    沈念sama閱讀 35,815評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站蚣驼,受9級特大地震影響魄幕,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜颖杏,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,477評論 3 331
  • 文/蒙蒙 一纯陨、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧输玷,春花似錦队丝、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,022評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至赔嚎,卻和暖如春膘盖,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背尤误。 一陣腳步聲響...
    開封第一講書人閱讀 33,147評論 1 272
  • 我被黑心中介騙來泰國打工侠畔, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人损晤。 一個(gè)月前我還...
    沈念sama閱讀 48,398評論 3 373
  • 正文 我出身青樓软棺,卻偏偏與公主長得像,于是被迫代替她去往敵國和親尤勋。 傳聞我的和親對象是個(gè)殘疾皇子喘落,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,077評論 2 355

推薦閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,336評論 0 10
  • 誦不盡的少年志 “滔滔江河水,淹不盡浩浩中華魂最冰;巍巍昆侖山瘦棋,鎖不住陣陣中華風(fēng)∨冢”古今中外赌朋,膾炙人口的愛國詩詞...
    Summer_Shaw閱讀 5,335評論 3 5
  • 進(jìn)電梯回家,看見哥哥鞋帶開了篇裁,弟弟便蹲下給哥哥系鞋帶 哥哥小伙伴家長給哥哥一塊芝麻煎餅沛慢,哥哥給弟弟分。我說給弟弟大...
    英才居閱讀 209評論 0 0