First off, the Dwarves were involved in the war – Sauron had Erebor under attack at the same time as Gondor, though the books themselves mention it only indirectly:
'Now why did not we wish for some of our kinsfolk?' [said Gimli.]
Legolas stood before the gate and turned his bright eyes away north and east, and his fair face was troubled. 'I do not think that any would come,' he answered. 'They have no need to ride to war; war already marches on their own lands.'
More precisely, from Appendix B
... and Brand was driven back into Dale. There he had the aid of the Dwarves of Erebor, and there was a great battle at the mountain's feet. It lasted three days, but in the end both King Brand and King Dáin Ironfoot were slain, and the Easterlings had the victory. But they could not take the gate, and many, both Dwarves and Men, took refuge in Erebor, and there withstood a siege.
That's pretty involved, I should say.
However, the Dwarves that passed through the Shire didn't necessarily have a lot to do with that. As Nerrolken commented, they were mostly just traders and merchants travelling, well, on their own account. Much like my favourite character:
A fox passing by on business of his own stopped several minutes and sniffed.
'Hobbits!' he thought. 'Well, what next? I have heard of strange doings in this land, but I have seldom heard of a Hobbit sleeping out doors under a tree. Three of them! There's something mighty queer about this.'
...no, the Shire is blissfully well-protected... Rangers, you know...
Anyway. The exact passage about hints to evil goings in the wide world is this:
The ancient East-West Road ran through the Shire to its end at the Grey Havens, and dwarves had always used it on their way to their mines in the Blue Mountains. They were the hobbits' chief source of news from distant parts – if they wanted any; as a rule the dwarves said little and the hobbits asked no more. But now Frodo often met strange dwarves of far countries, seeking refuge in the West. They were troubled, and some spoke in whispers of the Enemy and the Land of Mordor.
So, yes, some of those dwarves were in fact passing through the Shire in hope to avoid the war, but dwarves weren't really an unusual sight.