Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Docker K8s cluster deploys tomcat, using a single image to increase the reusability of the image.

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

As written above, k8s clusters have been set up. For specific steps, please see the previous article.

The Dockerfile file is written to create a common image, which is not required to be mirrored every time the tomcat is deployed directly.

# at first, I wanted to use the official image of tomcat, but the official image systems all use diban 8 system, because I want to do log cutting, I need to install cronolog software. # google and Baidu did not find out how to use apt-get to install, but can only use source code to install, but the installation process requires the support of gcc and make # if you don't operate on apt-get update, you can't install it. However, due to the backwardness of the system, the official or 163 or Tsinghua sources do not support it. In the end, I had no choice but to use the mirror of ubuntu 14. FROM ubuntu:14.04.5# tomcat installation directory ENV TOMCAT_HOME / usr/local/tomcat# here is the directory where you put the files in server.xml. This directory needs to make a hyperlink with server.xml in the tomcat/conf folder. Why? # because I want to mount the configuration file using configmap, if I mount it directly to the conf directory, then all the other files in the directory will be gone. So we mount the newly created directory while we are closed, and then do a hyperlink mapping. ENV SERVER_XML / configfile# configure jdk environment ENV JAVA_HOME/ opt/jdk1.7.0_21ENV JRE_HOME $JAVA_HOME/jreENV JAVA_BIN $JAVA_HOME/binENV CLASSPATH $CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/libENV PATH $TOMCAT_HOME/bin:$JAVA_BIN:$JAVA_HOME/jre/bin:$PATH:$HOME/bin# add jdk package to / opt directory ADD jdk-7u21-linux-x64.tar.gz / optADD apache-tomcat-7.0.77 .tar.gz / usr/localRUN ADD. / catalina.sh $TOMCAT_HOME/bin/ADD. / cronolog-1.6.2.tar.gz / opt/# this is a tomcat startup script written manually by yourself # the content is very simple, just two lines. The first line is to start tomcat and use sh / usr/local/tomcat/bin/startup.sh. # Container requires that there must be a process executed in the foreground so that the container will not exit, so just tail-f on the second line. & &\ rm-rf $TOMCAT_HOME/webapps/* & & rm-rf $TOMCAT_HOME/conf/server.xml & & mkdir $SERVER_XML & &\ touch $SERVER_XML/server.xml & & ln-s $SERVER_XML/server.xml $TOMCAT_HOME/conf/server.xmlEXPOSE 8080ENTRYPOINT ["/ bin/sh" "/ usr/local/tomcat/bin/start.sh"]

The contents of the configuration file you need are as follows:

Start.sh

#! / bin/shsh / usr/local/tomcat/bin/startup.shtail-f / usr/local/tomcat/bin/catalina.sh

Catalina.sh

# the above is consistent with the original tomcat default configuration file # 421 # touch "$CATALINA_OUT" 422 if ["$1" = "- security"]; then423 if [$have_tty-eq 1] Then424 echo "Using Security Manager" 425 fi426 shift427 eval $_ NOHUP "\" $_ RUNJAVA\ "\" $LOGGING_CONFIG\ "" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS\ 428-$JAVA_ENDORSED_DIRS\ "\ 429-classpath"\ "$CLASSPATH\"\ 430-Djava.security.manager\ 431-Djava.security.policy== "\" $CATALINA_BASE/conf/catalina. Policy\ ""\ 432-Dcatalina.base= "\" $CATALINA_BASE\ "\ 433-Dcatalina.home="\ "$CATALINA_HOME\"\ 434-Djava.io.tmpdir="\ "$CATALINA_TMPDIR\"\ 435 org.apache.catalina.startup.Bootstrap" $@ "start\ 436 > >" $CATALINA_OUT "2 > & 1" & "437 438 else439 eval $_ NOHUP"\ "$_ RUNJAVA\" "\" $LOGGING_CONFIG\ "" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS\ 440-$JAVA_ENDORSED_DIRS\ "\ 441-classpath"\ "$CLASSPATH\"442-Dcatalina.base="\ "$CATALINA_BASE\"\ 443-Dcatalina.home= "\" $CATALINA_HOME\ "\ 444-Djava.io.tmpdir="\ "$CATALINA_TMPDIR\"\ 445 org.

The following is a direct build image.

Create a server.xml file where configmap holds the tomcat.

Kubectl create configmap cm-server.xml-the absolute path of from-file='server.xml'

Write the yaml file of K8s

ApiVersion: apps/v1kind: Deploymentmetadata: name: dubbo-admin labels: app: dubbo-adminspec: replicas: 1 selector: matchLabels: app: dubbo-admin template: metadata: labels: app: dubbo-adminspec: # where we need to elaborate, we have created three volume Store the log of tomcat, Java project code and a tomcat configuration file (server.xml) volumes:-name: "code-war" hostPath: path: "/ Disk/data/tomcat/dubbo-admin/code/"-name: "tomcat-log" hostPath: path: "/ Disk/data/tomcat/dubbo-admin/log/"-name: " Serverxml "configMap: name: tomcat-dubbo-admin-server.xml items:-key: server.xml path: server.xml containers:-name: dubbo-admin # Container mounts 3 volume using the image image: fushuitong/tomcat:jdk7u21-tomcat7.0.77-cronolog1.6.2 ports:-containerPort: 8080 # just build The mount directory is as follows:-name: code-war mountPath: / usr/local/tomcat/webapps-name: tomcat-log mountPath: / usr/local/tomcat/logs-name: serverxml mountPath: / configfile

Just create this Deployment directly.

Create a service and put the port of tomcat on the node for external access. If there is a nginx in front of the tomcat, you can map it directly to clusterIP. You can forward it using nginx.

Changed the yaml file of service

ApiVersion: v1kind: Servicemetadata: name: dubbo-adminspec: ports:-port: 8080 nodePort: 32333 targetPort: dubbo-admin protocol: TCP selector: app: dubbo-admin type: NodePort

Finally, you can access the corresponding tomca project by accessing port 32333 of any node's ip.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report