linux

linux

Selasa, 28 Februari 2012

test koneksi di linux

for tes conection use ping to destination server :
for monitoring connection :
1. the sequance number ( green colour )
2.time ( blue colour )
3.packet loss ( yellow colour )
4.packet error ( pink colour )

root@<o000o>:/# ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.174 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.171 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=0.147 ms
64 bytes from 192.168.1.1: icmp_seq=4 ttl=64 time=0.148 ms
64 bytes from 192.168.1.1: icmp_seq=5 ttl=64 time=0.149 ms
^C
--- 192.168.1.1 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4000ms
rtt min/avg/max/mdev = 0.147/0.157/0.174/0.019 ms

64 bytes from 172.16.0.25: icmp_seq=65100 ttl=64 time=0.718 ms
64 bytes from 172.16.0.25: icmp_seq=65101 ttl=64 time=0.638 ms
64 bytes from 172.16.0.25: icmp_seq=65102 ttl=64 time=0.639 ms
64 bytes from 172.16.0.25: icmp_seq=65103 ttl=64 time=0.521 ms

--- 172.16.0.25 ping statistics ---
261711 packets transmitted, 261008 received, +198 errors, 0% packet loss, time 261709076ms
rtt min/avg/max/mdev = 0.356/0.498/468.511/1.706 ms, pipe 3
64 bytes from 172.16.0.25: icmp_seq=625 ttl=64 time=0.562 ms
64 bytes from 172.16.0.25: icmp_seq=626 ttl=64 time=0.546 ms
64 bytes from 172.16.0.25: icmp_seq=627 ttl=64 time=0.548 ms
64 bytes from 172.16.0.25: icmp_seq=628 ttl=64 time=0.971 ms

--- 172.16.0.25 ping statistics ---
628 packets transmitted, 602 received, 4% packet loss, time 626995ms
rtt min/avg/max/mdev = 0.540/1.079/53.770/3.836 ms

root@<o000o>:/# ping -c 9 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.186 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.166 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=0.164 ms
64 bytes from 192.168.1.1: icmp_seq=4 ttl=64 time=0.165 ms
64 bytes from 192.168.1.1: icmp_seq=5 ttl=64 time=0.173 ms
64 bytes from 192.168.1.1: icmp_seq=6 ttl=64 time=0.164 ms
64 bytes from 192.168.1.1: icmp_seq=7 ttl=64 time=0.173 ms
64 bytes from 192.168.1.1: icmp_seq=8 ttl=64 time=0.163 ms
64 bytes from 192.168.1.1: icmp_seq=9 ttl=64 time=0.163 ms

--- 192.168.1.1 ping statistics ---
9 packets transmitted, 9 received, 0% packet loss, time 7999ms
rtt min/avg/max/mdev = 0.163/0.168/0.186/0.015 ms

ping for steess network :

root@<o000o>:/# ping -c 1000 -f -n 192.168.188.21
PING 192.168.188.21 (192.168.188.21) 56(84) bytes of data.

--- 192.168.188.21 ping statistics ---
1000 packets transmitted, 1000 received, 0% packet loss, time 661ms
rtt min/avg/max/mdev = 0.509/0.647/2.210/0.164 ms, ipg/ewma 0.661/0.613 ms


 stress network with large packet :

root@<o000o>:/# ping -s 512 -c 1000 -f -n 192.168.188.21
PING 192.168.188.21 (192.168.188.21) 512(540) bytes of data.

--- 192.168.188.21 ping statistics ---
1000 packets transmitted, 1000 received, 0% packet loss, time 1311ms
rtt min/avg/max/mdev = 1.242/1.292/1.664/0.068 ms, ipg/ewma 1.313/1.339 ms

for recording route :

root@<o000o>:/# ping -c 2  -R 192.168.21.8
PING 192.168.21.8 (192.168.21.8) 56(124) bytes of data.
64 bytes from 192.168.21.8: icmp_seq=1 ttl=62 time=8.65 ms
RR:     192.168.1.191
        172.16.0.57
        192.168.21.201
        192.168.21.8
        192.168.21.8
        172.16.0.58
        192.168.1.1
        192.168.1.191

64 bytes from 192.168.21.8: icmp_seq=2 ttl=62 time=8.66 ms      (same route)

Senin, 20 Februari 2012

konsole xterm setting

to create monitoring for many server use xterm





 create script like bellow with user non root
create file with name xtermtest

$nano xtermtest

