  
<div id="snippet_180" class="snippet">
  <h2><a href="/snippets/180-How-to-install-and-use-the-Sphinx-search-engine-and-acts-as-sphinx-plugin-on-Debian-Etch" title="How to install and use the Sphinx search engine and acts_as_sphinx plugin on Debian Etch - Shell Script (Bash) - sphinx, search, acts_as_sphinx, debian, etch, rails, install, libstemmer">How to install and use the Sphinx search engine and acts_as_sphinx plugin on Debian Etch</a></h2>
  <div class="details">
    <a style="background-color: #FFFF94;" href="http://snippets.aktagon.com/languages/131-Shell-Script-Bash-">
      Shell Script (Bash)</a> posted about 1 year ago by christian
          
  </div>

  <div class="body">
    <p>Inspiration for this snippet was taken from <a href="http://www.sphinxsearch.com/forum/view.html?id=1419">this post</a> on the Sphinx forum, plus <a href="http://www.datanoise.com/articles/2007/3/23/acts_as_sphinx-plugin">this blog post</a>.</p>


	<h2>Compiling Sphinx</h2>


	<p>First install the prerequisites:</p>


	<p><pre class="active4d"><span class="line-numbers">   1 </span> sudo aptitude install libmysql++-dev libmysqlclient15-dev checkinstall
</pre></p>


	<p>Next download sphinx, libstemmer and install everything and the fish:</p>


	<p><pre class="active4d"><span class="line-numbers">   1 </span> cd /usr/local/src
<span class="line-numbers">   2 </span> 
<span class="line-numbers">   3 </span> wget http://sphinxsearch.com/downloads/sphinx-0.9.8-rc2.tar.gz
<span class="line-numbers">   4 </span> tar zxvf sphinx-0.9.8-rc2.tar.gz 
<span class="line-numbers">   5 </span> 
<span class="line-numbers">   6 </span> cd sphinx-0.9.8-rc2/
<span class="line-numbers">   7 </span> 
<span class="line-numbers">   8 </span> <span class="LineComment"><span class="LineComment">#</span> Add stemming support for Swedish, Finnish and other fun languages.</span>
<span class="line-numbers">   9 </span> wget http://snowball.tartarus.org/dist/libstemmer_c.tgz
<span class="line-numbers">  10 </span> tar zxvf libstemmer_c.tgz
<span class="line-numbers">  11 </span> 
<span class="line-numbers">  12 </span> ./configure --with-libstemmer
<span class="line-numbers">  13 </span> make
<span class="line-numbers">  14 </span> 
<span class="line-numbers">  15 </span> make install
</pre></p>


	<h2>Configure Sphinx</h2>


	<p>Create a sphinx.conf file in your Rails config directory, as described <a href="http://www.datanoise.com/articles/2007/3/23/acts_as_sphinx-plugin">here</a>, or use <a href="http://snippets.aktagon.com/snippets/181-Sphinx-template-configuration-file">this  template</a>.</p>


	<h2>Install acts_as_sphinx plugin</h2>


	<p><pre class="active4d"><span class="line-numbers">   1 </span> ./script/plugin install http://svn.datanoise.com/acts_as_sphinx
</pre></p>


	<p>Add acts_as_sphinx to your model:</p>


	<p><pre class="active4d"><span class="line-numbers">   1 </span> class Documents
<span class="line-numbers">   2 </span>    acts_as_sphinx
<span class="line-numbers">   3 </span> end
</pre></p>


	<h2>Indexing content</h2>


	<p><pre class="active4d"><span class="line-numbers">   1 </span> rake sphinx:index
