A soldier on duty near the Louvre museum in Paris opened fire on a man who attempted to attack him with a machete, officials said.