在做实验的过程中少不了搭建环境,但是要一个个去搭建服务,无疑是特别浪费时间的,用docker可以解决这些问题。
用VMware安装Linux系统
本身用的笔记本安装的centos7系统,我选择的是最小化安装,这样可以把它当作一个模板机,之后无论需要多少直接克隆即可。由于是最小化安装,所以缺少很多包,需要对模板机安装一些必备的软件和设置。
关闭selinux
selinux开启可能会造成一些不必要的问题,排错不好找原因,所以选择关闭。
文件所在位置为/etc/selinux/config
| 12
 3
 4
 
 | // 原文件为:SELINUX=enforcing
 //改为
 SELINUX=disabled
 
 | 
卸载自带防火墙
| 12
 
 | yum -y remove firewalld
 
 | 
更改镜像源
这里用的是阿里云的。
| 12
 3
 4
 5
 6
 7
 8
 9
 
 | // 删除系统自带的镜像源rm -rf /etc/yum.repos.d/*
 // 下载阿里云镜像文件
 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
 // 清除系统缓存
 yum clean all
 // 生成缓存
 yum makecache
 
 
 | 
安装软件包
| 1
 | yum -y install net-tools vim git python3
 | 
使用脚本安装docker
脚本是从网上找的
新建脚本文件为docker-install.sh
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 
 | #!/bin/bash#
 #********************************************************************
 #Author:        wangxiaochun
 #QQ:            29308620
 #Date:          2020-01-26
 #FileName:      install_docker_for_centos7.sh
 #URL:           http://www.magedu.com
 #Description:       The test script
 #Copyright (C):     2020 All rights reserved
 #********************************************************************
 COLOR="echo -e \\033[1;31m"
 END="\033[m"
 VERSION="19.03.5-3.el7"
 wget -P /etc/yum.repos.d/ https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo  || { ${COLOR}"互联网连接失败,请检查网络配置!"${END};exit; }
 yum clean all
 yum -y install docker-ce-$VERSION docker-ce-cli-$VERSION || { ${COLOR}"Base,Extras的yum源失败,请检查yum源配置"${END};exit; }
 mkdir -p /etc/docker
 cat > /etc/docker/daemon.json <<EOF
 {
 "registry-mirrors": ["https://si7y70hh.mirror.aliyuncs.com"]
 }
 EOF
 
 systemctl restart docker
 docker version && ${COLOR}"Docker安装成功"${END} || ${COLOR}"Docker安装失败"${END}
 
 
 | 
赋予脚本执行权限并执行脚本
| 12
 
 | chmod +x docker-install.sh./docker-install.sh
 
 | 
安装docker-compose
我选择的是pip安装方式。
| 12
 
 | pip3 install docker-compose
 
 |