From Halopedia, the Halo wiki
This section of the page is tips and strategies to help readers accomplish this level, particularly on the Legendary difficulty.
On Legendary, destroying the Scarab at the same time you protect your base, as well as not having your units completely destroyed before you scratch the surface of the Scarab's health bar can be extremely difficult. There are various ways to beat this mission on Legendary, that work just as well...
Note: while it is strongly encouraged for you to buy the Halo Wars Strategy Guide, do not feel that you are under bondage to do exactly what it says 100% of the time.
In the initial construction of your base, destroy your armory, and build a barracks in its place. Build all supply pads in any other open spots, except for one field armory.
Immediately start building marine squads, and upgrade them all of the way, as quickly as possible until you have reached maximum population. (even 40, once you buy the "reinforcements" upgrade from your field armory).
Note that there is no set way that you should do this, but you'll be advised to be destroying at least 2 or 3 power nodes before assaulting the Scarab.
From your field armory, buy "reinforcements", "booster shots", "reserves", and all of the "turret" upgrades. After you have done this, destroy your field armory and replace it with a supply pad, and make the supply pad heavy.
To prepare your base against the Covenant onslaught, upgrade 2 of your turrets to "flame mortar", and the other 2 to "rail gun". Also, lock your 2 Rhinos down to act as additional turrets.
Once you have all 40 population reached, basically all fully upgraded marines, you are ready to begin the attack. Send all of them in one massive wave, and run back and forth, from side to side of the Scarab as its head turns. Use your rocket abilities whenever you can. As your units are destroyed by the Covenant opposition, make your main waypoint at the position of the Scarab, and keep a steady flow of marines to aid in the battle. Make use of your MAC blast on the Scarab whenever you can.
As the level progresses, there will come a time when there is very little of the barrier protecting your base left. This calls for desperate measures. When your base is in actual danger of being destroyed by the Scarab, literally command your marines to stand in front of the blast to draw the Scarab's fire. The reason to build marines is because vehicles such as Warthogs and Scorpions are too big, and there are too few of them, so that the Scarab immediately blows through them. Marines, on the other hand, are whittled down more slowly, but it is still difficult on Legendary.
Keep on sending salvos of rockets, and reinforcing the assault, and eventually if done right, the Scarab will fall. Good luck...