Thursday, 27 June 2013

Centos 6/RHEL add a user in a Fluxbox based Desktop

A useful side effect of using just the minimum Xserver and Fluxbox setup is not just the ease with which it drops to a server (Ctrl+Alt+F4), but also the uncomplicated way in which you can add new users. There is no need for scripts or GUI programs to add and remove users, just a couple of commands which you can run in Rxvt, it is not necessary to change the run level although you can if needed.

Once the user is added, a new Desktop environment is created
which can be customised to suit. 

Add a user in two commands as below.

$ sudo useradd -d /home/anton -s /bin/bash -g users anton

$ sudo passwd anton

and set the passwd.

-d being the directory path, -s the shell and -g the group

See below image of this done in Rxvt with user name 'speccy'

A new Desktop environment is created for the user which can be styled to suit your preference.

And as you can see there are all the basic tools you need for a Desktop Linux environment, file manager, terminal emulator, web browser etc. Check out Centos minimal installation and Fluxbox setup for more info.

If you use Ctrl+Alt+F4 or 'sudo telinit 3' to drop out of the Graphical/Desktop environment, your user will still be logged in (and the Xserver stil running), you can log out the user with

# pkill -KILL -u anton

Replace anton with your user name, you can use the who command as below to see which users are logged in.

You can add multiple users as described above and adjust all the Fluxbox/Desktop styles as required.


You will also have to set permissions for a manually created user
so for the user anton created above. For non encrypted.

# chown -R anton /home/anton

# chmod -R 755 /home/anton

Or whatever permission level you decide on. 

See add a user in a Desktop


Wednesday, 26 June 2013

Centos 6/RHEL install Kmod Nvidia Drivers

Setting up your Nvidia Graphics Card is a little easier thanks to the Kmod driver packages available from the Elrepo repo. These are the Nvidia drivers repackaged using weak-updates so that they can be used by any Centos 6 kernel. It is a simple process to use these as they can be installed using yum from the repo, and require very little in the way of configuration.

To install, first obtain the Elrepo package, install it and set it up as you prefer. Then install the package with

$ sudo yum -y --enablerepo=elrepo install kmod-nvidia

Reboot the system to start using the nvidia drivers.

Once the package is installed, unlike with the Genuine Nvidia Driver there are no other steps such as blacklisting the nouveau drivers, you simply have to run

$ su c 'nvidia-settings'  

To fine tune your configuration.

A straighforward way to install drivers for Nvidia.

More repos

Centos 6/RHEL install Node.js and Npm

Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.

Installing Node.js is straightforward now as the source is available from Github and it is in the Epel repo for Centos 6. 
Both methods are shown here, however the recommended installation method is via the Epel repo.

Install from Github

Install dependencies and git (Ensure to set up kernel files)

$ sudo yum -y install binutils gcc make patch libgomp glibc-headers glibc-devel kernel-headers kernel-devel dkms git

$ git clone git://

When all is downloaded move in to the node directory

$ cd node


$ make

$ sudo make install

Now you can run node to check the version

$ node -v                       node version 

$ npm -v         node package manager version      

Install npm from Epel repo 

The recommended way to install Node.js is via the Epel repo 
as it comes ready with many essential packages.

Once you have done that you can just enable and install

$ sudo yum -y --enablerepo=epel install npm

Let's test it out by running a small script in node.

Open up a text editor and copy the following into it before saving the file as 'example.js' It builds a http server.

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello this is a test file for the Node generated server on port 1337\n');
}).listen(1337, '');
console.log('Server running at');

That done, now open a terminal and issue the following command

$ node example.js

This runs the test script, you should get the output below

Indicating that the server is running at

Now in your browser go to that address, not forgetting the port number (1337)

I trimmed the jpeg to remove unwanted whitespace, but the image above is something like what you should be seeing, depending on  which browser you are using.

Try another test, the ubiquitous hello.js, open up your editor and type into it or copy & paste the lines below.

  console.log("excessively drawn out");
}, 1000) 
  console.log("dramatically elongated");
}, 2000) 
  console.log("ridiculously stretched");
}, 3000)   
  console.log("exuberantly prolix");
}, 4000) 
  console.log("profoundly protractile");
}, 5000)    
  console.log("abundantly irrelevant");
}, 6000)
  console.log("resolutely persistent");
}, 7000) 
  console.log("ambivalently & ambiguously esoteric");
}, 8000)
  console.log("but disparately unique");
}, 9000)                     
  console.log("World !");
}, 10000)
  console.log("Hello, annoyingly long");