<span class="line-numbers">   2 </span> 
<span class="line-numbers">   3 </span> (<span class="Keyword">in</span> /var/www/xxx.com/releases/20080429144230)
<span class="line-numbers">   4 </span> Sphinx 0.9.8-rc2 (r1234)
<span class="line-numbers">   5 </span> Copyright (c) 2001-2008, Andrew Aksyonoff
<span class="line-numbers">   6 </span> 
<span class="line-numbers">   7 </span> using config file <span class="String"><span class="String">'</span>./sphinx.conf<span class="String">'</span></span>...
<span class="line-numbers">   8 </span> indexing index <span class="String"><span class="String">'</span>xxx.com<span class="String">'</span></span>...
<span class="line-numbers">   9 </span> collected 5077 docs, 0.6 MB
<span class="line-numbers">  10 </span> sorted 0.1 Mhits, 100.0% <span class="Keyword">done</span>
<span class="line-numbers">  11 </span> total 5077 docs, 632096 bytes
<span class="line-numbers">  12 </span> total 0.160 sec, 3950427.25 bytes/sec, 31729.86 docs/sec
</pre></p>


	<h2>Reindexing content</h2>


	<p>sphinx:index shouldn&#8217;t be run while the searchd process is running, so use rake sphinx:rotate instead, which restarts the searchd process after indexing.</p>


	<h2>Starting the daemon</h2>


	<p><pre class="active4d"><span class="line-numbers">   1 </span> mkdir -m 664 /var/log/sphinx
<span class="line-numbers">   2 </span> rake sphinx:start
<span class="line-numbers">   3 </span> 
<span class="line-numbers">   4 </span> (<span class="Keyword">in</span> /var/www/xxx.com/releases/20080429144230)
<span class="line-numbers">   5 </span> Sphinx 0.9.8-rc2 (r1234)
<span class="line-numbers">   6 </span> Copyright (c) 2001-2008, Andrew Aksyonoff
<span class="line-numbers">   7 </span> 
<span class="line-numbers">   8 </span> using config file <span class="String"><span class="String">'</span>./sphinx.conf<span class="String">'</span></span>...
<span class="line-numbers">   9 </span> Sphinx searchd server started.
</pre></p>


	<h2>Searching</h2>


	<p><pre class="active4d"><span class="line-numbers">   1 </span> Documents.find_with_sphinx <span class="String"><span class="String">'</span>why did I write this<span class="String">'</span></span>
</pre></p>
  </div>

  <div style="font-size: 0.8em;margin:0.5em;">
    
      Tagged <a href="/tags/446-sphinx">sphinx</a>, <a href="/tags/56-search">search</a>, <a href="/tags/447-acts-as-sphinx">acts_as_sphinx</a>, <a href="/tags/108-debian">debian</a>, <a href="/tags/157-etch">etch</a>, <a href="/tags/9-rails">rails</a>, <a href="/tags/188-install">install</a>, <a href="/tags/448-libstemmer">libstemmer</a>
    
    
  </div>
</div>



  
<div id="snippet_69" class="snippet">
  <h2><a href="/snippets/69-Creating-a-local-Debian-mirror-for-your-Xen-servers" title="Creating a local Debian mirror for your Xen servers - Shell Script (Bash) - xen, debian, etch, local mirror, amd64, anonftpsync, nginx">Creating a local Debian mirror for your Xen servers</a></h2>
  <div class="details">
    <a style="background-color: #FFFF94;" href="http://snippets.aktagon.com/languages/131-Shell-Script-Bash-">
      Shell Script (Bash)</a> posted over 2 years ago by marko
          
  </div>

  <div class="body">
    <p>Once you&#8217;ve bought a dual or quad Xeon and started to experiment with virtualization you will soon want to create your local mirror to make installs lightning fast. This is a step-by-step how i did it.</p>


	<p>First create the Xen that will be our mirror server. The size requirements can be found here: <a href="http://www.debian.org/mirror/size">Debian mirror sizes</a> The combined size of amd64 architecture and architecture independent files was 39Gb on 1.9.2007. So I made the image 50Gb big. Remember to change this mirror to a location near you.
