Showing posts with label OpenVZ. Show all posts
Showing posts with label OpenVZ. Show all posts

Constraints needed for OpenVPN within OpenVZ




You can run OpenVPN Access Server on a virtual host within a VPS (Virtual Private Server) if particular constraints are satisfied.


Prepare your VPS host so that the following requirements are met:

All the steps described below to be done on the host node, not the individual VPS container. You have to login as root user.

1. Make the iptables state and nat modules accessible to containers.

Edit /etc/vz/vz.conf and add "ipt_state iptable_nat" to the end of the list of IPTABLES modules.

2. Allow the container to open the TUN/TAP interface.

# vzctl stop <VPSID>

# vzctl set <VPSID> --devices c:10:200:rw --save

# vzctl set <VPSID> --capability net_admin:on --save

3. These kernel modules and commands should be ran/installed on the host node before the container is started:

# modprobe ipt_mark

# modprobe ipt_MARK

# modprobe tun

4. Now start the container:

# vzctl start <VPSID>

5. After starting the container run these commands on the host node:

# vzctl exec <VPSID> mkdir -p /dev/net

# vzctl exec <VPSID> mknod /dev/net/tun c 10 200

# vzctl exec <VPSID> chmod 600 /dev/net/tun

6. Install AS normally in the container.


That's it...

cPanel - edquota: Quota file not found or has wrong format.


Error:

After running /scripts/fixquotas it gives the following error message and showing unlimited disk space in
WHM >> Main >> List accounts.

==============================================================
edquota: Quota file not found or has wrong format.
No filesystems with quota detected.
==============================================================

Solution:

The error is due to no quota file. You can follow the steps shown below to fix this issue.

root@server [~]# touch /home/quota.user
root@server [~]# touch /home/quota.group
root@server [~]# chmod 600 /home/quota.user
root@server [~]# chmod 600 /home/quota.group
root@server [~]# quotacheck -acugvm

quotacheck: Scanning /dev/simfs [/] quotacheck: Cannot stat old user quota file: No such file or directory
quotacheck: Cannot stat old group quota file: No such file or directory
quotacheck: Cannot stat old user quota file: No such file or directory
quotacheck: Cannot stat old group quota file: No such file or directory
done
quotacheck: Checked 16689 directories and 234323 files
quotacheck: Old file not found.
quotacheck: Old file not found.

root@server [~]# /scripts/fixquotas --force

Installing Default Quota Databases......Done
Quota Mode: Linux
journaled quota support: not available with vzaquota (disabled)
Quotas have been enabled, however they may not be up to date as quotacheck has been skipped.
Reading package Starter
Resetting quota for arun to 2000 M
.
..
...

Thanks...

OpenVZ - Operation not permitted on changing date



Error:

When you try to set date in a OpenVZ container, it may show Operation not permitted error.


Reason:

The capability for setting time is not given for the container.
sys_time capability mustbe enabled for the container to set the date and time.


Solution:

1. Login to OpenVZ Hardware Node as root user.

2. [root@HN ~] # vzlist -a | grep <IP of VPS>
                  <VPSID>         59  running   <IP>  server.example.com

3. [root@HN ~] # vzctl stop <VPSID>

4. [root@HN ~] # vzctl set <VPSID> --capability sys_time:on --save

5. [root@HN ~] # vzctl start <VPSID>


Now the capability parameter for changing time is given for the container.
Try again changing the date. This time it will permit you to change the date and time.

Reference:
http://wiki.openvz.org/Man/vzctl.8#Capability_option

cPanel - Unlimited Quota issue in OpenVZ Containers



The Following Two Cases Have the Same Fix:-


Error-Case 1:-

safe_userchgid error in WHM

If you are using OpenVZ container(VPS) you may encounter the following error in WHM when you create new accounts.

safe_userchgid: chown: /home/vps/etc: Permission denied at /usr/local/cpanel/Cpanel/SafetyBits.pm line 93.
Cpanel::SafetyBits::safe_userchgid(517, 12, '/home/vps/etc') called at /usr/local/cpanel/Whostmgr/Accounts/Create.pm line 846
Whostmgr::Accounts::Create::_wwwacct('dkim', 1, 'mxcheck', 'auto', 'spf', 1, 'maxftp', 'n', ...) called at /usr/local/cpanel/Whostmgr/Accounts/Create.pm line 1849
Whostmgr::Accounts::Create::__createaccount('mxcheck', 'auto', 'dkim', 1, 'spf', 1, 'language', 'en', ...) called at /usr/local/cpanel/Whostmgr/Accounts/Create.pm line 1899
Whostmgr::Accounts::Create::_createaccount('mxcheck', 'auto', 'dkim', 1, 'spf', 1, 'language', 'en', ...) called at whostmgr/bin/whostmgr5 line 565
main::wwwacct() called at whostmgr/bin/whostmgr5 line 214

