Friday, January 29, 2010

SNMP & Cacti Configuration

Basically, i refer my SNMP and Cacti installation here. It works nicely. I would like to paste here everything i have done to make it works in my PC.

Below is how the architecture looks since I want Cacti to monitor many devices at a time. Firstly, assign one PC as manager (which Cacti will be installed) and all of devices to be monitored. They are connected using SNMP.


Below is the setting I had done to my manager:

1) Firstly, install SNMP
$sudo apt-get install snmpd

2) Then check
$sudo gedit /etc/default/snmpd

Make sure
# snmpd control (yes means start daemon).
SNMPDRUN=yes

# snmpd options (use syslog, close stdin/out/err).
SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid 127.0.0.1'

3) Next,
$sudo gedit /etc/snmp/snmpd.conf

In the line of com2sec setting, I have adjusted as below (slightly different from How-To)
# sec.name source community
com2sec readonly localhost public

If you have your own community, you could use it for better security.

4) Check SNMP configuration
$snmpwalk -Os -c public -v 1 localhost system

(If you use your community, replace 'public' with your community name)

This command will return result something like this:


5) CACTI- Installation
I did exactly like here.

For all other devices, configure SNMP server same like above. That's all :)

Sunday, January 17, 2010

Mysql Cluster with Mysql 5.1 on Ubuntu Server 9.10

We're currently implementing memcached on mysql cluster using mysql 5.1. So, to make it quick, i followed a guide from howtoforge written by Peter Okupski in this site. It works for me.

There are several things need to be concerned before implementing this guide on ubuntu server 9.10.
  1. Don't install mysql-server5.1 from the repository using apt-get.
    For me, it's easier to install mysql cluster by using source code in ubuntu. Source code can be downloaded form mysql site. On 'select platform' option, choose 'source code' and download the tar file mysql-cluster-gpl-[version].tar.gz
    (Note: register, it is free!)

  2. Install build-essential package to allow compiling source file
    $ sudo apt-get install build-essential

  3. Install developer's library for ncurses
    $ sudo apt-get install libncurses5-dev

    This will avoid an error:
    configure error: No curses/termcap library found
Now, it's ready :-)

References:

Sunday, January 10, 2010

Setting Up Gateway in Ubuntu

I just think how to set up simple gateway server for a LAN. After searched for a while, i found some useful guide (see references).
First, the server machine needs to have at least two interfaces, e.g. eth0 and eth1. In my case, I used eth0 for connecting to internet and eth1 for connecting LAN connection.
It is not necessarily use eth0 to be connected to Internet. It depends on your Internet connection. It could be wlan0, ppp0 etc. This also useful for connecting two different networks.

Assume that your machine will be used as a gateway. This guide will be based on the figure below:


IP address Configuration
In this guide, IP address for each host in LAN need to be configured manually, unless DHCP server is installed.

DNS Server and Gateway
All hosts in LANneed to have same DNS server as your machine has and add the IP address of your machine as a gateway in LAN hosts, so that the IP packets will be route to the Internet through your machine.

Configuration of 'Gateway' machine
Step 1: Find DNS server on your machine
$ cat /etc/resolv.conf

The output will be like this
# Generated by NetworkManager
nameserver 10.1.2.21
nameserver 10.0.0.92

Step 2: Enable IP forwarding
First, check the default value. There are two ways.
Note: 0 means it is disabled

1. using sysctl command.
$ sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 0

2. cat the file /proc/sys/net/ipv4/ip_forward.
$ cat /proc/sys/net/ipv4/ip_forward
0

Second, change the value temporarily, so that, it will reset to 0 when you have shutting down the machine.
$ sudo sysctl -w net.ipv4.ip_forward=1

Try to check again to see the changed value.

To permanently enable the IP forwarding, you need to edit sysctl configuration file. Use any familiar text editor such as nano, vi and gedit.
$ sudo gedit /etc/sysctl.conf

