The design of codes for distributed storage systems that protects from node failures has been studied for years, and locally repairable code (LRC) is such a method that gives a solution for fast recovery of node failures. Linear complementary dual code (LCD code) is useful for preventing malicious attacks, which helps to secure the system. In this paper, we combine LRC and LCD code by integration of enhancing security and repair efficiency, and propose some techniques for constructing LCD codes with their localities determined. On the basis of these methods and inheriting previous achievements of optimal LCD codes, we give optimal or near-optimal [n, k, d; r] LCD codes for k ≤ 6 and n ≥ k+1 with relatively small locality, mostly r ≤ 3. Since all of our obtained codes are distanceoptimal, in addition, we show that the majority of them are r-optimal and the other 63 codes are all near r-optimal, according to CM bound.