docker tomcat jvm 使用 visualVM监控

1.  建立基础镜像

FROM centos

MAINTAINER fengjian <fengjian@senyint.com>
ENV TZ "Asia/Shanghai"
ENV TERM xterm

ENV JAVA_HOME /data/jdk
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /data/tomcat
ENV CATALINA_BASE /data/tomcat
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin

RUN rm /etc/yum.repos.d/* -rf
ADD Centos-7.repo /etc/yum.repos.d/
ADD epel.repo /etc/yum.repos.d/
RUN yum clean all
RUN yum -y install unzip net-tools bind-utils sysstat  kde-l10n-Chinese telnet reinstall glibc-common

RUN  localedef -c -f UTF-8 -i zh_CN zh_CN.utf8   
          
ENV LC_ALL "zh_CN.UTF-8"  

ADD localtime  /etc/
ADD jdk.tar.gz /data
ADD tomcat.tar.gz /data
ADD profile /etc
ADD 20-nproc.conf /etc/security/limits.d/
ADD limits.conf /etc/security/
RUN mkdir -p /data/webserver
RUN mkdir -p /data/logs

 

2. tomcat/conf/catalina.sh 添加初始堆参数

JAVA_OPTS="$JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -server -Xms4096M -Xmx4096M -Xss512k -XX:+AggressiveOpts -XX:+UseBiasedLocking -XX:-UseCounterDecay -XX:+AlwaysPreTouch  -XX:+DisableExplicitGC -XX:MaxTenuringThreshold=31 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC  -XX:+CMSParallelRemarkEnabled -XX:LargePageSizeInBytes=128m  -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -Djava.awt.headless=true -XX:CMSInitiatingOccupancyFraction=75 -XX:MaxTenuringThreshold=6 -XX:+ExplicitGCInvokesConcurrent -XX:+ParallelRefProcEnabled -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=18999 -Dcom.sun.management.jmxremote.rmi.port=18999 -Dcom.sun.management.jmxremote.local.only=false -Djava.rmi.server.hostname=192.168.200.10"

**其中 Djava.rmi.server.hostname= 192.168.200.10 为宿主机的IP地址。

 

3. 加入应用

FROM 192.168.200.10/source/tomcat8_jdk1.8_test

MAINTAINER fengjian <fengjian@senyint.com.com>

ADD webserver.tar.gz /data/webserver/

EXPOSE 80 18999

CMD ["/data/tomcat/bin/catalina.sh","run"]

 

 

4. 运行应用docker

docker run -d --name 1111 -p 50001:80  -p 18999:18999 192.168.200.10/source/gateway_test_jvm

 

5. 使用visualVM监控

 

 

 

二,

 

2. tomcat/conf/catalina.sh 添加初始堆参数

JAVA_OPTS="$JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -server -Xms4096M -Xmx4096M -Xss512k -XX:+AggressiveOpts -XX:+UseBiasedLocking -XX:-UseCounterDecay -XX:+AlwaysPreTouch  -XX:+DisableExplicitGC -XX:MaxTenuringThreshold=31 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC  -XX:+CMSParallelRemarkEnabled -XX:LargePageSizeInBytes=128m  -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -Djava.awt.headless=true -XX:CMSInitiatingOccupancyFraction=75 -XX:MaxTenuringThreshold=6 -XX:+ExplicitGCInvokesConcurrent -XX:+ParallelRefProcEnabled -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=18999 -Dcom.sun.management.jmxremote.rmi.port=18999 -Dcom.sun.management.jmxremote.local.only=false -Djava.rmi.server.hostname=192.168.20.174"

**其中 Djava.rmi.server.hostname= 192.168.20.174 为宿主机的IP地址。

 

部署在k8s中,使用nodePort 指定端口,端口与jmxremote.port 相同

apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: gateway
  namespace: senyint
spec:
  selector:
    matchLabels:
      app: gateway
  replicas: 1
  template:
    metadata:
      labels:
        app: gateway
    spec:
      nodeName: node1   #指定部署到 node1 上 
      containers:
      - name: gateway
        image: 192.168.200.10/source/gateway_test_jvm
        resources:
          limits:
            cpu: 2
            memory: 8192Mi
          requests:
            cpu: 100m
            memory: 512Mi
        ports:
        - name: webport
          containerPort: 80
        - name: jvmport
          containerPort: 31999

---
apiVersion: v1
kind: Service
metadata:
  name: gateway
  namespace: senyint
spec:
  type: NodePort
  ports:
    - name: webport
      port: 80
      targetPort: 80
      protocol: TCP
    - name: jvmport
      port: 31999
      targetPort: 31999
      protocol: TCP
      nodePort: 31999
  selector:
    app: gateway

 

或者使用标签

kubectl label nodes  node1    jvmmonitor=test

apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: gateway
  namespace: senyint
spec:
  selector:
    matchLabels:
      app: gateway
  replicas: 1
  template:
    metadata:
      labels:
        app: gateway
    spec:
      nodeSelector:
        jvmmonitor: test
      containers:
      - name: gateway
        image: 192.168.200.10/source/gateway_test_jvm
        resources:
          limits:
            cpu: 2
            memory: 8192Mi
          requests:
            cpu: 100m
            memory: 512Mi
        ports:
        - name: webport
          containerPort: 80
        - name: jvmport
          containerPort: 31999

---
apiVersion: v1
kind: Service
metadata:
  name: gateway
  namespace: senyint
spec:
  type: NodePort
  ports:
    - name: webport
      port: 80
      targetPort: 80
      protocol: TCP
    - name: jvmport
      port: 31999
      targetPort: 31999
      protocol: TCP
      nodePort: 31999
  selector:
    app: gateway

 

 

 

posted @ 2018-08-28 13:48  fengjian1585  阅读(846)  评论(0编辑  收藏  举报