Save it as hello.js and run it with

$ node hello.js               (wait around 10 seconds)

So now you can build things using Node.js on Centos 6 or RHEL.

More repos.

Tuesday, 25 June 2013

Centos 6/RHEL writing image file to USB drive

You can write a Centos 6 install image file on to a USB stick in order to boot from it. This is often useful for installing on a device which has no DVD drive but can be set to boot from a USB stick, such as netbooks etc.

Write image file to USB

To do this first download the required image from one of the mirrors The netinstall.iso is the one used on this blog for building up the system. Keep it in the home directory when done.

Now insert your USB drive and find out the device path it has been assigned, such as /dev/sdc, you can use mount or fdisk for this depending whether your system mounts it automatically.

$ sudo fdisk -l

 Disk /dev/sdc: 4022 MB, 4022337024 bytes
124 heads, 62 sectors/track, 1021 cylinders
Units = cylinders of 7688 * 512 = 3936256 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x6f20736b

You can also use

$ mount

To see if the device is mounted, if it has been, then use umount to unmount it. For example

$ sudo umount /dev/sdc

Now you have found the device name you can write the downloaded image file to it using the dd command. As root issue

# dd if=/home/anton/CentOS-6.4-i386-netinstall.iso of=/dev/sdc

Replacing the user and file/path names with yours, this will write the image you have in your home directory to the USB drive.

So you can now use this to boot from and install Centos 6 on a device which doesn't have a DVD drive but can be configured to boot from a USB stick.

Read image from a DVD drive

If you have the installation media on a DVD disc and wish to turn it into an image file to use as above or in another fashion then just place it in the drive and find the device name with ls