It is the issue in settings the quotaugidlimit value for your VPS. You have to increase quotaugidlimit value to solve this issue.


Error-Case 2:-

When you create new accounts in cPanel/WHM its Quota is shown as Unlimited.
It will not change even if you run /scripts/fixquotas.


Solution:

It is the issue in setting up the quotaugidlimit value for that particular VPS.
In order to fix the issues shown above, you need root access to the Hardware Node (HN) of that particular VPS.

You can fix this issue by following the steps shown below.

1. Login to HN as root user.

2. [root@HN ~] # vzlist -a | grep <IP of VPS>
                  <VPSID>         59 running   <IP>  server.example.com

3. [root@HN ~] # vzctl stop <VPSID>

4. [root@HN ~] # vzctl set <VPSID> --quotaugidlimit 1000 --save
                  CT configuration saved to /etc/vz/conf/<VPSID>.conf

5. [root@HN ~] # vzctl start <VPSID>

If you are facing Case1 issue only, try creating new accounts.

If you are facing Case2 issue you have to do the following steps too.

6. [root@HN ~] # vzctl enter <VPSID>

7. [root@vps ~] # /scripts/fixquotas

Verify the Quota in WHM whether it is updates or not.


Reference:-
http://wiki.openvz.org/User_Guide/Managing_Resources
 
 

OpenVZ - Change Disk Quota

To check if your VE ran out of its disk quota, use the following commands (inside a VPS).

# df
   -To show disk space usage

# df -i
   -To show the inodes usage

If one of the commands give you usage of 100%, that means you hit one of the disk quota limit. You can increase the limit from the host system (Hardware Node) only.

To change the current Disk Quota,

1.Login to Hardware Node,

# vzquota stat <VPSID>
   -To  get the current values for disk quota. The result will be as shown in the figure.


2. To increase the disk space quota, use vzctl set --diskspace

# vzctl set <VPSID> --diskspace  $(( 1048576*3 )):$(( 1153434*3 )) --save
   -To increase quota by a factor 3

3. To increase the disk inodes quota, use vzctl set --diskinodes.


# vzctl set <VPSID> --diskinodes $(( 200000*4 )):$(( 220000*4 )) --save 
   -To increase quota by a factor 4

# vzctl exec <VPSID> df -i
   -To check whether the changes affected or not.

OpenVZ- UBC Parameters

UBC Parameters:

                     UBC, or User BeanCounters is a set of limits and guarantees controlled per Virtual Environment. UBC is the major component of OpenVZ resource management.


 The figure shows the UBC parameters of a VPS.
Enter in to VPS and run the following command.

# cat /proc/user_beancounters
   -To show the UBC parameters of a VPS.

                   You can see if you hit the limits for some UBC parameters by analyzing the last column (named failcnt). It shows a number of fails for this counter, i.e. a number of times a parameter hit the limit. Usually what you need to do is to increase the parameter. But you need to do it carefully.


If you want to increase kmemsize,

1. Get the current values for the parameter's barrier and limit
    Let, kmemsize barrier is 'x', and its limit is 'y'.

2. Increase the values. Say, we want to increase kmemsize by 2 times.

   # vzctl set <VPSID> --kmemsize $((x*2)):$((y*2)) --save 
    The above command doubled the parameter using bash arithmetic.

By using --save flag, we denote we want to both apply the new settings to the running VE, and save them in the configuration file (from which they will be taken during next VE start).

3. Check the new configuration.

# vzcfgvalidate /etc/vz/conf/<VPSID>.conf 


Note:-You can change the other parameters as like 'kmemsize'.
 

OpenVZ- Create a Container

To create a container, you have to
-Choose the container ID
-Choose the OS template to use for the Container

Choose a container id greater than 100. CTID 0-100 are reserver.

# vzlist -a
    -To list all the containers in the Hardware Node. You can choose a ID other than in the list.

# ls /vz/template/cache/
   centos-5-x86_64.tar.gz
   fedora-7-x86_64.tar.gz
   suse-10.3-x86_64.tar.gz
  
   -To list all the OS templates in the Hardware Node.

               After the Container ID and the installed OS template have been chosen, you can create the Container private area with the vzctl create command. The private area is the directory containing the actual files of the given Container; it is usually residing in /vz/private/CTID/. The private area is mounted to the /vz/root/CTID directory on the Hardware Node and provides Container users with a complete Linux file system tree.

              The vzctl create command requires only the Container ID and the name of the OS template as arguments; however, in order to avoid setting all the Container resource control parameters after creating the private area, you can specify a sample configuration to be used for your new Container. The sample configuration files are residing in the /etc/vz/conf directory and have names with the following mask: ve-configname.conf-sample. The most commonly used sample is the ve-basic.conf-sample file; this sample file has resource control parameters suitable for most Containers.


