While planning to sail the open seas and visiting other countries, I have decided to take a personal firearm. Owning and carrying a personal firearm is legal in my home state. What would be the proper procedures upon entering ports around the world. Could I expect my firearm to be confiscated permanently? Temporarily? Would having a lockable firearm safe aboard be acceptable?
As owner of a yacht there is no problem. I have been in contact with Bobby Schenk, a well-known German open-sea sailor who writes about problems on board, in your case firearms.
As owner of your boat the relevant law for possessing and storing weapons is your country of origin, in your case USA, more specifically your state law. I suppose you have all relevant documents like firearms certicate etc. etc. They will be needed.
After traveling into a port you will get a formular with an entry "Firearms". There you declare all your firearms (and ammunition, whatever). The next step depends on the given country.
If you hide a gun on board and it will be found, you are in deep trouble. This can and will be judged (rightfully !) as gun running, your boat will be very likely confiscated and you face severe penalties. There is simply no reason to do it.
I think I do not need to explain that you are bound by the laws of the country in which your port is => No weapons outside the boat.
For firearms itself: Against a speedboat with a dozen heavily armed pirates resistance is futile, but against one or several poor (meaning: no money) stragglers who are lightly armed firearms may be a necessity. Hand guns are not recommended: In panic and fear you will not be able to get exact shots, even on the torso. Then again, even if you hit them with deadly force, they could be fully able to retaliate or reach you for a few seconds or even a minute (!) on a very constricted space. The standard option is a pump-action shotgun with buckshots, but the buckshots must have plastic cartridges because paper cartridges swell on board and cause jamming.
EDIT: I see that I must dispel myths.
The first one is stop believing Hollywood Bullshit where one MAN fights an entire army and wins. This is complete and utter crap. We have known pirate areas in Colombia, Lagos, Somalia and Indonesia and these are the pirates I mean with "speedboat attack". These types enter well-armed container ships driving under full speed and gaining millions by blackmailing and dealing stolen goods. The win will be invested for better equipment. They are equipped with fully automatic AK-47/AK-74 assault rifles, RPG-7 rocket propelled grenade launchers and some have even the M2 machine gun. While these types of pirates are targeting container ships they do not mind entering yachts. Yachties either evade these areas or are sailing after warships. If you still do not believe, ask someone from the Navy what he/she thinks about your beliefs.
The other myth is that there should be no weapons on board. There is no police at international waters which you can ask for help, you are completely on your own. And then are those guys which are poor and without gun, but have a knife or machete and intend to rob or kill you. You do not need to use a gun, simply showing it from the distance means that the game is over, they will be dead if they continue. The time you actually use your gun will be e.g. to kill a shark which locked his jaws into your rudder or to give acoustic signals (Your fellows are swimming, out of earshot and not looking in your direction).
If you have for whatever reason no gun and need to throw back an attack, Molotov cocktails are the best improvised weapon you have.
Don't do it. As long as you stay within American waters, you are ok (I suggest keeping a copy of your gun permit with you). While you are in international waters, you are probably still ok. However as soon as you cross a border into any other country, you are bound by laws of that country. If by the laws of those countries you are not allowed to own/carry/conceal a firearm, then no matter how you store it you will be breaking the law. The repercussions may be extremely severe - for example, in Japan up to 10 years in prison plus 1 million yen fine (about $10,000).
To answer your question about customs searches, there is no rule. In some cases you may not be search at all, in other cases they will turn the entire boat inside out - and sometimes in the same country. If you have something illegal (and a gun will likely be illegal in those countries), the chances are that it will be found and you will suffer the consequences. Therefore I strongly recommend to leave your gun at home if you are planning to travel internationally.