Common commands used in vps


Common commands used in vps

>>vzctl create vpsid –ostemplate ostemplatename //To create vps

Note: Once a guest host is set up, you can find its filesystem under /var/lib/vz/root/vpsid, and its private area under /var/lib/vz/private/vpsid — unless you change the defaults using the –root or –private options. The private directory contains files specific to the virtual environment (VE).

e.g if you created the guest as vz number 10011, its root filesystem would be under /var/lib/vz/root/10011

>>vzctl set –ipadd ipaddr –nameserver nameserverIP –hostname hostname –save  //The –ipadd parameter assigns the IP address to the first venet interface in the guest OS, the –hostname assigns the VPS its hostname, and the –nameserver paramter provides the first nameserver.

>>vzctl start vpsid // Once the VPS is set up, go ahead and start the guest by running where vpsid is the ID that you assigned to the guest when you created it.

>>vzlist //You can see what VPSes are running on physical node.

Output will be like :

VPSID      NPROC STATUS  IP_ADDR         HOSTNAME
10011        54    running 0.0.0.0        hostname

options:
-a :
To display all VPSes, whether they are running or not.

e.g. “vzlist -a”

>>vzlist -o vpsid,laverage //To check load average for all virtual machine on node.

>>vzcalc -v vpsid  //What resources are being consumed by a VPS. To see how much memory is being used by a VPS

>>vzctl set vpsid –onboot yes –save //By default, VPSes will not be started up when you boot the system. you probably do want VPSes to load after a system has restarted. You can change this setting using this cmd

One of the things that is frustrating about OpenVZ is that it’s not straightforward to say “give a VPS 256MB of RAM”; instead, you have to adjust a couple of parameters.To make things a bit simpler, let’s look at setting a VPS with a minimum of 256MB of RAM, and up to 1GB. To do that, set the vmguarpages (that’s the memory that’s guaranteed to the VPS) and privvmpages (that’s the maximum amount of memory that will be granted) parameters:

>>vzctl set vpsid –vmguarpages 65536 –save
>>vzctl set vpsid –privvmpages 262144 –save

Another way to do this that is much more easy than calculating the amount of RAM by “pages”. Just multiply the amount of RAM that you want by 256 as an easy way to arrive at the right amount of RAM:

vzctl set vpsid –vmguarpages $((256 * 256)) –save
vzctl set vpsid –privvmpages $((256 * 1024)) –save

As you set parameters for each VPS, the configuration settings are stored in /etc/vz/conf/vpsid.conf. If you make any changes to this file manually, you can use the vzcfgvalidate utility to make sure that the configuration file is correct.

>>vzctl enter vpsid //To enter into the vps through Node

exit //After you’ve finished whatever admin tasks you need to perform, just type exit to exit from the vps. you’ll be return on node machine.

>>vzctl set vpsid –userpasswd user:passwd //To reset a password for a user. note: If the user does not exist, it will be created.

If you’d like to run a command in a VPS without actually entering the VPS, you can use the exec parameter for vzctl to run a command as root. For example, if you want to run a quick update inside centos vps simply Run:

>>vzctl exec vpsid yum update

>>vzctl stop vpsid //To stop vps through Node

>>vzctl restart vpsid //To restart vps through Node

>>vzctl status vpsid //

Note: VPSes can also be shut down or rebooted normally from within the VPS

>>vzctl destroy veid //if you have a VPS that you’d like to get rid of

A note of caution here: the vzctl utility does not ask for confirmation before destroying the VPS. As soon as you press Enter, that’s all she wrote — the VPS will be removed, its private data directories removed,

Added information:

LOGFILE=/var/log/vzctl.log

>>vzctl runscript <veid> <script_path> //This used to run different shell scripts inside your vps. specify full path to the script on the Hardware Node.

Note:You can execute this command for both running Containers and stopped ones. In the latter case, the corresponding Container will be started before running the specified scripts inside it.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: