导读 本文档详细介绍 Docker 实战之 CentOS7 系统环境配置,为后期安装 Docker 做准备。
0 优化环境

直接复制以下代码,优化环境,如果执行了一下代码,那么接下来的1和2步骤可以不用再操作了。

sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config &> /dev/null
setenforce 0
systemctl stop firewalld
systemctl disable firewalld
iptables -F
systemctl stop NetworkManager &> /dev/null
systemctl disable NetworkManager &> /dev/null
1 关闭SELinux和防火墙
[root@Docker ]# vim /etc/selinux/config
SELINUX=disabled
[root@Docker ]# setenforce 0
[root@Docker ]# getenforce
Permissive
2 关闭Firewalld 和 iptables
[root@Docker ]# systemctl stop firewalld
[root@Docker ]# systemctl disable firewalld
[root@Docker ]# systemctl status firewalld
[root@Docker ]# iptables -F
3 配置 yum 源
[root@Docker ]# mv /etc/yum.repos.d/Cent* /tmp
[root@Docker ]# vim /etc/yum.repos.d/CentOS7.repo
[aliyun-os]
name=aliyun-os
baseurl=//mirrors.aliyun.com/centos/7/os/x86_64/
enabled=1
gpgcheck=0

[aliyun-epel]
name=aliyun-epel
baseurl=//mirrors.aliyun.com/epel/7/x86_64/
enabled=1
gpgcheck=0

[aliyun-extra]
name=aliyun-extra
baseurl=//mirrors.aliyun.com/centos/7/extras/x86_64/
enabled=1
gpgcheck=0

[root@Docker ]# yum clean all && yum makecache
添加 epel 源
[root@Docker ]# yum install epel-release -y
添加 docker-ce 源
[root@Docker ]# yum install -y yum-utils
[root@Docker ]# yum-config-manager --add-repo //mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@Docker ]# cat /etc/yum.repos.d/docker-ce.repo 
[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=//mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=//mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-stable-debuginfo]
name=Docker CE Stable - Debuginfo $basearch
baseurl=//mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/stable
enabled=0
gpgcheck=1
gpgkey=//mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-stable-source]
name=Docker CE Stable - Sources
baseurl=//mirrors.aliyun.com/docker-ce/linux/centos/7/source/stable
enabled=0
gpgcheck=1
gpgkey=//mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-edge]
name=Docker CE Edge - $basearch
baseurl=//mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/edge
enabled=0
gpgcheck=1
gpgkey=//mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-edge-debuginfo]
name=Docker CE Edge - Debuginfo $basearch
baseurl=//mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/edge
enabled=0
gpgcheck=1
gpgkey=//mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-edge-source]
name=Docker CE Edge - Sources
baseurl=//mirrors.aliyun.com/docker-ce/linux/centos/7/source/edge
enabled=0
gpgcheck=1
gpgkey=//mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-test]
name=Docker CE Test - $basearch
baseurl=//mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/test
enabled=0
gpgcheck=1
gpgkey=//mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-test-debuginfo]
name=Docker CE Test - Debuginfo $basearch
baseurl=//mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/test
enabled=0
gpgcheck=1
gpgkey=//mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-test-source]
name=Docker CE Test - Sources
baseurl=//mirrors.aliyun.com/docker-ce/linux/centos/7/source/test
enabled=0
gpgcheck=1
gpgkey=//mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-nightly]
name=Docker CE Nightly - $basearch
baseurl=//mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=//mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-nightly-debuginfo]
name=Docker CE Nightly - Debuginfo $basearch
baseurl=//mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=//mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-nightly-source]
name=Docker CE Nightly - Sources
baseurl=//mirrors.aliyun.com/docker-ce/linux/centos/7/source/nightly
enabled=0
gpgcheck=1
gpgkey=//mirrors.aliyun.com/docker-ce/linux/centos/gpg

[root@Docker ]# yum clean all && yum makecache
4 配置 hostname
[root@Docker ]# vim /etc/hostname
Docker
5 配置/etc/hosts
[root@Docker ]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhostlocaldomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.10.7 Docker

[root@Docker ]# ping $HOSTNAME
6 同步时间
[root@Docker ]# find / -name Shanghai
/usr/share/zoneinfo/Asia/Shanghai
/usr/share/zoneinfo/posix/Asia/Shanghai
/usr/share/zoneinfo/right/Asia/Shanghai
[root@Docker ]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 
cp: overwrite ‘/etc/localtime’? y
[root@Docker ]# yum install -y ntp ntpdate
[root@Docker ]# systemctl enable ntpd
[root@Docker ]# systemctl start ntpd
[root@Docker ]# ntpdate cn.pool.ntp.org
[root@Docker ]# ntpdate 0.rhel.pool.ntp.org

手动改时间: date -s "2019-09-09 19:19"

7 配置 pip 镜像源,方便快速下载python库(这一步很重要)
[root@Docker ]# mkdir /.pip
[root@Docker ]# vim  /.pip/pip.conf  #写入下以内容
[global]
index-url = //mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
8  配置网卡信息
[root@Docker ]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=ens33
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.10.7
GATEWAY=192.168.10.2
NETMASK=255.255.255.0
总结

以上的操作就是 CentOS7 系统环境配置的过程,为安装 Docker 做好准备。想看怎么安装 Docker 的朋友请持续关注我的文章,希望我的文章能给大家带来帮助。

本文原创地址://q13zd.cn/docker-combat-centos7.html编辑:public,审核员:逄增宝