linux

linux

Selasa, 27 Desember 2011

catatan aja

screen
untuk keluar dr screen ( detach ): ctrl + a  d
untuk keluar dan berhenti dr screen : exit
root@napinfo-188-205:~# screen -r
There are several suitable screens on:
        2170.pts-2.napinfo-188-205      (Detached)
        2178.pts-2.napinfo-188-205      (Detached)
Type "screen [-d] -r [pid.]tty.host" to resume one of them.
root@napinfo-188-205:~# screen -r 2170
[detached]
root@napinfo-188-205:~# screen -r 2178
[detached]

-----> gunakan ctrl + a + d  --> untuk kembali ke consol
root@napinfo-188-205:~# screen -r
There are several suitable screens on:
        2170.pts-2.napinfo-188-205      (Detached)
        2178.pts-2.napinfo-188-205      (Detached)
Type "screen [-d] -r [pid.]tty.host" to resume one of them.
========================================
untuk installasi :
download open-iscsi
cd open-iscsi
vi open-scsi/iscsi_sysfs.c
tambah return 0; di :
---------------------------------------
int iscsi_sysfs_check_class_version(void)
{
        char *version;
        int i;

-->>    return 0;
        version = iscsi_sysfs_get_iscsi_kernel_version();
        if (!version)
                goto fail;

        log_warning("transport class version %s. iscsid version %s",
                    version, ISCSI_VERSION_STR);
--------------------------------------------
iscsiadm -m iface
iscsiadm -m node
iscsid
iscsiadm -m discovery -t sendtargets -p 192.168.1.1:3260
cat /proc/scsi/scsi
root@<-III->:~# cat /proc/scsi/scsi
Attached devices:
Host: scsi1 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: ST3500418AS      Rev: CC38
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi2 Channel: 00 Id: 00 Lun: 00
  Vendor: TSSTcorp Model: CDDVDW SH-S223B  Rev: SB02
  Type:   CD-ROM                           ANSI  SCSI revision: 05
root@<-III->:~#
masuk ke manajemen storage add host di tab configure
modprobe iscsi_tcp
iscsiadm -m node -T iqn.1992-01.com.lsi:1535.600a0b8000744f8e000000004c0eee50 -l
iscsiadm -m node
 cat /proc/scsi/scsi
Attached devices:
Host: scsi1 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: ST3500418AS      Rev: CC38
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi2 Channel: 00 Id: 00 Lun: 00
  Vendor: TSSTcorp Model: CDDVDW SH-S223B  Rev: SB02
  Type:   CD-ROM                           ANSI  SCSI revision: 05
Host: scsi4 Channel: 00 Id: 00 Lun: 01
  Vendor: IBM      Model: Universal Xport  Rev: 0250
  Type:   Direct-Access                    ANSI  SCSI revision: 05
root@<-III->:~#
============================
startup GUI di slackware
slackware defaultnya running level3 yang boot masyk command propt mode
untukmengubah ke boot mode GUI lakukan langkah di bawah ini:
edit file di : /etc/inittab
temukan baaris berikut :
# Default run level. (Do not set to 0 or 6)
id:3:initdefault:

ubah angka 3 diatas menjadi angka 4 untuk mode GUI
=============================
install Grub buat slackware :
http://slackbuilds.org/repository/13.1/system/grub2/
download :ftp://alpha.gnu.org/gnu/grub/grub-1.98.tar.gz
          http://slackbuilds.org/slackbuilds/13.1/system/grub2.tar.gz

tar -xvf grub2.tar.gz
mv grub-1.98.tar.gz grub2/
cd grub2
./grub2.SlackBuild
cd /tmp
installpkg grub2-1.98-x86_64-2_SBo.tgz
cat /proc/mdstat
grub-install /dev/md0

berikut ini  pilihan bisa 2 cara :
1.grub-mkconfig -o /boot/grub/grub.cfg
  hasilnya masih kosong...
2.copy grub.cfg
  cp /usr/doc/grub2-1.98/grub.cfg /boot/grub2/
 
saya pilih yang no 2.
edit file grub.cfg jadi :
---------------------------------------------------------------
#
# Sample GRUB configuration file
#

# Boot automatically after 30 secs.
set timeout=10

# By default, boot the first entry.
set default=0

# Fallback to the second entry.
set fallback=1


# For booting GNU/Linux
menuentry "linuxslac_serever" {
        set root='(md0)'
        linux /boot/vmlinuz root=/dev/md0
        initrd
}

# Change the colors.
menuentry "Change the colors" {
        set menu_color_normal=light-green/brown
        set menu_color_highlight=red/blue
}
==============================
lupa password :
boot dari media apa aja ( cd linux/flashdisk atau yg lain )
yg penting bisa akses HDD asli  yang buat boot :
masuk command prompt :
create direktori :
mkdir /mnt/satu
mount HDD asli :
mount /dev/sda2 /mnt/satu
kemudian masuk ke folder /etc/passwd ( di hdd asli nya :
cd /mnt/satu/etc/
vi passwd
cari bagian :
root:x:0:0::/root:/bin/bash
bin:x:1:1:bin:/bin:/bin/false
daemon:x:2:2:daemon:/sbin:/bin/false
adm:x:3:4:adm:/var/log:/bin/false
lp:x:4:7:lp:/var/spool/lpd:/bin/false
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
...
pada bagian :
root:x:0:0::/root:/bin/bash
hilangkan huruf x nya menjadi :
root::0:0::/root:/bin/bash
kemudian save :  esc -->  wq enter
kemudian reboot , dan boot dari flash Haddisk asli :
insyalloh password jadi kosong...
login pake root untuuk password jangan ketik apa1 tapi langsung enter.
setelah bisa masuk baru buat passwoed baru lagi...
===============================
speed harddisk
 hdparm -tT /dev/md1

root@HO-168-33:/opt# sudo hdparm -tT /dev/md1

/dev/md1:
 Timing cached reads:   1416 MB in  2.00 seconds = 708.31 MB/sec
 Timing buffered disk reads:  108 MB in  3.09 seconds =  34.94 MB/sec
root@HO-168-33:/opt#
==============================
=================================create swap file ====================================
8G memory swap
root@darkstar:/etc/rc.d# dd if=/dev/zero of=/swapfile bs=1024 count=8000000
8000000+0 records in
8000000+0 records out
8192000000 bytes (8.2 GB) copied, 74.8582 s, 109 MB/s

# dd if=/dev/zero of=/mnt/swap/swapfile bs=1k count=20480
# mkswap /mnt/swap/swapfile
# swapon /mnt/swap/swapfile
To make it enable at boot, you need to add the swap file in the /etc/fstab file like below:
/swap1         swap             swap        defaults         0   0


1. Adding swap file on Linux
Login as root or change to super user then type the following command to create 1 GB swap file.
dd if=/dev/zero of=/swap1 bs=1M count=1024

bash-3.1# dd if=/dev/zero of=/swap1 bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 28.3646 s, 37.9 MB/s
Run ?mkswap? to set up a Linux swap area on a device or in a file, in this case in the /swap1 file.
mkswap /swap1
For example:
bash-3.1# mkswap /swap1
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=e501fc72-f731-4624-ab45-ee898f6cf1c5
After setting up the swap area, now we need to enable / activate the swap file by using ?swapon? command.
swapon /swap1
You are done. But the swap file will be disable if you reboot the system.
To make it enable at boot, you need to add the swap file in the /etc/fstab file like below:
/swap1         swap             swap        defaults         0   0
----------
dd if=/dev/zero of=/swap1 bs=1M count=1024
mkswap /swap1
swapon /swap1
============================
wget -r -P /home/hihi -l 0 -c -N -nH --cust-dir=3 ftp://root:dkdji@192.168.5.1//home/semangka/*

wget -r -P /home/hihi -l 0 -c -nH --cus-dir=3 --user=root ftp://192.168.5.1//home/semangka/*
==========================================================================================================
di ftp server
/etc/rc.d/rc.inetd start
config di /etc/inetd.conf
kemudian edit di /etc/vsftp.conf
      #anonymous_enable=YES
      anonymous_enable=NO
      # Uncomment this to enable any form of FTP write command.
      write_enable=YES
    
di wget ( client )
di /etc/wgetrc copy ke /root
cp /etc/wgetrc /root/.wgetrc
tambahkan di /root/.wgetrc

ftp_password = jakarta
background = on
timestamping = on
continue = on
#preserve-permissions = on

contoh command di client
wget -r -P /mnt/md0/stalfa/IPOT  -l 0 -c -N -nH --cut-dirs=2 --user=root ftp://192.168.188.204://opt/*
===================================

Senin, 26 Desember 2011

NFS Server

NFS Server on Slackware 13.1

Supposed that your IP address is 192.168.1.x, and you are going to run NFS service for all users in 192.168.1.0/24 (192.168.1.1 - 192.168.1.254).
On Slackware 13.1, it is very easy to do it.
  1. Make folder for NFS service, with all permission for all users.
  2. # mkdir /home/nfs && chmod 0777 /home/nfs/
  3. Edit /etc/exports
  4. /home/nfs 192.168.1.0/24(rw,no_root_squash,no_subtree_check,sync)
  5. Start NFS service
  6. # chmod a+x /etc/rc.d/rc.nfsd && /etc/rc.d/rc.nfsd start
    If it complains nfsd.ko module failed as shown:
    FATAL: Error inserting nfsd (/lib/modules/2.6.33.4-smp/kernel/fs/nfsd/nfsd.ko): Invalid module format
    Maybe you are using "huge" kernel (Slackware default kernel). You can update it with "generic" kernel (remember to mkinitrd). Also, you can just ignore the error, because NFS service runs successfully already.  on client do this to mount the nfs :  makedir /mnt/nfs  mount -t nfs -o nolock,sync,ro 192.168.1.x:/home/nfs /mnt/nfs check with mount you will find out the mount

Kamis, 22 Desember 2011

mdadm

just note

//=================================================================================
// add new hard disk
//=================================================================================
1. plug in th hard disk on empty bay, let say, in to bay 4 (as host3, 1st bay as host0)
2. do this command:

# echo 0 0 0 > /sys/class/scsi_host/host3/scan

for bay number 3:
# echo 0 0 0 > /sys/class/scsi_host/host2/scan

for bay number 3:
# echo 0 0 0 > /sys/class/scsi_host/host1/scan

for bay number 1 (1st):
# echo 0 0 0 > /sys/class/scsi_host/host0/scan

>>> >>> the hard drive will be accessible

//=================================================================================
// remove hard disk
//=================================================================================

beware, to UNMOUNT the file system FIRST !!!!!!!!!!!!!!!!!!!!!!!!!!!!!

to remove harddisk from bay second bay or bay number 2 (it is as host1), do:

# echo 1 > /sys/class/scsi_device/1:0:0:0/device/delete

to remove harddisk from bay third bay or bay number 3 (it is as host2), do:

# echo 1 > /sys/class/scsi_device/2:0:0:0/device/delete

to remove harddisk from the fourth bay or bay number 4 (it is as host3), do:

# echo 1 > /sys/class/scsi_device/3:0:0:0/device/delete



Hotswap a SCSI, SAS, or SATA drive in Linux
============================================
There seems to be not a lot of information on Google about this, thus, I post.
At my work, the majority of our servers have hot-swappable drive bays ? however, Linux doesn?t usually automatically notice the drive is gone.
 Worse, sometimes it doesn?t even notice new drives hooked up.
Now, SCSI and SAS both support hot-plugging on a protocol level, and SATA II does as well. If your chassis is equipped with a hotswap drive bays, then that?s all you really need.
 I haven?t noticed any problems with SATA I hotswaps, but they appear to be less successful.
A common task I need to do is either:
upgrade a drive in a server
replace a dying drive with a new one

If the drive is in a RAID, or if it?s a separate sized drive for a disk upgrade, it?s a good idea to trigger the kernel driver to rescan information about the new disk.
In /sys/bus/scsi/devices, you?ll find a number of numbers that?ll correspond to your disk drives:
server devices # ls -1
 0:0:0:0@
 1:0:0:0@
 2:0:0:0@

You can determine more information about the drive by cat?ing it?s model file:
 server devices # cat "0:0:0:0/model"
 ST3250410AS

Now, to cause the kernel to rescan the drive attached to the port, do this:
 echo > "0:0:0:0/rescan"

Check dmesg now:
 server devices # dmesg
 ---snip---
 SCSI device sda: 488397168 512-byte hdwr sectors (250059 MB)
 sda: Write Protect is off
 sda: Mode Sense: 00 3a 00 00
 SCSI device sda: drive cache: write back

Now, that?s pretty exciting, as this can be used to skip a reboot.  If you switch the drive, and trigger the rescan,
it?ll update the drive information including the partition layout.  Make sure you don?t swap out your main system drive,
 otherwise your computer will freeze, and there will be data loss and possibly corruption.
Sometimes, this strategy fails to work, and I don?t know why (and resort to rebooting.)
 I'm currently researching how to do this a bit better, I have a buggy script that I use to improve this method,
but it's not ready for public release yet. Does anyone have a better method?  Please comment!

//=================================================================================
// add new hard disk
//=================================================================================
1. plug in th hard disk on empty bay, let say, in to bay 4 (as host3, 1st bay as host0)
2. do this command:

# echo 0 0 0 > /sys/class/scsi_host/host3/scan

for bay number 3:
# echo 0 0 0 > /sys/class/scsi_host/host2/scan

for bay number 2 (1st):
# echo 0 0 0 > /sys/class/scsi_host/host1/scan

for bay number 1 (1st):
# echo 0 0 0 > /sys/class/scsi_host/host0/scan

>>> >>> the hard drive will be accessible

//=================================================================================
// remove new hard disk
//=================================================================================

to remove harddisk from the second bay or bay number 2 (it is as host1), do:

# echo 1 > /sys/class/scsi_device/1:0:0:0/device/delete

to remove harddisk from the third bay or bay number 3 (it is as host2), do:

# echo 1 > /sys/class/scsi_device/2:0:0:0/device/delete

to remove harddisk from the fourth bay or bay number 4 (it is as host3), do:

# echo 1 > /sys/class/scsi_device/3:0:0:0/device/delete


to see sdx ?
/sys/bus/scsi/devices/0:0:0:0/block


#
# -----------------------------------
# Commands used for working with Raid
# -----------------------------------
#
#
# Latest Version:
# ==============
#    http://www.1U-Raid5/HowTo/Commands.uhow2.txt
#
#
#    http://www.cse.unsw.edu.au/~neilb/source/mdadm/
#    http://www.{countrycode}.kernel.org/pub/linux/utils/raid/mdadm/
#
#
# 04-21-99 amo Date-of-Birth
# 08-28-04 amo Added more commands
# 05-26-05 amo Added more mdadm commands
#
#
#
# To Define your Raid Array
# -------------------------
#    ln -s /etc/raidxx.conf /etc/raidtab
#
#
# To Stop and Start the Raid Array
# --------------------------------
#     /etc/init.d/raid2 stop
#     /etc/init.d/raid2 start
#
#    -- or --
#
#    raidstop  /dev/md0
#    raidstart /dev/md0
#
#
#    mdadm --stop /dev/md4
#
#
#
# Config Files
# ------------
#     /etc/{raid}/raidtab
#        raidstart -a
#
#    /etc/mdtab
#        mdadd -ar    ( mdcreate )
#
#
# To Create the Raid Devices
# --------------------------
#
#    raidadd -a
#        md0 : inactive hdc1 hde1 16402302 blocks
#
#    raidrun /dev/md0
#        md0 : active raid0 hdc1 hde1 16401920 blocks 256k chunks
#        -- turn it on
#
#    raidstart /dev/md0
#
#
#
# To Initialize Raid
# ------------------
#    mkraid -V    - version info
#       mkraid /dev/md0
#
#    mkraid -force /dev/md0
#
#    mkraid -c /etc/raidtab /dev/md0
#        mkraid is only relevant for RAID 1, 4, and 5 devices
#        mkraid: aborted
#
#       - or -
#
#    http://www.cse.unsw.edu.au/~neilb/source/mdctl/mdctl-0.5.tgz
#    mdctl --assemble [ --force ] /dev/md0 /dev/hdc1 /dev/hde1 /dev/hdg1
#
#    http://www.cse.unsw.edu.au/~neilb/source/mdadm/
#    http://acd.ucar.edu/~fredrick/linux/fedoraraid/
#
#
#    mdadm --stop /dev/md4
#    mdadm --zero-superblock /dev/hda1
#    mdadm --zero-superblock /dev/hdb1
#
#
#    mdadm --version
#
#    mdadm -QE --scan
#
#    mdadm --detail /dev/md0
#
#    mdadm --detail --scan
#
#
#    mdadm --examine /dev/sda1
#    mdadm --examine /dev/sdb1
#    mdadm --examine /dev/sdc1
#
#    mdadm --assemble /dev/md0 /dev/sda1 /dev/sdb1 /dev/sdc1
#
#    mdadm --create /dev/md0 --verbose --level=mirror --raid-devices=2 /dev/sdb1 /dev/sdc1
#
#    # resync ??
#    mdadm --assemble --run --force --update=resync /dev/md2 /dev/sbd3  /dev/sbd4 /dev/sbd5
#
#    ???
#    mdadm -R -A /dev/md0 /dev/hdx /dev/hdy
#
#    # hotadd a disk
#    mdadm /dev/md0 -a /dev/hdg1
#    mdadm /dev/md0 --force -a /dev/hdg1
#
#
#    #
#    # stop and rebuild it
#    #
#    mdadm --stop --scan
#    mdadm --assemble /dev/md0 --auto --scan --update=summaries --verbose
#
#    #
#    # Monitoring the sw raid
#    #
#    nohup mdadm --monitor --mail=RaidSupport@your-domain.com --delay=300 /dev/md0
#
#
#
# To Check if its recognized
# --------------------------
#    cat /proc/mdstat
#        Personalities : [1 linear] [2 raid0] [3 raid1] [4 raid5]
#        read_ahead 128 sectors
#        md0 : active raid0 hdc1 hde1 16401920 blocks 256k chunks/usr/local/squid/sbin/starter.sh
#        md1 : inactive
#
#    mdadm -A /dev/hde1
#
#    lsraid -a /dev/md0
#
#
# To Format a NEW raid device
# ---------------------------
#    mkfs.ext2 /dev/md0
#        mke2fs -b 4096 -R stride=16 /dev/md0
#        mke2fs -m 1 /dev/md0
#
#        mke2fs -b 4096 -i 16384 -R stride=32 -s sparse-super-flag /dev/md0
#
#        tune2fs -c 1 -i 1d -m 10 /dev/md0
#
#
#    - for Ext3 Journeling FS  ( download new e2fsprogs-1.25 )
#    - define ext3 in /etc/fstab
#    mke2fs -j /dev/md0
#
#    -- or --
#
#    mkreiserfs /dev/md0
#
#
#
# To Check the formating before mounting
# --------------------------------------
#    e2fsck /dev/md0
#
#    e2fsck -yf /dev/md0    - just fix it  ( very dangerous though )
#
#
# To Mount and use the Raid devices
# ---------------------------------
#    mkdir /Raid5 ; mount /dev/md0 /Raid5
#
#
# To Un-mount the Raid devices
# ----------------------------
#    umount /Raid5
#
# To Stop Raid
# ------------
#    raidstop /dev/md0
#    cat /proc/mdstat    -- to verify devices not listed
#
# To Restart Raid
# ---------------
#    raidstart /dev/md0
#    raidstart -a
#    raidrun -a
#    cat /proc/mdstat    -- to verify devices not listed
#
#
# HotAdd and Remove /dev/sdb
# -----------------
#    mdadm /dev/md0 --fail /dev/sda1
#    mdadm /dev/md0 --remove /dev/sda1
#
#
#     -- or --
#
#    raidhotremove -->> without running: "raidstop /dev/md0"
#  
#    raidsetfaulty /dev/md0 /dev/sdb2
#    raidhotremove /dev/md0 /dev/sdb2
#
#    -- after adding the new disk ... watch it resync
#    raidhotadd /dev/md0 /dev/sdb2
#
#    #
#    # to hotadd the new/missing device
#    #
#    mdadm /dev/md0 -a /dev/hdc1
#

# To remove any faulties:

You can remove any faulty or failed drives with :

sudo mdadm --manage /dev/md0 --remove faulty
-- or --
sudo mdadm --manage /dev/md0 --remove failed

This lets mdadm know to deallocate the device space. When you hot-add a new spare drive it should replace the /dev/sd<failed> node. After the hot-add you can:

sudo mdadm --manage /dev/md0 --re-add /dev/sd<failed>

-- a real world case --

sudo mdadm --manage /dev/md0 --re-add /dev/sdc1

#
# To View the raid devices
# -------------------------
#    mdadm --detail /dev/md0
#
#
# Test your RAID Systems
# ----------------------
#    http://www.1U-Raid5.net/Testing
#
#
# Backup data on your RAID systems
# --------------------------------
#    http://www.Linux-Backup.net
#
#
#
# end of file
****************************************************************************
root@HO-168-22:~# mdadm --detail /dev/md0
/dev/md0:                              
        Version : 0.90                 
  Creation Time : Mon Aug 22 18:19:18 2011
     Raid Level : raid1                 
     Array Size : 1953511936 (1863.01 GiB 2000.40 GB)
  Used Dev Size : 1953511936 (1863.01 GiB 2000.40 GB)
   Raid Devices : 2
  Total Devices : 3
Preferred Minor : 0
    Persistence : Superblock is persistent

    Update Time : Mon Jan 30 22:17:04 2012
          State : clean
 Active Devices : 2
Working Devices : 2
 Failed Devices : 1
  Spare Devices : 0

           UUID : bdebd41b:bd11b324:e932e65d:e0c75763
         Events : 0.39068

    Number   Major   Minor   RaidDevice State
       0       8        1        0      active sync   /dev/sda1
       1       8       33        1      active sync   /dev/sdc1

       2       8       17        -      faulty spare
root@HO-168-22:~# mdadm --manage /dev/md0 --remove faulty
mdadm: hot removed 8:17
root@HO-168-22:~# mdadm --detail /dev/md0
/dev/md0:
        Version : 0.90
  Creation Time : Mon Aug 22 18:19:18 2011
     Raid Level : raid1
     Array Size : 1953511936 (1863.01 GiB 2000.40 GB)
  Used Dev Size : 1953511936 (1863.01 GiB 2000.40 GB)
   Raid Devices : 2
  Total Devices : 2
Preferred Minor : 0
    Persistence : Superblock is persistent

    Update Time : Mon Jan 30 22:19:11 2012
          State : clean
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

           UUID : bdebd41b:bd11b324:e932e65d:e0c75763
         Events : 0.39070

    Number   Major   Minor   RaidDevice State
       0       8        1        0      active sync   /dev/sda1
       1       8       33        1      active sync   /dev/sdc1
root@HO-168-22:~# cat /proc/mdstat
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] [multipath]
md0 : active raid1 sdc1[1] sda1[0]
      1953511936 blocks [2/2] [UU]

unused devices: <none>
note : if mdadm show faulty you cam remove if with
mdadm --manage /dev/md0 --remove faulty

Selasa, 20 Desember 2011

streaming replikasi di postgresql

step2 straming replication postgresql 9.02mc

1. Install postgres di primary dan standby seperti biasa :
   #./configure ,------------->  ./configure --with-openssl --with-tcl --enable-thread-safety
   # make
   # make install
   # useradd postgres  ----gunakan useradd
   # mkdir /usr/local/pgsql/data
   # chown postgres /usr/local/pgsql/data
   # su - postgres
2. tentukan ip mis primary : 192.168.5.11
                   standby : 192.168.5.16
2. buat initial database di primary sepertibiasa menggunakan :
   #/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
  
3. edit postgresql.conf di primary
   listen_addresses = '*'
4. edit pg_hba.conf   di primary
   host   replication     postgres      192.168.5.16/32     trust
5. buat direktory untuk menyimpan segmen logfile ( untuk postgresql.conf di archive_command )
   buat di primary dan standby:
   mkdir /home/pgsql/data/archive   
   mkdir /home/pgsql/data/pg_log                 # tambahan untuk menyimpan log
6. edit lagi postgresql.conf
   wal_level = hot_standby
   archive_mode = on
   archive_command = 'cp %p /home/pgsql/data/archive/%f'
   max_wal_senders = 5
   wal_keep_segments = 6000
  

---------> cek untuk primary postgresql.conf di hot_standby=off
7. start postgres di primary
============================================================================================
8. buat sama postgresql.conf di standby dengan postgresql.conf di primary ( bisa di copykan )
   supaya bisa bertindak sebagai master setelah failover ( coba cek di archive command sesuaikan path nya)
9. masuk ke consol baru dengan user postgres (copy data primary ke standby ) di primary
   #su - postgres
   $/usr/local/pgsql/bin/psql -c "SELECT pg_start_backup('label',true)"
   $rsync -a -v -e ssh /home/pgsql/data/ 192.168.5.16:/home/pgsql/data/ --exclude postmaster.pid       -->ada 2 path perhatikan
   $ /usr/local/pgsql/bin/psql -c "SELECT pg_stop_backup()"

10.edit postgresql.conf di slave :
   hot_standby = on
11.buat file recovery.conf di slave dengan mengcopy dari /usr/local/pgsql/share/recovery.conf.sample
   #cp /usr/local/pgsql/share/recovery.conf.sample /home/pgsql/data
12.edit recovery.conf tersebut :
   restore_command = 'cp  /home/pgsql/data/archive/%f "%p"'
   standby_mode = 'on'
   primary_conninfo = 'host=192.168.5.11 port=5432 user=postgres'         #ip primary
   trigger_file = '/home/pgsql/data/failover'
13.start service postgresql di standby
   $/usr/local/pgsql/bin/postgres -D /home/pgsql/data >logfile 2>&1 &
    /usr/local/pgsql/bin/postgres -D /opt/db/data >/opt/db/data/logfile 2>&1 &
14.bandingkan current WAL write di primary dengan receive di standby:
   di standby :
   $/usr/local/pgsql/bin/psql -c "SELECT pg_last_xlog_receive_location()"
    pg_last_xlog_receive_location
    -------------------------------
    0/5000078
    (1 row)
   di primary  :
   $/usr/local/pgsql/bin/psql -c "SELECT pg_current_xlog_location()"
     pg_current_xlog_location
     --------------------------
     0/5000078
     (1 row)
15.cek progress streaming dengan command :
   di primary :
    $ ps -ef | grep sender
      postgres  6879  6831  0 10:31 ?        00:00:00 postgres:  wal receiver process   streaming 0/5000078

    di standby
    $ ps -ef | grep receiver
      postgres  6878  6872  1 10:31 ?        00:00:01 postgres: wal receiver process   streaming  0/5000078


  How to failover:
   * touch /tmp/pgsql.trigger ... start querying to failover server
  How to restart replication after failover :
   * remake a fresh backup. master doesn't have to be stopped
  How to restart replication after standby fails:
   * restart postgres in standby after eliminating cause of failure
  How to disconnect standby from primary:
   * touch /tmp/pgsql.trigger in slave while primary running.
  How to re-sync standby after isolation:
   * shutdown standby, make a fresh backup as per above
------------------------------------------------------------------
monitoring : http://www.postgresql.org/docs/9.0/static/warm-standby.html

25.2.5.2. Monitoring

An important health indicator of streaming replication is the amount of WAL records generated in the primary,
 but not yet applied in the standby. You can calculate this lag by comparing the current WAL write location on
 the primary with the last WAL location received by the standby. They can be retrieved using pg_current_xlog_location
 on the primary and the pg_last_xlog_receive_location on the standby, respectively (see Table 9-56 and Table 9-57 for details).
The last WAL receive location in the standby is also displayed in the process status of the WAL receiver process,
 displayed using the ps command (see Section 27.1 for details).

-----------------------------------------------------------------
test :
1.kalau kabel diputus ( standby ) kira2 10 jam terus sisi primary di insert/delete data
  dan create db, kemudian kabel di pasang lagi maka terjadi streaming data di standby ,
  dan..... proses create db, insert/delete data juga terjadi di standby ( ada sinkonisasi data )
2.kalau kabel di putus di sisi primary, dan di standby di insert/delete data atau create db
  maka proses ini tidak bisa dilakukan, muncul " cannot execute xxxxxxxxxxx in a read-only transaction"
  dan kalau kabel disambung lagi maka proses transacsi tetap bisa dilakukan di primary.
3.proses pemutusan koneksi dapat dilakukan dengan menggunakan triger di standby : membuat file failover dengan
  path seperti yang ada di recovery.conf : trigger_file = '/home/pgsql/data2/failover '
  berikan perintah : touch /home/pgsql/dqtq2/failover
  setelah nya maka standby bertindak sebagai master dan bisa digunakan untuk transaksi langsung
  perintah insert/delete data atau create db bisa dilakukan.
4.jika server standby di matikan mendadak ( tekan tombol power lama ),di sisi primary diberikan transaksi
  ( insert2 dan create db ) kemudian standby dinyalakan lagi
  setelah di ping bisa startup service postgre nya (/usr/local/pgsql/bin/pg_ctl -D /home/db/postgres/data2 start )
  -------------------------------------------proses startup standby ----------------------
  postgres@<===>:~$ /usr/local/pgsql/bin/pg_ctl -D /home/pgsql/data2 start
  pg_ctl: another server might be running; trying to start server anyway
  LOG:  database system was interrupted while in recovery at log time 2011-01-20 10:12:29 WIT
  HINT:  If this has occurred more than once some data might be corrupted and you might need to choose an earlier recovery target.
  LOG:  entering standby mode
  cp: cannot stat `/home/pgsql/data2/archive/00000001000000000000000C': No such file or directory
  LOG:  consistent recovery state reached at 0/C008260
  LOG:  redo starts at 0/C0081D0
  LOG:  record with zero length at 0/C008260
  LOG:  database system is ready to accept read only connections
  cp: cannot stat `/home/pgsql/data2/archive/00000001000000000000000C': No such file or directory
  LOG:  streaming replication successfully connected to primary
  server starting
  postgres@<===>:~$ ps -ax
  -------------------------------------------------------------------------------------------
  dan di cek standby ternyata terjadi sinkronisasi ( data yang transaksi di primari juga ada di standby ).
5.jika sisi primary di matikan mendadak ( tekan tombol power ) sisi standby tetap tidak bisa buat transaksi
  terdapat pesan " cannot execute INSERT in a read-only transaction "
  dan jika primary di nyalakan lagi dan service postgres dinyalakan belum terjadi streaming lagi.
  streaming bisa dilakukan lagi bila standby di stop service postgre nya dan di startup lagi servicenya ( restart service )
6.jika triger failover di buat maka standby akan menjadi master. selanjutnya master ini disebut mastersy
  dan master awal bisa dijadikan slave selanjutnya slave ini disebut standbym
  standbym buat initial baru ( direktory baru buat data base ) dengan initdb
  proses selanjutnya sama dengan diatas untuk membuat standby biasa hanya saja perlu di ubah untuk path dan ip
  yang perlu diperhatikan :
  akan ada direktory failover ( berasal dr file untuk triger failover di mastersy ) direktory ini dihapus dulu.
 7.jika ada satu primary dan 2 standby, dan satu standby di trigger file fileover maka
  proses streaming replikasi akan putus dan stanby yg putus seolah2 jadi master sendiri /independent, dan proses
  primary dan standbya masih berjalan.\
8. jika ada satu primary dan 2 standby kemudian service primari di stop maka di kedua client akan ada message :
     
cp: cannot stat `/home/pgsql/data2/archive/000000020000000000000029': No such file or directory
cp: cannot stat `/home/pgsql/data2/archive/000000020000000000000029': No such file or directory
FATAL:  could not connect to the primary server: could not connect to server: Connection refused
        Is the server running on host "192.168.5.16" and accepting
        TCP/IP connections on port 5432?
   
cp: cannot stat `/home/pgsql/data2/archive/000000020000000000000029': No such file or directory
cp: cannot stat `/home/pgsql/data2/archive/000000020000000000000029': No such file or directory
FATAL:  could not connect to the primary server: could not connect to server: Connection refused
        Is the server running on host "192.168.5.16" and accepting
        TCP/IP connections on port 5432?
   
cp: cannot stat `/home/pgsql/data2/archive/000000020000000000000029': No such file or directory
cp: cannot stat `/home/pgsql/data2/archive/000000020000000000000029': No such file or directory
FATAL:  could not connect to the primary server: could not connect to server: Connection refused
        Is the server running on host "192.168.5.16" and accepting
        TCP/IP connections on port 5432?
message iniberulang2 sampai service primary aktive lagi
9.jika service primary masih nyala dan tiba2 primary mati mendadak...maka standby masih aktif dan masih bisa dilihat
  tapi tidak bisa buat transaksi.
10. Ada 1 primary dan 2 standby,kemudian primary mati mendadak, salah satu dari slave kemudian di jadikan primary
    dengan memberikan file triger (failover) saat itu standby yang lain masih dlm keadaan menunggu sampai primary utama aktif( nyala).
    saat standby dijadikan primary standby yang lain tidak bisa langsung dijadikan standby terhadap primary baru.
    matikan dulu service postgres di standby kemudian :
    dengan mengedit :
    recovery.conf di standby pada bagian :
    recovery_target_timeline = 'latest'
    primary_conninfo = 'host=192.168.5.16 port=5432 user=postgres '
    restore_command = 'cp  /home/pgsql/cobadb/archive/%f "%p"'  ----> sesuaikan pathnya

    kemudian lakukan copy dr primary baru ke standby ( 2 file terakhir di archive termasuk history)
    /usr/local/pgsql/bin/psql -c "SELECT pg_start_backup('label',true)"
    rsync -a -v -e ssh /home/pgsql/cobadb/archive/000000020000000000000036 192.168.5.11:/home/pgsql/cobadb/archive/       -->ada 2 path perhatikan
    rsync -a -v -e ssh /home/pgsql/cobadb/archive/00000003.history 192.168.5.11:/home/pgsql/cobadb/archive/
    /usr/local/pgsql/bin/psql -c "SELECT pg_stop_backup()"

    setelah itu aktifkan service postgres maka "standby akan ready to accept connections"