Find these two lines, and uncomment the second line (remove the # symbol)
Before:
# Uncomment the next line to enable packet forwarding for IPv4
#net.ipv4.ip_forward=1

After:
# Uncomment the next line to enable packet forwarding for IPv4
net.ipv4.ip_forward=1

or simply edit using this command:
$ sudo sed -i 's/#net.ipv4.ip_forward/net.ipv4.ip_forward/g' /etc/sysctl.conf

Then update the change made.
$ sudo sysctl -p /etc/sysctl.conf

Step 3: Configure NAT on IP tables
iptables is very useful for maintain tables of IPv4 packet filtering in linux kernel. It has lots of chain rule. For performing NAT we have the command above (see manual for details):
$ sudo iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE

-t nat, an option of IP table to perform NAT at each packet matching.
-A POSTROUTING. The –A is used for append chain rule of –t and we use POSTROUTING for altering packets as they are about to go out.

-s indicates as source address from where the IP packet can route through the NAT. it should be followed by IP address along with the netmask. In this command it shows and IP address of 192.168.1.0 with subnet mask 255.255.255.0, which need to be written as 192.168.1.0/24. This IP will be used in LAN from 192.168.1.1 - 192.168.1.254. Your machine can use 192.168.1.1 for eth0 interface. (Google IP and subnet mask tutorial)

-o is used for name of an interface via which a packet is going to be sent (POSTROUTING). In this example, we used eth0 since it is the only interface that can be connected to internet.

-j should be followed by target extension. In this option we choose MASQUERADE. This target is only valid in the NAT table, in the POSTROUTING chain. Masquerading is equivalent to specifying a mapping to the IP address of the interface the packet is going out.

Now, restart your network service (not necessary)
$ sudo /etc/init.d/networking restart

We are done configuring IP forwarding, NAT and gateway on your machines. The next step is configuring IP address on LAN hosts.

Configuration of Hosts in LAN
Enter IP address to the hosts in range 192.168.1.2 - 192.168.1.254.
in the gateway field, put the IP address of 'gateway' machine, which is 192.168.1.1

Then, add the IP address for DNS server similar to the gateway configuration.

Last, restart the network for linux host. Note that the configuration will be the same for Windows hosts.
Done.

Check internet connection for the hosts in LAN
Hope this will help you. Enjoy!

References:

Wednesday, December 16, 2009

Share Folder on Ubuntu

Hi, I like google, so i wanna share things i got from google. It teach me a lots. But actually, our proposal still not completely done yet. We need to find more about the tools used, MySQL cluster stuff etc.
Now, let's see how to share directory in ubuntu and other Linux distributions.

It is very useful to share things over network. Computer users usually share their directories inside their LAN, containing files such as documents, audio files, or movies. This post will simply make your directory shared over network to Linux and Windows client. The famous Linux program used is samba (ask google please). I'm currently using Karmic Koala (9.10) so the default setting might be somewhat different from other versions.

Samba Server
There are two ways, graphical and command line interface. We will focus on CLI.

Step 1: install samba
$ sudo apt-get install samba

Step 2: configure samba file /etc/samba/smb.conf
Make sure backup the original file
$ sudo cp /etc/samba/smb.conf /etc/samba/smb.conf

Then use any editor such as gedit, nano, etc.
$ sudo gedit /etc/samba/smb.conf

First, check these following lines are correctly in default
workgroup = WORKGROUP
server string = %h server (Samba, Ubuntu)

Note: the %h will show your hostname. So, put anything you want as the server name.

If you want to share your home directory, remove the semicolon on each of this line
;[homes]
; comment = Home Directories
; browseable = no

You also can share any directory you want by creating your own entry, but make sure the directory exists. For example, you might want to share your 'video' directory on path /home/user1/video, so you need to add these lines
[my_videos]
comment = video
path = /home/user1/video
read only = yes
guest ok = yes
browseable = yes

Some explanations on this entry.
The bracket [..] is used to rename the shared directory
comment is just some note
path is the location of the share directory
read only, to disallow from being written
guest ok, allow 'guest' user to be connected without password

For example, Linux client can be connected by smbclient command with -U option which indicate as user. (will be explained in Linux and Windows Client section)
browseable, allow other users in network to see your shared directory
Some Tips:
Run this command inside share directory to make all directories, sub-directories and files are in read-only permission

For directory, (drwxr-xr-x)
$ find . -type d -exec chmod 755 {} \;

For files, (-rwr—r--)
$ find . -type d -exec chmod 644 {} \;

Linux client
For Linux client to connect to the shared directory, just go to nautilus and simply use the IP address or the hostname. Then you will see the shared directory.

Make sure you have installed smbclient package.
$ sudo apt-get install smbclient

Then, type the samba server IP address on nautilus location bar as follow:
smb://ip_address
smb://hostname

Also can be opened from web browser, but the appearance will be same like ftp

Client also can connect thorugh command line.
To list files shared directory as user 'guest'. The user should be exist
$ smbclient -L //192.168.56.1 -U guest

Direcly connect (almost similar to ftp)
$ smbclient //server/shared_directory -U user

Example,
$ smbclient //192.168.56.101/ shared_directory -U guest
Enter guest's password:
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.4.0]
smb: \>

