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,命名空间,从名字 ...
随机推荐
- delphi DBgrid应用全书
在一个Dbgrid中显示多数据库 在数据库编程中,不必要也不可能将应用程序操作的所有数据库字段放入一个数据库文件中.正确的数据库结构应是:将数据库字段放入多个数据库文件,相关的数据库都包含一个唯 ...
- 将微服务部署到 Azure Kubernetes 服务 (AKS) 实践
本文是对 <.NET Tutorial - Deploy a microservice to Azure> 的翻译和实践.入门级踩坑实践,k8s 大佬请回避,以免耽误您宝贵的时间. 介绍 ...
- ios网络访问官方演示程序
官方演示程序 AppDelegate 设置缓存 NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:4 * 1024 * ...
- [LeetCode]Mysql系列5
题目1 1112. 每位学生的最高成绩 编写一个 SQL 查询,查询每位学生获得的最高成绩和它所对应的科目,若科目成绩并列,取 course_id 最小的一门.查询结果需按 student_id 增序 ...
- netty---sync,await
LOG.info("*************************WINDOWS系统*********************************"); //设置事件处理 ...
- hystrix总结之请求批量执行
hystrix可以将同一个命令的多次执行合并到一起执行. public class HelloWorldCommandCollapser extends HystrixCollapser<Lis ...
- Spring系列 之数据源的配置 数据库 数据源 连接池的区别
Spring系列之数据源的配置 数据源,连接池,数据库三者的区别 连接池:这个应该都学习过,比如c3p0,druid等等,连接池的作用是为了提高程序的效率,因为频繁的去创建,关闭数据库连接,会对性能有 ...
- Springboot+Vue实现仿百度搜索自动提示框匹配查询功能
案例功能效果图 前端初始页面 输入搜索信息页面 点击查询结果页面 环境介绍 前端:vue 后端:springboot jdk:1.8及以上 数据库:mysql 核心代码介绍 TypeCtrler .j ...
- 3.ConcurrentMap-并发Map
- vue学习09 图片切换
目录 vue学习09 图片切换 定义图片数组:imgList:[],列表数据使用数组保存 添加图片索引:index 绑定src属性:使用v-bind,v-bind指令可以设置元素属性,比如src 图片 ...