Friday, July 8, 2011

Installing and setting up netdot on Ubuntu 10.04 to 11.04

2 comments
This is how to set up  netdot (from the University of Oregon) on Ubuntu. I've only tested this on Ubuntu 10.04 and 10.10 but there's no reason why it shouldn't work on 11.04 as well.

First of all install Apache and MySQL and Apache perl modules using the following commands.

sudo apt-get install apache2 apache2-dev mysql-server mysql-client \
libapache2-mod-perl2 libapache2-mod-perl2-dev build-essential 

When asked for a root password for MySQL provide one and remember it.

Download the latest version of netdot from here. (Not the VM, the Source Code) I used version 0.99.

Extract the package and change directory into it.

tar -xvzf netdot-0.99.tar.gz
cd netdot-0.99 

Netdot needs a whole lot of dependencies for it to install correctly. You can check which dependencies are missing by using the command:

make testdeps

You will get a long list of various packages needed by netdot and whether they are installed. Chances are, most of them will not be installed. You find and install them one by one, by the creators of netdot have very thoughtfully provided us with a handy script to take care of all that. Just type:

sudo make installdeps-apt-get

At the end of all the installing, it will download a file called oui.txt or something. You will see a list of organizations or something. Don't worry if it gets seems to get stuck some way down. Just terminate it.


Run make testdeps again to see if everything is installed. If everything went smoothly all the dependencies should now be ok. IF you are running 0.98 you will need to additionally install two more packages.

sudo apt-get install libssl-dev rrdtool

If all the dependencies are ok, you can get on with installing netdot, (If some of the dependencies have not been installed for some reason, you can try to install them manually) but first you must change the configuration file. Make a copy of the default config file that is provided, name it as Site.conf and open it for editing.

cp etc/Default.conf etc/Site.conf 

Include your MySQL root password in DB_DBA_PASSWORD.

Install netdot using the following command.

sudo make install APACHEUSER=www-data APACHEGROUP=www-data 


Install the database and populate it with default values.

sudo make installdb

Now you need to tell Apache what modules to load, where to find netdot etc... Just create a sym-link to the provided configuration file inside Apache's conf.d directory and restart Apache.

ln -s /usr/local/netdot/etc/netdot_apache2_local.conf /etc/apache2
/conf.d
service apache2 graceful

Now you should be able to access the netdot web interface at http://localhost/netdot
Default user name: admin,  password: admin

If netdot isn't able to discover devices, i.e, you get a

"ERROR - Device::_get_snmp_session: Cannot connect to domain.net. Tried communities: community " 

error, you need to install the following package

sudo apt-get install snmp-mibs-downloader


Then, edit your config file ( /usr/local/netdot/etc/Site.conf )

sudo vim /usr/local/netdot/etc/Site.conf

Comment out the line that says ":mibs", save and exit, restart Apache and you will be good to go.

Thursday, June 9, 2011

How to set up a CentOS repository

0 comments
If your organization is heavily reliant on a certain operating system, - say CentOS - on your workstations, it would be a good idea to set up a local repository. Each time a workstation needs a new software download or upgrade, it doesn't have to go to the internet. The idea is that our repository will work quietly every night and download the latest updates from official mirror sites. Come morning, when the machines are booted up, a fully updated local mirror will be waiting to serve the machines on the local network, saving loads of precious bandwidth and time.

The task is pretty simple. I'm sure there are probably more ways to so this, but this is how i know it. It works too!

What I will be doing is locating a mirror on the internet that supports "rsync". "rsync" is a Linux command that has a pretty straightforward function. It can synchronize a local directory or directory structure with a remote location. So what we are going to do is, find a CentOS directory structure somewhere on the internet and replicate it on our local repository machine. I use ftp.jaist.ac.jp which has a pretty fast link with our University network. You may choose one that suits your location.

Once you've found it, all you need to do is run the rsync command with a few special arguments.

rsync -avSHP --delete --exclude "local*" --exclude "isos" ftp.jaist.ac.jp::pub/Linux/CentOS/5.6 /var/www/html/CentOS/ 

The above command will create a replica of the directory structure found at ftp://ftp.jaist.ac.jp/pub/Linux/CentOS/5.6/ inside the web root of the local repository machine. The entire download is around 20GB so it will take a while on the first run. After that is done, all you've got to do is put the above command in a script and make a cron job run it every night.