$ ls -l /sys/block/*/device

lrwxrwxrwx. 1 root root 0 Jun 29 18:16 /sys/block/sda/device -> ../../../1:0:1:0
lrwxrwxrwx. 1 root root 0 Jun 29 18:16 /sys/block/sdb/device -> ../../../4:0:1:0
lrwxrwxrwx. 1 root root 0 Jun 29 18:16 /sys/block/sr0/device -> ../../../4:0:0:0

The third entry down is not a hard drive or partition and is likely to be a cd drive, confirm it with

$ ls -l /dev/sr0

brw-rw----+ 1 root cdrom 11, 0 Jun 29 18:16 /dev/sr0

and you can use the dd command with the device path

# dd if=/dev/sr0 of=/path/and/filename.iso

to make an .iso image copy of the DVD disc, where /dev/sr0 is the disc to copy and path and filename is the location to copy to.

Mount an image file 

You may also want to mount the image you just created or any other image, do this with the mount -o loop. after creating a directory in which to mount it, for example

# mkdir /mnt/myimage

# mount -o loop nameofimage.iso /mnt/myimage

(Assumes you are in the same directory as the iso)

Having done this and running the mount command to check, shows my Centos image mounted in my /mnt/myimage directory.

$ mount
/dev/mapper/vg_centos-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda2 on /boot type ext4 (rw)
/dev/mapper/vg_centos-lv_home on /home type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/sdb1 on /media/storage type vfat (rw)
/dev/sdc on /tmp/usb type vfat (rw)
/home/anton/CentOS-6.4-i386-netinstall.iso on /mnt/myimage type iso9660 (rw,loop=/dev/loop0)

Wednesday, 19 June 2013

Centos 6/RHEL install Apache Maven

Maven is a software project management and comprehension tool which can enable you to manage a project's build, reporting and documentation from a central piece of information.
Installing Apache Maven on Centos 6/RHEL is relatively simple as long as you have the JDK set up correctly. 

This means paying particular attention to your JAVA_HOME path/variable as Maven appends to it and uses the jre, an incorrect setting will result in Maven being unable to start properly.

JAVA_HOME should just be the top level JDK directory with or without a trailing slash ie


So install the JDK and set the JAVA_HOME path if not already

That done, now download Maven from Apache Maven site to your home directory.

Use wget if you have it installed

$ sudo yum -y install wget

$  wget

Or you can download directly from the the site link above

There are just 3 steps to install it as follows:

1. Unzip to /usr/local

2. Symlink to create the maven directory

3. Add the paths to /home/<user>/.bashrc

Now to install it.

$ cd /usr/local

Extract the files from the downloaded tar.gz

$ sudo tar xvf /home/<user>/apache-maven-3.0.5-bin.tar.gz 

Symlink to the extracted folder and create the maven folder

$ sudo ln -s apache-maven-3.0.5/ maven

So now you have it installed at /usr/local, you need to set up paths in .bashrc

(Use your user name)

$ sudo vi /home/anton/.bashrc

Enter under your other settings

export M2_HOME=/usr/local/maven

export PATH=$M2_HOME/bin:${PATH}

Save the file and source it

$ source /home/anton/.bashrc

If you have installed Ant already also then your .bashrc might resemble as below

export JAVA_HOME="/usr/java/jdk1.7.0_06"


export CLASSPATH=.:/usr/java/jdk1.7.0_06/lib/tools.jar



export M2_HOME=/usr/local/maven

export PATH=$M2_HOME/bin:${PATH}

With the CLASSPATH added for good measure.

Now is probably a good time to test all those entries just in case, so

$ echo $JAVA_HOME




$ echo $ANT_HOME


and finally check your new Maven installation

$ mvn -version

Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 13:51:28+0000)

Maven home: /usr/local/maven

Java version: 1.7.0_06, vendor: Oracle Corporation

Java home: /usr/java/jdk1.7.0_06/jre

Default locale: en_US, platform encoding: UTF-8

OS name: “linux”, version: “2.6.32-358.6.2.el6.i686“, arch: “i386“, family: “unix”

Test Maven

To get started or test it out first create a project folder
and move into it.

$ mkdir mavapp && cd mavapp

Start maven and issue the archetype:generate command

$ mvn archetype:generate

Maven will download some required packages and then you will be asked to choose a quickstart version number

Choose org.apache.maven.archetypes:maven-archetype-quickstart version:
1: 1.0-alpha-1
2: 1.0-alpha-2
3: 1.0-alpha-3
4: 1.0-alpha-4
5: 1.0
6: 1.1

Enter 6 and continue, more packages will be downloaded and you will be asked to define values, my examples below, the package value will default to whichever the groupid is.

Define value for property 'groupId': : com.dom.romcom
Define value for property 'artifactId': : MavenTestApp
Define value for property 'version':  1.0-SNAPSHOT: :
Define value for property 'package':  com.dom.romcom: :

After a confirmation 'Y' the project will be set up

[INFO] Parameter: groupId, Value: com.dom.romcom
[INFO] Parameter: packageName, Value: com.dom.romcom
[INFO] Parameter: package, Value: com.dom.romcom
[INFO] Parameter: artifactId, Value: MavenTestApp
[INFO] Parameter: basedir, Value: /home/anton/mavapp
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: /home/anton/mavapp/MavenTestApp
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4:51.066s
[INFO] Finished at: Sun Jun 16 17:42:59 BST 2013
[INFO] Final Memory: 14M/178M

Maven also generates predefined archetypes which you can choose
for example 768 gives you a choice of Spring versions to pick in a similar fashion. Below shows the directory structure for both when done.

Inside the src folders are the main and test folders for the projects class files and junit test cases.

The above are just examples,
for more info on using Maven check out the Apache Maven site.

Thursday, 13 June 2013

Centos 6/RHEL install MongoDB

MongoDB (from “humongous”) is a high-performance, open source, schema-free document-oriented database. It is used in a variety of applications at institutions across the globe. It has a huge following of contributors, with eminent software engineers from around the world attached to the project in a list which reads like a who’s who of the software world.

It has the MongoDB manual which is equally large at 1234 pages long and will take the majority of people the best part of a lifetime to negotiate. There are sections on the MongoDb site relating to the variety of implementations for Mongo, which are numerous. 

A recent addition is the Little MongoDB book by Karl Seguin, who produced a similar book for the Redis Database. Online courses are now available from 10gen in collaboration with Edx (Mit/Harvard. Probably the best resources to get started with Mongo are the MongoDB Tutorial or the MongoDB quick reference booklet.

MongoDB is written in C++ and offers the following features:

   * Collection oriented storage: easy storage of object/JSON-style data
   * Dynamic queries
   * Full index support, including on inner objects and embedded arrays
   * Query profiling
   * Replication and fail-over support
   * Efficient storage of binary data including large objects (e.g. photos
   and videos)
   * Auto-sharding for cloud-level scalability (currently in early alpha)
   * Commercial Support Available

A key goal of MongoDB is to bridge the gap between key/value stores (which are fast and highly scalable) and traditional RDBMS systems (which are deep in functionality).

Mongo uses a different structure to relational databases, with collections instead of tables, documents instead of rows and fields instead of columns. Additionally it uses lightweight, easily traversable and efficient binary serialized JSON(BSON

Queries and other operations in MongoDB are represented as documents passed to find() and other methods. 

10gen provide the binaries for Centos 6/RHEL

$ sudo vi /etc/yum.repos.d/10gen.repo         enter into it

For 64bit

name=10gen Repository

For 32bit

name=10gen Repository

Install the server

$ sudo yum -y --enablerepo=10gen install mongo-10gen mongo-10gen-server

$ sudo service mongod start            to start the server

$ mongo                                starts an instance

You do not need to seperately 'create' a database with mongo as the first insert command will do this, so let's put in some data

>  db.firstdb.insert({name: 'Gertrude'})

and find it with find()

>  db.firstdb.find()
{ "_id" : ObjectId("51b647bba7e270046e1d364a"), "name" : "Gertrude" }

To drop the database first use it

>  use firstdb
switched to db firstdb

>  db.dropDatabase();
{ "dropped" : "firstdb", "ok" : 1 }

Make sure its gone

> db.firstdb.find()


You should shut down the server properly, or it will lock down. In the mongo shell switch to the admin database and issue the shutdownServer() command.

> use admin 

> db.shutdownServer()
Thu Jun 13 08:06:29.049 DBClientCursor::init call() failed
server should be down...
Thu Jun 13 08:06:29.050 trying reconnect to
Thu Jun 13 08:06:29.051 reconnect failed couldn't connect to server

and then exit the instance

>  exit

Now if you start the server again it will function correctly, if you have not shut it down as above, at least on Centos 6/RHEL then you may get an error on restarting and have to go through
the fixing procedure. But on restart now its fine

$ sudo service mongod start
Starting mongod: Thu Jun 13 11:05:29.231
Thu Jun 13 11:05:29.231 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Thu Jun 13 11:05:29.231
about to fork child process, waiting until server is ready for connections.
forked process: 2561
all output going to: /var/log/mongo/mongod.log
child process started successfully, parent exiting

You can also shut it down from the bash shell with the following

$  sudo mongod --dbpath /var/lib/mongo --shutdown
Thu Jun 13 08:32:53.867
Thu Jun 13 08:32:53.867 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Thu Jun 13 08:32:53.867
killing process with pid: 3670

[anton@Centos ~]

(Change the --dbpath flag to yours if its different)

MongoDB is huge entity and a little different but it is worth the effort once you get comfortable with it. See more commands at

and there are, as mentioned above, a lot of other resources.

MongoDB, a popular database which works well on Centos 6/RHEL. 

More repos

Sunday, 2 June 2013

Centos 6/RHEL change eth1 back to eth0 or rename device

Occasionally because of a hardware change (you may have used a different ethernet device & then removed it) your original eth0 gets it's name changed to eth1, or if using a number of devices the names get changed around out of the order in which you prefer to see them. This can be annoying and you may want to change the names back. You can do this by altering two files in your system.

First go into /etc/udev/rules.d/ 

Vi and Vim commands

$ sudo vi /etc/udev/rules.d/70-persistent-net.rules 

First establish if there are any unused devices still present and delete the entry, remembering to rename or remove the corresponding ifcfg file in /etc/sysconfig/network-scripts.

For example, above I want to delete the old eth0 entry and then find the eth1 device I am still using but wish to rename and change the NAME parameter from eth1 back to eth0.

So make your adjustments or removals in 70-persistent-net.rules and then go to /etc/sysconfig/network-scripts where you will alter and rename the ifcfg-eth1 file.

$ sudo vi /etc/sysconfig/network-scripts/ifcfg-eth1

eth1 renamed to eth0
Change the parameters to suit, DEVICE="eth0" etc, not forgetting the HWADDR, which is the Mac address from the ifconfig or dmesg command. Then you can rename it as in the examples above where you can see the that the Hwaddr for eth0 in the lower image is the same as the Hwaddr for the renamed eth1 from the top image.

$ sudo mv /etc/sysconfig/network-scripts/ifcfg-eth1 /etc/sysconfig/network-scripts/ifcfg-eth0

Or write a new file completely with contents similar to below


Which are typical parameters for someone using a static IP address on a wired ethernet card. Finally, issue the command

$ sudo service network restart

Or reboot your system to enable the new named device.