#!/bin/sh
xterm -geometry  65x8 -title bandung -bg OliveDrab3 -e "ping 10.0.10.51"  &
sleep 1
xterm -geometry  65x8 -title surabaya -bg chartreuse4   -e "ping 10.0.10.52" &
sleep 1
xterm -geometry  65x8 -title semarang -bg DarkOliveGreen  -e "ping 10.0.10.53" &
sleep 1
xterm -geometry  65x8 -title makasar -bg SeaGreen4 -e "ping 10.0.10.54" &
sleep 1
xterm -geometry  65x8 -title medan -bg cyan4  -e "ping 10.0.10.55" &
sleep 1
xterm -geometry  65x8 -title solo -bg cyan4  -e "ping 10.0.10.56" &
sleep 1
xterm -geometry  65x8 -title bsd -bg SeaGreen4  -e "ping 10.0.10.57" &
sleep 1
xterm -geometry  65x8 -title puri -bg DarkOliveGreen -e "ping 10.0.10.58" &
sleep 1
xterm -geometry  65x8 -title malang -bg cyan4  -e "ping 10.0.10.59" &
sleep 1
xterm -geometry  65x8 -title pluit -bg chartreuse4 -e "ping 10.0.10.60" &
sleep 1
xterm -geometry  65x8 -title manado -bg OliveDrab3  -e "ping 10.0.10.61" &
sleep 1
xterm -geometry  65x8 -title pekanbaru -bg SeaGreen4  -e "ping 10.0.10.62" &
sleep 1
xterm -geometry  65x8 -title pontianak -bg DarkOliveGreen  -e "ping 10.0.10.63" &
sleep 1
xterm -geometry  65x8 -title balikpapan -bg SeaGreen4  -e "ping 10.0.10.64" &
sleep 1
xterm -geometry  65x8 -title kelapagading -bg cyan4  -e "ping 192.168.21.8" &

$su -
password:

#chmod a+x xtermtest

$./xtermtest

enjoy your new konsole :)

for detail color you can see at http://critical.ch/xterm/













Jumat, 17 Februari 2012

performance server

there are some item must be look at server performance
1.cpu
2.memory
3.Haddisk
4.ethernet

for first use nmon

Senin, 13 Februari 2012

Linux beginner / Pemula

melihat lokasi

#pwd

melihat isi direktori
#ls
#ls -a
#ls -l

masuk ke direktori

cd nama_direktori

membuat direktori
mkdir nama_file

increase size mdadm

This just my note  how to increase array raid from 54G to 80G
it was work without lost data
just follow this steps
 
root@HO-1-231:~# fdisk -l | grep dev                                                                                        
Disk /dev/md0 doesn't contain a valid partition table                                                                       
Disk /dev/sdc doesn't contain a valid partition table                                                                       
Disk /dev/sdd doesn't contain a valid partition table                                                                       
Disk /dev/sda: 2000.4 GB, 2000398934016 bytes                                                                               
/dev/sda1               1      243201  1953512001   fd  Linux raid autodetect                                               
Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes                                                                               
/dev/sdb1               1      243201  1953512001   fd  Linux raid autodetect                                               
Disk /dev/md0: 2000.4 GB, 2000396222464 bytes                                                                               
Disk /dev/sdc: 2000.4 GB, 2000398934016 bytes                                                                               
Disk /dev/sdd: 2000.4 GB, 2000398934016 bytes                                                                               
root@HO-1-231:~# fdisk /dev/sdc                                                                                             
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel                                          
Building a new DOS disklabel with disk identifier 0x5ce337a5.                                                               
Changes will remain in memory only, until you decide to write them.                                                         
After that, of course, the previous content won't be recoverable.                                                           

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted. 

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to  
         sectors (command 'u').                                         

Command (m for help): p

Disk /dev/sdc: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes   
Disk identifier: 0x5ce337a5                           

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action         
   e   extended        
   p   primary partition (1-4)
p                             
Partition number (1-4): 1     
First cylinder (1-243201, default 1): 
Using default value 1                 
Last cylinder, +cylinders or +size{K,M,G} (1-243201, default 243201): +50G

Command (m for help): p

Disk /dev/sdc: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes   
Disk identifier: 0x5ce337a5                           

   Device Boot      Start         End      Blocks   Id  System

/dev/sdc1               1        6528    52436128+  83  Linux 
Partition 1 does not start on physical sector boundary.       

Command (m for help): t
Selected partition 1   
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): p

Disk /dev/sdc: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes   
Disk identifier: 0x5ce337a5                           

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1        6528    52436128+  fd  Linux raid autodetect
Partition 1 does not start on physical sector boundary.                      

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.                             
root@HO-1-231:~# fdisk /dev/sdd            
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x3c581631.                     
Changes will remain in memory only, until you decide to write them.               
After that, of course, the previous content won't be recoverable.                 

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted. 

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to  
         sectors (command 'u').                                         

