The maximum principle is a basic qualitative property of the solution of second-order elliptic boundary value problems. The preservation of the qualitative characteristics, such as the maximum principle, in discrete model is one of the key requirements. It is well known that standard linear finite element solution does not satisfy maximum principle on general triangular meshes in 2D. In this paper we consider how to enforce discrete maximum principle for linear finite element solutions for the linear second-order self-adjoint elliptic equation. First approach is based on repair technique, which is a posteriori correction of the discrete solution. Second method is based on constrained optimization. Numerical tests that include anisotropic cases demonstrate how our method works for problems for which the standard finite element methods produce numerical solutions that violate the discrete maximum principle.