#!/usr/bin/env bash
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
sudo yum-config-manager --enable docker-ce-edge
yum makecache fast
yum install docker-ce -y
加速方法1:
cat >> /etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["https://registry.docker-cn.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker && systemctl enable docker
cat >><<EOF
{
"registry-mirrors": ["https://registry.docker-cn.com"],
"hosts": [
"tcp://0.0.0.0:2375",
"unix:///var/run/docker.sock"
]
}
EOF
参考:https://blog.fundebug.com/2017/04/17/about-docker-sock/
docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer
这个可以管理镜像
有webshell
可以重启容器
k8s也用到sock功能: https://github.com/lannyMa/k8s-web-terminal
加速方法2:
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://50208f86.m.daocloud.io
systemctl daemon-reload
systemctl restart docker && systemctl enable docker
echo 'iptables -P FORWARD ACCEPT' >> /etc/rc.local
iptables -P FORWARD ACCEPT
## install docker-compose
cat >>pip.sh<<EOF
cd
yum install python-pip -y
mkdir ~/.pip
cat > pip.conf<<a
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
a
mv ./pip.conf ~/.pip/
pip install docker-compose
pip install --upgrade pip
EOF
#下载最新的 docker 二进制文件
$ wget https://get.docker.com/builds/Linux/x86_64/docker-17.04.0-ce.tgz
$ tar -xvf docker-17.04.0-ce.tgz
$ cp docker/docker* /root/local/bin
$ cp docker/completion/bash/docker /etc/bash_completion.d/
$
#创建 docker 的 systemd unit 文件
$ cat docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.io
[Service]
Environment="PATH=/root/local/bin:/bin:/sbin:/usr/bin:/usr/sbin"
EnvironmentFile=-/run/flannel/docker ## 这里比较关键
ExecStart=/root/local/bin/dockerd --log-level=error $DOCKER_NETWORK_OPTIONS
ExecReload=/bin/kill -s HUP $MAINPID
Restart=on-failure
RestartSec=5
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
Delegate=yes
KillMode=process
[Install]
WantedBy=multi-user.target
其他
17版本末日呢有warring.
[root@node1 docker]# docker info|grep Driver
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
Storage Driver: overlay
Logging Driver: json-file
Cgroup Driver: cgroupfs ## 17默认是这个,还有systemd
如果安装k8s的时候Cgroup 需要匹配,参考链接里说
kubelet的/etc/systemd/system/kubelet.service.d/10-kubeadm.conf
文件,其中包含如下内容:
Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=systemd"
参考:
http://blog.csdn.net/tycoon1988/article/details/40826235
k8s主张把以下选项置为1
http://blog.frognew.com/2017/07/kubeadm-install-kubernetes-1.7.html#1准备
# cat >> /etc/sysctl.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0
EOF
# sysctl -p /etc/sysctl.conf