Tampilkan postingan dengan label Linux. Tampilkan semua postingan
Tampilkan postingan dengan label Linux. Tampilkan semua postingan

Kamis, 16 September 2010

Setup Nagios (NMS) om FEDORA

1- First install some tools : httpd, gcc, glib, glibc-common, gd and gd-devel

yum install httpd
yum install gcc
yum install glibc glibc-common
yum install gd gd-devel
 

2- Create nagios user :

#/usr/sbin/useradd -m nagios
#passwd nagios

3- Add nagcmd group

/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd apache

4- Now go to http://www.nagios.org download files .

nagios-3.1.0.tar.gz nagios-plugins-1.4.13.tar.gz nrpe-2.12.tar.gz

tar  -zxvf  nagios-3.1.0.tar.gz  
cd  nagios-3.1.0
./configure --with-command-group=nagcmd
 #make all; make install; make install-init; make install-config; make install-commandmode; make install-webconf

5- Edit your email admin address :

Go to

vi /usr/local/nagios/etc/objects/contacts.cfg

6- Create a nagiosadmin account for logging into the Nagios web interfaceassign to this you’ll need it later.

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

enter the password.

7- Restart the httpd server :

#Service  httpd   restart

The second step : Extract and install plugins

1- Go to you downloaded nagios tools

 tar  -zxvf   nagios-plugins-1.4.13.tar.gz

2- cd nagios-plugins

./configure --with-nagios-user=nagios --with-nagios-group=nagios
make; make   install

3- Now you have to add nagios to Chkconfig

chkconfig --add nagios
chkconfig nagios on

4- Verify if you have a good config of nagios with the command

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

5- Check if there are no errors displayed; then start nagios with command :

service  nagios  start

To simplify the procesure please disable the selinux and iptables and ip6tables

now open your browser and http://localhost/nagios orr http://ip/nagios

Kamis, 11 Maret 2010

Check mailbox size of all accounts in Zimbra mail server

Buat File dengan isi Scrip di bawah ini :

################
#!/bin/bash
all_account=`zmprov gaa`;
for account in ${all_account}
do
mb_size=`zmmailbox -z -m ${account} gms`;
echo "Mailbox size of ${account} = ${mb_size}";
done
##############

misal nya : checkmailsize.sh

# chmod 755

untuk menjalankan nya

# ./checkmailsize.sh


Kamis, 11 Februari 2010

Automating Cisco Router Backups

Automating Cisco Router Backups


tep 1: Download and install rancid.
——————————————————————–

For additional information on rancid’s complete functionality see the following site.

http://www.shrubbery.net/rancid/

Install rancid, build-essential, and expect.

Code:
sudo apt-get install rancid-core rancid-util build-essential expect

Step 2: Create .cloginrc file in the rancid directory.
——————————————————————–

Opend a terminal and type the following.

Code:
sudo gedit /var/lib/rancid/.cloginrc

Add entries for each router, switch, pix firewall you’d like to backup by using the following format.

Code:
add password    IPADDRESS       {telnetpassword}      {enablepassword}

IPADDRESS = the actual ip address of the device you want to backup.
telnetpassword = the actual telnet password for the device you want to backup.
enablepassword = the actual enable password for the device you want to backup.

The “{}” are required. At the bottom of the .clogin add the following line if you require SSH access to your equipment.

Code:
add method     *    telnet ssh

With this clogin will first try to telnet then ssh to your equipment.

Step 3: Protect the .cloginrc file.
——————————————————————–

Code:
sudo chmod 640 /var/lib/rancid/.cloginrc

Step 4: Create a backup directory for backup configs.
——————————————————————–

Code:
sudo mkdir /var/lib/rancid/backups/

Step 5: Change ownership of the /usr/lib/rancid/backups/ directory.
——————————————————————–

Code:
sudo chown -R rancid.rancid /var/lib/rancid/backups/

Step 6: Change permissions to the rancid directory.
——————————————————————–

Code:
sudo chmod 770 /var/lib/rancid/

Step 7: Set password for rancid account
——————————————————————–

Code:
sudo passwd rancid

Step 8: Test .cloginrc
——————————————————————–

As the user rancid test accessing your equipment.

Code:
su rancid

Now using once of the network devices that you’ve put in the .cloginrc for rancid type the following in the open terminal.

Code:
/usr/lib/rancid/bin/clogin  IPADDESSOFDEVICE

You should see the clogin telnet (or ssh) to the device in question and switch to enable mode on the device. If everything works the proceed on to step 8. Otherwise take a look at your /var/lib/rancid/.cloginrc .


