tags: - postgresql - lxc categories: - informational comments: true
Attempt to emulate production databases using linux containers. Can be used to test database take-over, replication settings, performance, etc…
sudo apt install lxc lxc-templates lxc-utils cgroup-tools
sudo lxc-create -n db1 -t ubuntu -- -r focal -u test --password welcome
sudo lxc-create -n db2 -t ubuntu -- -r focal -u test --password welcome
set memory limit on container
cgroup settings will not work unless lxcfs is installed.
sudo apt install lxcfs
<https://github.com/lxc/lxc/issues/2845>
Hi, after install lxcfs, the free command in lxc container show the correct memory now, Thanks.
In PRD a database node - KVM - is allocated 1 CPU and 2 GB RAM.
Options: Create a KVM with 1 CPU and 2GB RAM or run container with memory and
CPU restriction.
Emulate containers with 1 CPU and 512MB RAM.
Testing
sudo lxc-cgroup -n db1 memory.soft_limit_in_bytes 536870912 sudo lxc-cgroup -n db1 memory.limit_in_bytes 536870912
sudo lxc-cgroup -n db1 cpuset.cpus 0
Permanent
sudo vi /var/lib/lxc/db1/config
… lxc.cgroup.memory.limit_in_bytes = 536870912 lxc.cgroup.memory.max_usage_in_bytes = 536870912
lxc.cgroup.cpuset.cpus = 0
Start the containers
sudo lxc-start -n db1 # 10.0.3.11 sudo lxc-start -n db2 # 10.0.3.111 “`