Command (m for help): p

Disk /dev/sdd: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes   
Disk identifier: 0x3c581631                           

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action         
   e   extended        
   p   primary partition (1-4)
p                             
Partition number (1-4): 1     
First cylinder (1-243201, default 1): 
Using default value 1                 
Last cylinder, +cylinders or +size{K,M,G} (1-243201, default 243201): +50G

Command (m for help): p

Disk /dev/sdd: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes   
Disk identifier: 0x3c581631                           

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1        6528    52436128+  83  Linux 
Partition 1 does not start on physical sector boundary.       

Command (m for help): t
Selected partition 1   
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): p

Disk /dev/sdd: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes   
Disk identifier: 0x3c581631                           

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1        6528    52436128+  fd  Linux raid autodetect
Partition 1 does not start on physical sector boundary.                      

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.                             
root@HO-1-231:~# fdisk -l | grep dev
Disk /dev/md0 doesn't contain a Valid partition table
Disk /dev/sda: 2000.4 GB, 2000398934016 bytes        
/dev/sda1               1      243201  1953512001   fd  Linux raid autodetect
Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes                                
/dev/sdb1               1      243201  1953512001   fd  Linux raid autodetect
Disk /dev/md0: 2000.4 GB, 2000396222464 bytes                                
Disk /dev/sdc: 2000.4 GB, 2000398934016 bytes                                
/dev/sdc1               1        6528    52436128+  fd  Linux raid autodetect
Disk /dev/sdd: 2000.4 GB, 2000398934016 bytes                                
/dev/sdd1               1        6528    52436128+  fd  Linux raid autodetect
root@HO-1-231:~# mdadm --create /dev/md1 --verbose --level=raid1 --raid-devices=2 /dev/sdc1 /dec/sdd1
mdadm: Cannot open /dec/sdd1: No such file or directory                                              
mdadm: create aborted                                                                                
root@HO-1-231:~# mdadm --create /dev/md1 --verbose --level=raid1 --raid-devices=2 /dev/sdc1 /dev/sdd1
mdadm: size set to 52436032K                                                                         
mdadm: array /dev/md1 started.                                                                       
root@HO-1-231:~# cat /proc/mdstat                                                                    
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] [multipath]                
md1 : active raid1 sdd1[1] sdc1[0]                                                                   
      52436032 blocks [2/2] [UU]                                                                     
      [>....................]  resync =  1.1% (599232/52436032) finish=7.2min speed=119846K/sec      
                                                                                                     
md0 : active raid1 sda1[1] sdb1[0]                                                                   
      1953511936 blocks [2/2] [UU]                                                                   
                                                                                                     
unused devices: <none>                                                                               
root@HO-1-231:~# cat /proc/mdstat                                                                    
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] [multipath]                
md1 : active raid1 sdd1[1] sdc1[0]                                                                   
      52436032 blocks [2/2] [UU]                                                                     
      [>....................]  resync =  1.4% (755520/52436032) finish=9.1min speed=94440K/sec       
                                                                                                     
md0 : active raid1 sda1[1] sdb1[0]                                                                   
      1953511936 blocks [2/2] [UU]                                                                   
                                                                                                     
unused devices: <none>                                                                               
root@HO-1-231:~# cat /proc/mdstat                                                                    
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] [multipath]                
md1 : active raid1 sdd1[1] sdc1[0]                                                                   
      52436032 blocks [2/2] [UU]                                                                     
      [>....................]  resync =  2.6% (1403328/52436032) finish=8.4min speed=100237K/sec     
                                                                                                     
md0 : active raid1 sda1[1] sdb1[0]                                                                   
      1953511936 blocks [2/2] [UU]                                                                   
                                                                                                     
unused devices: <none>                                                                               
root@HO-1-231:~# cat /proc/mdstat                                                                    
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] [multipath]                
md1 : active raid1 sdd1[1] sdc1[0]                                                                   
      52436032 blocks [2/2] [UU]                                                                     
      [>....................]  resync =  3.2% (1691072/52436032) finish=9.5min speed=89003K/sec      
                                                                                                     
md0 : active raid1 sda1[1] sdb1[0]                                                                   
      1953511936 blocks [2/2] [UU]                                                                   
                                                                                                     
unused devices: <none>                                                                               
root@HO-1-231:~# cat /proc/mdstat                                                                    
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] [multipath]                
md1 : active raid1 sdd1[1] sdc1[0]                                                                   
      52436032 blocks [2/2] [UU]                                                                     
      [>....................]  resync =  4.7% (2512256/52436032) finish=10.2min speed=81040K/sec     
                                                                                                     
