In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Write at the front
1. For the method and process of building docker+k8s, please refer to the previous blog
two。 The architecture we use is the architectural pattern of duboo. All applications except tomcat and jar are launched to the virtual machine.
Start tomcat using the container
Because use the container to start the project, there must be a process running in the foreground, otherwise the container run will automatically exit. So we did a second build on the official image of tomcat and made some configurations of our own.
After the official image of tomcat starts the container, the log of tomcat is put to the foreground and printed out, and the log cannot be cut. The log is lost when the container exits. Let's solve these two problems.
Problem 1: log cutting
First compile and install the cronolog tool in the container. However, before installing cronolog, you need to install gcc software on the system. The official image provided by tomcat is very clean, and there is no need for gcc. We need to install gcc and make first.
Problem 2: solve the problem of log output in the foreground.
The official tomcat image starts the container in the way of catalina.sh run. In this way, the startup log is output directly to the foreground, which ensures that the container does not exit. But our goal is to keep the log locally.
Let's change the startup mode of tomcat and write a script for start.sh, which is as follows:
#! / bin/shsh / usr/local/tomcat/bin/startup.shtail-f / usr/local/tomcat/bin/catalina.sh
Because if you start tomcat using startup.sh directly, there will be no process running in the foreground, which will cause the container to exit, so we add a command called tail-f. Tail, just write one of those files.
This ensures that tomcat logs are cut and saved in the background.
The contents of the Dockerfile file are as follows:
FROM tomcat:7.0-slimLABEL maintainer= "ZhiYu Xin" ADD. / catalina.sh / usr/local/tomcat/bin/ADD. / cronolog-1.6.2.tar.gz / opt/ADD. / start.sh / usr/local/tomcat/bin/WORKDIR / opt/cronolog-1.6.2RUN echo "deb http://ftp.us.debian.org/debian/ jessie main contrib non-free" > >\ / etc/apt/sources.list & & echo "deb-src http://ftp. Us.debian.org/debian/ jessie main contrib non-free "\ > > / etc/apt/sources.list & & apt-get update-y & & apt-get install-y gcc-4.8 glossy usr/local/tomcat/bin/start.shEXPOSE 8080ENTRYPOINT 4.8 g++-4.8-multilib make & &\. / configure & & make & & make install & & chmod axix / usr/local/tomcat/bin/start.shEXPOSE 8080ENTRYPOINT [" / bin/sh " "/ usr/local/tomcat/bin/start.sh"]
Question 3: how to store the output log of the container directly to the host computer of docker.
We need to mount a volume to the / usr/local/tomcat/logs directory when starting the container.
It is best to create a corresponding directory locally before starting the container.
The yml of the launch container is as follows:
ApiVersion: apps/v1kind: Deploymentmetadata: name: tomcat labels: app: tomcatspec: replicas: 1 selector: matchLabels: app: tomcat template: metadata: labels: app: tomcatspec: # declare a volume for later use volumes:-name: "tomcat-log" hostPath: path: "/ data" containers:-name: tomcat1 Image: xinsir8/tomcat:v1 ports:-containerPort: 8080 # Mount a volume volumeMounts: # which directory to mount to-mountPath: / usr/local/tomcat/logs name: tomcat-log # Resource restrictions resources: requests: memory: "64Mi" cpu: " 250m "limits: memory:" 128Mi "cpu:" 500m "
Question 4: how to solve the network problem, the communication between nginx scheduling and tomcat, the communication between tomcat and jar, etc.
In fact, it is very simple to solve this problem, we can create a service to solve this problem. The yml file that creates the service is as follows
ApiVersion: v1kind: Servicemetadata: # service name name: tomcat-servicespec: # service type, including but not limited to [NodePort, ClusterIP, NodePort, LoadBalancer] type: NodePort ports: # container port-port: 8080 # mapped port nodePort: 31003 selector: # this service will be applied to all containers labeled app equal to tomcat app: tomcat
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.