1.规划节点
IP主机名节点10.24.2.156masterKubernetes master 节点10.24.2.157nodeKubernetes worker 节点
2.基础准备
Kubernetes 集群已部署完成,将提供的压缩包 GPMall.tar.gz 上传到master 节点/root 目录下并解压。
GPMall.tar.gz:https://download.csdn.net/download/qq_52716296/86405354
3.Redis 容器化部署
(1)编写 Dockerfile
编写 yum 文件
[root@master ~]# cd gpmall/[root@master gpmall]# cat local.repo[gpmall]name=gpmall
baseurl=file:///opt/gpmall
2gpgcheck=0enabled=1
编写 Dockerfile 文件:
[root@master gpmall]# cat Dockerfile-redis
FROM centos:centos7.5.1804
MAINTAINER Guo
# 配置 yum 源
ADD gpmall.tar /opt
RUN rm -rfv /etc/yum.repos.d/* ADD local.repo /etc/yum.repos.d/
#安装 Redis
RUN yum -y install redis
# 开放端口
EXPOSE 6379#安装清理缓存文件
RUN yum clean all
#修改绑定 IP 地址
RUN sed -i -e 's@bind 127.0.0.1@bind 0.0.0.0@g' /etc/redis.conf
#关闭保护模式
RUN sed -i -e 's@protected-mode yes@protected-mode no@g' /etc/redis.conf
#启动
ENTRYPOINT ["/usr/bin/redis-server","/etc/redis.conf"]
CMD []
(2)构建镜像
构建镜像 gpmall-redis:v1.0:
[root@master gpmall]# docker build -t gpmall-redis:v1.0 -f Dockerfile-redis . Sending build context to Docker daemon 507.6MB
Step 1/12 : FROM centos:centos7.5.1804
---> cf49811e3cdb
Step 2/12 : MAINTAINER Guo
---> Using cache
---> 02855371e6e9
Step 3/12 : ADD gpmall.tar /opt ---> Using cache
---> bb41486d722b
Step 4/12 : RUN rm -rfv /etc/yum.repos.d/*
---> Using cache
---> 310d88dd58d7
Step 5/12 : ADD local.repo /etc/yum.repos.d/ ---> Using cache
---> ebd2db8d8bf6
Step 6/12 : RUN yum -y install redis
---> Using cache
---> bbb61e6529ad
Step 7/12 : EXPOSE 6379
---> Using cache
---> d4e578610926
Step 8/12 : RUN yum clean all ---> Using cache
---> 7d204f260c6a
Step 9/12 : RUN sed -i -e 's@bind 127.0.0.1@bind 0.0.0.0@g' /etc/redis.conf
---> Using cache
---> 6f495fddae91
查看镜像列表:
[root@master gpmall]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
gpmall-redis v1.0 0e71dea163a7 2 minutes ago 465MB
4.Mariadb 容器化部署
(1)编写 Dockerfile
编写数据库初始化脚本 run.sh:
[root@master gpmall]# cat mysql_init.sh#!/bin/bash
mysql_install_db --user=mysql
(mysqld_safe &)|grep a
sleep 3s
mysqladmin -u root password '123456'sleep 3s
mysql -uroot -p123456 -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIEDBY '123456'"sleep 3s
mysql -uroot -p123456 -e "create database gpmall;use gpmall;source /opt/gpmall.sql;"sleep 3s
编写 Dockerfile 文件:
[root@master gpmall]# cat Dockerfile-mariadb
FROM centos:centos7.5.1804
MAINTAINER Chinaskill
# 配置 yum 源
ADD gpmall.tar /opt
RUN rm -rfv /etc/yum.repos.d/* ADD local.repo /etc/yum.repos.d/
# 安装 MariaDB
RUN yum install -y MariaDB-server expect net-tools
RUN yum clean all
COPY gpmall.sql /opt/
ADD mysql_init.sh /opt/
RUN chmod +x /opt/mysql_init.sh
RUN /opt/mysql_init.sh
ENV LC_ALL en_US.UTF-8
EXPOSE 3306
CMD ["mysqld_safe"]
(2)构建镜像
构建镜像:
[root@master gpmall]# docker build -t gpmall-mariadb:v1.0 -f Dockerfile-mariadb . Sending build context to Docker daemon 507.6MB
Step 1/14 : FROM centos:centos7.5.1804
---> cf49811e3cdb
Step 2/14 : MAINTAINER Chinaskill ---> Using cache
---> 612224da592d
Step 3/14 : ADD gpmall.tar /opt
6
---> Using cache
---> 6d1ddf658c25
Step 4/14 : RUN rm -rfv /etc/yum.repos.d/*
---> Using cache
---> 6a228b86827e
Step 5/14 : ADD local.repo /etc/yum.repos.d/ ---> Using cache
---> 68cd0048ecc7
Step 6/14 : RUN yum install -y MariaDB-server expect net-tools
---> Using cache
---> dbf601e719e3
Step 7/14 : RUN yum clean all ---> Using cache
---> 0508690b35f5
Step 8/14 : COPY gpmall.sql /opt/ ---> Using cache
---> 617904a55aa2
Step 9/14 : ADD mysql_init.sh /opt/ ---> Using cache
---> 80e1373d25f2
Step 10/14 : RUN chmod +x /opt/mysql_init.sh
---> Using cache
---> 3d970f66be13
Step 11/14 : RUN /opt/mysql_init.sh
---> Using cache
---> d47f24b255a8
Step 12/14 : ENV LC_ALL en_US.UTF-8
---> Using cache
---> 4b4b6dde5062
Step 13/14 : EXPOSE 33067
---> Using cache
---> 5f755d3f324f
Step 14/14 : CMD ["mysqld_safe"]
---> Using cache
---> 6c3bbd33bd7b
Successfully built 6c3bbd33bd7b
Successfully tagged gpmall-mariadb:v1.0
查看镜像列表:
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
gpmall-mariadb v1.0 6c3bbd33bd7b 28 seconds ago 1.06GB
5.ZooKeeper 容器化部署
(1)编写 Dockerfile
编写 Dockerfile 文件:
[root@master gpmall]# cat Dockerfile-zookeeper
FROM centos:centos7.5.1804
MAINTAINER Chinaskill
# 配置 yum 源
ADD gpmall.tar /opt
RUN rm -rfv /etc/yum.repos.d/* ADD local.repo /etc/yum.repos.d/
# 安装 JDK
RUN yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
ENV work_path /usr/local
WORKDIR $work_path8# 安装 ZooKeeper
ADD zookeeper-3.4.14.tar.gz /usr/local
ENV ZOOKEEPER_HOME /usr/local/zookeeper-3.4.14
# PATH
ENV PATH$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$ZOOKEEPER_HOME/bin
RUN cp$ZOOKEEPER_HOME/conf/zoo_sample.cfg $ZOOKEEPER_HOME/conf/zoo.cfgEXPOSE 2181# 设置开机自启
CMD $ZOOKEEPER_HOME/bin/zkServer.sh start-foreground
(2)构建镜像
构建镜像 gpmall-zookeeper:v1.0:
[root@master gpmall]# docker build -t gpmall-zookeeper:v1.0 -f Dockerfile-zookeeper . Sending build context to Docker daemon 507.6MB
Step 1/14 : FROM centos:centos7.5.1804
---> cf49811e3cdb
Step 2/14 : MAINTAINER Chinaskill ---> Using cache
---> 612224da592d
Step 3/14 : ADD gpmall.tar /opt ---> Using cache
---> 6d1ddf658c25
Step 4/14 : RUN rm -rfv /etc/yum.repos.d/*
---> Using cache
---> 6a228b86827e
Step 5/14 : ADD local.repo /etc/yum.repos.d/ ---> Using cache
---> 68cd0048ecc7
9
Step 6/14 : RUN yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel ---> Using cache
---> 2fd39963721f
Step 7/14 : ENV work_path /usr/local ---> Using cache
---> 3fdc92bc1ed1
Step 8/14 : WORKDIR $work_path
---> Using cache
---> c072b5dab01f
Step 9/14 : ADD zookeeper-3.4.14.tar.gz /usr/local ---> Using cache
---> 41eac879569f
Step 10/14 : ENV ZOOKEEPER_HOME /usr/local/zookeeper-3.4.14
---> Using cache
---> 3d875f5082d4
Step 11/14 : ENV PATH$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$ZOOKEEPER_HOME/bin
---> Using cache
---> 7875d2c65d28
Step 12/14 : RUN cp$ZOOKEEPER_HOME/conf/zoo_sample.cfg$ZOOKEEPER_HOME/conf/zoo.cfg
---> Using cache
---> d0c5f717cd0b
Step 13/14 : EXPOSE 2181
---> Using cache
---> c74c0223d17e
Step 14/14 : CMD $ZOOKEEPER_HOME/bin/zkServer.sh start-foreground
---> Using cache
---> df75e640384d
Successfully built df75e640384d
10
Successfully tagged gpmall-zookeeper:v1.0
查看镜像列表:
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
gpmall-zookeeper v1.0 1791a788e338 2 minutes ago 740MB
期待下次的分享,别忘了三连支持博主呀~
我是 念舒_C.ying ,期待你的关注~💪💪💪
版权归原作者 念舒_C.ying 所有, 如有侵权,请联系我们删除。