md0 : active raid1 sda1[1] sdb1[0]                                                                   
      1953511936 blocks [2/2] [UU]                                                                   
                                                                                                     
unused devices: <none>                                                                               
root@HO-1-231:~# cat /proc/mdstat                                                                    
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] [multipath]                
md1 : active raid1 sdd1[1] sdc1[0]                                                                   
      52436032 blocks [2/2] [UU]                                                                     
      [=========>...........]  resync = 46.1% (24198208/52436032) finish=8.0min speed=58504K/sec     
                                                                                                     
md0 : active raid1 sda1[1] sdb1[0]                                                                   
      1953511936 blocks [2/2] [UU]                                                                   
                                                                                                     
unused devices: <none>                                                                               
root@HO-1-231:~# cat /proc/mdstat                                                                    
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] [multipath]                
md1 : active raid1 sdd1[1] sdc1[0]                                                                   
      52436032 blocks [2/2] [UU]                                                                     
      [===================>.]  resync = 96.2% (50460544/52436032) finish=0.4min speed=66731K/sec     
                                                                                                     
md0 : active raid1 sda1[1] Sdb1[0]                                                                   
      1953511936 blocks [2/2] [UU]                                                                   
                                                                                                     
unused devices: <none>                                                                               
root@HO-1-231:~# cat /proc/mdstat                                                                    
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] [multipath]                
md1 : active raid1 sdd1[1] sdc1[0]                                                                   
      52436032 blocks [2/2] [UU]                                                                     
                                                                                                     
md0 : active raid1 sda1[1] sdb1[0]                                                                   
      1953511936 blocks [2/2] [UU]                                                                   
                                                                                                     
unused devices: <none>                                                                               
root@HO-1-231:~# ls /mnt                                                                             
README  cdrecorder/  cdrom/  dvd/  floppy/  hd/  memory/  tmp/  zip/                                 
root@HO-1-231:~# mkdir /mnt/md1                                                                      
root@HO-1-231:~# mount /dev/md1 /mnt/md1                                                             
mount: you must specify the filesystem type                                                          
root@HO-1-231:~# mkfs.xfs -f /dev/md1                                                                
warning: device is not properly aligned /dev/md1                                                     
meta-data=/dev/md1               isize=256    agcount=16, agsize=819313 blks                         
         =                       sectsz=512   attr=2                                                 
data     =                       bsize=4096   blocks=13109008, imaxpct=25                            
         =                       sunit=0      swidth=0 blks                                          
naming   =version 2              bsize=4096   ascii-ci=0                                             
log      =internal log           bsize=4096   blocks=6400, version=2                                 
         =                       sectsz=512   sunit=0 blks, lazy-count=1                             
realtime =none                   extsz=4096   blocks=0, rtextents=0                                  
root@HO-1-231:~# mount /dev/md1 /mnt/md1                                                                
root@HO-1-231:~# mc                                                                                     

root@HO-1-231:/mnt/md1# exit
exit                        

root@HO-1-231:~# cd /mnt/md1
root@HO-1-231:/mnt/md1# ls  
siapsrv/                    
root@HO-1-231:/mnt/md1# ls          
siapsrv/                            
root@HO-1-231:/mnt/md1# cd siapsrv/ 
root@HO-1-231:/mnt/md1/siapsrv# ls  
grub2/  grub2.tar.gz  monmdadm/  postgresql-9.0.4.tar.gz  rc.pg_reload*  rc.pg_start*  rc.pg_stop*
root@HO-1-231:/mnt/md1/siapsrv# mv rc.pg_reload testt                                             
root@HO-1-231:/mnt/md1/siapsrv# ls                                                                
grub2/  grub2.tar.gz  monmdadm/  postgresql-9.0.4.tar.gz  rc.pg_start*  rc.pg_stop*  testt*       
root@HO-1-231:/mnt/md1/siapsrv# md5                                                               
md5pass  md5sum                                                                                   
root@HO-1-231:/mnt/md1/siapsrv# ls                                                                
grub2/  grub2.tar.gz  monmdadm/  postgresql-9.0.4.tar.gz  rc.pg_start*  rc.pg_stop*  testt*       
root@HO-1-231:/mnt/md1/siapsrv# md5sum testt > md5sum                                             
root@HO-1-231:/mnt/md1/siapsrv# ls                                                                
grub2/  grub2.tar.gz  md5sum  monmdadm/  postgresql-9.0.4.tar.gz  rc.pg_start*  rc.pg_stop*  testt*
root@HO-1-231:/mnt/md1/siapsrv# mc                                                                 

root@HO-1-231:/mnt/md1/siapsrv# exit
exit                                

