วันพุธที่ 27 ตุลาคม พ.ศ. 2553

split /var/log/message log

I'm using gentoo and vixie-cron as a system cron. After using it for a while, I found that gentoo store cron log in to /var/log/message. And, I just kind of like to split this for monitoring easily. Here is what I have done.

edit this :
/etc/syslog-ng/syslog-ng.conf

add the following lines :
filter f_cron { facility (cron); };
destination cron { file("/var/log/cron.log"); };
log { source(src); filter(f_cron); destination(cron); };

reload syslog-ng :
/etc/init.d/syslog-ng reload

you may need to setting the logrotate. Please see the example in /etc/logrotate.d/ for example

วันอังคารที่ 19 ตุลาคม พ.ศ. 2553

terminal key map

Some ssh client need config for special button.
You can use this value to map the keyboard button to this value perform function properly.

Home \033[1~
Delete \033[3~
End \033[4~
Page Up \033[5~
Page Down \033[6~

วันพุธที่ 6 ตุลาคม พ.ศ. 2553

find command with -exec options

find command is quite a handy tool for file searching. It can also include an command to execute for matched file with

1) -exec command ;
2) -exec command {} +

Both are different.
Let say you have 3 files, a b c in the directory.

#find . -exec echo '{}' >> tmp1 \;
output in tmp1 will be :
.
./b
./a
./c
./tmp1

#find . -exec echo '{}' >> tmp2 \+;
output in tmp2 will be :
a b c

with + all matched file will be append and execute once.
with ; all matched file will be execute for each matching.

วันศุกร์ที่ 10 กันยายน พ.ศ. 2553

Gentoo prebuilt package installation

With gentoo, you can customize every packages you want because gentoo give that choices to you. Emerge, package manager, will built package for you from source code. However, compiling package in gentoo can be very time-consuming task, Especially, when you have more gentoo system. I have found option of emerge that can build package and you can use this prebuilt package to other system.

(1) build package
#quickpkg mysql
- This will build package from files on your system. If the package you wanna built are on the system already.


#emerge -b mysql
-the -b(--buildpkg) option tell emerge to do additional task when installing package to the system.

*In this case(mysql), the prebuilt package will be available in /usr/portage/packages/dev-db/ directory.

(2) use prebuilt package
Place the prebuilt package in appropriate directory, in this case : /usr/portage/packages/dev-db/
#emerge --usepkgonly mysql

For more information please consult the man page :
#man emerge
#man quickpkg
#man make.conf

วันอังคารที่ 7 กันยายน พ.ศ. 2553

Install windows font in linux(ubuntu)

Linux user cannot avoid living with windows user. That make linux users to adjust ourselves to read file from windows including fonts they using.

(1) using font package
#sudo apt-get install msttcorefonts

#sudo fc-cache -fv


(2) copying font files from windows
copy *.ttf font to /usr/share/fonts/truetype/thai

#fc-cache -fv

reference
1. ms-font package installation [here]

วันจันทร์ที่ 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.