docker安裝升級linux內核(2.6.32->3.10.81)


.內核升級環境准備

#查看已經安裝的和未安裝的軟件包組,來判斷我們是否安裝了相應的開發環境和開發庫; 
yum grouplist 
#一般是安裝這兩個軟件包組,這樣做會確定你擁有編譯時所需的一切工具 
yum groupinstall "Development Tools" 
#你必須這樣才能讓 make *config 這個指令正確地執行 
yum install ncurses-devel 
#如果你沒有 X 環境,這一條可以不用 
yum install qt-devel 
#創建 CentOS-6 內核時需要它們 
yum install hmaccalc zlib-devel binutils-devel elfutils-libelf-devel 

 

 

2.開始升級內核:

 cd /usr/src/linux-3.10.81
 #復制原內核配置 
 cp /boot/config-2.6.32-71.el6.x86_64 .config 
 vim .config
 /*將如下內容 追加入.config 並保存
    CONFIG_NF_NAT_IPV4=y
    CONFIG_IP_NF_TARGET_MASQUERADE=y
    CONFIG_NETFILTER_XT_MATCH_ADDRTYPE=y
    CONFIG_MEMCG_SWAP=y
    CONFIG_MEMCG_SWAP_ENABLED=y
    CONFIG_AUFS_FS=y
    CONFIG_DM_THIN_PROVISIONING=y
    CONFIG_OVERLAY_FS=y
    CONFIG_CGROUP_PERF=y
    CONFIG_CFS_BANDWIDTH=y
    HYPERVISOR_GUEST=y
    CONFIG_VMWARE_BALLOON=m
 */
 #編輯內核配置,開啟內核CGROUP支持
 make menuconfig
 #選擇General setup-->Control Group support->Memory Resource Controller for Control Groups選中
 #自動整理.config
 sh -c 'yes "" | make oldconfig'
 #編譯並安裝內核(j8代表8個線程同時編譯,請根據你的機器情況設置)
 make -j8 bzImage && make -j8 modules && make -j8 modules_install && make install
 vim /etc/grub.conf 
 修改default=0保存。即選擇從你新編譯的內核啟動linux。
 #重啟
 reboot 

 #注意:重新編譯內核請運行
 cd /usr/src/linux-3.10.81
 make mrproper
 make clean

 

3.安裝docker

#啟動后
uname -r
返回3.10.81表示內核安裝並啟動成功
#rehl的docker安裝說明https://docs.docker.com/installation/rhel/
#如下是安裝說明的簡化:
#a.下載docker的rpm
wget https://get.docker.com/rpm/1.7.0/centos-6/RPMS/x86_64/docker-engine-1.7.0-1.el6.x86_64.rpm
#本地安裝rpm包
 sudo yum localinstall --nogpgcheck docker-engine-1.7.0-1.el6.x86_64.rpm
#啟動docker服務
sudo service docker start 這里等價於docker -d 

#如果要追加參數請修改/etc/sysconfig/docker 這個文件 如:加入other_args=" -s vfs"
-s 是指定使用的文件系統,默認是devicemapper 也可以是vfs 或aufs(ubuntu的)
我的在這里使用默認的devicemapper沒有啟動成功。請看FAQ#
#運行docker的最簡鏡像
docker run hello-world

#docker image/ps/search/pull 等等正常就成功了
#登入容器
docker exec -ti 26723dc2509a /bin/bash

 

4.FAQ有兩個問題還沒有解決

ERRO[0000] [graphdriver] prior storage driver "devicemapper" failed: exit status 1
FATA[0000] Error starting daemon: error initializing graphdriver: exit status 1
出現上述錯誤有如下解決辦法!
*1. yum upgrade device-mapper-libs 再次啟動看是否可以
2. 使用另一種文件系統試一下如:docker -d -s vfs 默認是devicemapper系統 還可以使用aufs
3.#至此如果還是沒有啟動docker-daemon守護服務,那就用下面的方法把docker版本降低試下**並在/etc/yum.repos.d/hop5.repo中添加yum源內容*
[hop5]                                             
name=www.hop5.in Centos Repository                 
baseurl=http://www.hop5.in/yum/el6/                
gpgcheck=0                                         
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-HOP5    
保存並更新cache
yum makecache
安裝docker-io
yum install docker-io
再次運行
docker -d 
成功!
**上面第3步,啟動docker-daemon不成功,可能是我的線上機器是虛擬機的問題所以加上 -s vfs 就啟動成功了。**

##宿主機不能正常ping容器的ip
注意宿主(host)的iptables設置。