<pre class="active4d"><span class="line-numbers">   1 </span> xen-create-image --hostname=mirrors.aktagon.com \
<span class="line-numbers">   2 </span> --size=50Gb --swap=256Mb --ip=10.0.0.44 \
<span class="line-numbers">   3 </span> --netmask=255.255.255.0 --gateway=10.0.0.2 \
<span class="line-numbers">   4 </span> --force --dir=/work/vserver --memory=256Mb \
<span class="line-numbers">   5 </span> --arch=amd64 \
<span class="line-numbers">   6 </span> --kernel=/boot/vmlinuz-2.6.18-5-xen-amd64 \
<span class="line-numbers">   7 </span> --debootstrap --dist=etch \
<span class="line-numbers">   8 </span> --mirror= http://ftp.<span class="Keyword">fi</span>.debian.org/debian/\
<span class="line-numbers">   9 </span> --passwd
</pre></p>


	<p>Then ssh into your new Xen as root.
<pre class="active4d"><span class="line-numbers">   1 </span> ssh -l root mirrors.aktagon.com
</pre></p>


	<p>Make base configurations for a fresh Xen.
<pre class="active4d"><span class="line-numbers">   1 </span> apt-get update <span class="Operator">&amp;&amp;</span> apt-get install locales console-data <span class="Operator">&amp;&amp;</span> dpkg-reconfigure locales
</pre></p>


	<p>Then get the mirror synchronization script from Debian.
<pre class="active4d"><span class="line-numbers">   1 </span> wget <span class="String"><span class="String">&quot;</span>http://www.debian.org/mirror/anonftpsync<span class="String">&quot;</span></span>
<span class="line-numbers">   2 </span> chmod a+x anonftpsync 
</pre></p>


	<p>Then install dependencies for anonftpsync script. Otherwise the script will fail with a <i>-bash: lockfile: command not found</i> error.
<pre class="active4d"><span class="line-numbers">   1 </span> apt-get install procmail
</pre></p>


	<p>Install nginx.
<pre class="active4d"><span class="line-numbers">   1 </span> apt-get install nginx
</pre></p>


	<p>Configure anonftpsync with your favorite editor and change the lines below. These settings will setup a mirror <em>only</em> for amd64 files. You could remove i386 from the excluded architectures, but then a 50Gb image won&#8217;t fit all the files.
<pre class="active4d"><span class="line-numbers">   1 </span> TO=/var/www/debian
<span class="line-numbers">   2 </span> RSYNC_HOST=ftp.<span class="Keyword">fi</span>.debian.org
<span class="line-numbers">   3 </span> RSYNC_DIR=debian
<span class="line-numbers">   4 </span> LOGDIR=/var/log/mirroring
<span class="line-numbers">   5 </span> ARCH_EXCLUDE=<span class="String"><span class="String">&quot;</span>alpha arm hppa hurd-i386 i386 ia64 m68k mipsel mips powerpc s390 sh sparc source<span class="String">&quot;</span></span>
</pre></p>


	<p>Make the log directory.
