设为首页 收藏本站
查看: 945|回复: 0

[经验分享] docker实现tomcat+jdk+msm

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2017-2-17 09:31:35 | 显示全部楼层 |阅读模式
Docker容器 docker版本      : 1.7.1
系统    版本     :CentOS release 6.8
tomcat版本    :apache-tomcat-7.0.57
memcache版本:yum安装

Docker 容器在运行里有些步骤出错会产生<none>之类的无效镜像,产生之后直接运行脚本
删除
[iyunv@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 配置[iyunv@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/memcach ... tupAndConfiguration

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删除脚本 [iyunv@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 配置[iyunv@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删除脚本         [iyunv@1xxmemcached]# cat del.sh
#!/bin/bash
#
#
docker rm -f mem1
docker rmi mem
docker build -t mem .







配置完基础镜像运行容器,为方便我这里也定义了脚本
[iyunv@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
QQ截图20170217092932.png

容器tom2号 session信息
QQ截图20170217092937.png
JSESSIONID=A4B7390062C98E719D1CBF5C198F835D-n2


QQ截图20170217092943.png
JSESSIONID=A4B7390062C98E719D1CBF5C198F835D-n2


验证Session信息一致说明成功


Service.xml文件内容

[iyunv@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


  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
[iyunv@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>



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-343263-1-1.html 上篇帖子: Docker的常规应用手册 下篇帖子: docker-swarm初探
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表