笔记
【摘要】 创建数据库容器镜像 vi Dockerfile FROM centos:centos7.5.1804 RUN rm -rf /etc/yum.repos.d/* COPY yum.repo /etc/yum.repos.d/ COPY mysql.sh /root/ COPY start.sh /root/ COPY my.cnf /etc/ COPY gpmall.sql /...
创建数据库容器镜像
vi Dockerfile
FROM centos:centos7.5.1804
RUN rm -rf /etc/yum.repos.d/*
COPY yum.repo /etc/yum.repos.d/
COPY mysql.sh /root/
COPY start.sh /root/
COPY my.cnf /etc/
COPY gpmall.sql /root/
RUN /root/mysql.sh
CMD ["/root/start.sh"]
EXPOSE 3306
vi mysql.sh
#!/bin/bash
yum install mariadb mariadb-server -y
mysql_install_db --user=mysql
sleep 5
mysqld_safe &
sleep 5
mysql -e "create database gpmall;grant all privileges on *.* to 'root'@'%' identified by '123456'"
mysql -u root gpmall < /root/gpmall.sql
mysql -e "use mysql;update user set password=password('123456') where user='root';flush privileges"
vi my.cnf
[client-server]
[mysqld]
symbolic-links=0
default-storage-engine = innodb
innodb_file_per_table
collation-server = utf8_general_ci
init-connect = 'SET NAMES utf8'
character-set-server = utf8
max_connections=10000
!includedir /etc/my.cnf.d
vi yum.repo
[mariadb]
name=mariadb
baseurl=ftp://192.168.1.110/yum/paas/ChinaskillMall/gpmall-repo
gpgcheck=0
enabled=1
[centos]
name=centos
baseurl=ftp://192.168.1.110/yum/centos
gpgcheck=0
enabled=1
创建Redis容器
vi Dockerfile
FROM centos:centos7.5.1804
RUN rm -rf /etc/yum.repos.d/*
COPY yum.repo /etc/yum.repos.d/
RUN yum install redis -y && 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
CMD ["redis-server","/etc/redis.conf"]
EXPOSE 6379
vi yum.repo
[mariadb]
name=mariadb
baseurl=ftp://192.168.1.110/yum/paas/ChinaskillMall/gpmall-repo
gpgcheck=0
enabled=1
[centos]
name=centos
baseurl=ftp://192.168.1.110/yum/centos
gpgcheck=0
enabled=1
创建zookeeper容器
vi Dockerfile
FROM centos:centos7.5.1804
ADD zookeeper-3.4.14.tar.gz /opt/
ADD jdk-8u77-linux-x64.tar.gz /opt/
RUN cp /opt/zookeeper-3.4.14/conf/zoo_sample.cfg /opt/zookeeper-3.4.14/conf/zoo.cfg
ENV JAVA_HOME /opt/jdk1.8.0_77
ENV CLASSPATH .:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV PATH $JAVA_HOME/bin:$PATH
CMD ["/opt/zookeeper-3.4.14/bin/zkServer.sh","start-foreground"]
EXPOSE 2181
创建nginx容器
vi Dockerfile
FROM centos:centos7.5.1804
RUN rm -rf /etc/yum.repos.d/*
COPY start.sh /root/
COPY yum.repo /etc/yum.repos.d/
RUN yum install nginx -y
ADD nginx.tar /usr/share/nginx/html/
CMD ["/root/start.sh"]
EXPOSE 80
vi yum.repo
[mariadb]
name=mariadb
baseurl=ftp://192.168.1.110/yum/paas/ChinaskillMall/gpmall-repo
gpgcheck=0
enabled=1
[centos]
name=centos
baseurl=ftp://192.168.1.110/yum/centos
gpgcheck=0
enabled=1
vi /etc/nginx/nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
upstream userlogin {
server jar1.mall:8082;
server jar2.mall:8082;
}
upstream shop {
server jar1.mall:8081;
server jar2.mall:8081;
}
include /etc/nginx/conf.d/*.conf; log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
}
vi /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /user/login {
proxy_pass http://userlogin;
}
location /shopping {
proxy_pass http://shop;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
vi start.sh
#!/bin/bash
nginx -g 'daemon off;'
创建kafka容器
vi Dockerfile
FROM centos:centos7.5.1804
MAINTAINER chjy090
ADD jdk-8u77-linux-x64.tar.gz /opt/
ADD kafka_2.11-1.1.1.tgz /opt/
ENV JAVA_HOME=/opt/jdk1.8.0_77
ENV CLASSPATH=.:$JAVA_HOME/lib/bt.jar:$JAVA_HOME/lib/tools.jar
ENV PATH=$JAVA_HOME/bin:$PATH
RUN sed -i "s/zookeeper.connect=localhost:2181/zookeeper.connect=zk.mall:2181/g" /opt/kafka_2.11-1.1.1/config/server.properties
CMD ["/opt/kafka_2.11-1.1.1/bin/kafka-server-start.sh","/opt/kafka_2.11-1.1.1/config/server.properties"]
EXPOSE 9092
创建jar容器
vi Dockerfile
FROM centos:centos7.5.1804
ADD jdk-8u77-linux-x64.tar.gz /opt/
ENV JAVA_HOME /opt/jdk1.8.0_77
ENV CLASSPATH .:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV PATH $JAVA_HOME/bin:$PATH
COPY gpmall-shopping-0.0.1-SNAPSHOT.jar /app/
COPY gpmall-user-0.0.1-SNAPSHOT.jar /app/
COPY shopping-provider-0.0.1-SNAPSHOT.jar /app/
COPY user-provider-0.0.1-SNAPSHOT.jar /app/
COPY start.sh /root/
CMD ["bash","/root/start.sh"]
vi start.sh
/bin/bash
echo 192.168.1.19 mysql.mall >> /etc/hosts
java -Xmx200m -jar /app/shopping-provider-0.0.1-SNAPSHOT.jar | grep --line-buffer "JVM running for" | while read a ; do
java -Xmx200m -jar /app/user-provider-0.0.1-SNAPSHOT.jar | grep --line-buffer "JVM running for" | while read b ; do
java -Xmx200m -jar /app/gpmall-shopping-0.0.1-SNAPSHOT.jar | grep --line-buffer "JVM running for" | while read c ; do
java -Xmx200m -jar /app/gpmall-user-0.0.1-SNAPSHOT.jar
done
done
done
编排模板
vi docker-compose
version: "3.8"
services:
redis.mall1:
image: redis_mall
expose:
- 6379
container_name: redis.mall1
restart: always
redis.mall2:
image: redis_mall
expose:
- 6379
container_name: redis.mall2
restart: always
zk1.mall1:
image: zookeeper_mall
expose:
- 2181
container_name: zk1.mall1
restart: always
zk1.mall2:
image: zookeeper_mall
expose:
- 2181
container_name: zk1.mall2
restart: always
kafka1.mall1:
image: kafka_mall
expose:
- 9092
container_name: kafka1.mall1
environment:
KAFKA_ADVERTISED_HOST_NAME: kafka1.mall
links:
- "zk1.mall1:zk1.mall"
restart: always
kafka1.mall2:
image: kafka_mall
expose:
- 9092
container_name: kafka1.mall2
environment:
KAFKA_ADVERTISED_HOST_NAME: kafka2.mall
links:
- "zk1.mall2:zk1.mall"
restart: always
mysql.mall:
image: mysql_mall
ports:
- "8066:3306"
container_name: mysql.mall
restart: always
jar1.mall:
image: jar_mall
expose:
- 8081
- 8082
container_name: jar1.mall
links:
- "zk1.mall1:zk1.mall"
- "kafka1.mall1:kafka1.mall"
- "redis.mall1:redis.mall"
depends_on:
- zk1.mall1
- kafka1.mall1
- mysql.mall
- redis.mall1
restart: always
jar2.mall:
image: jar_mall
expose:
- 8081
- 8082
container_name: jar2.mall
links:
- "zk1.mall2:zk1.mall"
- "kafka1.mall2:kafka1.mall"
- "redis.mall2:redis.mall"
depends_on:
- redis.mall2
- zk1.mall2
- kafka1.mall2
- mysql.mall
restart: always
nginx.mall:
image: nginx_mall
ports:
- "835:80"
container_name: nginx.mall
links:
- jar1.mall
- jar2.mall
depends_on:
- jar1.mall
- jar2.mall
restart: always
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)