What kind of a relay is that? Most 24V relays have coil current 10-20mA. Using IRF540 is ok but huge overkill, even if you are driving a contactor.
2x 10k will split supply voltage when opto is on so Vgs will be in the 12V range (good). IRF540 has input capacitance of ~1nF so 10K values are ok.
note that output current is 24V/(2*10k)=1.2mA. according to datasheet this opto is meant for 20mA drive current. note that min CTR of 50%. so to reliably drive output, you need at least 1.2mA/50% = 2.4mA. According to Fig5, Vf is about 1V when If=2.4mA or similar.
Assuming that output of your micro is 5V, using 1k resistor gives you If= (5V-1V)/1k=4mA which is good (it is between 2.4mA and 20mA).
even if your micro has 3.3V output, (3.3V-1V)/1k= 2.3mA which should still be ok.