Step 9: Test grabing a backup config from the same device.

——————————————————————–

As rancid run the following test to make sure that you have everything setup correctly.

Code:
/usr/lib/rancid/bin/clogin  -c 'write term' IPADDESSOFDEVICE > /var/lib/rancid/backups/test.cfg

Verify the output:

Code:
less /var/lib/rancid/backups/test.cfg

If everthing checks out move on to step 10.

Step 10: Create the bash script for the backups
——————————————————————–

Here’s a sample script for you to copy and paste into a file (i.e. network_device_backup.sh) and to tweak, add, or change for your needs. But save the script somewhere the rancid user can access and execute the script from (i.e./var/lib/rancid/). If you are planning on backing up a various types of routers, switches, firewalls etc you may want to create serveral differnet scripts.

Code:
#!/bin/bash
# Variables

clogin=/usr/lib/rancid/bin/clogin
path=/var/lib/rancid/backups/
tdy=`date +%m%d%Y`

#backup network device

$clogin -c 'write term' 192.168.0.1 > $path/foo-$tdy.cfg

NOTE: When rancid is installed the default shell for the rancid user is csh. So for the script above to work the “#!/bin/bash’ is needed.

Step 11: Make the script executable to rancid.
——————————————————————–

Code:
sudo chmod 700 /path/to/script

Step 12: Test the backup script.
——————————————————————–

Test your script logged in as rancid.

Code:
su rancid

Now from wherever you put the backup script verify that it works before adding it as a cron job. For this example I’m going to use the following location /var/lib/rancid/.scripts/routers.sh with the output path being /var/lib/rancid/backups/.

Code:
 ./var/lib/rancid/.scripts/routers.sh

verify the config file that was generated to the output path you specified.

Code:
less /var/lib/rancid/backups/foo-12202005.cfg

Step 13: Add script to CRON.
——————————————————————–

As rancid add your script to CRONTAB.

Code:
su rancid

Now add an entry for your script.

Code:
crontab -e

To backup your equipment every Friday at 5pm should look like…

0 17 * * 5 /var/lib/rancid/.scripts/routers.sh >/dev/null 2>&1

Save the entry (crtl+x).

Verify the entry in crontab is correct.

Code:
crontab -l

For more infor on CRONTAB see the following post.
http://ubuntuforums.org/showthread.php?t=102626

Jumat, 29 Agustus 2008

Otomatisasi firewalling IP dan MAC Address dengan bash script

Bagaimana jika client kita berjumlah banyak, puluhan atau ratusan. Yang terpenting adalah, kita mempunyai daftar IP Address dan MAC Address client yang terhubung. Dengan menggunakan sedikit baris bash script sederhana, kita dapat membuat otomatisasinya.
Berikut langkah-langkahnya :

1. Buat file bernama rc.iplock didalam directory /etc/rc.d/ dengan isi sebagai berikut :

#!/bin/bash
# Bash script Lock IP Address dan MAC Address
iptables="/sbin/iptables" #path ke iptables
files="/etc/rc.d/list.txt" #path ke list IP Address dan MAC Address
device="eth1" #ethernet devices ke client
lockall="yes" #yes|no ,yes jika mendaftarkan semua IP & MAC Address
#jika tidak, tulis no.
#yes untuk metode pertama, no untuk metode kedua


if [ $lockall = "yes" ]; then
$iptables -I PREROUTING -t nat -i $device -j DROP
cat $files | while read ip_address mac_address; do
$iptables -I PREROUTING -t nat -i $devices -s $ip_address
-m mac --mac-source $mac_address -j ACCEPT
$iptables -I FORWARD -i $device -s ! $ip_address
-m mac --mac-source $mac_address -j DROP
$iptables -I PREROUTING -t nat -s ! $ip_address
-m mac --mac-source $mac_address -j DROP
done
elif [ $lockall = "no" ]; then
$iptables -I PREROUTING -t nat -i $device -j ACCEPT
cat $files | while read ip_address mac_address; do
$iptables -I FORWARD -i $device -s ! $ip_address
-m mac --mac-source $mac_address -j DROP
$iptables -I PREROUTING -t nat -s ! $ip_address
-m mac --mac-source $mac_address -j DROP
done
fi

echo "Locking IP Address and Mac Address..."
#end script


2. Buat file bernama list.txt didalam directory /etc/rc.d/ dengan format penulisan sebagai berikut :



Peringatan!! Jangan tambahkan baris apapun atau kalimat apapun selain format diatas!

Contoh isi file /etc/rc.d/list.txt untuk 3 client:

