Difference between revisions of "CentOS 8.x install lxc"
From Notes_Wiki
(Created page with "<yambe:breadcrumb self="Install lxc">CentOS 8.x lxc|lxc<yambe:breadcrumb> =CentOS 8.x install lxc= ==Package installation To install lxc on CentOS 8.x use: # Install required...") |
m |
||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[Main Page|Home]] > [[CentOS]] > [[CentOS 8.x]] > [[CentOS 8.x virtualization|Virtualization]] > [[CentOS 8.x lxc|lxc]] > [[CentOS 8.x install lxc|Install]] | |||
==Package installation | ==Package installation and creation of test container== | ||
To install lxc on CentOS 8.x use: | To install lxc on CentOS 8.x use: | ||
# Install required packages: | # Install required packages: | ||
Line 12: | Line 11: | ||
#::lxc-checkconfig | #::lxc-checkconfig | ||
#:</pre> | #:</pre> | ||
# Then create network bridge if not created already by referring [[Creating bridge interfaces (br0) for virtual hosts to use shared interface]] or [[CentOS 7.x Managing virtual networks using libvirt virsh command]] | # Enable lxc service | ||
#:<pre> | |||
#:: systemctl start lxc | |||
#:: systemctl enable lxc | |||
#:: systemctl status lxc | |||
#:</pre> | |||
# Then create network bridge if not created already by referring [[CentOS 8.x Creating bridge interfaces (br0) for virtual hosts to use shared interface]] or [[CentOS 7.x Managing virtual networks using libvirt virsh command]] | |||
# Edit '<tt>/etc/lxc/default.conf</tt>' and update value of '<tt>lxc.network.link</tt>' in this file appropriately. | # Edit '<tt>/etc/lxc/default.conf</tt>' and update value of '<tt>lxc.network.link</tt>' in this file appropriately. | ||
# Store container files in a different partition then / or /var using [[CentOS 7.x installing lxc#Get_more_space_for_lxc_containers]] | # Store container files in a different partition then / or /var using [[CentOS 7.x installing lxc#Get_more_space_for_lxc_containers]] | ||
Line 29: | Line 34: | ||
#:: lxc-ls | #:: lxc-ls | ||
#:</pre> | #:</pre> | ||
# | # Download lxc-template for centos 8 | ||
#:<pre> | |||
#:: lxc-create -t download -n lxc1 | |||
#:: centos ##Enter as input for Distribution | |||
#:: 8 ##Enter as input for Release | |||
#:: amd64 ##Enter as input for architecture | |||
#:</pre> | |||
#: You can see help of download template using '<tt>lxc-create -t download -h</tt>'. Based on the help output download template supports options -d for Distribution, -r for Revision and -a for Architecture. Thus, we can also create centos-8-amd64 container using: | |||
#::<pre> | |||
#::: lxc-create -n test1 -t download -- -d centos -r 8 -a amd64 | |||
#::</pre> | |||
#:: This can actually be faster as image index does not needs to be downloaded and printed | |||
# Run the container and see that it is working as expected | |||
#:<pre> | |||
#:: ##Validate container is not running | |||
#:: lxc-ls -f | |||
#:: | |||
#:: ##Set container root password | |||
#:: chroot /var/lib/lxc/lxc1/rootfs/ | |||
#:: passwd | |||
#:: exit | |||
#:: | |||
#:: #Start container and install openssh to connect remotely | |||
#:: lxc-start -n lxc1 -d | |||
#:: lxc-ls -f | |||
#:: lxc-console -n lxc1 -t 0 | |||
#:: ## Login with root user and password set in previous steps | |||
#:: yum -y install openssh-server | |||
#:: systemctl start sshd | |||
#:: systemctl enable sshd | |||
#:: systemctl status sshd | |||
#:: #Exit lxc-console with "Ctrl-a q" shortcut | |||
#:</pre> | |||
#Get container IP address using '<tt>lxc-ls -f</tt>' | |||
#ssh to container as root and test | |||
Refer: | Refer: | ||
* https://www.redhat.com/sysadmin/exploring-containers-lxc | * https://www.redhat.com/sysadmin/exploring-containers-lxc | ||
* https://askubuntu.com/questions/640208/lxc-create-bad-template-download | |||
[[Main Page|Home]] > [[CentOS]] > [[CentOS 8.x]] > [[CentOS 8.x virtualization|Virtualization]] > [[CentOS 8.x lxc|lxc]] > [[CentOS 8.x install lxc|Install]] | |||
Latest revision as of 03:15, 23 April 2022
Home > CentOS > CentOS 8.x > Virtualization > lxc > Install
Package installation and creation of test container
To install lxc on CentOS 8.x use:
- Install required packages:
- sudo dnf install lxc lxc-templates lxc-doc libcgroup-pam libcgroup-tools libcgroup
- Test by running
- lxc-checkconfig
- Enable lxc service
- systemctl start lxc
- systemctl enable lxc
- systemctl status lxc
- Then create network bridge if not created already by referring CentOS 8.x Creating bridge interfaces (br0) for virtual hosts to use shared interface or CentOS 7.x Managing virtual networks using libvirt virsh command
- Edit '/etc/lxc/default.conf' and update value of 'lxc.network.link' in this file appropriately.
- Store container files in a different partition then / or /var using CentOS 7.x installing lxc#Get_more_space_for_lxc_containers
- lxc-ls --active
- mkdir /mnt/data1/large_files/lxc-files
- mkdir /mnt/data1/large_files/lxc-files/{var_cache_lxc,var_lib_lxc}
- mv /var/cache/lxc/* /mnt/data1/large_files/lxc-files/var_cache_lxc/ #Ignore no-such files error, if printed
- rmdir /var/cache/lxc
- ln -s /mnt/data1/large_files/lxc-files/var_cache_lxc/ /var/cache/lxc
- mv /var/lib/lxc/* /mnt/data1/large_files/lxc-files/var_lib_lxc/ #Ignore no such fies error, if printed
- rmdir /var/lib/lxc
- ln -s /mnt/data1/large_files/lxc-files/var_lib_lxc/ /var/lib/lxc
- lxc-ls
- Download lxc-template for centos 8
- lxc-create -t download -n lxc1
- centos ##Enter as input for Distribution
- 8 ##Enter as input for Release
- amd64 ##Enter as input for architecture
- You can see help of download template using 'lxc-create -t download -h'. Based on the help output download template supports options -d for Distribution, -r for Revision and -a for Architecture. Thus, we can also create centos-8-amd64 container using:
- lxc-create -n test1 -t download -- -d centos -r 8 -a amd64
- This can actually be faster as image index does not needs to be downloaded and printed
- Run the container and see that it is working as expected
- ##Validate container is not running
- lxc-ls -f
- ##Set container root password
- chroot /var/lib/lxc/lxc1/rootfs/
- passwd
- exit
- #Start container and install openssh to connect remotely
- lxc-start -n lxc1 -d
- lxc-ls -f
- lxc-console -n lxc1 -t 0
- ## Login with root user and password set in previous steps
- yum -y install openssh-server
- systemctl start sshd
- systemctl enable sshd
- systemctl status sshd
- #Exit lxc-console with "Ctrl-a q" shortcut
- Get container IP address using 'lxc-ls -f'
- ssh to container as root and test
Refer:
- https://www.redhat.com/sysadmin/exploring-containers-lxc
- https://askubuntu.com/questions/640208/lxc-create-bad-template-download
Home > CentOS > CentOS 8.x > Virtualization > lxc > Install