docker实现tomcat+jdk+msm

简介:

Docker容器

 docker版本      : 1.7.1

 系统    版本     :CentOS release 6.8 

 tomcat版本    :apache-tomcat-7.0.57

 memcache版本:yum安装


Docker 容器在运行里有些步骤出错会产生<none>之类的无效镜像,产生之后直接运行脚本

删除

[root@1xx tom]#cat kong.sh

#!/bin/bash

#

 

for I in `docker images | grep"<none>" | awk -F" " '{print $3}'`;do

     echo"none key name $I"

     dockerstop $I

     docker  rmi -f $I

     echo$keys

done

docker images

 

 

Tomcat 配置

[root@1xx tom]#cat Dockerfile

FROM centos                                                   #基础镜像来自于centos

MAINTAINER xiong <812374156@qq.com>  #作者信息

#安装ifconfig 类型工具

RUN yum -y install net-tools                                    

 

#ADD复制本地文件并自动解压至目录下

ADD apache-tomcat-7.0.57.tar.gz/usr/local/ 

 

运行软链接命令

RUN ln -sv /usr/local/apache-tomcat-7.0.57/usr/local/tomcat

 

定义tomcat环境变量值

ENV CATALINA_HOME /usr/local/tomcat

ENV PATH $PATH:$CATALINA_HOME/bin

 

#复制jdk文件到root目录并使用rpm命令安装

COPY jdk-7u79-linux-x64.rpm /root/

RUN rpm -ivh  /root/jdk-7u79-linux-x64.rpm

 

#定义java环境变量

ENV JAVA_HOME=/usr/java/latest

ENV PATH $PATH:$JAVA_HOME/bin

 

当机器运行里自动启动,此处可省略

RUN echo"/usr/local/tomcat/catalina.sh start" >> /etc/rc.d/rc.local

 

产先配置好server.xml文件然后直接复制到conf文件目录下

COPY server.xml /usr/local/tomcat/conf/

 

复制msm文件至lib文件下

