基于docker-compose编排部署pig微服务快速开发框架

Pig微服务目录

      • 基于docker-compose编排部署Pig微服务快速开发框架
        • 1.规划节点
        • 2.基础准备
        • 案例实施
          • 1.基础环境准备
            • (1)上传软件包
          • 2.容器化部署MariaDB
            • (1)编写Dockerfile
            • (2)构建镜像
          • 3.容器化部署Redis
            • (1)编写Dockerfile
            • (2)构建镜像
          • 4.容器化部署Pig
            • (1)编写Dockerfile
            • (2)构建镜像
          • 5.容器化部署前端服务
            • (1)编写Dockerfile
            • (2)构建镜像
          • 6.编排部署Pig快速开发平台
            • (1)编写docker-compose.yaml
            • (2)部署服务

基于docker-compose编排部署Pig微服务快速开发框架

1.规划节点
IP 主机名 节点
192.168.100.10 master docker-compose节点
2.基础准备

将软件包上传至master节点/root目录下

案例实施
1.基础环境准备
(1)上传软件包
[root@k8s-master-node1 ~]# ls
anaconda-ks.cfg  chinaskills_cloud_paas_v2.0.2.iso  Pig.tar.gz
[root@k8s-master-node1 ~]# tar -zxvf Pig.tar.gz 

导入Centos:7.9.2009镜像

[root@k8s-master-node1 ~]# docker load -i Pig/CentOS_7.9.2009.tar 

查看集群状态

[root@k8s-master-node1 ~]# kubectl cluster-info
Kubernetes control plane is running at https://apiserver.cluster.local:6443
CoreDNS is running at https://apiserver.cluster.local:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
2.容器化部署MariaDB
(1)编写Dockerfile

编写mysql_init.sh脚本

[root@k8s-master-node1 ~]# cd Pig/
[root@k8s-master-node1 Pig]# vi mysql_init.sh 
#!/bin/bash
mysql_install_db --user=root
mysqld_safe --user=root &
sleep 8
mysqladmin -uroot password 'root'
mysql -uroot -proot -e "grant all on *.* to identified by 'root';flush privileges;"
mysql -uroot -proot -e "source /opt/pig_codegen.sql;source /opt/pig_config.sql;source /opt/pig_job.sql;source /opt/pig.sql;"

编写Yum源

[root@k8s-master-node1 Pig]# vi local.repo 
[pig]
name=pig
baseurl=file:///root/yum
gpgcheck=0
enabled=1

编写Dockerfile文件

