centos6 安装 docker17.06 with 升级内核2.6到4.4

由于centos6默认更新的docker版本为1.7.1, 不支持mount参数。所以需要升级docker到较新的版本。

从参考1,docker的官方文档中看到,要想使用mount需要docker17.06及以上版本。

参照参考2,进行docker18.06的安装;

步骤如下:

1.  导入GPG密钥
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
如果遇到 网络问题,执行如下命令:
yum -y update nss

2. 安装ELRepo
rpm -Uvh http://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm

3. 安装新内核
yum --enablerepo=elrepo-kernel install kernel-lt -y

4. 修改grub引导文件
vi /etc/grub.conf
将default=1修改为default=0
确保默认启动新的内核。一般新安装的内核会在第一个位置(从0开始),所以设置default=0
修改完成后重启电脑。
执行 uname-r
出现如下结果表示内核升级成功
4.4.163-1.el6.elrepo.x86_64


5. 安装docker
卸载原有的docker
yum remove docker-io
rm -rf /var/lib/docker

curl -O http://mirrors.ustc.edu.cn/docker-ce/linux/static/stable/x86_64/docker-17.06.2-ce.tgz
tar -xzvf docker-17.06.2-ce.tgz && cp docker/* /usr/bin && rm -rf docker
mkdir -p /etc/docker 
echo "{\"registry-mirrors\": [\"https://docker.mirrors.ustc.edu.cn\"]}" > /etc/docker/daemon.json

配置docker 服务:

#!/bin/sh
#set -x
BASE_HOME=/var/run
PID_FILE=$BASE_HOME/docker.pid

# dockerd父进程的id,如果docker.pid文件不存在则PID值就为-1
PID=-1
if [ -f $PID_FILE ];then
  PID=`cat $PID_FILE`
fi


status(){
    if [ $PID -gt -1 ]; then
       echo "dockerd is running"        
    else
       echo "dockerd is not running"        
    fi
}

start() {
    if [ $PID -gt -1 ]; then
       echo "dockerd has started,the pid is $PID"
       return
    fi
    nohup dockerd > /var/log/dockerd.log 2>&1 &
    COUNT=0
    NUMBER=0
    echo -e "starting...\c"
    while [ $COUNT -lt 2 ]; do
      echo -e ".\c"
      sleep 0.25
      if [ -f $PID_FILE ];then
         PID=`cat $PID_FILE`
      fi
      COUNT=`ps -ef |grep $PID|grep -v grep|wc -l`
      # dockerd父进程与docker-containerd子进程都启动
      if [ $COUNT -ge 2 ]; then
         echo -e "\ndockerd has started,the pid is $PID"
         return
      fi
      if [ $NUMBER -gt 20 ]; then
         break
      fi
      NUMBER=$NUMBER+1
    done
    
    echo -e "\ndockerd start failed"        
}

stop() {
   if [ $PID -eq -1 ]; then
    echo "dockerd is not running"
    return
   fi
   
   # PIDS得到的是dockerd父进程及docker-containerd子进程号
   # sort -r是为了先杀子进程,再杀父进程
   PIDS=`ps -ef|grep $PID|grep -v grep|awk '{print $2}'|sort -r`

   for VAR_PID in $PIDS ; do
      kill $VAR_PID > /dev/null 2>&1
   done
   
   # 因为有dockerd父进程和docker-containerd子进程,因此预先设置COUNT=2
   COUNT=2
   echo -e "stoping...\c"
   while [ $COUNT -gt 0 ]; do
      echo -e ".\c"
      sleep 0.05
      COUNT=`ps -ef |grep $PID |grep -v grep |wc -l`
      if [ $COUNT -eq 0 ]; then
        echo -e "\ndockerd has been stoped"
        break
      fi
   done
   # restart的时候会存在无法启动dockerd进程的问题。(因为PID值还是原先停掉的dockerd进程id)
   PID=-1
}

restart() {
   stop
   start
}

case "$1" in
    'start')
        start
        ;;
    'stop')
        stop
        ;;
    'status')
        status
        ;;
    'restart')
        restart
        ;;
    *)
    echo "usage: $0 {start|stop|restart|status}"
    exit 1
    ;;
esac

 启动docker 服务,查看docker 信息

service docker start

解决启动时的几个问题:

1. level=warning msg="Could not get operating system name: Error opening /usr/lib/os-release: open /usr/lib/os-release: no such file or directory" 

echo "CentOS release 6.x (Final)" | tee /usr/lib/os-release

 2. warning msg="could not change group /var/run/docker.sock to docker: group docker not found"

groupadd docker

3.kernal相关的问题:

服务启动的warning
warning msg="containerd: low RLIMIT_NOFILE changing to max" current=1024 max=4096
warning msg="Your kernel does not support kernel memory limit"
warning msg="mountpoint for pids not found"

docker info的warning
WARNING: No kernel memory limit support
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled

  待定位。

 

参考:

1. mount 要求的docker版本:https://docs.docker.com/storage/bind-mounts/

2. http://jaychang.cn/2018/05/24/CentOS6-x%E5%86%85%E6%A0%B8%E5%8D%87%E7%BA%A7-%E5%AE%89%E8%A3%85docker17-06-2-ce/

你可能感兴趣的:(basetool)