root@HO-1-231:/mnt/md1/siapsrv# cat /proc/mdstat
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] [multipath] 
md1 : active raid1 sdd1[1] sdc1[0]                                                    
      52436032 blocks [2/2] [UU]                                                      
                                                                                      
md0 : active raid1 sda1[1] sdb1[0]                                                    
      1953511936 blocks [2/2] [UU]                                                    
                                                                                      
unused devices: <none>                                                                
root@HO-1-231:/mnt/md1/siapsrv# mdadm /dev/md1 --fail /dev/sdc1 --remove /dev/sdc1    
mdadm: set /dev/sdc1 faulty in /dev/md1                                               
mdadm: hot remove failed for /dev/sdc1: Device or resource busy                       
root@HO-1-231:/mnt/md1/siapsrv# cd /                                                  
root@HO-1-231:/# mdadm /dev/md1 --fail /dev/sdc1 --remove /dev/sdc1                   
mdadm: set /dev/sdc1 faulty in /dev/md1                                               
mdadm: hot removed /dev/sdc1                                                          
root@HO-1-231:/# cat /proc/mdstat
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] [multipath] 
md1 : active raid1 sdd1[1]                                                            
      52436032 blocks [2/1] [_U]                                                      
                                                                                      
md0 : active raid1 sda1[1] sdb1[0]                                                    
      1953511936 blocks [2/2] [UU]                                                    
                                                                                      
unused devices: <none>                                                                
root@HO-1-231:/# fdisk -l | grep dev                                                  
Disk /dev/md0 doesn't contain a valid partition table                                 
Disk /dev/md1 doesn't contain a valid partition table                                 
Disk /dev/sda: 2000.4 GB, 2000398934016 bytes                                         
/dev/sda1               1      243201  1953512001   fd  Linux raid autodetect         
Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes                                         
/dev/sdb1               1      243201  1953512001   fd  Linux raid autodetect         
Disk /dev/md0: 2000.4 GB, 2000396222464 bytes                                         
Disk /dev/sdc: 2000.4 GB, 2000398934016 bytes                                         
/dev/sdc1               1        6528    52436128+  fd  Linux raid autodetect         
Disk /dev/sdd: 2000.4 GB, 2000398934016 bytes                                         
/dev/sdd1               1        6528    52436128+  fd  Linux raid autodetect         
Disk /dev/md1: 53.7 GB, 53694496768 bytes                                             
root@HO-1-231:/# fdisk /dev/sdc                                                       

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted. 

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to  
         sectors (command 'u').                                         

Command (m for help): p

Disk /dev/sdc: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes   
Disk identifier: 0x5ce337a5                           

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1        6528    52436128+  fd  Linux raid autodetect
Partition 1 does not start on physical sector boundary.                      

Command (m for help): d
Selected partition 1   

Command (m for help): p

Disk /dev/sdc: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes   
Disk identifier: 0x5ce337a5                           

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action         
   e   extended        
   p   primary partition (1-4)
p                             
Partition number (1-4): 1
First cylinder (1-243201, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-243201, default 243201): +84G

Command (m for help): p

Disk /dev/sdc: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x5ce337a5

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1       10968    88092396+  83  Linux
Partition 1 does not start on physical sector boundary.

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): p

Disk /dev/sdc: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x5ce337a5

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1       10968    88092396+  fd  Linux raid autodetect
Partition 1 does not start on physical sector boundary.

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
root@HO-1-231:/# fdisk -l | grep dev
Disk /dev/md0 doesn't contain a valid partition table
Disk /dev/md1 doesn't contain a valid partition table
Disk /dev/sda: 2000.4 GB, 2000398934016 bytes
/dev/sda1               1      243201  1953512001   fd  Linux raid autodetect
Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes
/dev/sdb1               1      243201  1953512001   fd  Linux raid autodetect
Disk /dev/md0: 2000.4 GB, 2000396222464 bytes
Disk /dev/sdc: 2000.4 GB, 2000398934016 bytes
/dev/sdc1               1       10968    88092396+  fd  Linux raid autodetect
Disk /dev/sdd: 2000.4 GB, 2000398934016 bytes
/dev/sdd1               1        6528    52436128+  fd  Linux raid autodetect
Disk /dev/md1: 53.7 GB, 53694496768 bytes
root@HO-1-231:/#
root@HO-1-231:/# df -h                                                       
Filesystem            Size  Used Avail Use% Mounted on                       
/dev/root             1.9T  165G  1.7T   9% /                                
tmpfs                 7.9G     0  7.9G   0% /dev/shm                         
/dev/md1               50G   25M   50G   1% /mnt/md1                         
root@HO-1-231:/# mdadm /dev/md1 -a /dev/sdc1                                 
mdadm: added /dev/sdc1                                                       
root@HO-1-231:/# cat /proc/mdstat                                            
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] [multipath] 
md1 : active raid1 sdc1[2] sdd1[1]                                                    
      52436032 blocks [2/1] [_U]                                                      
      [>....................]  recovery =  0.8% (460928/52436032) finish=13.1min speed=65846K/sec
