It's not illegal but I wouldn't run an exit node, exit's are what reach out to the clear net so any illegal activity it might be used for would appear to be coming from your IP address. You can successfully defend yourself in court over this, many have, but is it worth the hassle?
Tor Relays you can run easily enough but keep in mind many organizations get the IP addresses of tor relays/exits (they are all published online) and block them all so you may find your home IP getting randomly blocked by certain companies and you won't be able to explain it away.
If you want to run something at home consider a bridge, those are unpublished and must be manually connected to after requesting one from a country that censors Tor.
Relays/Exit nodes I would run on VPS instances if you want to contribute to the network, make sure they support/approve exit nodes, many do but have some reverse dns stuff you must setup to mention tor-exit and be sure the http page tor exits host is working, this is how they avoid the legal consequences of random illegal activity coming out of a tor exit if they don't support exits just run a relay.
Exit nodes host a basic http page explaining its an exit and what that means so they are easily identifiable as a tor exit if you browse to their IP in a browser.