##ip netns “Object "netns" is unknown, try "ip help".\n'”報錯錯誤 請安裝如下包:
wget https://repos.fedorapeople.org/openstack/EOL/openstack-grizzly/epel-6/iproute-2.6.32-130.el6ost.netns.2.x86_64.rpm

 

5.安裝aufs文件系統

cd /etc/yum.repos.d 
wget http://www.hop5.in/yum/el6/hop5.repo 
yum install kernel-ml-aufs 
docker -d -s aufs #使用aufs文件系統啟動docker服務

快速安裝方法

sudo yum install -y http://vault.centos.org/6.6/os/x86_64/Packages/device-mapper-libs-1.02.90-2.el6.x86_64.rpm http://vault.centos.org/6.6/os/x86_64/Packages/device-mapper-1.02.90-2.el6.x86_64.rpm http://vault.centos.org/6.6/os/x86_64/Packages/device-mapper-event-1.02.90-2.el6.x86_64.rpm http://vault.centos.org/6.6/os/x86_64/Packages/device-mapper-event-libs-1.02.90-2.el6.x86_64.rpm https://dl.fedoraproject.org/pub/epel/testing/6/x86_64/docker-io-1.6.2-1.el6.x86_64.rpm

更多參考:http://dirlt.com/docker.html

示例: 
啟動容器 :docker run -d ubuntu /bin/sh -c “while true; do echo hello world; sleep 2; done” 
容器里執行:docker exec ubuntu /bin/sh -c “ls /;”

更簡單的升級內核方法,經測試成功!
這里通過yum快速升級CentOS 6.x內核到3.10:
# rpm -ivh http://www.elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm
# yum --enablerepo=elrepo-kernel install kernel-lt -y
在grub.conf中確認裝好的內核在哪個位置:
# vi /etc/grub.conf
default=0
重啟系統,后查看內核信息:
# uname -r
3.10.65-1.el6.elrepo.x86_64

 

檢查docker依賴環境的腳本check-config.sh

#!/usr/bin/env bash
set -e

# bits of this were adapted from lxc-checkconfig
# see also https://github.com/lxc/lxc/blob/lxc-1.0.2/src/lxc/lxc-checkconfig.in

possibleConfigs=(
    '/proc/config.gz'
    "/boot/config-$(uname -r)"
    "/usr/src/linux-$(uname -r)/.config"
    '/usr/src/linux/.config'
)

