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,命名空间,从名字 ...
随机推荐
- 别再眼高手低了! 这些Linq方法都清楚地掌握了吗?
不要再眼高手低了,这些Enumerable之常见Linq扩展方法都清楚掌握了吗?其实这是对我自己来说的! 例如:一个人这个技术掌握了一点那个技术也懂一点,其他的好像也了解一些,感觉自己啥都会一点,又觉 ...
- elo system
今天了解了一下游戏中的PVP模块的实现,大多数的游戏都使用到了ELO算法,刚开始的时候并不清楚这个算法是做什么的,对此开始大量查找有关于ELO算法的资源,功夫不负有心人,总算找到一些有用的资源了. 先 ...
- shell进行微信报警的简单应用
一.企业微信注册地址: https://work.weixin.qq.com/?from=openApi二.请求格式 1.获取token的方法 curl -s 'https://qyapi.weixi ...
- Python中的枚举enumerate
- [HDU2553]N皇后问题(DFS)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2553 题意 n<=10,输出N皇后问题的方法数. 题解 可以使用各种方法.这里使用DFS. 使用 ...
- js监听事件的绑定与移除
监听事件的绑定与移除主要是addEventListener和removeEventListener的运用. addEventListener语法 element.addEventListener(ty ...
- java 多线程-3
十.同步机制解决Thread继承安全问题 创建三个窗口买票,共100张票.用继承来实现 方式一:同步代码块 public class RunMainExtends { public static vo ...
- php post数据丢失
from的enctype="multipart/form-data" php版本5.6.6 问题:部分POST数据接收不到 追源代码发现是php中max_input_vars配置造 ...
- PostGreSQL不同索引类型(btree & hash)的性能问题
在关系型数据库调优中,查询语句涉及到的索引类型是不得不考虑的一个问题.不同的类型的索引可能会适用不同类型的业务场景.这里我们所说的索引类型指的是访问方法(Access Method),至于从其他维度区 ...
- CSS3 新特性总结
1.边框 border-radius: 1-4 length|% / 1-4 length|%; 每个半径的四个值的顺序是:左上角,右上角,右下角,左下角.若省略左下角,和右上角相同,省略右下角,左上 ...