rolling with a different distro: centos 7

Because they’re so cheap I bought another 1TB Western Digital Blue drive from a local big box electronics store, swapped it into my R580 notebook, and installed a few other Linux distributions on the blank drive, eventually stopping at CentOS (Community ENTerprise Operating System) 7. CentOS 7 is Redhat Enterprise Linux (RHEL) 7 with all the Redhat branding and logos stripped out as well as the RHEL licensing structure. What’s left is an enterprise class version of Linux without any of the paid for RHEL hand holding.

There are a number of key differences between CentOS 7 and Ubuntu 14.04. One that’s important to me is support for RPM (Redhat Package Management) install files as opposed to Ubuntu’s DEB (DEBian) files, and all the tools built around those formats. Truth be told I prefer rpm and yum to deb and apt-get, although when you compare them dispassionately there’s really very little difference between them. Those folks that claim there is are the “fan boys (and girls)” of their distribution. I’ll be honest enough to say that long years of experience make me more comfortable using rpm, but that doesn’t make it overwhelmingly better.

One language I use and develop with is Java, choosing to use the official Oracle releases, which are pushed out either as ZIP, TGZ, or RPM files. No DEB files. It’s far easier to install via RPM on RPM supporting operating systems, such as RHEL/CentOS, Fedora, and openSUSE. If I want to use Oracle Java on Ubuntu then I have to go through some additional gyrations unpacking the TGZ file, as I’ve documented in previous Ubuntu posts.

In order to use Oracle Java I have to completely uninstall the Open Java/Iced Tea variants that just about every distribution wants to install. I dislike all those variants because they’re incomplete, don’t operate as correctly as the official Oracle release, and are always a few releases behind. And every time I uninstall Open Java I’m also forced to uninstall Libre Office due to insane dependencies of Libre Office on Open Java built-in to the distro.

CentOS 7 was no different, but it was straight forward and fast, unlike openSUSE 13.1. After removing Open Java and Libre Office, I installed Oracle Java 8 update 20, then downloaded the latest Libre Office (version 4.3.2.2). Sometimes you need to bypass the repos due to version rot not only for the latest Java, but the latest Libre Office as well. The CentOS versions of Libre Office are at 4.1.4.2 as of the date of this post. The primary driver is that Microsoft Office compatibility in Libre Office 4.3 is much better than in version 4.1.

I just mentioned openSUSE 13.1. That’s because I tried out OpenSUSE 13.1 KDE before settling on CentOS 7. While openSUSE installed fairly well, it had enough oddball quirks to it that I eventually installed CentOS 7 over it. Biggest problem with openSUSE is KDE itself; it’s changed to the point where I don’t like it at all any more. That’s a shock from my early days of 2007, when I fell in love with KDE 3. OpenSUSE is now completely off my radar.

One thing I will say about the latest Linux distributions, and that’s how they all effortlessly handle hardware. With all distributions both screen and network were easily detected and used. The wireless chip set on the R580 was the most surprising success; in all cases the chip set was detected and enabled. All I had to do was pick my home network and give it the password. After that it just ran.

Another big surprise is how all the distributions have current browsers, and how the current browsers handle multimedia. You’re looking at Firefox 31.1 above running a YouTube cat video using HTML 5 (no flash here!), complete with audio. When something as conservatively hidebound as CentOS 7 can run YouTube cat videos without flash, without turning to running arcane post-install command-line tools or installing additional “non-free” software from “non-free” repos, then you know the apocalypse has truly arrived.

Once installed it ran smoothly and without any incidents. I installed Oracle Java as well as the latest Libre Office. I also installed a few tools, such as gcc and g++, and then forked and built the latest node.js off of Github. It all built cleanly, and ran as well as it has on every other OS I’ve dropped it on. I tried some other hackery and it all worked as expected. From a software development perspective, CentOS 7 is like Mary Poppins, practically perfect in every way.

As good as CentOS 7 might be operationally and internally, I do have a number of complaints about CentOS 7. The first is how it looks.

CentOS 7’s desktop, which is their version of Gnome 3, looks like a poorly implemented copy of Mac OS X 10.5 (see above). If I’d wanted that look I’d have bought myself a Mac. Back in 2008 or so. The shadowing looks better on Mac OS X, while CentOS 7’s desktop decorations seem to take up too much space, especially between widgets.

Other annoyances include the desire of the Gnome developers to remove features, such as Nautilus’ ability to show previews (it once did), or the Gnome terminal’s loss of transparency in Gnome 3 (in Gnome 2 it was really very nice), or the inability to select gedit’s color theme (I always go in and select cobalt). Thankfully, they’re features that are still available in the same tools under Ubuntu 14.04. These are the kind of operational issues that tend make people like me cranky.

It’s been interesting playing with CentOS 7 this weekend, and I’ve certainly learned a lot. There’s certainly much to appreciate in CentOS 7. But as much as CentOS 7 has improved over all other versions of CentOS, I think I’ll stick with Ubuntu for the time being. In the mean time the CentOS 7 drive goes into storage until such time as I might have need of it.

building web applications with mongo db: an update

It’s been a while since I did anything with MongoDB, a NoSQL (Not Only SQL) open source database. My MongoDB rad skills[1] had gotten a little rusty as a consequence. So I moseyed on over to the MongoDB download site, grabbed a zipped up Windows x86-64 copy, plopped it down on my machine, and then started to follow the directions to “Building Web Applications with MongoDB: An Introduction.”

It’s a great little presentation, but it has a few little quirks that this posting is meant to smooth over. They are:

  1. His presentation is on Mac OS X. This update is for Windows 8.1 Update 1 64-bit.
  2. This update contains the full source code to the three web application files, with a few minor corrections.
  3. This update contains a MongoDB console correction.

