docker 如何在Telegraf容器中增加内存锁?

bihw5rsg  于 2023-06-21  发布在  Docker
关注(0)|答案(1)|浏览(266)

我将Telegraf作为Docker容器运行,其中包含docker-compose文件。

telegraf:
    image: telegraf:1.26.3
    container_name: telegraf
    depends_on:
      socket-proxy:
        condition: service_started
      influxdb:
        condition: service_healthy
    hostname: telegraf
    volumes:
      # several volumes
    ports:
      # several ports
    networks:
      - socket
      - data_export
    restart: unless-stopped
    labels:
      <<: *default-labels
      diun.include_tags: "^latest$$;^1.26.3$$"

它工作正常,但我添加了一些influxdb连接([[outputs.influxdb]]),当容器启动时,会显示一个警告:

2023-06-10T14:25:16Z I! Found 14 secrets...
2023-06-10T14:25:16Z W! Insufficient lockable memory 64kb when 112kb is required. Please increase the limit for Telegraf in your Operating System!

我尝试在容器中执行ulimit,但它不工作。

root@telegraf:/# ulimit -l    
64
root@telegraf:/# ulimit -l 112
bash: ulimit: max locked memory: cannot modify limit: Operation not permitted

我试图在我的docker-compose文件中添加ulimits,但我得到一个panic错误

ulimits:
  memlock: 112
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xa0525f]
goroutine 1 [running]:
github.com/awnumar/memguard/core.Purge.func1(0xc0001df930)
    /go/pkg/mod/github.com/awnumar/memguard@v0.22.3/core/exit.go:23 +0x3f
github.com/awnumar/memguard/core.Purge()
    /go/pkg/mod/github.com/awnumar/memguard@v0.22.3/core/exit.go:51 +0x25
github.com/awnumar/memguard/core.Panic({0x5be2400, 0xc0002a2330})
    /go/pkg/mod/github.com/awnumar/memguard@v0.22.3/core/exit.go:85 +0x25
github.com/awnumar/memguard/core.NewBuffer(0x20)
    /go/pkg/mod/github.com/awnumar/memguard@v0.22.3/core/buffer.go:73 +0x2d5
github.com/awnumar/memguard/core.NewCoffer()
    /go/pkg/mod/github.com/awnumar/memguard@v0.22.3/core/coffer.go:30 +0x34
github.com/awnumar/memguard/core.init.0()
    /go/pkg/mod/github.com/awnumar/memguard@v0.22.3/core/enclave.go:15 +0x2e

如何增加此容器的最大锁定内存?

ldxq2e6h

ldxq2e6h1#

我不确定这一点,但我认为memlock值被解释为 bytes,因此要指定112 KB的限制,您需要编写:

services:
  telegraf:
    ulimits:
      memlock: 114688

一个测试似乎证实了我的解释;给定这个完整的compose文件:

services:
  telegraf:
    ulimits:
      memlock: 114688
    image: telegraf:1.26.3
    entrypoint:
      - sleep
      - inf

在我docker-compose up堆栈之后,我可以执行telegraf容器并运行ulimit -a,然后看到“锁定内存”ulimit显示为112

$ docker-compose exec telegraf sh -c 'ulimit -a'
time(seconds)        unlimited
file(blocks)         unlimited
data(kbytes)         unlimited
stack(kbytes)        8192
coredump(blocks)     unlimited
memory(kbytes)       unlimited
locked memory(kbytes) 112
process              unlimited
nofiles              1073741816
vmemory(kbytes)      unlimited
locks                unlimited
rtprio               0

相关问题