升级linux内核(2.6.32->3.10.81),安装docker

1.内核升级环境准备


#查看已经安装的和未安装的软件包组,来判断我们是否安装了相应的开发环境和开发库;
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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

检查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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
 
 

版权声明:本文为博主原创文章,未经博主允许不得转载。

上一篇:JavaScript之二:this


下一篇:Android ListView 自定义 Adapter