This update is preparation to get everything set up on Windows 8.1 before running the presentation. When you run the presentation it will go a lot smoother for you. And you should run the presentation to get the full benefits of learning about MongoDB. But first the software we’ll need to install:

Software Version
Python 2.7.8
pymongo 2.7.2
bottle 0.12.7
MongoDB 2.6.4

Please note that these are the versions as of the time this post was published. If you come across this post at some point in the future, they may be different (i.e. higher).

First let’s install Python and the infrastructure tools for the MongoDB Python driver and web infrastructure you’ll need to run the presentation.

  1. Pick up the Python software from ActiveState’s ActivePython download page. Make sure to select a version 2.7 Python. Pick the 64-bit MSI installer, run the installer, and take the defaults. It will put all the binaries and tools into C:\Python27.
  2. After the Python installation open a command shell and cd into C:\Python27\Scripts. There you’ll find easy_install.exe and pip.exe. You can use either tool to install pymongo and bottle, but it’s easier to use easy_install. For pymongo type “easy_install pymongo” followed by “easy_install bottle”.

Next download the MongoDB database software from the MongoDB download page. Select the 64-bit zip file. What follows is how I have my sandbox set up for this. You can change it to suit your environment if you want.

  1. Create a local sandbox area. Mine is C:\Java (an historical artifact).
  2. Unzip the MongoDB zip file into C:\Java. My unzipped MongoDB application is located in C:\Java\mongodb-win32-x86_64-2008plus-2.6.4
  3. Create a directory structure for the MongoDB data store. Mine is C:\Java\data\db
  4. In the C:\Java\mongodb-win32-x86_64-2008plus-2.6.4\bin folder create a batch file called runmongo.bat
  5. In that batch file put the single line ‘mongod –dbpath C:/Java/data/db’. Now you can double click it in the file explorer and start up MongoDB pointing to where it should place all its data files.

Finally create a sub work folder to hold the application file. Mine is C:\Java\MongoDB. Place the following three files into that location. I use the MongoDB subfolder just to keep things straight, but you could call it Fred and it would still work. What follows are the three files to copy:

import bottle
import pymongo
import guestbookDAO

#This is the default route, our index page. Here we need to read the documents from MongoDB.
@bottle.route('/')
def guestbook_index():
    mynames_list = guestbook.find_names()
    return bottle.template('index', dict(mynames = mynames_list))

#We will post new entries to this route so we can insert them into MongoDB
@bottle.route('/newguest', method='POST')
def insert_newguest():
    name = bottle.request.forms.get("name")
    email = bottle.request.forms.get("email")
    guestbook.insert_name(name, email)
    bottle.redirect('/')

#This is to set up the connection.

#First, set up a connection string. My server is running on this computer, so localhost is OK.
connection_string = "mongodb://localhost"
#Next, let PyMongo know about the MongoDB connection we want to use. PyMongo will manage the connection pool.
connection = pymongo.MongoClient(connection_string)
#Now we want to set a context to the names database we created using the Mongo interactive shell.
database = connection.names
#Finally let our data access object class we built, which acts as our data layer, know about this.
guestbook = guestbookDAO.GuestbookDAO(database)

bottle.debug(True)
bottle.run(host='localhost', port=8082)

File: index.py

 

import string

class GuestbookDAO(object):

#Initialize our DAO class with the database and set the MongoDB collection we want to use.
    def __init__(self, database):
        self.db = database
        self.mynames = database.mynames

    def find_names(self):
        l = []
        for each_name in self.mynames.find():
            l.append({'name':each_name['name'], 'email':each_name['email']})

        return l

    def insert_name(self, newname, newemail):
        newdoc = {'name':newname, 'email':newemail}
        self.mynames.insert(newdoc)

File: guestbookDAO.py

 

<!DOCTYPE html>
<html>
    <head>
        <title>Welcome to MongoDB!</title>
        <style type="text/css">
            body { font-family: sans-serif; color: #4f494f; }
            form input { border-radius: 7.5px; }
            h5 { display: inline; }
            .label { text-align: right; }
            .guestbook { float: left; padding-top: 10px; }
            .name { width: 100%; float: left; padding: 3px; }
            .wrapper { padding-left: 25px; padding-top: 20px; }
        </style>
    </head>

    <body>
        <div class="wrapper">
            <h1>Welcome To MongoDB</h1>
            <div class="guestbook_input">
                <form method="post" class="form" action="/newguest">
                    Name: <input type="text" name="name"/>
                    Email: <input type="text" name="email"/>
                    <input type="submit" value="Add Guest"/>
                </form>
            </div>
            <div class="guestbook">
                <h3>Guests:</h3>
                %for name in mynames:
                <div class="name">
                <h5>Name:</h5> {{name['name']}},
                <h5>Email:</h5> {{name['email']}}
                </div>
                %end
            </div>
        </div>
    </body>
</html>

File: index.html

 

Copy these three files into C:\Java\MongoDB.

Go to the MongoDB presentation and follow along. When it comes time to start MongoDB double click the startmongo.bat file in the file explorer. When it comes time to start the MongoDB shell, double click mongo.exe. When it comes time to run the web application in C:\Java\MongoDB (comprised of those three files you should have copied there) open a command prompt, cd to C:\Java\MongoDB, and type ‘python index.py’ and hit return. Then follow the rest of the demo.

Note that when the demo talks about deleting records in your web application’s database, you should type ‘db.mynames.remove({})’ instead of ‘db.mynames.remove()’. MongoDB has advanced enough from the version used in the demo to cause some minor annoyance if you follow the speaker’s directions exactly.

[1] I guess I’m an old fart; I refuse to spell the plural of skills with a ‘z’.