1、最近在使用docker容器的时候,发现宿主机的agetty进程cpu占用率达到100%

在Google上搜了下,引起这个问题的原因是在使用"docker run"运行容器时使用了"/sbin/init"和"--privileged"参数。

使用/sbin/init启动容器并加上--privileged参数,相当于docker容器获得了宿主机的全权委托权限。这时docker容器内部的init与宿主机的init产生了混淆。

# 引用google到的一段话:

I've done all my testing on them without using --privileged, especially since that's so dangerous (effectively, you're telling this second init process on your system that it's cool to go ahead and manage your system resources, and then giving it access to them as well). I always think of --privileged as a hammer to be used very sparingly.

出于对安全的考虑,在启动容器时,docker容器里的系统只具有一些普通的linux权限,并不具有真正root用户的所有权限。而--privileged=true参数可以让docker容器具有linux root用户的所有权限。

为了解决这个问题,docker后来的版本中docker run增加了两个选项参数"--cap-add"和"--cap-drop"。

--cap-add : 获取default之外的linux的权限

--cap-drop: 放弃default linux权限

从docker官网的文档中可以查到,docker容器具有的default权限及--cap-add可以获取到的扩展权限如下:

Default 权限:

Capability Key

Capability Description

SETPCAP

Modify process capabilities.

MKNOD

Create special files using mknod(2).

AUDIT_WRITE

Write records to kernel auditing log.

CHOWN

Make arbitrary changes to file UIDs and GIDs (see chown(2)).

NET_RAW

Use RAW and PACKET sockets.

DAC_OVERRIDE

Bypass file read, write, and execute permission checks.

FOWNER

Bypass permission checks on operations that normally require

the file system UID of the process to match the UID of the file.

FSETID

Don’t clear set-user-ID and set-group-ID permission bits

when a file is modified.

KILL

Bypass permission checks for sending signals.

SETGID

Make arbitrary manipulations of process GIDs and supplementary

GID list.

SETUID

Make arbitrary manipulations of process UIDs.

NET_BIND_SERVICE

Bind a socket to internet domain privileged ports

(port numbers less than 1024).

SYS_CHROOT

Use chroot(2), change root directory.

SETFCAP

Set file capabilities.

通过--cap-add获取到的权限:

Capability Key

Capability Description

SYS_MODULE

Load and unload kernel modules.

SYS_RAWIO

Perform I/O port operations (iopl(2) and ioperm(2)).

SYS_PACCT

Use acct(2), switch process accounting on or off.

SYS_ADMIN

Perform a range of system administration operations.

SYS_NICE

Raise process nice value (nice(2), setpriority(2)) and

change the nice value for arbitrary processes.

SYS_RESOURCE

Override resource Limits.

SYS_TIME

Set system clock (settimeofday(2), stime(2), adjtimex(2));

set real-time (hardware) clock.

SYS_TTY_CONFIG

Use vhangup(2); employ various privileged ioctl(2) operations

on virtual terminals.

AUDIT_CONTROL

Enable and disable kernel auditing; change auditing filter rules;

retrieve auditing status and filtering rules.

MAC_OVERRIDE

Allow MAC configuration or state changes.

Implemented for the Smack LSM.

MAC_ADMIN

Override Mandatory Access Control (MAC). Implemented for

the Smack Linux Security Module (LSM).

NET_ADMIN

Perform various network-related operations.

SYSLOG

Perform privileged syslog(2) operations.

DAC_READ_SEARCH

Bypass file read permission checks and directory read and

execute permission checks.

LINUX_IMMUTABLE

Set the FS_APPEND_FL and FS_IMMUTABLE_FL i-node flags.

NET_BROADCAST

Make socket broadcasts, and listen to multicasts.

IPC_LOCK

Lock memory (mlock(2), mlockall(2), mmap(2), shmctl(2)).

IPC_OWNER

Bypass permission checks for operations on System V IPC objects.

SYS_PTRACE

Trace arbitrary processes using ptrace(2).

SYS_BOOT

Use reboot(2) and kexec_load(2), reboot and load a new kernel

for later execution.

LEASE

Establish leases on arbitrary files (see fcntl(2)).

WAKE_ALARM

Trigger something that will wake up the system.

BLOCK_SUSPEND

Employ features that can block system suspend.

所以,在运行容器时,可以不用--privileged参数的尽量不用,用--cap-add参数替代。如果必须使用--privileged=true参数的,可以通过在宿主机和容器中执行以下命令将agetty关闭。

shell> systemctl stop getty@tty1.service

shell> systemctl mask getty@tty1.service

参考资料:

https://github.com/docker/docker/issues/4040

https://docs.docker.com/engine/reference/run/

