在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=staticIPADDR=192.168.1.91NETMASK=255.255.255.0GATEWAY=192.168.1.1DNS1=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-srLinux4.19.6-1.el7.elrepo.x86_64
系统安全策略配置
永久关闭防火墙
systemctlstopfirewalld.servicesystemctldisablefirewalld.service
永久关闭SELinux
setenforce0vi /etc/sysconfig/selinux修改此项:SELINUX=disabled
关闭swap交换分区
#swapoff-a#vi /etc/fstab注释掉下面的一行,比如:#/dev/mapper/centos-swap swap swap defaults 0 0
开启IPV4转发,并立即生效
#vi /etc/sysctl.confnet.ipv4.ip_forward=1 net.bridge.bridge-nf-call-ip6tables = 1net.bridge.bridge-nf-call-iptables = 1#sudo sysctl -p
另外生产环境,建议把所有设备的网卡名称都统一,修改网卡名称:
# cd /etc/sysconfig/network-scripts/
#vi ifcfg-ens160
将下面连个参数修改一下:
DEVICE=eth0NAME=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 # 例如:sudo yum install docker-ce-17.12.0.ce
启动并加入开机启动
systemctlstartdockersystemctlenabledocker
验证安装是否成功
#docker info
Containers: 0Running: 0 Paused: 0 Stopped: 0Images: 0Server Version: 18.09.0Storage Driver: overlay2 Backing Filesystem: xfs Supports d_type: true Native Overlay Diff: trueLogging Driver: json-fileCgroup Driver: cgroupfsPlugins:Volume: local Network: bridge host macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslogSwarm: inactiveRuntimes: runcDefault Runtime: runcInit Binary: docker-initcontainerd version: c4446665cb9c30056f4998ed953e6d4ff22c7c39runc version: 4fc53a81fb7c994640722ac585fa9ca548971871init version: fec3683Security Options: seccomp Profile: defaultKernel Version: 3.10.0-957.1.3.el7.x86_64Operating System: CentOS Linux 7 (Core)OSType: linuxArchitecture: x86_64CPUs: 2Total Memory: 3.701GiBName: localhost.localdomainID: DAUF:Y57U:FORV:46DR:7PHI:MGO4:V6FA:NNEP:UO4S:ERMB:J5SV:IX2ODocker Root Dir: /var/lib/dockerDebug Mode (client): falseDebug Mode (server): falseRegistry: https://index.docker.io/v1/Labels:Experimental: falseInsecure Registries: 127.0.0.0/8Live Restore Enabled: falseProduct License: Community Engine
为了更便于学习DOCKER 命令 ,可以安装命令补全:
安装docker自带包:
source /usr/share/bash-completion/completions/docker
缺少下面的包,TAB会报错
yuminstall-y bash-completionsh /usr/share/bash-completion/bash_completion
重启服务器 reboot
镜像加速
鉴于国内网络问题,后续拉取 Docker 镜像十分缓慢,强烈建议安装 Docker 之后配置 国内镜像加速。
请在 /etc/docker/daemon.json 中写入如下内容(如果文件不存在请新建该文件)
{"registry-mirrors": ["https://registry.docker-cn.com"]}
注意,一定要保证该文件符合 json 规范,否则 Docker 将不能启动。
systemctldaemon-reloadsystemctl restart docker
查看镜像加速是否生效:
docker info
应该会发现以下信息
Registry Mirrors: https://registry.docker-cn.com/