内网低版本内核linux服务器要安装docker
1.离线安装docker
这一步没什么难度在网上找个安装包上传到服务器上按步骤安装
安装地址:Index of linux/static/stable/x86_64/
解压,然后将docker文件夹的内容复制到/usr/bin文件夹中便于平时启动
最后注册成系统服务
添加到service: vim /etc/systemd/system/docker.service
这里是基础配置,详细配置可使用指定配置文件来启动服务
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
上述文件取自于:
2.
启动docker的时候遇到错误
AUFS was not found in /proc/filesystem,或者Failed to built-in GetDriver graph devicemapper /var/lib/docker
FS,filesystem是linux所用的文件系统,低内核版本的linux一般使用的是overlay或者vfs和devicemapper。出现这种错误是因为启动docker时你的系统没有你所指定的文件系统类型。
解决方法为,在 /etc/docker/daemon.json里面指定"storage-driver"为你系统支持的fs
如果你的系统只有overlay的话可能又会遇到一个巨坑:
the backing xfs filesystem is formatted without d_type support
什么是d_type
d_type 是 Linux 内核的一个术语,表示 “目录条目类型”,而目录条目,其实是文件系统上目录信息的一个数据结构。d_type,就是这个数据结构的一个字段,这个字段用来表示文件的类型,是文件,还是管道,还是目录还是套接字等。
d_type 从 Linux 2.6 内核开始就已经支持了,只不过虽然 Linux 内核虽然支持,但有些文件系统实现了 d_type,而有些,没有实现,有些是选择性的实现,也就是需要用户自己用额外的参数来决定是否开启d_type的支持。
检查xfs文件系统是否支持d_type
[root@10-80-119-18 ~]# xfs_info /
meta-data=/dev/vda2 isize=256 agcount=9, agsize=2589248 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=20843184, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=5057, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
注意以上输出中的ftype字段,为0则表示不支持。
解决方案
- 指定docker的存储驱动类型为devicemapper,devicemapper不需要文件系统支持d_type,但docker官方目前推荐使用overlay2,因此不选择此方案。
- 重新格式化docker data-root目录所在的文件系统,xfs格式化时添加参数
ftype=1
,如下
mkfs.xfs -n ftype=1 /dev/mapper/vg_data-lv_data -f
改为devicemapper方法我的服务器不支持devicemapper所以不行,因为是上线的服务器
不可能格式化root目录,所以两个方法都行不通。
所幸的是我的服务器还支持vfs,在daemon.json里面指定了"storage-driver"为"vfs"之后启动便不报关于FS的错误了。
3. iptable和filewall的冲突
最后还遇到了Failed to program NAT chain: INVALID_ZONE: docker这个问题,大致应该是因为iptable和filewall冲突导致,如果想解决得修改防火墙。线上环境不好修改,所以得另外的想方法
我这里指定了关闭docker的iptable功能之后成功终于成功启动
关闭方法:在/etc/docker/daemon.json中添加 "iptables":false