docker运行容器后agetty进程cpu占用率100%的更多相关文章

  1. 获取进程CPU占用率

    获取进程CPU占用率 // 时间转换 static __int64 file_time_2_utc(const FILETIME* ftime) { LARGE_INTEGER li; li.LowP ...

  2. Linux下java进程CPU占用率高分析方法

    Linux下java进程CPU占用率高分析方法 在工作当中,肯定会遇到由代码所导致的高CPU耗用以及内存溢出的情况.这种情况发生时,我们怎么去找出原因并解决. 一般解决方法是通过top命令找出消耗资源 ...

  3. Linux下分析某个进程CPU占用率高的原因

      Linux下分析某个进程CPU占用率高的原因 通过top命令找出消耗资源高的线程id,利用strace命令查看该线程所有系统调用  1.top 查到占用cpu高的进程pid 2.查看该pid的线程 ...

  4. (转)Linux下java进程CPU占用率高-分析方法

    Linux下java进程CPU占用率高-分析方法 原文:http://itindex.net/detail/47420-linux-java-%E8%BF%9B%E7%A8%8B?utm_source ...

  5. Linux下java进程CPU占用率高分析方法(一)

    Linux下java进程CPU占用率高分析方法 在工作当中,肯定会遇到由代码所导致的高CPU耗用以及内存溢出的情况.这种情况发生时,我们怎么去找出原因并解决. 一般解决方法是通过top命令找出消耗资源 ...

  6. Linux下java进程CPU占用率高分析方法(二)

    1. 通过 top 命令查看当前系统CPU使用情况,定位CPU使用率超过100%的进程ID:2. 通过 ps aux | grep PID 命令进一步确定具体的线程信息:3. 通过 ps -mp pi ...

  7. Linux下java进程CPU占用率高-分析方法

    今天登陆同事的一台gateway 开始以为hive环境登陆不了了,仔细一看看了下是因为机器很卡,我每次等几秒没登陆就ctrl+c了,看了下是有个java进程cpu:340.4%  mem:14.6%  ...

  8. cidaemon.exe进程cpu占用率高及关闭cidaemon.exe进程方法

    问题描写叙述:   这段时间机器总是出现一个奇怪的问题:cidaemon.exe进程占用CUP率98%以上,大大影响了电脑的正常使用.资源管理器中出现多个cidaemon.exe进程,强制结束占用cp ...

  9. WMI获取进程CPU占用率

    Monitor % Process CPU Usage (specific process) http://www.tek-tips.com/viewthread.cfm?qid=395765 for ...

随机推荐

  1. IIS 设置 FTP 服务器 添加多个账户

    我们有很多童鞋经常开不动IIS自带的FTP如何创建,就算创建了也不会实现多用户,下面我来分享一下我的经验吧: 使用 IIS 设置 FTP 服务器 依次单击“开始”按钮.“控制面板”和“添加或删除程序” ...

  2. zabbix概述篇

    zabbix监控系统概述 监控系统 决不允许未经监控的业务和服务的上线 基本功能 采样:获取客户端数据(主动和被动模式) 存储 展示 告警 监控通道 ssh/telnet:无agent snmp:简单 ...

  3. textarea 转HTML

    Text2Html(str) { if (str == null) { return ""; } else if (str.length == 0) { return " ...

  4. 干货|Spring Cloud Bus 消息总线介绍

    继上一篇 干货|Spring Cloud Stream 体系及原理介绍 之后,本期我们来了解下 Spring Cloud 体系中的另外一个组件 Spring Cloud Bus (建议先熟悉 Spri ...

  5. React Native等比放大不丢失图片

    9月11号 0.33版本,resizeMode中添加了center, 可以实现一样的功能.不过希望这篇文章还能帮助大家. 之前我们学习了从零学React Native之08Image组件 大家可以发现 ...

  6. Spring data jpa hibernate:查询异常java.sql.SQLException: Column '列名' not found

    使用spring boot,jap,hibernate不小心的错误: java.sql.SQLException: Column '列名' not found: 这句话的意思是:找不到此列 为什么会出 ...

  7. 在SAE上使用Flask插件

    因为我之前学习的时候使用的是虚拟环境,下载的所有需要用到的插件都在flask这个文件夹里面,SAE上Flask的版本和我本地用的版本对不上,导致有时候import都不对,于是我就把本地的环境直接放到S ...

  8. Flask学习之十三 日期和时间

    英文博客地址:http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xiii-dates-and-times 中文翻译地址: ...

  9. 22-1 rbac权限设计

    一 表结构设计 from django.db import models # Create your models here. from django.db import models # Creat ...

  10. MySQL列出当前月的每一天

    因为工作的原因,要用MySQL列出当前月份每一天的日期,自己查了下网上资料都是列出最近一个月的日期的解决方案,自己根据查到的的方案,修改成了下面两个方案,在此记录下: 方案一: SELECT date ...