Versioning server configurations based on debian / ubuntu

Good day, dear community.
I decided to share a small idea, maybe someone will be interested and useful.

Tired of lost and broken configurations, authorization on servers under root in order to transfer new optimal configurations, I decided to create repositories from the configuration folders and give them access to a more accessible place.

A little bit about yourself


I myself am a web programmer, for some time I was sitting on ubuntu, the server (VPS) almost everything on debian. There is not much experience in server administration, unlike colleagues and hosters, but knowledge in this direction has always been very attractive. I could sit for hours in the console and solve certain tasks. When time was running out, more experienced colleagues would pick up task toys and tell me what I was doing wrong. But it was always interesting what exactly they did themselves and how the settings of more loaded projects occur. All projects we store in bitbucket using Mercurial version control system. One fine day, we decided to maintain an up-to-date version of projects on servers using the same tool and made our life very easy. Now you can raise the latest updates on the server in two commands:

hg pull && hg up

Why hosters do not offer such software on their shared hosting remains a mystery. In my opinion, FTP upload yesterday. Now new employees come and give them access to the servers slowly, but already under my control, having seen the picture from the other side, I was horrified what it was done on the server and it was very difficult to find. After several hours, the server returned to my normal state and came to me:

Idea for a million


Having received a new debain-based server (VPS), without thinking twice, I created a repository in the configuration folder.

New server
We produce all commands from under the root user.
First of all, we update the software on the server:
apt-get update && apt-get upgrade

We put the Mercurial package (appeared in debian 6, but saw installation articles under debian 5):
apt-get install mercurial

Go to the configuration folder:
cd /etc

Create a repository:
hg init

What will the hidden folder ".hg" be created for? Let's
talk a little about ourselves:
nano /etc/.hg/hgrc

Specify the data:
[ui]
username = User <****@gmail.com>


Already now you can find out about all the files by running the command:
hg status

Mercury will only show a list of files that are still new to it.

Specify that we want to add all the new files to the following commit:
hg add

Finally, we fix the first state of the configurations:
hg commit -m 'first commit'

Now you can safely install and configure the rest of the software.

At any time, you can check the status of the configurations using the command:
hg status

What exactly has changed in the files can be found with the command:
hg diff ./путь до файла

You can roll back the changes with the command:
hg revert ./путь до файла

It will be even better to get acquainted with all the teams:
hg help


Publication

When we raise a new server or update the old one all the time remember:
  • Where are your server setup reminders
  • On which project has he raised similar software
  • What is the root password for the server (to read the configs)

and the list may be large.

I decided to upload everything to the private repository. Again, we are using bitbucket . We create a repository on it, we get a path, something like:
https://bitbucket.org/username/etc-project-a

rediscover the configuration of our repository:
nano /etc/.hg/hgrc

And indicate below:
[paths]
default = https://bitbucket.org/username/etc-project-a

Run the command:
hg push

What mercury will ask you for authorization data on the bitbucket server. The good news is that you can configure authorization by ssh key.

Now our configurations are in a dry, cool place. You can always look at how one or another server is configured and raise a new one using examples. To do this, you need to clone the repository to the local machine, or use the quite convenient web-interface from the bitpacket.

Pros:
  • Store configuration versions
  • You can always roll back to the stable version
  • You can determine in one command what you did without you
  • You can quickly find out how the server is configured without logging in to it.

Minuses:
  • Remember to commit recent changes

I wanted to add automatic commits on the crown, but I thought it was better to leave such a simple solution. Perhaps there are other ready-made solutions about which I would gladly read. Who knows, maybe this short article will help you come up with a simpler and more useful solution about which, I hope, you will also share with us.

Thanks.

Also popular now: