You need to know writing, then establish ambassy by double clicking on the logo near your capital city name. ( it cost money. around 30-50 gold in old time). You must be at peace with the civilisation you want to establish ambasy.
To minimize declaration of war on you, be sure you have 1 spearman and 1 archer per city. because a.i. know how well defended you are ( yes it s a cheat ), and keep a few archer or horseman near your border.
If an a.i. declare war on you, then immediatly choose an ally, your ally should be close to your ennemy, so he will engage fight. most of the time they will fight between themselve and leave you alone. To make an ally you will have to pay, lump- sum gold, or a technology, or a luxuries ( if you have raod or sea connection). Most of the time i can make alliance for a single luxuri trade.
Dont forget that alliance last 20 turn , so dont make peace with your ennemy until alliance is ended ( you will need to call your ally and deselect alliance from active trade menu). If you make peace while you have an alliance, then your reputation is screw up and it will be harder to trade in the futur.