下面提供了Linux下资源组的配置和使用过程:
- 要使用 cgroups,你必须在你的系统上安装“libcgroup”包:
# yum install libcgroup
- 为 cgroups 创建一个配置文件:
# vi /etc/cgconfig.conf mount { cpu = /cgroup/cpumem; cpuset = /cgroup/cpumem; memory = /cgroup/cpumem; } # High priority group group mysqldb { cpu { # Allocate the relative share of CPU resources equal to 75% cpu.shares="750"; } cpuset { # No alternate memory nodes if the system is not NUMA cpuset.mems="0"; # Allocate CPU cores 2 through 5 to tasks in the cgroup cpuset.cpus="2-5"; } memory { # Allocate at most 8 GB of memory to tasks memory.limit_in_bytes="8G"; # Allocate at most 16 GB of memory+swap to tasks memory.memsw.limit_in_bytes="16G"; # Apply a soft limit of 4 GB to tasks memory.soft_limit_in_bytes="4G"; } }
- 创建 cgroup 规则定义文件:
# vi /etc/cgrules.conf # Assign tasks run by the mysql user to mysqldb mysql cpu,cpuset,memory mysqldb
- 启动cgconfig服务,配置为系统启动时启动。
$ service cgconfig start $ chkconfig cgconfig on
至此,mysql的资源组已经准备就绪。
重新启动 mysqld,它将根据上面提供的配置和规则获得资源。我们也可以在运行时查找和更改资源组限制。
要查找资源限制:
$ cgget -r memory.stat mysqldb
设置资源限制:
$ cgset -r blkio.throttle.read_bps_device="8:1 0" iocap1
保存当前修改的配置以备将来使用:
$ cgsnapshot -s > current_cgconfig.conf
日期:2020-09-17 00:13:23 来源:oir作者:oir