{{tag>Brouillon Debian Linux}}
= Notes cgroup
Voir :
* http://blog.hintcafe.com/post/60223405371/resource-limiting-using-cgroups
* http://www.linuxmao.org/CGroup
* http://libcg.sourceforge.net/
* http://askubuntu.com/questions/345055/how-to-use-cgroup-in-ubuntu-13-04
* http://www.janoszen.com/2013/02/06/limiting-linux-processes-cgroups-explained
* http://www.serverwatch.com/tutorials/article.php/3921001/Setting-Up-Linux-Cgroups.htm
* https://unix.stackexchange.com/questions/22400/using-linux-cgroups-to-balance-cpu-performance
* http://hydra.geht.net/tino/english/faq/debian/squeeze/cgroups/
* http://upstart.ubuntu.com/wiki/Cgroup
* http://hydra.geht.net/tino/english/faq/debian/squeeze/cgroups/
* http://www.linuxmao.org/CGroup
* https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Resource_Management_Guide/Starting_a_Process.html
* [[https://codywu2010.wordpress.com/2015/09/27/cpuset-by-example/|cpuset]]
* https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/managing_monitoring_and_updating_the_kernel/assembly_using-cgroupfs-to-manually-manage-cgroups_managing-monitoring-and-updating-the-kernel
* https://docs.kernel.org/admin-guide/cgroup-v2.html
* https://github.com/kubernetes-sigs/kind/issues/3650
* https://linuxembedded.fr/2021/11/limiter-les-ressources-dune-ligne-de-commande-avec-systemd
* https://lpc.events/event/16/contributions/1184/attachments/1019/1963/delegation-slides.pdf
* https://www.freedesktop.org/software/systemd/man/latest/systemd.resource-control.html
* https://systemd.io/CGROUP_DELEGATION/
* https://blog.stephane-robert.info/docs/admin-serveurs/linux/cgroups/
Tester si tous est ok
apt-get install lxc
lxc-checkconfig
ou
#apt-get install docker.io
#/usr/share/docker.io/contrib/check-config.sh
https://github.com/opencontainers/runc/blob/main/script/check-config.sh
Dans Debian :mount cgroup automatically in mountkernfs.
* https://wiki.debian.org/LXC
* http://blog.blaisethirard.com/creer-des-serveurs-virtuels-debian-7-wheezy-avec-lxc-sur-un-dedie-ovh-kimsufi-2/
* http://www.pointroot.org/index.php/2013/05/12/installation-du-systeme-de-virtualisation-lxc-linux-containers-sur-debian-wheezy/
* https://fralef.me/getting-started-with-lxc-on-debian-wheezy.html
* http://sylvain.fankhauser.name/setting-up-lxc-containers-in-30-minutes-debian-wheezy.html
* http://l3net.wordpress.com/2013/08/10/debian-virtualization-lxc-application-containers/
Normalement sous Debian, les cgroup sont automatiquement montés (dans le mountkernfs)
$ mount |grep cgroup
none on /sys/fs/cgroup type tmpfs (rw,relatime,size=4k,mode=755)
systemd on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,name=systemd)
Si ce n'est pas le cas, la technique d'ajouter dans /etc/fstab
''/etc/fstab''
cgroup /cgroup cgroup defaults 0 0
ou alors passer à systemd
apt-get install systemd systemd-sysv
Voir :
* https://medium.com/@johannes_gehrs/getting-started-with-systemd-on-debian-jessie-e024758ca63d
* https://wiki.debian.org/systemd
* http://www.linuxcore.fr/2012/10/systemctl/
Mais comme nous choisissons la méthode avec des services (méthode à la Redhat)
Pour connaître les ????? FIXME prit en charge par le noyau
# lssubsys -a
cpuset
cpu
cpuacct
memory
devices
freezer
net_cls
blkio
perf_event
Install du packet
apt-get update && apt-get install -y cgroup-tools
Puis
dpkg -L cgroup-tools
Donc
mkdir /etc/sysconfig/
cp -p /usr/share/doc/cgroup-tools/examples/cgconfig.sysconfig /etc/sysconfig/cgconfig
cp -p /usr/share/doc/cgroup-tools/examples/cgred.conf /etc/sysconfig/cgred
cp -p /usr/share/doc/cgroup-tools/examples/cgred /etc/init.d/
cp -p /usr/share/doc/cgroup-tools/examples/cgconfig /etc/init.d/
cp -p /usr/share/doc/cgroup-tools/examples/cgconfig.conf /etc/
cp -p /usr/share/doc/cgroup-tools/examples/cgrules.conf /etc/
chmod a+x /etc/init.d/cgconfig /etc/init.d/cgred
ln -s /etc/sysconfig/cgconfig /etc/default/
ln -s /etc/sysconfig/cgred /etc/default/
sed -i -e 's|/var/lock/subsys/|/var/lock/|g' /etc/init.d/cgred
sed -i -e 's|/var/lock/subsys/|/var/lock/|g' /etc/init.d/cgconfig
getent group cgred >/dev/null || groupadd -r cgred
Puis prendre le fichier /etc/rc.d/init.d/functions sur une CentOS.
mkdir -p /etc/rc.d/init.d/
cp -p functions /etc/rc.d/init.d/
Commenter la ligne **[ -z "${CONSOLETYPE:-}" ] && CONSOLETYPE="$(/sbin/consoletype)"**
vi /etc/rc.d/init.d/functions
Puis
mkdir /cgroup
cd /cgroup
mkdir $(lssubsys -a)
Erreur sous Debian :
# /etc/init.d/cgconfig start
Starting cgconfig service: Error: cannot mount memory to /cgroup/memory: No such file or directory
/usr/sbin/cgconfigparser; error loading /etc/cgconfig.conf: Cgroup mounting failed
[FAIL] Failed to parse /etc/cgconfig.conf ... failed!
Solution : rajouter "cgroup_enable=memory swapaccount=1" à votre Grub :
''/etc/default/grub''
GRUB_CMDLINE_LINUX="vga=795 cgroup_enable=memory swapaccount=1"
update-grub
Pour le debug si nécessaire :
export CGROUP_LOGLEVEL=debug
Autres
allocated 133693440 bytes of page_cgroup
please try 'cgroup_disable=memory' option if you don't want memory cgroups
-----
https://wiki.debian.org/LXC
''/etc/fstab''
cgroup /sys/fs/cgroup cgroup defaults 0 0
* http://stackoverflow.com/questions/21337522/trying-to-use-cgroups-in-debian-wheezy-and-no-daemons
* http://blog.hbis.fr/2012/01/16/debian-webserver_and_cgroups/
* http://linuxaria.com/article/introduction-to-cgroups-the-linux-conrol-group
''/etc/default/grub''
GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"
* http://blog.docker.com/2013/10/gathering-lxc-docker-containers-metrics/
-------------
sudo apt-get install cgroup-tools
sudo cgcreate -a jean -g memory:plop
echo 10000000 > /sys/fs/cgroup/memory/plop/memory.kmem.limit_in_bytes
sudo cgexec -g memory:plop bash
-------------
cgroupv1 ou v2 ?
podman info
docker info
mount | grep cgroup2
systemctl --user status
grep cgroup /proc/filesystems
Pour passer à la version 2
grubby --update-kernel=ALL --args="systemd.unified_cgroup_hierarchy=1"
Autres
cat /sys/fs/cgroup/user.slice/user-1003.slice/cgroup.controllers
cpuset cpu io memory pids