Wednesday, September 23, 2009

Screen as window manager

In case that you didn't know screen is a window manager and a very useful one however for consoles ...
This is my .screenrc file

hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]'
# Default screens
screen -t shell1 0
screen -t shell2 1
screen -t shell3 2
screen -t shell4 3

To switch between screens type CTRL+a 0 - goes on screen 0 - replace 0 with 1-3 to end up on a different window(screen)

To detach is a simple CTRL+a d - this will put screen into the background and you can reatach with
screen -r or if you have multiple sessions
screen -ls will list the screens that you have running and then
screen -r sessionName

Monday, September 21, 2009

Simple benchmark programs for Linux

In case that you want to test a new server for disk performance you
can do it very quickly with the following tools

bonnie++ from http://www.coker.com.au/bonnie++/
iozone from http://www.iozone.org/

These two will make different tests to your file systems.

Also you can use hdparam (do hdparam --help for all the options)
This is an example from a very old computer with SATA2

# hdparm -t /dev/sda

/dev/sda:
Timing buffered disk reads: 170 MB in 3.03 seconds = 56.06 MB/sec

Thursday, September 17, 2009

Create from scratch a Xen image [Part-1]

This is a mini howto on creating from scratch a xen domU guest system cloning the
hostOS.

What you need:

- have a host os which runs xen in dom0 (you can install a centOS and choose virtualization as profile)
- some disk space (i put 20Gb for the / and 2 for swap)
- run the following two commands to set the volumes

pvcreate /dev/sda7 -- change the /dev/sda7 with whatever you want to
vgcreate VolGroup00 /dev/sda7 -- change the /dev/sda7 with whatever you want to

if unsure what to do look it on on how to create volumes in linux (google it ... )



The following script will create you and image:

#!/bin/sh

##########################################
echo $0 "Starting"                       #
echo "This script will clone the guestOS #
creating a new xen image"                #
#
# echo "Author: dioda11@gmail.com"       #
##########################################

if [ $@ ne 1 ]; then
echo "please give a numeric identifier for the clone
between 10 and 100"
exit 1;
# if ![ $1 lt 100 ]  
fi

IMGID=$1
BASEDIRMOUNT=/mnt

VOLGROUP=VolGroup00

lvcreate  -L 20G -n   LV_VM$IMGID_RH5.3_ROOT   $VOLGROUP
lvcreate  -L 2G -n   LV_VM$IMGID_RH5.3_SWAP  $VOLGROUP

mkfs.ext3  /dev/$VOLGROUP/LV_VM$IMGID_RH5.3_ROOT
mkswap  /dev/$VOLGROUP/LV_VM$IMGID_RH5.3_SWAP


if [ -d $BASEDIRMOUNT/$IMGID ]; then
mount /dev/$VOLGROUP/LV_VM$IMGID_RH5.3_ROOT $BASEDIRMOUNT/$IMGID
echo "Mounting the /dev/$VOLGROUP/LV_VM$IMGID_RH5.3_ROOT was " $? 
else
mkdir -p $BASEDIRMOUNT/$IMGID
echo "Creating $BASEDIRMOUNT/$IMGID was  " $?
mount /dev/$VOLGROUP/LV_VM$IMGID_RH5.3_ROOT $BASEDIRMOUNT/$IMGID
echo "Mounting the /dev/$VOLGROUP/LV_VM$IMGID_RH5.3_ROOT was " $? 
fi


echo "Cloning the host OS === "

ARCH=`uname -m`

if [ $ARCH == "x86_64" ]; then 
cp -ax /{bin,dev,etc,lib,lib64,root,sbin,usr,var} $BASEDIRMOUNT/$IMGID
else 
cp -ax /{bin,dev,etc,lib,root,sbin,usr,var} $BASEDIRMOUNT/$IMGID
fi

mkdir $BASEDIRMOUNT/$IMGID/{home,proc,opt,sys,tmp}
chmod 777 $BASEDIRMOUNT/$IMGID/tmp

echo "Cloning finished === " $?


echo "At this point you need to fix the /etc/fstab and create the xen config file"

# umount $BASEDIRMOUNT/$IMGID

------------------------

Friday, August 21, 2009

CakePHP - start a project with the console application

To start fast a new project with cakephp 1.2 you will need:

- web server - I use apache 2.2
- php4 or php5 - I use php5
- mysql server - I use mysql 5.0.45
- cakephp - I use cake_1.2.4.8284

After the web and mysql servers are installed install the cakephp - I choosed the path

/var/www/frameworks/cake_1.2.4.8284

Then open a xterm or any shell:

cd /var/www/frameworks/cake_1.2.4.8284/cake/console
cake bake help

Will give you all the info you need to know on how to bootstrap your new project.
I choosed the following:

cake bake project
Then just answer the questions that cake asks:


