一,容器化部署jar
其中需要用到的包有:
gpmall-shopping-0.0.1-SNAPSHOT.jar,
jdk-8u77-linux-x64.tar.gz,gpmall-user-0.0.1-SNAPSHOT.jar,
shopping-provider-0.0.1-SNAPSHOT.jar,
user-provider-0.0.1-SNAPSHOT.jar,
Dockerfile,ftp.repo,start.sh
1.Dockerfile:
FROM 10.211.55.10/library/centos:centos7.5.1804
MAINTAINER Chinaskill
RUN rm -rvf /etc/yum.repos.d/*
ADD ftp.repo /etc/yum.repos.d/
#RUN yum install -y java-1.8.0
ADD jdk-8u77-linux-x64.tar.gz /opt
ENV JAVA_HOME=/opt/jdk1.8.0_77
ENV JRE_HOME=${JAVA_HOME}/jre
ENV CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
ENV PATH=${JAVA_HOME}/bin:$PATH
ADD gpmall-shopping-0.0.1-SNAPSHOT.jar /opt/
ADD gpmall-user-0.0.1-SNAPSHOT.jar opt/
ADD shopping-provider-0.0.1-SNAPSHOT.jar /opt/
ADD user-provider-0.0.1-SNAPSHOT.jar /opt/
ADD start.sh /start.sh
RUN chmod +x /start.sh
EXPOSE 8081
EXPOSE 8082
EXPOSE 20880
EXPOSE 20881
EXPOSE 9090
CMD ["bash","/start.sh"]
2.ftp.repo
[gpmall]
name=gpmall
baseurl=ftp://10.211.55.10/gpmall-repo
gpgcheck=0
nabled=1
[centos]
name=centos
baseurl=ftp://10.211.55.10/centos
gpgcheck=0
enabled=1
3.start.sh
#!/bin/bash
sleep 5
nohup java -jar /opt/shopping-provider-0.0.1-SNAPSHOT.jar &
sleep 30
nohup java -jar /opt/user-provider-0.0.1-SNAPSHOT.jar &
sleep 30
nohup java -jar /opt/gpmall-shopping-0.0.1-SNAPSHOT.jar &
sleep 30
nohup java -jar /opt/gpmall-user-0.0.1-SNAPSHOT.jar &
sleep 30
while [[ true ]]; do
sleep 1
done
二,容器化部署Kafka
1.需要用到的包有kafka_2.11-1.1.1.tgz和Dockerfile,ftp.repo
1.Dockerfile
FROM 10.211.55.10/library/centos:centos7.5.1804
MAINTAINER Chinaskill
RUN rm -rvf /etc/yum.repos.d/*
COPY ftp.repo /etc/yum.repos.d/local.repo
RUN yum -y install java-1.8.0
ADD kafka_2.11-1.1.1.tgz /usr/local
ENV KAFKA_HOME /usr/local/kafka_2.11-1.1.1
RUN sed -i 's/localhost:2181/zk1.mall:2181,zk2.mall:2181,zk3.mall:2181/g' /usr/local/kafka_2.11-1.1.1/config/server.properties
EXPOSE 9092
ENTRYPOINT [ "/usr/local/kafka_2.11-1.1.1/bin/kafka-server-start.sh", "/usr/local/kafka_2.11-1.1.1/config/server.properties" ]
2.ftp.repo
[gpmall]
name=gpmall
baseurl=ftp://10.211.55.10/gpmall-repo
gpgcheck=0
nabled=1
[centos]
name=centos
baseurl=ftp://10.211.55.10/centos
gpgcheck=0
enabled=1
三,容器化部署mariadb
1,其中配置文件有Dockerfile ftp.repo gpmall.sql init.sh
1.Dockerfile:
FROM 10.211.55.10/library/centos:centos7.5.1804
MAINTAINER Chinaskill
RUN rm -rvf /etc/yum.repos.d/*
ADD ftp.repo /etc/yum.repos.d/
ADD gpmall.sql /root/
RUN yum install -y mariadb-server
RUN sed -i "13cport = 8066" /etc/my.cnf.d/server.cnf
ADD init.sh /root/init.sh
RUN chmod +x /root/init.sh
RUN /root/init.sh
ENV LC_ALL en_US.UTF-8
EXPOSE 3306
EXPOSE 8066
CMD ["mysqld_safe"]
2.ftp.repo
[gpmall]
name=gpmall
baseurl=ftp://10.211.55.10/gpmall-repo
gpgcheck=0
nabled=1
[centos]
name=centos
baseurl=ftp://10.211.55.10/centos
gpgcheck=0
enabled=1
3.init.sh
#!/bin/bash
mysql_install_db --user=mysql
mysqld_safe &
sleep 3s
mysqladmin -u root password '123456'
sleep 3s
mysql -uroot -p123456 -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456'"
sleep 3s
mysql -uroot -p123456 -e "create database gpmall;use gpmall;"
mysql -uroot -p123456 gpmall < /root/gpmall.sql
四,容器化部署nginx
1.其中配置文件有dist Dockerfile ftp.repo
1.Dockerfile:
FROM 10.211.55.10/library/centos:centos7.5.1804
MAINTAINER Chinaskill
RUN rm -rvf /etc/yum.repos.d/*
ADD ftp.repo /etc/yum.repos.d/
RUN yum install nginx -y
RUN sed -i '12ilocation /user {proxy_pass http://jar:8082;}' /etc/nginx/conf.d/default.conf
RUN sed -i '12ilocation /shopping {proxy_pass http://jar:8081;}' /etc/nginx/conf.d/default.conf
RUN rm -rf /usr/share/nginx/html/*
ADD dist/ /usr/share/nginx/html/
EXPOSE 80
CMD ["nginx","-g","daemon off;"]
2.ftp.repo
[gpmall]
name=gpmall
baseurl=ftp://10.211.55.10/gpmall-repo
gpgcheck=0
nabled=1
[centos]
name=centos
baseurl=ftp://10.211.55.10/centos
gpgcheck=0
enabled=1
五,容器化部署redis
1,配置文件有Dockerfile ftp.repo
1.Dockerfile
FROM 10.211.55.10/library/centos:centos7.5.1804
MAINTAINER Chinaskill
RUN rm -rvf /etc/yum.repos.d/*
COPY ftp.repo /etc/yum.repos.d/local.repo
RUN yum clean all
RUN yum list
RUN yum -y install redis
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
RUN sed -i -e 's@daemonize yes@daemonize no@g' /etc/redis.conf
EXPOSE 6379
#ENTRYPOINT ["/usr/bin/redis-server","/etc/redis.conf"]
ENTRYPOINT redis-server /etc/redis.conf
CMD ["redis-server"]
2.ftp.repo
[gpmall]
name=gpmall
baseurl=ftp://10.211.55.10/gpmall-repo
gpgcheck=0
nabled=1
[centos]
name=centos
baseurl=ftp://10.211.55.10/centos
gpgcheck=0
enabled=1
六,容器化部署zookeeper
1,配置文件有zookeeper-3.4.14.tar.gz,Dockerfile,ftp.repo
1.Dockerfile
FROM 10.211.55.10/library/centos:centos7.5.1804
MAINTAINER Chinaskill
RUN rm -rvf /etc/yum.repos.d/*
COPY ftp.repo /etc/yum.repos.d/local.repo
RUN yum -y install java-1.8.0
ADD zookeeper-3.4.14.tar.gz /usr/local
ENV ZOOKEEPER_HOME /usr/local/zookeeper-3.4.14
ENV PATH $PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$ZOOKEEPER_HOME/bin
EXPOSE 2181
EXPOSE 2888
EXPOSE 3888
CMD $ZOOKEEPER_HOME/bin/zkServer.sh start-foreground
2.ftp.repo
[gpmall]
name=gpmall
baseurl=ftp://10.211.55.10/gpmall-repo
gpgcheck=0
nabled=1
[centos]
name=centos
baseurl=ftp://10.211.55.10/centos
gpgcheck=0
enabled=1
七,商城编排部署yaml文件
1,docker-compose.yaml
2,zookeeper1,zookeeper2,zookeeper3
1.docker-compose.yaml
version: '2'
services:
zk1.mall:
image: 10.211.55.10/library/chinaskillmall-zookeeper:v1.1
restart: always
expose:
- 2181
- 2888
- 3888
volumes:
- ./zookeeper1/conf:/usr/local/zookeeper-3.4.14/conf
- ./zookeeper1/data:/data
zk2.mall:
image: 10.211.55.10/library/chinaskillmall-zookeeper:v1.1
restart: always
expose:
- 2181
- 2888
- 3888
volumes:
- ./zookeeper2/conf:/usr/local/zookeeper-3.4.14/conf
- ./zookeeper2/data:/data
zk3.mall:
image: chinaskillmall-zookeeper:v1.1
restart: always
expose:
- 2181
- 2888
- 3888
volumes:
- ./zookeeper3/conf:/usr/local/zookeeper-3.4.14/conf
- ./zookeeper3/data:/data
kafka1.mall:
image: 10.211.55.10/library/chinaskillmall-kafka:v1.1
restart: always
expose:
- 9092
links:
- zk1.mall
- zk2.mall
- zk3.mall
redis.mall:
image: 10.211.55.10/library/chinaskillmall-redis:v1.1
expose:
- 6379
mysql.mall:
image: 10.211.55.10/library/chinaskillmall-mysql:v1.1
expose:
- 8066
nginx:
image: 10.211.55.10/library/chinaskillmall-nginx:v1.1
restart: always
ports:
- "80:80"
links:
- jar
jar:
image: 10.211.55.10/library/chinaskillmall-jar:v1.1
links:
- kafka1.mall
- mysql.mall
- redis.mall
- zk1.mall
- zk2.mall
- zk3.mall
expose:
- 8081
- 8082
- 20880
- 20881
- 9090
2.zookeeper1(conf,data)
1.conf(configuration.xsl log4j.properties zoo.cfg)
(1)configuration.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:template match="configuration">
<html>
<body>
<table border="1">
<tr>
<td>name</td>
<td>value</td>
<td>description</td>
</tr>
<xsl:for-each select="property">
<tr>
<td><a name="{name}"><xsl:value-of select="name"/></a></td>
<td><xsl:value-of select="value"/></td>
<td><xsl:value-of select="description"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
(2) log4j.properties
# Define some default values that can be overridden by system properties
zookeeper.root.logger=INFO, CONSOLE
zookeeper.console.threshold=INFO
zookeeper.log.dir=.
zookeeper.log.file=zookeeper.log
zookeeper.log.threshold=DEBUG
zookeeper.tracelog.dir=.
zookeeper.tracelog.file=zookeeper_trace.log
#
# ZooKeeper Logging Configuration
#
# Format is "<default threshold> (, <appender>)+
# DEFAULT: console appender only
log4j.rootLogger=${zookeeper.root.logger}
# Example with rolling log file
#log4j.rootLogger=DEBUG, CONSOLE, ROLLINGFILE
# Example with rolling log file and tracing
#log4j.rootLogger=TRACE, CONSOLE, ROLLINGFILE, TRACEFILE
#
# Log INFO level and above messages to the console
#
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=${zookeeper.console.threshold}
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n
#
# Add ROLLINGFILE to rootLogger to get log file output
# Log DEBUG level and above messages to a log file
log4j.appender.ROLLINGFILE=org.apache.log4j.RollingFileAppender
log4j.appender.ROLLINGFILE.Threshold=${zookeeper.log.threshold}
log4j.appender.ROLLINGFILE.File=${zookeeper.log.dir}/${zookeeper.log.file}
# Max log file size of 10MB
log4j.appender.ROLLINGFILE.MaxFileSize=10MB
# uncomment the next line to limit number of backup files
#log4j.appender.ROLLINGFILE.MaxBackupIndex=10
log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.ROLLINGFILE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n
#
# Add TRACEFILE to rootLogger to get log file output
# Log DEBUG level and above messages to a log file
log4j.appender.TRACEFILE=org.apache.log4j.FileAppender
log4j.appender.TRACEFILE.Threshold=TRACE
log4j.appender.TRACEFILE.File=${zookeeper.tracelog.dir}/${zookeeper.tracelog.file}
log4j.appender.TRACEFILE.layout=org.apache.log4j.PatternLayout
### Notice we are including log4j's NDC here (%x)
log4j.appender.TRACEFILE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L][%x] - %m%n
(3) zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/data
clientPort=2181
server.1=zk1.mall:2888:3888
server.2=zk2.mall:2888:3888
server.3=zk3.mall:2888:3888
总结
这个其实有点难,想要完全自己会编写还需扎实的基础