creating OP_RETURN script on bitcoin core console. i.e. with the help of commands
createrawtransaction has an option for data. That will create an OP_RETURN output with whatever hex-encoded data you want in it. So you would have a createrawtransaction command that looks something like this:

createrawtransaction '[]' '{"data":"deadbeef"}'