linux(centos8):使用namespace做资源隔离
一,namespace是什么?
说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest
对应的源码可以访问这里获取: https://github.com/liuhongdi/
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,namespace的用途?
三,查看一个进程所属的namespace
[root@blog ~]# ps auxfww | grep nginx:
root 491 0.0 0.0 71028 3368 ? Ss May18 0:00 nginx: master process /usr/local/openresty/nginx/sbin/nginx
nginx 492 0.0 0.0 102496 7036 ? S May18 0:00 \_ nginx: worker process
nginx 493 0.0 0.0 102764 7496 ? S May18 0:00 \_ nginx: worker process
nginx 494 0.0 0.0 102496 5856 ? S May18 0:00 \_ nginx: worker process
…
[root@blog ~]# ls /proc/492/ns/
cgroup ipc mnt net pid pid_for_children user uts
[root@blog ns]# ll /proc/492/ns/
total 0
lrwxrwxrwx 1 nginx nginx 0 Jun 15 13:32 cgroup -> 'cgroup:[4026531835]'
lrwxrwxrwx 1 nginx nginx 0 Jun 15 13:32 ipc -> 'ipc:[4026531839]'
lrwxrwxrwx 1 nginx nginx 0 Jun 15 13:32 mnt -> 'mnt:[4026532277]'
lrwxrwxrwx 1 nginx nginx 0 Jun 15 13:32 net -> 'net:[4026531992]'
lrwxrwxrwx 1 nginx nginx 0 Jun 15 13:32 pid -> 'pid:[4026531836]'
lrwxrwxrwx 1 nginx nginx 0 Jun 15 13:32 pid_for_children -> 'pid:[4026531836]'
lrwxrwxrwx 1 nginx nginx 0 Jun 15 13:32 user -> 'user:[4026531837]'
lrwxrwxrwx 1 nginx nginx 0 Jun 15 13:32 uts -> 'uts:[4026531838]’
四,查看一个进程的mnt namespace信息
[root@blog ns]# ll /proc/492/mount*
-r--r--r-- 1 nginx nginx 0 Jun 13 23:23 /proc/492/mountinfo
-r--r--r-- 1 nginx nginx 0 Jun 13 23:23 /proc/492/mounts
-r-------- 1 nginx nginx 0 Jun 13 23:23 /proc/492/mountstats
[root@localhost ~]# mkdir /root/hosta
[root@localhost ~]# touch /root/hosta/a.txt
[root@localhost ~]# mkdir /root/hostb
[root@localhost ~]# touch /root/hostb/b.txt
[root@localhost ~]# ls /mnt
hgfs
[root@localhost ~]# unshare --mount --uts bash
[root@localhost ~]# hostname hosta && exec bash
[root@hosta ~]# readlink /proc/$$/ns/{mnt,uts}
mnt:[4026532774]
uts:[4026532775]
[root@hosta ~]# mount --bind hosta/ /mnt/
[root@hosta ~]# ls /mnt
a.txt
[root@localhost ~]# ls /mnt
hgfs
[root@localhost ~]# unshare --mount --uts bash
[root@localhost ~]# hostname hostb && exec bash
[root@hostb ~]# readlink /proc/$$/ns/{mnt,uts}
mnt:[4026532706]
uts:[4026532707]
[root@hostb ~]# mount --bind hostb/ /mnt/
[root@hostb ~]# ls /mnt
b.txt
五,测试pid namespace
[root@localhost ~]# unshare --pid --uts --mount --fork bash
[root@localhost ~]# hostname hosta && exec bash
[root@hosta ~]# echo $$
1
[root@hosta ~]# pstree -pl
systemd(1)─┬─ModemManager(871)─┬─{ModemManager}(911)
│ └─{ModemManager}(924)
├─NetworkManager(867)─┬─dhclient(993)
│ ├─{NetworkManager}(915)
│ └─{NetworkManager}(925)
…
[root@hosta ~]# readlink /proc/$$/ns/{pid,uts,mnt}
pid:[4026531836]
uts:[4026531838]
mnt:[4026531840]
[root@hosta liuhongdi]# mount --types proc proc /proc/
[root@hosta liuhongdi]# pstree -pl
bash(1)───pstree(70)
[root@hosta liuhongdi]# readlink /proc/$$/ns/{pid,uts,mnt}
pid:[4026532779]
uts:[4026532778]
mnt:[4026532777]
六,查看linux的版本:
[root@node1 ~]# more /etc/redhat-release
CentOS Linux release 8.1.1911 (Core)
[root@node1 ~]# uname -r
4.18.0-147.el8.x86_64
linux(centos8):使用namespace做资源隔离的更多相关文章
- linux(centos8):使用cgroups做资源限制
一,什么是cgroups? 1,cgroups是资源的控制组,它提供了一套机制用于控制一组特定进程对资源的使用. cgroups绑定一个进程集合到一个或多个限制资源使用的子系统上. 2, cg ...
- Hadoop Yarn内存资源隔离实现原理——基于线程监控的内存隔离方案
注:本文以hadoop-2.5.0-cdh5.3.2为例进行说明. Hadoop Yarn的资源隔离是指为运行着不同任务的“Container”提供可独立使用的计算资源,以避免它们之间相互干扰.目 ...
- Hystrix系列-5-Hystrix的资源隔离策略
转自:https://blog.csdn.net/liuchuanhong1/article/details/73718794 Hystrix的资源隔离策略有两种,分别为:线程池和信号量. 说到资源隔 ...
- 服务容错保护断路器Hystrix之八:Hystrix资源隔离策略
在一个基于微服务的应用程序中,您通常需要调用多个微服务完成一个特定任务.不使用舱壁模式,这些调用默认是使用相同的线程来执行调用的,这些线程Java容器为处理所有请求预留的.在高服务器请求的情况下,一个 ...
- 利用yarn多队列实现hadoop资源隔离
大数据处理离不开hadoop集群的部署和管理,对于本来硬件资源就不多的创业团队来说,做好资源的共享和隔离是很有必要的,毕竟不像BAT那么豪,那么怎么样能把有限的节点同时分享给多组用户使用而且互不影响呢 ...
- 资源管理与调度系统-YARN资源隔离及以YARN为核心的生态系统
资源管理与调度系统-YARN资源隔离及以YARN为核心的生态系统 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.什么是资源隔离 资源隔离是指为不同任务提供可独立使用的计算资源以 ...
- Docker 容器资源隔离 namespace(十)
目录 一.简介 Linux Namespace的6大类型 二.Mount Namespace 三.IPC Namespace 四.Network Namespace 五.UTS Namespace 六 ...
- docker容器技术基础之linux cgroup、namespace
一.开头 接触过docker的同学多多少少听过这样一句话"docker容器通过linux namespace.cgroup特性实现资源的隔离与限制".今天我们来尝试学习一下这两个东 ...
- linux中的namespace
本文将就namespace这个知识点,进行简单的归纳总结,力求通俗易通.在资料汇总的过程中,参考了许多网上的博客资料,在文章尾部给出相关链接. namespace,命名空间,从名字 ...
随机推荐
- Python 面试题 字符串 删除多少个字符使得出现做多的字符数量大于等于字符串长度的一半.
str1 = input() num = {} for i in set(str1): num[i]=str1.count(i) max_value = max(num.values()) n=abs ...
- python之csrf简介
django为用户实现防止跨站请求伪造的功能,通过中间件 django.middleware.csrf.CsrfViewMiddleware 来完成.而对于django中设置防跨站请求伪造功能有分为全 ...
- django之models报错
django 执行python manage.py makemigrations报错:TypeError: __init__() missing 1 required positional argum ...
- ES6 数组方法库
文章目录 多维数组降维成一维数组 reduce() 回调 flat() 多维数组降维成一维数组 reduce() var arr1 = [[0, 1], [2, 3], [4, 5]]; var ar ...
- Autofac的使用
Autofac的使用 「Autofac简介」 「基本的使用方式」 「如何实现webapi控制器自动注入接口」 一.Autofac简介 ❝ Autofac是实现依赖注入的类库之一,他可以帮助你实现程序的 ...
- 确成硅化+恒力+苏大文正节点2 oracle ora-4030 错误pga version:11204
Errors in file /u01/app/oracle/oracle/diag/rdbms/orcl/orcl/trace/orcl_j000_61543.trc (incident=18009 ...
- Win10 搭建FTP环境,并使用Java实现上传,下载,删除
测试的环境一般都是在自己电脑上面装的,现在一般都使用Win10开发 搭建FTP: 第一步:打开控制面板:点击程序 第二步: 第三步: 然后点击确认后等待完成 完成后在启动中找到IIS管理器 打开 在网 ...
- python os模块方法详解
os.access() 方法使用当前的uid/gid尝试访问路径.大部分操作使用有效的 uid/gid, 因此运行环境可以在 suid/sgid 环境尝试. 实例: os.chdir() 方法用于改变 ...
- Cookies题解
来源:<算法竞赛进阶指南> Describe: 有M块饼干要分给N个孩子.当有k个孩子分到的饼干数比第i个孩子分到的多时,会产生g[i]*k的贡献.求最小的贡献及任意一种方案. Solut ...
- 黑菜菌的JAVA学习笔记
简介 本文是笔者对<JAVA编程思想>的学习笔记.以自己的思维理解来写下这篇文章,尽可能地简练,易懂.本文将随本人学习进度实时更新 对象导论 抽象过程 汇编语言是对底层机器码的抽象,而面向 ...