前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >推荐!两个有用的运维工具nsenter+cgroup(一)

推荐!两个有用的运维工具nsenter+cgroup(一)

作者头像
锅总
发布2024-06-12 15:34:27
640
发布2024-06-12 15:34:27
举报
文章被收录于专栏:锅总锅总

在应用没有用容器的方式运行时,可以用nsenter和cgroup相关命令来进行控制,对应用进行资源隔离和namespace限制。本文先给出命令工具的入口,后续单独出一篇讲其应用场景及使用样例。

一、nsenter

linux namespace 控制工具,用于进入和设置namespace

  1. [root@gentlewok ~]# nsenter --help
  2. Usage:
  3. nsenter [options] <program> [<argument>...]
  4. Run a program with namespaces of other processes.
  5. Options:
  6. -t, --target <pid> target process to get namespaces from
  7. -m, --mount[=<file>] enter mount namespace
  8. -u, --uts[=<file>] enter UTS namespace (hostname etc)
  9. -i, --ipc[=<file>] enter System V IPC namespace
  10. -n, --net[=<file>] enter network namespace
  11. -p, --pid[=<file>] enter pid namespace
  12. -U, --user[=<file>] enter user namespace
  13. -S, --setuid <uid> set uid in entered namespace
  14. -G, --setgid <gid> set gid in entered namespace
  15. --preserve-credentials do not touch uids or gids
  16. -r, --root[=<dir>] set the root directory
  17. -w, --wd[=<dir>] set the working directory
  18. -F, --no-fork do not fork before exec'ing <program>
  19. -Z, --follow-context set SELinux context according to --target PID
  20. -h, --help display this help and exit
  21. -V, --version output version information and exit
  22. For more details see nsenter(1).
  23. [root@gentlewok ~]# nsenter -V
  24. nsenter from util-linux 2.23.2

二、cgroup相关命令

用于控制进程资源相关操作 ,在linux机器上执行 man + 红框中的命令(去掉末尾数字)即可获得对应用法

https://github.com/libcgroup/libcgroup/tree/main/doc/man

分析下docker容器创建

运行时是runc

runc的源码里也写了一个nsenter,用于操作linux namespaces

容器创建过程

扩展阅读:

在网上找到两篇对容器的创建流程讲解得比较详细的文章,供各位参考,向大佬致敬!

1、create and run a container

https://terenceli.github.io/%E6%8A%80%E6%9C%AF/2021/12/23/runc-internals-2

2、runc double clone

https://terenceli.github.io/%E6%8A%80%E6%9C%AF/2021/12/28/runc-internals-3

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2024-05-31,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 锅总 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、nsenter
  • 二、cgroup相关命令
  • 分析下docker容器创建
  • 容器创建过程
  • 2、runc double clone
相关产品与服务
容器服务
腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档