How to install sar on Debian
First install the sysstat package which includes sar:
1 apt-get install sysstat
Then run crontab -e and add the following to collect stats:
1 # Collect measurements at 10-minute intervals 2 0,10,20,30,40,50 * * * * /usr/lib/sa/sa1 3 # Create daily reports and purge old files 4 0 0 * * * /usr/lib/sa/sa2 -A
You now have access to IO and CPU usage history.
How to install and use the Sphinx search engine and acts_as_sphinx plugin on Debian Etch
Inspiration for this snippet was taken from this post on the Sphinx forum, plus this blog post.
Compiling Sphinx
First install the prerequisites:
1 sudo aptitude install libmysql++-dev libmysqlclient15-dev checkinstall
Next download sphinx, libstemmer and install everything and the fish:
1 cd /usr/local/src 2 3 wget http://sphinxsearch.com/downloads/sphinx-0.9.8-rc2.tar.gz 4 tar zxvf sphinx-0.9.8-rc2.tar.gz 5 6 cd sphinx-0.9.8-rc2/ 7 8 # Add stemming support for Swedish, Finnish and other fun languages. 9 wget http://snowball.tartarus.org/dist/libstemmer_c.tgz 10 tar zxvf libstemmer_c.tgz 11 12 ./configure --with-libstemmer 13 make 14 15 make install
Configure Sphinx
Create a sphinx.conf file in your Rails config directory, as described here, or use this template.
Install acts_as_sphinx plugin
1 ./script/plugin install http://svn.datanoise.com/acts_as_sphinx
Add acts_as_sphinx to your model:
1 class Documents 2 acts_as_sphinx 3 end
Indexing content
1 rake sphinx:index 2 3 (in /var/www/xxx.com/releases/20080429144230) 4 Sphinx 0.9.8-rc2 (r1234) 5 Copyright (c) 2001-2008, Andrew Aksyonoff 6 7 using config file './sphinx.conf'... 8 indexing index 'xxx.com'... 9 collected 5077 docs, 0.6 MB 10 sorted 0.1 Mhits, 100.0% done 11 total 5077 docs, 632096 bytes 12 total 0.160 sec, 3950427.25 bytes/sec, 31729.86 docs/sec
Reindexing content
sphinx:index shouldn’t be run while the searchd process is running, so use rake sphinx:rotate instead, which restarts the searchd process after indexing.
Starting the daemon
1 mkdir -m 664 /var/log/sphinx 2 rake sphinx:start 3 4 (in /var/www/xxx.com/releases/20080429144230) 5 Sphinx 0.9.8-rc2 (r1234) 6 Copyright (c) 2001-2008, Andrew Aksyonoff 7 8 using config file './sphinx.conf'... 9 Sphinx searchd server started.
Searching
1 Documents.find_with_sphinx 'why did I write this'
nginx startup script for Debian
1 sudo vim /etc/init.d/nginx
Paste in the following (remember to run ‘set :paste’ in VIM when pasting):
1 #! /bin/sh 2 ## 3 # nginx start script 4 ## 5 6 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 7 DAEMON=/usr/local/sbin/nginx 8 NAME=nginx 9 DESC=nginx 10 11 if [ ! -x $DAEMON ] 12 then 13 echo "Couldn't find $DAEMON. Please set path to DAEMON." 14 exit 0 15 fi 16 17 18 # Include nginx defaults if available 19 if [ -f /etc/default/nginx ] ; then 20 . /etc/default/nginx 21 fi 22 23 set -e 24 25 case "$1" in 26 start) 27 echo -n "Starting $DESC: " 28 start-stop-daemon --start --pidfile /var/run/$NAME.pid \ 29 --exec $DAEMON -- $DAEMON_OPTS 30 echo "$NAME." 31 ;; 32 stop) 33 echo -n "Stopping $DESC: " 34 start-stop-daemon --stop --pidfile /var/run/$NAME.pid \ 35 --exec $DAEMON 36 echo "$NAME." 37 ;; 38 restart|force-reload) 39 echo -n "Restarting $DESC: " 40 start-stop-daemon --stop --pidfile \ 41 /var/run/$NAME.pid --exec $DAEMON 42 sleep 1 43 start-stop-daemon --start --pidfile \ 44 /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS 45 echo "$NAME." 46 ;; 47 reload) 48 echo -n "Reloading $DESC configuration: " 49 start-stop-daemon --stop --signal HUP --pidfile /var/run/$NAME.pid \ 50 --exec $DAEMON 51 echo "$NAME." 52 ;; 53 *) 54 N=/etc/init.d/$NAME 55 echo "Usage: $N {start|stop|restart|force-reload}" >&2 56 exit 1 57 ;; 58 esac 59 60 exit 0
Now make the script executable with this command:
1 sudo chmod 755 /etc/init.d/nginx
Lastly, run this command to make the script run when the server starts and stops:
1 sudo /usr/sbin/update-rc.d -f nginx defaults
Installing Rails, mongrel and mongrel_cluster on Debian
DRAFT …
Install RubyGems
1 http://rubyforge.org/frs/download.php/29548/rubygems-1.0.1.tgz 2 3 tar zxvf rubygems-1.0.1.tgz 4 5 cd rubygems-1.0.1 6 7 ruby setup.rb
Install Rails
1 gem install rails
Install sqlite3 (optional)
1 apt-get install sqlite3 libsqlite3-dev 2 gem install sqlite3-ruby
Install mongrel and mongrel_cluster
1 $ gem install mongrel mongrel_cluster 2 3 $ mongrel_rails cluster::configure -e production \ 4 -p 8000 \ 5 -a 127.0.0.1 \ 6 -N 3 \ 7 -c /var/www/xyz/current 8 9 10 $ mongrel_rails cluster::start 11 12 13 $ useradd -g www-data -d /var/www mongrel
Surviving reboots
1 sudo mkdir /etc/mongrel_cluster 2 3 sudo ln -s /var/www/xyz/config/mongrel_cluster.yml /etc/mongrel_cluster/xyz.yml 4 5 sudo cp /usr/local/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5/resources/mongrel_cluster /etc/init.d/ 6 7 sudo chmod +x /etc/init.d/mongrel_cluster 8 9 sudo /usr/sbin/update-rc.d -f mongrel_cluster defaults 10 11 mongrel_cluster_ctl status
Stale pids
If your mongrels crash or if you kill them, mongrel_cluster won’t start your mongrels because mongrel_cluster believes the processes are still running, instead mongrel_cluster complains and does nothing:
1 ** !!! PID file tmp/pids/mongrel.8000.pid already exists. Mongrel could be running already. Check your log/mongrel.8000.log for errors. 2 ** !!! Exiting with error. You must stop mongrel and clear the .pid before I'll attempt a start.
To fix this simply add the —clean switch to the /usr/local/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5/resources/mongrel_cluster startup script:
1 mongrel_cluster_ctl start -c $CONF_DIR --clean
Compiling Ruby with OpenSSL, Zlib and Readline support on Debian
DRAFT … From http://blog.fiveruns.com/2008/3/3/compiling-ruby-rubygems-and-rails-on-ubuntu
Install pre-requisites
1 apt-get -y install build-essential libssl-dev libreadline5-dev zlib1g-dev
Download and install
1 cd /usr/local/src 2 3 wget http://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6.tar.gz 4 5 tar zxvf ruby-1.8.6.tar.gz 6 7 cd ruby-1.8.6.tar.gz 8 9 ./configure --prefix=/usr/local --with-openssl-dir=/usr --with-readline-dir=/usr --with-zlib-dir=/usr 10 11 make 12 make install 13 14 ruby -ropenssl -rzlib -rreadline -e "puts :success" 15