In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Basic concept
LAMP:Linux-Apache-Mysql-Php
Stable, synchronous, good customer experience, high resource utilization rate-small number of visits
LNMP: Linux-Nginx-Mysql-Php
Asynchronous processing, load balancing, large amount of concurrent visits, high utilization-- the number of visits increases gradually.
LNMPA: Linux-Apache-Nginx-Mysql-Php-
The front-end niginx and the back-end apache-- have large traffic and stable operation
Nginx: lightweight asynchronous Web server / reverse server proxy and IMCP/POP3 proxy server.
The way Nginx handles connections is similar to the simulation of apache. Nginx generates multiple child processes worker through the main process master, and then each worker generates many threads, which handle specific requirements. Because of asynchronous processing, the speed is very fast!
The performance of Nginx is compared with that of apache and lighttp, as shown below:
System requirement
System version with unix as kernel: Centos/RHEL/Fedora/Debian/Ubuntu
Hard disk space above 3GB is required
MySQL 5.6and MaiiaDB 10 must have more than 1G of memory
SElinux must be turned off
Strictly case-sensitive under Linux, you should pay attention to entering commands
The normal use of Yum source is required.
Installation steps
1. Download and install the LNMP one-click installation package:
# tar-xvf lnmp1.2-full.tar.gz
# cd lnmp1.2-full
#. / install.sh lnmp | lamp | lnmpa
If you want to uninstall if the installation fails, execute. / uninstall to uninstall
Use the network yum source to install the LNMP command with one click
Install LNMP execution: wget-c http://soft.vpser.net/lnmp/lnmp1.2-full.tar.gz & & tar xvf lnmp1.2-full.tar.gz & & cd lnmp1.2-full &. / install.shlnmp
If you need to install LNMPA or LAMP, replace the parameter after. / install.sh with lnmpa or lamp.
After the above command is executed, the following prompt appears:
You need to set the root password for MySQL (if you do not enter directly, enter will be set to root). Enter and enter to proceed to the next step, as shown below:
Here, you need to confirm whether MySQL InnoDB is enabled. If you are not sure whether it is enabled, you can enter y, y for enabling, and n for not enabling. The default is y. Enter and enter to proceed to the next step, and select the MySQL version:
Enter the serial number of the MySQL or MariaDB version, enter to proceed to the next step, and select the PHP version:
Enter the serial number of the PHP version, enter to proceed to the next step, and choose whether to install memory optimization:
You can choose not to install, Jemalloc or TCmalloc, enter the corresponding serial number to enter.
After prompting "Press any keyto install...or Press Ctrl+c to cancel", press enter to confirm the start of installation.
The LNMP script automatically installs and compiles Nginx, MySQL, PHP, phpMyAdmin, and ZendOptimizer software.
3. Installation completed
If Nginx: OK,MySQL: OK,PHP: OK is displayed
And Nginx, MySQL, PHP all exist on running,80 and 3306 ports, and Install lnmp v1.2 completes the existing it. If so, it means that the installation has been successful.
4. Installation failed
If the prompt similar to the above figure appears, it indicates that the installation failed, indicating that the installation was not successful!
Related software installation directory
Nginx home directory: / usr/local/nginx
Nginx log directory: / home/wwwlogs
Mysql: / usr/local/mysql
Mysql database: / usr/local/mysql/var/
PHP: / usr/local/php
PHPMyadmin: / home/wwwroot/default/phpmyadmin
Default website directory: / home/wwwroot/default/
Status management command
LNMP status Management: lnmp {start | stop | reload | restart | kill | status}
State management of LNMP programs: lnmp {nginx | mysql | mariadb | php-fpm | pureftpd} {start | stop | reload | restart | kill | status}
LNMP profile
1. Configuration file directory
Niginx main configuration file directory / usr/local/nginx/conf/nginx.conf
Mysql profile directory / etc/my.cnf
PHP profile directory / usr/local/php/etc/php.ini
Php-fpm configuration directory / usr/local/php/etc/php-fpm.conf
2. Detailed explanation of configuration
# vi / usr/local/nginx/conf/nginx.conf
User www www
# the program runs users and groups
Worker_processes auto
# start processes and specify the number of worker processes started by nginx. It is recommended to specify according to the number of cpu, which is generally equal to the number of cpu
Error_log / home/wwwlogs/nginx_error.log crit
# Global error Log
Pid / usr/local/nginx/logs/nginx.pid
# main process PID saves files
# Specifies the value for maximum file descriptors that can be opened by thisprocess.
Worker_rlimit_nofile 51200
# number of file descriptors
Events
{
Use epoll
# use epoll model. For kernels above 2.6, it is recommended to use epoll model to improve performance
Worker_connections 51200
# the maximum number of connections to a worker process should be adjusted according to the hardware and used in conjunction with the previous work process to be as large as possible, but do not run the cpu to 100%. The maximum number of connections allowed by each process is theoretically worker_processes*worker_connections, depending on the hardware and bandwidth of the server.
Multi_accept on
}
Http
# overall environment configuration-website configuration
{
Include mime.types
Default_type application/octet-stream
# set mime type, file transfer type mime.type file definition
Server_names_hash_bucket_size 128
# Save the hash table size of the server name
Client_header_buffer_size32k
# size of header buffer requested by client
Large_client_header_buffers 4 32k
# maximum client head buffer size
Client_max_body_size 50m
# maximum file size uploaded by the client (M)
Sendfile on
The # sendfile instruction specifies whether nginx calls the sendfile function (zero copy mode) to output the text. For ordinary applications, it must be set to on. If it is used for downloading and other application disk IO heavy-load applications, it can be set to off to balance the processing speed of disk and network Imando O and reduce the uptime of the system.
Tcp_nopush on
This is the default, the result is that the packet will not be sent immediately, and when the packet is maximum, it will be transmitted at once, which will help to solve the network congestion. (valid only on sendfile on)
Keepalive_timeout 60
# connection timeout
Tcp_nodelay on
# disable the nagle algorithm, that is, do not cache data. Effectively solve network congestion
Fastcgi_connect_timeout 300
Fastcgi_send_timeout 300
Fastcgi_read_timeout 300
Fastcgi_buffer_size 64k
Fastcgi_buffers 4 64k
Fastcgi_busy_buffers_size 128k
Fastcgi_temp_file_write_size256k
# fastcgi Settings
Gzip on
Gzip_min_length 1k
Gzip_buffers 4 16k
Gzip_http_version1.1
Gzip_comp_level2
Gzip_types text/plain application/javascript
Application/x-javascripttext/javascript text/css application/xml application/xml+rss
Gzip_varyon
Gzip_proxied expired no-cache no-store private auth
Gzip_disable "MSIE [1-6]\."
# limit_conn_zone$binary_remote_addr zone=perip:10m
# # Ifenable limit_conn_zone,add "limit_conn perip 10;" to server section.
Server_tokens off
# hide the nginx version number (curl-I 192.168.4.154 can be viewed, which is more secure
# log format
Log_format access'$remote_addr-$remote_user [$time_local]
"$request"'
'$status $body_bytes_sent "$http_referer"'
'"$http_user_agent" $http_x_forwarded_for'
# define log format
Server
{
Listen 80 default_server
# listen [::]: 80 default_server ipv6only=on
# listen on port 80. The listening settings of WEB service can be in the form of "IP address: Port".
Server_name www.lnmp.org
# server name, which can be written to multiple domain names separated by spaces
Index index.html index.htm index.php
# default web page file
Root/ home/wwwroot/default
# webpage home directory
# error_page 404 / 404.html
Includeenable-php.conf
Location / nginx_status
{
Stub_status on
Access_log off
}
# enable status status monitoring
Location ~. *\. (gif | jpg | jpeg | png | bmp | swf) $
{
Expires 30d
}
# static file processing with a retention period of 30 days
Location. *\. (js | css)? $
{
Expires 12h
}
# js and css file processing with a retention period of 12 hours
Location ~ /\.
{
Deny all
}
Access_log / home/wwwlogs/access.log access
# access the log correctly
}
Includevhost/*.conf
# Sub-configuration files take effect under vhost/
}
Check for nginx profile statement errors
/ usr/local/nginx/sbin/nginx-t
Smooth restart of the nginx process
1) pkill-HUP nginx
2) / usr/local/nginx/sbin/nginx-s reload
7. Configuration experiment
1.nginx status monitoring
Location / nginx_status {
Stub_status on
Access_log off
}
# client access URL: http://IP/nginx_status
Note: "Active connections" indicates the current number of active connections
"server accepts handled requests" indicates the connection information that has been processed
The three numbers in turn represent the number of connections processed, the number of successful TCP handshakes, and the number of requests processed
Experimental results
2.nginx virtual host
When using Nginx to build a virtual host server, each virtual WEB site has an independent "server {}" configuration segment, and its listening IP address and port number can be specified separately. Of course, the name of the website is also different.
-Domain name-based virtual host
1. Two sites www.benet.com and www.accp.com
192.168.1.1 www.benet.com
192.168.1.1 benet.com
192.168.1.1 www.accp.com
192.168.1.1 accp.com
Modify the hosts file under Linux and windows to resolve the domain name normally
two。 Set up the web page root directory for two virtual WEB hosts respectively, and prepare to test the home page
Mkdir-p / home/wwwroot/benet/
Mkdir-p / home/wwwroot/accp/
3. Modify nginx.conf configuration file-> set up domain name virtual host
Configure two "server {}" areas, corresponding to two WEB sites, and specify their respective site names, listening addresses, site root directories, access logs, and so on.
Add configuration information for two virtual hosts in the main configuration file (within the scope of http {})
Server {
Listen 80
Server_name www.benet.com benet.com
Charset utf-8
Access_log logs/benet.access.log
Location / {
Root/ home/wwwroot/benet
Index index.php index.html
}
}
Server {
Listen 80
Server_name www.accp.com accp.com
Charset utf-8
Access_log logs/accp.access.log
Location / {
Root/ home/wwwroot/accp
Index index.html index.php
}
}
4. Restart nginx and use a browser to access the two WEB sites through www.benet.com and www.accp.com, respectively
Check the correctness of the configuration file / usr/local/nginx/sbin/nginx-t
Reload the configuration file pkill-1 nginx | pkill-HUP nginx
5. Test results
Note:
Errors in checking the correctness of the configuration file
A. the comments expressed in the file must have # on every line in the capital
B. be careful not to add an extra letter when modifying the configuration file
C. sometimes the position of the wrong line may not be accurate.
3. List page display
Server
{
Listen 80
Server_name www.benet.com
Index index.html index.htm index.php
Root/ home/wwwroot/benet
Autoindex on
A. comment out the benet home page file
B. Add autoindexon in the virtual machine host configuration area corresponding to the configuration file
Save and reload the configuration file pkill-1 nginx
At this point, the web page only displays the home page directory
4.rewrite (when the website domain name is updated, use the jump feature to inform the user of the change of the domain name)
Location ~\ .php$ {
Proxy_pass http://127.0.0.1;
}
Example 1: domain name jump
Enter www.benet.com and jump to www.accp.com
Server {
Listen 80
Server_name www.benet.com benet.com
Charset utf-8
Access_log logs/benet.access.log access
Location / {
Root/ home/wwwroot/benet
Index index.php index.html
}
If ($http_host = www.benet.com) {
# determine whether the header of the domain name of the website is www.benet.com. If so, perform the following jump
# this sentence is a judgment statement, but it is not an if statement in shell, so the ending does not use a fi ending
Rewrite (. *) http://www.accp.com permanent
}
}
Note: the position where this statement is added, inside the server, outside the location
Refresh configuration file test normal jump
Example 2: file jump
Server {
Listen 80
Server_name www.accp.com accp.com
Charset utf-8
Access_log logs/benet.access.log access
Location / {
Root/ home/wwwroot/accp
Index index.html index.php
}
Rewrite inde / indexa.html last
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.