Skip to content

Instantly share code, notes, and snippets.

@rushipkar90
Created September 11, 2015 15:12
Show Gist options
  • Save rushipkar90/e3a724885664420215c2 to your computer and use it in GitHub Desktop.
Save rushipkar90/e3a724885664420215c2 to your computer and use it in GitHub Desktop.
OpenVZ Commands
For OpenVZ refer this URL: (https://openvz.org/User_Guide/Operations_on_Containers)
=======================
vzlist -a ------ To list all the containers on OpenVZ including running and stopped.
vzlist -a 101 ----- To check specific container is present or not (101 => Container ID)
/vz/template/cache ------ Contains all the OS templates
/vz/private/ ----- it contains list of all the existing containers.
vzctl create 101 --ostemplate fedora-core-4 -–config vps.basic ---- First give OS
vzctl create 101 ---- To create new container.
vzctl set 101 --onboot yes --save
=======================
Setting Network Parameters
====================
# vzctl set 101 --hostname test101.my.org --save
# vzctl set 101 --ipadd 10.0.186.1 --save
# vzctl set 101 --nameserver 192.168.1.165 --save
====================
Setting root Password for VPS
# vzctl set 101 --userpasswd root:test
cat /proc/vz/veinfo ------- Shows all the VPS containers along with assigned dedicated IP's.
=> 101 0 20 10.0.186.1 ( Where 20 represents no. of active processes running under container ID.)
===================================
vzctl start 101 ----- To start particular container
vzctl stop 101 ----- To stop particular container
vzctl status 101 ---- To check the status of particular container
vzctl stop 101 --fast ----- To forcefully stop particular container by killing all the running processes on it.
vzctl restart 101 ----- For restarting specific containter.
vzctl destroy 101 ----- To delete container from node.
vzctl set 101 --disabled yes --save ----- Disabling Container (After the Container stopping, the Container user will not be able to start it again until you enable this Container again by passing the --disabled no option to vzctl set. You can also use the --force option to start any disabled Container).
vzctl start 103 --force ---- To start disabled container.
vzctl chkpnt 101 ---- Suspending Container
vzctl restore 101 ---- Unsuspending Container (You cannot change settings of the suspended Container).
Above command wont work if container is mounted. To destory that container, First stop it
# vzctl stop 101
# vzctl destroy 101
# vzctl status 101
========================================
# ls /etc/sysconfig/vz-scripts/101.* ------- it shows the logs for container destoryed
/etc/sysconfig/vz-scripts/101.conf.destroyed
Use the vzctl exec VPS_ID command for running a command inside the VPS with the given ID. For ex. to restart SSH service for the particular container(Running Commands in Container)
==================================
# vzctl exec 101 service sshd status
# vzctl exec 101 service sshd start
# vzctl exec 101 service sshd status
# vzctl exec 101 /etc/init.d/sshd status
sshd is stopped
# vzctl exec 101 /etc/init.d/sshd start
Starting sshd:[ OK ]
# vzctl exec 101 /etc/init.d/sshd status
sshd (pid 26187) is running...
==================================
If you wish to execute a command in all running VPS, you can use the following script:
# for i in `vzlist –o veid -H`; do \
echo "VPS $i"; vzctl exec $i <command>; done
[checking that quota is on]
# grep DISK_QUOTA /etc/sysconfig/vz
[checking available space on /vz partition]
# df /vz
[editing VPS configuration file to add DISK_QUOTA=no]
# vi /etc/sysconfig/vz-scripts/101.conf
[checking that quota is off for VPS 101]
# grep DISK_QUOTA /etc/sysconfig/vz-scripts/101.conf
# vzctl exec 101 df
vzcpucheck ----- To check the current Hardware Node CPU utilization
# vzctl set 102 --cpuunits 1500 --cpulimit 4 --save
VIMP - To check traffic on the node
====================
yum install iptraf
iptraf --- To view all things
iptraf -h ---- For help
-i iface - start the IP traffic monitor (use "-i all" for all interfaces)
=> iptraf -i all ------ To monitor all the interfaces of server
iptraf -i em1 ------ To monitor specific interface on the server (In this case, em1 interface).
-g - start the general interface statistics
=> iptraf -g
-d iface - start the detailed statistics facility on an interface
=> iptraf -d em1
-s iface - start the TCP and UDP monitor on an interface
=>iptraf -s em1
-z iface - shows the packet size counts on an interface
=> iptraf -z em1
-l iface - start the LAN station monitor ("-l all" for all LAN interfaces)
=> iptraf -l em1
-B - run in background (use only with one of the above parameters)
-t timeout - when used with one of the above parameters, tells the facility to run only for the specified number of minutes (timeout)
-L logfile - specifies an alternate log file for any direct invocation of a facility from the command line. The log is placed in /var/log/iptraf if path is not specified.
-I interval - specifies the log interval for all facilities except the IP traffic monitor. Value is in minutes.
-f - clear all locks and counters. Use with great caution. Normally used to recover from an abnormal termination.
====================
vzlist -o hostname,laverage,veid -- To check the load on all containers
cat /proc/cpuinfo
/etc/init.d/vz restart
service lighttpd restart
For the iptraf instructions
===========================
http://iptraf.seul.org/2.7/ifaces.html
http://blog.nexcess.net/2011/10/04/monitoring-linux-bandwidth-utilization-with-iptraf-and-iftop/
===========================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment