<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.openvz.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=HostGIS</id>
	<title>OpenVZ Virtuozzo Containers Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.openvz.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=HostGIS"/>
	<link rel="alternate" type="text/html" href="https://wiki.openvz.org/Special:Contributions/HostGIS"/>
	<updated>2026-06-13T17:46:58Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.1</generator>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=ExecuteInAllVEs&amp;diff=3898</id>
		<title>ExecuteInAllVEs</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=ExecuteInAllVEs&amp;diff=3898"/>
		<updated>2008-01-06T15:23:33Z</updated>

		<summary type="html">&lt;p&gt;HostGIS: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I found myself often faced with a need to run the same command in all VEs, e.g. ''apachectl restart'' to restart all webservers or ''dmesg | tail'' to see the latest news from everybody.&lt;br /&gt;
&lt;br /&gt;
You can loop through all VEs and execute this this easily:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  for veid in `vzlist -Hoveid`; do vzctl exec $veid COMMAND; done &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Knowing this, you can also save some typing later by making a simple utility out of it.&lt;br /&gt;
I like to call this ''/usr/sbin/vzexec'' so I can later just say ''vzexec apachectl restart''&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
  # vzexec -- execute a command on all VEs&lt;br /&gt;
  if [ &amp;quot;$1&amp;quot; == &amp;quot;&amp;quot; ]; then&lt;br /&gt;
    echo &amp;quot;$0 -- Execute a command on all VEs&amp;quot;&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &amp;quot;Example: vzexec service httpd restart&amp;quot;&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &amp;quot;Note that variables are expanded in the host's shell, and use ' ' to prevent this.&amp;quot;&lt;br /&gt;
    echo &amp;quot;Example:   vzexec echo \$PWD    and   vzexec 'echo \$PWD'   are different.&amp;quot;&lt;br /&gt;
    exit&lt;br /&gt;
  fi&lt;br /&gt;
  for veid in `vzlist -Hoveid`; do&lt;br /&gt;
    echo &amp;quot;*** VE $veid&amp;quot;&lt;br /&gt;
    vzctl exec $veid $@&lt;br /&gt;
  done&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>HostGIS</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=ExecuteInAllVEs&amp;diff=3897</id>
		<title>ExecuteInAllVEs</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=ExecuteInAllVEs&amp;diff=3897"/>
		<updated>2008-01-06T15:23:20Z</updated>

		<summary type="html">&lt;p&gt;HostGIS: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I found myself often faced with a need to run the same command in all VEs, e.g. ''apachectl restart'' to restart all webservers or ''dmesg | tail'' to see the latest news from everybody.&lt;br /&gt;
&lt;br /&gt;
You can loop through all VEs and execute this this easily:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  for veid in `vzlist -Hoveid`; do vzctl exec $veid COMMAND; done &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Knowing this, you can also save some typing later by making a simple utility out of it. I like to call this ''/usr/sbin/vzexec'' so I can later just say ''vzexec apachectl restart''&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
  # vzexec -- execute a command on all VEs&lt;br /&gt;
  if [ &amp;quot;$1&amp;quot; == &amp;quot;&amp;quot; ]; then&lt;br /&gt;
    echo &amp;quot;$0 -- Execute a command on all VEs&amp;quot;&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &amp;quot;Example: vzexec service httpd restart&amp;quot;&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &amp;quot;Note that variables are expanded in the host's shell, and use ' ' to prevent this.&amp;quot;&lt;br /&gt;
    echo &amp;quot;Example:   vzexec echo \$PWD    and   vzexec 'echo \$PWD'   are different.&amp;quot;&lt;br /&gt;
    exit&lt;br /&gt;
  fi&lt;br /&gt;
  for veid in `vzlist -Hoveid`; do&lt;br /&gt;
    echo &amp;quot;*** VE $veid&amp;quot;&lt;br /&gt;
    vzctl exec $veid $@&lt;br /&gt;
  done&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>HostGIS</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=ExecuteInAllVEs&amp;diff=3896</id>
		<title>ExecuteInAllVEs</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=ExecuteInAllVEs&amp;diff=3896"/>
		<updated>2008-01-06T15:22:42Z</updated>

		<summary type="html">&lt;p&gt;HostGIS: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I found myself often faced with a need to run the same command in all VEs, e.g. ''apachectl restart'' to restart all webservers or ''dmesg | tail'' to see the latest news from everybody.&lt;br /&gt;
&lt;br /&gt;
At its core is just this simple tidbit: a for loop around vzlist.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  for veid in `vzlist -Hoveid`; do vzctl exec $veid COMMAND; done &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Knowing this, you can also save some typing later by making a simple utility out of it. I like to call this ''/usr/sbin/vzexec'' so I can later just say ''vzexec apachectl restart''&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
  # vzexec -- execute a command on all VEs&lt;br /&gt;
  if [ &amp;quot;$1&amp;quot; == &amp;quot;&amp;quot; ]; then&lt;br /&gt;
    echo &amp;quot;$0 -- Execute a command on all VEs&amp;quot;&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &amp;quot;Example: vzexec service httpd restart&amp;quot;&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &amp;quot;Note that variables are expanded in the host's shell, and use ' ' to prevent this.&amp;quot;&lt;br /&gt;
    echo &amp;quot;Example:   vzexec echo \$PWD    and   vzexec 'echo \$PWD'   are different.&amp;quot;&lt;br /&gt;
    exit&lt;br /&gt;
  fi&lt;br /&gt;
  for veid in `vzlist -Hoveid`; do&lt;br /&gt;
    echo &amp;quot;*** VE $veid&amp;quot;&lt;br /&gt;
    vzctl exec $veid $@&lt;br /&gt;
  done&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>HostGIS</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=ExecuteInAllVEs&amp;diff=3895</id>
		<title>ExecuteInAllVEs</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=ExecuteInAllVEs&amp;diff=3895"/>
		<updated>2008-01-06T15:20:19Z</updated>

		<summary type="html">&lt;p&gt;HostGIS: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I found myself often faced with a need to run the same command in all VEs, e.g. ''apachectl restart'' to restart all webservers or ''dmesg | tail'' to see the latest news from everybody. This simple utility is just a loop around ''vzctl exec'' but I find it very handy.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
  # vzexec -- execute a command on all VEs&lt;br /&gt;
  if [ &amp;quot;$1&amp;quot; == &amp;quot;&amp;quot; ]; then&lt;br /&gt;
    echo &amp;quot;$0 -- Execute a command on all VEs&amp;quot;&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &amp;quot;Example: vzexec service httpd restart&amp;quot;&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &amp;quot;Note that variables are expanded in the host's shell, and use ' ' to prevent this.&amp;quot;&lt;br /&gt;
    echo &amp;quot;Example:   vzexec echo \$PWD    and   vzexec 'echo \$PWD'   are different.&amp;quot;&lt;br /&gt;
    exit&lt;br /&gt;
  fi&lt;br /&gt;
  for veid in `vzlist -Hoveid`; do&lt;br /&gt;
    echo &amp;quot;*** VE $veid&amp;quot;&lt;br /&gt;
    vzctl exec $veid $@&lt;br /&gt;
  done&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>HostGIS</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=ExecuteInAllVEs&amp;diff=3874</id>
		<title>ExecuteInAllVEs</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=ExecuteInAllVEs&amp;diff=3874"/>
		<updated>2008-01-03T18:47:32Z</updated>

		<summary type="html">&lt;p&gt;HostGIS: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I found myself often faced with a need to run the same command in all VEs, e.g. ''apachectl restart'' to restart all webservers or ''dmesg | tail'' to see the latest news from everybody. This simple utility is just a loop around ''vzctl exec'' but I find it very handy.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
  # vzexec -- execute a command on all VEs&lt;br /&gt;
  CONFDIR=&amp;quot;/etc/vz/conf&amp;quot;&lt;br /&gt;
  if [ &amp;quot;$1&amp;quot; == &amp;quot;&amp;quot; ]; then&lt;br /&gt;
    echo &amp;quot;$0 -- Execute a command on all VEs&amp;quot;&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &amp;quot;Example: vzexec service httpd restart&amp;quot;&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &amp;quot;Note that variables are expanded in the host's shell, and use ' ' to prevent this.&amp;quot;&lt;br /&gt;
    echo &amp;quot;Example:   vzexec echo \$PWD    and   vzexec 'echo \$PWD'   are different.&amp;quot;&lt;br /&gt;
    exit&lt;br /&gt;
  fi&lt;br /&gt;
  for veconf in $CONFDIR/*.conf ; do&lt;br /&gt;
    veid=`basename $veconf .conf`&lt;br /&gt;
    if [ &amp;quot;$veid&amp;quot; == &amp;quot;0&amp;quot; ]; then continue; fi&lt;br /&gt;
    vename=`grep ^NAME $veconf | head -1 | sed -e 's@NAME=@@' | sed -e 's@&amp;quot;@@g'`&lt;br /&gt;
    echo &amp;quot;*** VE $veid ($vename)&amp;quot;&lt;br /&gt;
    vzctl exec $veid $@&lt;br /&gt;
  done&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>HostGIS</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=ExecuteInAllVEs&amp;diff=3873</id>
		<title>ExecuteInAllVEs</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=ExecuteInAllVEs&amp;diff=3873"/>
		<updated>2008-01-03T18:47:03Z</updated>

		<summary type="html">&lt;p&gt;HostGIS: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I found myself often faced with a need to run the same command in all VEs, e.g. ''apachectl restart'' to restart all webservers or ''dmesg | tail'' to see the latest news from everybody. This simple utility is just a loop around ''vzctl exec'' but I find it very handy.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
  CONFDIR=&amp;quot;/etc/vz/conf&amp;quot;&lt;br /&gt;
  if [ &amp;quot;$1&amp;quot; == &amp;quot;&amp;quot; ]; then&lt;br /&gt;
    echo &amp;quot;$0 -- Execute a command on all VEs&amp;quot;&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &amp;quot;Example: vzexec service httpd restart&amp;quot;&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &amp;quot;Note that variables are expanded in the host's shell, and use ' ' to prevent this.&amp;quot;&lt;br /&gt;
    echo &amp;quot;Example:   vzexec echo \$PWD    and   vzexec 'echo \$PWD'   are different.&amp;quot;&lt;br /&gt;
    exit&lt;br /&gt;
  fi&lt;br /&gt;
  for veconf in $CONFDIR/*.conf ; do&lt;br /&gt;
    veid=`basename $veconf .conf`&lt;br /&gt;
    if [ &amp;quot;$veid&amp;quot; == &amp;quot;0&amp;quot; ]; then continue; fi&lt;br /&gt;
    vename=`grep ^NAME $veconf | head -1 | sed -e 's@NAME=@@' | sed -e 's@&amp;quot;@@g'`&lt;br /&gt;
    echo &amp;quot;*** VE $veid ($vename)&amp;quot;&lt;br /&gt;
    vzctl exec $veid $@&lt;br /&gt;
  done&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>HostGIS</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=ExecuteInAllVEs&amp;diff=3872</id>
		<title>ExecuteInAllVEs</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=ExecuteInAllVEs&amp;diff=3872"/>
		<updated>2008-01-03T18:44:31Z</updated>

		<summary type="html">&lt;p&gt;HostGIS: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
  CONFDIR=&amp;quot;/etc/vz/conf&amp;quot;&lt;br /&gt;
  if [ &amp;quot;$1&amp;quot; == &amp;quot;&amp;quot; ]; then&lt;br /&gt;
    echo &amp;quot;$0 -- Execute a command on all VEs&amp;quot;&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &amp;quot;Example: vzexec service httpd restart&amp;quot;&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &amp;quot;Note that variables are expanded in the host's shell, and use ' ' to prevent this.&amp;quot;&lt;br /&gt;
    echo &amp;quot;Example:   vzexec echo \$PWD    and   vzexec 'echo \$PWD'   are different.&amp;quot;&lt;br /&gt;
    exit&lt;br /&gt;
  fi&lt;br /&gt;
  for veconf in $CONFDIR/*.conf ; do&lt;br /&gt;
    veid=`basename $veconf .conf`&lt;br /&gt;
    if [ &amp;quot;$veid&amp;quot; == &amp;quot;0&amp;quot; ]; then continue; fi&lt;br /&gt;
    vename=`grep ^NAME $veconf | head -1 | sed -e 's@NAME=@@' | sed -e 's@&amp;quot;@@g'`&lt;br /&gt;
    echo &amp;quot;*** VE $veid ($vename)&amp;quot;&lt;br /&gt;
    vzctl exec $veid $@&lt;br /&gt;
  done&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>HostGIS</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=ExecuteInAllVEs&amp;diff=3871</id>
		<title>ExecuteInAllVEs</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=ExecuteInAllVEs&amp;diff=3871"/>
		<updated>2008-01-03T18:44:09Z</updated>

		<summary type="html">&lt;p&gt;HostGIS: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
  CONFDIR=&amp;quot;/etc/vz/conf&amp;quot;&lt;br /&gt;
  if [ &amp;quot;$1&amp;quot; == &amp;quot;&amp;quot; ]; then&lt;br /&gt;
    echo &amp;quot;$0 -- Execute a command on all VEs&amp;quot;&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &amp;quot;Example: vzexec service httpd restart&amp;quot;&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &amp;quot;Note that variables are expanded in the host's shell, and use '' to prevent this.&amp;quot;&lt;br /&gt;
    echo &amp;quot;Example:   vzexec echo \$PWD    and   vzexec 'echo \$PWD'   are different.&amp;quot;&lt;br /&gt;
    exit&lt;br /&gt;
  fi&lt;br /&gt;
  for veconf in $CONFDIR/*.conf ; do&lt;br /&gt;
    veid=`basename $veconf .conf`&lt;br /&gt;
    if [ &amp;quot;$veid&amp;quot; == &amp;quot;0&amp;quot; ]; then continue; fi&lt;br /&gt;
    vename=`grep ^NAME $veconf | head -1 | sed -e 's@NAME=@@' | sed -e 's@&amp;quot;@@g'`&lt;br /&gt;
    echo &amp;quot;*** VE $veid ($vename)&amp;quot;&lt;br /&gt;
    vzctl exec $veid $@&lt;br /&gt;
  done&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>HostGIS</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=ExecuteInAllVEs&amp;diff=3870</id>
		<title>ExecuteInAllVEs</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=ExecuteInAllVEs&amp;diff=3870"/>
		<updated>2008-01-03T18:43:14Z</updated>

		<summary type="html">&lt;p&gt;HostGIS: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;code&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
CONFDIR=&amp;quot;/etc/vz/conf&amp;quot;&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; == &amp;quot;&amp;quot; ]; then&lt;br /&gt;
  echo &amp;quot;$0 -- Execute a command on all VEs&amp;quot;&lt;br /&gt;
  echo &amp;quot;&amp;quot;&lt;br /&gt;
  echo &amp;quot;Example: vzexec service httpd restart&amp;quot;&lt;br /&gt;
  echo &amp;quot;&amp;quot;&lt;br /&gt;
  echo &amp;quot;Note that variables are expanded in the host's shell, and use '' to prevent this.&amp;quot;&lt;br /&gt;
  echo &amp;quot;Example:   vzexec echo \$PWD    and   vzexec 'echo \$PWD'   are different.&amp;quot;&lt;br /&gt;
  exit&lt;br /&gt;
fi&lt;br /&gt;
for veconf in $CONFDIR/*.conf ; do&lt;br /&gt;
  veid=`basename $veconf .conf`&lt;br /&gt;
  if [ &amp;quot;$veid&amp;quot; == &amp;quot;0&amp;quot; ]; then continue; fi&lt;br /&gt;
  vename=`grep ^NAME $veconf | head -1 | sed -e 's@NAME=@@' | sed -e 's@&amp;quot;@@g'`&lt;br /&gt;
  echo &amp;quot;*** VE $veid ($vename)&amp;quot;&lt;br /&gt;
  vzctl exec $veid $@&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>HostGIS</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=ExecuteInAllVEs&amp;diff=3869</id>
		<title>ExecuteInAllVEs</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=ExecuteInAllVEs&amp;diff=3869"/>
		<updated>2008-01-03T18:42:48Z</updated>

		<summary type="html">&lt;p&gt;HostGIS: program code, no wording&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{{&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
CONFDIR=&amp;quot;/etc/vz/conf&amp;quot;&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; == &amp;quot;&amp;quot; ]; then&lt;br /&gt;
  echo &amp;quot;$0 -- Execute a command on all VEs&amp;quot;&lt;br /&gt;
  echo &amp;quot;&amp;quot;&lt;br /&gt;
  echo &amp;quot;Example: vzexec service httpd restart&amp;quot;&lt;br /&gt;
  echo &amp;quot;&amp;quot;&lt;br /&gt;
  echo &amp;quot;Note that variables are expanded in the host's shell, and use '' to prevent this.&amp;quot;&lt;br /&gt;
  echo &amp;quot;Example:   vzexec echo \$PWD    and   vzexec 'echo \$PWD'   are different.&amp;quot;&lt;br /&gt;
  exit&lt;br /&gt;
fi&lt;br /&gt;
for veconf in $CONFDIR/*.conf ; do&lt;br /&gt;
  veid=`basename $veconf .conf`&lt;br /&gt;
  if [ &amp;quot;$veid&amp;quot; == &amp;quot;0&amp;quot; ]; then continue; fi&lt;br /&gt;
  vename=`grep ^NAME $veconf | head -1 | sed -e 's@NAME=@@' | sed -e 's@&amp;quot;@@g'`&lt;br /&gt;
  echo &amp;quot;*** VE $veid ($vename)&amp;quot;&lt;br /&gt;
  vzctl exec $veid $@&lt;br /&gt;
done&lt;br /&gt;
}}}&lt;/div&gt;</summary>
		<author><name>HostGIS</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Creating_a_template_cache_:_Slackware_or_HostGIS_Linux&amp;diff=3687</id>
		<title>Creating a template cache : Slackware or HostGIS Linux</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Creating_a_template_cache_:_Slackware_or_HostGIS_Linux&amp;diff=3687"/>
		<updated>2007-11-30T17:00:58Z</updated>

		<summary type="html">&lt;p&gt;HostGIS: /* Zipping it up into a cache image */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Creating a new Host Template Cache for HostGIS Linux 4.x or Slackware 11.x/12.x ==&lt;br /&gt;
&lt;br /&gt;
This process uses VMWare to install the OS into a VM, then to trim down the VM's contents to only those items suitable for a VPS/VE environment, then to save a snapshot of the system as a host template cache for use in OpenVZ.&lt;br /&gt;
&lt;br /&gt;
This document focuses on HostGIS Linux (a Slackware derivative) but aside from the specifics about installation settings, it should be 99% applicable to Slackware as well.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Create the VM in VMWare ===&lt;br /&gt;
&lt;br /&gt;
Technically, you could probably do this on a hardware PC without VMWare, but VMWare does make it more convenient.&lt;br /&gt;
&lt;br /&gt;
Start by creating a new VM in VMWare.&lt;br /&gt;
* The disk and RAM stats can be minimal, as the system will never see live use.&lt;br /&gt;
* There is no need to create the entire disk at once during the setup.&lt;br /&gt;
* Create the disk as SCSI.&lt;br /&gt;
&lt;br /&gt;
Then install HGL.&lt;br /&gt;
* Create a small partition at the end of the disk for swap. Some swap is technically necessary, but since you'll never in fact be using it, a few MB should be fine.&lt;br /&gt;
* Set the passwords to 'password'&lt;br /&gt;
* Do set the timezone properly. The internal clock does not use UTC/GMT.&lt;br /&gt;
* Select the default mouse, but do NOT enable GPM at startup.&lt;br /&gt;
* Hostname:  template   Domain: internal.lan&lt;br /&gt;
* IP config:  as appropriate for your LAN&lt;br /&gt;
* Nameserver: no&lt;br /&gt;
&lt;br /&gt;
Reboot into your new HGL install, and log in.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Delete unnecessary stuff ==&lt;br /&gt;
&lt;br /&gt;
A lot of packages aren't relevant to a VPS setting, e.g. floppy disk utilities and kernel modules, even getty listening on the console.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  # kernel, kernel modules, documentation, mount points&lt;br /&gt;
  rm -rf /lib/modules /boot /dev/.udev /usr/doc /usr/info /media&lt;br /&gt;
&lt;br /&gt;
  # packages not applicable to a VPS setting&lt;br /&gt;
  cd /var/log/packages&lt;br /&gt;
  for pkg in \&lt;br /&gt;
     hotplug-* hdparm-* devmapper-* udev-* usbutils-* pciutils-* module-init-tools-* \&lt;br /&gt;
     mdadm-* floppy-* lvm2-* raidtools-* reiserfsprogs-* \&lt;br /&gt;
     smartmontools-* sysfsutils-* syslinux-* wireless_tools.* quota-* iptables-*&lt;br /&gt;
  do removepkg $pkg ; done&lt;br /&gt;
&lt;br /&gt;
  # prune init's getty&lt;br /&gt;
  vi  /etc/inittab # delete everything after entry l6 (runlevel 6)&lt;br /&gt;
  init q&lt;br /&gt;
&lt;br /&gt;
  # clean out the fstab and mtab files&lt;br /&gt;
  ( cd /etc ; rm -f fstab mtab ; ln -s ../proc/mounts mtab )&lt;br /&gt;
  echo &amp;quot;proc     /proc      proc     defaults    0  0&amp;quot; &amp;gt;&amp;gt; /etc/fstab&lt;br /&gt;
  echo &amp;quot;devpts   /dev/pts   devpts   mode=0620   0  0&amp;quot; &amp;gt;&amp;gt; /etc/fstab&lt;br /&gt;
&lt;br /&gt;
  # the startup sequence and services&lt;br /&gt;
  cd /etc/rc.d&lt;br /&gt;
  rm -f rc.gpm-sample rc.gpm rc.hotplug rc.ip_forward rc.modules \&lt;br /&gt;
        rc.scanluns  rc.serial rc.udev rc.sysvinit&lt;br /&gt;
  vi rc.syslog    # delete all mentions of klogd&lt;br /&gt;
  vi rc.M         # delete the setterm entry&lt;br /&gt;
  vi rc.S         # delete the MOTD clobbering&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Fix permissions and ownerships ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  # clear out old/dummy SSL certificates&lt;br /&gt;
  mv /etc/ssl/openssl.cnf /tmp ; rm -r /etc/ssl/* ; mv /tmp/openssl.cnf /etc/ssl&lt;br /&gt;
&lt;br /&gt;
  # set an ownership on any unowned files&lt;br /&gt;
  find / -mount -nouser -exec chown root {} \; &amp;amp;&lt;br /&gt;
  find / -mount -nogroup -exec chgrp root {} \; &amp;amp;&lt;br /&gt;
&lt;br /&gt;
  # remove the setuid bit from programs which nobody else should use&lt;br /&gt;
  # you may want to review this list first, as some folks want their users&lt;br /&gt;
  # able to edit cronjobs and to change their own passwords, etc.&lt;br /&gt;
  for i in \&lt;br /&gt;
    /bin/ping /bin/mount /bin/ping6 /bin/umount /usr/bin/chfn \&lt;br /&gt;
     /usr/bin/chsh /usr/bin/crontab /usr/bin/chage /usr/bin/traceroute6 /usr/bin/traceroute \&lt;br /&gt;
     /usr/bin/expiry /usr/bin/newgrp /usr/bin/passwd /usr/bin/gpasswd \&lt;br /&gt;
     /usr/libexec/ssh-keysign /usr/libexec/pt_chown /usr/bin/wall /usr/bin/write&lt;br /&gt;
     do chmod u-s $i ; done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Changes to rc scripts ==&lt;br /&gt;
&lt;br /&gt;
OpenVZ emulates rebooting with an external cronjob called vpsreboot and a dummy file called /reboot within the VPS, and emulates the /etc/mtab file by pointing it to /proc/mounts So, some small changes are necessary to the rc scripts.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  # somewhere in rc.6 add this command: touch /reboot&lt;br /&gt;
  vi /etc/rc.d/rc.6&lt;br /&gt;
&lt;br /&gt;
  # somewhere in rc.M, add this command: rm -f /etc/mtab ;  ln -s /proc/mounts /etc/mtab&lt;br /&gt;
  vi /etc/rc.d/rc.M&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Blanking settings ==&lt;br /&gt;
&lt;br /&gt;
Lastly, you'll want to delete or blank out a bunch of files so they start fresh&lt;br /&gt;
when the VE is booted for its first time.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  # stop all services&lt;br /&gt;
  apachectl stop&lt;br /&gt;
  killall syslogd klogd udevd crond&lt;br /&gt;
  /etc/rc.d/rc.sendmail stop&lt;br /&gt;
  /etc/rc.d/rc.inetd stop&lt;br /&gt;
  /etc/webmin/stop&lt;br /&gt;
  /etc/rc.d/rc.pgsql stop&lt;br /&gt;
  /etc/rc.d/rc.mysqld stop&lt;br /&gt;
  killall named proftpd&lt;br /&gt;
&lt;br /&gt;
  # blow away the network configuration with dummy strings for later replacement&lt;br /&gt;
  #    replace the IP address with __IPADDRESS_&lt;br /&gt;
  #    replace the netmask with __NETMASK__&lt;br /&gt;
  #    replace the GATEWAY with __GATEWAY__&lt;br /&gt;
  vi /etc/rc.d/rc.inet1.conf&lt;br /&gt;
&lt;br /&gt;
  # disable the root and user accounts&lt;br /&gt;
  # by changing the password for root and user to a ! character.&lt;br /&gt;
  vi /etc/shadow&lt;br /&gt;
&lt;br /&gt;
  # refresh the 'locate' cache&lt;br /&gt;
  /etc/cron.daily/slocate&lt;br /&gt;
&lt;br /&gt;
  # blank out the system logfiles&lt;br /&gt;
  for logfile in \&lt;br /&gt;
      /var/log/messages /var/log/syslog /var/log/debug /var/log/secure \&lt;br /&gt;
      /var/log/maillog /var/log/spooler /var/log/proftpd.log /var/log/xinetd.log \&lt;br /&gt;
      /var/log/dmesg /var/log/faillog /var/log/lastlog /var/log/wtmp \&lt;br /&gt;
      /var/log/apache/access_log /var/log/apache/error_log \&lt;br /&gt;
      /var/log/webmin/miniserv.error /var/log/webmin/miniserv.pid&lt;br /&gt;
  do cp /dev/null $logfile ; done&lt;br /&gt;
  rmdir /var/log/sa&lt;br /&gt;
&lt;br /&gt;
  # clear the SSH host key&lt;br /&gt;
  rm -f /etc/ssh/ssh_host_*&lt;br /&gt;
&lt;br /&gt;
  # database server logfiles&lt;br /&gt;
  rm -f /var/lib/mysql/*.err /var/lib/pgsql/logfile&lt;br /&gt;
&lt;br /&gt;
  # delete vi backup files, bash_history files, and other small application crud&lt;br /&gt;
  unset HISTFILE&lt;br /&gt;
  find / -name '*~' \&lt;br /&gt;
      -o -name .bash_history \&lt;br /&gt;
      -o -name .gnupg \&lt;br /&gt;
      -o -name .lesshst \&lt;br /&gt;
      -o -name .viminfo \&lt;br /&gt;
      -o -name .rnd \&lt;br /&gt;
      -delete&lt;br /&gt;
&lt;br /&gt;
  # anything under /tmp&lt;br /&gt;
  rm -rf /tmp/*&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Zipping it up into a cache image ==&lt;br /&gt;
&lt;br /&gt;
A VE cache is just a tar.gz file of the entire filesystem, excluding some very dynamic stuff which gets populated by the OS at runtime anyway:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  tar zcvf /tmp/HostGIS_Linux_4.2_64bit.tar.gz --exclude='/sys/*' --exclude='/proc/*' --exclude='/tmp/*' /&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>HostGIS</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Creating_a_template_cache_:_Slackware_or_HostGIS_Linux&amp;diff=3686</id>
		<title>Creating a template cache : Slackware or HostGIS Linux</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Creating_a_template_cache_:_Slackware_or_HostGIS_Linux&amp;diff=3686"/>
		<updated>2007-11-30T17:00:43Z</updated>

		<summary type="html">&lt;p&gt;HostGIS: /* Changes to rc scripts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Creating a new Host Template Cache for HostGIS Linux 4.x or Slackware 11.x/12.x ==&lt;br /&gt;
&lt;br /&gt;
This process uses VMWare to install the OS into a VM, then to trim down the VM's contents to only those items suitable for a VPS/VE environment, then to save a snapshot of the system as a host template cache for use in OpenVZ.&lt;br /&gt;
&lt;br /&gt;
This document focuses on HostGIS Linux (a Slackware derivative) but aside from the specifics about installation settings, it should be 99% applicable to Slackware as well.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Create the VM in VMWare ===&lt;br /&gt;
&lt;br /&gt;
Technically, you could probably do this on a hardware PC without VMWare, but VMWare does make it more convenient.&lt;br /&gt;
&lt;br /&gt;
Start by creating a new VM in VMWare.&lt;br /&gt;
* The disk and RAM stats can be minimal, as the system will never see live use.&lt;br /&gt;
* There is no need to create the entire disk at once during the setup.&lt;br /&gt;
* Create the disk as SCSI.&lt;br /&gt;
&lt;br /&gt;
Then install HGL.&lt;br /&gt;
* Create a small partition at the end of the disk for swap. Some swap is technically necessary, but since you'll never in fact be using it, a few MB should be fine.&lt;br /&gt;
* Set the passwords to 'password'&lt;br /&gt;
* Do set the timezone properly. The internal clock does not use UTC/GMT.&lt;br /&gt;
* Select the default mouse, but do NOT enable GPM at startup.&lt;br /&gt;
* Hostname:  template   Domain: internal.lan&lt;br /&gt;
* IP config:  as appropriate for your LAN&lt;br /&gt;
* Nameserver: no&lt;br /&gt;
&lt;br /&gt;
Reboot into your new HGL install, and log in.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Delete unnecessary stuff ==&lt;br /&gt;
&lt;br /&gt;
A lot of packages aren't relevant to a VPS setting, e.g. floppy disk utilities and kernel modules, even getty listening on the console.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  # kernel, kernel modules, documentation, mount points&lt;br /&gt;
  rm -rf /lib/modules /boot /dev/.udev /usr/doc /usr/info /media&lt;br /&gt;
&lt;br /&gt;
  # packages not applicable to a VPS setting&lt;br /&gt;
  cd /var/log/packages&lt;br /&gt;
  for pkg in \&lt;br /&gt;
     hotplug-* hdparm-* devmapper-* udev-* usbutils-* pciutils-* module-init-tools-* \&lt;br /&gt;
     mdadm-* floppy-* lvm2-* raidtools-* reiserfsprogs-* \&lt;br /&gt;
     smartmontools-* sysfsutils-* syslinux-* wireless_tools.* quota-* iptables-*&lt;br /&gt;
  do removepkg $pkg ; done&lt;br /&gt;
&lt;br /&gt;
  # prune init's getty&lt;br /&gt;
  vi  /etc/inittab # delete everything after entry l6 (runlevel 6)&lt;br /&gt;
  init q&lt;br /&gt;
&lt;br /&gt;
  # clean out the fstab and mtab files&lt;br /&gt;
  ( cd /etc ; rm -f fstab mtab ; ln -s ../proc/mounts mtab )&lt;br /&gt;
  echo &amp;quot;proc     /proc      proc     defaults    0  0&amp;quot; &amp;gt;&amp;gt; /etc/fstab&lt;br /&gt;
  echo &amp;quot;devpts   /dev/pts   devpts   mode=0620   0  0&amp;quot; &amp;gt;&amp;gt; /etc/fstab&lt;br /&gt;
&lt;br /&gt;
  # the startup sequence and services&lt;br /&gt;
  cd /etc/rc.d&lt;br /&gt;
  rm -f rc.gpm-sample rc.gpm rc.hotplug rc.ip_forward rc.modules \&lt;br /&gt;
        rc.scanluns  rc.serial rc.udev rc.sysvinit&lt;br /&gt;
  vi rc.syslog    # delete all mentions of klogd&lt;br /&gt;
  vi rc.M         # delete the setterm entry&lt;br /&gt;
  vi rc.S         # delete the MOTD clobbering&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Fix permissions and ownerships ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  # clear out old/dummy SSL certificates&lt;br /&gt;
  mv /etc/ssl/openssl.cnf /tmp ; rm -r /etc/ssl/* ; mv /tmp/openssl.cnf /etc/ssl&lt;br /&gt;
&lt;br /&gt;
  # set an ownership on any unowned files&lt;br /&gt;
  find / -mount -nouser -exec chown root {} \; &amp;amp;&lt;br /&gt;
  find / -mount -nogroup -exec chgrp root {} \; &amp;amp;&lt;br /&gt;
&lt;br /&gt;
  # remove the setuid bit from programs which nobody else should use&lt;br /&gt;
  # you may want to review this list first, as some folks want their users&lt;br /&gt;
  # able to edit cronjobs and to change their own passwords, etc.&lt;br /&gt;
  for i in \&lt;br /&gt;
    /bin/ping /bin/mount /bin/ping6 /bin/umount /usr/bin/chfn \&lt;br /&gt;
     /usr/bin/chsh /usr/bin/crontab /usr/bin/chage /usr/bin/traceroute6 /usr/bin/traceroute \&lt;br /&gt;
     /usr/bin/expiry /usr/bin/newgrp /usr/bin/passwd /usr/bin/gpasswd \&lt;br /&gt;
     /usr/libexec/ssh-keysign /usr/libexec/pt_chown /usr/bin/wall /usr/bin/write&lt;br /&gt;
     do chmod u-s $i ; done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Changes to rc scripts ==&lt;br /&gt;
&lt;br /&gt;
OpenVZ emulates rebooting with an external cronjob called vpsreboot and a dummy file called /reboot within the VPS, and emulates the /etc/mtab file by pointing it to /proc/mounts So, some small changes are necessary to the rc scripts.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  # somewhere in rc.6 add this command: touch /reboot&lt;br /&gt;
  vi /etc/rc.d/rc.6&lt;br /&gt;
&lt;br /&gt;
  # somewhere in rc.M, add this command: rm -f /etc/mtab ;  ln -s /proc/mounts /etc/mtab&lt;br /&gt;
  vi /etc/rc.d/rc.M&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Blanking settings ==&lt;br /&gt;
&lt;br /&gt;
Lastly, you'll want to delete or blank out a bunch of files so they start fresh&lt;br /&gt;
when the VE is booted for its first time.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  # stop all services&lt;br /&gt;
  apachectl stop&lt;br /&gt;
  killall syslogd klogd udevd crond&lt;br /&gt;
  /etc/rc.d/rc.sendmail stop&lt;br /&gt;
  /etc/rc.d/rc.inetd stop&lt;br /&gt;
  /etc/webmin/stop&lt;br /&gt;
  /etc/rc.d/rc.pgsql stop&lt;br /&gt;
  /etc/rc.d/rc.mysqld stop&lt;br /&gt;
  killall named proftpd&lt;br /&gt;
&lt;br /&gt;
  # blow away the network configuration with dummy strings for later replacement&lt;br /&gt;
  #    replace the IP address with __IPADDRESS_&lt;br /&gt;
  #    replace the netmask with __NETMASK__&lt;br /&gt;
  #    replace the GATEWAY with __GATEWAY__&lt;br /&gt;
  vi /etc/rc.d/rc.inet1.conf&lt;br /&gt;
&lt;br /&gt;
  # disable the root and user accounts&lt;br /&gt;
  # by changing the password for root and user to a ! character.&lt;br /&gt;
  vi /etc/shadow&lt;br /&gt;
&lt;br /&gt;
  # refresh the 'locate' cache&lt;br /&gt;
  /etc/cron.daily/slocate&lt;br /&gt;
&lt;br /&gt;
  # blank out the system logfiles&lt;br /&gt;
  for logfile in \&lt;br /&gt;
      /var/log/messages /var/log/syslog /var/log/debug /var/log/secure \&lt;br /&gt;
      /var/log/maillog /var/log/spooler /var/log/proftpd.log /var/log/xinetd.log \&lt;br /&gt;
      /var/log/dmesg /var/log/faillog /var/log/lastlog /var/log/wtmp \&lt;br /&gt;
      /var/log/apache/access_log /var/log/apache/error_log \&lt;br /&gt;
      /var/log/webmin/miniserv.error /var/log/webmin/miniserv.pid&lt;br /&gt;
  do cp /dev/null $logfile ; done&lt;br /&gt;
  rmdir /var/log/sa&lt;br /&gt;
&lt;br /&gt;
  # clear the SSH host key&lt;br /&gt;
  rm -f /etc/ssh/ssh_host_*&lt;br /&gt;
&lt;br /&gt;
  # database server logfiles&lt;br /&gt;
  rm -f /var/lib/mysql/*.err /var/lib/pgsql/logfile&lt;br /&gt;
&lt;br /&gt;
  # delete vi backup files, bash_history files, and other small application crud&lt;br /&gt;
  unset HISTFILE&lt;br /&gt;
  find / -name '*~' \&lt;br /&gt;
      -o -name .bash_history \&lt;br /&gt;
      -o -name .gnupg \&lt;br /&gt;
      -o -name .lesshst \&lt;br /&gt;
      -o -name .viminfo \&lt;br /&gt;
      -o -name .rnd \&lt;br /&gt;
      -delete&lt;br /&gt;
&lt;br /&gt;
  # anything under /tmp&lt;br /&gt;
  rm -rf /tmp/*&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Zipping it up into a cache image ==&lt;br /&gt;
&lt;br /&gt;
A VE cache is just a tar.gz file of the entire filesystem, excluding some very dynamic stuff which gets populated by the OS at runtime anyway:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
tar zcvf /tmp/HostGIS_Linux_4.2_64bit.tar.gz --exclude='/sys/*' --exclude='/proc/*' --exclude='/tmp/*' /&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>HostGIS</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Creating_a_template_cache_:_Slackware_or_HostGIS_Linux&amp;diff=3685</id>
		<title>Creating a template cache : Slackware or HostGIS Linux</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Creating_a_template_cache_:_Slackware_or_HostGIS_Linux&amp;diff=3685"/>
		<updated>2007-11-30T17:00:28Z</updated>

		<summary type="html">&lt;p&gt;HostGIS: /* Fix permissions and ownerships */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Creating a new Host Template Cache for HostGIS Linux 4.x or Slackware 11.x/12.x ==&lt;br /&gt;
&lt;br /&gt;
This process uses VMWare to install the OS into a VM, then to trim down the VM's contents to only those items suitable for a VPS/VE environment, then to save a snapshot of the system as a host template cache for use in OpenVZ.&lt;br /&gt;
&lt;br /&gt;
This document focuses on HostGIS Linux (a Slackware derivative) but aside from the specifics about installation settings, it should be 99% applicable to Slackware as well.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Create the VM in VMWare ===&lt;br /&gt;
&lt;br /&gt;
Technically, you could probably do this on a hardware PC without VMWare, but VMWare does make it more convenient.&lt;br /&gt;
&lt;br /&gt;
Start by creating a new VM in VMWare.&lt;br /&gt;
* The disk and RAM stats can be minimal, as the system will never see live use.&lt;br /&gt;
* There is no need to create the entire disk at once during the setup.&lt;br /&gt;
* Create the disk as SCSI.&lt;br /&gt;
&lt;br /&gt;
Then install HGL.&lt;br /&gt;
* Create a small partition at the end of the disk for swap. Some swap is technically necessary, but since you'll never in fact be using it, a few MB should be fine.&lt;br /&gt;
* Set the passwords to 'password'&lt;br /&gt;
* Do set the timezone properly. The internal clock does not use UTC/GMT.&lt;br /&gt;
* Select the default mouse, but do NOT enable GPM at startup.&lt;br /&gt;
* Hostname:  template   Domain: internal.lan&lt;br /&gt;
* IP config:  as appropriate for your LAN&lt;br /&gt;
* Nameserver: no&lt;br /&gt;
&lt;br /&gt;
Reboot into your new HGL install, and log in.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Delete unnecessary stuff ==&lt;br /&gt;
&lt;br /&gt;
A lot of packages aren't relevant to a VPS setting, e.g. floppy disk utilities and kernel modules, even getty listening on the console.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  # kernel, kernel modules, documentation, mount points&lt;br /&gt;
  rm -rf /lib/modules /boot /dev/.udev /usr/doc /usr/info /media&lt;br /&gt;
&lt;br /&gt;
  # packages not applicable to a VPS setting&lt;br /&gt;
  cd /var/log/packages&lt;br /&gt;
  for pkg in \&lt;br /&gt;
     hotplug-* hdparm-* devmapper-* udev-* usbutils-* pciutils-* module-init-tools-* \&lt;br /&gt;
     mdadm-* floppy-* lvm2-* raidtools-* reiserfsprogs-* \&lt;br /&gt;
     smartmontools-* sysfsutils-* syslinux-* wireless_tools.* quota-* iptables-*&lt;br /&gt;
  do removepkg $pkg ; done&lt;br /&gt;
&lt;br /&gt;
  # prune init's getty&lt;br /&gt;
  vi  /etc/inittab # delete everything after entry l6 (runlevel 6)&lt;br /&gt;
  init q&lt;br /&gt;
&lt;br /&gt;
  # clean out the fstab and mtab files&lt;br /&gt;
  ( cd /etc ; rm -f fstab mtab ; ln -s ../proc/mounts mtab )&lt;br /&gt;
  echo &amp;quot;proc     /proc      proc     defaults    0  0&amp;quot; &amp;gt;&amp;gt; /etc/fstab&lt;br /&gt;
  echo &amp;quot;devpts   /dev/pts   devpts   mode=0620   0  0&amp;quot; &amp;gt;&amp;gt; /etc/fstab&lt;br /&gt;
&lt;br /&gt;
  # the startup sequence and services&lt;br /&gt;
  cd /etc/rc.d&lt;br /&gt;
  rm -f rc.gpm-sample rc.gpm rc.hotplug rc.ip_forward rc.modules \&lt;br /&gt;
        rc.scanluns  rc.serial rc.udev rc.sysvinit&lt;br /&gt;
  vi rc.syslog    # delete all mentions of klogd&lt;br /&gt;
  vi rc.M         # delete the setterm entry&lt;br /&gt;
  vi rc.S         # delete the MOTD clobbering&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Fix permissions and ownerships ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  # clear out old/dummy SSL certificates&lt;br /&gt;
  mv /etc/ssl/openssl.cnf /tmp ; rm -r /etc/ssl/* ; mv /tmp/openssl.cnf /etc/ssl&lt;br /&gt;
&lt;br /&gt;
  # set an ownership on any unowned files&lt;br /&gt;
  find / -mount -nouser -exec chown root {} \; &amp;amp;&lt;br /&gt;
  find / -mount -nogroup -exec chgrp root {} \; &amp;amp;&lt;br /&gt;
&lt;br /&gt;
  # remove the setuid bit from programs which nobody else should use&lt;br /&gt;
  # you may want to review this list first, as some folks want their users&lt;br /&gt;
  # able to edit cronjobs and to change their own passwords, etc.&lt;br /&gt;
  for i in \&lt;br /&gt;
    /bin/ping /bin/mount /bin/ping6 /bin/umount /usr/bin/chfn \&lt;br /&gt;
     /usr/bin/chsh /usr/bin/crontab /usr/bin/chage /usr/bin/traceroute6 /usr/bin/traceroute \&lt;br /&gt;
     /usr/bin/expiry /usr/bin/newgrp /usr/bin/passwd /usr/bin/gpasswd \&lt;br /&gt;
     /usr/libexec/ssh-keysign /usr/libexec/pt_chown /usr/bin/wall /usr/bin/write&lt;br /&gt;
     do chmod u-s $i ; done&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Changes to rc scripts ==&lt;br /&gt;
&lt;br /&gt;
OpenVZ emulates rebooting with an external cronjob called vpsreboot and a dummy file called /reboot within the VPS, and emulates the /etc/mtab file by pointing it to /proc/mounts So, some small changes are necessary to the rc scripts.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# somewhere in rc.6 add this command: touch /reboot&lt;br /&gt;
vi /etc/rc.d/rc.6&lt;br /&gt;
&lt;br /&gt;
# somewhere in rc.M, add this command: rm -f /etc/mtab ;  ln -s /proc/mounts /etc/mtab&lt;br /&gt;
vi /etc/rc.d/rc.M&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Blanking settings ==&lt;br /&gt;
&lt;br /&gt;
Lastly, you'll want to delete or blank out a bunch of files so they start fresh&lt;br /&gt;
when the VE is booted for its first time.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  # stop all services&lt;br /&gt;
  apachectl stop&lt;br /&gt;
  killall syslogd klogd udevd crond&lt;br /&gt;
  /etc/rc.d/rc.sendmail stop&lt;br /&gt;
  /etc/rc.d/rc.inetd stop&lt;br /&gt;
  /etc/webmin/stop&lt;br /&gt;
  /etc/rc.d/rc.pgsql stop&lt;br /&gt;
  /etc/rc.d/rc.mysqld stop&lt;br /&gt;
  killall named proftpd&lt;br /&gt;
&lt;br /&gt;
  # blow away the network configuration with dummy strings for later replacement&lt;br /&gt;
  #    replace the IP address with __IPADDRESS_&lt;br /&gt;
  #    replace the netmask with __NETMASK__&lt;br /&gt;
  #    replace the GATEWAY with __GATEWAY__&lt;br /&gt;
  vi /etc/rc.d/rc.inet1.conf&lt;br /&gt;
&lt;br /&gt;
  # disable the root and user accounts&lt;br /&gt;
  # by changing the password for root and user to a ! character.&lt;br /&gt;
  vi /etc/shadow&lt;br /&gt;
&lt;br /&gt;
  # refresh the 'locate' cache&lt;br /&gt;
  /etc/cron.daily/slocate&lt;br /&gt;
&lt;br /&gt;
  # blank out the system logfiles&lt;br /&gt;
  for logfile in \&lt;br /&gt;
      /var/log/messages /var/log/syslog /var/log/debug /var/log/secure \&lt;br /&gt;
      /var/log/maillog /var/log/spooler /var/log/proftpd.log /var/log/xinetd.log \&lt;br /&gt;
      /var/log/dmesg /var/log/faillog /var/log/lastlog /var/log/wtmp \&lt;br /&gt;
      /var/log/apache/access_log /var/log/apache/error_log \&lt;br /&gt;
      /var/log/webmin/miniserv.error /var/log/webmin/miniserv.pid&lt;br /&gt;
  do cp /dev/null $logfile ; done&lt;br /&gt;
  rmdir /var/log/sa&lt;br /&gt;
&lt;br /&gt;
  # clear the SSH host key&lt;br /&gt;
  rm -f /etc/ssh/ssh_host_*&lt;br /&gt;
&lt;br /&gt;
  # database server logfiles&lt;br /&gt;
  rm -f /var/lib/mysql/*.err /var/lib/pgsql/logfile&lt;br /&gt;
&lt;br /&gt;
  # delete vi backup files, bash_history files, and other small application crud&lt;br /&gt;
  unset HISTFILE&lt;br /&gt;
  find / -name '*~' \&lt;br /&gt;
      -o -name .bash_history \&lt;br /&gt;
      -o -name .gnupg \&lt;br /&gt;
      -o -name .lesshst \&lt;br /&gt;
      -o -name .viminfo \&lt;br /&gt;
      -o -name .rnd \&lt;br /&gt;
      -delete&lt;br /&gt;
&lt;br /&gt;
  # anything under /tmp&lt;br /&gt;
  rm -rf /tmp/*&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Zipping it up into a cache image ==&lt;br /&gt;
&lt;br /&gt;
A VE cache is just a tar.gz file of the entire filesystem, excluding some very dynamic stuff which gets populated by the OS at runtime anyway:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
tar zcvf /tmp/HostGIS_Linux_4.2_64bit.tar.gz --exclude='/sys/*' --exclude='/proc/*' --exclude='/tmp/*' /&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>HostGIS</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Creating_a_template_cache_:_Slackware_or_HostGIS_Linux&amp;diff=3684</id>
		<title>Creating a template cache : Slackware or HostGIS Linux</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Creating_a_template_cache_:_Slackware_or_HostGIS_Linux&amp;diff=3684"/>
		<updated>2007-11-30T16:58:57Z</updated>

		<summary type="html">&lt;p&gt;HostGIS: nearing the final version!&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Creating a new Host Template Cache for HostGIS Linux 4.x or Slackware 11.x/12.x ==&lt;br /&gt;
&lt;br /&gt;
This process uses VMWare to install the OS into a VM, then to trim down the VM's contents to only those items suitable for a VPS/VE environment, then to save a snapshot of the system as a host template cache for use in OpenVZ.&lt;br /&gt;
&lt;br /&gt;
This document focuses on HostGIS Linux (a Slackware derivative) but aside from the specifics about installation settings, it should be 99% applicable to Slackware as well.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Create the VM in VMWare ===&lt;br /&gt;
&lt;br /&gt;
Technically, you could probably do this on a hardware PC without VMWare, but VMWare does make it more convenient.&lt;br /&gt;
&lt;br /&gt;
Start by creating a new VM in VMWare.&lt;br /&gt;
* The disk and RAM stats can be minimal, as the system will never see live use.&lt;br /&gt;
* There is no need to create the entire disk at once during the setup.&lt;br /&gt;
* Create the disk as SCSI.&lt;br /&gt;
&lt;br /&gt;
Then install HGL.&lt;br /&gt;
* Create a small partition at the end of the disk for swap. Some swap is technically necessary, but since you'll never in fact be using it, a few MB should be fine.&lt;br /&gt;
* Set the passwords to 'password'&lt;br /&gt;
* Do set the timezone properly. The internal clock does not use UTC/GMT.&lt;br /&gt;
* Select the default mouse, but do NOT enable GPM at startup.&lt;br /&gt;
* Hostname:  template   Domain: internal.lan&lt;br /&gt;
* IP config:  as appropriate for your LAN&lt;br /&gt;
* Nameserver: no&lt;br /&gt;
&lt;br /&gt;
Reboot into your new HGL install, and log in.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Delete unnecessary stuff ==&lt;br /&gt;
&lt;br /&gt;
A lot of packages aren't relevant to a VPS setting, e.g. floppy disk utilities and kernel modules, even getty listening on the console.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  # kernel, kernel modules, documentation, mount points&lt;br /&gt;
  rm -rf /lib/modules /boot /dev/.udev /usr/doc /usr/info /media&lt;br /&gt;
&lt;br /&gt;
  # packages not applicable to a VPS setting&lt;br /&gt;
  cd /var/log/packages&lt;br /&gt;
  for pkg in \&lt;br /&gt;
     hotplug-* hdparm-* devmapper-* udev-* usbutils-* pciutils-* module-init-tools-* \&lt;br /&gt;
     mdadm-* floppy-* lvm2-* raidtools-* reiserfsprogs-* \&lt;br /&gt;
     smartmontools-* sysfsutils-* syslinux-* wireless_tools.* quota-* iptables-*&lt;br /&gt;
  do removepkg $pkg ; done&lt;br /&gt;
&lt;br /&gt;
  # prune init's getty&lt;br /&gt;
  vi  /etc/inittab # delete everything after entry l6 (runlevel 6)&lt;br /&gt;
  init q&lt;br /&gt;
&lt;br /&gt;
  # clean out the fstab and mtab files&lt;br /&gt;
  ( cd /etc ; rm -f fstab mtab ; ln -s ../proc/mounts mtab )&lt;br /&gt;
  echo &amp;quot;proc     /proc      proc     defaults    0  0&amp;quot; &amp;gt;&amp;gt; /etc/fstab&lt;br /&gt;
  echo &amp;quot;devpts   /dev/pts   devpts   mode=0620   0  0&amp;quot; &amp;gt;&amp;gt; /etc/fstab&lt;br /&gt;
&lt;br /&gt;
  # the startup sequence and services&lt;br /&gt;
  cd /etc/rc.d&lt;br /&gt;
  rm -f rc.gpm-sample rc.gpm rc.hotplug rc.ip_forward rc.modules \&lt;br /&gt;
        rc.scanluns  rc.serial rc.udev rc.sysvinit&lt;br /&gt;
  vi rc.syslog    # delete all mentions of klogd&lt;br /&gt;
  vi rc.M         # delete the setterm entry&lt;br /&gt;
  vi rc.S         # delete the MOTD clobbering&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Fix permissions and ownerships ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  # clear out old/dummy SSL certificates&lt;br /&gt;
  mv /etc/ssl/openssl.cnf /tmp ; rm -r /etc/ssl/* ; mv /tmp/openssl.cnf /etc/ssl&lt;br /&gt;
&lt;br /&gt;
  # fix file permissions&lt;br /&gt;
  find / -mount -nouser -exec chown root {} \; &amp;amp;&lt;br /&gt;
  find / -mount -nogroup -exec chgrp root {} \; &amp;amp;&lt;br /&gt;
  for i in \&lt;br /&gt;
    /bin/ping /bin/mount /bin/ping6 /bin/umount /usr/bin/chfn \&lt;br /&gt;
     /usr/bin/chsh /usr/bin/crontab /usr/bin/chage /usr/bin/traceroute6 /usr/bin/traceroute \&lt;br /&gt;
     /usr/bin/expiry /usr/bin/newgrp /usr/bin/passwd /usr/bin/gpasswd \&lt;br /&gt;
     /usr/libexec/ssh-keysign /usr/libexec/pt_chown /usr/bin/wall /usr/bin/write&lt;br /&gt;
     do chmod u-s $i ; done&lt;br /&gt;
&lt;br /&gt;
/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Changes to rc scripts ==&lt;br /&gt;
&lt;br /&gt;
OpenVZ emulates rebooting with an external cronjob called vpsreboot and a dummy file called /reboot within the VPS, and emulates the /etc/mtab file by pointing it to /proc/mounts So, some small changes are necessary to the rc scripts.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# somewhere in rc.6 add this command: touch /reboot&lt;br /&gt;
vi /etc/rc.d/rc.6&lt;br /&gt;
&lt;br /&gt;
# somewhere in rc.M, add this command: rm -f /etc/mtab ;  ln -s /proc/mounts /etc/mtab&lt;br /&gt;
vi /etc/rc.d/rc.M&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Blanking settings ==&lt;br /&gt;
&lt;br /&gt;
Lastly, you'll want to delete or blank out a bunch of files so they start fresh&lt;br /&gt;
when the VE is booted for its first time.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  # stop all services&lt;br /&gt;
  apachectl stop&lt;br /&gt;
  killall syslogd klogd udevd crond&lt;br /&gt;
  /etc/rc.d/rc.sendmail stop&lt;br /&gt;
  /etc/rc.d/rc.inetd stop&lt;br /&gt;
  /etc/webmin/stop&lt;br /&gt;
  /etc/rc.d/rc.pgsql stop&lt;br /&gt;
  /etc/rc.d/rc.mysqld stop&lt;br /&gt;
  killall named proftpd&lt;br /&gt;
&lt;br /&gt;
  # blow away the network configuration with dummy strings for later replacement&lt;br /&gt;
  #    replace the IP address with __IPADDRESS_&lt;br /&gt;
  #    replace the netmask with __NETMASK__&lt;br /&gt;
  #    replace the GATEWAY with __GATEWAY__&lt;br /&gt;
  vi /etc/rc.d/rc.inet1.conf&lt;br /&gt;
&lt;br /&gt;
  # disable the root and user accounts&lt;br /&gt;
  # by changing the password for root and user to a ! character.&lt;br /&gt;
  vi /etc/shadow&lt;br /&gt;
&lt;br /&gt;
  # refresh the 'locate' cache&lt;br /&gt;
  /etc/cron.daily/slocate&lt;br /&gt;
&lt;br /&gt;
  # blank out the system logfiles&lt;br /&gt;
  for logfile in \&lt;br /&gt;
      /var/log/messages /var/log/syslog /var/log/debug /var/log/secure \&lt;br /&gt;
      /var/log/maillog /var/log/spooler /var/log/proftpd.log /var/log/xinetd.log \&lt;br /&gt;
      /var/log/dmesg /var/log/faillog /var/log/lastlog /var/log/wtmp \&lt;br /&gt;
      /var/log/apache/access_log /var/log/apache/error_log \&lt;br /&gt;
      /var/log/webmin/miniserv.error /var/log/webmin/miniserv.pid&lt;br /&gt;
  do cp /dev/null $logfile ; done&lt;br /&gt;
  rmdir /var/log/sa&lt;br /&gt;
&lt;br /&gt;
  # clear the SSH host key&lt;br /&gt;
  rm -f /etc/ssh/ssh_host_*&lt;br /&gt;
&lt;br /&gt;
  # database server logfiles&lt;br /&gt;
  rm -f /var/lib/mysql/*.err /var/lib/pgsql/logfile&lt;br /&gt;
&lt;br /&gt;
  # delete vi backup files, bash_history files, and other small application crud&lt;br /&gt;
  unset HISTFILE&lt;br /&gt;
  find / -name '*~' \&lt;br /&gt;
      -o -name .bash_history \&lt;br /&gt;
      -o -name .gnupg \&lt;br /&gt;
      -o -name .lesshst \&lt;br /&gt;
      -o -name .viminfo \&lt;br /&gt;
      -o -name .rnd \&lt;br /&gt;
      -delete&lt;br /&gt;
&lt;br /&gt;
  # anything under /tmp&lt;br /&gt;
  rm -rf /tmp/*&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Zipping it up into a cache image ==&lt;br /&gt;
&lt;br /&gt;
A VE cache is just a tar.gz file of the entire filesystem, excluding some very dynamic stuff which gets populated by the OS at runtime anyway:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
tar zcvf /tmp/HostGIS_Linux_4.2_64bit.tar.gz --exclude='/sys/*' --exclude='/proc/*' --exclude='/tmp/*' /&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>HostGIS</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Creating_a_template_cache_:_Slackware_or_HostGIS_Linux&amp;diff=3683</id>
		<title>Creating a template cache : Slackware or HostGIS Linux</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Creating_a_template_cache_:_Slackware_or_HostGIS_Linux&amp;diff=3683"/>
		<updated>2007-11-30T16:48:19Z</updated>

		<summary type="html">&lt;p&gt;HostGIS: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Creating a new Host Template Cache for HostGIS Linux 4.x or Slackware 11.x/12.x ==&lt;br /&gt;
&lt;br /&gt;
This process uses VMWare to install the OS into a VM, then to trim down the VM's contents to only those items suitable for a VPS/VE environment, then to save a snapshot of the system as a host template cache for use in OpenVZ.&lt;br /&gt;
&lt;br /&gt;
This document focuses on HostGIS Linux (a Slackware derivative) but aside from the specifics about installation settings, it should be 99% applicable to Slackware as well.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Create the VM in VMWare ===&lt;br /&gt;
&lt;br /&gt;
Technically, you could probably do this on a hardware PC without VMWare, but VMWare does make it more convenient.&lt;br /&gt;
&lt;br /&gt;
Start by creating a new VM in VMWare.&lt;br /&gt;
* The disk and RAM stats can be minimal, as the system will never see live use.&lt;br /&gt;
* There is no need to create the entire disk at once during the setup.&lt;br /&gt;
* Create the disk as SCSI.&lt;br /&gt;
&lt;br /&gt;
Then install HGL.&lt;br /&gt;
* Create a small partition at the end of the disk for swap. Some swap is technically necessary, but since you'll never in fact be using it, a few MB should be fine.&lt;br /&gt;
* Set the passwords to 'password'&lt;br /&gt;
* Do set the timezone properly. The internal clock does not use UTC/GMT.&lt;br /&gt;
* Select the default mouse, but do NOT enable GPM at startup.&lt;br /&gt;
* Hostname:  template   Domain: internal.lan&lt;br /&gt;
* IP config:  as appropriate for your LAN&lt;br /&gt;
* Nameserver: no&lt;br /&gt;
&lt;br /&gt;
Reboot into your new HGL install, and log in.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Delete unnecessary stuff ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  # kernel, kernel modules, documentation, mount points&lt;br /&gt;
  rm -rf /lib/modules /boot /dev/.udev /usr/doc /usr/info /media&lt;br /&gt;
&lt;br /&gt;
  # packages not applicable to a VPS setting, or which we don't use at HostGIS&lt;br /&gt;
  # e.g. phpMyAdmin and phpPgAdmin are security holes&lt;br /&gt;
  cd /var/log/packages&lt;br /&gt;
  for pkg in \&lt;br /&gt;
     hotplug-* hdparm-* devmapper-* udev-* usbutils-* pciutils-* module-init-tools-* \&lt;br /&gt;
     mdadm-* floppy-* lvm2-* phpMyAdmin-* phppgAdmin-* raidtools-* reiserfsprogs-* \&lt;br /&gt;
     smartmontools-* sysfsutils-* syslinux-* wireless_tools.* quota-* iptables-*&lt;br /&gt;
  do removepkg $pkg ; done&lt;br /&gt;
&lt;br /&gt;
  # most folks don't use GeoServer, so disable it by default&lt;br /&gt;
  chmod 644 /etc/rc.d/rc.geoserver&lt;br /&gt;
&lt;br /&gt;
  # prune init's getty&lt;br /&gt;
  vi  /etc/inittab # delete everything after entry l6 (runlevel 6)&lt;br /&gt;
  init q&lt;br /&gt;
&lt;br /&gt;
  # clean out the fstab and mtab files&lt;br /&gt;
  ( cd /etc ; rm -f fstab mtab ; ln -s ../proc/mounts mtab )&lt;br /&gt;
  echo &amp;quot;proc     /proc      proc     defaults    0  0&amp;quot; &amp;gt;&amp;gt; /etc/fstab&lt;br /&gt;
  echo &amp;quot;devpts   /dev/pts   devpts   mode=0620   0  0&amp;quot; &amp;gt;&amp;gt; /etc/fstab&lt;br /&gt;
&lt;br /&gt;
  # the startup sequence and services, even the firewall&lt;br /&gt;
  cd /etc/rc.d&lt;br /&gt;
  rm -f rc.gpm-sample rc.gpm rc.hotplug rc.ip_forward rc.modules \&lt;br /&gt;
        rc.scanluns  rc.serial rc.udev rc.sysvinit   rc.firewall&lt;br /&gt;
  vi rc.syslog    # delete all mentions of klogd&lt;br /&gt;
  vi rc.local     # delete smartd and inetd&lt;br /&gt;
  vi rc.M         # delete the setterm entry&lt;br /&gt;
  vi rc.S         # delete the MOTD clobbering&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Fix permissions and ownerships ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# clear out old/dummy SSL certificates&lt;br /&gt;
mv /etc/ssl/openssl.cnf /tmp ; rm -r /etc/ssl/* ; mv /tmp/openssl.cnf /etc/ssl&lt;br /&gt;
&lt;br /&gt;
# fix file permissions&lt;br /&gt;
find / -mount -nouser -exec chown root {} \; &amp;amp;&lt;br /&gt;
find / -mount -nogroup -exec chgrp root {} \; &amp;amp;&lt;br /&gt;
for i in \&lt;br /&gt;
   /bin/ping /bin/mount /bin/ping6 /bin/umount /usr/bin/chfn \&lt;br /&gt;
   /usr/bin/chsh /usr/bin/crontab /usr/bin/chage /usr/bin/traceroute6 /usr/bin/traceroute \&lt;br /&gt;
   /usr/bin/expiry /usr/bin/newgrp /usr/bin/passwd /usr/bin/gpasswd \&lt;br /&gt;
   /usr/libexec/ssh-keysign /usr/libexec/pt_chown /usr/bin/wall /usr/bin/write&lt;br /&gt;
   do chmod u-s $i ; done&lt;br /&gt;
&lt;br /&gt;
# fix Apache's configuration:&lt;br /&gt;
# add ServerTokens prod&lt;br /&gt;
# go to the htdocs Directory definition and change Indexes to -Indexes&lt;br /&gt;
# delete the entries for phpmyadmin and phppgadmin&lt;br /&gt;
vi /etc/apache/httpd.conf&lt;br /&gt;
&lt;br /&gt;
# keep FTP users chrooted:&lt;br /&gt;
echo &amp;quot;&amp;quot; &amp;gt;&amp;gt; /etc/proftpd.conf&lt;br /&gt;
echo &amp;quot;# keep all users chrooted to their homedir&amp;quot; &amp;gt;&amp;gt; /etc/proftpd.conf&lt;br /&gt;
echo &amp;quot;DefaultRoot ~&amp;quot; &amp;gt;&amp;gt; /etc/proftpd.conf&lt;br /&gt;
&lt;br /&gt;
# allow the mailq to be checked by anybody:&lt;br /&gt;
chgrp smmsp /var/spool/mqueue&lt;br /&gt;
chmod g+rx /var/spool/mqueue&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Changes to rc scripts ==&lt;br /&gt;
&lt;br /&gt;
A VPS cannot actually reboot, since there's no power switch to power-cycle the machine&lt;br /&gt;
after the VE has been shut down. OpenVZ emulates this effect with an external cronjob&lt;br /&gt;
called vpsreboot (see /etc/cron.d/vz). In order to reboot a VPS that has been shut down&lt;br /&gt;
and which is expecting a reboot, the shutdown sequence must create a file named /reboot&lt;br /&gt;
in the VPS's filesystem.&lt;br /&gt;
&lt;br /&gt;
Also, the /etc/mtab file should point to /proc/mounts so it can detect the / filesystem.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vi /etc/rc.d/rc.6&lt;br /&gt;
And add these two lines near the start:&lt;br /&gt;
# create the reboot flag so we get rebooted automatically&lt;br /&gt;
touch /reboot&lt;br /&gt;
&lt;br /&gt;
vi /etc/rc.d/rc.M&lt;br /&gt;
And add these two lines near the start:&lt;br /&gt;
# replace the mtab file with a link to /proc/mounts so OpenVZ can find the / filesystem&lt;br /&gt;
rm -f /etc/mtab ;  ln -s /proc/mounts /etc/mtab&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Blanking settings ==&lt;br /&gt;
&lt;br /&gt;
Lastly, you'll want to delete or blank out a bunch of files so they start fresh&lt;br /&gt;
when the VE is booted for its first time.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# stop all services&lt;br /&gt;
apachectl stop&lt;br /&gt;
killall syslogd klogd udevd crond&lt;br /&gt;
/etc/rc.d/rc.sendmail stop&lt;br /&gt;
/etc/webmin/stop&lt;br /&gt;
/etc/rc.d/rc.pgsql stop&lt;br /&gt;
/etc/rc.d/rc.mysqld stop&lt;br /&gt;
killall named proftpd&lt;br /&gt;
killall xinetd&lt;br /&gt;
&lt;br /&gt;
# blow away the network configuration with dummy strings for later replacement&lt;br /&gt;
#    replace the IP address with __IPADDRESS_&lt;br /&gt;
#    replace the netmask with __NETMASK__&lt;br /&gt;
#    replace the GATEWAY with __GATEWAY__&lt;br /&gt;
vi /etc/rc.d/rc.inet1.conf&lt;br /&gt;
&lt;br /&gt;
# disable the root and user accounts&lt;br /&gt;
# by changing the password for root and user to a ! character.&lt;br /&gt;
vi /etc/shadow&lt;br /&gt;
&lt;br /&gt;
# refresh the 'locate' cache&lt;br /&gt;
/etc/cron.daily/slocate&lt;br /&gt;
&lt;br /&gt;
# blank out the system logfiles&lt;br /&gt;
for logfile in \&lt;br /&gt;
    /var/log/messages /var/log/syslog /var/log/debug /var/log/secure \&lt;br /&gt;
    /var/log/maillog /var/log/spooler /var/log/proftpd.log /var/log/xinetd.log \&lt;br /&gt;
    /var/log/dmesg /var/log/faillog /var/log/lastlog /var/log/wtmp \&lt;br /&gt;
    /var/log/apache/access_log /var/log/apache/error_log \&lt;br /&gt;
    /var/log/webmin/miniserv.error /var/log/webmin/miniserv.pid&lt;br /&gt;
do cp /dev/null $logfile ; done&lt;br /&gt;
rmdir /var/log/sa&lt;br /&gt;
&lt;br /&gt;
# clear the SSH host key&lt;br /&gt;
rm -f /etc/ssh/ssh_host_*&lt;br /&gt;
&lt;br /&gt;
# database server logfiles&lt;br /&gt;
rm -f /var/lib/mysql/*.err /var/lib/pgsql/logfile&lt;br /&gt;
&lt;br /&gt;
# delete vi backup files, bash_history files, and other small application crud&lt;br /&gt;
unset HISTFILE&lt;br /&gt;
find / -name '*~' \&lt;br /&gt;
    -o -name .bash_history \&lt;br /&gt;
    -o -name .gnupg \&lt;br /&gt;
    -o -name .lesshst \&lt;br /&gt;
    -o -name .viminfo \&lt;br /&gt;
    -o -name .rnd \&lt;br /&gt;
    -delete&lt;br /&gt;
&lt;br /&gt;
# the junk under /tmp&lt;br /&gt;
rm -rf /tmp/*&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Zipping it up into a cache image ==&lt;br /&gt;
&lt;br /&gt;
A VE cache is just a tar.gz file of the entire filesystem, excluding some very dynamic stuff which gets populated by the OS at runtime anyway:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
tar zcvf /tmp/HostGIS_Linux_4.2_64bit.tar.gz --exclude='/sys/*' --exclude='/proc/*' --exclude='/tmp/*' /&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>HostGIS</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Creating_a_template_cache_:_Slackware_or_HostGIS_Linux&amp;diff=3681</id>
		<title>Creating a template cache : Slackware or HostGIS Linux</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Creating_a_template_cache_:_Slackware_or_HostGIS_Linux&amp;diff=3681"/>
		<updated>2007-11-30T16:29:41Z</updated>

		<summary type="html">&lt;p&gt;HostGIS: Creating a template cache for SLackware or HostGIS Linux moved to Creating a template cache : Slackware or HostGIS Linux: Typo in title&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Creating a new Host Template Cache&lt;br /&gt;
for HostGIS Linux 4.x or Slackware 11.x/12.x&lt;br /&gt;
&lt;br /&gt;
This process uses VMWare to install the OS into a VM, then to trim down the VM's contents to only those items suitable for a VPS/VE environment, then to save a snapshot of the system as a host template cache for use in OpenVZ.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** CREATING THE VM&lt;br /&gt;
&lt;br /&gt;
Start by creating a new VM in VMWare. The stats can be minimal, and there&lt;br /&gt;
is no need to create the entire disk at once during the setup.&lt;br /&gt;
   * Create the disk as SCSI.&lt;br /&gt;
&lt;br /&gt;
Then install HGL.&lt;br /&gt;
  * Create a small partition at the end of the disk for swap. Some swap&lt;br /&gt;
    is technically necessary, but since you'll never in fact be using it,&lt;br /&gt;
    a few MB should be fine.&lt;br /&gt;
  * Set the passwords to 'password'&lt;br /&gt;
  * Do set the timezone properly. The internal clock does not use UTC/GMT.&lt;br /&gt;
  * Select the default mouse, but do NOT enable GPM at startup.&lt;br /&gt;
  * Hostname:  template   Domain: internal.lan&lt;br /&gt;
  * IP config:  as appropriate for your LAN&lt;br /&gt;
  * Nameserver: no&lt;br /&gt;
Reboot into your new HGL install.&lt;br /&gt;
&lt;br /&gt;
Now we want to tweak it into a usable template.&lt;br /&gt;
Go ahead and login to the VM.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** UPGRADES AND SECURITY PATCHES&lt;br /&gt;
&lt;br /&gt;
The default HGL you used may require some software to be reinstalled, since new versions&lt;br /&gt;
and critical bugfixes may have been released since that version of HGL was released.&lt;br /&gt;
Follow these instructions, and also update them as necessary for the appropriate versions&lt;br /&gt;
and to remove paragraphs when a revision of HGL comes out that no longer requires them.&lt;br /&gt;
&lt;br /&gt;
# HGL 4.2 - no necessary upgrades as of Nov 29 2007&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** REPLACE INETD WITH XINETD&lt;br /&gt;
&lt;br /&gt;
Inetd is good but minimal. Xinetd offers security features, such as restricting service &lt;br /&gt;
to only certain IPs, and only listening on certain interfaces,.&lt;br /&gt;
&lt;br /&gt;
removepkg inetd&lt;br /&gt;
rm -f /etc/inetd.conf* /etc/rc.d/rc.inetd&lt;br /&gt;
&lt;br /&gt;
cd /tmp&lt;br /&gt;
wget --header=&amp;quot;Host: xinetd.org&amp;quot; http://204.152.188.37/xinetd-2.3.14.tar.gz&lt;br /&gt;
tar zxvf xinetd*.gz&lt;br /&gt;
cd xinetd*&lt;br /&gt;
./configure --prefix=/usr --sysconfdir=/etc&lt;br /&gt;
make &amp;amp;&amp;amp; make install&lt;br /&gt;
mkdir /etc/xinetd.d&lt;br /&gt;
cat &amp;gt;&amp;gt; /etc/rc.d/rc.local &amp;lt;&amp;lt;EOF&lt;br /&gt;
&lt;br /&gt;
# xinetd&lt;br /&gt;
/usr/sbin/xinetd&lt;br /&gt;
EOF&lt;br /&gt;
cat &amp;gt; /etc/xinetd.conf &amp;lt;&amp;lt;EOF&lt;br /&gt;
defaults&lt;br /&gt;
{&lt;br /&gt;
        log_type        = SYSLOG daemon notice&lt;br /&gt;
        log_on_success  = HOST EXIT DURATION&lt;br /&gt;
        log_on_failure  = HOST ATTEMPT&lt;br /&gt;
        instances       = 30&lt;br /&gt;
        cps             = 50 10&lt;br /&gt;
}&lt;br /&gt;
includedir /etc/xinetd.d&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** NAGIOS: THE HEALTH-MONITORING SYSTEM&lt;br /&gt;
&lt;br /&gt;
groupadd nagios&lt;br /&gt;
useradd -g nagios -d /usr/local/nagios -m nagios&lt;br /&gt;
echo &amp;quot;nrpe             5666/tcp  # Nagios NRPE&amp;quot; &amp;gt;&amp;gt; /etc/services&lt;br /&gt;
&lt;br /&gt;
cd /tmp&lt;br /&gt;
wget http://superb-east.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.10.tar.gz&lt;br /&gt;
tar zxvf nagios-plugins-*.tar.gz ; cd nagios-plugins-*&lt;br /&gt;
./configure &amp;amp;&amp;amp; make all &amp;amp;&amp;amp; make install&lt;br /&gt;
cd /tmp&lt;br /&gt;
wget http://umn.dl.sourceforge.net/sourceforge/nagios/nrpe-2.10.tar.gz&lt;br /&gt;
tar zxvf nrpe-2.10.tar.gz ; cd nrpe-2.10&lt;br /&gt;
./configure &amp;amp;&amp;amp; make &amp;amp;&amp;amp; cp src/nrpe /usr/local/nagios/nrpe&lt;br /&gt;
&lt;br /&gt;
for plugin in \&lt;br /&gt;
   check_wave check_users check_ups check_time check_tcp check_swap check_ssh check_ssmtp \&lt;br /&gt;
   check_spop check_simap check_smtp check_sensors check_rpc check_real check_pop check_ping \&lt;br /&gt;
   check_overcr check_oracle check_nwstat check_nt check_nntps check_nntp check_nagios \&lt;br /&gt;
   check_mysql_query check_mrtgtraf check_mrtg check_log check_jabber check_ircd \&lt;br /&gt;
   check_imap check_ifstatus check_ifoperstatus check_icmp check_http check_ftp check_flexlm \&lt;br /&gt;
   check_file_age check_dummy check_disk_smb check_dig check_dhcp check_clamd check_by_ssh \&lt;br /&gt;
   check_breeze check_apt check_udp&lt;br /&gt;
do rm -f /usr/local/nagios/libexec/$plugin ; done&lt;br /&gt;
&lt;br /&gt;
cat &amp;gt; /usr/local/nagios/nrpe.cfg &amp;lt;&amp;lt;EOF&lt;br /&gt;
# NRPE Config File&lt;br /&gt;
pid_file=/var/run/nrpe.pid&lt;br /&gt;
debug=0&lt;br /&gt;
command_timeout=60&lt;br /&gt;
connection_timeout=300&lt;br /&gt;
&lt;br /&gt;
# And now the list of allowed check-commands:&lt;br /&gt;
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -m /&lt;br /&gt;
command[check_dns]=/usr/local/nagios/libexec/check_dns www.google.com&lt;br /&gt;
command[check_load]=/usr/local/nagios/libexec/check_load -w 5,5,5 -c 8,8,8&lt;br /&gt;
command[check_mailq]=/usr/local/nagios/libexec/check_mailq -w 10 -c 20&lt;br /&gt;
command[check_mysql]=/usr/local/nagios/libexec/check_mysql -d gisdata -H localhost -u gisdata -p password&lt;br /&gt;
command[check_pgsql]=/usr/local/nagios/libexec/check_pgsql -d gisdata -H localhost -l gisdata -p password&lt;br /&gt;
command[check_ntp]=/usr/local/nagios/libexec/check_ntp -H pool.ntp.org&lt;br /&gt;
command[check_crond]=/usr/local/nagios/libexec/check_procs -u root -c 1: --command=crond&lt;br /&gt;
command[check_syslogd]=/usr/local/nagios/libexec/check_procs -u root -c 1:1 --command=syslogd&lt;br /&gt;
command[check_xinetd]=/usr/local/nagios/libexec/check_procs -u root -c 1:1 --command=xinetd&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
cat &amp;gt; /etc/xinetd.d/nrpe &amp;lt;&amp;lt;EOF&lt;br /&gt;
# description: NRPE for Nagios&lt;br /&gt;
service nrpe&lt;br /&gt;
{&lt;br /&gt;
   socket_type     = stream&lt;br /&gt;
   protocol        = tcp&lt;br /&gt;
   wait            = no&lt;br /&gt;
   user            = nagios&lt;br /&gt;
   server          = /usr/local/nagios/nrpe&lt;br /&gt;
   server_args     = -c /usr/local/nagios/nrpe.cfg --inetd&lt;br /&gt;
   only_from       = __HOSTIP__&lt;br /&gt;
}&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R nagios:nagios /usr/local/nagios&lt;br /&gt;
chmod -R o-rwx /usr/local/nagios&lt;br /&gt;
chmod go-rwx /etc/xinetd.d&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** OTHER UNNECESSARY STUFF&lt;br /&gt;
&lt;br /&gt;
# kernel, kernel modules, documentation, mount points&lt;br /&gt;
rm -rf /lib/modules /boot /dev/.udev /usr/doc /usr/info /media&lt;br /&gt;
&lt;br /&gt;
# packages not applicable to a VPS setting, or which we don't use at HostGIS&lt;br /&gt;
# e.g. phpMyAdmin and phpPgAdmin are security holes&lt;br /&gt;
cd /var/log/packages&lt;br /&gt;
for pkg in \&lt;br /&gt;
   hotplug-* hdparm-* devmapper-* udev-* usbutils-* pciutils-* module-init-tools-* \&lt;br /&gt;
   mdadm-* floppy-* lvm2-* phpMyAdmin-* phppgAdmin-* raidtools-* reiserfsprogs-* \&lt;br /&gt;
   smartmontools-* sysfsutils-* syslinux-* wireless_tools.* quota-* iptables-*&lt;br /&gt;
do removepkg $pkg ; done&lt;br /&gt;
&lt;br /&gt;
# most folks don't use GeoServer, so disable it by default&lt;br /&gt;
chmod 644 /etc/rc.d/rc.geoserver&lt;br /&gt;
&lt;br /&gt;
# prune init's getty&lt;br /&gt;
vi  /etc/inittab # delete everything after entry l6 (runlevel 6)&lt;br /&gt;
init q&lt;br /&gt;
&lt;br /&gt;
# clean out the fstab and mtab files&lt;br /&gt;
( cd /etc ; rm -f fstab mtab ; ln -s ../proc/mounts mtab )&lt;br /&gt;
echo &amp;quot;proc     /proc      proc     defaults    0  0&amp;quot; &amp;gt;&amp;gt; /etc/fstab&lt;br /&gt;
echo &amp;quot;devpts   /dev/pts   devpts   mode=0620   0  0&amp;quot; &amp;gt;&amp;gt; /etc/fstab&lt;br /&gt;
&lt;br /&gt;
# the startup sequence and services, even the firewall&lt;br /&gt;
cd /etc/rc.d&lt;br /&gt;
rm -f rc.gpm-sample rc.hotplug rc.ip_forward rc.modules rc.scanluns  rc.serial rc.udev rc.sysvinit rc.firewall&lt;br /&gt;
vi rc.syslog    # delete all mentions of klogd&lt;br /&gt;
vi rc.local     # delete smartd and inetd&lt;br /&gt;
vi rc.M         # delete the setterm entry&lt;br /&gt;
vi rc.S         # delete the MOTD clobbering&lt;br /&gt;
&lt;br /&gt;
# blow away the network configuration with dummy strings for later replacement&lt;br /&gt;
#    replace the IP address with __IPADDRESS_&lt;br /&gt;
#    replace the netmask with __NETMASK__&lt;br /&gt;
#    replace the GATEWAY with __GATEWAY__&lt;br /&gt;
vi /etc/rc.d/rc.inet1.conf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** BASIC FILE SECURITY SETTINGS&lt;br /&gt;
&lt;br /&gt;
# clear out old/dummy SSL certificates&lt;br /&gt;
mv /etc/ssl/openssl.cnf /tmp ; rm -r /etc/ssl/* ; mv /tmp/openssl.cnf /etc/ssl&lt;br /&gt;
&lt;br /&gt;
# fix file permissions&lt;br /&gt;
find / -mount -nouser -exec chown root {} \; &amp;amp;&lt;br /&gt;
find / -mount -nogroup -exec chgrp root {} \; &amp;amp;&lt;br /&gt;
for i in \&lt;br /&gt;
   /bin/ping /bin/mount /bin/ping6 /bin/umount /usr/bin/chfn \&lt;br /&gt;
   /usr/bin/chsh /usr/bin/crontab /usr/bin/chage /usr/bin/traceroute6 /usr/bin/traceroute \&lt;br /&gt;
   /usr/bin/expiry /usr/bin/newgrp /usr/bin/passwd /usr/bin/gpasswd \&lt;br /&gt;
   /usr/libexec/ssh-keysign /usr/libexec/pt_chown /usr/bin/wall /usr/bin/write&lt;br /&gt;
   do chmod u-s $i ; done&lt;br /&gt;
&lt;br /&gt;
# fix Apache's configuration:&lt;br /&gt;
# add ServerTokens prod&lt;br /&gt;
# go to the htdocs Directory definition and change Indexes to -Indexes&lt;br /&gt;
# delete the entries for phpmyadmin and phppgadmin&lt;br /&gt;
vi /etc/apache/httpd.conf&lt;br /&gt;
&lt;br /&gt;
# keep FTP users chrooted:&lt;br /&gt;
echo &amp;quot;&amp;quot; &amp;gt;&amp;gt; /etc/proftpd.conf&lt;br /&gt;
echo &amp;quot;# keep all users chrooted to their homedir&amp;quot; &amp;gt;&amp;gt; /etc/proftpd.conf&lt;br /&gt;
echo &amp;quot;DefaultRoot ~&amp;quot; &amp;gt;&amp;gt; /etc/proftpd.conf&lt;br /&gt;
&lt;br /&gt;
# allow the mailq to be checked by anybody:&lt;br /&gt;
chgrp smmsp /var/spool/mqueue&lt;br /&gt;
chmod g+rx /var/spool/mqueue&lt;br /&gt;
&lt;br /&gt;
# disable the root and user accounts&lt;br /&gt;
# by changing the password for root and user to a ! character.&lt;br /&gt;
vi /etc/shadow&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** REBOOTING&lt;br /&gt;
&lt;br /&gt;
A VPS cannot actually reboot, since there's no power switch to power-cycle the machine&lt;br /&gt;
after the VE has been shut down. OpenVZ emulates this effect with an external cronjob&lt;br /&gt;
called vpsreboot (see /etc/cron.d/vz). In order to reboot a VPS that has been shut down&lt;br /&gt;
and which is expecting a reboot, the shutdown sequence must create a file named /reboot&lt;br /&gt;
in the VPS's filesystem.&lt;br /&gt;
&lt;br /&gt;
Also, the /etc/mtab file should point to /proc/mounts so it can detect the / filesystem.&lt;br /&gt;
&lt;br /&gt;
vi /etc/rc.d/rc.6&lt;br /&gt;
And add these two lines near the start:&lt;br /&gt;
# create the reboot flag so we get rebooted automatically&lt;br /&gt;
touch /reboot&lt;br /&gt;
&lt;br /&gt;
vi /etc/rc.d/rc.M&lt;br /&gt;
And add these two lines near the start:&lt;br /&gt;
# replace the mtab file with a link to /proc/mounts so OpenVZ can find the / filesystem&lt;br /&gt;
rm -f /etc/mtab ;  ln -s /proc/mounts /etc/mtab&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** DELETING AND BLANKING SETTINGS&lt;br /&gt;
&lt;br /&gt;
Lastly, you'll want to delete or blank out a bunch of files so they start fresh&lt;br /&gt;
when the VE is booted for its first time.&lt;br /&gt;
&lt;br /&gt;
# stop all services&lt;br /&gt;
apachectl stop&lt;br /&gt;
killall syslogd klogd udevd crond&lt;br /&gt;
/etc/rc.d/rc.sendmail stop&lt;br /&gt;
/etc/webmin/stop&lt;br /&gt;
/etc/rc.d/rc.pgsql stop&lt;br /&gt;
/etc/rc.d/rc.mysqld stop&lt;br /&gt;
killall named proftpd&lt;br /&gt;
killall xinetd&lt;br /&gt;
&lt;br /&gt;
# refresh the 'locate' cache&lt;br /&gt;
/etc/cron.daily/slocate&lt;br /&gt;
&lt;br /&gt;
# blank out the system logfiles&lt;br /&gt;
for logfile in \&lt;br /&gt;
    /var/log/messages /var/log/syslog /var/log/debug /var/log/secure \&lt;br /&gt;
    /var/log/maillog /var/log/spooler /var/log/proftpd.log /var/log/xinetd.log \&lt;br /&gt;
    /var/log/dmesg /var/log/faillog /var/log/lastlog /var/log/wtmp \&lt;br /&gt;
    /var/log/apache/access_log /var/log/apache/error_log \&lt;br /&gt;
    /var/log/webmin/miniserv.error /var/log/webmin/miniserv.pid&lt;br /&gt;
do cp /dev/null $logfile ; done&lt;br /&gt;
rmdir /var/log/sa&lt;br /&gt;
&lt;br /&gt;
# clear the SSH host key&lt;br /&gt;
rm -f /etc/ssh/ssh_host_*&lt;br /&gt;
&lt;br /&gt;
# database server logfiles&lt;br /&gt;
rm -f /var/lib/mysql/*.err /var/lib/pgsql/logfile&lt;br /&gt;
&lt;br /&gt;
# delete vi backup files, bash_history files, and other small application crud&lt;br /&gt;
unset HISTFILE&lt;br /&gt;
find / -name '*~' \&lt;br /&gt;
    -o -name .bash_history \&lt;br /&gt;
    -o -name .gnupg \&lt;br /&gt;
    -o -name .lesshst \&lt;br /&gt;
    -o -name .viminfo \&lt;br /&gt;
    -o -name .rnd \&lt;br /&gt;
    -delete&lt;br /&gt;
&lt;br /&gt;
# the junk under /tmp&lt;br /&gt;
rm -rf /tmp/*&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** CREATING THE VE CACHE IMAGE&lt;br /&gt;
&lt;br /&gt;
A VE cache is just a tar.gz file of the entire filesystem. So creating them is simple!&lt;br /&gt;
&lt;br /&gt;
tar zcvf /tmp/HostGIS_Linux_4.2_64bit.tar.gz --exclude='/sys/*' --exclude='/proc/*' --exclude='/tmp/*' /&lt;br /&gt;
&lt;br /&gt;
Ta-da! That's your new VE template cache. Just SFTP it to the VE server and you're all set!&lt;/div&gt;</summary>
		<author><name>HostGIS</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Creating_a_template_cache_:_Slackware_or_HostGIS_Linux&amp;diff=3680</id>
		<title>Creating a template cache : Slackware or HostGIS Linux</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Creating_a_template_cache_:_Slackware_or_HostGIS_Linux&amp;diff=3680"/>
		<updated>2007-11-30T16:29:13Z</updated>

		<summary type="html">&lt;p&gt;HostGIS: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Creating a new Host Template Cache&lt;br /&gt;
for HostGIS Linux 4.x or Slackware 11.x/12.x&lt;br /&gt;
&lt;br /&gt;
This process uses VMWare to install the OS into a VM, then to trim down the VM's contents to only those items suitable for a VPS/VE environment, then to save a snapshot of the system as a host template cache for use in OpenVZ.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** CREATING THE VM&lt;br /&gt;
&lt;br /&gt;
Start by creating a new VM in VMWare. The stats can be minimal, and there&lt;br /&gt;
is no need to create the entire disk at once during the setup.&lt;br /&gt;
   * Create the disk as SCSI.&lt;br /&gt;
&lt;br /&gt;
Then install HGL.&lt;br /&gt;
  * Create a small partition at the end of the disk for swap. Some swap&lt;br /&gt;
    is technically necessary, but since you'll never in fact be using it,&lt;br /&gt;
    a few MB should be fine.&lt;br /&gt;
  * Set the passwords to 'password'&lt;br /&gt;
  * Do set the timezone properly. The internal clock does not use UTC/GMT.&lt;br /&gt;
  * Select the default mouse, but do NOT enable GPM at startup.&lt;br /&gt;
  * Hostname:  template   Domain: internal.lan&lt;br /&gt;
  * IP config:  as appropriate for your LAN&lt;br /&gt;
  * Nameserver: no&lt;br /&gt;
Reboot into your new HGL install.&lt;br /&gt;
&lt;br /&gt;
Now we want to tweak it into a usable template.&lt;br /&gt;
Go ahead and login to the VM.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** UPGRADES AND SECURITY PATCHES&lt;br /&gt;
&lt;br /&gt;
The default HGL you used may require some software to be reinstalled, since new versions&lt;br /&gt;
and critical bugfixes may have been released since that version of HGL was released.&lt;br /&gt;
Follow these instructions, and also update them as necessary for the appropriate versions&lt;br /&gt;
and to remove paragraphs when a revision of HGL comes out that no longer requires them.&lt;br /&gt;
&lt;br /&gt;
# HGL 4.2 - no necessary upgrades as of Nov 29 2007&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** REPLACE INETD WITH XINETD&lt;br /&gt;
&lt;br /&gt;
Inetd is good but minimal. Xinetd offers security features, such as restricting service &lt;br /&gt;
to only certain IPs, and only listening on certain interfaces,.&lt;br /&gt;
&lt;br /&gt;
removepkg inetd&lt;br /&gt;
rm -f /etc/inetd.conf* /etc/rc.d/rc.inetd&lt;br /&gt;
&lt;br /&gt;
cd /tmp&lt;br /&gt;
wget --header=&amp;quot;Host: xinetd.org&amp;quot; http://204.152.188.37/xinetd-2.3.14.tar.gz&lt;br /&gt;
tar zxvf xinetd*.gz&lt;br /&gt;
cd xinetd*&lt;br /&gt;
./configure --prefix=/usr --sysconfdir=/etc&lt;br /&gt;
make &amp;amp;&amp;amp; make install&lt;br /&gt;
mkdir /etc/xinetd.d&lt;br /&gt;
cat &amp;gt;&amp;gt; /etc/rc.d/rc.local &amp;lt;&amp;lt;EOF&lt;br /&gt;
&lt;br /&gt;
# xinetd&lt;br /&gt;
/usr/sbin/xinetd&lt;br /&gt;
EOF&lt;br /&gt;
cat &amp;gt; /etc/xinetd.conf &amp;lt;&amp;lt;EOF&lt;br /&gt;
defaults&lt;br /&gt;
{&lt;br /&gt;
        log_type        = SYSLOG daemon notice&lt;br /&gt;
        log_on_success  = HOST EXIT DURATION&lt;br /&gt;
        log_on_failure  = HOST ATTEMPT&lt;br /&gt;
        instances       = 30&lt;br /&gt;
        cps             = 50 10&lt;br /&gt;
}&lt;br /&gt;
includedir /etc/xinetd.d&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** NAGIOS: THE HEALTH-MONITORING SYSTEM&lt;br /&gt;
&lt;br /&gt;
groupadd nagios&lt;br /&gt;
useradd -g nagios -d /usr/local/nagios -m nagios&lt;br /&gt;
echo &amp;quot;nrpe             5666/tcp  # Nagios NRPE&amp;quot; &amp;gt;&amp;gt; /etc/services&lt;br /&gt;
&lt;br /&gt;
cd /tmp&lt;br /&gt;
wget http://superb-east.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.10.tar.gz&lt;br /&gt;
tar zxvf nagios-plugins-*.tar.gz ; cd nagios-plugins-*&lt;br /&gt;
./configure &amp;amp;&amp;amp; make all &amp;amp;&amp;amp; make install&lt;br /&gt;
cd /tmp&lt;br /&gt;
wget http://umn.dl.sourceforge.net/sourceforge/nagios/nrpe-2.10.tar.gz&lt;br /&gt;
tar zxvf nrpe-2.10.tar.gz ; cd nrpe-2.10&lt;br /&gt;
./configure &amp;amp;&amp;amp; make &amp;amp;&amp;amp; cp src/nrpe /usr/local/nagios/nrpe&lt;br /&gt;
&lt;br /&gt;
for plugin in \&lt;br /&gt;
   check_wave check_users check_ups check_time check_tcp check_swap check_ssh check_ssmtp \&lt;br /&gt;
   check_spop check_simap check_smtp check_sensors check_rpc check_real check_pop check_ping \&lt;br /&gt;
   check_overcr check_oracle check_nwstat check_nt check_nntps check_nntp check_nagios \&lt;br /&gt;
   check_mysql_query check_mrtgtraf check_mrtg check_log check_jabber check_ircd \&lt;br /&gt;
   check_imap check_ifstatus check_ifoperstatus check_icmp check_http check_ftp check_flexlm \&lt;br /&gt;
   check_file_age check_dummy check_disk_smb check_dig check_dhcp check_clamd check_by_ssh \&lt;br /&gt;
   check_breeze check_apt check_udp&lt;br /&gt;
do rm -f /usr/local/nagios/libexec/$plugin ; done&lt;br /&gt;
&lt;br /&gt;
cat &amp;gt; /usr/local/nagios/nrpe.cfg &amp;lt;&amp;lt;EOF&lt;br /&gt;
# NRPE Config File&lt;br /&gt;
pid_file=/var/run/nrpe.pid&lt;br /&gt;
debug=0&lt;br /&gt;
command_timeout=60&lt;br /&gt;
connection_timeout=300&lt;br /&gt;
&lt;br /&gt;
# And now the list of allowed check-commands:&lt;br /&gt;
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -m /&lt;br /&gt;
command[check_dns]=/usr/local/nagios/libexec/check_dns www.google.com&lt;br /&gt;
command[check_load]=/usr/local/nagios/libexec/check_load -w 5,5,5 -c 8,8,8&lt;br /&gt;
command[check_mailq]=/usr/local/nagios/libexec/check_mailq -w 10 -c 20&lt;br /&gt;
command[check_mysql]=/usr/local/nagios/libexec/check_mysql -d gisdata -H localhost -u gisdata -p password&lt;br /&gt;
command[check_pgsql]=/usr/local/nagios/libexec/check_pgsql -d gisdata -H localhost -l gisdata -p password&lt;br /&gt;
command[check_ntp]=/usr/local/nagios/libexec/check_ntp -H pool.ntp.org&lt;br /&gt;
command[check_crond]=/usr/local/nagios/libexec/check_procs -u root -c 1: --command=crond&lt;br /&gt;
command[check_syslogd]=/usr/local/nagios/libexec/check_procs -u root -c 1:1 --command=syslogd&lt;br /&gt;
command[check_xinetd]=/usr/local/nagios/libexec/check_procs -u root -c 1:1 --command=xinetd&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
cat &amp;gt; /etc/xinetd.d/nrpe &amp;lt;&amp;lt;EOF&lt;br /&gt;
# description: NRPE for Nagios&lt;br /&gt;
service nrpe&lt;br /&gt;
{&lt;br /&gt;
   socket_type     = stream&lt;br /&gt;
   protocol        = tcp&lt;br /&gt;
   wait            = no&lt;br /&gt;
   user            = nagios&lt;br /&gt;
   server          = /usr/local/nagios/nrpe&lt;br /&gt;
   server_args     = -c /usr/local/nagios/nrpe.cfg --inetd&lt;br /&gt;
   only_from       = __HOSTIP__&lt;br /&gt;
}&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R nagios:nagios /usr/local/nagios&lt;br /&gt;
chmod -R o-rwx /usr/local/nagios&lt;br /&gt;
chmod go-rwx /etc/xinetd.d&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** OTHER UNNECESSARY STUFF&lt;br /&gt;
&lt;br /&gt;
# kernel, kernel modules, documentation, mount points&lt;br /&gt;
rm -rf /lib/modules /boot /dev/.udev /usr/doc /usr/info /media&lt;br /&gt;
&lt;br /&gt;
# packages not applicable to a VPS setting, or which we don't use at HostGIS&lt;br /&gt;
# e.g. phpMyAdmin and phpPgAdmin are security holes&lt;br /&gt;
cd /var/log/packages&lt;br /&gt;
for pkg in \&lt;br /&gt;
   hotplug-* hdparm-* devmapper-* udev-* usbutils-* pciutils-* module-init-tools-* \&lt;br /&gt;
   mdadm-* floppy-* lvm2-* phpMyAdmin-* phppgAdmin-* raidtools-* reiserfsprogs-* \&lt;br /&gt;
   smartmontools-* sysfsutils-* syslinux-* wireless_tools.* quota-* iptables-*&lt;br /&gt;
do removepkg $pkg ; done&lt;br /&gt;
&lt;br /&gt;
# most folks don't use GeoServer, so disable it by default&lt;br /&gt;
chmod 644 /etc/rc.d/rc.geoserver&lt;br /&gt;
&lt;br /&gt;
# prune init's getty&lt;br /&gt;
vi  /etc/inittab # delete everything after entry l6 (runlevel 6)&lt;br /&gt;
init q&lt;br /&gt;
&lt;br /&gt;
# clean out the fstab and mtab files&lt;br /&gt;
( cd /etc ; rm -f fstab mtab ; ln -s ../proc/mounts mtab )&lt;br /&gt;
echo &amp;quot;proc     /proc      proc     defaults    0  0&amp;quot; &amp;gt;&amp;gt; /etc/fstab&lt;br /&gt;
echo &amp;quot;devpts   /dev/pts   devpts   mode=0620   0  0&amp;quot; &amp;gt;&amp;gt; /etc/fstab&lt;br /&gt;
&lt;br /&gt;
# the startup sequence and services, even the firewall&lt;br /&gt;
cd /etc/rc.d&lt;br /&gt;
rm -f rc.gpm-sample rc.hotplug rc.ip_forward rc.modules rc.scanluns  rc.serial rc.udev rc.sysvinit rc.firewall&lt;br /&gt;
vi rc.syslog    # delete all mentions of klogd&lt;br /&gt;
vi rc.local     # delete smartd and inetd&lt;br /&gt;
vi rc.M         # delete the setterm entry&lt;br /&gt;
vi rc.S         # delete the MOTD clobbering&lt;br /&gt;
&lt;br /&gt;
# blow away the network configuration with dummy strings for later replacement&lt;br /&gt;
#    replace the IP address with __IPADDRESS_&lt;br /&gt;
#    replace the netmask with __NETMASK__&lt;br /&gt;
#    replace the GATEWAY with __GATEWAY__&lt;br /&gt;
vi /etc/rc.d/rc.inet1.conf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** BASIC FILE SECURITY SETTINGS&lt;br /&gt;
&lt;br /&gt;
# clear out old/dummy SSL certificates&lt;br /&gt;
mv /etc/ssl/openssl.cnf /tmp ; rm -r /etc/ssl/* ; mv /tmp/openssl.cnf /etc/ssl&lt;br /&gt;
&lt;br /&gt;
# fix file permissions&lt;br /&gt;
find / -mount -nouser -exec chown root {} \; &amp;amp;&lt;br /&gt;
find / -mount -nogroup -exec chgrp root {} \; &amp;amp;&lt;br /&gt;
for i in \&lt;br /&gt;
   /bin/ping /bin/mount /bin/ping6 /bin/umount /usr/bin/chfn \&lt;br /&gt;
   /usr/bin/chsh /usr/bin/crontab /usr/bin/chage /usr/bin/traceroute6 /usr/bin/traceroute \&lt;br /&gt;
   /usr/bin/expiry /usr/bin/newgrp /usr/bin/passwd /usr/bin/gpasswd \&lt;br /&gt;
   /usr/libexec/ssh-keysign /usr/libexec/pt_chown /usr/bin/wall /usr/bin/write&lt;br /&gt;
   do chmod u-s $i ; done&lt;br /&gt;
&lt;br /&gt;
# fix Apache's configuration:&lt;br /&gt;
# add ServerTokens prod&lt;br /&gt;
# go to the htdocs Directory definition and change Indexes to -Indexes&lt;br /&gt;
# delete the entries for phpmyadmin and phppgadmin&lt;br /&gt;
vi /etc/apache/httpd.conf&lt;br /&gt;
&lt;br /&gt;
# keep FTP users chrooted:&lt;br /&gt;
echo &amp;quot;&amp;quot; &amp;gt;&amp;gt; /etc/proftpd.conf&lt;br /&gt;
echo &amp;quot;# keep all users chrooted to their homedir&amp;quot; &amp;gt;&amp;gt; /etc/proftpd.conf&lt;br /&gt;
echo &amp;quot;DefaultRoot ~&amp;quot; &amp;gt;&amp;gt; /etc/proftpd.conf&lt;br /&gt;
&lt;br /&gt;
# allow the mailq to be checked by anybody:&lt;br /&gt;
chgrp smmsp /var/spool/mqueue&lt;br /&gt;
chmod g+rx /var/spool/mqueue&lt;br /&gt;
&lt;br /&gt;
# disable the root and user accounts&lt;br /&gt;
# by changing the password for root and user to a ! character.&lt;br /&gt;
vi /etc/shadow&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** REBOOTING&lt;br /&gt;
&lt;br /&gt;
A VPS cannot actually reboot, since there's no power switch to power-cycle the machine&lt;br /&gt;
after the VE has been shut down. OpenVZ emulates this effect with an external cronjob&lt;br /&gt;
called vpsreboot (see /etc/cron.d/vz). In order to reboot a VPS that has been shut down&lt;br /&gt;
and which is expecting a reboot, the shutdown sequence must create a file named /reboot&lt;br /&gt;
in the VPS's filesystem.&lt;br /&gt;
&lt;br /&gt;
Also, the /etc/mtab file should point to /proc/mounts so it can detect the / filesystem.&lt;br /&gt;
&lt;br /&gt;
vi /etc/rc.d/rc.6&lt;br /&gt;
And add these two lines near the start:&lt;br /&gt;
# create the reboot flag so we get rebooted automatically&lt;br /&gt;
touch /reboot&lt;br /&gt;
&lt;br /&gt;
vi /etc/rc.d/rc.M&lt;br /&gt;
And add these two lines near the start:&lt;br /&gt;
# replace the mtab file with a link to /proc/mounts so OpenVZ can find the / filesystem&lt;br /&gt;
rm -f /etc/mtab ;  ln -s /proc/mounts /etc/mtab&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** DELETING AND BLANKING SETTINGS&lt;br /&gt;
&lt;br /&gt;
Lastly, you'll want to delete or blank out a bunch of files so they start fresh&lt;br /&gt;
when the VE is booted for its first time.&lt;br /&gt;
&lt;br /&gt;
# stop all services&lt;br /&gt;
apachectl stop&lt;br /&gt;
killall syslogd klogd udevd crond&lt;br /&gt;
/etc/rc.d/rc.sendmail stop&lt;br /&gt;
/etc/webmin/stop&lt;br /&gt;
/etc/rc.d/rc.pgsql stop&lt;br /&gt;
/etc/rc.d/rc.mysqld stop&lt;br /&gt;
killall named proftpd&lt;br /&gt;
killall xinetd&lt;br /&gt;
&lt;br /&gt;
# refresh the 'locate' cache&lt;br /&gt;
/etc/cron.daily/slocate&lt;br /&gt;
&lt;br /&gt;
# blank out the system logfiles&lt;br /&gt;
for logfile in \&lt;br /&gt;
    /var/log/messages /var/log/syslog /var/log/debug /var/log/secure \&lt;br /&gt;
    /var/log/maillog /var/log/spooler /var/log/proftpd.log /var/log/xinetd.log \&lt;br /&gt;
    /var/log/dmesg /var/log/faillog /var/log/lastlog /var/log/wtmp \&lt;br /&gt;
    /var/log/apache/access_log /var/log/apache/error_log \&lt;br /&gt;
    /var/log/webmin/miniserv.error /var/log/webmin/miniserv.pid&lt;br /&gt;
do cp /dev/null $logfile ; done&lt;br /&gt;
rmdir /var/log/sa&lt;br /&gt;
&lt;br /&gt;
# clear the SSH host key&lt;br /&gt;
rm -f /etc/ssh/ssh_host_*&lt;br /&gt;
&lt;br /&gt;
# database server logfiles&lt;br /&gt;
rm -f /var/lib/mysql/*.err /var/lib/pgsql/logfile&lt;br /&gt;
&lt;br /&gt;
# delete vi backup files, bash_history files, and other small application crud&lt;br /&gt;
unset HISTFILE&lt;br /&gt;
find / -name '*~' \&lt;br /&gt;
    -o -name .bash_history \&lt;br /&gt;
    -o -name .gnupg \&lt;br /&gt;
    -o -name .lesshst \&lt;br /&gt;
    -o -name .viminfo \&lt;br /&gt;
    -o -name .rnd \&lt;br /&gt;
    -delete&lt;br /&gt;
&lt;br /&gt;
# the junk under /tmp&lt;br /&gt;
rm -rf /tmp/*&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** CREATING THE VE CACHE IMAGE&lt;br /&gt;
&lt;br /&gt;
A VE cache is just a tar.gz file of the entire filesystem. So creating them is simple!&lt;br /&gt;
&lt;br /&gt;
tar zcvf /tmp/HostGIS_Linux_4.2_64bit.tar.gz --exclude='/sys/*' --exclude='/proc/*' --exclude='/tmp/*' /&lt;br /&gt;
&lt;br /&gt;
Ta-da! That's your new VE template cache. Just SFTP it to the VE server and you're all set!&lt;/div&gt;</summary>
		<author><name>HostGIS</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Creating_a_template_cache_:_Slackware_or_HostGIS_Linux&amp;diff=3679</id>
		<title>Creating a template cache : Slackware or HostGIS Linux</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Creating_a_template_cache_:_Slackware_or_HostGIS_Linux&amp;diff=3679"/>
		<updated>2007-11-30T16:27:17Z</updated>

		<summary type="html">&lt;p&gt;HostGIS: very raw initial version&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Creating a new &amp;quot;Host Template Cache&amp;quot; for HostGIS Linux&lt;br /&gt;
&lt;br /&gt;
This document describes how to use VMWare to create a new VM,&lt;br /&gt;
install HostGIS Linux (HGL) on it and tweak the system into shape,&lt;br /&gt;
and then create a Host Template Cache (a compressed VE image) for&lt;br /&gt;
use in OpenVZ.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** CREATING THE VM&lt;br /&gt;
&lt;br /&gt;
Start by creating a new VM in VMWare. The stats can be minimal, and there&lt;br /&gt;
is no need to create the entire disk at once during the setup.&lt;br /&gt;
   * Create the disk as SCSI.&lt;br /&gt;
&lt;br /&gt;
Then install HGL.&lt;br /&gt;
  * Create a small partition at the end of the disk for swap. Some swap&lt;br /&gt;
    is technically necessary, but since you'll never in fact be using it,&lt;br /&gt;
    a few MB should be fine.&lt;br /&gt;
  * Set the passwords to 'password'&lt;br /&gt;
  * Do set the timezone properly. The internal clock does not use UTC/GMT.&lt;br /&gt;
  * Select the default mouse, but do NOT enable GPM at startup.&lt;br /&gt;
  * Hostname:  template   Domain: internal.lan&lt;br /&gt;
  * IP config:  as appropriate for your LAN&lt;br /&gt;
  * Nameserver: no&lt;br /&gt;
Reboot into your new HGL install.&lt;br /&gt;
&lt;br /&gt;
Now we want to tweak it into a usable template.&lt;br /&gt;
Go ahead and login to the VM.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** UPGRADES AND SECURITY PATCHES&lt;br /&gt;
&lt;br /&gt;
The default HGL you used may require some software to be reinstalled, since new versions&lt;br /&gt;
and critical bugfixes may have been released since that version of HGL was released.&lt;br /&gt;
Follow these instructions, and also update them as necessary for the appropriate versions&lt;br /&gt;
and to remove paragraphs when a revision of HGL comes out that no longer requires them.&lt;br /&gt;
&lt;br /&gt;
# HGL 4.2 - no necessary upgrades as of Nov 29 2007&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** REPLACE INETD WITH XINETD&lt;br /&gt;
&lt;br /&gt;
Inetd is good but minimal. Xinetd offers security features, such as restricting service &lt;br /&gt;
to only certain IPs, and only listening on certain interfaces,.&lt;br /&gt;
&lt;br /&gt;
removepkg inetd&lt;br /&gt;
rm -f /etc/inetd.conf* /etc/rc.d/rc.inetd&lt;br /&gt;
&lt;br /&gt;
cd /tmp&lt;br /&gt;
wget --header=&amp;quot;Host: xinetd.org&amp;quot; http://204.152.188.37/xinetd-2.3.14.tar.gz&lt;br /&gt;
tar zxvf xinetd*.gz&lt;br /&gt;
cd xinetd*&lt;br /&gt;
./configure --prefix=/usr --sysconfdir=/etc&lt;br /&gt;
make &amp;amp;&amp;amp; make install&lt;br /&gt;
mkdir /etc/xinetd.d&lt;br /&gt;
cat &amp;gt;&amp;gt; /etc/rc.d/rc.local &amp;lt;&amp;lt;EOF&lt;br /&gt;
&lt;br /&gt;
# xinetd&lt;br /&gt;
/usr/sbin/xinetd&lt;br /&gt;
EOF&lt;br /&gt;
cat &amp;gt; /etc/xinetd.conf &amp;lt;&amp;lt;EOF&lt;br /&gt;
defaults&lt;br /&gt;
{&lt;br /&gt;
        log_type        = SYSLOG daemon notice&lt;br /&gt;
        log_on_success  = HOST EXIT DURATION&lt;br /&gt;
        log_on_failure  = HOST ATTEMPT&lt;br /&gt;
        instances       = 30&lt;br /&gt;
        cps             = 50 10&lt;br /&gt;
}&lt;br /&gt;
includedir /etc/xinetd.d&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** NAGIOS: THE HEALTH-MONITORING SYSTEM&lt;br /&gt;
&lt;br /&gt;
groupadd nagios&lt;br /&gt;
useradd -g nagios -d /usr/local/nagios -m nagios&lt;br /&gt;
echo &amp;quot;nrpe             5666/tcp  # Nagios NRPE&amp;quot; &amp;gt;&amp;gt; /etc/services&lt;br /&gt;
&lt;br /&gt;
cd /tmp&lt;br /&gt;
wget http://superb-east.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.10.tar.gz&lt;br /&gt;
tar zxvf nagios-plugins-*.tar.gz ; cd nagios-plugins-*&lt;br /&gt;
./configure &amp;amp;&amp;amp; make all &amp;amp;&amp;amp; make install&lt;br /&gt;
cd /tmp&lt;br /&gt;
wget http://umn.dl.sourceforge.net/sourceforge/nagios/nrpe-2.10.tar.gz&lt;br /&gt;
tar zxvf nrpe-2.10.tar.gz ; cd nrpe-2.10&lt;br /&gt;
./configure &amp;amp;&amp;amp; make &amp;amp;&amp;amp; cp src/nrpe /usr/local/nagios/nrpe&lt;br /&gt;
&lt;br /&gt;
for plugin in \&lt;br /&gt;
   check_wave check_users check_ups check_time check_tcp check_swap check_ssh check_ssmtp \&lt;br /&gt;
   check_spop check_simap check_smtp check_sensors check_rpc check_real check_pop check_ping \&lt;br /&gt;
   check_overcr check_oracle check_nwstat check_nt check_nntps check_nntp check_nagios \&lt;br /&gt;
   check_mysql_query check_mrtgtraf check_mrtg check_log check_jabber check_ircd \&lt;br /&gt;
   check_imap check_ifstatus check_ifoperstatus check_icmp check_http check_ftp check_flexlm \&lt;br /&gt;
   check_file_age check_dummy check_disk_smb check_dig check_dhcp check_clamd check_by_ssh \&lt;br /&gt;
   check_breeze check_apt check_udp&lt;br /&gt;
do rm -f /usr/local/nagios/libexec/$plugin ; done&lt;br /&gt;
&lt;br /&gt;
cat &amp;gt; /usr/local/nagios/nrpe.cfg &amp;lt;&amp;lt;EOF&lt;br /&gt;
# NRPE Config File&lt;br /&gt;
pid_file=/var/run/nrpe.pid&lt;br /&gt;
debug=0&lt;br /&gt;
command_timeout=60&lt;br /&gt;
connection_timeout=300&lt;br /&gt;
&lt;br /&gt;
# And now the list of allowed check-commands:&lt;br /&gt;
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -m /&lt;br /&gt;
command[check_dns]=/usr/local/nagios/libexec/check_dns www.google.com&lt;br /&gt;
command[check_load]=/usr/local/nagios/libexec/check_load -w 5,5,5 -c 8,8,8&lt;br /&gt;
command[check_mailq]=/usr/local/nagios/libexec/check_mailq -w 10 -c 20&lt;br /&gt;
command[check_mysql]=/usr/local/nagios/libexec/check_mysql -d gisdata -H localhost -u gisdata -p password&lt;br /&gt;
command[check_pgsql]=/usr/local/nagios/libexec/check_pgsql -d gisdata -H localhost -l gisdata -p password&lt;br /&gt;
command[check_ntp]=/usr/local/nagios/libexec/check_ntp -H pool.ntp.org&lt;br /&gt;
command[check_crond]=/usr/local/nagios/libexec/check_procs -u root -c 1: --command=crond&lt;br /&gt;
command[check_syslogd]=/usr/local/nagios/libexec/check_procs -u root -c 1:1 --command=syslogd&lt;br /&gt;
command[check_xinetd]=/usr/local/nagios/libexec/check_procs -u root -c 1:1 --command=xinetd&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
cat &amp;gt; /etc/xinetd.d/nrpe &amp;lt;&amp;lt;EOF&lt;br /&gt;
# description: NRPE for Nagios&lt;br /&gt;
service nrpe&lt;br /&gt;
{&lt;br /&gt;
   socket_type     = stream&lt;br /&gt;
   protocol        = tcp&lt;br /&gt;
   wait            = no&lt;br /&gt;
   user            = nagios&lt;br /&gt;
   server          = /usr/local/nagios/nrpe&lt;br /&gt;
   server_args     = -c /usr/local/nagios/nrpe.cfg --inetd&lt;br /&gt;
   only_from       = __HOSTIP__&lt;br /&gt;
}&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
chown -R nagios:nagios /usr/local/nagios&lt;br /&gt;
chmod -R o-rwx /usr/local/nagios&lt;br /&gt;
chmod go-rwx /etc/xinetd.d&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** OTHER UNNECESSARY STUFF&lt;br /&gt;
&lt;br /&gt;
# kernel, kernel modules, documentation, mount points&lt;br /&gt;
rm -rf /lib/modules /boot /dev/.udev /usr/doc /usr/info /media&lt;br /&gt;
&lt;br /&gt;
# packages not applicable to a VPS setting, or which we don't use at HostGIS&lt;br /&gt;
# e.g. phpMyAdmin and phpPgAdmin are security holes&lt;br /&gt;
cd /var/log/packages&lt;br /&gt;
for pkg in \&lt;br /&gt;
   hotplug-* hdparm-* devmapper-* udev-* usbutils-* pciutils-* module-init-tools-* \&lt;br /&gt;
   mdadm-* floppy-* lvm2-* phpMyAdmin-* phppgAdmin-* raidtools-* reiserfsprogs-* \&lt;br /&gt;
   smartmontools-* sysfsutils-* syslinux-* wireless_tools.* quota-* iptables-*&lt;br /&gt;
do removepkg $pkg ; done&lt;br /&gt;
&lt;br /&gt;
# most folks don't use GeoServer, so disable it by default&lt;br /&gt;
chmod 644 /etc/rc.d/rc.geoserver&lt;br /&gt;
&lt;br /&gt;
# prune init's getty&lt;br /&gt;
vi  /etc/inittab # delete everything after entry l6 (runlevel 6)&lt;br /&gt;
init q&lt;br /&gt;
&lt;br /&gt;
# clean out the fstab and mtab files&lt;br /&gt;
( cd /etc ; rm -f fstab mtab ; ln -s ../proc/mounts mtab )&lt;br /&gt;
echo &amp;quot;proc     /proc      proc     defaults    0  0&amp;quot; &amp;gt;&amp;gt; /etc/fstab&lt;br /&gt;
echo &amp;quot;devpts   /dev/pts   devpts   mode=0620   0  0&amp;quot; &amp;gt;&amp;gt; /etc/fstab&lt;br /&gt;
&lt;br /&gt;
# the startup sequence and services, even the firewall&lt;br /&gt;
cd /etc/rc.d&lt;br /&gt;
rm -f rc.gpm-sample rc.hotplug rc.ip_forward rc.modules rc.scanluns  rc.serial rc.udev rc.sysvinit rc.firewall&lt;br /&gt;
vi rc.syslog    # delete all mentions of klogd&lt;br /&gt;
vi rc.local     # delete smartd and inetd&lt;br /&gt;
vi rc.M         # delete the setterm entry&lt;br /&gt;
vi rc.S         # delete the MOTD clobbering&lt;br /&gt;
&lt;br /&gt;
# blow away the network configuration with dummy strings for later replacement&lt;br /&gt;
#    replace the IP address with __IPADDRESS_&lt;br /&gt;
#    replace the netmask with __NETMASK__&lt;br /&gt;
#    replace the GATEWAY with __GATEWAY__&lt;br /&gt;
vi /etc/rc.d/rc.inet1.conf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** BASIC FILE SECURITY SETTINGS&lt;br /&gt;
&lt;br /&gt;
# clear out old/dummy SSL certificates&lt;br /&gt;
mv /etc/ssl/openssl.cnf /tmp ; rm -r /etc/ssl/* ; mv /tmp/openssl.cnf /etc/ssl&lt;br /&gt;
&lt;br /&gt;
# fix file permissions&lt;br /&gt;
find / -mount -nouser -exec chown root {} \; &amp;amp;&lt;br /&gt;
find / -mount -nogroup -exec chgrp root {} \; &amp;amp;&lt;br /&gt;
for i in \&lt;br /&gt;
   /bin/ping /bin/mount /bin/ping6 /bin/umount /usr/bin/chfn \&lt;br /&gt;
   /usr/bin/chsh /usr/bin/crontab /usr/bin/chage /usr/bin/traceroute6 /usr/bin/traceroute \&lt;br /&gt;
   /usr/bin/expiry /usr/bin/newgrp /usr/bin/passwd /usr/bin/gpasswd \&lt;br /&gt;
   /usr/libexec/ssh-keysign /usr/libexec/pt_chown /usr/bin/wall /usr/bin/write&lt;br /&gt;
   do chmod u-s $i ; done&lt;br /&gt;
&lt;br /&gt;
# fix Apache's configuration:&lt;br /&gt;
# add ServerTokens prod&lt;br /&gt;
# go to the htdocs Directory definition and change Indexes to -Indexes&lt;br /&gt;
# delete the entries for phpmyadmin and phppgadmin&lt;br /&gt;
vi /etc/apache/httpd.conf&lt;br /&gt;
&lt;br /&gt;
# keep FTP users chrooted:&lt;br /&gt;
echo &amp;quot;&amp;quot; &amp;gt;&amp;gt; /etc/proftpd.conf&lt;br /&gt;
echo &amp;quot;# keep all users chrooted to their homedir&amp;quot; &amp;gt;&amp;gt; /etc/proftpd.conf&lt;br /&gt;
echo &amp;quot;DefaultRoot ~&amp;quot; &amp;gt;&amp;gt; /etc/proftpd.conf&lt;br /&gt;
&lt;br /&gt;
# allow the mailq to be checked by anybody:&lt;br /&gt;
chgrp smmsp /var/spool/mqueue&lt;br /&gt;
chmod g+rx /var/spool/mqueue&lt;br /&gt;
&lt;br /&gt;
# disable the root and user accounts&lt;br /&gt;
# by changing the password for root and user to a ! character.&lt;br /&gt;
vi /etc/shadow&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** REBOOTING&lt;br /&gt;
&lt;br /&gt;
A VPS cannot actually reboot, since there's no power switch to power-cycle the machine&lt;br /&gt;
after the VE has been shut down. OpenVZ emulates this effect with an external cronjob&lt;br /&gt;
called vpsreboot (see /etc/cron.d/vz). In order to reboot a VPS that has been shut down&lt;br /&gt;
and which is expecting a reboot, the shutdown sequence must create a file named /reboot&lt;br /&gt;
in the VPS's filesystem.&lt;br /&gt;
&lt;br /&gt;
Also, the /etc/mtab file should point to /proc/mounts so it can detect the / filesystem.&lt;br /&gt;
&lt;br /&gt;
vi /etc/rc.d/rc.6&lt;br /&gt;
And add these two lines near the start:&lt;br /&gt;
# create the reboot flag so we get rebooted automatically&lt;br /&gt;
touch /reboot&lt;br /&gt;
&lt;br /&gt;
vi /etc/rc.d/rc.M&lt;br /&gt;
And add these two lines near the start:&lt;br /&gt;
# replace the mtab file with a link to /proc/mounts so OpenVZ can find the / filesystem&lt;br /&gt;
rm -f /etc/mtab ;  ln -s /proc/mounts /etc/mtab&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** DELETING AND BLANKING SETTINGS&lt;br /&gt;
&lt;br /&gt;
Lastly, you'll want to delete or blank out a bunch of files so they start fresh&lt;br /&gt;
when the VE is booted for its first time.&lt;br /&gt;
&lt;br /&gt;
# stop all services&lt;br /&gt;
apachectl stop&lt;br /&gt;
killall syslogd klogd udevd crond&lt;br /&gt;
/etc/rc.d/rc.sendmail stop&lt;br /&gt;
/etc/webmin/stop&lt;br /&gt;
/etc/rc.d/rc.pgsql stop&lt;br /&gt;
/etc/rc.d/rc.mysqld stop&lt;br /&gt;
killall named proftpd&lt;br /&gt;
killall xinetd&lt;br /&gt;
&lt;br /&gt;
# refresh the 'locate' cache&lt;br /&gt;
/etc/cron.daily/slocate&lt;br /&gt;
&lt;br /&gt;
# blank out the system logfiles&lt;br /&gt;
for logfile in \&lt;br /&gt;
    /var/log/messages /var/log/syslog /var/log/debug /var/log/secure \&lt;br /&gt;
    /var/log/maillog /var/log/spooler /var/log/proftpd.log /var/log/xinetd.log \&lt;br /&gt;
    /var/log/dmesg /var/log/faillog /var/log/lastlog /var/log/wtmp \&lt;br /&gt;
    /var/log/apache/access_log /var/log/apache/error_log \&lt;br /&gt;
    /var/log/webmin/miniserv.error /var/log/webmin/miniserv.pid&lt;br /&gt;
do cp /dev/null $logfile ; done&lt;br /&gt;
rmdir /var/log/sa&lt;br /&gt;
&lt;br /&gt;
# clear the SSH host key&lt;br /&gt;
rm -f /etc/ssh/ssh_host_*&lt;br /&gt;
&lt;br /&gt;
# database server logfiles&lt;br /&gt;
rm -f /var/lib/mysql/*.err /var/lib/pgsql/logfile&lt;br /&gt;
&lt;br /&gt;
# delete vi backup files, bash_history files, and other small application crud&lt;br /&gt;
unset HISTFILE&lt;br /&gt;
find / -name '*~' \&lt;br /&gt;
    -o -name .bash_history \&lt;br /&gt;
    -o -name .gnupg \&lt;br /&gt;
    -o -name .lesshst \&lt;br /&gt;
    -o -name .viminfo \&lt;br /&gt;
    -o -name .rnd \&lt;br /&gt;
    -delete&lt;br /&gt;
&lt;br /&gt;
# the junk under /tmp&lt;br /&gt;
rm -rf /tmp/*&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
***** CREATING THE VE CACHE IMAGE&lt;br /&gt;
&lt;br /&gt;
A VE cache is just a tar.gz file of the entire filesystem. So creating them is simple!&lt;br /&gt;
&lt;br /&gt;
tar zcvf /tmp/HostGIS_Linux_4.2_64bit.tar.gz --exclude='/sys/*' --exclude='/proc/*' --exclude='/tmp/*' /&lt;br /&gt;
&lt;br /&gt;
Ta-da! That's your new VE template cache. Just SFTP it to the VE server and you're all set!&lt;/div&gt;</summary>
		<author><name>HostGIS</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Setting_up_an_iptables_firewall&amp;diff=3103</id>
		<title>Setting up an iptables firewall</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Setting_up_an_iptables_firewall&amp;diff=3103"/>
		<updated>2007-05-16T17:12:39Z</updated>

		<summary type="html">&lt;p&gt;HostGIS: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This document consists of two parts. The first is setting up a firewall (using iptables) on the HN, which will restrict traffic to the VEs. The effect would emulate, as far as the VEs and their customers are concerned, an external hardware firewall controlled by the sysadmin. The second is setting up a firewall that protects the HN itself but still allows traffic to the VEs, thus allowing individual VEs to define their own iptables.&lt;br /&gt;
&lt;br /&gt;
While the firewalls shown here can be accomplished using iptables manually (or using Fedora core's iptables service), the methods presented here are especially modular and easy to modify. This is important when you have 20+ VEs and a lot of other things to be doing...&lt;br /&gt;
&lt;br /&gt;
The scripts and pathnames given here are for Fedora Core 6, though they can probably be applied to most similar SysV-like systems with little modification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A little background ==&lt;br /&gt;
&lt;br /&gt;
On our systems, we use the HN to provide privileged services which are not appropriate for access by the VEs. For example, the HN acts as a backup server, runs Nagios for health monitoring, has a webserver for managing the 3ware RAID controller, etc. The VEs are leased to customers, who can't entirely be trusted, especially if they get hacked. As such, our scenario is one in which the HN must be protected from all access (even from the VEs) except for a few trusted hosts (e.g. my home-office).&lt;br /&gt;
&lt;br /&gt;
The exception to this is the nameserver, which we want open to the world. We use it as a caching nameserver for our VEs and also to host DNS for a few customer domain.&lt;br /&gt;
&lt;br /&gt;
== Setting up a HN-based firewall ==&lt;br /&gt;
&lt;br /&gt;
This setup emulates (to the VEs anyway) an external hardware firewall. It protects the HN from any access and then defines what services and ports are allowed/banned for individual VEs. This leaves the firewall controlled by the site administrator, not be individual VEs and the hackers who've gotten into them. ;)&lt;br /&gt;
&lt;br /&gt;
First off, let's disable Fedora's existing &amp;lt;code&amp;gt;iptables&amp;lt;/code&amp;gt; service:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
service iptables off&lt;br /&gt;
chkconfig iptables off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now create the new &amp;lt;code&amp;gt;firewall&amp;lt;/code&amp;gt; service. This code should be &amp;lt;code&amp;gt;/etc/init.d/firewall&amp;lt;/code&amp;gt; and then should be chmod'd 755.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
# firewall      Start iptables firewall&lt;br /&gt;
# chkconfig: 2345 08 92&lt;br /&gt;
# description:  Starts, stops and saves iptables firewall&lt;br /&gt;
# This script sets up the firewall for the INPUT chain (which is for the HN itself)&lt;br /&gt;
# and then processes the config files under /etc/firewall.d to set up additional rules&lt;br /&gt;
# in the FORWARD chain to allow access to VEs' services.&lt;br /&gt;
&lt;br /&gt;
. /etc/init.d/functions&lt;br /&gt;
&lt;br /&gt;
# the IP block allocated to this server&lt;br /&gt;
SEGMENT=&amp;quot;192.168.0.0/24&amp;quot;&lt;br /&gt;
# the IP used by the hosting server itself&lt;br /&gt;
THISHOST=&amp;quot;192.168.0.1&amp;quot;&lt;br /&gt;
# services that should be allowed to the HN; services for VEs are configured in /etc/firewall.d/*&lt;br /&gt;
OKPORTS=&amp;quot;53&amp;quot;&lt;br /&gt;
# hosts allowed full access through the firewall, to all VEs and to this server&lt;br /&gt;
DMZS=&amp;quot;12.34.56.78 90.123.45.67&amp;quot;&lt;br /&gt;
&lt;br /&gt;
purge() {&lt;br /&gt;
  echo -n &amp;quot;Firewall: Purging and allowing all traffic&amp;quot;&lt;br /&gt;
  iptables -P OUTPUT ACCEPT&lt;br /&gt;
  iptables -P FORWARD ACCEPT&lt;br /&gt;
  iptables -P INPUT ACCEPT&lt;br /&gt;
  iptables -F&lt;br /&gt;
  success ; echo&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
setup() {&lt;br /&gt;
  echo -n &amp;quot;Firewall: Setting default policies to DROP&amp;quot;&lt;br /&gt;
  iptables -P INPUT DROP&lt;br /&gt;
  iptables -P FORWARD DROP&lt;br /&gt;
  iptables -I INPUT   -j ACCEPT -m state --state ESTABLISHED,RELATED&lt;br /&gt;
  iptables -I FORWARD -j ACCEPT -m state --state ESTABLISHED,RELATED&lt;br /&gt;
  iptables -I INPUT -j ACCEPT -i lo&lt;br /&gt;
  iptables -I FORWARD -j ACCEPT --source $SEGMENT&lt;br /&gt;
  success ; echo&lt;br /&gt;
&lt;br /&gt;
  echo &amp;quot;Firewall: Allowing access to HN&amp;quot;&lt;br /&gt;
  for port in $OKPORTS ; do&lt;br /&gt;
    echo -n &amp;quot;          port $port&amp;quot;&lt;br /&gt;
    iptables -I INPUT -j ACCEPT -s $SEGMENT -d $THISHOST --protocol tcp --destination-port $port&lt;br /&gt;
    iptables -I INPUT -j ACCEPT -s $SEGMENT -d $THISHOST --protocol udp --destination-port $port&lt;br /&gt;
    success ; echo&lt;br /&gt;
  done&lt;br /&gt;
  for ip in $DMZS ; do&lt;br /&gt;
    echo -n &amp;quot;          DMZ $ip&amp;quot;&lt;br /&gt;
    iptables -I INPUT   -i eth0 -j ACCEPT -s $ip&lt;br /&gt;
    iptables -I FORWARD -i eth0 -j ACCEPT -s $ip&lt;br /&gt;
    success ; echo&lt;br /&gt;
  done&lt;br /&gt;
&lt;br /&gt;
  VESETUPS=`echo /etc/firewall.d/*`&lt;br /&gt;
  if [ &amp;quot;$VESETUPS&amp;quot; != &amp;quot;/etc/firewall.d/*&amp;quot; ] ; then&lt;br /&gt;
  echo &amp;quot;Firewall: Setting up VE firewalls&amp;quot;&lt;br /&gt;
  for i in $VESETUPS ; do&lt;br /&gt;
    . $i&lt;br /&gt;
    echo -n &amp;quot;          $VENAME VE$VEID&amp;quot;&lt;br /&gt;
    if [ -n &amp;quot;$BANNED&amp;quot; ]; then&lt;br /&gt;
      for source in $BANNED ;  do iptables -I FORWARD -j DROP --destination $VEIP --source $source ; done&lt;br /&gt;
    fi&lt;br /&gt;
    if [ -n &amp;quot;$OPENPORTS&amp;quot; ]; then&lt;br /&gt;
      for port in $OPENPORTS ; do iptables -I FORWARD -j ACCEPT --protocol tcp --destination $VEIP --destination-port $port ; done&lt;br /&gt;
      for port in $OPENPORTS ; do iptables -I FORWARD -j ACCEPT --protocol udp --destination $VEIP --destination-port $port ; done&lt;br /&gt;
    fi&lt;br /&gt;
    if [ -n &amp;quot;$DMZS&amp;quot; ]; then&lt;br /&gt;
      for source in $DMZS ; do iptables -I FORWARD -j ACCEPT --protocol tcp --destination $VEIP --source $source ; done&lt;br /&gt;
      for source in $DMZS ; do iptables -I FORWARD -j ACCEPT --protocol udp --destination $VEIP --source $source ; done&lt;br /&gt;
    fi&lt;br /&gt;
    [ $? -eq 0 ] &amp;amp;&amp;amp; success || failure&lt;br /&gt;
    echo&lt;br /&gt;
  done&lt;br /&gt;
  fi&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
case &amp;quot;$1&amp;quot; in&lt;br /&gt;
  start)&lt;br /&gt;
    echo &amp;quot;Starting firewall...&amp;quot;&lt;br /&gt;
    purge&lt;br /&gt;
    setup&lt;br /&gt;
    ;;&lt;br /&gt;
  stop)&lt;br /&gt;
    echo &amp;quot;Stopping firewall...&amp;quot;&lt;br /&gt;
    purge&lt;br /&gt;
    ;;&lt;br /&gt;
  restart)&lt;br /&gt;
    $0 stop&lt;br /&gt;
    $0 start&lt;br /&gt;
    ;;&lt;br /&gt;
  status)&lt;br /&gt;
    iptables -n -L&lt;br /&gt;
    ;;&lt;br /&gt;
  *)&lt;br /&gt;
    echo &amp;quot;Usage: $0 &amp;lt;start|stop|restart|status&amp;gt;&amp;quot;&lt;br /&gt;
    ;;&lt;br /&gt;
esac&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above script can be called like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
service firewall start&lt;br /&gt;
service firewall stop&lt;br /&gt;
service firewall restart&lt;br /&gt;
service firewall status&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It will set up the firewall for the HN according to the parameters you specified for OKPORTS, DMZs, etc. and then it will call each file under /etc/firewall.d and process  its configuration.&lt;br /&gt;
&lt;br /&gt;
So create a file under /etc/firewall.d The exact filename isn't important, as long as it's meaningful to you, e.g. &amp;lt;code&amp;gt;ExampleCompany&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;ve12&amp;lt;/code&amp;gt; and give it content like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This file is processed by /etc/init.d/firewall&lt;br /&gt;
VEID=&amp;quot;1&amp;quot;                      # the VE's ID#&lt;br /&gt;
VENAME=&amp;quot;Customer1&amp;quot;            # A human-friendly label for the VE&lt;br /&gt;
VEIP=&amp;quot;192.168.1.34&amp;quot;           # the IP address for this VE&lt;br /&gt;
OPENPORTS=&amp;quot;80 443&amp;quot;            # ports that should be universally opened to the entire Internet&lt;br /&gt;
DMZS=&amp;quot;1.2.3.0/24 5.6.7.8/32&amp;quot;  # IPs and blocks that should have full access to the VE's services&lt;br /&gt;
BANNED=&amp;quot;&amp;quot;                     # IPs and blocks that should be entirely blocked from the VE's services&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And there you go. Go ahead and start the firewall and check its status:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
service firewall restart&lt;br /&gt;
service firewall status&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, you can now add and edit the configurations for individual VEs very easily. This method proves a lot easier to manage than Fedora's iptables-config mechamism!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Setting up a firewall that allows per-VE configuration ==&lt;br /&gt;
&lt;br /&gt;
This setup configures iptables on the HN to disallow access to all hosts, including the VEs. However, it allows all traffic into the VEs so they may define their own iptables rules and therefore manage their own firewall.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;This content is missing. You are invited to fill it in, if you get to it before I do. :)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[[Traffic accounting with iptables]]&lt;br /&gt;
&lt;br /&gt;
[[ Category: Networking ]]&lt;br /&gt;
[[ Category: Firewalls ]]&lt;/div&gt;</summary>
		<author><name>HostGIS</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Setting_up_an_iptables_firewall&amp;diff=3102</id>
		<title>Setting up an iptables firewall</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Setting_up_an_iptables_firewall&amp;diff=3102"/>
		<updated>2007-05-16T17:11:46Z</updated>

		<summary type="html">&lt;p&gt;HostGIS: /* A little background */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This document consists of two parts. The first is setting up a firewall (using iptables) on the HN, which will restrict traffic to the VEs. The effect would emulate, as far as the VEs and their customers are concerned, an external hardware firewall controlled by the sysadmin. The second is setting up a firewall that protects the HN itself but still allows traffic to the VEs, thus allowing individual VEs to define their own iptables.&lt;br /&gt;
&lt;br /&gt;
While the firewalls shown here can be accomplished using iptables manually (or using Fedora core's iptables service), the methods presented here are especially modular and easy to modify. This is important when you have 20+ VEs and a lot of other things to be doing...&lt;br /&gt;
&lt;br /&gt;
The scripts and pathnames given here are for Fedora Core 6, though they can probably be applied to most similar SysV-like systems with little modification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A little background ==&lt;br /&gt;
&lt;br /&gt;
On our systems, we use the HN to provide privileged services which are not appropriate for access by the VEs. For example, the HN acts as a backup server, runs Nagios for health monitoring, has a webserver for managing the 3ware RAID controller, etc. The VEs are leased to customers, who can't entirely be trusted, especially if they get hacked. As such, our scenario is one in which the HN must be protected from all access (even from the VEs) except for a few trusted hosts (e.g. my home-office).&lt;br /&gt;
&lt;br /&gt;
The exception to this is the nameserver, which we want open to the world. We use it as a caching nameserver for our VEs and also to host DNS for a few customer domain.&lt;br /&gt;
&lt;br /&gt;
== Setting up a HN-based firewall ==&lt;br /&gt;
&lt;br /&gt;
This setup emulates (to the VEs anyway) an external hardware firewall. It protects the HN from any access and then defines what services and ports are allowed/banned for individual VEs. This leaves the firewall controlled by the site administrator, not be individual VEs and the hackers who've gotten into them. ;)&lt;br /&gt;
&lt;br /&gt;
First off, let's disable Fedora's existing &amp;lt;code&amp;gt;iptables&amp;lt;/code&amp;gt; service:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
service iptables off&lt;br /&gt;
chkconfig iptables off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now create the new &amp;lt;code&amp;gt;firewall&amp;lt;/code&amp;gt; service. This code should be &amp;lt;code&amp;gt;/etc/init.d/firewall&amp;lt;/code&amp;gt; and then should be chmod'd 755.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
# firewall      Start iptables firewall&lt;br /&gt;
# chkconfig: 2345 08 92&lt;br /&gt;
# description:  Starts, stops and saves iptables firewall&lt;br /&gt;
# This script sets up the firewall for the INPUT chain (which is for the HN itself)&lt;br /&gt;
# and then processes the config files under /etc/firewall.d to set up additional rules&lt;br /&gt;
# in the FORWARD chain to allow access to VEs' services.&lt;br /&gt;
&lt;br /&gt;
. /etc/init.d/functions&lt;br /&gt;
&lt;br /&gt;
# the IP block allocated to this server&lt;br /&gt;
SEGMENT=&amp;quot;192.168.0.0/24&amp;quot;&lt;br /&gt;
# the IP used by the hosting server itself&lt;br /&gt;
THISHOST=&amp;quot;192.168.0.1&amp;quot;&lt;br /&gt;
# services that should be allowed to the HN; services for VEs are configured in /etc/firewall.d/*&lt;br /&gt;
OKPORTS=&amp;quot;53&amp;quot;&lt;br /&gt;
# hosts allowed full access through the firewall, to all VEs and to this server&lt;br /&gt;
DMZS=&amp;quot;12.34.56.78 90.123.45.67&amp;quot;&lt;br /&gt;
&lt;br /&gt;
purge() {&lt;br /&gt;
  echo -n &amp;quot;Firewall: Purging and allowing all traffic&amp;quot;&lt;br /&gt;
  iptables -P OUTPUT ACCEPT&lt;br /&gt;
  iptables -P FORWARD ACCEPT&lt;br /&gt;
  iptables -P INPUT ACCEPT&lt;br /&gt;
  iptables -F&lt;br /&gt;
  success ; echo&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
setup() {&lt;br /&gt;
  echo -n &amp;quot;Firewall: Setting default policies to DROP&amp;quot;&lt;br /&gt;
  iptables -P INPUT DROP&lt;br /&gt;
  iptables -P FORWARD DROP&lt;br /&gt;
  iptables -I INPUT   -j ACCEPT -m state --state ESTABLISHED,RELATED&lt;br /&gt;
  iptables -I FORWARD -j ACCEPT -m state --state ESTABLISHED,RELATED&lt;br /&gt;
  iptables -I INPUT -j ACCEPT -i lo&lt;br /&gt;
  iptables -I FORWARD -j ACCEPT --source $SEGMENT&lt;br /&gt;
  success ; echo&lt;br /&gt;
&lt;br /&gt;
  echo &amp;quot;Firewall: Allowing access to HN&amp;quot;&lt;br /&gt;
  for port in $OKPORTS ; do&lt;br /&gt;
    echo -n &amp;quot;          port $port&amp;quot;&lt;br /&gt;
    iptables -I INPUT -j ACCEPT -s $SEGMENT -d $THISHOST --protocol tcp --destination-port $port&lt;br /&gt;
    iptables -I INPUT -j ACCEPT -s $SEGMENT -d $THISHOST --protocol udp --destination-port $port&lt;br /&gt;
    success ; echo&lt;br /&gt;
  done&lt;br /&gt;
  for ip in $DMZS ; do&lt;br /&gt;
    echo -n &amp;quot;          DMZ $ip&amp;quot;&lt;br /&gt;
    iptables -I INPUT   -i eth0 -j ACCEPT -s $ip&lt;br /&gt;
    iptables -I FORWARD -i eth0 -j ACCEPT -s $ip&lt;br /&gt;
    success ; echo&lt;br /&gt;
  done&lt;br /&gt;
&lt;br /&gt;
  VESETUPS=`echo /etc/firewall.d/*`&lt;br /&gt;
  if [ &amp;quot;$VESETUPS&amp;quot; != &amp;quot;/etc/firewall.d/*&amp;quot; ] ; then&lt;br /&gt;
  echo &amp;quot;Firewall: Setting up VE firewalls&amp;quot;&lt;br /&gt;
  for i in $VESETUPS ; do&lt;br /&gt;
    . $i&lt;br /&gt;
    echo -n &amp;quot;          $VENAME VE$VEID&amp;quot;&lt;br /&gt;
    if [ -n &amp;quot;$BANNED&amp;quot; ]; then&lt;br /&gt;
      for source in $BANNED ;  do iptables -I FORWARD -j DROP --destination $VEIP --source $source ; done&lt;br /&gt;
    fi&lt;br /&gt;
    if [ -n &amp;quot;$OPENPORTS&amp;quot; ]; then&lt;br /&gt;
      for port in $OPENPORTS ; do iptables -I FORWARD -j ACCEPT --protocol tcp --destination $VEIP --destination-port $port ; done&lt;br /&gt;
      for port in $OPENPORTS ; do iptables -I FORWARD -j ACCEPT --protocol udp --destination $VEIP --destination-port $port ; done&lt;br /&gt;
    fi&lt;br /&gt;
    if [ -n &amp;quot;$DMZS&amp;quot; ]; then&lt;br /&gt;
      for source in $DMZS ; do iptables -I FORWARD -j ACCEPT --protocol tcp --destination $VEIP --source $source ; done&lt;br /&gt;
      for source in $DMZS ; do iptables -I FORWARD -j ACCEPT --protocol udp --destination $VEIP --source $source ; done&lt;br /&gt;
    fi&lt;br /&gt;
    [ $? -eq 0 ] &amp;amp;&amp;amp; success || failure&lt;br /&gt;
    echo&lt;br /&gt;
  done&lt;br /&gt;
  fi&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
case &amp;quot;$1&amp;quot; in&lt;br /&gt;
  start)&lt;br /&gt;
    echo &amp;quot;Starting firewall...&amp;quot;&lt;br /&gt;
    purge&lt;br /&gt;
    setup&lt;br /&gt;
    ;;&lt;br /&gt;
  stop)&lt;br /&gt;
    echo &amp;quot;Stopping firewall...&amp;quot;&lt;br /&gt;
    purge&lt;br /&gt;
    ;;&lt;br /&gt;
  restart)&lt;br /&gt;
    $0 stop&lt;br /&gt;
    $0 start&lt;br /&gt;
    ;;&lt;br /&gt;
  status)&lt;br /&gt;
    iptables -n -L&lt;br /&gt;
    ;;&lt;br /&gt;
  *)&lt;br /&gt;
    echo &amp;quot;Usage: $0 &amp;lt;start|stop|restart|status&amp;gt;&amp;quot;&lt;br /&gt;
    ;;&lt;br /&gt;
esac&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above script can be called like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
service firewall start&lt;br /&gt;
service firewall stop&lt;br /&gt;
service firewall restart&lt;br /&gt;
service firewall status&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It will set up the firewall for the HN according to the parameters you specified for OKPORTS, DMZs, etc. and then it will call each file under /etc/firewall.d and process  its configuration.&lt;br /&gt;
&lt;br /&gt;
So create a file under /etc/firewall.d The exact filename isn't important, as long as it's meaningful to you, e.g. &amp;lt;pre&amp;gt;ExampleCompany&amp;lt;/pre&amp;gt; or &amp;lt;pre&amp;gt;ve12&amp;lt;/pre&amp;gt; and give it content like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This file is processed by /etc/init.d/firewall&lt;br /&gt;
VEID=&amp;quot;1&amp;quot;                      # the VE's ID#&lt;br /&gt;
VENAME=&amp;quot;Customer1&amp;quot;            # A human-friendly label for the VE&lt;br /&gt;
VEIP=&amp;quot;192.168.1.34&amp;quot;           # the IP address for this VE&lt;br /&gt;
OPENPORTS=&amp;quot;80 443&amp;quot;            # ports that should be universally opened to the entire Internet&lt;br /&gt;
DMZS=&amp;quot;1.2.3.0/24 5.6.7.8/32&amp;quot;  # IPs and blocks that should have full access to the VE's services&lt;br /&gt;
BANNED=&amp;quot;&amp;quot;                     # IPs and blocks that should be entirely blocked from the VE's services&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And there you go. Go ahead and start the firewall and check its status:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
service firewall restart&lt;br /&gt;
service firewall status&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, you can now add and edit the configurations for individual VEs very easily. This method proves a lot easier to manage than Fedora's iptables-config mechamism!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Setting up a firewall that allows per-VE configuration ==&lt;br /&gt;
&lt;br /&gt;
This setup configures iptables on the HN to disallow access to all hosts, including the VEs. However, it allows all traffic into the VEs so they may define their own iptables rules and therefore manage their own firewall.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;This content is missing. You are invited to fill it in, if you get to it before I do. :)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[[Traffic accounting with iptables]]&lt;br /&gt;
&lt;br /&gt;
[[ Category: Networking ]]&lt;br /&gt;
[[ Category: Firewalls ]]&lt;/div&gt;</summary>
		<author><name>HostGIS</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Setting_up_an_iptables_firewall&amp;diff=3101</id>
		<title>Setting up an iptables firewall</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Setting_up_an_iptables_firewall&amp;diff=3101"/>
		<updated>2007-05-16T17:07:19Z</updated>

		<summary type="html">&lt;p&gt;HostGIS: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This document consists of two parts. The first is setting up a firewall (using iptables) on the HN, which will restrict traffic to the VEs. The effect would emulate, as far as the VEs and their customers are concerned, an external hardware firewall controlled by the sysadmin. The second is setting up a firewall that protects the HN itself but still allows traffic to the VEs, thus allowing individual VEs to define their own iptables.&lt;br /&gt;
&lt;br /&gt;
While the firewalls shown here can be accomplished using iptables manually (or using Fedora core's iptables service), the methods presented here are especially modular and easy to modify. This is important when you have 20+ VEs and a lot of other things to be doing...&lt;br /&gt;
&lt;br /&gt;
The scripts and pathnames given here are for Fedora Core 6, though they can probably be applied to most similar SysV-like systems with little modification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A little background ==&lt;br /&gt;
&lt;br /&gt;
On our systems, we use the HN to provide privileged services which are not appropriate for access by the VEs. For example, the HN acts as a backup server, runs Nagios for health monitoring, has a webserver for managing the 3ware RAID controller, etc. The VEs are leased to customers, who can't entirely be trusted, especially if they get hacked. As such, our scenario is one in which the HN must be protected from all access (even from the VEs) except for a few trusted hosts (e.g. my home-office).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Setting up a HN-based firewall ==&lt;br /&gt;
&lt;br /&gt;
This setup emulates (to the VEs anyway) an external hardware firewall. It protects the HN from any access and then defines what services and ports are allowed/banned for individual VEs. This leaves the firewall controlled by the site administrator, not be individual VEs and the hackers who've gotten into them. ;)&lt;br /&gt;
&lt;br /&gt;
First off, let's disable Fedora's existing &amp;lt;code&amp;gt;iptables&amp;lt;/code&amp;gt; service:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
service iptables off&lt;br /&gt;
chkconfig iptables off&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now create the new &amp;lt;code&amp;gt;firewall&amp;lt;/code&amp;gt; service. This code should be &amp;lt;code&amp;gt;/etc/init.d/firewall&amp;lt;/code&amp;gt; and then should be chmod'd 755.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
# firewall      Start iptables firewall&lt;br /&gt;
# chkconfig: 2345 08 92&lt;br /&gt;
# description:  Starts, stops and saves iptables firewall&lt;br /&gt;
# This script sets up the firewall for the INPUT chain (which is for the HN itself)&lt;br /&gt;
# and then processes the config files under /etc/firewall.d to set up additional rules&lt;br /&gt;
# in the FORWARD chain to allow access to VEs' services.&lt;br /&gt;
&lt;br /&gt;
. /etc/init.d/functions&lt;br /&gt;
&lt;br /&gt;
# the IP block allocated to this server&lt;br /&gt;
SEGMENT=&amp;quot;192.168.0.0/24&amp;quot;&lt;br /&gt;
# the IP used by the hosting server itself&lt;br /&gt;
THISHOST=&amp;quot;192.168.0.1&amp;quot;&lt;br /&gt;
# services that should be allowed to the HN; services for VEs are configured in /etc/firewall.d/*&lt;br /&gt;
OKPORTS=&amp;quot;53&amp;quot;&lt;br /&gt;
# hosts allowed full access through the firewall, to all VEs and to this server&lt;br /&gt;
DMZS=&amp;quot;12.34.56.78 90.123.45.67&amp;quot;&lt;br /&gt;
&lt;br /&gt;
purge() {&lt;br /&gt;
  echo -n &amp;quot;Firewall: Purging and allowing all traffic&amp;quot;&lt;br /&gt;
  iptables -P OUTPUT ACCEPT&lt;br /&gt;
  iptables -P FORWARD ACCEPT&lt;br /&gt;
  iptables -P INPUT ACCEPT&lt;br /&gt;
  iptables -F&lt;br /&gt;
  success ; echo&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
setup() {&lt;br /&gt;
  echo -n &amp;quot;Firewall: Setting default policies to DROP&amp;quot;&lt;br /&gt;
  iptables -P INPUT DROP&lt;br /&gt;
  iptables -P FORWARD DROP&lt;br /&gt;
  iptables -I INPUT   -j ACCEPT -m state --state ESTABLISHED,RELATED&lt;br /&gt;
  iptables -I FORWARD -j ACCEPT -m state --state ESTABLISHED,RELATED&lt;br /&gt;
  iptables -I INPUT -j ACCEPT -i lo&lt;br /&gt;
  iptables -I FORWARD -j ACCEPT --source $SEGMENT&lt;br /&gt;
  success ; echo&lt;br /&gt;
&lt;br /&gt;
  echo &amp;quot;Firewall: Allowing access to HN&amp;quot;&lt;br /&gt;
  for port in $OKPORTS ; do&lt;br /&gt;
    echo -n &amp;quot;          port $port&amp;quot;&lt;br /&gt;
    iptables -I INPUT -j ACCEPT -s $SEGMENT -d $THISHOST --protocol tcp --destination-port $port&lt;br /&gt;
    iptables -I INPUT -j ACCEPT -s $SEGMENT -d $THISHOST --protocol udp --destination-port $port&lt;br /&gt;
    success ; echo&lt;br /&gt;
  done&lt;br /&gt;
  for ip in $DMZS ; do&lt;br /&gt;
    echo -n &amp;quot;          DMZ $ip&amp;quot;&lt;br /&gt;
    iptables -I INPUT   -i eth0 -j ACCEPT -s $ip&lt;br /&gt;
    iptables -I FORWARD -i eth0 -j ACCEPT -s $ip&lt;br /&gt;
    success ; echo&lt;br /&gt;
  done&lt;br /&gt;
&lt;br /&gt;
  VESETUPS=`echo /etc/firewall.d/*`&lt;br /&gt;
  if [ &amp;quot;$VESETUPS&amp;quot; != &amp;quot;/etc/firewall.d/*&amp;quot; ] ; then&lt;br /&gt;
  echo &amp;quot;Firewall: Setting up VE firewalls&amp;quot;&lt;br /&gt;
  for i in $VESETUPS ; do&lt;br /&gt;
    . $i&lt;br /&gt;
    echo -n &amp;quot;          $VENAME VE$VEID&amp;quot;&lt;br /&gt;
    if [ -n &amp;quot;$BANNED&amp;quot; ]; then&lt;br /&gt;
      for source in $BANNED ;  do iptables -I FORWARD -j DROP --destination $VEIP --source $source ; done&lt;br /&gt;
    fi&lt;br /&gt;
    if [ -n &amp;quot;$OPENPORTS&amp;quot; ]; then&lt;br /&gt;
      for port in $OPENPORTS ; do iptables -I FORWARD -j ACCEPT --protocol tcp --destination $VEIP --destination-port $port ; done&lt;br /&gt;
      for port in $OPENPORTS ; do iptables -I FORWARD -j ACCEPT --protocol udp --destination $VEIP --destination-port $port ; done&lt;br /&gt;
    fi&lt;br /&gt;
    if [ -n &amp;quot;$DMZS&amp;quot; ]; then&lt;br /&gt;
      for source in $DMZS ; do iptables -I FORWARD -j ACCEPT --protocol tcp --destination $VEIP --source $source ; done&lt;br /&gt;
      for source in $DMZS ; do iptables -I FORWARD -j ACCEPT --protocol udp --destination $VEIP --source $source ; done&lt;br /&gt;
    fi&lt;br /&gt;
    [ $? -eq 0 ] &amp;amp;&amp;amp; success || failure&lt;br /&gt;
    echo&lt;br /&gt;
  done&lt;br /&gt;
  fi&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
case &amp;quot;$1&amp;quot; in&lt;br /&gt;
  start)&lt;br /&gt;
    echo &amp;quot;Starting firewall...&amp;quot;&lt;br /&gt;
    purge&lt;br /&gt;
    setup&lt;br /&gt;
    ;;&lt;br /&gt;
  stop)&lt;br /&gt;
    echo &amp;quot;Stopping firewall...&amp;quot;&lt;br /&gt;
    purge&lt;br /&gt;
    ;;&lt;br /&gt;
  restart)&lt;br /&gt;
    $0 stop&lt;br /&gt;
    $0 start&lt;br /&gt;
    ;;&lt;br /&gt;
  status)&lt;br /&gt;
    iptables -n -L&lt;br /&gt;
    ;;&lt;br /&gt;
  *)&lt;br /&gt;
    echo &amp;quot;Usage: $0 &amp;lt;start|stop|restart|status&amp;gt;&amp;quot;&lt;br /&gt;
    ;;&lt;br /&gt;
esac&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above script can be called like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
service firewall start&lt;br /&gt;
service firewall stop&lt;br /&gt;
service firewall restart&lt;br /&gt;
service firewall status&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It will set up the firewall for the HN according to the parameters you specified for OKPORTS, DMZs, etc. and then it will call each file under /etc/firewall.d and process  its configuration.&lt;br /&gt;
&lt;br /&gt;
So create a file under /etc/firewall.d The exact filename isn't important, as long as it's meaningful to you, e.g. &amp;lt;pre&amp;gt;ExampleCompany&amp;lt;/pre&amp;gt; or &amp;lt;pre&amp;gt;ve12&amp;lt;/pre&amp;gt; and give it content like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This file is processed by /etc/init.d/firewall&lt;br /&gt;
VEID=&amp;quot;1&amp;quot;                      # the VE's ID#&lt;br /&gt;
VENAME=&amp;quot;Customer1&amp;quot;            # A human-friendly label for the VE&lt;br /&gt;
VEIP=&amp;quot;192.168.1.34&amp;quot;           # the IP address for this VE&lt;br /&gt;
OPENPORTS=&amp;quot;80 443&amp;quot;            # ports that should be universally opened to the entire Internet&lt;br /&gt;
DMZS=&amp;quot;1.2.3.0/24 5.6.7.8/32&amp;quot;  # IPs and blocks that should have full access to the VE's services&lt;br /&gt;
BANNED=&amp;quot;&amp;quot;                     # IPs and blocks that should be entirely blocked from the VE's services&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And there you go. Go ahead and start the firewall and check its status:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
service firewall restart&lt;br /&gt;
service firewall status&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, you can now add and edit the configurations for individual VEs very easily. This method proves a lot easier to manage than Fedora's iptables-config mechamism!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Setting up a firewall that allows per-VE configuration ==&lt;br /&gt;
&lt;br /&gt;
This setup configures iptables on the HN to disallow access to all hosts, including the VEs. However, it allows all traffic into the VEs so they may define their own iptables rules and therefore manage their own firewall.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;This content is missing. You are invited to fill it in, if you get to it before I do. :)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[[Traffic accounting with iptables]]&lt;br /&gt;
&lt;br /&gt;
[[ Category: Networking ]]&lt;br /&gt;
[[ Category: Firewalls ]]&lt;/div&gt;</summary>
		<author><name>HostGIS</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Setting_up_an_iptables_firewall&amp;diff=3100</id>
		<title>Setting up an iptables firewall</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Setting_up_an_iptables_firewall&amp;diff=3100"/>
		<updated>2007-05-16T15:52:31Z</updated>

		<summary type="html">&lt;p&gt;HostGIS: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This document consists of two parts. The first is setting up a firewall (using iptables) on the HN, which will restrict traffic to the VEs. The effect would emulate, as far as the VEs and their customers are concerned, an external hardware firewall controlled by the sysadmin. The second is setting up a firewall that protects the HN itself but still allows traffic to the VEs, thus allowing individual VEs to define their own iptables.&lt;br /&gt;
&lt;br /&gt;
== Setting up a HN-based firewall ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Setting up a firewall that allows per-VE configuration ==&lt;br /&gt;
&lt;br /&gt;
Although it is possible to use iptables within each VE individually, I've not been able to get this to work reliably, but more importantly we simply don't trust our customers to effectively manage their own firewalls and prefer to keep these many firewalls consolidated into one place. As such, this content is missing. You are invited to fill it in, if you get to it before I do. :)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[[Traffic accounting with iptables]]&lt;br /&gt;
&lt;br /&gt;
[[ Category: Networking ]]&lt;br /&gt;
[[ Category: Firewalls ]]&lt;/div&gt;</summary>
		<author><name>HostGIS</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Setting_up_an_iptables_firewall&amp;diff=3099</id>
		<title>Setting up an iptables firewall</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Setting_up_an_iptables_firewall&amp;diff=3099"/>
		<updated>2007-05-16T15:48:33Z</updated>

		<summary type="html">&lt;p&gt;HostGIS: New page: This document consists of two parts. The first is setting up a firewall (using iptables) on the HN, which will restrict traffic to the VEs. The effect would emulate, as far as the VEs and ...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This document consists of two parts. The first is setting up a firewall (using iptables) on the HN, which will restrict traffic to the VEs. The effect would emulate, as far as the VEs and their customers are concerned, an external hardware firewall controlled by the sysadmin. The second is setting up a firewall that protects the HN itself but still allows traffic to the VEs, thus allowing individual VEs to define their own iptables.&lt;br /&gt;
&lt;br /&gt;
Setting up a HN-based firewall&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Setting up a firewall that allows per-VE configuration&lt;br /&gt;
&lt;br /&gt;
Although it is possible to use iptables within each VE individually, I've not been able to get this to work reliably, but more importantly we simply don't trust our customers to effectively manage their own firewalls and prefer to keep these many firewalls consolidated into one place. As such, this content is missing. You are invited to fill it in, if you get to it before I do. :)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
See Also&lt;br /&gt;
&lt;br /&gt;
Traffic_accounting_with_iptables&lt;/div&gt;</summary>
		<author><name>HostGIS</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Virtual_Ethernet_device&amp;diff=3084</id>
		<title>Virtual Ethernet device</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Virtual_Ethernet_device&amp;diff=3084"/>
		<updated>2007-05-09T06:55:23Z</updated>

		<summary type="html">&lt;p&gt;HostGIS: /* Making a veth-device persistent */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Virtual ethernet device''' is an ethernet-like device which can be used inside a [[VE]]. Unlike&lt;br /&gt;
[[venet]] network device, veth device has a MAC address. Due to this, it can be used in configurations, when veth is bridged to ethX or other device and VE user fully sets up his networking himself, &lt;br /&gt;
including IPs, gateways etc.&lt;br /&gt;
&lt;br /&gt;
Virtual ethernet device consist of two ethernet devices - one in [[VE0]] and another one &lt;br /&gt;
in VE. These devices are connected to each other, so if a packet goes to one&lt;br /&gt;
device it will come out from the other device.&lt;br /&gt;
&lt;br /&gt;
== Virtual ethernet device usage ==&lt;br /&gt;
&lt;br /&gt;
=== Kernel module ===&lt;br /&gt;
First of all, make sure the &amp;lt;code&amp;gt;vzethdev&amp;lt;/code&amp;gt; module is loaded:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# lsmod | grep vzeth&lt;br /&gt;
vzethdev                8224  0&lt;br /&gt;
vzmon                  35164  5 vzethdev,vznetdev,vzrst,vzcpt&lt;br /&gt;
vzdev                   3080  4 vzethdev,vznetdev,vzmon,vzdquota&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In case it is not loaded, load it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# modprobe vzethdev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You might want to add the module to &amp;lt;code&amp;gt;/etc/init.d/vz script&amp;lt;/code&amp;gt;, so it will be loaded during startup.&lt;br /&gt;
&lt;br /&gt;
{{Note|since vzctl version 3.0.11, vzethdev is loaded by /etc/init.d/vz}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Adding veth to a VE ===&lt;br /&gt;
&lt;br /&gt;
{{Note|Use random MAC addresses. Do not use MAC addresses of real eth devices, because this can lead to collisions and MAC addresses must be entered in XX:XX:XX:XX:XX:XX format.}}&lt;br /&gt;
&lt;br /&gt;
==== syntax vzctl version &amp;lt; 3.0.14 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl set &amp;lt;VEID&amp;gt; --veth_add &amp;lt;dev_name&amp;gt;,&amp;lt;dev_addr&amp;gt;,&amp;lt;ve_dev_name&amp;gt;,&amp;lt;ve_dev_addr&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here &lt;br /&gt;
* &amp;lt;tt&amp;gt;dev_name&amp;lt;/tt&amp;gt; is the ethernet device name that you are creating on the [[VE0|host system]]&lt;br /&gt;
* &amp;lt;tt&amp;gt;dev_addr&amp;lt;/tt&amp;gt; is its MAC address&lt;br /&gt;
* &amp;lt;tt&amp;gt;ve_dev_name&amp;lt;/tt&amp;gt; is the corresponding ethernet device name you are creating on the VE&lt;br /&gt;
* &amp;lt;tt&amp;gt;ve_dev_addr&amp;lt;/tt&amp;gt; is its MAC address&lt;br /&gt;
&lt;br /&gt;
{{Note| that this option is incremental, so devices are added to already existing ones.}}&lt;br /&gt;
&lt;br /&gt;
NB there are no spaces after the commas&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl set 101 --veth_add veth101.0,00:12:34:56:78:9A,eth0,00:12:34:56:78:9B --save&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After executing this command &amp;lt;tt&amp;gt;veth&amp;lt;/tt&amp;gt; device will be created for VE 101 and veth configuration will be saved to a VE configuration file.&lt;br /&gt;
Host-side ethernet device will have &amp;lt;tt&amp;gt;veth101.0&amp;lt;/tt&amp;gt; name and &amp;lt;tt&amp;gt;00:12:34:56:78:9A&amp;lt;/tt&amp;gt; MAC address.&lt;br /&gt;
VE-side ethernet device will have &amp;lt;tt&amp;gt;eth0&amp;lt;/tt&amp;gt; name and &amp;lt;tt&amp;gt;00:12:34:56:78:9B&amp;lt;/tt&amp;gt; MAC address.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== syntax vzctl version &amp;gt;= 3.0.14 ====&lt;br /&gt;
&lt;br /&gt;
Read Update infos about [http://openvz.org/news/updates/vzctl-3.0.14-1 vzctl 3.0.14]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl set &amp;lt;VEID&amp;gt; --netif_add &amp;lt;ifname&amp;gt;[,&amp;lt;mac&amp;gt;,&amp;lt;host_ifname&amp;gt;,&amp;lt;host_mac]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here&lt;br /&gt;
* &amp;lt;tt&amp;gt;ifname&amp;lt;/tt&amp;gt; is the ethernet device name in the VE&lt;br /&gt;
* &amp;lt;tt&amp;gt;mac&amp;lt;/tt&amp;gt; is its MAC address in the VE&lt;br /&gt;
* &amp;lt;tt&amp;gt;host_ifname&amp;lt;/tt&amp;gt;  is the ethernet device name on the host ([[VE0]])&lt;br /&gt;
* &amp;lt;tt&amp;gt;host_mac&amp;lt;/tt&amp;gt; is its MAC address on the host ([[VE0]])&lt;br /&gt;
&lt;br /&gt;
{{Note|All parameters except ifname are optional and are automatically generated if not specified.}}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl set 101 --netif_add eth0,00:12:34:56:78:9A,veth101.0,00:12:34:56:78:9B --save&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Removing veth from a VE ===&lt;br /&gt;
&lt;br /&gt;
==== syntax vzctl version &amp;lt; 3.0.14 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl set &amp;lt;VEID&amp;gt; --veth_del &amp;lt;dev_name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here &amp;lt;tt&amp;gt;dev_name&amp;lt;/tt&amp;gt; is the ethernet device name in the [[VE0|host system]].&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl set 101 --veth_del veth101.0 --save&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After executing this command veth device with host-side ethernet name veth101.0 will be removed from VE 101 and veth configuration will be updated in VE config file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== syntax vzctl version &amp;gt;= 3.0.14 ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl set &amp;lt;VEID&amp;gt; --netif_del &amp;lt;dev_name&amp;gt;|all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here&lt;br /&gt;
* &amp;lt;code&amp;gt;dev_name&amp;lt;/code&amp;gt; is the ethernet device name in the [[VE]].&lt;br /&gt;
&lt;br /&gt;
{{Note|If you want to remove all ethernet devices in VE, use &amp;lt;code&amp;gt;all&amp;lt;/code&amp;gt;.}}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl set 101 --netif_del eth0 --save&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Common configurations with virtual ethernet devices ==&lt;br /&gt;
Module &amp;lt;tt&amp;gt;vzethdev&amp;lt;/tt&amp;gt; must be loaded to operate with veth devices.&lt;br /&gt;
&lt;br /&gt;
=== Simple configuration with virtual ethernet device ===&lt;br /&gt;
&lt;br /&gt;
==== Start a VE ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# vzctl start 101&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add veth device to VE ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# vzctl set 101 --veth_add veth101.0,00:12:34:56:78:9A,eth0,00:12:34:56:78:9B --save&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configure devices in VE0 ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# ifconfig veth101.0 0&lt;br /&gt;
[host-node]# echo 1 &amp;gt; /proc/sys/net/ipv4/conf/veth101.0/forwarding&lt;br /&gt;
[host-node]# echo 1 &amp;gt; /proc/sys/net/ipv4/conf/veth101.0/proxy_arp&lt;br /&gt;
[host-node]# echo 1 &amp;gt; /proc/sys/net/ipv4/conf/eth0/forwarding&lt;br /&gt;
[host-node]# echo 1 &amp;gt; /proc/sys/net/ipv4/conf/eth0/proxy_arp&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configure device in VE ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# vzctl enter 101&lt;br /&gt;
[ve-101]# /sbin/ifconfig eth0 0&lt;br /&gt;
[ve-101]# /sbin/ip addr add 192.168.0.101 dev eth0&lt;br /&gt;
[ve-101]# /sbin/ip route add default dev eth0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add route in [[VE0]] ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# ip route add 192.168.0.101 dev veth101.0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Virtual ethernet device with IPv6 ===&lt;br /&gt;
&lt;br /&gt;
==== Start [[VE]] ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# vzctl start 101&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add veth device to [[VE]] ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# vzctl set 101 --veth_add veth101.0,00:12:34:56:78:9A,eth0,00:12:34:56:78:9B --save&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configure devices in [[VE0]] ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# ifconfig veth101.0 0&lt;br /&gt;
[host-node]# echo 1 &amp;gt; /proc/sys/net/ipv6/conf/veth101.0/forwarding&lt;br /&gt;
[host-node]# echo 1 &amp;gt; /proc/sys/net/ipv6/conf/eth0/forwarding&lt;br /&gt;
[host-node]# echo 1 &amp;gt; /proc/sys/net/ipv6/conf/all/forwarding&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configure device in [[VE]] ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# vzctl enter 101&lt;br /&gt;
[ve-101]# /sbin/ifconfig eth0 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Start router advertisement daemon (radvd) for IPv6 in VE0 ====&lt;br /&gt;
First you need to edit radvd configuration file. Here is a simple example of &amp;lt;tt&amp;gt;/etc/radv.conf&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface veth101.0&lt;br /&gt;
{&lt;br /&gt;
        AdvSendAdvert on;&lt;br /&gt;
        MinRtrAdvInterval 3;&lt;br /&gt;
        MaxRtrAdvInterval 10;&lt;br /&gt;
        AdvHomeAgentFlag off;&lt;br /&gt;
&lt;br /&gt;
        prefix 3ffe:2400:0:0::/64&lt;br /&gt;
        {&lt;br /&gt;
                AdvOnLink on;&lt;br /&gt;
                AdvAutonomous on;&lt;br /&gt;
                AdvRouterAddr off;&lt;br /&gt;
        };&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
interface eth0&lt;br /&gt;
{&lt;br /&gt;
        AdvSendAdvert on;&lt;br /&gt;
        MinRtrAdvInterval 3;&lt;br /&gt;
        MaxRtrAdvInterval 10;&lt;br /&gt;
        AdvHomeAgentFlag off;&lt;br /&gt;
&lt;br /&gt;
        prefix 3ffe:0302:0011:0002::/64&lt;br /&gt;
        {&lt;br /&gt;
                AdvOnLink on;&lt;br /&gt;
                AdvAutonomous on;&lt;br /&gt;
                AdvRouterAddr off;&lt;br /&gt;
        };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, start radvd:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# /etc/init.d/radvd start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add IPv6 addresses to devices in [[VE0]] ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# ip addr add dev veth101.0 3ffe:2400::212:34ff:fe56:789a/64&lt;br /&gt;
[host-node]# ip addr add dev eth0 3ffe:0302:0011:0002:211:22ff:fe33:4455/64&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Virtual ethernet devices can be joined in one bridge ===&lt;br /&gt;
Perform steps 1 - 4 from Simple configuration chapter for several VEs and/or veth devices&lt;br /&gt;
&lt;br /&gt;
==== Create bridge device ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# brctl addbr vzbr0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add veth devices to bridge ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# brctl addif vzbr0 veth101.0&lt;br /&gt;
...&lt;br /&gt;
[host-node]# brctl addif vzbr0 veth101.n&lt;br /&gt;
[host-node]# brctl addif vzbr0 veth102.0&lt;br /&gt;
...&lt;br /&gt;
...&lt;br /&gt;
[host-node]# brctl addif vzbr0 vethXXX.N&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configure bridge device ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# ifconfig vzbr0 0&lt;br /&gt;
[host-node]# echo 1 &amp;gt; /proc/sys/net/ipv4/conf/vzbr0/forwarding&lt;br /&gt;
[host-node]# echo 1 &amp;gt; /proc/sys/net/ipv4/conf/vzbr0/proxy_arp&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add routes in [[VE0]] ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# ip route add 192.168.101.1 dev vzbr0&lt;br /&gt;
...&lt;br /&gt;
[host-node]# ip route add 192.168.101.n dev vzbr0&lt;br /&gt;
[host-node]# ip route add 192.168.102.1 dev vzbr0&lt;br /&gt;
...&lt;br /&gt;
...&lt;br /&gt;
[host-node]# ip route add 192.168.XXX.N dev vzbr0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus you'll have more convinient configuration, i.e. all routes to VEs will be through this bridge and VEs can communicate with each other even without these routes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Making a veth-device persistent ===&lt;br /&gt;
&lt;br /&gt;
At the moment, it is not possible to have the commands needed for a persistent veth being made automatically be vzctl. A  bugreport ( http://bugzilla.openvz.org/show_bug.cgi?id=301 ) has already been made. Until then, here's a way to make the above steps persistent.&lt;br /&gt;
&lt;br /&gt;
1. First, edit the VE's configuration to specify what the veth's IP address(es) should be, and to indicate that a custom script should be run when starting up a VE.&lt;br /&gt;
 * Open up /etc/vz/conf/VEID.conf&lt;br /&gt;
 * Comment out any IP_ADDRESS entries to prevent a VENET-device from being created in the VE&lt;br /&gt;
 * Add or change the entry CONFIG_CUSTOMIZED=&amp;quot;yes&amp;quot;&lt;br /&gt;
 * Add an entry VETH_IP_ADDRESS=&amp;quot;&amp;lt;VE IP&amp;gt;&amp;quot; The VE IP can have multiple IPs, separated by spaces&lt;br /&gt;
&lt;br /&gt;
2. Now to create that &amp;quot;custom script&amp;quot;. The following helper script will check the configuration file for IP addresses and for the veth interface, and configure the IP routing accordingly. Create the script /usr/sbin/vznetaddroute to have the following, and then &amp;lt;code&amp;gt;chmod 0500 /usr/sbin/vznetaddroute&amp;lt;/code&amp;gt; to make it executable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# /usr/sbin/vznetaddroute&lt;br /&gt;
# a script to bring up bridged network interfaces (veth's) in a VE&lt;br /&gt;
&lt;br /&gt;
CONFIGFILE=/etc/vz/conf/$VEID.conf&lt;br /&gt;
. $CONFIGFILE&lt;br /&gt;
VZHOSTIF=`echo $NETIF |sed 's/^.*host_ifname=\(.*\),.*$/\1/g'`&lt;br /&gt;
&lt;br /&gt;
if [ ! -n &amp;quot;$VETH_IP_ADDRESS&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;According to $CONFIGFILE VE$VEIDI has no veth IPs configured.&amp;quot;&lt;br /&gt;
   exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [ ! -n &amp;quot;$VZHOSTIF&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;According to $CONFIGFILE VE$VEIDI has no veth interface configured.&amp;quot;&lt;br /&gt;
   exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
for IP in $VETH_IP_ADDRESS; do&lt;br /&gt;
   echo &amp;quot;Adding interface $VZHOSTIF and route $IP for VE$VEID to VE0&amp;quot;&lt;br /&gt;
   /sbin/ifconfig $VZHOSTIF 0&lt;br /&gt;
   echo 1 &amp;gt; /proc/sys/net/ipv4/conf/$VZHOSTIF/proxy_arp&lt;br /&gt;
   echo 1 &amp;gt; /proc/sys/net/ipv4/conf/$VZHOSTIF/forwarding&lt;br /&gt;
   /sbin/ip route add $IP dev $VZHOSTIF&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Now create /etc/vz/vznet.conf containing the following. This is what defines the &amp;quot;custom script&amp;quot; as being the vznetaddroute which you just created.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
EXTERNAL_SCRIPT=&amp;quot;/usr/sbin/vznetaddroute&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Of course, the VE's operating system will need to be configured with those IP address(es) as well. Consult the manual for your VE's OS for details.&lt;br /&gt;
&lt;br /&gt;
That's it! At this point, when you restart the VE you should see a new line in the output, indicating that the interface is being configured and a new route being added. And you should be able to ping the host, and to enter the VE and use the network.&lt;br /&gt;
&lt;br /&gt;
=== Virtual ethernet devices + VLAN ===&lt;br /&gt;
This configuration can be done by adding vlan device to the previous configuration.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Virtual network device]]&lt;br /&gt;
* [[Differences between venet and veth]]&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
* [http://www.tldp.org/HOWTO/Linux+IPv6-HOWTO/hints-daemons-radvd.html Linux IPv6 HOWTO, a chapter about radvd]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: Networking]]&lt;br /&gt;
[[Category: HOWTO]]&lt;/div&gt;</summary>
		<author><name>HostGIS</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Postgresql_and_shared_memory&amp;diff=3017</id>
		<title>Postgresql and shared memory</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Postgresql_and_shared_memory&amp;diff=3017"/>
		<updated>2007-04-16T20:04:08Z</updated>

		<summary type="html">&lt;p&gt;HostGIS: page created, prompted by Kirill's email&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I tried running PostgreSQL as one of my first experiments, and hit upon some nuances of shared memory, which may be helpful to relate here.&lt;br /&gt;
&lt;br /&gt;
One of the easiest ways to increase Postgres's performance is to turn up the shared_buffers parameter in the postgresql.conf file; this is basically the amount of shared memory which the postmaster will use for buffering everything: table data, indexes, etc. The default value is really small, and if you have RAM to spare you may want to crank it up to 128MB (that's 16384 shared buffers, for pgsql 8.1 and earlier) or even more. But if it then complains that it couldn't allocate the shared memory, this page explains why.&lt;br /&gt;
&lt;br /&gt;
PostgreSQL uses shared memory. As such, you have to check two things about the VE.&lt;br /&gt;
&lt;br /&gt;
1. UBC's shmpages setting for this VE. This dictates how many pages (8k apiece) are available to the VE, e.g. shmpages=16384 gives a limit of 128 MB of shared memory.&lt;br /&gt;
&lt;br /&gt;
2. &amp;quot;/sbin/sysctl kernel.shmmax&amp;quot;  This is the VE's self-imposed limit on how much shared memory may be allocated in a single request.&lt;br /&gt;
&lt;br /&gt;
Get that? Not only does the HN impose a limit on the VE's total shared memory usage, but the VE itself has a setting for the maximum amount in a single chunk.&lt;br /&gt;
&lt;br /&gt;
Some other notes:&lt;br /&gt;
&lt;br /&gt;
* Note that shared memory is part of the VE's overall memory usage. It is not a second memory pool.&lt;br /&gt;
&lt;br /&gt;
* Note that processes other than PostgreSQL may be using shared memory, and also that shmpages includes stuff other than IPC shared memory (tmpfs, shmem, etc) So don't set shmpages to exactly the amount you want to give Postgres.&lt;br /&gt;
&lt;br /&gt;
* The sysctl kernel.shmmax value set in the HN/VE0 applies only to the HN, not to VEs.&lt;/div&gt;</summary>
		<author><name>HostGIS</name></author>
		
	</entry>
</feed>