Linux 内存占用大排查

用命令 top 查看发现内存使用很高,可用内存很少,导致有些服务无法正常启动。

这时,可以用下面的命令查看占用内存前10的进程,改变 10 的数字,可以调整前几的个数。

ps -aux | sort -k4nr | head -n 10

下图解释:
第二行中,第一个红框是进程的名称,第二个红框是占用内存的大小,单位是 KB,其他行以此类推。

附:
测试服务器占用内存程序统计

hkd-config:0.8G
hkd-admin:0.9G
hkd-gateway:0.9G
user:1G
logstash-2:1G
hkd-portal:0.9G
custom:1G
canan_1:1G
canal.deployer:1G
hkd-auth:1.1G
canal-admin:1.2G
logstash-7.3.0: 1.4G
elasticsearch-6.7.0:1.6G
kafka_2.12-2.3.0:1.7*3=4.1G
elk:2.8+2.8+3=8.6G
老框架:4.4G
kafka web占用:2.1G
root     17438 15.5 10.6 7921152 1734696 ?     Sl   Apr26 211:29 /usr/bin/java -Djava.util.logging.config.file=/opt/tomcat8-apptf/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /opt/tomcat8-apptf/bin/bootstrap.jar:/opt/tomcat8-apptf/bin/tomcat-juli.jar -Dcatalina.base=/opt/tomcat8-apptf -Dcatalina.home=/opt/tomcat8-apptf -Djava.io.tmpdir=/opt/tomcat8-apptf/temp org.apache.catalina.startup.Bootstrap start
root      6476  0.1  9.6 7916628 1575408 ?     Sl   Apr16  22:09 /opt/jdk1.8/jre/bin/java -Djava.util.logging.config.file=/opt/tomcat8-hkd/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -server -Xdebug -Xnoagent -Djava.compiler=NONE -Djava.endorsed.dirs=/opt/tomcat8-hkd/endorsed -classpath /opt/tomcat8-hkd/bin/bootstrap.jar:/opt/tomcat8-hkd/bin/tomcat-juli.jar -Dcatalina.base=/opt/tomcat8-hkd -Dcatalina.home=/opt/tomcat8-hkd -Djava.io.tmpdir=/opt/tomcat8-hkd/temp org.apache.catalina.startup.Bootstrap start
elk      32598  0.1  9.3 4891372 1515732 ?     Sl   Mar27  68:09 /opt/jdk1.8/bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.io.tmpdir=/tmp/elasticsearch-2337579875749112581 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -Xloggc:logs/gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=32 -XX:GCLogFileSize=64m -Des.path.home=/home/vdb1/elasticsearch-6.7.0 -Des.path.conf=/home/vdb1/elasticsearch-6.7.0/config -Des.distribution.flavor=default -Des.distribution.type=tar -cp /home/vdb1/elasticsearch-6.7.0/lib/* org.elasticsearch.bootstrap.Elasticsearch
root      3621  1.5  5.8 4481876 956672 ?      Sl   Apr23  86:46 /opt/jdk1.8/bin/java -jar -Xms512m -Xmx512m -XX:+UseParNewGC -XX:ParallelGCThreads=4 -XX:MaxTenuringThreshold=9 -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+PrintGCDateStamps -XX:+CMSClassUnloadingEnabled -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+PrintGCDetails -XX:+ExplicitGCInvokesConcurrentAndUnloadsClasses -XX:+PrintHeapAtGC -XX:+HeapDumpOnOutOfMemoryError -XX:-OmitStackTraceInFastThrow -Xloggc:/opt/hkd-cloud/hkd-user/logs/heap_trace.txt -XX:HeapDumpPath=/opt/hkd-cloud/hkd-user/logs/HeapDumpOnOutOfMemoryError/ -javaagent:/opt/hkd-cloud/hkd-user/elastic-apm-agent-1.15.0.jar -Delastic.apm.service_name=hkd_user -Delastic.apm.server_url=http://219.155.87.248:8200 -Delastic.apm.secret_token= -Delastic.apm.application_packages=accessing-user /opt/hkd-cloud/hkd-user/hkd-user-server-1.0.jar --spring.profiles.active=test
root     11453  0.3  5.5 6789640 909044 ?      Sl   Mar31 145:08 /usr/bin/java -server -Xms2048m -Xmx3072m -Xmn1024m -XX:SurvivorRatio=2 -XX:PermSize=96m -XX:MaxPermSize=256m -Xss256k -XX:-UseAdaptiveSizePolicy -XX:MaxTenuringThreshold=15 -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF-8 -DappName=otter-canal -Dlogback.configurationFile=/opt/hkd-cloud/canal.deployer-1.1.2/bin/../conf/logback.xml -Dcanal.conf=/opt/hkd-cloud/canal.deployer-1.1.2/bin/../conf/canal.properties -classpath .:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../conf:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/zookeeper-3.4.5.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/zkclient-0.10.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/spring-tx-3.2.18.RELEASE.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/spring-orm-3.2.18.RELEASE.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/spring-jdbc-3.2.18.RELEASE.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/spring-expression-3.2.18.RELEASE.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/spring-core-3.2.18.RELEASE.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/spring-context-3.2.18.RELEASE.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/spring-beans-3.2.18.RELEASE.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/spring-aop-3.2.18.RELEASE.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/snappy-java-1.1.7.1.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/slf4j-api-1.7.12.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/simpleclient_pushgateway-0.4.0.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/simpleclient_httpserver-0.4.0.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/simpleclient_hotspot-0.4.0.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/simpleclient_common-0.4.0.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/simpleclient-0.4.0.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/scala-reflect-2.11.12.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/scala-logging_2.11-3.8.0.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/scala-library-2.11.12.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/rocketmq-remoting-4.3.0.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/rocketmq-logging-4.3.0.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/rocketmq-common-4.3.0.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/rocketmq-client-4.3.0.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/protobuf-java-3.6.1.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/oro-2.0.8.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/netty-tcnative-boringssl-static-1.1.33.Fork26.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/netty-all-4.1.6.Final.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/netty-3.2.2.Final.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/mysql-connector-java-5.1.40.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/metrics-core-2.2.0.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/lz4-java-1.4.1.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/logback-core-1.1.3.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/logback-classic-1.1.3.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/kafka-clients-1.1.1.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/kafka_2.11-1.1.1.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/jsr305-3.0.2.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/jopt-simple-5.0.4.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/jctools-core-2.1.2.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/jcl-over-slf4j-1.7.12.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/jackson-databind-2.9.6.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/jackson-core-2.9.6.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/jackson-annotations-2.9.0.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/ibatis-sqlmap-2.3.4.726.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/httpcore-4.4.3.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/httpclient-4.5.1.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/h2-1.4.196.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/guava-18.0.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/fastsql-2.0.0_preview_644.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/fastjson-1.2.28.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/druid-1.1.9.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/disruptor-3.4.2.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/commons-logging-1.1.3.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/commons-lang3-3.4.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/commons-lang-2.6.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/commons-io-2.4.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/commons-compress-1.9.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/commons-codec-1.9.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/commons-beanutils-1.8.2.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/canal.store-1.1.2.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/canal.sink-1.1.2.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/canal.server-1.1.2.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/canal.protocol-1.1.2.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/canal.prometheus-1.1.2.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/canal.parse.driver-1.1.2.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/canal.parse.dbsync-1.1.2.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/canal.parse-1.1.2.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/canal.meta-1.1.2.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/canal.instance.spring-1.1.2.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/canal.instance.manager-1.1.2.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/canal.instance.core-1.1.2.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/canal.filter-1.1.2.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/canal.deployer-1.1.2.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/canal.common-1.1.2.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/aviator-2.2.1.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/aopalliance-1.0.jar:/opt/hkd-cloud/canal.deployer-1.1.2/bin/../lib/aliware-apache-rocketmq-cloud-1.0.jar:.:/opt/jdk1.8/lib:/opt/jdk1.8/jre/lib: com.alibaba.otter.canal.deployer.CanalLauncher

posted @ 2019-11-05 14:43  哈喽哈喽111111  阅读(8136)  评论(0编辑  收藏  举报