root@HO-1-231:/# cat /proc/mdstat                                                                  
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] [multipath]              
md1 : active raid1 sdc1[2] sdd1[1]                                                                 
      52436032 blocks [2/1] [_U]                                                                   
      [============>........]  recovery = 61.8% (32446976/52436032) finish=5.1min speed=65110K/sec 
                                                                                                   
md0 : active raid1 sda1[1] sdb1[0]                                                                 
      1953511936 blocks [2/2] [UU]                                                                 
                                                                                                   
unused devices: <none>                                                                             
root@HO-1-231:/# cat /proc/mdstat                                                                  
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] [multipath]              
md1 : active raid1 sdc1[0] sdd1[1]                                                                 
      52436032 blocks [2/2] [UU]                                                                   
                                                                                                   
md0 : active raid1 sda1[1] sdb1[0]                                                                 
      1953511936 blocks [2/2] [UU]                                                                 
                                                                                                   
unused devices: <none>                                                                             
root@HO-1-231:/# mdadm /dev/md1 --fail /dev/sdd1 --remove /dev/sdd1
mdadm: set /dev/sdd1 faulty in /dev/md1                            
mdadm: hot removed /dev/sdd1                                       
root@HO-1-231:/# cat /proc/mdstat
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] [multipath] 
md1 : active raid1 sdc1[0]                                                            
      52436032 blocks [2/1] [U_]                                                      
                                                                                      
md0 : active raid1 sda1[1] sdb1[0]                                                    
      1953511936 blocks [2/2] [UU]                                                    
                                                                                      
unused devices: <none>                                                                
root@HO-1-231:/# fdisk /dev/sdd                                                       

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted. 

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to  
         sectors (command 'u').                                         

Command (m for help): p

Disk /dev/sdd: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes   
Disk identifier: 0x3c581631                           

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1        6528    52436128+  fd  Linux raid autodetect
Partition 1 does not start on physical sector boundary.                      

Command (m for help): d
Selected partition 1   

Command (m for help): p

Disk /dev/sdd: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes   
Disk identifier: 0x3c581631                           

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action         
   e   extended        
   p   primary partition (1-4)
p                             
Partition number (1-4): 1     
First cylinder (1-243201, default 1): 
Using default value 1                 
Last cylinder, +cylinders or +size{K,M,G} (1-243201, default 243201): +84G

Command (m for help): p

Disk /dev/sdd: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes   
Disk identifier: 0x3c581631                           

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1       10968    88092396+  83  Linux 
Partition 1 does not start on physical sector boundary.       

Command (m for help): t
Selected partition 1   
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): p

Disk /dev/sdd: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes   
Disk identifier: 0x3c581631                           

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1       10968    88092396+  fd  Linux raid autodetect
Partition 1 does not start on physical sector boundary.                      

Command (m for help): t
Selected partition 1   
Hex code (type L to list codes): fd

Command (m for help): p

Disk /dev/sdd: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes   
Disk identifier: 0x3c581631                           

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1       10968    88092396+  fd  Linux raid autodetect
Partition 1 does not start on physical sector boundary.                      

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.                             
root@HO-1-231:/# mdadm /dev/md1 -a /dev/sdd1
mdadm: added /dev/sdd1 
root@HO-1-231:/# cat /proc/mdstat
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] [multipath] 
md1 : active raid1 sdd1[2] sdc1[0]                                                    
      52436032 blocks [2/1] [U_]                                                      
      [===============>.....]  recovery = 76.3% (40046528/52436032) finish=3.1min speed=66193K/sec
                                                                                                  
md0 : active raid1 sda1[1] sdb1[0]                                                                
      1953511936 blocks [2/2] [UU]                                                                
                                                                                                  
unused devices: <none>                                                                            
root@HO-1-231:/# cat /proc/mdstat                                                                 
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] [multipath]             
md1 : active raid1 sdd1[2] sdc1[0]                                                                
      52436032 blocks [2/1] [U_]                                                                  
      [===================>.]  recovery = 97.1% (50961088/52436032) finish=0.3min speed=68716K/sec
                                                                                                  
md0 : active raid1 sda1[1] sdb1[0]                                                                
      1953511936 blocks [2/2] [UU]                                                                
                                                                                                  
