【题目1】容器化部署Redis
在master节点上编写/root/redis/Dockerfile文件构建chinaskill-redis:v1.1镜像,具体要求如下:(需要用到的软件包在/桌面/附件/容器云附件/gpmall-single.tar.gz)
(1)基础镜像:centos:centos7.5.1804;
(2)作者:Chinaskill;
(3)修改配置文件中的bind 127.0.0.1为bind 0.0.0.0;
(4)设置Redis免密,并关闭保护模式;
(5)开放端口:6379;
(6)设置服务开机自启。
完成后构建镜像,并提交master节点的用户名、密码和IP到答题框。
[root@master redis]# ls
Dockerfile ftp.repo
[root@master redis]# cat ftp.repo
[gpmall]
name=gpmall
baseurl=ftp://192.168.200.10/gpmall-repo
gpgcheck=0
[centos]
name=centos
baseurl=ftp://192.168.200.10/centos
gpgcheck=0
[root@master redis]# cat Dockerfile
[root@master redis]# cat Dockerfile
FROM centos:centos7.5.1804
MAINTAINER Chinaskill
RUN rm -rf /etc/yum.repos.d/*
ADD ftp.repo /etc/yum.repos.d/
RUN yum -y install redis \
&& sed -i 's/bind 127.0.0.1/bind 0.0.0.0/g' /etc/redis.conf \ #设置免密(bind 127.0.0.1 修改为 bind 0.0.0.0 )
&& sed -i 's/protected-mode yes/protected-mode no/g' /etc/redis.conf #关闭保护模式 (protected-mode yes 修改为 protected-mode no)
EXPOSE 6379 #暴露容器内的端口
CMD ["redis-server","/etc/redis.conf"]
[root@master redis]# cd /root/redis/ && docker build -t chinaskill-redis:v1.1 .
【题目2】容器化部署MariaDB
在master节点上编写/root/mariadb/Dockerfile文件构建chinaskill-mariadb:v1.1镜像,具体要求如下:(需要用到的软件包在/桌面/附件/容器云附件/gpmall-single.tar.gz)
(1)基础镜像:centos:centos7.5.1804;
(2)作者:Chinaskill;
(3)设置数据库密码:123456;
(4)创建数据库gpmall并导入数据库文件gpmall.sql;
(5)设置字符编码:UTF-8;
(6)开放端口:3306;
(7)设置服务开机自启。
完成后构建镜像,并提交master节点的用户名、密码和IP到答题框。
[root@master mariadb]# ls
Dockerfile ftp.repo gpmall.sql init.sh
[root@master mariadb]# cat Dockerfile
FROM centos:centos7.5.1804
MAINTAINER Chinaskill
RUN rm -rf /etc/yum.repos.d/*
ADD ftp.repo /etc/yum.repos.d/
ADD gpmall.sql init.sh /opt/
RUN yum -y install mariadb-server \
&& bash /opt/init.sh
ENV LC_ALL en_US.UTF-8 #设置字符编码:UTF-8
EXPOSE 3306
CMD ["mysqld_safe","--user=root"]
[root@master mariadb]# cat init.sh
#!/bin/bash
mysql_install_db --user=root #初始化数据库
mysqld_safe --user=root &
sleep 3
mysqladmin -u root password '123456' #设置数据库密码
mysql -uroot -p123456 -e "grant all privileges on *.* to root@'%' identified by '123456';" #授权
mysql -uroot -p123456 -e "set names utf8;create database gpmall character set utf8;use gpmall;source /opt/gpmall.sql;" #创建gpmall数据库
[root@master mariadb]# docker build -t chinaskill-mariadb:v1.1 .
【题目3】容器化部署Zookeeper
在master节点上编写/root/zookeeper/Dockerfile文件构建chinaskill-zookeeper:v1.1镜像,具体要求如下:(需要用到的软件包在/桌面/附件/容器云附件/gpmall-single.tar.gz)
(1)基础镜像:centos:centos7.5.1804;
(2)作者:Chinaskill;
(3)开放端口:2181;
(4)设置服务开机自启。
完成后构建镜像,使用构建的镜像运行容器myzookeeper,并提交master节点的用户名、密码和IP到答题框。
[root@master zookeeper]# ls
Dockerfile ftp.repo zookeeper-3.4.14 zookeeper-3.4.14.tar.gz
[root@master zookeeper]# cat Dockerfile
FROM centos:centos7.5.1804
MAINTAINER Chinaskill
RUN rm -rf /etc/yum.repos.d/*
ADD ftp.repo /etc/yum.repos.d/
ADD zookeeper-3.4.14.tar.gz /opt/
RUN yum -y install java-1.8.0-openjdk* \
&& mv /opt/zookeeper-3.4.14/conf/zoo_sample.cfg /opt/zookeeper-3.4.14/conf/zoo.cfg
EXPOSE 2181
CMD ["sh","-c","/opt/zookeeper-3.4.14/bin/zkServer.sh start && tail -f /etc/shadow"]
[root@master mariadb]# docker build -t chinaskill-zookeeper:v1.1 .
【题目4】容器化部署Kafka
在master节点上编写/root/kafka/Dockerfile文件构建chinaskill-kafka:v1.1镜像,具体要求如下:(需要用到的软件包在/桌面/附件/容器云附件/gpmall-single.tar.gz)
(1)基础镜像:centos:centos7.5.1804;
(2)作者:Chinaskill;
(3)开放端口:9092;
(4)设置服务开机自启。
完成后构建镜像,并提交master节点的用户名、密码和IP到答题框。
[root@master kafka]# ls
Dockerfile ftp.repo kafka_2.11-1.1.1.tgz zookeeper-3.4.14.tar.gz
[root@master kafka]# cat Dockerfile
FROM centos:centos7.5.1804
MAINTAINER Chinaskill
RUN rm -rf /etc/yum.repos.d/*
ADD ftp.repo /etc/yum.repos.d/
ADD zookeeper-3.4.14.tar.gz kafka_2.11-1.1.1.tgz /opt/
RUN yum -y install java-1.8.0-openjdk* \
&& mv /opt/zookeeper-3.4.14/conf/zoo_sample.cfg /opt/zookeeper-3.4.14/conf/zoo.cfg
EXPOSE 9092
CMD ["sh","-c","/opt/zookeeper-3.4.14/bin/zkServer.sh start && /opt/kafka_2.11-1.1.1/bin/kafka-server-start.sh /opt/kafka_2.11-1.1.1/config/server.properties"]
[root@master kafka]# docker build -t chinaskill-kafka:v1.1 .
【题目5】容器化部署Nginx
在master节点上编写/root/nginx/Dockerfile文件构建chinaskill-nginx:v1.1镜像,具体要求如下:(需要用到的软件包在/桌面/附件/容器云附件/gpmall-single.tar.gz)
(1)基础镜像:centos:centos7.5.1804;
(2)作者:Chinaskill;
(3)编写/etc/nginx/conf.d/default.conf文件,配置反向代理,将80端口请求转发到8081、8082和8083;
(4)将dist中的文件复制到/usr/share/nginx/html/目录下;
(5)复制所有的jar包到镜像中;
(6)开放端口:80、443、8081、8082、8083;
(7)设置服务开机自启。
完成后构建镜像,并提交master节点的用户名、密码和IP到答题框。
[root@master nginx]# ls
dist gpmall-user-0.0.1-SNAPSHOT.jar
Dockerfile setup.sh
ftp.repo shopping-provider-0.0.1-SNAPSHOT.jar
gpmall-shopping-0.0.1-SNAPSHOT.jar user-provider-0.0.1-SNAPSHOT.jar
[root@master nginx]# cat Dockerfile
FROM centos:centos7.5.1804
MAINTAINER Chinaskill
RUN rm -rf /etc/yum.repos.d/*
ADD ftp.repo /etc/yum.repos.d/
ADD *.jar setup.sh /root/
RUN yum -y install nginx java-1.8.0-openjdk* \
&& sed -i '1a location /shopping { proxy_pass http://127.0.0.1:8081;}' /etc/nginx/conf.d/default.conf \
&& sed -i '2a location /user { proxy_pass http://127.0.0.1:8082;}' /etc/nginx/conf.d/default.conf \
&& sed -i '3a location /cashier { proxy_pass http://127.0.0.1:8083;}' /etc/nginx/conf.d/default.conf \
&& chmod +x /root/setup.sh \
&& rm -rf /usr/share/nginx/html/*
ADD dist /usr/share/nginx/html/
EXPOSE 80 8081 8082 8083 443
CMD ["nginx","-g","daemon off;"]
[root@master nginx]# cat setup.sh
#!/bin/bash
nohup java -jar /root/shopping-provider-0.0.1-SNAPSHOT.jar &
sleep 5
nohup java -jar /root/user-provider-0.0.1-SNAPSHOT.jar &
sleep 5
nohup java -jar /root/gpmall-shopping-0.0.1-SNAPSHOT.jar &
sleep 5
nohup java -jar /root/gpmall-user-0.0.1-SNAPSHOT.jar &
sleep 5
[root@master nginx]# docker build -t chinaskill-nginx:v1.1 .
【题目6】编排部署商城
在master节点上编写/root/chinaskillmall/docker-compose.yaml文件部署,具体要求如下:
(1)容器1名称:mall-mysql;镜像:chinaskill-mariadb:v1.1;端口映射:13306:3306;
(2)容器2名称:mall-redis;镜像:chinaskill-redis:v1.1;端口映射:16379:6379;
(3)容器3名称:mall-kafka;镜像:chinaskill-kafka:v1.1;端口映射:19092:9092;
(4)容器4名称:mall-zookeeper;镜像:chinaskill-zookeeper:v1.1;端口映射:12181:2181;
(5)容器5名称:mall-nginx;镜像:chinaskill-nginx:v1.1;端口映射:83:80,1443:443;自启动所有的jar包程序。
完成后编排部署商城,并能成功访问商城首页。然后提交master节点的用户名、密码和IP到答题框。
[root@master ~]# cat docker-compose.yaml
version: "3.3"
services:
mysql.mall:
container_name: mall-mysql
image: chinaskill-mariadb:v1.1
ports:
- 13306:3306
redis.mall:
container_name: mall-redis
image: chinaskill-redis:v1.1
ports:
- 16379:6379
zookeeper.mall:
container_name: mall-zookeeper
image: chinaskill-zookeeper:v1.1
ports:
- 12181:2181
kafka.mall:
container_name: mall-kafka
image: chinaskill-kafka:v1.1
ports:
- 19092:9092
nginx-mall:
depends_on:
- mysql.mall
- redis.mall
- zookeeper.mall
- kafka.mall
container_name: mall-nginx
image: chinaskill-nginx:v1.1
ports:
- 83:80
- 1443:443
command: ["sh","-c","/root/setup.sh && nginx && tail -f /etc/shadow"]
[root@master ~]# docker exec -it mall-mysql bash
[root@522c75b9af2e /]# mysql -uroot -p123456
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.23-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
k8s部署gpmall
[root@master gpmall]# cat k8s-gpmall.yaml
apiVersion: v1
kind: Pod
metadata:
name: gpmall
labels:
app: gpmall
spec:
hostAliases:
- ip: 127.0.0.1
hostnames:
- "zookeeper.mall"
- "kafka.mall"
- "mysql.mall"
- "redis.mall"
containers:
- name: redis
image: chinaskill-redis:v1.1
ports:
- containerPort: 6379
- name: mariadb
image: chinaskill-mariadb:v1.1
ports:
- containerPort: 3306
- name: zookeeper
image: chinaskill-zookeeper:v1.1
ports:
- containerPort: 2181
- name: kafka
image: chinaskill-kafka:v1.1
ports:
- containerPort: 9092
- name: nginx
image: chinaskill-nginx:v1.1
ports:
- containerPort: 80
command:
- sh
- -c
- "bash /root/start.sh && nginx -g 'daemon off;'"
---
apiVersion: v1
kind: Service
metadata:
name: chinaskill-mall
spec:
selector:
app: gpmall
type: NodePort
ports:
- port: 80
targetPort: 80
nodePort: 30010