How is temperature defined, and measured? In questions like this one, temperatures of millions of degrees (Celsius, Kelvin, it doesn't really matter at that point) are mentioned.
But, what does it mean exactly? What is measured, and how? As I more or less expected,  the Wikipedia article mentions that the official definition  (the one I was told in elementary school, either between freezing and boiling points of water for Celsius, or between absolute zero and triple point of water for Kelvin) doesn't really work above 1300K.
So, questions:


*

*For "earthly temperatures", how is temperature measured consistently? Why would linearity of the measuring device be assumed, in particular to extrapolate beyond the initial (0-100, or 0-273.16) range? What guarantees that two thermometers, working under different principles (say, mercury and electricity), that agree at 0C and 100C, will agree at 50C?


*What do statements like "the temperature in the Sun's core is $1.5\times10^7K$ mean? Or, even, what do the "7000K" in the Earth's core mean?

 A: The modern understanding of temperature comes from statistical mechanics, where it is defined as,
$$\frac{1}{T} = \frac{\partial S}{\partial E}$$
where $S = k_B \ln \Omega(E)$ is the entropy of the system, with $\Omega(E)$ the number of states at energy $E$.  To see why it is a sensible definition, recall a key property is that systems of the same temperature when brought in contact will not exchange energy.
If two systems are brought in contact, they will act to maximise their entropy, with one system at some energy $E_\star$ and the other at $E_{\mathrm{total}}-E_\star$ with $E_\star$ defined as,
$$\frac{\partial S_1}{\partial E}\bigg\rvert_{E=E_\star} - \frac{\partial S_2}{\partial E}\bigg\rvert_{E=E_{\mathrm{total}}-E_\star}=0.$$
If nothing is to occur when they are brought in contact, it must mean the system in question already had this energy, which is equivalent mathematically to stating,
$$\frac{\partial S_1}{\partial E} = \frac{\partial S_2}{\partial E} \leftrightarrow T_1 = T_2$$
implying they both have the same property which we call temperature. This shows why it is a sensible definition that is consistent with what we observe in experiment. It is also worth noting that with this definition, it follows entropy must increase. If the systems are at different energies, we have that,
$$\delta S = \frac{\partial S_1}{\partial E}\delta E_1 + \frac{S_2}{\partial E}\delta E_2 = \left( \frac{\partial S_1}{\partial E}-\frac{\partial S_2}{\partial E}\right)\delta E_1 = \left(\frac{1}{T_1}-\frac{1}{T_2}\right) \delta E_1 >0$$
using conservation that implies $\delta E_1 = -\delta E_2$. I hope this elucidates how temperature is defined, and why the definition is sensible and useful. 

It is worth pointing out one could argue, why temperature was not defined in some alternate manner, like as $\frac{1}{T^2} = \frac{\partial S}{\partial E}$. The fact it is $\frac{1}{T}$ is motivated by explicitly computing $T$ for various systems, and finding $\frac{1}{T} = \frac{\partial S}{\partial E}$ is the most convenient choice. 
A: Definitions
First and foremost, temperature is a parameter defining a statistical distribution, much as the statistical parameters of mean and standard deviation define the normal probability distribution. Temperature defines the equilibrium (maximum likelihood) distribution of energies of particles in a collection of statistically independent particles through the Boltzmann distribution. If the possible energies of the particles are $E_i$, then the maximum likelihood particle energy distribution is proportional to $\exp\left(-\frac{E_i}{k\,T}\right)$, where $T$ is simply a parameter of the distribution. Most often, the higher the system's total energy, the higher its temperature (but this is not always so, see my answer here) and indeed for ideal gases, the temperature is proportional to the mean energy of the constituent molecules (sometimes one hears people incorrectly saying that temperature measures the mean particle energy - this is so for ideal gasses but not in general). This latter, incorrect definition will nonetheless give much correct intuition for common systems - an eight year old girl at my daughter's school in  our parents' science sessions once told me that she thought temperature measured the amount of heat energy in a body, and I was pretty impressed by that answer from an eight year old.
An equivalent definition that allows us to calculate the temperature statistical parameter is that an equilibrium thermodynamic system's reciprocal temperature, $\beta = \frac{1}{k\,T}$ is defined by:
$$\frac{1}{k\,T} = \partial_U S\tag{1}$$
where $U$ is the total internal energy of a system and $S$ the system's entropy i.e. $\beta$ (sometimes quaintly called the "perk") is how much a given system "thermalizes" (increases its entropy) in response to the adding of heat to its internal energy $U$ (how much the system rouses or "perks up"). The Boltzmann constant depends on how one defines one's unit temperature - in natural (Plank) units unity temperature is defined so that $k = 1$. 
This definition hearkens back to Carnot's ingenious definition of temperature, whereby one chooses a "standard" heat reservoir and then measures the efficiency of an ideal heat engine working between a reservoir whose temperature is to be measured and the standard one. If the efficiency is $\eta$, then the temperature of the hot reservoir is $\frac{1}{1-\eta}$. The choice of the standard reservoir is equivalent to fixing the Boltzmann constant. Of course, ideal heat engines do not exist, but this is a "thought experiment" definition. Nonetheless, this definition leads to the the realization that there must be a function of state - the entropy - and that we can define the temperature through (1). See my answer here for more details.
Measurements
Extreme temperatures, such as the cores of stars, are calculated theoretically. Given a stellar thermodynamic model and calculations of pressure from gravitational theory, one can calculate the statistical distribution of energies that prevails. Stellar models predict surface temperatures and these latter, not so extreme temperatures can be measured by spectroscopy, i.e. by measuring the spectrum of emitted light and then fitting it to the Planck Radiation Law. Given reasonable agreement between predicted and observed quantities, one can have reasonable confidence in the temperatures calculated for the star core.
Pyrometry, grounded on the Stefan-Boltzmann law, is another, simpler (but less accurate) way to measure highish temperatures.
Earth core temperatures are deduced partly through theoretical models in the same way, but also inferred from what we know about the behavior of matter at these temperatures. Such temperatures and pressures can be created in the laboratory and monitored through pyrometry. We are reasonably confident of the phase diagram for iron, for example, and we know under what temperatures and pressures it will be liquid and when it will be solid. Then, seismic wave measurements give us a picture of the core of the Earth; thus we know the radius of the inner, solid core. Given that we know the phase diagram for the assumed core iron-nickel alloy, the solid core boundary gives us an indirect measurement of the temperature at the boundary. 
A: I love people questioning the meanings of measurements we take.  Far too many people just blindly assume that if the liquid in the thermometer reaches 99 degrees Fahrenheit, then that's simply the truth.  Kudos to you for questioning it.
WetSavannaAnimal has the correct "modern" definitions of temperature, which are based on how scientists currently model the world around us.  However, if we want to look at what "guarantees" we have, it's helpful to think about it a bit backwards.  While I could make a statement such as "your mercury and electronic thermometers will agree at 50 °C because they are both devices designed to measure the same statistical value," it can be helpful instead to look from a historical perspective at how we arrived at thermometers in the first place.  From such a viewpoint, you have no guarantee from physics that two thermometers will read the same, but historically physicists chose to focus on properties which could be measured consistently.
As an example, I could start with the Celsius scale which states that water at its freezing point is at 0 °C and at its boiling point is at 100 °C.  On its own, this definition would permit any number of highly nonlinear devices, such that no two thermometers would have to agree at any temperature except 0 and 100.  However, physicists noticed useful properties about objects.  They noticed that if you bring two objects of different temperatures in contact, they equalize at some middle temperature.  You could build tables of different sizes of objects and temperatures of objects and reliably predict the final temperature when they are brought together.
One of the properties we know of temperature is that this particular effect is very linear.  We can define the heat capacities of the objects $H_a$ and $H_b$, and their temperatures, and show that the final temperature is just a weighted average based on $H_a$ and $H_b$.  Now we know this because we read it in a textbook.  The original physicists had to discover it.  What they would have noticed is that you could model this effect by a linear model of the objects and a non-linear mapping to map this to readings off their thermometers.  This showed them that the effects were linear, and the only non-linearity was coming from their thermometers.  With this information in mind, it would be easy for them to construct thermometers that are as linear as possible themselves (such as our liquid thermometers we use to take a person's temperature).  This would lead everyone to be able to agree on some 50 °C point, whether it's 1 inch of mercury in a thermometer or 20 degrees of deflection on a bimetal spring.  Everyone could agree that there is some linear thing to measure because the underlying physics of heat transfer was linear.  Why it was linear took much longer to figure out, but we understood that these linear models were a great fit for physics.
This then permits us to start talking about temperatures above 100 °C.  Consider if I have a 99 g block of steel and a 1 g steel bullet, and I heat the bullet up to a much hotter temperature than 100 °C.  Let's say that, in truth, I heat it up to 1000 °C, but I don't yet know that temperature.  I measure the temperature using my thermometer, and see that the mercury goes 5 inches higher than my 100 °C line.  Now, I put the steel block and bullet together, and let them equalize.  When I'm done, I observe that the block+bullet is now 10 °C warmer than room temperature (well within the range of my thermometer).  I can now calculate from that 10 °C temperature gain and the relative masses of the blocks that the bullet must have been 1000 °C, so that 5 inch mark on my thermometer must be the 1000 °C mark.  If my thermometer is linear, this should be 10× higher than the 100 °C mark (if it's non-linear, I'll have to note that detail).  If I do this for a few temperatures, I can develop confidence that my thermometer is linear in these regions higher than 100 °C.
At some point, you are right in feeling like the measurements get absurd.  Millions of degrees doesn't seem to mean much to humans, does it?  However, we have equations predicting heat transfers due to radiation from very hot objects.  These equations do a very good job of predicting heat transfer on terrestrial scales.  If we apply those equations to the spectra we see from stars, we find that the calculations do indeed suggest millions of degrees.  It's a very indirect measurement, but if we measure something indirectly many different ways, and they all provide the same result, we can have a high degree of confidence that that measurement is the same as we would get if we measured it directly.
