I think Scoottr hit the nail on the head. From your description, you're doing too much building/research and not paying enough attention to military.
I'm going to completely agree with this.
In your next game, one potential way to compensate for this (which EweezE was hinting at) is to try to do an early rush of a neighbour.
I'm going to COMPLETELY disagree with this -- unless the situation calls for it, which means:
1) Your nearest neighbor is so close that you will be unable to expand peacefully to a large enough size without being cut off, which also means that their cities border yours as early in the game as one contemplates an axe rush (so that it can be feasible to keep and develop at least some of them); and
2) You have copper readily available (BW should be one of your first research targets so that will be obvious quickly), OR you are playing the Egyptians or Persians and you have horses readily available, OR you are playing Huayna Capac and your near neighbor is not Mansa Musa.
If your nearest neighbor is halfway across the continent, an axe rush is a waste of resources and time that could better be spent producing settlers and expanding peacefully. If you have no copper or horses and you aren't playing the Inca, an early rush isn't feasible.
There are times when it is called for, and Sisiutl's how-to guide in the War Academy has some good tips on ways to go about it, but in my sincere opinion, in MOST games it's not a good idea.
To further the idea of the "unit pump" city that Scoottr mentioned, try to earn a Level 4 unit either in an early rush or by fighting barbarians, or a combination of both. Then research Literature and build the Heroic Epic in that production city. This will give it 100% production when building military units, which it should focus on, only building other things to keep it happy and healthy as needed.
Another good idea and I second this and always do it. Later on, settling Great Generals there and building West Point in that same city also are good notions, but of course that's not something for the early game.
In general, people who have played previous Civ games sometimes run into problems with Civ4. Even if you know the differences, the implications of those differences can be very confusing. Getting used to the idea of a single combat strength instead of split attack/defense, which means some of the units that used to be strictly for defense (e.g. Riflemen) are now good for attack, to the way siege units work and what that means for city defense and attacking cities, to how promotions operate, to the use and leverage of Cottages and specialists, to the limitations on expansion built into the economy and how to stretch those limits, to the increased diplomacy options, to the way religions work, to the changed happiness features, all took time for me. There's a lot of unlearning that needs to be done.
Also, although this doesn't seem to be your problem, one can run into equal and parallel difficulties if one warmongers too much and builds too little, mainly because of the hit to your economy from war weariness (more so than the fact that you won't build wonders and stuff that way). There's a rhythm to these things. But for sure, you need to pay enough attention to the military that the other civs don't see you as easy prey. One thing I always do is to build 10-12 Swordsmen and about 5 each cats and Chariots or Horse Archers in the Classical Age, even if I don't plan to go to war and use them. That way, number one I look scary and the AI is less inclined to mess with me, and number two if I do decide to do some early warmongering (or if that nut job Montezuma is a neighbor, which almost always means I have to), I'm prepared for it. Plus those Swordsmen upgrade nicely to Macemen later on.