小白贴:Docker 实战之 CentOS7 系统环境配置
本文档详细介绍 Docker 实战之 CentOS7 系统环境配置,为后期安装 Docker 做准备。文内含长段代码可复制可往左滑,希望对大家有帮助!
优化环境
直接复制以下代码,优化环境,如果执行了一下代码,那么接下来的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
关闭SELinux和防火墙
[root@Docker ]# vim /etc/selinux/config
SELINUX=disabled
[root@Docker ]# setenforce 0
[root@Docker ]# getenforce
Permissive
<以上代码可复制粘贴,可往左滑>
关闭Firewalld 和 iptables
[root@Docker ]# systemctl stop firewalld
[root@Docker ]# systemctl disable firewalld
[root@Docker ]# systemctl status firewalld
[root@Docker ]# iptables -F
<以上代码可复制粘贴,可往左滑>
配置 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=https://mirrors.aliyun.com/centos/7/os/x86_64/
enabled=1
gpgcheck=0
[aliyun-epel]
name=aliyun-epel
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
enabled=1
gpgcheck=0
[aliyun-extra]
name=aliyun-extra
baseurl=https://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 http://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=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-stable-debuginfo]
name=Docker CE Stable - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/stable
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-stable-source]
name=Docker CE Stable - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/stable
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-edge]
name=Docker CE Edge - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/edge
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-edge-debuginfo]
name=Docker CE Edge - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/edge
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-edge-source]
name=Docker CE Edge - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/edge
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-test]
name=Docker CE Test - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-test-debuginfo]
name=Docker CE Test - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-test-source]
name=Docker CE Test - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-nightly]
name=Docker CE Nightly - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-nightly-debuginfo]
name=Docker CE Nightly - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-nightly-source]
name=Docker CE Nightly - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/nightly
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[root@Docker ]# yum clean all && yum makecache
<以上代码可复制粘贴,可往左滑>
配置 hostname
[root@Docker ]# vim /etc/hostname
Docker
<以上代码可复制粘贴,可往左滑>
配置/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
<以上代码可复制粘贴,可往左滑>
同步时间
[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"
配置 pip 镜像源,方便快速下载python库
这一步很重要
[root@Docker ]# mkdir /.pip
[root@Docker ]# vim /.pip/pip.conf #写入下以内容
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
<以上代码可复制粘贴,可往左滑>
配置网卡信息
[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 的朋友请持续关注文章,希望文章能给大家带来帮助。
官方站点:www.linuxprobe.com
Linux命令大全:www.linuxcool.com
Linux系统下载站:www.linuxdown.com
刘遄老师QQ:5604922
Linux技术交流群:193666693
(新群,火热加群中……)
书籍在线学习(电脑阅读效果佳):
http://www.linuxprobe.com/chapter-00.html
想要学习Linux系统的读者可以点击"阅读原文"按钮来了解书籍《Linux就该这么学》,同时也非常适合专业的运维人员阅读,成为辅助您工作的高价值工具书!