For Windows client
Start -> Run
Then type the IP address or hostname, also can be connected through windows explorer (same as nautilus).
It also can be opened from browser by entering server ip address
\\ip_address

Hope this will help you. Enjoy!

References:

Perl for Noob

As before in our course of study, we just familiar with C, C++ and Java. For the sake of our project, I have been exploring Perl. Noted that memcached was firstly written by Brad Fitzpatrick together with Anatoly Corobey in Perl.

This is just fast study for very very very beginners of Perl (Correct me if i'm wrong, i am a noob too) :)

PERL - Practical Extraction and Report Language


Installing PERL
Perl is nicely included on Linux and Unix, but for Windows user, refer here. I currently use Ubuntu Karmic Koala, so I checked where is my Perl located by:

whereis perl

Most of the time, it located at /usr/bin/perl but anywhere doesnt matter. But, it's important to note whereis since it will be embedded in the first line of your script:

#!/usr/bin/perl --> This line must appear in the very first line of your script except for some condition I'll explain below.

OK, next to check is the version of your Perl.

perl -v

Mine is 5.10 (latest by now). I read somewhere that version 5.6.0 isn't stable and buggy than the later versions so do update ok :)

Done with checking.

Writing PERL
Simply touch your program or Perl file by putting extension; .pl or .plx --Both ways are OK. (e.g.: touch file.pl). Then change the file mode (chmod u+x file.pl) so it's executable.

Open editor (gedit, nano, vi, pico -- any will works, but I just started to love mcedit because it's nice); mcedit file.pl

OK, like I said, your first line must be #!/usr/bin/perl BUT, if you're using Perl 5.10 like me, you could consider of using use feature ':5.10' to replace #!/usr/bin/perl. This indicate that we could use some new feature in this latest version where some reserve words are added to simplify works. Here, I will discuss some basic commands of 5.10.

Basically, there are three in total - variable types in Perl:
  • Scalar - holds single data (int, long, char, string)
  • Array - holds list for scalar (10 int, 100 char, etc)
  • Hash - hold key-pair, refer further explanation below.
  • So, let us go one by one. I promise it's simple.

    Scalar
    Define: use dollar sign ($) together with variable name. E.g.: $var, $name.
    Example: $a = "value"; $number = 1;



    Remember this rule,
    • $ for Scalar

    • @ for Array

    • % for Hash


    $calar hold single data, so to print specific data or one element in @rray or %ash, use $calar. :-)

    Tuesday, November 24, 2009

    Welcome!

    Hello, everybody!

    My name is Khairina. I am one of this blog author other than Hafiz, my friend. In this blog, we intended to share our interest on various things related to Linux and open-source and we hope later we are able to provide solutions to all your problems :-)