合 含有Docker的环境agetty进程导致cpu占用率100%
Tags: DockerCPU很高CPU使用率agettyCPU飙升100%
现象
分析
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | [root@lhrdb ~]# cat /proc/96013/cgroup 11:cpuset:/docker/3906b1ee7972d2fa8d2c13fb4da92c55e6b2f02c3fd5d7b04335f53faa6c7ef9 10:perf_event:/docker/3906b1ee7972d2fa8d2c13fb4da92c55e6b2f02c3fd5d7b04335f53faa6c7ef9 9:blkio:/docker/3906b1ee7972d2fa8d2c13fb4da92c55e6b2f02c3fd5d7b04335f53faa6c7ef9 8:hugetlb:/docker/3906b1ee7972d2fa8d2c13fb4da92c55e6b2f02c3fd5d7b04335f53faa6c7ef9 7:net_prio,net_cls:/docker/3906b1ee7972d2fa8d2c13fb4da92c55e6b2f02c3fd5d7b04335f53faa6c7ef9 6:pids:/docker/3906b1ee7972d2fa8d2c13fb4da92c55e6b2f02c3fd5d7b04335f53faa6c7ef9/system.slice/system-getty.slice/getty@tty1.service 5:cpuacct,cpu:/docker/3906b1ee7972d2fa8d2c13fb4da92c55e6b2f02c3fd5d7b04335f53faa6c7ef9 4:freezer:/docker/3906b1ee7972d2fa8d2c13fb4da92c55e6b2f02c3fd5d7b04335f53faa6c7ef9 3:memory:/docker/3906b1ee7972d2fa8d2c13fb4da92c55e6b2f02c3fd5d7b04335f53faa6c7ef9 2:devices:/docker/3906b1ee7972d2fa8d2c13fb4da92c55e6b2f02c3fd5d7b04335f53faa6c7ef9/system.slice/system-getty.slice 1:name=systemd:/docker/3906b1ee7972d2fa8d2c13fb4da92c55e6b2f02c3fd5d7b04335f53faa6c7ef9/system.slice/system-getty.slice/getty@tty1.service [root@lhrdb ~]# docker ps | grep 3906b1ee797 3906b1ee7972 lhrbest/lhrubuntu1804:3.0 "init" 3 days ago Up 9 minutes 0.0.0.0:234->22/tcp, :::234->22/tcp, 0.0.0.0:43391->3389/tcp, :::43391->3389/tcp lhrubuntu1804 [root@lhrdb ~]# docker exec -it 3906b1ee7972 systemctl stop getty@tty1.service [root@lhrdb ~]# docker exec -it 3906b1ee7972 systemctl mask getty@tty1.service Created symlink /etc/systemd/system/getty@tty1.service → /dev/null. [root@lhrdb ~]# [root@lhrdb ~]# [root@lhrdb ~]# [root@lhrdb ~]# top top - 14:27:01 up 27 min, 7 users, load average: 2.54, 14.14, 14.87 Tasks: 1162 total, 2 running, 1160 sleeping, 0 stopped, 0 zombie %Cpu(s): 4.6 us, 3.3 sy, 0.0 ni, 91.1 id, 0.0 wa, 0.0 hi, 0.0 si, 0.9 st KiB Mem : 65806012 total, 35938112 free, 12325460 used, 17542440 buff/cache KiB Swap: 35520504 total, 35520504 free, 0 used. 47804184 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 96016 root 20 0 16076 976 824 R 100.0 0.0 2:52.44 agetty 2751 root 20 0 3162464 96052 25840 S 5.6 0.1 1:18.24 dockerd 91686 lhr 20 0 7958748 2.0g 1.0g S 5.0 3.3 0:15.23 gaussdb 91687 lhr 20 0 7936228 2.0g 1.0g S 4.6 3.3 0:15.22 gaussdb 91689 lhr 20 0 7514420 1.6g 1.0g S 4.0 2.6 0:13.15 gaussdb 91979 lhr 20 0 6760800 1.3g 793984 S 4.0 2.0 0:11.74 gaussdb 41738 root 20 0 10.7g 909940 9900 S 1.7 1.4 0:24.06 sqlservr [root@lhrdb ~]# cat /proc/96016/cgroup 11:cpuset:/docker/91fb4dc420690971d2d9cbf335af6066174d7cc23ec34e7c8f28962830c65fbb 10:perf_event:/docker/91fb4dc420690971d2d9cbf335af6066174d7cc23ec34e7c8f28962830c65fbb 9:blkio:/docker/91fb4dc420690971d2d9cbf335af6066174d7cc23ec34e7c8f28962830c65fbb 8:hugetlb:/docker/91fb4dc420690971d2d9cbf335af6066174d7cc23ec34e7c8f28962830c65fbb 7:net_prio,net_cls:/docker/91fb4dc420690971d2d9cbf335af6066174d7cc23ec34e7c8f28962830c65fbb 6:pids:/docker/91fb4dc420690971d2d9cbf335af6066174d7cc23ec34e7c8f28962830c65fbb 5:cpuacct,cpu:/docker/91fb4dc420690971d2d9cbf335af6066174d7cc23ec34e7c8f28962830c65fbb 4:freezer:/docker/91fb4dc420690971d2d9cbf335af6066174d7cc23ec34e7c8f28962830c65fbb 3:memory:/docker/91fb4dc420690971d2d9cbf335af6066174d7cc23ec34e7c8f28962830c65fbb 2:devices:/docker/91fb4dc420690971d2d9cbf335af6066174d7cc23ec34e7c8f28962830c65fbb/system.slice/system-getty.slice 1:name=systemd:/docker/91fb4dc420690971d2d9cbf335af6066174d7cc23ec34e7c8f28962830c65fbb/system.slice/system-getty.slice/getty@tty1.service [root@lhrdb ~]# docker images | grep 91fb4dc4 [root@lhrdb ~]# docker ps | grep 91fb4dc4 91fb4dc42069 lhrbest/lhrubuntu1604:3.0 "init" 3 days ago Up 11 minutes 0.0.0.0:233->22/tcp, :::233->22/tcp, 0.0.0.0:43390->3389/tcp, :::43390->3389/tcp lhrubuntu1604 [root@lhrdb ~]# docker exec -it 91fb4dc42069 systemctl mask getty@tty1.service Created symlink from /etc/systemd/system/getty@tty1.service to /dev/null. [root@lhrdb ~]# docker exec -it 91fb4dc42069 systemctl stop getty@tty1.service [root@lhrdb ~]# [root@lhrdb ~]# [root@lhrdb ~]# top top - 14:28:04 up 28 min, 7 users, load average: 1.53, 11.58, 13.93 Tasks: 1162 total, 2 running, 1160 sleeping, 0 stopped, 0 zombie %Cpu(s): 1.3 us, 0.6 sy, 0.0 ni, 96.0 id, 0.0 wa, 0.0 hi, 0.1 si, 2.0 st KiB Mem : 65806012 total, 35857464 free, 12374612 used, 17573936 buff/cache KiB Swap: 35520504 total, 35520504 free, 0 used. 47755044 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 41738 root 20 0 10.8g 947896 9928 S 7.8 1.4 0:28.26 sqlservr 2751 root 20 0 3162464 98500 25852 S 7.2 0.1 1:22.11 dockerd 91686 lhr 20 0 7958748 2.0g 1.0g S 4.6 3.3 0:18.29 gaussdb |
解决
宿主机和docker容器都需要执行如下命令: