Background introduction: Alibaba cloud, 512M memory (the most loser configuration), set up a lamp environment, except that MySQL has been allocated about 100m (this can’t be less), HTTP has occupied more than 200m, which is too large, so we decided to replace it with a lighter, high concurrency nginx.
Background data
As shown in the figure below: the system is only 500m, which takes up 100m of MySQL. Httpd accounts for more than 1 / 2 (often up to a dozen processes). The remaining 50m, sometimes even less, can’t bear it. It often causes database crash and writes an automatic restart script, but it’s not a cure
#Count the number of Apache processes
ps aux|grep httpd | wc –l
Solutions
-
1: Optimized for Apache. Including optimizing the operation mode of workers and so on. You can refer to Apache optimization
-
2: replace the lightweight server. Adopt lighter servers such as nginx or lighthttpd. According to the legend, nginx is a better way to achieve load balancing and high concurrency, and decides to practice it.
Replace Apache with nginx
-
1: Stop Apache
sudo service httpd stopNote: in case, it’s better not to unload it in advance.
-
2: Install nginx
yum install nginx -
3: Start nginx
sudo nginxAfter successful installation, the startup is as follows
-
4: Simple configuration nginx
It is mainly to modify the log [easy to trace PROBLEMS] and the web_ Root file [quick start website] -
5: Restart nginx
[[email protected] nginx]# nginx -s quit
[[email protected] nginx]# nginxAs shown in the figure below, the web directory configuration succeeded!
-
6: Add PHP support
Install PHP FPM
yum install php-fpmnginx.conf set up
location ~ \.php$ {root /var/www/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name; include fastcgi_params;
}
-
7: Restart the service, website reply.
-
8: A simple comparison of consumption and consumption is shown as follows: 200m is basically saved, although this may be the data at the initial stage of operation; however, it is still a lot lighter, with each service accounting for about 1 / 4 of the total storage and many fewer threads. Performance in terms of memory usage. I think it’s OK. Next, it depends on performance
follow-up
The first time I contacted nginx, I felt it was pretty good overall. In the future, basic anti attack, multi port setting and performance configuration will be carried out.
Original link of personal website