CentOS7安装
镜像文件:CentOS-7-x86_64-DVD-1908,官网可下载。
虚拟机采用:VirtualBox-6.1.42-155177-Win,官网可下载
安装步骤后续补上。
查看CentOS的版本
cat /etc/centos-release
Centos Linux release 7.7.1908(core)
退出CentOS屏保快捷键
CTL+ALT+L
设置cecureCRT远程访问
#在centos上关闭防火墙
systemctl status firewalld.service #查看防火墙状态
systemctl stop firewalld.service #关闭防火墙
systemctl disable firewalld.service #关闭启动防火墙
#检查SSH进程是否有
ps -e | grep sshd
#结果如下,表明有SSH业务:
2927 ? 00:00:00 sshd
2971 ? 00:00:00 sshd
#修改sshd_config 的设置
#ssd_config是sshd服务的配置文件,可在其中配置参数,登陆用户等,文件位置位于/etc/ssh/sshd_config:
#(1)打开Port 22,sshd服务的端口
#(2)设置Protocol 2
#(3)打开PermitRootLogin yes
#(4)打开PasswordAuthentication yes
vim /etc/ssh/sshd_config
#重启ssh服务
systemctl restart sshd.service
以上操作在centos上设置。
在宿主机上的cecurCRT进行配置,将usename修改为root
登入成功。
安装docker的基础环境配置
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel http://mirrors.aliyun.com/repo/epel-7.repo
#以上是配置阿里基本库和扩展库
yum clean all #清空缓存
yum makecache #重新导入阿里库
yum install -y bash-completion vim lrzsz wget expect net-tools nc nmap tree dos2unix htop iftop unzip telnet s1 psmisc nethogs glances bc ntpdate openldap-devel # 安装一些软件,对于最新化安装的centos可以安装,正常应该都已经安装
安装docker发行的版本
1、docker EE 企业版,收费
2、docker CE 社区版,免费
安装dacker的要求
1、docker 必须安装在centos7平台以上,内核不低于3.10
2、在centos平台运行docker,需要对内核进行配置,打开内核转发功能
cat << EOF > /etc/sysctl.d/docker.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.all.rp_filter = 0
net.ipv4.ip_forward = 1
EOF
#重新加载内核参数
modprobe br_netfilter
sysctl -p /etc/sysctl.d/docker.conf
#执行结果:
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.all.rp_filter = 0
net.ipv4.ip_forward = 1
#要保持本地软件源较新,可以用阿里云yum源更新软件
3、安装docker-ce社区版
#下载阿里源repo文件
#提前配置好yum仓库
#1、阿里云自带仓库。#2、阿里云专属的docker仓库
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/docker-ce.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum clean all && yum makecache
利用yum快速安装docker
yum list docker-ce --showduplicates | sort -r #查看仓库软件包情况
#yum 安装
yum install docker-ce-20.10.6 -y
#如需安装旧版本
yum install -y docker-ce-18.09.9
#卸载docker
yum uninstall docker-ce-xxxx
镜像加速器
使用docker首要操作就是获取镜像文件,默认下载是从Docker Hub下载,网速较慢,国内很多云服务商都是提供了加速器服务,阿里云加速器,Daocloud加速器,灵雀云加速器等。
#1、创建etc/docker目录daemo.json,采用阿里云加速器
mkdir -p /etc/docker
touch /etc/docker/daemon.json
#vim的操作 i:进入编写,wq!:保持退出,q!:不保持,退出
{
"registry-mirros":[
"http://f1361db2.m.daocloud.io"
]
}
#2、重启,设置开机自启
systemctl daemon-reload
systemctl enable docker
systemctl restart docker
#3、查看docker运行情况
docker info
#其结果如下,表示成功:
[root@localhost docker]# docker info
Client:
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.10.4
Path: /usr/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: v2.17.2
Path: /usr/libexec/docker/cli-plugins/docker-compose
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 20.10.6
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 2806fc1057397dbaeefbea0e4e17bddfbd388f38
runc version: v1.1.5-0-gf19387a
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-1062.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 991MiB
Name: localhost.localdomain
ID: E2PU:BESV:BUZT:KOQL:TZYB:XXMR:W7XH:5IZ4:52HD:GMDV:J2T7:IHFG
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
http://f1361db2.m.daocloud.io/
Live Restore Enabled: false
#4.下载一个nginx镜像
docker search nginx : 搜索仓库的nginx镜像
#搜索结果
[root@localhost docker]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 18394 [OK]
unit Official build of NGINX Unit: a polyglot app鈥 0 [OK]
bitnami/nginx Bitnami nginx Docker Image 158 [OK
#选择official 下载多,NAME为nginx
docker pull nginx
#其结果,下载成功:
Using default tag: latest
latest: Pulling from library/nginx
26c5c85e47da: Pull complete
4f3256bdf66b: Pull complete
2019c71d5655: Pull complete
8c767bdbc9ae: Pull complete
78e14bb05fd3: Pull complete
75576236abf5: Pull complete
Digest: sha256:63b44e8ddb83d5dd8020327c1f40436e37a6fffd3ef2498a6204df23be6e7e94
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
docker images #查看下载的镜像文件
#其结果如下:
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 6efc10a0510f 4 days ago 142MB
#5 运行nginx的容器:run:运行容器,-d:后台运行,--name:给容器取名, -p 宿主机端口:容器端口
docker run -d --rm --name nginx -p 80:80 nginx
#6 查看容器运行
docker ps
在宿主机的网页输入容器IP,查看nignx运行情况:
运行成功。
总结
1、安装centos7
2、为了便于操作,设置cecureCRT远程访问
3、配置docker安装的环境
4、安装合适的docker版本
5、设置镜像加速器
6、验证docker使用