In my experience with 24V solenoid valves, they don't need the maximum listed current. For a 2A solenoid it probably needs 1-1.5A to activate, and then ~500mA to hold open. You can design circuits which supply this.
The listed mosfet has a threshold voltage between 2 and 4 volts, so it's likely the ESP32 can't turn it on from 3.3V. You would want a smaller mosfet to drive the gate on it.
This is a really obnoxious part to design this circuit with, because the gate voltage range is above a microcontroller but it's also below 24v. I would encourage you to get a logic level mosfet if you have the option to. That way you don't need to worry about all of these gate voltage thresholds, and you could use 1 mosfet and 1 resistor.
This is the best I could come up with, it should be compatible with most garden variety p-mosfets and n-mosfets, and a handful of 10k resistors:
simulate this circuit – Schematic created using CircuitLab
EDIT:
This is how it would simplify with a logic-level mosfet.
simulate this circuit
Very easy to find a new part with:
- VDS of greater than 24V, 30 is very common
- Current rating greater than 2A
- low RDSon specified between 1.8-4.5V, usually means its logic level
- VGSth max of 3.3V or less
- low input capacitance, otherwise put a series resistor