One defensive unit (except in a frontline city that is under pressure from the ai) is more than enough and later in monarchy, add warriors to help with the riot control. This has the advantage that those warriors will "promote" to riflemen when you get Leo's. You will than have lots of 40 shield riflemen that you only paid 10 shields for.
There is an important downside to doing this. If you play republic, each of those units takes one shield of support each turn, which quickly eats up the 30 shield advantage of promoting warriors to riflemen. If you need garrisons in your cities, then it doesn't matter, but building lots of extra warriors to give yourself a large army will cost you big in production time or gold for rush buying. A more effective strategy is to delay chivalry for as long as possible, and, shortly before discovering it, build many, many horsemen. You should then very quickly discover leadership and tactics and have a nice large army of cavalry with which to pound your enemies.
In the early game, the best defence is, in my opinion, having a tech or two that a potential enemy does not and having enough cities to be able to afford to lose one or two by surprise. Giving a couple of techs to a potential enemy can quickly turn that enemy into a friend or even ally at this stage in the game. At this point, occupying as much land as possible is important.
As the game progresses, garrison important cities with what you have available, especially costal cities with wonders and cities bordering another civ, but one unit per city is usually enough. Keep enough gold (or caravans near good cities) to buy units or diplomats in emergencies. Around this time, stop giving techs or gold to foreign civs who make threats, because they should either be too far away to be a danger, or you should have preparations made to keep them at bay. You want, generally, to build ships and caravans at this stage, not military units.
In the later game, you can afford to start building a military and start punishing those who want to go to war with you. The enemy should very seldom be attacking your cities, because you will be attacking them.