Tag Archives: openvz

Execute a command in all running OpenVZ Containers

If you wish to execute a command in all running Containers, you can use the following script:
[codesyntax lang="bash"]

for i in `cat /proc/vz/veinfo | awk '{print $1}'|egrep -v '^0$'`; \

do echo "Container $i"; vzctl exec $i <command>; done

[/codesyntax]

where <command> is the command to be executed in all the running Containers. For example:

[codesyntax lang="bash"]
for i in `cat /proc/vz/veinfo | awk '{print $1}'|egrep -v '^0$'`; \

do echo "Container $i"; vzctl exec $i uptime; done
[/codesyntax]

Container 1
2:26pm up 6 days, 1:28, 0 users, load average: 0.00, 0.00, 0.00
Container 101
2:26pm up 6 days, 1:39, 0 users, load average: 0.00, 0.00, 0.00

Source: http://download.swsoft.com/virtuozzo/virtuozzo4.0/docs/en/lin/VzLinuxUG/260.htm

How to view in what openvz vps a process is running

1. Login on openvz node and use ps command to find the PID
[codesyntax lang="bash"]

ssh root@openvz-node
ps auxwwwf

[/codesyntax]

2. After finding PID execute following commands
[codesyntax lang="bash"]

PID=12345
for i in `vzlist -a | grep running | awk '{print $1}'`; do echo $i; ps $* -p $(grep -l "^envID:[[:space:]]*$i\$" /proc/[0-9]*/status | sed -e 's=/proc/\([0-9]*\)/.*=\1=') | grep $PID; done

[/codesyntax]

How to install openvz on CentOS 6.2

1. Add openvz repo
[codesyntax lang="bash"]

cd /etc/yum.repos.d
wget http://download.openvz.org/openvz.repo
rpm --import http://download.openvz.org/RPM-GPG-Key-OpenVZ

[/codesyntax]

2. Install openvz
[codesyntax lang="bash"]

yum install openvz-kernel-rhel6 vzctl vzquota bridge-utils

[/codesyntax]

3. Modify relevant kernel settings (sysctl.conf)
[codesyntax lang="bash"]

vim /etc/sysctl.conf

[/codesyntax]

net.ipv4.ip_forward=1
kernel.sysrq = 1

net.ipv4.conf.all.rp_filter=1
net.ipv4.icmp_echo_ignore_broadcasts=1

net.ipv4.conf.default.forwarding=1
net.ipv4.conf.default.proxy_arp = 0
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.eth0.proxy_arp=1

[codesyntax lang="bash"]

sysctl -p

[/codesyntax]

4. Reboot the server
[codesyntax lang="bash"]

reboot

[/codesyntax]

5. Disable se linux
[codesyntax lang="bash"]

vim /etc/sysconfig/selinux

[/codesyntax]

SELINUX=disabled

6. Install strace (I do not remember why I initially wanted this installed, but still it has nothing to spoil)

[codesyntax lang="bash"]

yum install strace

[/codesyntax]

Useless, but still: View in what OpenVZ Container are you in

1. Logon on the machine and execute the following command:

[codesyntax lang="bash"]

cat /proc/vz/veinfo | awk '{print "ID: "$1 " - IP: "$4}'

[/codesyntax]