-
在ESXi中安装centos7.5操作系统;
-
创建磁盘分区
-
配置IP地址和DNS
#vi /etc/sysconfig/network-scripts/ifcfg-ens160
DEVICE="ens160"
HWADDR="00:21:70:10:7E:CD"
NM_CONTROLLED="no"
ONBOOT="yes"
BOOTPROTO=static
IPADDR=192.168.1.91
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=192.168.1.1
4.在vmware vsphere环境中为了更好的使用体验,建议先安装vmware tools
安装vmware tools前请安装以下组件:
#yum groupinstall "Perl Support" -y
#yum install gcc gcc-c++ automake make -y
#yum install kernel-devel -y
#yum install net-tools
国内建议先更换一下阿里源:
#yum install wget -y
#wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#yum clean all
#yum makecache
安装vmware tools:
mount /dev/sr0 /mnt/
cp /mnt/VMwareTools-9.4.0-1280544.tar.gz /tmp/
cd /tmp/
tar -zxvf VMwareTools-9.4.0-1280544.tar.gz
cd vmware-tools-distrib/
./vmware-install.pl
- 升级kernel版本
查看系统版本信息:
awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
启用 ELRepo仓库:rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
查看可用内核yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
安装最新内核yum --disablerepo="*" --enablerepo=elrepo-kernel install -y kernel-ml kernel-ml-devel
查看已安装的内核版本awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
设置升级后的最新版本,即就是编号为0的那个grub2-set-default 0
vim /etc/default/grub 修改此项:GRUB_DEFAULT=0
生产grub2配置文件,并重启
grub2-mkconfig -o /boot/grub2/grub.cfg
reboot
验证内核:
# uname -sr
Linux 4.19.6-1.el7.elrepo.x86_64
- 系统安全策略配置 永久关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
永久关闭SELinux
setenforce 0
vi /etc/sysconfig/selinux
修改此项:SELINUX=disabled
关闭swap交换分区
#swapoff -a
#vi /etc/fstab
注释掉下面的一行,比如:
#/dev/mapper/centos-swap swap swap defaults 0 0
开启IPV4转发,并立即生效
#vi /etc/sysctl.conf
net.ipv4.ip_forward=1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
#sudo sysctl -p
另外生产环境,建议把所有设备的网卡名称都统一,修改网卡名称:
# cd /etc/sysconfig/network-scripts/
#vi ifcfg-ens160
将下面连个参数修改一下:
DEVICE=eth0
NAME=eth0
mv ifcfg-ens160 ifcfg-eth0
因 CentOS7 采用 grub2 引导,还需要对 grub2 进行修改,编辑 /etc/default/grub 配置文件,在 GRUB_CMDLINE_LINUX 这个参数后面加入 net.ifnames=0 biosdevname=0
vi /etc/default/grub
GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet net.ifnames=0 biosdevname=0"
用 grub2-mkconfig 命令重新生成GRUB配置并更新内核
grub2-mkconfig -o /boot/grub2/grub.cfg
重启系统:reboot
更新一下系统:yum update -y
- 开始安装docker:
安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
yum install -y yum-utils device-mapper-persistent-data lvm2
设置yum源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
或者 http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
列出可安装的DOCKER版本
yum list docker-ce --showduplicates | sort -r
安装docker $ sudo yum install docker-ce #由于repo中默认只开启stable仓库,故这里安装的是最新稳定版18.09.0-3 $ sudo yum install <FQPN> # 例如:sudo yum install docker-ce-17.12.0.ce
启动并加入开机启动
systemctl start docker
systemctl enable docker
验证安装是否成功
#docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 18.09.0
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: c4446665cb9c30056f4998ed953e6d4ff22c7c39
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-957.1.3.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.701GiB
Name: localhost.localdomain
ID: DAUF:Y57U:FORV:46DR:7PHI:MGO4:V6FA:NNEP:UO4S:ERMB:J5SV:IX2O
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine
- 为了更便于学习DOCKER 命令 ,可以安装命令补全:
安装docker自带包:
source /usr/share/bash-completion/completions/docker
缺少下面的包,TAB会报错
yum install -y bash-completion
sh /usr/share/bash-completion/bash_completion
重启服务器 reboot
- 镜像加速 鉴于国内网络问题,后续拉取 Docker 镜像十分缓慢,强烈建议安装 Docker 之后配置 国内镜像加速。 请在 /etc/docker/daemon.json 中写入如下内容(如果文件不存在请新建该文件)
{
"registry-mirrors": [
"https://registry.docker-cn.com"
]
}
注意,一定要保证该文件符合 json 规范,否则 Docker 将不能启动。
systemctl daemon-reload
systemctl restart docker
查看镜像加速是否生效:
docker info
应该会发现以下信息
Registry Mirrors: https://registry.docker-cn.com/