.内核升级环境准备
#查看已经安装的和未安装的软件包组,来判断我们是否安装了相应的开发环境和开发库; 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". '”报错错误 请安装如下包: 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 '