How to find out the linux version

Veröffentlicht von Jens am 04. September 2009

Kernel

  1. uname -a

Distributions

Redhat:

  1. cat /etc/redhat-release

Debian:

  1. cat /etc/debian_version

SuSE:

  1. cat /etc/SuSE-release

Remove blank lines with grep

Veröffentlicht von Jens am 23. Februar 2009

  1. grep -v ^$

HOWTO: Install a rails stack with ruby-enterprise and passenger on CentOS

Veröffentlicht von Jens am 22. Februar 2009

Preparations:
Install CentOS with Apache and Mysql.

1. Install ruby enterprise:

  1. wget http://rubyforge.org/frs/download.php/41040/ruby-enterprise-X.X.X-X.tar.gz
  2. tar xzvf ruby-enterprise-X.X.X-X.tar.gz
  3. ./ruby-enterprise-X.X.X-X/installer

2. Create some links:

  1. ln -fs /opt/ruby-enterprise-1.8.6-20080624 /opt/ruby-enterprise
  2. ln -fs /opt/ruby-enterprise/bin/gem /usr/bin/gem
  3. ln -fs /opt/ruby-enterprise/bin/irb /usr/bin/irb
  4. ln -fs /opt/ruby-enterprise/bin/rake /usr/bin/rake
  5. ln -fs /opt/ruby-enterprise/bin/rails /usr/bin/rails
  6. ln -fs /opt/ruby-enterprise/bin/ruby /usr/bin/ruby

3. gem install rails -v 2.X.X

Problems:
I’ve got problems with missing Mysql libraries. To fix this:

3.1 Install mysql-devel

  1. yum install mysql-devel

3.2 Install mysql-gem

  1. /opt/ruby-enterprise-1.8.6-20080624/bin/ruby /opt/ruby-enterprise-1.8.6-20080624/bin/gem install mysql — –with-mysql-include=/usr/include/mysql –with-mysql-lib=/usr/lib64/mysql

4. Passenger (mod_rails)

4.1 Install Passenger (mod_rails)

  1. gem install passenger

4.2 Passenger Apache Module

  1. passenger-install-apache2-module

5. ImageMagick

5.1 Install ImageMagick Libraries

  1. yum install ImageMagick-devel

5.2 Install rmagick via gems

  1. sudo gem install –no-rdoc –no-ri –no-update-sources rmagick -v 1.15.15

Problems:

Parameter –version doesn’t work.
Don’t use the parameter “–version”

Read more about this problem:
http://www.beanlogic.co.uk/2008/8/13/installing-a-specific-verison-of-rmagick

Missing msfonts

Installation of msfonts according to:
http://hi.baidu.com/rainchen/blog/item/089ef7364497de320a55a9a3.html

  1. wget http://www.osresources.com/files/centos-windows-fonts/msfonts.tbz
  2. mkdir /usr/share/fonts/default/TrueType
  3. tar xvjpf msfonts.tbz -C /usr/share/fonts/default/TrueType/

6. Config of apache and your rails app
For configuration of passenger follow the instructions there

Thats it!

Set up ssh key pairs

Veröffentlicht von Jens am 19. Dezember 2008

With ssh key pairs you can easier login to your servers.

To generate an ssh key pair you´ll need to run the following line in your terminal:

  1. ssh-keygen -t dsa

It will ask you for location and pass phrase. You should accept the default location (~/.ssh/id_dsa.pub). For the pass phrase I usually just press return. Then the private key will have a blank pass phrase and you can login to your servers without a password. Comfort vs. security. Your choice.

After this you need to upload the public key to the server.

To generate an ssh key pair you’ll need to run the following line in your terminal:

  1. scp ~/.ssh/id_dsa.pub you@yourserver.com:

Finally login to the server and append the public key to authorized keys:

  1. ssh you@yourserver.com
  2. mkdir .ssh          # if it's not already there
  3. cat id_dsa.pub >> .ssh/authorized_keys
  4. rm id_dsa.pub       # cleanup

Make sure that the .ssh folder and the authorized_keys have the right permissions:

  1. chmod 700 ~/.ssh
  2. chmod 600 ~/.ssh/authorized_keys

After this, you should be able to login to the server and use scp without having to enter a password.

If you login or copy files to your servers a lot, you can setup an alias in ~/.ssh/config (on your local machine):

  1. Host ys
  2. HostName yourserver.com
  3. User you

Easy backup and cleanup for logfiles

Veröffentlicht von Jens am 03. Dezember 2008

For your applications in production you should keep some logfiles but delete the older ones to save files space.

The following bash script will do the job.

It will zip all files older than 7 days.
Delete all files older than 30 days.
Folders will be ignored.

  1. #!/bin/bash
  2.  
  3. directory="/application/log"
  4. old="7"
  5. older="30"
  6. find $directory -mtime +$old -exec gzip {} \;
  7. find $directory -mtime +$older -exec rm {} \;

I call the script in the crontab like this:

  1. /usr/sbin/clean-log.sh > /dev/null 2>&1

Display the TOTAL harddisk size in linux

Veröffentlicht von Jens am 28. November 2008

Use fdisk to do the trick:

  1. fdisk -l | grep Disk

The output will be something like the following:

  1. Disk /dev/sda: 10.7 GB, 10737418240 bytes
  2. Disk /dev/sdb: 53.6 GB, 53687091200 bytes