192.168.1.5 00:89:CD:64:01:EF
192.168.1.20 00:90:DD:14:11:CF
192.168.1.14 00:40:EE:21:26:GE


3. Set file rc.iplock agar dapat di eksekusi :

chmod +x /etc/rc.d/rc.iplock


4. Tambahkan didalam file /etc/rc.d/rc.local agar dapat di eksekusi pada saat start up :

/etc/rc.d/rc.iplock


5. Jalankan :

/etc/rc.d/rc.iplock

6. Selesai! Selamat Anda dapat bintang =P

Firewalling IP Address dan MAC Address dengan iptables

Kadang kita sebagai administrator suatu jaringan sangat dipusingkan dengan beberapa client "nakal" yang suka berganti-ganti IP Address. Padahal sebelumnya suatu IP Address tertentu dari client sudah kita blok aksesnya untuk jam-jam tertentu, atau kita blok untuk mengakses suatu situs tertentu.
Mungkin sedikit yang bisa saya berikan disini adalah, bagaimana kita dapat mengatasi "kenakalan" client-client tersebut agar tidak bisa mengganti IP Address mereka secara "enaknya saja". Saya harapkan Anda paling tidak sudah tahu apa itu IP Address dan apa itu MAC Address.

Keuntungan dan kerugian :

  • Keuntungan yang didapatkan adalah, kita dapat dengan mudah memonitor "pergerakan" client dan melakukan logging untuk administrasi jaringan atau analisa-analisa lain yang diperlukan, karena client tidak dapat melakukan perubahan IP Address.
  • Kerugian, seandainya saja interface hardware milik client mengalami kerusakan dan melakukan pergantian, kita harus melakukan konfigurasi ulang rules firewall kita berdasarkan MAC Address yang baru. Tapi kerusakan ini sangat jarang terjadi.


Ada 2 metode yang saya gunakan disini dan dapat rekan-rekan sekalian pilih salah satunya, yaitu :

  • Pertama, apakah kita akan melakukan pendaftaran semua IP Address dan MAC Address client-client kita dan tidak memperkenankan semua client yang terhubung dengan kita tidak dapat berganti-ganti IP Address. Jika IP dan MAC Address tidak terdaftar didalam rules firewall, maka client tidak dapat melakukan koneksi.
  • Kedua, apakah kita hanya menginginkan IP Address dan MAC Address tertentu saja yang tidak kita inginkan untuk berganti-ganti IP Address. Disini, jika ada IP baru dan dengan MAC Address baru, client tetap dapat melakukan koneksi.

Kasus, disini kita mempunya 3 client, yaitu :
IP Client 1 = 192.168.1.5
MAC Address 1 = 00:89:CD:64:01:EF

IP Client 2 = 192.168.1.20
MAC Address 1 = 00:90:DD:14:11:CF

IP Client 3 = 192.168.1.14
MAC Address 3 = 00:40:EE:21:26:GE

Semua client terkoneksi melalui ethernet (LAN Card/NIC) 1 yang diberi nama eth1.

Firewalling dengan metode pertama :

#drop semua prerouting di eth1
iptables -I PREROUTING -t nat -i eth1 -j DROP

#------------------- client pertama------------------------
#accept IP 192.168.1.5 dengan mac address 00:89:CD:64:01:EF
iptables -I PREROUTING -t nat -i eth1 -s 192.168.1.5
-m mac --mac-source 00:89:CD:64:01:EF -j ACCEPT

#drop IP 192.168.1.5 dengan mac address 00:89:CD:64:01:EF
#jika menggantinya dengan IP lain selain dari 192.168.1.5
iptables -I FORWARD -i eth1 -s ! 192.168.1.5
-m mac --mac-source 00:89:CD:64:01:EF -j DROP

#drop prerouting IP 192.168.1.5 dengan mac address 00:89:CD:64:01:EF
#jika menggantinya dengan IP lain selain dari 192.168.1.5
iptables -I PREROUTING -t nat -s ! 192.168.1.5
-m mac --mac-source 00:89:CD:64:01:EF -j DROP

#------------------- client kedua------------------------
#accept IP 192.168.1.20 dengan mac address 00:90:DD:14:11:CF
iptables -I PREROUTING -t nat -i eth1 -s 192.168.1.20
-m mac --mac-source 00:90:DD:14:11:CF -j ACCEPT

#drop IP 192.168.1.20 dengan mac address 00:90:DD:14:11:CF
#jika menggantinya dengan IP lain selain dari 192.168.1.20
iptables -I FORWARD -i eth1 -s ! 192.168.1.20
-m mac --mac-source 00:90:DD:14:11:CF -j DROP

