วันจันทร์ที่ 30 สิงหาคม พ.ศ. 2553

mtime, ctime, and atime timestamp Linux

Recently, I've implemented a caching system. This involve removing old file from the cache. One important factor for making a decision is a file timestamp. There are many timestamp implemented in the file system here are method for viewing timestamp info.

mtime, ctime, and atime

atime - access time
mtime - if modify time
ctime - of change time

To view atime

ls -lu

To view ctime

ls -lc

To view mtime

ls -lt

Access time is when last time data from the file was access.

Modify time is when last change was done to the file.

Change time id when you change owner.

Or

Use stat command

stat filename

stat newname2.txt
File: `newname2.txt'
Size: 13 Blocks: 8 IO Block: 4096 regular file
Device: 805h/2053d Inode: 2338058 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2011-01-28 16:01:10.000000000 +0700
Modify: 2011-01-28 16:02:35.000000000 +0700
Change: 2011-01-28 16:06:26.000000000 +0700

to verify with ls command
--
References :

วันพุธที่ 4 สิงหาคม พ.ศ. 2553

Gentoo migration to raid

At some point, high availability become more essential to your server. Raid1(mirror) can help server to be able to continue even the disk go wrong. This blog is intend to be a complete just-type-guide for system admin. I hope that you guy succeeded in this migration

Background my system is gentoo on sda. The new disk will be sdb. After finishing copying data to sdb. The another new disk will be replace as sda. sda and sdb will be raid1 mirroring each other.

#0 move running service to another system
- make sure that the system can be down for maintainance


#1 shutdown system
shutdown -h now

#2 install new hdd as sdb
some vendor disable port B (for sdb) please make sure that it is enable so it can be visible from linux.

#3 boot system with live cd
modprobe raid1

#4 format disk and create raid on sdb
available 500GB
-> sdb1 boot 1GB ext2
-> sdb5 root entire ext3
-> sdb6 swap 4GB swap
cfdisk /dev/sdb
cd /dev && MAKEDEV md
mdadm --create /dev/md1 --level=1 --raid-devices=2 missing /dev/sdb1
mdadm --create /dev/md5 --level=1 --raid-devices=2 missing /dev/sdb5
mke2fs /dev/md1
mke2fs -j /dev/md5
mkswap /dev/sdb6
swapon /dev/sdb6


#5 copy data from sda to raid
mkdir /mnt/gentoo1
mount /dev/sda5 /mnt/gentoo1
mount /dev/md5 /mnt/gentoo
mount /dev/sda1 /mnt/gentoo1/boot
mkdir /mnt/gentoo/boot
mount /dev/md1 /mnt/gentoo/boot
cp -dpRx /mnt/gentoo1/* /mnt/gentoo/


#6 install boot loader to raid
mount -t proc none /mnt/gentoo/proc
mount -o bind /dev /mnt/gentoo/dev
chroot /mnt/gentoo /bin/bash
env-update
source /etc/profile
export PS1=”(chroot) $PS1”
#Edit grub.conf change root=/dev/sdaxx to mdxx
nano /boot/grub/grub.conf
#install boot loader to the disk
grub –no-floppy
- device (hd0) /dev/sdb
- root (hd0,0)
- setup (hd0)

#7 edit fstab to mount disk on raid instead // or just copy from preedit @ /home/username/fstab
nano /etc/fstab

#8 shutdown & replace sda with new disk
exit
cd /
umount /mnt/gentoo/boot /mnt/gentoo/proc /mnt/gentoo/dev /mnt/gentoo
umount /mnt/gentoo1/boot /mnt/gentoo1
shutdown -h now
-replace new disk


#9 sync disk and install boot loader
-change bios priority to start boot from sdb
sfdisk -d /dev/sdb | sfdisk /dev/sda
mdadm --add /dev/md1 /dev/sda1
mdadm --add /dev/md5 /dev/sda5
#edit fstab add sda as swap
nano /etc/fstab
mkswap /dev/sda6
swapon /dev/sda6
grub –no-floppy
- device (hd0) /dev/sda
- root (hd0,0)
- setup (hd0)


#wait until sync finish
- reboot test
- restore bios boot priority
- restore sevice back to the server.

วันศุกร์ที่ 23 เมษายน พ.ศ. 2553

Mounting file as filesystem

Linux provide various and flexible file system for user to choose.

Here are an example

Create empty 10 Mb file.
#dd if=/dev/zero of=file.img bs=1k count=10000

Attach the file to loopback file system
#losetup /dev/loop0 file.img

Create file system on loopback device
#mke2fs -c /dev/loop0 10000

Mount loopback device
#mount -t ext2 /dev/loop0 /mnt/point1

So you can have any file system on any file system.

To find out more detail about file system please visit the following links :
-Anatomy of file system

-Cryptographic File Systems Performance

-Loopback Tricks

วันศุกร์ที่ 12 มีนาคม พ.ศ. 2553

The linux documentation project

Linux newbie might be looking for reliable document for linux.
Here is a good link that worth a look.

Link:
http://tldp.org/guides.html

วันพุธที่ 10 มีนาคม พ.ศ. 2553

Configuring gentoo apache with fcgi

mod php and worker are not stable as PHP official page.

Gentoo user might not aware this because we can compile PHP with threads use flag without realizing the warning.

Before get start with apache-worker fcgid and php. You need the following :
1) installed PHP with cgi use flag.
2) installed mod_fcgid (emerge mod_fcgid)

PHP configuration :
- modify /etc/php/cgi-php5/php.ini to suite your need.

apache configuration :
- modify /etc/apache2/modules.d/20_mod_fcgid.conf adding the following in
AddHandler fcgid-script .php .fcgi
DefaultInitEnv PHPRC "/etc/php/cgi-php5"

IdleTimeout 60
BusyTimeout 120
ProcessLifeTime 360
SpawnScoreUpLimit 2100
MaxProcessCount 2100
DefaultMaxClassProcessCount 2100
IPCConnectTimeout 120
IPCCommTimeout 120

FCGIWrapper /usr/bin/php-cgi .php

Please change the /usr/bin/cgi/ to your path. And don't forget to add +ExecCGI to option directive.

- edit /etc/conf.d/apache2 add -D FCGID to APACHE2_OPTS

restarting apache.

วันอังคารที่ 9 มีนาคม พ.ศ. 2553

Monit : debuging monit process

Misconfiguration on apache can lead monit false alet and do wrong action. I found that some monit process in one of my servers always complaining about apache cannot connect port 80. which is not right cause I can still access the pages.

Here are tip for debugging what goes wrong:

1) stop monit as a daemon
2) smart monit in foreground
#monit -Iv
3) see the message

From my experience, the server response with 403 http code cause monit alert cannot connect host port 80.
So, I change apache config to get 200 code and everything back to work :)

Monit : server monitoring tools

If you have a web server, have you ever experience apache process not responding to http request?

or

How to make sure that apache are running? and If server load go too high please restart it for me.

Monit can help you monitoring common for system admin.


It can monitoring server process, file size, memory server load. And, you can set the appropriate action to those events: sending email, restart process etc.

To install monit
for gentoo :
#emerge -av monit
for debian:
#apt-get install monit

Configuring monit
Locate configuration file : /etc/monitrc or /etc/monit/monitrc
Here is the example configuration for apache with these condition
1) check whether apache is running : if not restart
2) check http:80 is working : if not restart
3) if server go to high : restart apache process
set daemon 120

set mailserver smtp.localhost


set mail-format { from: admin@localhost.com }

set alert systemadmin@localhost.com


check process apache with pidfile /var/run/apache2.pid
start program = "/etc/init.d/apache2 start"
stop program = "/etc/init.d/apache2 stop"
if failed port 80 protocol http then restart
if loadavg(5min) greater than 100 for 2 cycles then restart
alert extrapeople@localhost.com

If you are interested in monit for advance feature please visit monit official site.
check out monit document