Once you have the repository ready you need to tell the workstations to look for updates not on internet mirrors but in the local repository. On each of the workstations,

1. Navigate to /etc/yum.repos.d

 cd /etc/yum.repos.d

2. Backup CentOS.Base.repo file

cp CentOS.Base.repo CentOS.Base.repo.bak

3. Open the original CentOS.Base.repo with an editor like VIM

vim CentOS.Base.repo

4. For all of the sections base, updates, addons etc, comment out the line which begins with "mirrorlist". We don't want the workstation looking for mirrors. Uncomment the lines which begin with "baseurl" and change it to look like this. Replace the ip address with the ip address of your repository.

[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://10.16.91.1/CentOS/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#released updates 
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://10.16.91.1/CentOS/$releasever/updates/$basearch/

gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever - Addons
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons
baseurl=http://10.16.91.1/CentOS/$releasever/addons/$basearch/

gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://10.16.91.1/CentOS/$releasever/extras/$basearch/

gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
baseurl=http://10.16.91.1/CentOS/$releasever/centosplus/$basearch/

gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
baseurl=http://10.16.91.1/CentOS/$releasever/contrib/$basearch/

gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5


5. Run a yum update. The  update should now come from the local repository.

Linux Commands - Before you get started

0 comments
Before we get into the actual Linux commands, let me introduce you to how the whole thing works. Because there is an effectively infinite number of commands, you can never remember all of them. It would be futile to even try as even the most experienced Linux system administrators do not neccessarily remember everything.  However there IS a certain structure - a pattern - that all commands have in common. A good understanding of these patterns will help you remember commands and even predict guess commands that you don't actually know.

Commands are files

Of course in Linux, everything is a file! When we enter a command on the CLI (or invoke it using the GUI for that matter) we are effectively calling on a certain script, which is stored inside a file to do its work.

For example the command to view the network configuration is "ifconfig":

ifconfig

If you navigate to the /sbin directory and list the available files, ( ls -l ) you will see one called "ifconfig". So when you enter "ifconfig" and press enter, you are actually summoning the file that's inside /sbin. If you look at the other files inside /sbin, you will probably notice more files with familiar names.

That solves another mystery. That is how the terminal knows how to auto-complete your commands when you press TAB. It simply looks for files that match the string you have typed, inside the /sbin directory, /bin directory and any other location specified in the PATH environment variable. 
The command:

/sbin/ifconfig

would therefore have the exact same effect as using just "ifconfig".

So, what would a "command not found" error message mean? In all likelihood, you've made a typo, but if your sure you've typed it correctly, "command not found" probably means that there is no such file to execute. Maybe you need to install a package to get that file or maybe the file is not inside one of the locations in the PATH environment variable.

In case you need to find out the location of a particular command you can use the following commmand:

whereis <command/file>

Doesn't get any more straightforward than that!

Parameters

Okay. Now for all those bits and pieces trailing the commands. Parameters or arguments you may call them, allow you to tell the kernel exactly how you want a command to work. A command is ALWAYS a single word (no spaces). An argument ALWAYS comes after a SPACE. For example:

tar -xvf myarchive.tar

is the correct command used to untar the archive "myarchive.tar". It invokes the command "tar" and passes the arguments "xvf" to it.

If you type it this way:

tar-xvf myarchive.tar (no space between tar and -x)
the terminal will look for a command called "tar-xvf" instead of "tar" and will of course give you a "command not found" error. "myarchive.tar" serves as simply another argument.

Wednesday, June 1, 2011

Linux distros demystified

0 comments
Being open-source, Linux comes in hundreds of variations by different vendors. There are however several base distributions that all of the variations are derived from. Some of the more ones popular are, RHEL(Red Hat Enterprise Linux), Fedora, Debian, Gentoo and Mandriva. The distros that we are used to - the likes of Ubuntu, CentOS, and openSUSE are based on one of the base distros such as RHEL. For example, CentOS is a (free) derivative of RHEL. Ubuntu is a Debian based distribution.


The point of having so many distros to choose from is that each one is specialized in some way or other. Ubuntu and openSUSE for example cater towards personal use while the likes of CentOS (Community ENTerprise OS) are geared more towards use in an enterprise environment. For example, the Ubuntu desktop edition features a rich set of graphical tools to make life easier for a layman, while CentOS which has minimal 'frills' includes apache2 web server and other useful applications built into its core installation.