1. 建立基础镜像
FROM centos
MAINTAINER fengjianENV 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 fengjianADD webserver.tar.gz/data/webserver/EXPOSE80 18999CMD ["/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: gatewaynamespace: senyint
spec:
selector:
matchLabels:
app: gateway
replicas:1template:
metadata:
labels:
app: gateway
spec:
nodeName: node1 #指定部署到 node1 上
containers:-name: gateway
image:192.168.200.10/source/gateway_test_jvm
resources:
limits:
cpu:2memory: 8192Mi
requests:
cpu: 100m
memory: 512Mi
ports:-name: webport
containerPort:80
-name: jvmport
containerPort:31999
---apiVersion: v1
kind: Service
metadata:
name: gatewaynamespace: senyint
spec:
type: NodePort
ports:-name: webport
port:80targetPort:80protocol: TCP-name: jvmport
port:31999targetPort:31999protocol: TCP
nodePort:31999selector:
app: gateway
或者使用标签
kubectl label nodes node1 jvmmonitor=test
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: gatewaynamespace: senyint
spec:
selector:
matchLabels:
app: gateway
replicas:1template:
metadata:
labels:
app: gateway
spec:
nodeSelector:
jvmmonitor: test
containers:-name: gateway
image:192.168.200.10/source/gateway_test_jvm
resources:
limits:
cpu:2memory: 8192Mi
requests:
cpu: 100m
memory: 512Mi
ports:-name: webport
containerPort:80
-name: jvmport
containerPort:31999
---apiVersion: v1
kind: Service
metadata:
name: gatewaynamespace: senyint
spec:
type: NodePort
ports:-name: webport
port:80targetPort:80protocol: TCP-name: jvmport
port:31999targetPort:31999protocol: TCP
nodePort:31999selector:
app: gateway