Sometimes there are days when nothing works 🙂

In such cases, we can only hope that tomorrow will be better than today 🙂

Before I start with the nonsense, I want to say, that I am not very advanced with web hosting and all I will write is the experience I have gained in recent times 2-3 months. I administer a fairly busy VPS in terms of traffic, according to tyxo is in the top 80 but enters the top 70 ;). That's my thought, that after so long I have acquired various habits and reached good practices in one way or another (usually more difficult) :D. I will not even write or go into the details of the configuration at all. Rather, I will share ideas to think about.

  1. Update the software regularly. Apache, php mysql all wants updates. Whether to patch holes in the security, whether due to fixed bugs or new features. Always keep your software up to date. In general, it is rare to drill a server through the applications, usually through holes in the code of the hosted things, but let's not rely only on this.
  2. Apache – it is not desirable for your web server to have more active modules than the ones you actually use. The more modules on- slow work.
  3. Multiple users on the same server – opcode cache. Some time ago I wrote Besides zerdion do satisfactory tests and see the real benefits of this magic. In my case I chose eAccelerator because in a real working environment it shows the best results with all the settings to it. Faster loading with less eating resources, which means more users.
  4. They push you with traffic – gzip. The easiest way to reduce the real traffic you make is with gzip compression of http responses to the client. Mod deflate is the apache solution. For other http servers I have not researched the issue :). Real around 50% I lost traffic when compressing on html,css,js,xml. I need to see if I can compress other types of content as well. Because real photos are the content that makes the most traffic in a site.
  5. mysql serer – I highly recommend it if you haven't been awarded a version 5.1 to do it. In general, Oracle has some small experience with databases 😆 and this experience has put it well into 5.1 version I have not tried 5.5 but I plan to do that soon. Definitely speeded up the work of sql queries maybe slightly dropped the load but by no more than 5-6% but also the new functionalities for the programmers are wonderful. The basic one partitions. When upgrading, be careful what settings you have in my.cfg Not all old options are valid, it's also a good idea to remove old libraries at least with CentOS 5.5 made problems with Debian I did not have such annoyances. Then look at the mysql log because some of the options have different names and it is good to change them if you go to 5.5 don't wonder why your configuration doesn't work.
  6. sql queries. Be sure to enable the slow query recording option. In these logs you can return information to the programmers if you are not for slow requests to be optimized. The fewer such requests the less load on your server 😉
  7. A little protection – change the default port of ssh you don't need crazy bots to try to hack you. Apache secure it with mod_security quite a useful module makes filtering on quite a bit – sql inj, rfi DDoS and others. It won't stop a lot of fuss, but at least the lamers will weed them out. PHP is a good idea to protect with Suhosin. It can be put as an additional extension or directly as a patch in the php code. I personally prefer the first one I think is cleaner.

For starters, these are the things I can think of. They are not many and when I think about it I have done a lot of optimizations on the server but many of them are quite specific according to the situation and there is no point in explaining them such as cache limits or how many processes the apache has been raised. Probably in time I will think of more things that are how to say some of the little things that give the big result.. The machine is quite well optimized for comparison we make 20k unique visits per day and we are on the lowest possible vps plan load time on the pages we do not exceed 1,5-2 sec or if it exceeds it is due to external sources of ads otherwise the page itself spits out for fractions of a second. People close to us have non-optimized servers with a lot more resources than ours and have the same results. In general, his mother is optimizing and her father is drinking beer

ps The song is slightly related to the theme 😀

I hadn't worked on my demo for almost a year NUKI. Today I have time to fix things because there were a lot of things that were not quite good. I added some new functionality. I rearranged the code, with more features so I shortened it and it became clearer.

The main new functionality I introduced is the signal trap. At some point as the demon rotates the dreambox the receiver decides to kill it and thus stops monitoring my process, which in itself is a rather unpleasant moment. And I can't figure out what's going on because the space for logs is ungodly small and I have to make complex schemes with network sharing that I don't care about.. In general, the signal trap is a nice feature of bash scripts to intercept signals from outputs or those sent to them by the kernel via kill say 😉 and thus we can prevent some of the immediate subsequent events. Just insert that SIGKIL or kill -9 it cannot be intercepted and prevented, so is the design in the kernel. It terminates the PID submitted to it directly. Now the corresponding code

#trapping signals I know -9 dosent work but we try it just in case ; )
trap on_exit 0 14 1 2 9 13 15 6 8 4 3 11 5
on_exit () {
make_debug 10 #unexpected error
#reboot now if we hawe trapped signal
reboot -d 0
exit 0

The first line tells us what action to take and at which signals we will intercept more for the signals. man signals 😉 In this case, I am interested in these. As you can see, they lead to a simple function that debugs a message and restarts the receiver. I'm not having lunch, that will lead to the result I expect, because I think all that interferes is killing with kill -9 but nothing prevents it from being tried.

The other drastic changes are the features most things that are repeated by the code I pushed them into functions, that was a little awkward to watch no, that is now de 😉 I had a slight drama with return in bash – I put my return in one function and expect behavior like all other programming languages ​​I know, but it turned out that return returns only integer values ​​and that maximum 2 😀 and I wanted to return my string. There was an ugly pig. The solution to the problem is simple


if [ $T -eq $N ]
 echo "Cam is down! Reboot..."
make_debug 4 # cam is down
echo $rcam

# ---cuted----

#finding real cam1
 rcam1=$(find_cam $cam1)

The first part is the end of my function and through echo I spit out the result. Taking it is elementary with the last line in the upper passage.

Hmmm I think, that this is the interesting part of the code.

I want to thank her for her inspiration the SilMJ0O13UI&feature=related