How to set up a basic military in Dwarf Fortress?
Solution 1:
This is something I always have difficulty with. This answer is a combination of past experience, the military chapter of Getting Started with Dwarf Fortress and the Military information on the wiki.
The first thing you'll want to do is carefully pick the dwarves to form your budding militia. You'll see it suggested in several places to avoid picking females, or dwarves with family as that can lead to problems when and if they eventually die in a horrible manner. I disagree, as that can take away some of the most poignant stories the game can produce. Regardless, you'll want to give them the profession Soldier, so it's easy re-draft them if you ever need them for something else.
Now create a squad w/ your selected dwarves (or use the squad screen to do this...) Once you've got a half dozen dwarves or so in your squad you'll want to equip them. There are several default uniforms to pick from. I like marksdwarves, but that does add the complication of ammunition. Eventually you'll want to have both melee and ranged squads, and very possibly a mix for surprise situations.
Early on you'll probably need to armor your dwarves in leather, but you definitely want to switch to metal armor at the first opportunity. If you create a custom uniform don't forget you'll need to set it on your dwarves. Especially if it's post squad creation once you've completed those half-dozen sets of beautiful steel armor.
Next you'll need to set up a barracks for your milita to train in. If your barracks is near your fortress entrance (often a good idea) and far from your regular sleeping quarters you may want to force your militia to sleep in the barracks... of course this could mean less happy thoughts, depending on how fancy the dwarves home is (assuming it even has one assigned!)
Archery targets, and properly equipping your marksdwarves is a complicated set of affairs, and I've gotten it wrong often enough. Check your equipment and be sure your dwarves have the type and amount of bolts that they'll need. I like to make bone bolts and use those for practice and reserve the metal ones for real combat.
Danger rooms, considered an exploit by some people can help train the defensive skills of the dwarves.
Possibly the most important thing is going to be setting up proper training for your dwarves. Once you get a couple of squads going you can rotate them between active/off duty so they all get trained equally, but you also always have some ready dwarves to fight.
Solution 2:
@aslum's answer goes into detail about some in-game mechanics, but there's a strong option if you're embarking on a new fort - namely, to bring along 2 dwarves with 5 Weapon / 5 Teacher skill levels and set them to train. This allows you to get a few expert dwarves very quickly and is an effective way to kickstart your military from year 1
See this !!SCIENCE!! thread on the forum: Drunken masters - how to use the Teacher skill