I disagree with the last part.
Avoid pleasantries. Don't ask the officer how they are doing today. Don't compliment them. Don't comment on the weather. These are considered proper pleasantries in polite society, but they can make the officer think you're being overly friendly in order to hide something.
When you arrive at the counter, simply say "hello sir/ma'am", hand your documents, carefully listen to and obey instructions (such as fingerprints), answer any questions in a clear, concise manner, and then end the interaction with "thank you sir/ma'am."