I'm nearly at the end of this derivation but totally stuck so I'd appreciate a nudge in the right direction
Consider a set of N identical but distinguishable particles in a system of energy E. These particles are to be placed in energy levels $E_i$ for $i = 1, 2 .. r$. Assume that we have $n_i$ particles in each energy level. The two constraints we impose are that $\sum_{i}^{r}n_i = N$ and $\sum_{i}^{r}E_i n_i = E$.
The number of microstates in a given macrostate is given by \begin{equation} \Omega = \frac{N!}{\prod_{i}^r n_{i}!} \end{equation}
We want to maximize this and for ease of notation, we work with $\ln\Omega$ and we use Stirling's approximation ($\ln x! = x\ln x - x$) to obtain \begin{equation} \ln\Omega = N\ln N - N - \sum_{i}^{r}n_i\ln n_i - n_i \end{equation}
Maximizing this function subject to the constraints $\sum_{i}^{r}n_i = N$ and $\sum_{i}^{r}E_i n_i = E$ is a classic Lagrange multiplier problem. We represent the undetermined multipliers to be $\alpha$ and $\beta$ for the two constraints and obtain \begin{align} \frac{\partial\ln\Omega}{\partial n_i} &= \alpha\frac{\partial n_i}{\partial n_i} + \beta\frac{\partial E_i n_i}{\partial n_i} \\ \nonumber \ln n_i &= \alpha + \beta E_i \\ \nonumber \therefore n_i &= e^{\alpha}e^{\beta E_i} \end{align}
Now, we use the first constraint equation to determine $\alpha$. We get \begin{align} \sum_i^r n_i &= N \\ \nonumber \sum_i^r e^{\alpha}e^{\beta E_i} &= N \\ \nonumber e^\alpha &= \frac{N}{\sum_i^re^{\beta E_i}} \\ \nonumber e^\alpha &= \frac{N}{Z} \end{align}
We have introduced the partition function, $Z=\sum_i^re^{\beta E_i}$ in the last line. Next, we have the second constraint equation that determines $\beta$ \begin{align} \sum_i^r E_i n_i &= E \\ \nonumber \frac{\sum_{i}^{r} E_i e^{\beta E_i}}{\sum_i^r e^{\beta E_i}} &= \frac{E}{N} \\ \nonumber \end{align}
I'm assuming I should somehow connect $E$ with $T$ so let's say $E=Nk_B T$. Then we have \begin{align} \frac{N}{Z}\frac{\partial Z}{\partial\beta} &= E \\ \frac{\partial\ln Z}{\partial\beta} &= k_B T \end{align}
How do I get to $\beta = -\frac{1}{k_B T}$ here? Notice that this derivation requires an extra minus sign compared to the usual definition of $\beta$ and this should come out naturally too, shouldn't it?