Dec 22, 2011

make sure pgpool node/instance is up ( with bash script )

--idea--
this idea came to me when some one ask " how do we ensure that postgresql's node has been activated again ? ". by asking google and with have no answer, finally why we don't make a happy script with bash ^_^...

--scenario--
as simple as i love to, this script is run as background service that check node's status every 3 second. And if one of node/both is down, script is automatic bring it UP/ON again.

--1--
must to know  how to chek node status:
*> node UP/ON
$ tail /var/log/pgpool.log
2011-12-22 10:06:18 DEBUG: pid 8726: starting health checking
2011-12-22 10:06:18 DEBUG: pid 8726: health_check: 0 th DB node status: 1
2011-12-22 10:06:18 DEBUG: pid 8726: health_check: 1 th DB node status: 1

$ pcp_node_info 10 localhost 9898 postgres password 1
xxx.xxx.xxx.xxx. xxxx 1 1073741823.500000
$ pcp_node_info 10 localhost 9898 postgres password 1 | awk '{print $3}'
1

*> node Down
$ tail /var/log/pgpool.log
2011-12-22 10:14:41 DEBUG: pid 8726: starting health checking
2011-12-22 10:14:41 DEBUG: pid 8726: health_check: 0 th DB node status: 1
2011-12-22 10:14:41 DEBUG: pid 8726: health_check: 1 th DB node status: 3

$ pcp_node_info 10 localhost 9898 postgres password 1
10.10.130.17 5432 3 1073741823.500000
$ pcp_node_info 10 localhost 9898 postgres password 1 | awk '{print $3}'
3

--script--

#!/bin/bash
# brekele.inc

Node_stat=`pcp_node_info 10 localhost 9898 postgres password 0 | awk '{print $3}'`
Node_stat2=`pcp_node_info 10 localhost 9898 postgres password 1 | awk '{print $3}'`

echo "PID: $$ : `date` : daemon check \" $0 \" is running"
echo "=========== Hit Ctl-C to exit ============"

start(){
#echo "jalankan"
pcp_attach_node  90 localhost 9898 postgres password 0 && echo "node UP" || echo "node Down"
}

start2(){
#echo "jalankan"
pcp_attach_node  90 localhost 9898 postgres password 1 && echo "node UP" || echo "node Down"
}

if [ $Node_stat -eq 3 ]
then
start
fi

if [ $Node_stat2 -eq 3 ]
then
start2
fi

sleep 3
exec $0

echo "This line will never echo!"
exit 99

--cek & jajal--
try run on your own terminal/console and with your awn risk ^_^
$ ./script
PID: 26284 : Thu Dec 22 10:43:06 WIT 2011 : daemon check " /mnt/script " is running
=========== Hit Ctl-C to exit ============
PID: 26284 : Thu Dec 22 10:43:09 WIT 2011 : daemon check " /mnt/script " is running
=========== Hit Ctl-C to exit ============



Oct 20, 2011

send oracle 11g audit log to syslog server ( on other PC)

--preparation-- 
well...... this time i will write about syslog, and for this experiment what we need is :
- kiwi syslog server get from here and install it on your PC( i use xp for this server syslog)
- oracle db
- and of course, a cup of coffee is a must and other thing that make you relax and comfortable ( :p )

--scema--
first thing to do is redirect oracle audit log to syslog, and than from syslog send to syslog server( kiwi syslog)

 --1--
 edit initSID.ora and add this folowing config :
create "/var/log/oracle/" firs
audit_file_dest='/var/log/oracle/'
audit_trail='OS'
AUDIT_SYSLOG_LEVEL=local1.warning
after that edit /etc/syslog.conf, and add this folowing config :
#Save oracle rdbms audit trail to oracle_audit.log
local1.warning          /var/log/oracle/oracle_audit.log
#Send oracle rdbms audit trail to remote syslog server
local1.warning       @1.1.1.1 #<= ip your syslog server
--2--
restart syslog service with command :
/sbin/service syslog restart     # or 
/etc/init.d/init.d/syslog restart 
oracle DB must be restart to
CONNECT SYS / AS SYSOPER
Enter password: password

SHUTDOWN IMMEDIATE
STARTUP
-----------------
SQL> shutdown IMMEDIATE
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> STARTUP
ORACLE instance started.

