在elasticsearch的config中加jvm.options文件,修改堆棧大小,默認是2GB,直接啟動(dòng)es即可,保證之前已經(jīng)映射了配置文件。
-Xms5g -Xmx5g
## JVM configuration ################################################################ ## IMPORTANT: JVM heap size ################################################################ ## ## You should always set the min and max JVM heap ## size to the same value. For example, to set ## the heap to 4 GB, set: ## ## -Xms4g ## -Xmx4g ## ## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html ## for more information ## ################################################################ # Xms represents the initial size of total heap space # Xmx represents the maximum size of total heap space -Xms5g -Xmx5g ################################################################ ## Expert settings ################################################################ ## ## All settings below this section are considered ## expert settings. Don't tamper with them unless ## you understand what you are doing ## ################################################################ ## GC configuration -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly ## optimizations # pre-touch memory pages used by the JVM during initialization -XX:+AlwaysPreTouch ## basic # force the server VM (remove on 32-bit client JVMs) -server # explicitly set the stack size (reduce to 320k on 32-bit client JVMs) -Xss1m # set to headless, just in case -Djava.awt.headless=true # ensure UTF-8 encoding by default (e.g. filenames) -Dfile.encoding=UTF-8 # use our provided JNA always versus the system one -Djna.nosys=true # use old-style file permissions on JDK9 -Djdk.io.permissionsUseCanonicalPath=true # flags to configure Netty -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 # log4j 2 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Dlog4j.skipJansi=true ## heap dumps # generate a heap dump when an allocation from the Java heap fails # heap dumps are created in the working directory of the JVM -XX:+HeapDumpOnOutOfMemoryError # specify an alternative path for heap dumps # ensure the directory exists and has sufficient space #-XX:HeapDumpPath=${heap.dump.path} ## GC logging #-XX:+PrintGCDetails #-XX:+PrintGCTimeStamps #-XX:+PrintGCDateStamps #-XX:+PrintClassHistogram #-XX:+PrintTenuringDistribution #-XX:+PrintGCApplicationStoppedTime # log GC status to a file with time stamps # ensure the directory exists #-Xloggc:${loggc} # By default, the GC log file will not rotate. # By uncommenting the lines below, the GC log file # will be rotated every 128MB at most 32 times. #-XX:+UseGCLogFileRotation #-XX:NumberOfGCLogFiles=32 #-XX:GCLogFileSize=128M # Elasticsearch 5.0.0 will throw an exception on unquoted field names in JSON. # If documents were already indexed with unquoted fields in a previous version # of Elasticsearch, some operations may throw errors. # # WARNING: This option will be removed in Elasticsearch 6.0.0 and is provided # only for migration purposes. #-Delasticsearch.json.allow_unquoted_field_names=true
補充:Docker 容器內存限制
docker run -d -i -t -m 256M --memory-swap 512M --name centos2.12 centos /bin/bash
docker run -d -i -t -m 256M --memory-swap 512M --name centos centos /bin/bash
-m, --memory # 內存限制大小,單位可以為 b,k,M,g;最小為4M --memory-swap # 內存+交換分區大小總限制 --memory-reservation # 預留內存大??;容器在宿主機最小占用內存; --oom-kill-disable # out-of-memory 內存溢出;限制kill容器進(jìn)程,默認沒(méi)設置 --oom-score-adj # 容器被 OOM killer 殺死的優(yōu)先級,范圍是[-1000, 1000],默認為 0 --memory-swappiness # 用于設置容器的虛擬內存控制行為。值為 0~100 之間的整數 --kernel-memory 核心內存限制,最小為 4M。
--memory-swap 不是交換分區,而是 memory + swap 的大??; 容器的交換分區 swap = memory-swap - memory
memory-swap 不設置 或者設置為 0 ; 容器的交換分區 swap 大小就是 memory 的小大; 容器的進(jìn)程使用最大內存 = memory + swap
當 memory-swap 設置為 -1 時(shí); 容器內存大小為 memory 設置的大??; 交換分區大小為宿主機 swap 大??; 容器進(jìn)程能使用的最大內存 = memory + 宿主機 swap 大??;
--oom-kill-disable 限制 kill 容器進(jìn)程; (必須設置在 memory 之后才有限;) docker run -d -i -t -m 256M --oom-kill-disable --name Centos-1 centos /bin/bash
核心內存和用戶(hù)內存不同的地方在于核心內存不能被交換出。
不能交換出去的特性使得容器可以通過(guò)消耗太多內存來(lái)堵塞一些系統服務(wù)。
核心內存包括: stack pages(棧頁(yè)面) slab pages socket memory pressure tcp memory pressure
可以通過(guò)設置核心內存限制來(lái)約束這些內存。
每個(gè)進(jìn)程都要消耗一些棧頁(yè)面,通過(guò)限制核心內存,可以在核心內存使用過(guò)多時(shí)阻止新進(jìn)程被創(chuàng )建。
docker run -d -i -t -m 500M --kernel-memory 128M --name Centos-2 centos /bin/bash 限制容器內存 256M;限制核心內存 128M 。 docker run -d -i -t --kernel-memory 128M --name Centos-3 centos /bin/bash 內存為宿主機memory大小, 限制核心內存 128M
容器的內核可以交換出一定比例的匿名頁(yè)。
--memory-swappiness就是用來(lái)設置這個(gè)比例的。 --memory-swappiness可以設置為從 0 到 100。 # 0 表示關(guān)閉匿名頁(yè)面交換。 # 100 表示所有的匿名頁(yè)都可以交換。默認情況下,如果不適用--memory-swappiness,則該值從父進(jìn)程繼承而來(lái)。 docker run -d -i -t --memory-swappiness=0 --name Centos-4 centos /bin/bash 將--memory-swappiness設置為 0 可以保持容器的工作集,避免交換代理的性能損失。
Swappiness 的值越大,表示越積極使用swap分區,越小表示越積極使用物理內存。默認值swappiness=60
sysctl vm.swappiness = 100 # cat /proc/sys/vm/swappiness
以上為個(gè)人經(jīng)驗,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。
Copyright ? 2009-2022 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 特網(wǎng)科技 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 百度云 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站