# vzctl create <CTID>  --ostemplate centos-5-x86 -–config basic

            If you specify neither an OS template nor a sample configuration, vzctl will try to take the corresponding values from the global OpenVZ configuration file (/etc/vz/vz.conf).

Now the VPS is created. We can now configure the VPS with the start-up and network parameters.

OpenVZ- Concept of Container, Hardware Node and CT0

Container:-

    A container (otherwise known as CT, Virtual Environment (VE), Virtual Private Server (VPS) etc.) is one of the main concepts of OpenVZ.
    Container is an isolated entity which performs and executes exactly like a stand-alone server. Container can be rebooted independently and have root access, users/groups, IP address(es), memory, processes, files, applications, system libraries and configuration files.

    OpenVZ allows to have multiple CTs on a single Hardware Node. Every container has a ConTainer's IDentifer (CTID) which is used to manage the container.
     The OpenVZ software reserves the IDs ranging from 0 to 100. Though OpenVZ uses only ID 0, future versions might use additional Container IDs for internal needs. Do not create Containers with IDs below 101.

Hardware Node:-

    Hardware Node (otherwise known as host system) is a term used in OpenVZ. Basically it means the physical server on which OpenVZ is installed and running. Sometimes Hardware Node is abbreviated as HW or HN.

CT0:-

    In OpenVZ, you have multiple CTs, as well as the host system  itself, which is otherwise known as CT0 or VE0. In other words, CT0 means the server itself. From CT0, we can use vzctl and other tools to manage containers. From CT0, all the containers' processes, files, etc. are accessible. From CT0, we manage the hardware, install a new kernel, etc.
CT0 - Container Zero
Container ID Zero is given to the Hardware Node itself.

What is OpenVZ?

OpenVZ
     
     OpenVZ (Open VirtualiZation) is an operating system-level virtualization technology based on the Linux kernel and operating system. OpenVZ allows a physical server to run multiple isolated operating system instances, known as containers, Virtual Private Servers (VPSs).OpenVZ is limited in that it requires both the host and guest OS to be Linux.

    OpenVZ is a virtualisation technology that was developed by Parallels, and is the basis for their Virtuozzo platform. OpenVZ consists of the open sourced parts of Virtuozzo.

    OpenVZ works somewhat like Solaris Zones or FreeBSD jails, in the aspect that it utilizes a single operating system kernel and creates various user-environments within the single operating system space. The various user-environments are called Virtual Environments, of VE.

    Users in a VE will have their own view on the available resources in the system. They are only able to see and interact with processes running in the same VE, they only have access to files and diskspace assigned to the VE and can only see network-traffic destined to the IP address assigned to the VE.

Advantages
    Due to the fact that OpenVZ uses a single operating system kernel to provide various Virtual Environments the overhead of OpenVZ is very low. No memory is wasted by loading copies of the kernel for every VE, no translation is needed for I/O going to the storage or network.This allows for very lightweight VE’s, with some environments taking less then 8MB of memory and only a few megabytes of diskspace.

    Another advantage of OpenVZ is that it doesn’t require any hardware-assisted virtualisation on the system and it doesn’t need to ‘emulate’ any cpu or I/O instructions, which would put a large strain on the resources.
     Your files and processes are visible on the host-system, but hidden from other users of the system. Only the root-user on the host can access your resources. This access is also used to make backups of all your files, so System Administers can help you with a restore in case you accidentally erase some files.

     It is possible to mount iso images and use sshfs systems using fuse, but kernel-mode mounting is not available.

DisAdvantages
    A disadvantage of the OpenVZ VE’s is that only Linux environments are possible, since the kernel is shared between all environments it’s not possible for a VE to make modifications to the kernel. It’s also not allowed for the VE’s to change their IP-configuration, to act as NFS servers or to mount filesystems, as this would have an impact on the host’s security system.

Note:- You can refer the following links to know more about OpenVZ
http://sudosu.in/search?q=openvz#!/2012/07/openvz-concept-of-container-hardware.html
http://sudosu.in/search?q=openvz#!/2012/07/openvz-create-container.html
http://sudosu.in/search?q=openvz#!/2012/07/openvz-frequently-used-commands.html
http://sudosu.in/search?q=openvz#!/2012/07/openvz-ubc.html
http://sudosu.in/search?q=openvz#!/2012/07/openvz-change-disk-quota.html