线上考试系统---虚拟化技术部署

部署前端服务器

1.将资源上传到服务器

scp -r dist/ [email protected]:~

2.在服务器上创建基础容器

[root@docker0 ~]# docker run -it --name c0 centos:latest /bin/bash
[root@c1092b8c9ce5 /]# [root@docker0 ~]# 
[root@docker0 ~]# docker attach c0

3.在容器中修改yum源

[root@c1092b8c9ce5 /]# rm -rf /etc/yum.repos.d/*
[root@c1092b8c9ce5 /]# cat /etc/redhat-release 
CentOS Linux release 8.4.2105
[root@65b0e0641432 /]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2495  100  2495    0     0   7403      0 --:--:-- --:--:-- --:--:--  7403
[root@65b0e0641432 /]# ls /etc/yum.repos.d/
CentOS-Base.repo
[root@65b0e0641432 /]# yum clean all && yum makecache
Failed to set locale, defaulting to C.UTF-8
0 files removed
Failed to set locale, defaulting to C.UTF-8
CentOS-8.5.2111 - Base - mirrors.aliyun.com       597 kB/s | 4.6 MB     00:07    
CentOS-8.5.2111 - Extras - mirrors.aliyun.com      13 kB/s |  10 kB     00:00    
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com  452 kB/s | 8.4 MB     00:19    
Metadata cache created.

4.在容器中安装epel

[root@65b0e0641432 /]# yum -y install epel-release

5.在容器中安装nginx

[root@65b0e0641432 /]# yum -y install nginx
[root@65b0e0641432 /]# [root@docker0 ~]# 

6.导出tar包

[root@docker0 ~]# docker export -o centos_nginx.tar c0
[root@docker0 ~]# ls
anaconda-ks.cfg   centos_nginx.tar  centos_yum.tar  initserver.sh
centos_httpd.tar  centos.tar        dist

7.引入tar包

[root@docker0 ~]# docker import -m "维护世界和平" centos_nginx.tar centos:nginx
sha256:b5d54b55bd165ef173d37d0689512a11747bcf1e478c3b7dfce0f9141c09ba8d

8.查看镜像

[root@docker0 ~]# docker image ls
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
centos       nginx     b5d54b55bd16   10 seconds ago   366MB
mysql        latest    a82a8f162e18   4 weeks ago      586MB
centos       latest    5d0da3dc9764   2 years ago      231MB

9.停用c0容器,删除c0容器

[root@docker0 ~]# docker stop c0
c0
[root@docker0 ~]# docker rm c0
c0
[root@docker0 ~]# docker ps --all
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

10.创建新的centos nginx容器,在创建的同时指定端口,以及 挂载目录

[root@docker0 ~]# docker run -it --name c0 -p80:80/tcp -v /opt/:/usr/share/nginx/html centos:nginx /bin/bash

11.在容器内部启动nginx服务

[root@0a2dcc6f2e1f /]# nginx

12.在宿主上把dist⽬录中的⽂件复制opt⽬录中

[root@docker0 ~]# cp -r dist/* /opt

线上考试系统---虚拟化技术部署_第1张图片

你可能感兴趣的:(云计算学习,运维,服务器,nginx)