2. Let the infinite sequence $\left\{a_{n}\right\}$ have all positive terms, and let $S_{n}$ be the sum of its first $n$ terms. For any positive integer $n$, the arithmetic mean of $a_{n}$ and 2 equals the geometric mean of $S_{n}$ and 2. Then the general term formula of the sequence is $\qquad$ .
2. $a_{n}=4 n-2\left(n \in \mathbf{N}_{+}\right)$.

From the problem, we know that $\frac{a_{n}+2}{2}=\sqrt{2 S_{n}}$, which means
$$
S_{n}=\frac{\left(a_{n}+2\right)^{2}}{8} \text {. }
$$

From equation (1), we have $\frac{a_{1}+2}{2}=\sqrt{2 a_{1}}$, which gives $a_{1}=2$.
Also from equation (1), we get
$S_{n-1}=\frac{\left(a_{n-1}+2\right)^{2}}{8}(n \geqslant 2)$.
Thus, $a_{n}=S_{n}-S_{n-1}=\frac{\left(a_{n}+2\right)^{2}}{8}-\frac{\left(a_{n-1}+2\right)^{2}}{8}(n \geqslant 2)$.
Simplifying, we get $\left(a_{n}+a_{n-1}\right)\left(a_{n}-a_{n-1}-4\right)=0$.
Since $a_{n}>0, a_{n-1}>0$, we have,
$$
a_{n}-a_{n-1}=4(n \geqslant 2), a_{1}=2 \text {. }
$$

Therefore, the sequence $\left\{a_{n}\right\}$ is an arithmetic sequence with the first term 2 and common difference 4, and its general term formula is
$$
a_{n}=2+4(n-1)=4 n-2\left(n \in \mathbf{N}_{+}\right) \text {. }
$$