Everybody has different circumstances and different amounts of time available, so however you setup your writing routine you'll need to adapt it to fit your needs. With that said, though, there are some basic principles you can follow.
Do the research first
While it is possible to write some content before doing the research, sooner or later you will hit the limit of what you can say with confidence. So if it's a choice between writing for the sake of writing or doing the actual work the writing is supposed to present, do the research.
See also: Don't neglect your data!
Of course, in some fields writing is a crucial part of the research itself, and for those writing in a second (or third or fourth...) language then it's important to practice writing and make a conscious effort to improve.
See also: Writing your way to a PhD
See also: Writing your thesis in a second language
Turn off the internet
Or at least the parts of the internet that distract you. If you reach a difficult point in your writing and your first instinctive response is to check email (then facebook, news headlines etc), then you will be at your most distracted when you need to be at your most focused.
I wrote my thesis with no internet connection at home, removing the need for willpower to avoid online procrastination. For those unable to do this, try using software to block sites during your writing time (I have recommended Freedom in the past, but it's become less reliable lately- check this list for alternatives).
Let yourself settle
I usually find that it takes me about 20 minutes just to let my brain settle and to focus. At first, my brain is just racing through countless ideas, so I try to relax into the writing rather than rushing to produce words as fast as possible.
One useful technique is to turn the screen off and spend a few minutes with pen and paper to decide exactly what you want to communicate or what points you need to cover. Try to narrow your focus, slow your brain down a little, and just work on one idea at a time.
See also: How to overcome writer's block
Set achievable targets
When writing my thesis, I set myself a minimum daily target of 500 words per day*. This was high enough to feel like a significant amount of work, but low enough that I knew I could easily beat the target most days. Whether I struggled to reach 500 or easily wrote 2000, both felt good.You might not be able to produce 500 words per day regularly, so set a target you know you can beat every day.
*I didn't do this all the way through my PhD, only at the end when I had to get the thesis done. Also, there are times when polishing what you have is more important than increasing the word count- when this happens just make the goal to finish the section you are working on.
See also: How I wrote a PhD thesis in 3 months
Figure out what works for you
Some people find it easiest to get up early and write while they are fresh. Personally, I find it easier to stay up than to get up. You don't have to copy somebody else's routine if it doesn't work for you.Figure out what writing routine works for you, then try to write during the same hours each day.
Get away from the computer when you need a break
Avoid email and facebook during breaks. Get away from the computer and leave your phone turned off, make a cup of tea, go for a walk around the block... anything that gives you a break from staring at the screen.Avoid eating at your desk.
Don't work to exhaustion
I always tried to leave a bit in reserve, stopping work for the day while I still had something to say. Some people panic that they won't be able to start again if they stop, but by working to exhaustion they make it much harder to start again the next day.
At the end of the day...
Turn the screen off and take 10 minutes with pen and paper to write down any thoughts you have and tasks you still need to do. Give yourself something easy to start the next day with.