unused devices: <none>                                                                            
root@HO-1-231:/# cat /proc/mdstat                                                                 
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] [multipath]             
md1 : active raid1 sdd1[1] sdc1[0]                                                                
      52436032 blocks [2/2] [UU]                                                                  
                                                                                                  
md0 : active raid1 sda1[1] sdb1[0]                                                                
      1953511936 blocks [2/2] [UU]                                                                
                                                                                                  
unused devices: <none>                                                                            
root@HO-1-231:/# mdadm --detail /dev/md0 | grep -e 'Array Size' -e 'Device Size'                  
     Array Size : 1953511936 (1863.01 GiB 2000.40 GB)                                             
root@HO-1-231:/# mdadm --detail /dev/md1 | grep -e 'Array Size' -e 'Device Size'                  
     Array Size : 52436032 (50.01 GiB 53.69 GB)                                                   
root@HO-1-231:/# mdadm --detail /dev/md1                                                          
/dev/md1:                                                                                         
        Version : 0.90                                                                            
  Creation Time : Thu Feb  2 20:07:41 2012                                                        
     Raid Level : raid1                                                                           
     Array Size : 52436032 (50.01 GiB 53.69 GB)                                                   
  Used Dev Size : 52436032 (50.01 GiB 53.69 GB)                                                   
   Raid Devices : 2                                                                               
  Total Devices : 2                                                                               
Preferred Minor : 1                                                                               
    Persistence : Superblock is persistent                                                        

    Update Time : Thu Feb  2 21:09:54 2012
          State : clean                   
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

           UUID : d2a575b9:b98dd42f:473eda47:d8152018
         Events : 0.122

    Number   Major   Minor   RaidDevice State
       0       8       33        0      active sync   /dev/sdc1
       1       8       49        1      active sync   /dev/sdd1
root@HO-1-231:/# mdadm --detail /dev/md1 | grep -e 'Array Size' -e 'Used Dev Size'
     Array Size : 52436032 (50.01 GiB 53.69 GB)
  Used Dev Size : 52436032 (50.01 GiB 53.69 GB)
root@HO-1-231:/# mdadm --grow /dev/md1 -z max
root@HO-1-231:/# mdadm --detail /dev/md1 | grep -e 'Array Size' -e 'Used Dev Size'
     Array Size : 88092288 (84.01 GiB 90.21 GB)
  Used Dev Size : 88092288 (84.01 GiB 90.21 GB)
root@HO-1-231:/# mount
/dev/root on / type xfs (rw,relatime,attr2,noquota)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
usbfs on /proc/bus/usb type usbfs (rw)
tmpfs on /dev/shm type tmpfs (rw)
/dev/md1 on /mnt/md1 type xfs (rw)
root@HO-1-231:/# resize2fs /dev/md1
resize2fs 1.41.11 (14-Mar-2010)
resize2fs: Bad magic number in super-block while trying to open /dev/md1
Couldn't find valid filesystem superblock.
root@HO-1-231:/# mc

root@HO-1-231:/mnt/md1/siapsrv# exit
exit

root@HO-1-231:/# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/root             1.9T  165G  1.7T   9% /
tmpfs                 7.9G     0  7.9G   0% /dev/shm
/dev/md1               50G   25M   50G   1% /mnt/md1
root@HO-1-231:/# xfs_growfs /mnt/md1
meta-data=/dev/md1               isize=256    agcount=16, agsize=819313 blks
         =                       sectsz=512   attr=2
data     =                       bsize=4096   blocks=13109008, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0
log      =internal               bsize=4096   blocks=6400, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 13109008 to 22023072
root@HO-1-231:/# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/root             1.9T  165G  1. T   9% /
tmpfs                 7.9G     0  7.9G   0% /dev/shm
/dev/md1               84G   26M   84G   1% /mnt/md1
root@HO-1-231:/#md5sum -c md5sum

ok

Kamis, 19 Januari 2012

compress

How can I compress a whole directory under Linux / UNIX using a shell prompt?A. It is very easy to compress a Whole Linux/UNIX directory. It is useful to backup files, email all files, or even to send software you have created to friends. Technically, it is called as a compressed archive. GNU tar command is best for this work. It can be use on remote Linux or UNIX server. It does two things for you:
=> Create the archive
=> Compress the archive
You need to use tar command as follows (syntax of tar command):
tar -zcvf archive-name.tar.gz directory-name
Where,
  • -z: Compress archive using gzip program
  • -c: Create archive
  • -v: Verbose i.e display progress while creating archive
  • -f: Archive File name
