您的位置:首页 > 运维架构 > Docker

docker实现tomcat+jdk+msm

2017-02-16 10:57 447 查看
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$keysdonedocker images

Tomcat 配置

[root@1xx tom]#cat Dockerfile
FROM centos #基础镜像来自于centosMAINTAINER 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/tomcatENV 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/latestENV 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 xiongdocker 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 mem1docker rmi memdocker 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




容器tom2号 session信息



JSESSIONID=A4B7390062C98E719D1CBF5C198F835D-n2




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"%r" %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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息