he was a minor aristocrat and official of the state of lu ( in what is now shandong province ) who spent most of his life as an itinerant scholar-teacher as well as an adviser to the rulers of various chinese states .