In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "the installation and basic usage of the OpenVZ virtual machine on the CentOS system". In the daily operation, I believe that many people have doubts about the installation and basic usage of the OpenVZ virtual machine on the CentOS system. The editor consulted all kinds of materials and sorted out the simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about the installation and basic usage of the OpenVZ virtual machine on the CentOS system. Next, please follow the editor to study!
OpenVZ is open source software and is an operating system-level server virtualization solution based on the Linux platform. OpenVZ uses the core of SWsoft's Virutozzo virtualization server software products, and Virutozzo is a commercial virtualization solution provided by SWsoft.
OpenVZ can create multiple isolated virtual private servers (VPS) on a single physical server and share hardware and management resources with maximum efficiency. Each VPS runs exactly the same as an independent server, because its own users and applications can be restarted independently, and it has root access rights, users, IP addresses, memory, processors, files, application services, system library files, configuration files, and so on. With lightweight processing attrition and efficient design, OpenVZ is the best choice for running application services and virtualizing real-time data production servers.
OpenVZ software also provides users with tools to help automate the management of virtual servers. Template-based application deployment can create new virtual servers and put them into use in a simple way in a few minutes, and OpenVZ can run several times more virtualized servers per CPU than other virtualized server technologies.
OpenVZ is an operating system-level virtualization technology based on Linux kernel and operating system. OpenVZ allows physical servers to run multiple operating systems, known as virtual private servers (VPS,Virtual Private Server) or virtual environments (VE, Virtual Environment).
Compared with hardware virtualized VMware and paravirtualized Xen, both host OS and guest OS of OpenVZ must be Linux (although different Linux distributions can be used in different virtual environments). However, OpenVZ claims that this has a performance advantage. According to the OpenVZ website, there is only a 1-3% performance loss between using OpenVZ and using a stand-alone server.
Install OpenVZ
To complete the installation of OpenVZ, we need to first add the OpenVZ library to yum:
The code is as follows:
Cd / etc/yum.repos.d
Wget http://download.openvz.org/openvz.repo
Rpm-- import http://download.openvz.org/RPM-GPG-Key-OpenVZ
Now open the openvz.repo file:
The code is as follows:
Vi openvz.repo
Next, disable the [openvz-kernel-rhel5] library (enabled=0) and enable the [openvz-kernel-rhel6] library as an alternative (enabled=1):
The code is as follows:
[...]
[openvz-kernel-rhel6]
Name=OpenVZ RHEL6-based kernel
# baseurl= http://download.openvz.org/kernel/branches/rhel6-2.6.32/current/
Mirrorlist= http://download.openvz.org/kernel/mirrors-rhel6-2.6.32
Enabled=1
Gpgcheck=1
Gpgkey= http://download.openvz.org/RPM-GPG-Key-OpenVZ
[openvz-kernel-rhel5]
Name=OpenVZ RHEL5-based kernel
# baseurl= http://download.openvz.org/kernel/branches/rhel5-2.6.18/current/
Mirrorlist= http://download.openvz.org/kernel/mirrors-rhel5-2.6.18
Enabled=0
Gpgcheck=1
Gpgkey= http://download.openvz.org/RPM-GPG-Key-OpenVZ
[...]
This library contains a variety of OpenVZ kernels (for more information on different kernels, visit http://wiki.openvz.org/Kernel_flavors). The following command:
The code is as follows:
Yum search vzkernel
All available kernels are listed on the screen:
The code is as follows:
[root@server1 yum.repos.d] # yum search vzkernel
[...]
Vzkernel.i686: The Linux kernel
Vzkernel.x86_64: The Linux kernel
Vzkernel-devel.i686: Development package for building kernel modules to match the kernel
Vzkernel-devel.x86_64: Development package for building kernel modules to match the kernel
Vzkernel-firmware.noarch: Firmware files used by the Linux kernel
Vzkernel-headers.i686: Header files for the Linux kernel for use by glibc
Vzkernel-headers.x86_64: Header files for the Linux kernel for use by glibc
[...]
[root@server1 yum.repos.d] #
Select one of them and install it as follows:
The code is as follows:
Yum install vzkernel
This should also automatically update the GRUB bootstrapper. In any case, we are going to open / boot/grub/menu.lst; now that the first kernel should already contain the new OpenVZ kernel. Make sure that the default value is 0 so that the first kernel (that is, the OpenVZ kernel) is automatically booted and the default CentOS kernel is replaced.
The code is as follows:
Vi / boot/grub/menu.lst
# grub.conf generated by anaconda
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a / boot partition. This means that
# all kernel and initrd paths are relative to / boot/, eg
# root (hd0,0)
# kernel / vmlinuz-version ro root=/dev/mapper/vg_server1-lv_root
# initrd / initrd- [generic-] version.img
# boot=/dev/sda
Default=0
Timeout=5
Splashimage= (hd0,0) / grub/splash.xpm.gz
Hiddenmenu
Title OpenVZ (2.6.32-042stab057.1)
Root (hd0,0)
Kernel / vmlinuz-2.6.32-042stab057.1 ro root=/dev/mapper/vg_server1-lv_root rd_LVM_LV=vg_server1/lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=de rd_LVM_LV=vg_server1/lv_swap rd_NO_DM rhgb quiet
Initrd / initramfs-2.6.32-042stab057.1.img
Title CentOS (2.6.32-279.el6.x86_64)
Root (hd0,0)
Kernel / vmlinuz-2.6.32-279.el6.x86_64 ro root=/dev/mapper/vg_server1-lv_root rd_LVM_LV=vg_server1/lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=de rd_LVM_LV=vg_server1/lv_swap rd_NO_DM rhgb quiet
Initrd / initramfs-2.6.32-279.el6.x86_64.img
Now we need to install several OpenVZ user tools:
The code is as follows:
Yum install vzctl vzquota
Open / etc/sysctl.conf and make sure the file contains the following settings:
The code is as follows:
Vi / etc/sysctl.conf
[...]
Net.ipv4.ip_forward = 1
Net.ipv4.conf.default.proxy_arp = 0
Net.ipv4.conf.all.rp_filter = 1
Kernel.sysrq = 1
Net.ipv4.conf.default.send_redirects = 1
Net.ipv4.conf.all.send_redirects = 0
Net.ipv4.icmp_echo_ignore_broadcasts=1
Net.ipv4.conf.default.forwarding=1
[...]
If you need to modify / etc/sysctl.conf, please add the following after the above command:
The code is as follows:
Sysctl-p
If your virtual machine IP address comes from a different subnet rather than using the IP address of the host system directly, then the next step is critical. If you ignore this step, the network will not work properly on the virtual machine.
Open / etc/vz/vz.conf and set NEIGHBOUR_DEVS to all:
The code is as follows:
Vi / etc/vz/vz.conf
[...]
NEIGHBOUR_DEVS=all
[...]
If you want OpenVZ to work properly, then SELinux must be disabled. Open / etc/sysconfig/selinux and set the value of SELINUX to disabled:
The code is as follows:
Vi / etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing-SELinux security policy is enforced.
# permissive-SELinux prints warnings instead of enforcing.
# disabled-No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted-Targeted processes are protected
# mls-Multi Level Security protection.
SELINUXTYPE=targeted
Finally, restart the system:
The code is as follows:
Reboot
If your system has successfully restarted, congratulations-the installation has been completed successfully!
Run:
The code is as follows:
Uname-r
At this point our new OpenVZ kernel should show the following:
The code is as follows:
[root@server1 ~] # uname-r
2.6.32-042stab057.1
The code is as follows:
[root@server1 ~] #
Before creating a virtual machine with OpenVZ, we need to add a set of templates under the / vz/template/cache directory for the distribution we want to use, which will be responsible for the generation of the virtual machine. You can find a list of pre-created templates at the following address: http://wiki.openvz.org/Download/template/precreated).
I intend to use CentOS 6 in my virtual machine, so I need to download the CentOS 6 template:
The code is as follows:
Cd / vz/template/cache
Wget http://download.openvz.org/template/precreated/centos-6-x86_64.tar.gz
Now I'm going to show you the basic commands involved in using OpenVZ.
To build a set of VPS through the CentOS 6 template, run:
The code is as follows:
Vzctl create 101-- ostemplate centos-6-x86_64-- config basic
Here 101 must be a separate ID-- and each virtual machine needs to have its own independent ID. You can use the last three digits of the virtual machine IP address to name it. For example, if the virtual machine IP address is 192.168.0.101, then its ID is 101.
If you want to run the virtual machine automatically when the system starts, execute the following command:
The code is as follows:
Vzctl set 101-- onboot yes-- save
To set the host name and IP address for the virtual machine, run the following command:
The code is as follows:
Vzctl set 101-- hostname test.example.com-- save
Vzctl set 101-- ipadd 192.168.0.101-- save
Next, we set the number of sockets to 120 and assign several domain name servers to the virtual machine:
The code is as follows:
Vzctl set 101-- numothersock 120-- save
Vzctl set 101-- nameserver 8.8.8.8-- nameserver 8.8.4.4-- nameserver 145.253.2.75-- save
(note that here we can also use the vzctl set command or edit the virtual machine configuration file directly in the / etc/vz/conf directory. If the virtual machine ID is 101, the path to the configuration file should be / etc/vz/conf/101.conf.)
Run the following command to start the virtual machine:
The code is as follows:
Vzctl start 101
Execute the following command to set the root password for the virtual machine:
The code is as follows:
Vzctl exec 101 passwd
You can now connect to the virtual machine through SSH (such as PuTTY) or by manually entering the following command:
The code is as follows:
Vzctl enter 101
To exit the virtual machine console, you can enter:
The code is as follows:
Exit
Stop the virtual machine from running, run:
The code is as follows:
Vzctl stop 101
Restart the virtual machine to run:
The code is as follows:
Vzctl restart 101
If you need to remove a virtual machine from disk (provided that we have stopped running the virtual machine), execute the following command:
The code is as follows:
Vzctl destroy 101
To list the current virtual machine and its running status, run:
The code is as follows:
Vzlist-a
[root@server1 cache] # vzlist-a
CTID NPROC STATUS IP_ADDR HOSTNAME
101 14 running 192.168.0.101 test.example.com
[root@server1 cache] #
To view the resources assigned to the corresponding virtual machine, run:
The code is as follows:
Vzctl exec 101 cat / proc/user_beancounters
[root@server1 cache] # vzctl exec 101 cat / proc/user_beancounters
Version: 2.5
Uid resource held maxheld barrier limit failcnt
101: kmemsize 1508202 1661695 11055923 11377049 0
Lockedpages 0 0 256 256 0
Privvmpages 5430 7102 65536 69632 0
Shmpages 381 381 21504 21504 0
Dummy 0 0 0
Numproc 19 21 240 240 0
Physpages 2489 2775 0 2147483647 0
Vmguarpages 0 0 33792 2147483647 0
Oomguarpages 2489 2775 26112 2147483647 0
Numtcpsock 5 5 360 360 0
Numflock 3 4 188 206 0
Numpty 0 1 16 16 0
Numsiginfo 0 2 256 256 0
Tcpsndbuf 44720 0 1720320 2703360 0
Tcprcvbuf 81920 0 1720320 2703360 0
Othersockbuf 13144 14356 1126080 2097152 0
Dgramrcvbuf 0 8380 262144 262144 0
Numothersock 11 13 120 120 0
Dcachesize 0 0 3409920 3624960 0
Numfile 503 531 9312 9312 0
Dummy 0 0 0
Dummy 0 0 0
Dummy 0 0 0
Numiptent 10 10 128 128 0
[root@server1 cache] #
The information in the failcnt column is very important, normally all values should be 0; if there is a non-zero number, it means that the current virtual machine does not have enough resources and we need to allocate more resources to it. Open the virtual machine configuration file in the / etc/vz/conf directory, increase the number of corresponding resources, and finally restart the virtual machine.
If you need to do something else, you can run the following command to see all the instructions for vzctl:
The code is as follows:
Man vzctl
At this point, the study on the installation and basic usage of the OpenVZ virtual machine on the CentOS system is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.