Multiple-crystal X-ray diffraction and a multi-beam optical stress sensor were used to study AlN/c-sapphire templates grown by plasma-assisted molecular beam epitaxy. The influence of the nucleation and buffer layers growth regimes, temperature, the ratio between Al and N* growth fluxes on the stress generation and the character of the dislocation structure were analyzed. Templates with the best crystal quality with screw and edge threading dislocation densities in a range of 4∙10^8 and 8∙10^9 cm-2, respectively, were obtained at the flux ratio of Al to N* close to 1 by using two-stage temperature regimes.