COPY mem/* /usr/local/tomcat/lib/

 

运行启动catalina.sh脚本使用run 脚本在运行之后启动并打印debug信息在使用ctrl+p ctrl+q 运行容器,否则脚本运行后之后脚本会退出

CMD["catalina.sh","run"]

 

Msm下载

memcached session manager

https://github.com/magro/memcached-session-manager/wiki/SetupAndConfiguration

 

 memcached-session-manager-tc6-${version}.jar for tomcat6,

 memcached-session-manager-tc7-${version}.jar for tomcat7

(attention: tomcat 7.0.23+) or memcached-session-manager-tc8-${version}.jar for tomcat8.

 

下载需要注意版本信息      并且需要注意的是版本号需要对应一致否则有可能报错

javolution-5.4.3.1.jar          

memcached-session-manager-tc7-2.1.1.jar            

spymemcached-2.11.1.jar

memcached-session-manager-2.1.1.jar 

msm-javolution-serializer-2.1.1.jar                        #也可以选择其它

 

tomcat删除脚本

 [root@1xxtom]#cat del.sh

#!/bin/bash

#

docker rm -f tom{1..9}

docker rm -f mem{1..9}

docker rmi xiong

docker build -t xiong .

docker images

 

 

Memcached 配置

[root@1xx memcached]# cat Dockerfile

         FROMcentos                                                          #基础镜像来自于centos

MAINTAINER xiong812374156@qq.com        #作者信息

 

RUN yum -yinstall memcached net-tools        #安装mem以及ifconfig 类型工具

        

         #运行memcached命令,别使用daemon 脚本在运行完之后容器会自动退出

CMD["/usr/bin/memcached","-p","11211","-m","64","-c","1024","-u","root"]

 

Memcached删除脚本

         [root@1xxmemcached]# cat del.sh

#!/bin/bash

#

#

docker rm -f mem1

docker rmi mem

docker build -t mem .

 

 

 

 

 

 

 

配置完基础镜像运行容器,为方便我这里也定义了脚本

[root@1xx tom]#cat docktest.sh

#!/bin/bash

#

# docker 运行容器名称tom2 端口本地92 容器8080 数据卷本地xx/xx/tom2/ 容器/web/apps 基础镜像

docker run -it--name tom2 -p 92:8080 -v /root/tom/tom2:/web/apps/ xiong

docker run -it--name tom3 -p 93:8080 -v /root/tom/tom3:/web/apps/ xiong

 

#docker 运行容器名称m2m1 端口本地201 远端11211 基础镜像

docker run -it--name mem1 -p 201:11211 mem

docker run -it--name mem2 -p 202:11211 mem

 

docker ps

 

 

测试容器memcached是否运行成功 本地运行telnet

wKioL1ilFLDBMnTXAAAo4BUoDcc821.png-wh_50

 

容器tom2 session信息

wKiom1ilFJrwV4zbAAC3niGsd7c947.png-wh_50

JSESSIONID=A4B7390062C98E719D1CBF5C198F835D-n2

 

 

wKiom1ilFH3jTqDmAACpMmwzn3k170.png-wh_50

JSESSIONID=A4B7390062C98E719D1CBF5C198F835D-n2

 

 

验证

Session信息一致说明成功

 

 

Service.xml文件内容

 

[root@1xx tom]# cat server.xml

<?xmlversion='1.0' encoding='utf-8'?>

<!--

  Licensed to the Apache Software Foundation(ASF) under one or more

  contributor license agreements.  See the NOTICE file distributed with

  thiswork for additional information regarding copyright ownership.

  The ASF licenses this file to You under theApache License, Version 2.0

  (the "License"); you may not usethis file except in compliance with

  the License. You may obtain a copy of the License at

 

     http://www.apache.org/licenses/LICENSE-2.0

 

  Unless required by applicable law or agreedto in writing, software

  distributed under the License is distributedon an "AS IS" BASIS,

  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied.

  See the License for the specific languagegoverning permissions and

  limitations under the License.

-->

<!--Note:  A "Server" is not itselfa "Container", so you may not

     define subcomponents such as"Valves" at this level.

     Documentation at /docs/config/server.html

 -->

<Serverport="8005" shutdown="SHUTDOWN">

  <ListenerclassName="org.apache.catalina.startup.VersionLoggerListener" />

  <!-- Security listener. Documentation at/docs/config/listeners.html

  <ListenerclassName="org.apache.catalina.security.SecurityListener" />

  -->

  <!--APR library loader. Documentation at/docs/apr.html -->

  <ListenerclassName="org.apache.catalina.core.AprLifecycleListener"SSLEngine="on" />

  <!--Initialize Jasper prior to webapps areloaded. Documentation at /docs/jasper-howto.html -->

  <ListenerclassName="org.apache.catalina.core.JasperListener" />

  <!-- Prevent memory leaks due to use ofparticular java/javax APIs-->

  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>

  <ListenerclassName="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>

  <ListenerclassName="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>

 

  <!-- Global JNDI resources

       Documentation at/docs/jndi-resources-howto.html

  -->

  <GlobalNamingResources>

    <!-- Editable user database that canalso be used by

         UserDatabaseRealm to authenticateusers

    -->

    <Resource name="UserDatabase"auth="Container"

             type="org.apache.catalina.UserDatabase"

              description="User databasethat can be updated and saved"

             factory="org.apache.catalina.users.MemoryUserDatabaseFactory"

              pathname="conf/tomcat-users.xml"/>

  </GlobalNamingResources>

 

  <!-- A "Service" is a collectionof one or more "Connectors" that share

       a single "Container"Note:  A "Service" is notitself a "Container",

       so you may not define subcomponents suchas "Valves" at this level.

       Documentation at/docs/config/service.html

   -->

  <Service name="Catalina">

 

    <!--The connectors can use a sharedexecutor, you can define one or more named thread pools-->

    <!--

    <Executorname="tomcatThreadPool" namePrefix="catalina-exec-"

        maxThreads="150"minSpareThreads="4"/>

    -->

 

 

    <!-- A "Connector" representsan endpoint by which requests are received

         and responses are returned.Documentation at :

         Java HTTP Connector: /docs/config/http.html(blocking & non-blocking)

         Java AJP  Connector: /docs/config/ajp.html

         APR (HTTP/AJP) Connector:/docs/apr.html

         Define a non-SSL HTTP/1.1 Connector onport 8080

    -->

    <Connector port="8080"protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="8443"/>

    <!-- A "Connector" using theshared thread pool-->

    <!--

    <Connectorexecutor="tomcatThreadPool"

               port="8080"protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="8443"/>

    -->

    <!-- Define a SSL HTTP/1.1 Connector onport 8443

         This connector uses the BIOimplementation that requires the JSSE

         style configuration. When using theAPR/native implementation, the

         OpenSSL style configuration isrequired as described in the APR/native

         documentation -->

    <!--

    <Connector port="8443"protocol="org.apache.coyote.http11.Http11Protocol"

               maxThreads="150"SSLEnabled="true" scheme="https" secure="true"

               clientAuth="false"sslProtocol="TLS" />

    -->

 

    <!-- Define an AJP 1.3 Connector on port8009 -->

    <Connector port="8009"protocol="AJP/1.3" redirectPort="8443" />

 

 

    <!-- An Engine represents the entrypoint (within Catalina) that processes

         every request.  The Engine implementation for Tomcat standalone

         analyzes the HTTP headers includedwith the request, and passes them

         on to the appropriate Host (virtualhost).

         Documentation at/docs/config/engine.html -->

 

    <!-- You should set jvmRoute to supportload-balancing via AJP ie :

    <Engine name="Catalina"defaultHost="localhost" jvmRoute="jvm1">

    -->

    <Engine name="Catalina" defaultHost="localhost">

 

      <!--For clustering, please take a lookat documentation at:

          /docs/cluster-howto.html  (simple how to)

          /docs/config/cluster.html (referencedocumentation) -->

      <!--

      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>

      -->

 

      <!-- Use the LockOutRealm to preventattempts to guess user passwords

           via a brute-force attack -->

      <RealmclassName="org.apache.catalina.realm.LockOutRealm">

        <!-- This Realm uses theUserDatabase configured in the global JNDI

             resources under the key"UserDatabase".  Any edits

             that are performed against thisUserDatabase are immediately

             available for use by theRealm.  -->

        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"

              resourceName="UserDatabase"/>

      </Realm>

 

        <Host name="localhost"appBase="/web/apps" unpackWARs="true"autoDeploy="false">

        <Context path=""docBase="/web/apps/" reloadable="true" >

            <ManagerclassName="de.javakaffee.web.msm.MemcachedBackupSessionManager"

              memcachedNodes="n1:192.168.8.101:201,n2:192.168.8.101:202"

              failoverNodes="n1"

              storageKeyPrefix="context"

              requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"

              transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"

                />

    </Context>

        <ValveclassName="org.apache.catalina.valves.AccessLogValve"directory="/web/logs"

               prefix="app_access_log"suffix=".txt"

               pattern="%h %l %u %t&quot;%r&quot; %s %b" />

        </Host>

 

    </Engine>

  </Service>

</Server>

 

 

 

 

Tomcat数据卷中 tomcat 目录 index.jsp

[root@1xx tom]# cat tom2/index.jsp

<%@ page language="java" %>

<%@ page import="java.util.*"%>

<html>

       <head>

                <title>tom2</title>

       </head>

       <body>

                <% out.println("Hello,tom2."); %>

       </body>

</html>

 




     本文转自812374156 51CTO博客,原文链接:http://blog.51cto.com/xiong51/1898356,如需转载请自行联系原作者





相关文章
|
7月前
|
Java 关系型数据库 MySQL
在Linux平台上进行JDK、Tomcat、MySQL的安装并部署后端项目
现在,你可以通过访问http://Your_IP:Tomcat_Port/Your_Project访问你的项目了。如果一切顺利,你将看到那绚烂的胜利之光照耀在你的项目之上!
422 41
|
8月前
|
Oracle Java 关系型数据库
Tomcat和JDK的详细安装、下载和环境配置指南
以上就是JDK和Tomcat的下载、安装和环境配置的详细步骤。希望这个指南能帮助你顺利完成设置。
578 32
|
7月前
|
开发框架 Java 关系型数据库
在Linux系统中安装JDK、Tomcat、MySQL以及部署J2EE后端接口
校验时,浏览器输入:http://[your_server_IP]:8080/myapp。如果你看到你的应用的欢迎页面,恭喜你,一切都已就绪。
541 17
|
7月前
|
Java 关系型数据库 MySQL
在Linux操作系统上设置JDK、Tomcat、MySQL以及J2EE后端接口的部署步骤
让我们总结一下,给你的Linux操作系统装备上最强的军队,需要先后装备好JDK的弓箭,布置好Tomcat的阵地,再把MySQL的物资原料准备好,最后部署好J2EE攻城车,那就准备好进军吧,你的Linux军团,无人可挡!
172 18
|
7月前
|
关系型数据库 MySQL Java
安装和配置JDK、Tomcat、MySQL环境,以及如何在Linux下更改后端端口。
遵循这些步骤,你可以顺利完成JDK、Tomcat、MySQL环境的安装和配置,并在Linux下更改后端端口。祝你顺利!
489 11
|
7月前
|
开发框架 关系型数据库 Java
Linux操作系统中JDK、Tomcat、MySQL的完整安装流程以及J2EE后端接口的部署
然后Tomcat会自动将其解压成一个名为ROOT的文件夹。重启Tomcat,让新“植物”适应新环境。访问http://localhost:8080/yourproject看到你的项目页面,说明“植物”种植成功。
243 10
|
8月前
|
Java 关系型数据库 MySQL
JDK、Tomcat、MariaDB数据库和Profile多环境的配置与使用
以上就是JDK、Tomcat、MariaDB数据库和Profile多环境的配置与使用的基本步骤。这些步骤可能会因为你的具体需求和环境而有所不同,但是基本的思路是一样的。希望这些信息能够帮助你更好地理解和使用这些工具。
291 17
|
NoSQL 关系型数据库 应用服务中间件
docker基础篇:安装tomcat
docker基础篇:安装tomcat
348 64
|
11月前
|
监控 Java 应用服务中间件
tomcat相关概念与部署tomcat多实例-zabbix监控(docker部署)
通过上述步骤,您可以在Ubuntu系统上成功编译并安装OpenCV 4.8。这种方法不仅使您能够定制OpenCV的功能,还可以优化性能以满足特定需求。确保按照每一步进行操作,以避免常见的编译问题。
174 23
|
11月前
|
监控 Java 应用服务中间件
tomcat相关概念与部署tomcat多实例-zabbix监控(docker部署)
通过上述步骤,您可以在Ubuntu系统上成功编译并安装OpenCV 4.8。这种方法不仅使您能够定制OpenCV的功能,还可以优化性能以满足特定需求。确保按照每一步进行操作,以避免常见的编译问题。
276 25