Welcome to CakePHP v1.2.4.8284 Console
---------------------------------------------------------------
App : app
Path: /var/www/frameworks/cake_1.2.4.8284/app
---------------------------------------------------------------
What is the full path for this app including the app directory name?
Example: /var/www/frameworks/cake_1.2.4.8284/app/myapp
[/var/www/frameworks/cake_1.2.4.8284/app/myapp] > /var/www/frameworks/cake_1.2.4.8284/app/slash0
Bake Project
Skel Directory: /var/www/frameworks/cake_1.2.4.8284/cake/console/libs/templates/skel
Will be copied to: /var/www/frameworks/cake_1.2.4.8284/app/slash0
---------------------------------------------------------------
Look okay? (y/n/q)
[y] > y
Do you want verbose output? (y/n)
[n] > n
---------------------------------------------------------------
Created: slash0 in /var/www/frameworks/cake_1.2.4.8284/app/slash0
---------------------------------------------------------------

Creating file /var/www/frameworks/cake_1.2.4.8284/app/slash0/views/pages/home.ctp
Wrote /var/www/frameworks/cake_1.2.4.8284/app/slash0/views/pages/home.ctp
Welcome page created
Random hash key created for 'Security.salt'
CAKE_CORE_INCLUDE_PATH set to /var/www/frameworks/cake_1.2.4.8284 in webroot/index.php
CAKE_CORE_INCLUDE_PATH set to /var/www/frameworks/cake_1.2.4.8284 in webroot/test.php
Remember to check these value after moving to production server



Change myapp to whatever name you want to have for the app.I put slash0.
At this point the application project is created into the path you specified.

/var/www/frameworks/cake_1.2.4.8284/app/slash0

From now on all you have to do is follow the cakephp book on how to develop :)
See http://book.cakephp.org

Monday, August 17, 2009

ssh-agent(ssh-add) from X under Gnome and CentOS5

Ok you connect to multiple servers and want NOT to type your very secret passphrase every time you
connect to a server.
If you use any type of X window manager is very easy to use a the file

$HOME/.xinitrc in which you have the following

exec ssh-agent

Then after you login into GNOME/KDE etc open a xterm, kterm or any other xterminal and type
ssh-add - you will be prompted to input your secret passphrase.

Be aware that if you don't have any type of keys into your $HOME/.ssh then all the above won't work
because ssh-add needs to have some keys to work with.

In case you need to generate keys is simple:

open a shell

$ssh-keygen -t rsa -b 1024 -- will make you a rsa key 1024 bits
$ssh-keygen -t dsa -b 1024 -- will make you a dsa key 1024 bits

Friday, August 14, 2009

Small size powerful editor for Windows - Notepad++

If you are looking for a powerful editor for windows that understands a large number of
programming languages - Notepad++ -
is very good.

I use it mainly for php but has support for so much more.

Thursday, August 13, 2009

My .vimrc file for vim text editor

I tried a few big names editors but I tell you what for *nix console is nothing else like vi (new vi called vim) ... ok I admit perhaps emacs-nox but I don't use it.

In order to get a little from a lot of options of vim I'll show you my .vimrc file

set softtabstop=2
set shiftwidth=2
set expandtab
set cindent
set smartindent
set autoindent
syntax enable

This enables the indentation and puts spaces instead of tab characters into the file.

For more info see - the following

https://github.com/dioda11/dotfiles

Common tasks with OpenVZ

You just want to skip all the reading about OpenVZ and start using it ?!
This is just for you.
It will install the openvz kernel and utilities and have a container ready.
Feel free to execute all or just a few commands.

### 
# info http://wiki.openvz.org/Quick_installation
# install script

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

# edit grub.conf if you want to change labels etc

reboot

yum install vzctl vzquota
/sbin/service vz start


### 
# info http://wiki.openvz.org/OS_template_cache_preparation
# os templates

# to make templates
# utilities
yum install vzpkg vzyum vzrpm43-python vzrpm44-python vzctl-lib

# metadata
yum search vztmpl

# create cache
vzpkgcache centos-4-i386-minimal



# Precreated template cache 
# YOU NEED TO DO THIS - there are many templates
# download from http://wiki.openvz.org/Download/template/precreated


#  Create and start a container 
# To create and start a container, run the following commands:
# 
# [host-node]# vzctl create CTID --ostemplate osname
# [host-node]# vzctl set CTID --ipadd a.b.c.d --save
# [host-node]# vzctl set CTID --nameserver a.b.c.d --save
# [host-node]# vzctl start CTID
# 

###########
vzctl create 1 --ostemplate centos-5-x86
vzctl set 1 --ipadd 10.0.51.254 --save
vzctl set  1 --nameserver 192.168.1.20 --save
vzctl start 1


# Here CTID is the numeric ID for the container; osname is the name of the OS template for the container, and a.b.c.d is the IP address to be assigned to the container.
# Your freshly-created container should be up and running now; you can see its processes:
# 
[host-node]# vzctl exec CTID ps ax
# 
# Enter to and exit from the container
# 
# To enter container give the following command:
# 
[host-node]# vzctl enter CTID
# entered into container CTID
# [container]#
# 
# To exit from container, just type exit and press Enter:
# 
[container]# exit
# exited from container VEID
# [host-node]#
# 
# Stop and destroy the container
# 
# To stop container:
# 
[host-node]# vzctl stop CTID
# Stopping container ...
# Container was stopped
# Container is unmounted
# 
# And to destroy container:
# 
[host-node]# vzctl destroy CTID
# Destroying container private area: /vz/private/CTID
# Container private area was destroyed
#