There's several ways to generate a fixed frequency. Quartz crystals are one, which use mechanical resonance to generate a fixed frequency. There's other types of mechanical resonators as well, ceramic oscillators come to mind, and there's also other ways to achieve resonance and/or oscillation. Anyway, mechanical resonators can be very precise, with precision measured in parts-per-million. They don't go far above 100 MHz though. Perhaps even more importantly though, their frequency is fixed, while computers can change their clock frequency at run-time, for instance for throttling based on frequency or power source, or just to satisfy overclockers.
It is also possible to generate frequencies by stringing purely electrical components together in such a way that they oscillate. Without going into detail about all the ways you can do this, the typical way that I know of that can generate high frequencies such as these is stringing an odd amount of inverters together. There's no stable state, so this will oscillate as fast as the inverters will go. A nice feature here is that if you change the operating voltage or some other characteristic of the inverters a little, the frequency will change. Such a thing is called a voltage-controlled oscillator, or VCO (this is a broader term though, there's more ways to make a VCO; here's an example of a device using the method I'm referring to). A downside is that due to the IC manufacturing process you don't really know what the frequency will be, and it will differ greatly between devices, based on temperature, age, etc..
These two technologies can be combined. The basic idea is that we can measure the frequency coming out of the VCO using a reference frequency from a quartz crystal, and then adjust the control voltage of the VCO to make change it to the frequency we want. This can be accomplished using a phase-locked loop (PLL). Specifically, a PLL tries to make its feedback input frequency and phase exactly the same as its reference input. So what's the point of generating something that's exactly the same? You can put any kind of circuit you want between the VCO and the PLL feedback input, in this case most notably a frequency divider. Frequency dividers are easy, you just make a counter that always increments until it reaches a set value, at which point it resets and toggles the state of the output clock. The PLL will try to make the output of the divider the same as the reference clock, therefore the output of the VCO must be the reference clock times the divider value, and we're done.
If you're mind-boggled about how inverters can be fast enough to generate such small time periods, consider that to make a processor you actually need to be able to compute things between two clock edges. (If you did not know/realize this and want to learn more, "synchronous logic" would be a good search term.) That computation is a lot more than a couple inversions, so VCOs will always be able to synthesize frequencies that are useful as a clock. In fact, the VCO might run at 10+ GHz, with the actual processor clock divided down from there, in order to be able to synthesize more frequencies, or just because it saves inverters in the inverter chain. I'm currently working in a group that is developing an IC based on a 60nm technology (much older than what's used in your computer) and if I recall correctly, the latency of an inverter is in the order of 0.1ns.