if [ $# -gt 0 ]; then
    CONFIG="$1"
else
    : ${CONFIG:="${possibleConfigs[0]}"}
fi

if ! command -v zgrep &> /dev/null; then
    zgrep() {
        zcat "$2" | grep "$1"
    }
fi

is_set() {
    zgrep "CONFIG_$1=[y|m]" "$CONFIG" > /dev/null
}

# see https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
declare -A colors=(
    [black]=30
    [red]=31
    [green]=32
    [yellow]=33
    [blue]=34
    [magenta]=35
    [cyan]=36
    [white]=37
)
color() {
    color=()
    if [ "$1" = 'bold' ]; then
        color+=( '1' )
        shift
    fi
    if [ $# -gt 0 ] && [ "${colors[$1]}" ]; then
        color+=( "${colors[$1]}" )
    fi
    local IFS=';'
    echo -en '\033['"${color[*]}"m
}
wrap_color() {
    text="$1"
    shift
    color "$@"
    echo -n "$text"
    color reset
    echo
}

wrap_good() {
    echo "$(wrap_color "$1" white): $(wrap_color "$2" green)"
}
wrap_bad() {
    echo "$(wrap_color "$1" bold): $(wrap_color "$2" bold red)"
}
wrap_warning() {
    wrap_color >&2 "$*" red
}

check_flag() {
    if is_set "$1"; then
        wrap_good "CONFIG_$1" 'enabled'
    else
        wrap_bad "CONFIG_$1" 'missing'
    fi
}

check_flags() {
    for flag in "$@"; do
        echo "- $(check_flag "$flag")"
    done
}

if [ ! -e "$CONFIG" ]; then
    wrap_warning "warning: $CONFIG does not exist, searching other paths for kernel config..."
    for tryConfig in "${possibleConfigs[@]}"; do
        if [ -e "$tryConfig" ]; then
            CONFIG="$tryConfig"
            break
        fi
    done
    if [ ! -e "$CONFIG" ]; then
        wrap_warning "error: cannot find kernel config"
        wrap_warning "  try running this script again, specifying the kernel config:"
        wrap_warning "    CONFIG=/path/to/kernel/.config $0 or $0 /path/to/kernel/.config"
        exit 1
    fi
fi

wrap_color "info: reading kernel config from $CONFIG ..." white
echo

echo 'Generally Necessary:'

echo -n '- '
cgroupSubsystemDir="$(awk '/[, ](cpu|cpuacct|cpuset|devices|freezer|memory)[, ]/ && $3 == "cgroup" { print $2 }' /proc/mounts | head -n1)"
cgroupDir="$(dirname "$cgroupSubsystemDir")"
if [ -d "$cgroupDir/cpu" -o -d "$cgroupDir/cpuacct" -o -d "$cgroupDir/cpuset" -o -d "$cgroupDir/devices" -o -d "$cgroupDir/freezer" -o -d "$cgroupDir/memory" ]; then
    echo "$(wrap_good 'cgroup hierarchy' 'properly mounted') [$cgroupDir]"
else
    if [ "$cgroupSubsystemDir" ]; then
        echo "$(wrap_bad 'cgroup hierarchy' 'single mountpoint!') [$cgroupSubsystemDir]"
    else
        echo "$(wrap_bad 'cgroup hierarchy' 'nonexistent??')"
    fi
    echo "    $(wrap_color '(see https://github.com/tianon/cgroupfs-mount)' yellow)"
fi

if [ "$(cat /sys/module/apparmor/parameters/enabled 2>/dev/null)" = 'Y' ]; then
    echo -n '- '
    if command -v apparmor_parser &> /dev/null; then
        echo "$(wrap_good 'apparmor' 'enabled and tools installed')"
    else
        echo "$(wrap_bad 'apparmor' 'enabled, but apparmor_parser missing')"
        echo -n '    '
        if command -v apt-get &> /dev/null; then
            echo "$(wrap_color '(use "apt-get install apparmor" to fix this)')"
        elif command -v yum &> /dev/null; then
            echo "$(wrap_color '(your best bet is "yum install apparmor-parser")')"
        else
            echo "$(wrap_color '(look for an "apparmor" package for your distribution)')"
        fi
    fi
fi

flags=(
    NAMESPACES {NET,PID,IPC,UTS}_NS
    DEVPTS_MULTIPLE_INSTANCES
    CGROUPS CGROUP_CPUACCT CGROUP_DEVICE CGROUP_FREEZER CGROUP_SCHED CPUSETS
    MACVLAN VETH BRIDGE
    NF_NAT_IPV4 IP_NF_FILTER IP_NF_TARGET_MASQUERADE
    NETFILTER_XT_MATCH_{ADDRTYPE,CONNTRACK}
    NF_NAT NF_NAT_NEEDED

    # required for bind-mounting /dev/mqueue into containers
    POSIX_MQUEUE
)
check_flags "${flags[@]}"
echo

echo 'Optional Features:'
{
    check_flags MEMCG_SWAP
    check_flags MEMCG_SWAP_ENABLED
    if  is_set MEMCG_SWAP && ! is_set MEMCG_SWAP_ENABLED; then
        echo "    $(wrap_color '(note that cgroup swap accounting is not enabled in your kernel config, you can enable it by setting boot option "swapaccount=1")' bold black)"
    fi
}
flags=(
    RESOURCE_COUNTERS
    CGROUP_PERF
    CFS_BANDWIDTH
)
check_flags "${flags[@]}"

echo '- Storage Drivers:'
{
    echo '- "'$(wrap_color 'aufs' blue)'":'
    check_flags AUFS_FS | sed 's/^/  /'
    if ! is_set AUFS_FS && grep -q aufs /proc/filesystems; then
        echo "    $(wrap_color '(note that some kernels include AUFS patches but not the AUFS_FS flag)' bold black)"
    fi
    check_flags EXT4_FS_POSIX_ACL EXT4_FS_SECURITY | sed 's/^/  /'

    echo '- "'$(wrap_color 'btrfs' blue)'":'
    check_flags BTRFS_FS | sed 's/^/  /'

    echo '- "'$(wrap_color 'devicemapper' blue)'":'
    check_flags BLK_DEV_DM DM_THIN_PROVISIONING EXT4_FS EXT4_FS_POSIX_ACL EXT4_FS_SECURITY | sed 's/^/  /'

    echo '- "'$(wrap_color 'overlay' blue)'":'
    check_flags OVERLAY_FS EXT4_FS_SECURITY EXT4_FS_POSIX_ACL | sed 's/^/  /'
} | sed 's/^/  /'
echo

#echo 'Potential Future Features:'
#check_flags USER_NS
#echo

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM