1 系统配置

SELinux 关闭

sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

关闭防火墙

systemctl stop firewalld.service && systemctl disable firewalld.service

修改系统语言环境

sudo echo 'LANG="en_US.UTF-8"' >> /etc/profile;source /etc/profile

关闭swap分区

swapoff   -a

vim /etc/fstab
#注释掉SWAP分区项,即可

 swap was on /dev/sda11 during installation
#UUID=0a55fdb5-a9d8-4215-80f7-f42f75644f69 none  swap    sw      0       0

#刷新swap使之生效
sysctl -p

Kernel性能调优

cat >> /etc/sysctl.conf<<EOF
net.ipv4.ip_forward=1
net.bridge.bridge-nf-call-iptables=1
net.ipv4.neigh.default.gc_thresh1=4096
net.ipv4.neigh.default.gc_thresh2=6144
net.ipv4.neigh.default.gc_thresh3=8192
EOF

2 Docker-ce安装

  1. 卸载旧版本Docker软件
sudo yum remove docker \
              docker-client \
              docker-client-latest \
              docker-common \
              docker-latest \
              docker-latest-logrotate \
              docker-logrotate \
              docker-selinux \
              docker-engine-selinux \
              docker-engine \
              container*
  1. 定义安装版本
export docker_version=18.06.3

step 1: 安装必要的一些系统工具

sudo yum update -y;
sudo yum install -y yum-utils device-mapper-persistent-data \
    lvm2 bash-completion;

Step 2: 添加软件源信息

sudo yum-config-manager --add-repo \
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo;

Step 3: 更新并安装 Docker-CE

sudo yum makecache all;
version=$(yum list docker-ce.x86_64 --showduplicates | sort -r|grep ${docker_version}|awk '{print $2}');
sudo yum -y install --setopt=obsoletes=0 docker-ce-${version} docker-ce-selinux-${version};

如果已经安装高版本Docker,可进行降级安装(可选)

yum downgrade --setopt=obsoletes=0 -y docker-ce-${version} docker-ce-selinux-${version};

把当前用户加入docker组

sudo usermod -aG docker $NEW_USER;

设置开机启动

sudo systemctl enable docker;

3 综合配置

cat > /etc/docker/daemon.json <<EOF
{
    "oom-score-adjust": -1000,
    "log-driver": "json-file",
    "log-opts": {
    "max-size": "100m",
    "max-file": "3"
    },
    "max-concurrent-downloads": 10,
    "max-concurrent-uploads": 10,
    "bip": "169.254.123.1/24",
    "registry-mirrors": ["https://7bezldxe.mirror.aliyuncs.com"],
    "storage-driver": "overlay2",
    "storage-opts": [
    "overlay2.override_kernel_check=true"
    ]
    "insecure-registries": ["10.20.23.139:5000"]
}
EOF
systemctl daemon-reload && systemctl restart docker

docker 代理设置

    mkdir -p /etc/systemd/system/docker.service.d
    vi /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://10.20.7.7:3128" "HTTPS_PROXY=https://10.20.7.7:3128" "NO_PROXY=localhost,127.0.0.1,10.20.23.139"

配置镜像加速地址 编辑/etc/docker/daemon.json

{
"registry-mirrors": ["https://7bezldxe.mirror.aliyuncs.com/"]
}

配置insecure-registries 编辑/etc/docker/daemon.json

{ "insecure-registries": ["10.20.23.139:5000"] }

配置Docker存储驱动 编辑/etc/docker/daemon.json

{
"storage-driver": "overlay2",
"storage-opts": ["overlay2.override_kernel_check=true"]
}

配置日志驱动 编辑/etc/docker/daemon.json

{
"log-driver": "json-file",
"log-opts": {
    "max-size": "100m",
    "max-file": "3"
    }
}
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