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.