<pre class="active4d"><span class="line-numbers">   1 </span> mkdir -p /var/log/mirroring
</pre></p>


	<p>Configure nginx by modifying /etc/nginx/nginx.conf with your favorite editor. Just add the autoindex line into server { location / { context
<pre class="active4d"><span class="line-numbers">   1 </span> <span class="LineComment"><span class="LineComment">#</span> abbreviated start of file for clarity...</span>
<span class="line-numbers">   2 </span>     server {
<span class="line-numbers">   3 </span>         listen       80<span class="Operator">;</span>
<span class="line-numbers">   4 </span>         server_name  localhost<span class="Operator">;</span>
<span class="line-numbers">   5 </span> 
<span class="line-numbers">   6 </span>         access_log  /var/log/nginx/localhost.access.log<span class="Operator">;</span>
<span class="line-numbers">   7 </span> 
<span class="line-numbers">   8 </span>         location / {
<span class="line-numbers">   9 </span>             root   /var/www<span class="Operator">;</span>
<span class="line-numbers">  10 </span>             <span class="LineComment"><span class="LineComment">#</span> add the line below to allow directory listing</span>
<span class="line-numbers">  11 </span>             autoindex  on<span class="Operator">;</span>
<span class="line-numbers">  12 </span>             index  index.html index.htm<span class="Operator">;</span>
<span class="line-numbers">  13 </span>         }
<span class="line-numbers">  14 </span>    <span class="LineComment"><span class="LineComment">#</span> abbreviated end of file for clarity...</span>
</pre></p>


	<p>Do the synchronizing. And wait&#8230; for a long while. On a 8/1Mbit cable the first synchronize took roughly 20 hours.
<pre class="active4d"><span class="line-numbers">   1 </span> ./anonftpsync
</pre></p>


	<p>Now modify your /etc/apt/sources.list on existing Xen images to use your local mirror. And remember to create new Xen images using your new mirror :) In the above case the  URL  is http://mirrors.aktagon.com/debian</p>


	<p>NB: there is no public mirrors.aktagon.com available&#8230; sorry.</p>
  </div>

  <div style="font-size: 0.8em;margin:0.5em;">
    
      Tagged <a href="/tags/156-xen">xen</a>, <a href="/tags/108-debian">debian</a>, <a href="/tags/157-etch">etch</a>, <a href="/tags/163-local-mirror">local mirror</a>, <a href="/tags/164-amd64">amd64</a>, <a href="/tags/165-anonftpsync">anonftpsync</a>, <a href="/tags/143-nginx">nginx</a>
    
    
  </div>
</div>



  
<div id="snippet_66" class="snippet">
  <h2><a href="/snippets/66-Quick-step-by-step-on-creating-a-xen-environment-in-Debian-Etch" title="Quick step by step on creating a xen environment in Debian Etch - Shell Script (Bash) - xen, debian, etch, stable, virtualisointi, virtualisering">Quick step by step on creating a xen environment in Debian Etch</a></h2>
  <div class="details">
    <a style="background-color: #FFFF94;" href="http://snippets.aktagon.com/languages/131-Shell-Script-Bash-">
      Shell Script (Bash)</a> posted over 2 years ago by marko
          
  </div>

  <div class="body">
    <p>Jumpstart with Xen out-of-the-box in Debian Etch stable.
<pre class="active4d"><span class="line-numbers">   1 </span> sudo apt-get install xen-tools xen-hypervisor linux-image-xen-amd64 bridge-utils iproute sysfsutils
<span class="line-numbers">   2 </span> <span class="LineComment"><span class="LineComment">#</span> [reboot into xen kernel now]</span>
<span class="line-numbers">   3 </span> sudo xen-create-image --hostname=db2.aktagon.com \
<span class="line-numbers">   4 </span> --size=10Gb --swap=256Mb --ip=10.0.0.51 \
<span class="line-numbers">   5 </span> --netmask=255.255.255.0 --gateway=10.0.0.2 \
<span class="line-numbers">   6 </span> --force --dir=/work/vserver --memory=512Mb \
<span class="line-numbers">   7 </span> --arch=i386 --kernel=/boot/vmlinuz-2.6.18-5-xen-amd64 \
<span class="line-numbers">   8 </span> --debootstrap --dist=etch \
<span class="line-numbers">   9 </span> --mirror=http://ftp.funet.<span class="Keyword">fi</span>/pub/linux/mirrors/debian/ \
<span class="line-numbers">  10 </span> --passwd
<span class="line-numbers">  11 </span> sudo xm create /etc/xen/db1.aktagon.com.cfg
</pre></p>
  </div>

  <div style="font-size: 0.8em;margin:0.5em;">
    
      Tagged <a href="/tags/156-xen">xen</a>, <a href="/tags/108-debian">debian</a>, <a href="/tags/157-etch">etch</a>, <a href="/tags/158-stable">stable</a>, <a href="/tags/225-virtualisointi">virtualisointi</a>, <a href="/tags/226-virtualisering">virtualisering</a>
    
    
  </div>
</div>






