The space station needs multiply redundant systems for all its systems. Fortunately, it is in space where the deterioration of machinery is minimized. Space probes and satellites routinely exceed their estimated working lives (except those that malfunctioned early in their careers).
Space station personnel will receive expert training in space station from birth especially if this is their heritage. Folks who are born and die on space stations need to be extra well versed and educated in all aspects of space station maintenance.
Your space station should be equipped with an army of repair and maintenance robots. There should be diagnostic sensors in every suitable location to detect the slightest system or structural failure. Every system and component needs to checked and rechecked for good running. This will be part of your space station's design. Easy access to all systems for checking, inspecting and, when needed, repairing.
Space station longevity begins with good systems and structural design. Make sure yours is designed for millennia. Do not you cut too many cost corners. The life of your space station and the lives of those living on it don't come cheap. You don't want them going cheaply either.
Make sure reliable supply routes are handy. For those occasions, when all your normal systems and procedures for maintaining, repairing and sustaining your space station fail. This could be the usual space piracy, interstellar wars, space whale rustlers or a rogue black hole.
Keep handy a goody supply of raw materials that can be converted into manufactured components. Have access to an external energy source by using large solar power collectors or nuclear based power generators (this can be fusion all the way up to antimatter). The power is needed to make and process components.
Recycle, recycle, and, don't forget, to recycle. To ensure long term survival, the golden rule is waste not. Defunct components are raw material. Use them again and again. Even if this means reducing to their constituent elements. Remember that's why your power generators are there.
Maintain friendly relationships with your neighbours. They are an excellent source for replacement parts and raw materials. Considering most of your raw materials will be extracted from asteroids, moons, and, sometimes, even planets. Territorial claims over who can access and use the material in those astronomical bodies may be in place. If you trespass on their asteroids and remove matter without permission you get a missile up your probic vent.
Be nice and respectful. It's a good idea to look after the neighbourhood. Even if they own the local system's asteroids, they might be grateful and let you extract minerals for shipping to their habitats, so in return you could be allowed to take some for yourself.
Good design, good work, well trained space station personnel and robots, good relationships with neighbours and suppliers, and leave nothing to chance. Take care for it, and it will take care for you.
Five millennia, hah! This baby's good for at least fifteen.