The Stoics thought about this, and their answer is to be healthy and moderate regarding the pursuit of pleasure and pain - don't pursue too much pleasure, and also don't put yourself under unnecessary pain.
I have an infographic that explains Stoicism in brief, comprehensive detail that I could share, if you'd like :>