[root@k8s-master-node1 Pig]# vi Dockerfile-mysql 
FROM centos:centos7.9.2009
MAINTAINER CSQ
RUN rm -rf /etc/yum.repos.d/*
COPY local.repo /etc/yum.repos.d/
COPY yum /root/yum
ENV LC_ALL en_US.UTF-8
RUN yum install -y mariadb-server
COPY mysql /opt/
COPY mysql_init.sh /opt/
RUN bash /opt/mysql_init.sh
EXPOSE 3306
CMD ["mysqld_safe","--user=root"]
(2)构建镜像
[root@k8s-master-node1 Pig]# docker build -t pig-mysql:v1.0 -f Dockerfile-mysql .
3.容器化部署Redis
(1)编写Dockerfile
[root@k8s-master-node1 Pig]# vi Dockerfile-redis
FROM centos:centos7.9.2009
MAINTAINER CSQ
RUN rm -rf /etc/yum.repos.d/*
COPY local.repo /etc/yum.repos.d/
COPY yum /root/yum
RUN yum install -y redis
RUN sed -i 's/127.0.0.1/0.0.0.0/g' /etc/redis.conf && \
    sed -i 's/protected-mode yes/protected-mode no/g' /etc/redis.conf
EXPOSE 6379
CMD ["/usr/bin/redis-server","/etc/redis.conf"]
(2)构建镜像
[root@k8s-master-node1 Pig]# docker build -t pig-redis:v1.0 -f Dockerfile-redis .
4.容器化部署Pig
(1)编写Dockerfile

编写启动文件

[root@k8s-master-node1 Pig]# vi pig_init.sh 
#!/bin/bash
nohup java -jar /root/pig-register.jar $JAVA_OPTS >/dev/null 2>&1 &
sleep 8
nohup java -jar /root/pig-gateway.jar $JAVA_OPTS >/dev/null 2>&1 &
sleep 8
nohup java -jar /root/pig-auth.jar $JAVA_OPTS >/dev/null 2>&1 &
sleep 8
nohup java -jar /root/pig-upms.jar &JAVA_OPTS >/dev/null 2>&1 

编写Dockerfile文件

[root@k8s-master-node1 Pig]# vi Dockerfile-pig 
FROM centos:centos7.9.2009
MAINTAINER CSQ
RUN rm -rf /etc/yum.repos.d/*
COPY local.repo /etc/yum.repos.d/
COPY yum /root/yum
ADD service /root/
RUN yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
COPY pig_init.sh /root/
RUN chmod +x /root/pig_init.sh
CMD ["/bin/bash","/root/pig_init.sh"]
(2)构建镜像
[root@k8s-master-node1 Pig]# docker build -t pig-service:v1.0 -f Dockerfile-pig .
5.容器化部署前端服务
(1)编写Dockerfile
[root@k8s-master-node1 Pig]# vi Dockerfile-nginx
FROM centos:centos7.9.2009
MAINTAINER CSQ
RUN rm -rf /etc/yum.repos.d/*
COPY local.repo /etc/yum.repos.d/
COPY yum /root/yum
RUN yum install -y nginx
COPY nginx/dist /data
COPY nginx/pig-ui.conf /etc/nginx/conf.d/
RUN /bin/bash -c 'echo init ok'
EXPOSE 80
CMD ["nginx","-g","daemon off;"]

(2)构建镜像
[root@k8s-master-node1 Pig]# docker build -t pig-nginx:v1.0 -f Dockerfile-nginx .
6.编排部署Pig快速开发平台
(1)编写docker-compose.yaml
[root@k8s-master-node1 Pig]# vi docker-compose.yaml 
version: '2'
services:
 pig-mysql:
  environment:
   MYSQL_ROOT_PASSWORD: root
  restart: always
  image: pig-mysql:v1.0
  container_name: pig-mysql
  ports:
   - 3306:3306
  links:
   - pig-service:pig-register
 pig-redis:
  restart: always
  image: pig-redis:v1.0
  hostname: pig-redis
  container_name: pig-redis
  ports:
   - 6379:6379
  links:
   - pig-service:pig-register
 pig-service:
  restart: always
  image: pig-service:v1.0
  hostname: pig-service
  container_name: pig-service
  ports:
   - 8848:8848
   - 9999:9999
  extra_hosts:
   - pig-auth:127.0.0.1
   - pig-gateway:127.0.0.1 
   - pig-register:127.0.0.1
   - pig-upms:127.0.0.1
   - pig-hou:127.0.0.1
  stdin_open: true
  tty: true
  privileged: true
 pig-nginx:
  restart: always
  image: pig-nginx:v1.0
  container_name: pig-nginx
  ports:
   - 8888:80
  links:
   - pig-service:pig-gateway
(2)部署服务
[root@k8s-master-node1 Pig]# docker-compose up -d

查看服务

[root@k8s-master-node1 Pig]# docker-compose ps
NAME                COMMAND                  SERVICE             STATUS              PORTS
pig-mysql           "mysqld_safe --user=…"   pig-mysql           running             0.0.0.0:3306->3306/tcp, :::3306->3306/tcp
pig-nginx           "nginx -g 'daemon of…"   pig-nginx           running             0.0.0.0:8888->80/tcp, :::8888->80/tcp
pig-redis           "/usr/bin/redis-serv…"   pig-redis           running             0.0.0.0:6379->6379/tcp, :::6379->6379/tcp
pig-service         "/bin/bash /root/pig…"   pig-service         running             0.0.0.0:8848->8848/tcp, 0.0.0.0:9999->9999/tcp, :::8848->8848/tcp, :::9999->9999/tcp

等待几分钟,在浏览器上通过http://master_ip:8888访问Pig

基于docker-compose编排部署pig微服务快速开发框架_第1张图片

你可能感兴趣的:(容器云,docker,微服务,运维)