从tomcat kubernetes容器中禁用localhost_access_log

kknvjkwl  于 2022-11-13  发布在  Kubernetes
关注(0)|答案(1)|浏览(178)

我有一个应用程序在一个Tomcat 9容器与Kubernetes。我想禁用localhost_access_log-yyy-mm-dd. txt从/usr/local/tomcat/logs。我知道有一种可能性,从server.xml注解这部分:

`<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />`

但是如果我尝试在Dockerfile中创建一个sed,并在启动容器时注解该部分,它将以Error状态结束。是否有可能在不接触server.xml的情况下创建此部分?

0yg35tkg

0yg35tkg1#

我不认为你真的需要用sed覆盖config,因为sed可能是纯停靠环境中的一种方式,但是当Kubernetes中的configmap有更好的选择时,为什么要sed呢?
从server.xml文件创建配置Map

kubectl create configmap server-config --from-file=server.xml

和服务器. xml

<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
  <GlobalNamingResources>
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>
  <Service name="Catalina">
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <Engine name="Catalina" defaultHost="localhost">
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
      </Host>
    </Engine>
  </Service>
</Server>

以及包含configmap卷的部署文件

apiVersion: apps/v1
kind: Deployment
metadata:
  name: tomcat-deployment
spec:
  selector:
    matchLabels:
      app: tomcat
  replicas: 1 
  template:
    metadata:
      labels:
        app: tomcat
    spec:
      containers:
      - name: tomcat
        image: tomcat:latest
        volumeMounts:
        - name: config-volume
          mountPath: /usr/local/tomcat/conf/
        ports:
        - containerPort: 8080
      volumes:
      - name: config-volume
        configMap:
          name: server-config

相关问题