#drop prerouting IP 192.168.1.20 dengan mac address 00:90:DD:14:11:CF
#jika menggantinya dengan IP lain selain dari 192.168.1.20
iptables -I PREROUTING -t nat -s ! 192.168.1.20
-m mac --mac-source 00:90:DD:14:11:CF -j DROP

Catatan :
Disini karena client 3 tidak masuk kedalam rules, maka tidak dapat melakukan koneksi, walaupun berganti IP Address yang sama dengan client 1 dan 2. Sedangkan client 1 dan 2 tetap dapat melakukan koneksi, selama tidak melakukan perubahan IP Address.


Firewalling dengan metode kedua :

#------------------- client pertama------------------------
#drop IP 192.168.1.5 dengan mac address 00:89:CD:64:01:EF
#jika menggantinya dengan IP lain selain dari 192.168.1.5
iptables -I FORWARD -i eth1 -s ! 192.168.1.5
-m mac --mac-source 00:89:CD:64:01:EF -j DROP

#drop prerouting IP 192.168.1.5 dengan mac address 00:89:CD:64:01:EF
#jika menggantinya dengan IP lain selain dari 192.168.1.5
iptables -I PREROUTING -t nat -s ! 192.168.1.5
-m mac --mac-source 00:89:CD:64:01:EF -j DROP

#------------------- client kedua------------------------
#drop IP 192.168.1.20 dengan mac address 00:90:DD:14:11:CF
#jika menggantinya dengan IP lain selain dari 192.168.1.20
iptables -I FORWARD -i eth1 -s ! 192.168.1.20
-m mac --mac-source 00:90:DD:14:11:CF -j DROP

#drop prerouting IP 192.168.1.20 dengan mac address 00:90:DD:14:11:CF
#jika menggantinya dengan IP lain selain dari 192.168.1.20
iptables -I PREROUTING -t nat -s ! 192.168.1.20
-m mac --mac-source 00:90:DD:14:11:CF -j DROP

Catatan :
Disini walaupun client 3 tidak masuk kedalam rules, tetap dapat melakukan koneksi, walaupun berganti IP Address asal tidak sama IP Addressnya dengan client 1 dan 2. Client 1 dan 2 tetap dapat melakukan koneksi, selama tidak melakukan perubahan IP Address.

Sabtu, 09 Agustus 2008

Installing and Configuring Cacti on Ubuntu Server

1. Install Apache Web Server with PHP support in Ubuntu Server

root@ovick:/# apt-get install apache2 apache2-mpm-prefork apache2-utils
root@ovick:/#
apt-get install libapache2-mod-php5 php5-cli php5-common php5-cgi php5-gd

2. Install Mysql Server with php Support

root@ovick:/# apt-get install mysql-server mysql-client libmysqlclient-dev
root@ovick:/#
apt-get install php5-mysql phpmyadmin

Other Dependencies Installation
root@ovick:/#
apt-get install make gcc g++ build-essential
root@ovick:/#
apt-get install cgilib libttf-dev libttf2 libpngwriter0-dev libpng12-dev libfreetype6-dev libart-2.0-dev snmp snmpd

edit the snmp community name and rights

ex: snmpd.conf
#####################################################
# sec.name source community
com2sec local localhost public
com2sec mynetwork 192.168.4.0/29 public
####
# Second, map the security names into group names:
# sec.model sec.name
group MyRWGroup v1 local
group MyRWGroup v2c local
group MyRWGroup usm local
group MyROGroup v1 mynetwork
group MyROGroup v2c mynetwork
group MyROGroup usm mynetwork

# Third, create a view for us to let the groups have rights to:
# incl/excl subtree mask
view all included .1 80

####
# Finally, grant the 2 groups access to the 1 view with different
# write permissions:
# context sec.model sec.level match read write notif
access MyROGroup "" any noauth exact all none none
access MyRWGroup "" any noauth exact all all none
access MyGroup "" any noauth exact all all none

# System contact information
syslocation Ubuntu-ku
syscontact System Ovick
################################################

setelah edit snmpd.conf renstart service nya
root@ovick:/#
/etc/init.d/snmpd restart
Untuk mengetes snmp nya :
root@ovick:/# snmpwalk -v1 -c public localhost

3. Install RRD Tool From Source

Download rddtool yang terbaru

root@ovick:/# cd /usr/local/bin
root@ovick:/#
wget http://oss.oetiker.ch/rrdtool/pub/rrdtool.tar.gz
root@ovick:/#
tar xfvz rrdtool.tar.gz
root@ovick:/#
rm rrdtool.tar.gz
root@ovick:/#
cd rrdtool-1.2.23
root@ovick:/#
./configure
root@ovick:/#
make
root@ovick:/#
make install