For example, you have directory called /home/jerry/prog and you would like to compress this directory then you can type tar command as follows:
$ tar -zcvf prog-1-jan-2005.tar.gz /home/jerry/prog
Above command will create an archive file called prog-1-jan-2005.tar.gz in current directory. If you wish to restore your archive then you need to use following command (it will extract all files in current directory):
$ tar -zxvf prog-1-jan-2005.tar.gz
Where,
  • -x: Extract files
If you wish to extract files in particular directory, for example in /tmp then you need to use following command:
$ tar -zxvf prog-1-jan-2005.tar.gz -C /tmp
$ cd /tmp
$ ls -

Selasa, 17 Januari 2012

upgrade backup and restore postgres with streaming replication

back up :

/usr/local/pgsql/bin/pg_dumpall > /opt/db/backupfile.dat


shutdown old server

/usr/local/pgsql/bin/pg_ctl -D /opt/db/data stop -m fast

rename directory

mv /usr/local/pgsql /usr/local/pgsql_old

mv /opt/db/data /opt/db/data_old

------------------------------------------------------------
prepare primary
install postgresql 9.02

./configure --with-openssl --with-tcl --enable-thread-safety ----enable-multibyte=UNICODE
make
make install
mkdir /opt/db/data
chown postgres /opt/db/data
su - postgres
/usr/local/pgsql/bin/initdb -D /opt/db/data

create folder
archive
pg_log
create pghba.conf  ---> see the old pg_hba.conf
create postgresql.conf (SR)  ---> see the old postgresql.conf

for streaming replication see :http://masis-9.blogspot.com/2011/12/streaming-replikasi-di-postgresql.html

start postgres

/usr/local/pgsql/bin/pg_ctl -D /opt/db/data start

---------------------------------------------------------------
prepare the slave

./configure
make
make install
mkdir /opt/db/data
chown postgres /opt/db/data
/usr/local/pgsql/bin/initdb -D /opt/db/data

config the slave for streaming replication see : http://masis-9.blogspot.com/2011/12/streaming-replikasi-di-postgresql.html

primary :
su - postgres
$/usr/local/pgsql/bin/psql -c "SELECT pg_start_backup('label',true)"
$rsync -a -v -e ssh /opt/db/data/ 192.168.168.210:/opt/db/data/ --exclude postmaster.pid
$ /usr/local/pgsql/bin/psql -c "SELECT pg_stop_backup()"

edit postgresql.conf at slave :
hot_standby = on

copy recovery.conf to slave
edit recovery.conf tersebut :
restore_command = 'cp  /opt/db/data/archive/%f "%p"'
standby_mode = 'on'
primary_conninfo = 'host=192.168.1.210 port=5432 user=postgres'         #ip primary
trigger_file = '/opt/db/data/failover'

start postgres at slave
--------------------------------------------------------------

make sure steaming running well

di standby :
$/usr/local/pgsql/bin/psql -c "SELECT pg_last_xlog_receive_location()"
di primary  :
$/usr/local/pgsql/bin/psql -c "SELECT pg_current_xlog_location()"

di primary :
$ ps -ef | grep sender
di standby
$ ps -ef | grep receiver

-----------------------------------------------------------
streaming replication running well

at primary restore database
contoh restore dr 192.168.188.31 ke 192.168.188.131
/usr/local/pgsql/bin/psql -f backupfile160112f.dat postgres

/usr/local/pgsql/bin/ls
 /opt/db/backupfile.dat

===================================================================
if anything going to worst  you can 
prepare back to old postgres

shuttingdown slave
/usr/local/pgsql/bin/pg_ctl -D /opt/db/data stop -m fast

shuttingdown primary
/usr/local/pgsql/bin/pg_ctl -D /opt/db/data stop -m fast

make sure both ( slave and primary ) database not running

rename new database
mv /usr/local/pgsql /usr/local/pgsql_new
mv /opt/db/data /opt/drop database jsxdfeed;db/data_new

rename back the old database

mv /usr/local/pgsql_old  /usr/local/pgsql
mv /opt/db/data_old  /opt/db/data

start the old postgres
/usr/local/pgsql/bin/pg_ctl -D /opt/db/data start
-------------------------------------------------------
=====================================================
======================================================

/usr/local/pgsql/bin/pg_dump -h 192.168.88.23 -U lima -Fc jsxdfeed -f jsxdfeed.dump -v
=========================================================================================
/usr/local/pgsql/bin/pg_dumpall -h 192.168.1.220 -f bacupdata.dat  -U totok

/usr/local/pgsql/bin/pg_dumpall -h 192.168.1.220 -f bacupdata.dat -v /
/usr/local/pgsql/bin/pg_dump -h 192.168.1.220 -f bacupdata.dat  -U totok -Fc jsxdfeed
---------------------------------------------------------------
/usr/local/pgsql/bin/psql -f backupfile.dat postgres