I've spent more than a few sleepless nights fixating on every little noise when I may as well have been unconscious.
Short of resorting to a hotel room while in bear country, following the advice on cooking and keeping a clean camp is a good start.
A friend of mine refers to the Glock 10mm I carry as a "sleep aid".
In practice, if a bear rips into my tent in the middle of the night my chances of getting off an effective shot are probably slim.
As for bear spray, yes, the experts say it's a better deterrent, but not very feasable to use while inside the tent while a bear is swatting at you from outside.
The key to peaceful sleep for me, I think, is to convince myself that I've done everything I can to minimize a bear's interest:
Follow guidelines for food and 'smelly' stuff.
Take the glock and bear spray 'sleep aids' to bed with me.
The 'sleep aids' may not help, but they do provide some peace of mind, real or imagined.
The glock is kept inside the sleeping bag along with a flashlight within emergency reach.
After that I put the earplugs in to keep me from fixating on every little noise and hope for the best.
If it's my day, well, it's my day.
In general, I think I'm probably safer sleeping in bear country than walking through certain urban areas.
A post dinner beverage or two and/or a little self medication doesn't hurt either
Having said that, I did recently spend one sleepless night at a CG in Oregon worrying about bears
As it turned out I had nothing to be concerned about.
A lot of good suggestions in this thread - take them to heart.
One note of caution - if you're going to carry heat make sure you understand the rules for each and every state you will be travelling through; and follow them. For example, are there restrictions on mag size? Weapons charges are a big deal and completely avoidable if you know the regs. I'm good in WA for concealed, but my cpl does not transfer over to many states. I can't carry in Cali like I can in WA.