3. Installing Cacti From Source

root@ovick:/# cd /var/www/
root@ovick:/#
wget http://www.cacti.net/downloads/cacti-0.8.6j.tar.gz
root@ovick:/#
tar xzvf cacti-0.8.6j.tar.gz
Buat direktori cacti and pindahkan isi smua isi derektori
cacti-0.8.6j ke direktori cacti
root@ovick:/#
mv cacti-0.8.6j cacti


4.Created the user and group

root@ovick:/# groupadd cacti
root@ovick:/# useradd -g cacti cacti
Now you need to make sure that you have the correct permissions for inside cacti folders and files
root@ovick:/#
cd /var/www/cacti
root@ovick:/# chown -R cacti:cacti rra/ log/

5. Create the cacti db in phpmyadmin

http://YOURIP/phpmyadmin
login using root account
set root password on phpmyadmin if you have already

Privileges>Root>edit privileges>change password
Do this for all 3 root accts listed (I do middle last because that’s the one that will lock you out after setting it)

Create cacti user
Privileges>add new user
user name: cacti
host: localhost
password: cacti

database for user: create database with same name and grant all privileges > Go
then I give the user grant access to it too
privileges>cacti>edit privileges>database specific privileges>Add privileges on the following database: cacti>Go

check the “grant box” (make sure all others are still checked)

root@ovick:/# mysql –p –u root cacti < cacti.sql

root@ovick:/# mysql –p –u root

root@ovick:/# mysql> flush privileges;

root@ovick:/# mysql> exit

Now you need to Edit /var/www/cacti/include/config.php and specify the MySQL user, password and database for your Cacti configuration.

root@ovick:/# vi /var/www/cacti/include/config.php

$database_default = “cacti”;
$database_hostname = “localhost”;
$database_username = “cacti”;
$database_password = “cacti”;

Enter a valid username for cacti, this user will also be used in the next step for data gathering.

Now we need to add the crontab for poller
crontab -e

Add the following line ans save you can chnage the time whenever you want.
*/5 * * * * php /var/www/cacti/poller.php > /dev/null 2>&1

Point your web browser to http://your-server-ip/cacti/ this will start with the following screen here click next
Enter admin admin for login

Change admin password
System settings
Change snmp community to your company’s community name save

Paths:
RRDTool Default Font Path
/usr/local/bin/rrdtool/src/DejaVuSansMono-Roman.ttf


I always force one entry for the graphing by using the cron command, use this:
php /var/www/cacti/poller.php > /dev/null 2>&1

(if not you will have red X on boxes where graphs should be (in IE7, blank in Firefox)
If they are red X’s wait for a bit until the first line gets mapped (every 5 min)
If you still have red X's check your RRDTool path, it must point to the bin, not the path.
then go to graphs.

Update your cacti:

root@ubuntu-ku:/# cd /vaw/www/cacti

root@ovick:/var/www/cacti-0# wget http://www.cacti.net/downloads/patches/0.8.6j/ping_php_version4_snmpgetnext.patch
root@ubuntu-ku:/var/www/cacti-0#
wget http://www.cacti.net/downloads/patches/0.8.6j/tree_console_missing_hosts.patch
root@ubuntu-ku:/var/www/cacti-0# wget http://www.cacti.net/downloads/patches/0.8.6j/thumbnail_graphs_not_working.patch
root@ubuntu-ku:/var/www/cacti-0# wget http://www.cacti.net/downloads/patches/0.8.6j/graph_debug_lockup_fix.patch
root@ubuntu-ku:/var/www/cacti-0# wget http://www.cacti.net/downloads/patches/0.8.6j/snmpwalk_fix.patch
root@ubuntu-ku:/var/www/cacti-0# patch -p1 -N < ping_php_version4_snmpgetnext.patch
root@ubuntu-ku:/var/www/cacti-0# patch -p1 -N < tree_console_missing_hosts.patch
root@ubuntu-ku:/var/www/cacti-0# patch -p1 -N < thumbnail_graphs_not_working.patch
root@ubuntu-ku:/var/www/cacti-0# patch -p1 -N <>

6. Try to open full path url http://cactiserver/cacti/

All done with following those step carefully.
Singkat cerita, cacti saya sudah dapat berjalan dengan mengikuti langkah-langkah tersebut di atas.
Selamat mencoba, Good Luck

Reference :
1. http://www.cacti.net/downloads/docs/html/unix_configure_cacti.html

Label