Total System Global Area 1075527680 bytes
Fixed Size                  1304704 bytes
Variable Size             264243072 bytes
Database Buffers          805306368 bytes
Redo Buffers                4673536 bytes
Database mounted.
Database opened.
--test and jajal--
try to login to your Oracle DB and log must be create on syslog and kiwi syslog ono other server like this folowing pict


-source -
oracle doc

Sep 22, 2011

pgpoolAdmin, web interface for pgpool

--preparation--
next capter of pgpool from my last post ( here), now i wanna post about a tool that can manage pgpool from web interface called pgpoolAdmin. next... enjoy the post... ^_^

--1--
first we need to download pgpooladmin from here, extrak and copy or move to http directory( for exp : /var/www) 
$wget http://pgfoundry.org/frs/download.php/2964/pgpoolAdmin-3.0.3.tar.gz
$tar zxvf pgpoolAdmin-3.0.3.tar.gz
$sudo cp -Rf pgpoolAdmin-3.0.3 /var/www/test

 --2--
install pgpooladmin via web on: http://localhost/test/install


make sure owner of that file is "www-data"(of course have write akses) and check again




login with user that you create on /etc/pcp.conf (for more detail see my last post




and done.ya.. tooo.......!!!
 ^_^

Sep 12, 2011

Sep 8, 2011

postgresql replication with pgpool2 on ubuntu



--preparation--
next capter from may last post, now we'll make repication of postgreSQL with pgpool on ubuntu. assumtion, we have 2 server with postgresql installed ( n running well ) on each server.
 --1--
 first install pgpooll2, with
sudo apt-get install pgpool2
--2--
 edit config file on /etc/pgpool.conf
# Host name or IP address to listen on: '*' for all, '' for no TCP/IP
# connections
listen_addresses = '*'

# Port number for pgpool
port = 5433

# Port number for pgpool communication manager
pcp_port = 9898

parallel_mode = false

# Replication mode
replication_mode = true

# Load balancing mode, i.e., all SELECTs are load balanced.
# This is ignored if replication_mode is false.
load_balance_mode = true

backend_hostname0 = '1.1.1.1'
backend_port0 = 5432
backend_weight0 = 1
backend_data_directory0 = ''
backend_hostname1 = '1.1.1.2'
backend_port1 = 5432
backend_weight1 = 1
backend_data_directory1 = ''
edit config file on /etc/pcp.conf Append the following line
postgres:ee26005a83e958c153b095a080b52d14
#postgres is user of your postgresql 
#and ee26005a83e958c15.. bla... bla... is postgres password in md5.
*Note:
      to get/convert password in md5, you can use this ex command :
               PG1:~$ pg_md5 your_pass
               ee26005a83e958c153b095a080b52d14  
--3--
 restart the service
/etc/init.d/postgresql restart
 /etc/init.d/pgpool2 restart
--cek 'n jajal--
 create database on pgpool port
createdb db_test –p 9898 –h 1.1.1.1 –U postgres
If replication is working properly, in both machines a new database called “db_test” should be created. use this command to check it up:
$ psql –l –p 5432 –h 1.1.1.1 –U postgres
$ psql –l –p 5432 –h 1.1.1.2 –U postgres

next chapter : .: here:.
source :
http://sameerajayalath.blogspot.com
 google.com

Aug 25, 2011

install lighttp + postgresql di ubuntu

-- back from old day--
long time since write my latest post. Now, it's time to write again.... ^_^
starting with this tittle..

--1--
just simple as usually, type this command on your terminal
$ sudo apt-get install postgresql postgresql-client libpq-dev postgresql-client-common lighttpd php5-cgi php5-pgsql php5-cli 

--2--
edit "php.ini" on
vi /etc/php5/cgi/php.ini 
; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; http://php.net/cgi.fix-pathinfo
cgi.fix_pathinfo=1

then run this command To enable the fastcgi configuration
sudo lighttpd-enable-mod fastcgi
  sudo lighttpd-enable-mod fastcgi-php
  sudo /etc/init.d/lighttpd force-reload

--test & jajal--
create php file on /var/www containing :
<?php
phpinfo();
?>


Jun 13, 2011

Webalizer - Statistik trafik/kunjungan web (ubuntu)

--goal--
make subdomain trafik statistik

--install--
run this command :
sudo apt-get install webalizer
edit "/etc/apache2/apache2.conf" , set
HostnameLookups Off 
into :
HostnameLookups On 

--1--
All we need is already prepared, now set log of vhost in "/etc/apache2/sites-enabled" to spesifict folder.
exp. $sudo vi /etc/apache2/sites-enabled/monitor
CustomLog ${APACHE_LOG_DIR}/access.log
into:
CustomLog ${APACHE_LOG_DIR}/vhost/monitor/access.log
restart service
$sudo /etc/init.d/apache2 restart

--2--
create another file config of webalizer in /etc/webalizer
exp. vi /etc/webalier/monitor.conf
set the LogFile to apache2 logfile:
LogFile /var/log/apache2/vhost/monitor/access.log # apache log
OutputDir /var/webalizer/monitor/     #webalizer report
Incremental     yes
ReportTitle Usage statistics for
HostName monitor.brekele.co.cc 

--3--
create script to run webalizer via crontab
exp. vi /etc/webalizer/cron_job
#!/bin/bash

echo "di jalankan pada: `date +"%d-%B-%Y  %r"` " > /etc/webalizer/log
for i in /etc/webalizer/*.conf; do webalizer -c $i ; done 
#will run all *.conf file of webalizer config
and add to crontab
crontab -e
*/3 * * * *     root    /etc/webalizer/cron_job > /dev/null
#sesuakan dengan jam anda :D


--test & jajal--



Apr 26, 2011

Apr 7, 2011

list directori on NginX

-- goal --
we can list a directory under web root folder

-- 1 --
edit /etc/nginx/sites-enabled/default
sudo vi /etc/nginx/sites-enabled/default
-- 2 --
add this following config :
server {

        listen   80; ## listen for ipv4
        listen   [::]:80 default ipv6only=on; ## listen for ipv6
        server_name  localhost;
        autoindex on;         # add this to your config
        access_log  /var/log/nginx/localhost.access.log;
--3--
then restart your services:
sakti@sakti-sama:~$ sudo /etc/init.d/nginx restart
Restarting nginx: nginx..
-- test&jajal --

Mar 25, 2011

blok domain dengan bind

 nb: mungkin dah ada yang publish, tetapi ini berdasar pengalaman pribadi ( dah lama cuman baru mod nulisnya :D )

--goal--
intinya adalah untuk mem- blok domain yang kita inginkan sehingga user tidak bisa meng- akses.

--peralatan--
peralatan yang perlu disiapkan antaralain :
- secangkir kopi
- cemilan apa aja ( rilex can be fun :D )
- http://dns-bh.sagadc.org/files/spywaredomains.zones
    *sesuaikan letak file zone nya dengan file zone settingan anda
- bind sudah ter-install dengan baik di server(gateway). intinya, ready to use.

--1--
tambahkan pada file /etc/bind/named.conf.local
include "/etc/bind/spywaredomains.zones";

--2--
restart bind anda :
/etc/init.d/bind9 restart

--cek n jajal--
root@traficmng# nslookup facebook.com
Server:  192.168.1.112
Address: 192.168.1.112#53

Name: facebook.com
Address: 192.168.1.112
NB: - facebook.com sudah inputkan dalam file spywaredomains.zones.
- Uji coba pada kubuntu 10.04 :D


--saran--
bisa di gabung dengan crontab atau yang script lain, untuk penjadwalan jam berapa saja domain di block :D


have fun..

Feb 25, 2011

Set Up manual ip address in kubuntu

Do the following things to get kubuntu connection working :
1) Disable Network Manager:
sudo update-rc.d -f NetworkManager remove
sudo apt-get remove network-manage
2) Edit /etc/network/interfaces:
auto lo eth0
iface lo inet loopback
iface eth0 inet static
address 192.168.2.2
netmask 255.255.255.0
gateway 192.168.2.1
dns-domain 192.168.2.1
3) Edit /etc/resolv.conf:
domain Home
nameserver 192.168.2.1
4) Restart networking:
sudo /etc/init.d/networking restart
Finally, test it with your own risk :D

source : ubuntu forum