关闭防火墙以及 selinux (必选)

  1. __set_config() {
  2. firewall-cmd --state
  3. systemctl stop firewalld.service
  4. systemctl disable firewalld.service
  5. setenforce 0
  6. sed -i 's,^SELINUX=.*$,SELINUX=disabled,' /etc/selinux/config
  7. }
  8. __set_config

优化内核参数 (可选)

  • 下面备用链接
    1. bash -c "$(curl -sS https://gitlab.biz.kuaicdn.cn/shell/centos/-/raw/main/kernel/kernel_init.sh)"
    1. # 备用链接
    2. #bash -c "$(curl -sS https://gitee.com/lwmacct/web-vscode-shell/raw/main/workspace/shell/centos/kernel/sysctl.sh)"

设置阿里云 CentOS 镜像源 (可选,建议设置)

  1. __set_mirrors() {
  2. curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
  3. curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
  4. sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
  5. yum clean all
  6. yum makecache fast
  7. yum install -y sudo
  8. }
  9. __set_mirrors

CentoOS7 系 安装 Docker (正文)

  1. __install_docker() {
  2. yum install -y yum-utils device-mapper-persistent-data lvm2
  3. yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  4. sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
  5. yum makecache fast
  6. yum -y install docker-ce
  7. usermod -aG docker root
  8. mkdir -p /etc/docker
  9. cat >/etc/docker/daemon.json <<EOF
  10. {
  11. "registry-mirrors": ["https://bn4ll166.mirror.aliyuncs.com"],
  12. "data-root": "/data/docker-root",
  13. "dns": ["223.5.5.5","119.29.29.29"],
  14. "bip": "172.31.255.254/16",
  15. "storage-driver": "overlay2",
  16. "storage-opts": ["overlay2.override_kernel_check=true"],
  17. "userland-proxy": false,
  18. "log-driver": "json-file",
  19. "log-opts": {"max-size": "100m","max-file": "1"},
  20. "exec-opts": ["native.cgroupdriver=systemd"],
  21. "live-restore": true
  22. }
  23. EOF
  24. systemctl daemon-reload
  25. systemctl enable docker
  26. systemctl restart docker
  27. }
  28. __install_docker

安装 docker-compose

使用 Docker 释放安装

  1. docker run --privileged --rm -v /usr/local/bin/:/dest registry.cn-hangzhou.aliyuncs.com/lwmacct/file:1657436749-docker-compose-v2.6.1
  1. docker run --privileged --rm -v /usr/local/bin/:/dest registry.cn-hangzhou.aliyuncs.com/lwmacct/file:1649397829-docker-compose-v2.4.1

从 Github 安装

网络好的话推荐从 github 安装 官方教程>>