原文: https://sunkaiyuan.blog.csdn.net/article/details/126260261
安装Docker
# 配置阿里源
[root@master01 ~]# yum -y install wget
[root@master01 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# 做好备份,为了更新失败时切换回去
[root@master01 ~]#[root@centos7 /]# cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
# 清除缓存并生成新的缓存
[root@master01 ~]# yum clean all
[root@master01 ~]#[root@centos7 /]# yum makecache
1、关闭防火墙
[root@master01 ~]# systemctl stop firewalld && systemctl disable firewalld
2、关闭iptables防火墙
# 安装iptables
[root@master01 ~]# yum install iptables-services -y
# 禁用iptables
root@master01 ~]# service iptables stop && systemctl disable iptables
# 清空防火墙规则
[root@master01~]# iptables -F
3、关闭selinux
[root@master01 ~]# setenforce 0
[root@master01 ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
# 注意:修改selinux配置文件之后,重启机器,selinux才能永久生效
[root@master01 ~]# reboot
# 显示Disabled表示selinux关闭成功
[root@master01 ~]# getenforce
4、配置时间同步
[root@master01 ~]# yum install -y ntp ntpdate
[root@master01 ~]# ntpdate cn.pool.ntp.org
# 编写计划任务
[root@master01 ~]# crontab -e
* */1 * * * /usr/sbin/ntpdate cn.pool.ntp.org
# 重启crond服务使配置生效
[root@master01 ~]# systemctl restart crond
5、安装基础软件包
[root@master01 ~]# yum install -y wget net-tools nfs-utils lrzsz gcc gcc-c++ make cmake libxml2-devel openssl-devel curl curl-devel unzip sudo ntp libaio-devel wget vim ncurses-devel autoconf automake zlib-devel python-devel epel-release openssh-server socat ipvsadm conntrack
6、安装docker-ce
# 配置docker-ce国内yum源(阿里云)
[root@master01 ~]# yum -y install yum-utils
[root@master01 ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 安装docker依赖包
[root@master01 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
# 安装docker-ce
[root@master01 ~]# yum install docker-ce -y
# 启动docker服务
[root@master01 ~]# systemctl start docker && systemctl enable docker
[root@master01 ~]# systemctl status docker
#看到running,表示docker正常运行
# 查看Docker 版本信息
[root@master01 ~]# docker version
7、开启包转发功能和修改内核参数
内核参数修改:br_netfilter模块用于将桥接流量转发至iptables链,br_netfilter内核参数需要开启转发。
[root@master01 ~]# modprobe br_netfilter
[root@master01 ~]#
cat > /etc/sysctl.d/docker.conf <<EOF net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 net.ipv4.ip_forward = 1 EOF
# 使参数生效
[root@master01 ~]# sysctl -p /etc/sysctl.d/docker.conf
8、查看br_netfilter模块
[root@master01 ~]# lsmod |grep br_netfilter
9、如果系统没有br_netfilter模块则执行下面的新增命令,如有则忽略
# (1) 临时新增br_netfilter模块,该方式重启后会失效
[root@master01 ~]# modprobe br_netfilter
# 永久新增br_netfilter模块
[root@master01 ~]#
cat > /etc/rc.sysinit << EOF #!/bin/bash for file in /etc/sysconfig/modules/*.modules ; do [ -x $file ] && $file done EOF
# (2) 在/etc/sysconfig/modules/目录下新建文件 br_netfilter.modules
[root@master01 ~]#
cat > /etc/sysconfig/modules/br_netfilter.modules << EOF modprobe br_netfilter EOF
# 增加权限
[root@master01 ~]# chmod 755 /etc/sysconfig/modules/br_netfilter.modules
# 重启机器模块也会自动加载
[root@localhost ~]# lsmod |grep br_netfilter
br_netfilter 22209 0
bridge 136173 1 br_netfilter
10、重启docker
[root@master01 ~]# systemctl restart docker
11、配置docker镜像加速器
# 修改/etc/docker/daemon.json,变成如下
[root@master01 ~]# sudo mkdir -p /etc/docker
[root@master01 ~]#
sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors":[ "https://y8y6vosv.mirror.aliyuncs.com", "https://registry.docker-cn.com", "https://docker.mirrors.ustc.edu.cn", "https://dockerhub.azk8s.cn", "http://hub-mirror.c.163.com" ] } EOF
# 让配置文件生效
[root@master01 ~]# sudo systemctl daemon-reload
[root@master01 ~]# sudo systemctl restart docker
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-XOmYFcuN-1660095730169)(file:///C:/Users/ADMINI~1/AppData/Local/Temp/msohtmlclip1/01/clip_image004.jpg)]
安装docker-compose
1、官方镜像
[root@master01 ~]# curl -L https://github.com/docker/compose/releases/download/1.28.6/docker-compose-`uname -s `-`uname -m` > /usr/local/bin/docker-compose
[root@master01 ~]# chmod +x /usr/local/bin/docker-compose
[root@master01 ~]# docker-compose -v
2、国内安装docker-compose(国内高速镜像)
# (1) 下载命令
[root@master01 ~]# curl -L https://get.daocloud.io/docker/compose/releases/download/1.28.6/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
# (2) 修改权限
[root@master01 ~]# sudo chmod +x /usr/local/bin/docker-compose
# (3) 查看安装是否成功
[root@master01 ~]# docker-compose -v
标签:compose,安装,master01,yum,docker,root,netfilter
From: https://www.cnblogs.com/jiftle/p/17043459.html