拥抱 K8S 系列 -01-CentOS7 安装 docker
发布于: 2020 年 09 月 03 日
1、先查看系统和内核版本
cat /etc/redhat-release CentOS Linux release 7.7.1908 (Core)uname -r3.10.0-1062.el7.x86_64# 说明:内核版本必须3.10+
2、系统初始化
【关闭selinux和firewalld】setenforce 0sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/configsystemctl stop firewalld.service && systemctl disable firewalld.service && systemctl mask firewalld.service【启用iptables】yum install iptables iptables-services -ysystemctl enable --now iptables#容器云K8S依赖iptables服务【主机时间,时区,系统语言】#For centos-7yum install -y ntpdatecat >>/var/spool/cron/root<<-'EOF'*/30 * * * * /sbin/ntpdate pool.ntp.org &> /tmp/timeEOFsystemctl reload crond.serviceln -snvf /usr/share/zoneinfo/Asia/Shanghai /etc/localtimeecho 'export LANG="en_US.UTF-8"' > /etc/profile.d/lang.sh. /etc/profile.d/lang.sh【内核/性能调优-limit】cat >/etc/security/limits.d/limit-prd.conf<<-EOF* hard nofile 1024000* soft nofile 1024000* hard nproc 102400* soft nproc 102400* soft memlock unlimited* hard memlock unlimitedEOF【内核/性能调优-sysctl】sed -i 's/^[^#]/#&/g' /etc/sysctl.confcat >/etc/sysctl.d/sysctl-prd.conf<<-'EOF'net.ipv4.ip_local_port_range = 1024 65000net.ipv4.tcp_rmem = 4096 87380 4194304net.ipv4.tcp_wmem = 4096 16384 4194304net.ipv4.tcp_mem = 94500000 915000000 927000000net.ipv4.tcp_synack_retries = 2net.ipv4.tcp_syn_retries = 2net.ipv4.tcp_max_syn_backlog = 262144net.ipv4.tcp_syncookies = 1net.ipv4.tcp_max_tw_buckets = 6144net.ipv4.tcp_tw_recycle = 1net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_fin_timeout = 15net.ipv4.tcp_keepalive_time = 600net.ipv4.tcp_sack = 1net.ipv4.tcp_window_scaling = 1net.ipv4.tcp_max_orphans = 3276800net.ipv4.tcp_timestamps = 1net.ipv4.neigh.default.gc_thresh1=4096net.ipv4.neigh.default.gc_thresh2=6144net.ipv4.neigh.default.gc_thresh3=8192net.core.wmem_default = 67108864net.core.rmem_default = 67108864net.core.rmem_max = 67108864net.core.wmem_max = 67108864net.core.netdev_max_backlog = 262144net.core.somaxconn = 65535vm.swappiness = 0vm.zone_reclaim_mode = 0vm.dirty_ratio = 60vm.dirty_background_ratio = 5vm.max_map_count = 262144vm.overcommit_memory=1fs.file-max=65535EOFcat <<EOF | sudo tee /etc/sysctl.d/sysctl-k8s.confnet.ipv4.ip_forward = 1net.bridge.bridge-nf-call-ip6tables = 1net.bridge.bridge-nf-call-iptables = 1EOFsudo sysctl --system【开启大内存页&禁用SWAP】chmod +x /etc/rc.d/rc.localcat >>/etc/rc.d/rc.local<<-EOFecho never > /sys/kernel/mm/transparent_hugepage/enabledecho never > /sys/kernel/mm/transparent_hugepage/defragswapoff -aEOFecho never > /sys/kernel/mm/transparent_hugepage/enabledecho never > /sys/kernel/mm/transparent_hugepage/defragswapoff -ased -i '/ swap / s/^/#/' /etc/fstab
3、更新yum源并安装依赖
cd /etc/yum.repos.d/mv -f * /tmpcurl -Os https://mirrors.aliyun.com/repo/Centos-7.repocurl -Os http://mirrors.aliyun.com/repo/epel-7.repoyum clean allyum makecacheyum -y install yum-utils device-mapper-persistent-data lvm2 bash-completion
4、安装yum源 (阿里云源)
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
5、安装docker-ce
yum makecache fastyum list docker-ce --showduplicates | sort -ryum install docker-ce -y# yum install docker-ce-18.06.3.ce -y
6、修改docker配置
mkdir -pv /etc/docker/tee /etc/docker/daemon.json <<-'EOF'{ "registry-mirrors": [ "https://dockerhub.azk8s.cn", "https://hub-mirror.c.163.com", "https://registry.docker-cn.com" ], "exec-opts": ["native.cgroupdriver=systemd"], "selinux-enabled": false, "graph": "/data/docker", "storage-driver": "overlay2", "storage-opts": ["overlay2.overridekernelcheck=true"]}EOF# 说明:# Docker为OverlayFS提供了两个存储驱动程序:旧版的overlay,新版的overlay2(更稳定)。# overlay2: Linux内核版本4.0或更高版本,或使用内核版本3.10.0-514+的RHEL或CentOS。
7、创建docker数据目录
mkdir -pv /data/docker/
8、启动docker并开机启动
systemctl start docker ;systemctl enable docker; systemctl status docker
9、检查docker配置
docker versiondocker info | grep -A 1 'Registry Mirrors'docker info | grep "Docker Root Dir"
10、安装docker-compose
# 更多版本请查看 https://github.com/docker/compose/releases/curl -L https://github.com/docker/compose/releases/download/1.27.0-rc2/docker-compose-Linux-x86_64 > /usr/bin/docker-composechmod +x /usr/bin/docker-composedocker-compose version
最后为写在文章最后的凑够50字数的正文
最后为写在文章最后的凑够50字数的正文
最后为写在文章最后的凑够50字数的正文
最后为写在文章最后的凑够50字数的正文
最后为写在文章最后的凑够50字数的正文
划线
评论
复制
发布于: 2020 年 09 月 03 日阅读数: 91
版权声明: 本文为 InfoQ 作者【张无忌】的原创文章。
原文链接:【http://xie.infoq.cn/article/346a3848bdb6d2bd8cd7e205e】。文章转载请联系作者。
张无忌
关注
运维老司机带你精通各种删库删服操作 2020.08.27 加入
最近在写K8S系列文章
评论