Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Enterprise LAMP environment application-mysql

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Chapter 1 Enterprise LAMP Environment Application 1.1 LNMP Application Environment

Before 2010, the classic web service environment combination most commonly used by Internet companies is LAMP (that is, Linux,apache,mysql,PHP). In recent years, with the gradual popularity of Nginx web services, there has been a new web service environment combination-LNMP or LEMP, in which LNMP is the initials such as Linux,nginx,Mysql,PHP, while E in LEMP indicates that Nginx,LNMP has gradually become the mainstream combination environment for the websites of large and medium-sized Internet companies in China.

1.1.1 introduction to LNMP

LNMP represents the web server architecture of Nginx+MySQL+PHP under the Linux system. Nginx is a high-performance HTTP and reverse proxy server, as well as an IMAP/POP3/SMTP proxy server. Mysql is a small relational database management system. PHP is a scripting language that embeds HTML documents executed on the server side. These four kinds of software are all free and open source software, which are combined into a free, efficient and scalable website service system.

1.1.2 advantages of LNMP:

1. As a Web server: it uses fewer resources, supports more concurrent connections and is more efficient than Apache,Nginx.

two。 As a load balancing server: Nginx can not only directly support Rails and PHP internally, but also support external services as a HTTP proxy server. Nginx is written in C, both in terms of system resource overhead and CPU use efficiency is much better than Perlbal.

3. As a mail proxy server: Nginx is also an excellent mail proxy server (one of the earliest purposes of developing this product is also as a mail proxy server), Last/fm describes the successful and wonderful experience.

4.Nginx installation is very simple: the configuration file is very concise (it can also support perl syntax). Nginx supports smooth loading of new configurations and the ability to upgrade software versions with uninterrupted service.

1.1.3 LNMP composite workflow

When the LNMP composition works, the user first enters the domain name through the browser to request the Nginx web service. If the request is static, the Nginx resolution is returned to the user. If it is a dynamic request (ending with .php), it will be sent to the PHP engine service (fastCGI process php-fpm) through the fastCGI interface (common production method) for parsing. If the dynamic request wants to read the database data, then PHP will continue to request the MYSQL database backward, read the required data, and finally return the obtained data to the user through the Nginx service, which is the basic request sequence flow of the LNMP environment.

1.1.4 introduction to CGI

The earliest Web server simply responded to the HTTP request from the browser and returned the HTML file stored on the server to the browser, that is, static html. Things are always developing, and websites are becoming more and more complex, so dynamic technology appears. But the server cannot directly run files like php,asp, so you can't do it yourself, so outsource it to someone else, but you have to make an agreement with the third, what I give you, and then what you give me, that is, I send the request parameters to you, and then I receive your processing results to the client. Then the agreement is common gateway interface, or cgi for short. This protocol can be implemented in vb,c,php,python. Cgi is just an interface protocol, not a language at all.

According to the type of CGI program, the WEB server will decide how to transfer data to CGI program, generally speaking, it will transfer data to and from CGI program through standard input / output stream and environment variables.

How CGI works: whenever a customer requests CGI, the WEB server requests the operating system to generate a new CGI interpreter process (such as php-cgi.exe), one process of CGI quits after processing one request, and creates a new process when the next request comes. Of course, this is fine when the traffic is small and there is no concurrency. However, when the number of visitors increases and concurrency exists, this method is not suitable. So there is fastcgi.

1.1.5 introduction to FASTCGI

A protocol for communication between FASTCGI:WEB servers and processors, which is an improvement of CGI. Repeated loading of CGI programs is the main reason for the poor performance of CGI. If CGI programs remain in memory and accept FastCGI process manager scheduling, it can provide good performance, scalability, Fail-Over characteristics and so on.

FASTCGI is a resident CGI that runs all the time and does not take time to fork a process when the request arrives. FastCGI is a language-independent, scalable CGI open extension that keeps the CGI interpreter process in memory for high performance

1.2 principle Analysis of the whole workflow of 1.2.1 FastCGI

In general, the entire workflow of FastCGI is as follows:

1. Load the FastCGI process Manager (IIS ISAPI or Apache Module) when Web Server starts

2. The FastCGI process manager initializes itself, starts multiple CGI interpreter processes (see multiple php-cgi) and waits for the WebServer connection.

3. When the client request arrives at Web Server, the FastCGI process manager selects and connects to a CGI interpreter. Web server sends CGI environment variables and standard input to the FastCGI child process php-cgi.

4. The FastCGI child process returns the standard output and error information from the same connection to Web Server after processing. When the FastCGI child process closes the connection, the request is processed. The FastCGI child process then waits and processes the next connection from the FastCGI process manager (running in Web Server). In CGI mode, php-cgi exits here.

Chapter 2 introduction to the database of LNMP MYSQL2.1 MYSQL database

Mysql is a very important and popular open source relational database software in the Internet field, which is developed and maintained by the Swedish company mysql AB. In 2006, mysql AB was acquired by SUN, and in 2008, SUN was acquired by oracle, the leader in the traditional database field, so mysql database currently belongs to oracle, but it is still open source.

Mysql is a kind of relational database management software. the characteristic of relational database is to save the data in different two-bit tables and put these tables into different databases, instead of putting all the data into a large warehouse. This design increases the reading speed, flexibility and manageability of MYSQL.

2.2 LNMP MySQL database installation (binary package installation)

Mysql software download address information: www.mysql.com mirrors.sohu.com

After downloading the mysql software, check the directory file size after mysql is decompressed

Serial number

Mysql installation mode

Characteristic description

one

Yum/rpm package installation

It is characterized by simplicity and high speed, but it is impossible to customize the installation. Beginners often use this method.

two

Binary installation

Decompression software, simple configuration can be used, no installation, faster, professional DBA like this way.

three

Source code compilation and installation

The feature is that the installation can be customized, but it takes a long time to install, such as: character set installation path

four

Source software combined with yum/rpm installation

Make the source software into a rpm that meets the requirements, put it in the yum warehouse, and then install it through yum. The advantage is that the installation is fast and the parameters can be set arbitrarily, but the installer needs to have deeper capabilities.

2.2.1 download the mysql binary package

[root@web02 tools] # rz-E

Rz waiting to receive.

[root@web02 tools] # ls

Mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz

Nginx-1.10.2

Nginx-1.10.2.tar.gz

[root@web02 tools] # tar xf mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz

[root@web02 tools] # ls

Mysql-5.6.34-linux-glibc2.5-x86_64 nginx-1.10.2

Mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz nginx-1.10.2.tar.gz

[root@web02tools] # cdmysql-5.6.34-linux-glibc2.5-x86_64

[root@web02mysql-5.6.34-linux-glibc2.5-x86_64] # ll-hi

Total 68K

663049 drwxr-xr-x 2 root root 4.0K May 22 09:56 bin

663186-rw-r--r-- 1 7161 31415 18K Sep 30 2016 COPYING

800440 drwxr-xr-x 3 root root 4.0K May 22 09:57data

800443 drwxr-xr-x 2 root root 4.0K May 22 09:57docs

800533 drwxr-xr-x 3 root root 4.0K May 22 09:57include

663139 drwxr-xr-x 3 root root 4.0K May 22 09:57 lib

790581 drwxr-xr-x 4 root root 4.0K May 22 09:56 man

790632 drwxr-xr-x 10 root root 4.0K May 22 09:57 mysql-test

663138-rw-r--r-- 1 7161 31415 2.5K Sep 30 2016README

800431 drwxr-xr-x 2 root root 4.0K May 22 09:57scripts

663095 drwxr-xr-x 28 root root 4.0K May 22 09:56 share

800447 drwxr-xr-x 4 root root 4.0K May 22 09:57sql-bench

800433 drwxr-xr-x 2 root root 4.0K May 22 09:57support-files

[root@web02 mysql-5.6.34-linux-glibc2.5-x86_64] # cd..

[root@web02 tools] # ls

Mysql-5.6.34-linux-glibc2.5-x86_64 nginx-1.10.2

Mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz nginx-1.10.2.tar.gz

[root@web02 tools] # du-sh mysql-5.6.34-linux-glibc2.5-x86_64

1.1G mysql-5.6.34-linux-glibc2.5-x86_64

2.2.2 move the extracted mysql package to the program directory and rename it

[root@web02 tools] # mv mysql-5.6.34-linux-glibc2.5-x86_64/application/mysql-5.6.34

2.2.3 create a soft link for mysql

[root@web02 tools] # ln-s / application/mysql-5.6.34//application/mysql

[root@web02 tools] # cd / application/

[root@web02 application] # ls

Mysql mysql-5.6.34 nginx nginx-1.10.2

[root@web02 application] # ll

Total 8

Lrwxrwxrwx 1root root 26 May 22 10:01 mysql- > / application/mysql-5.6.34/

Drwxr-xr-x 13 root root 4096 May 22 09:57mysql-5.6.34

Lrwxrwxrwx 1root root 25 May 19 08:52 nginx- > / application/nginx-1.10.2

Drwxr-xr-x 11 root root 4096 May 19 12:59nginx-1.10.2

2.2.4 add administrative users while the mysql program is running and authorize

Useradd-s / sbin/nologin-M mysql

Chown-R mysql.mysql / application/mysql

2.2.5 initialize the database

/ application/mysql/scripts/mysql_install_db--basedir=/application/mysql-datadir=/application/mysql/data/-user=mysql

2.2.6 replication startup script authorization

[root@web02 application] # cp / application/mysql/support-files/mysql.server/etc/init.d/mysqld # # put the daemon file in the startup file, in the daemon way

[root@web02 application] #

[root@web02 application] # ll / etc/init.d/mysqld

-rwxr-xr-x 1 root root 10875 May 22 10:13/etc/init.d/mysqld

[root@web02 application] # chmod + x / etc/init.d/mysqld

2.2.7 modify paths in startup scripts and mysql commands

[root@web02 application] # ll / etc/init.d/mysqld

-rwxr-xr-x 1 root root 10875 May 22 10:13/etc/init.d/mysqld

[root@web02 application] # sed-I 's#/usr/local/mysql#/application/mysql#g'/application/mysql/bin/mysqld_safe / etc/init.d/mysqld

Note: the replaced application is the installation path. If the installation path is not in application, it should be replaced with the installation path name.

[root@web02 application] #

2.2.8 copy the default configuration file to start mysql

[root@web02 application] # cp / application/mysql/support-files/my-default.cnf/etc/my.cnf

Cp: overwrite `/ etc/my.cnf'? Y

[root@web02 application] #

[root@web02application] # / etc/init.d/mysqld start

Starting MySQL... SUCCESS!

2.3Managing mysql database 2.3.1 logging in and logging out of mysql

[root@web02 application] # / application/mysql/bin/mysql-uroot

Mysql > exit

Bye

Or ctrl+d.

Optimize the login process

Echo 'export PATH=/application/mysql/bin:$PATH' > > / etc/profile

Source / etc/profile

Which mysql

2.3.2 set login password and log in

[root@web02 application] # mysqladmin-u root password "oldboy123"

Warning: Using a password on the command lineinterface can be insecure.

[root@web02 application] #

[root@web02 application] # mysql-uroot-poldboy123 # Note-p cannot be followed by a space.

2.3.3 set the mysql service to boot automatically

# 11. Join the boot self-boot

Chkconfig-add mysqld

Chkconfig mysqld on

2.3.4 basic database commands

Show databases

Mysql > select database ()

+-+

| | database () |

+-+

| | mysql |

+-+

1 row in set (0.00 sec)

Mysql >

2.5.4 View which user logs in to the database

Mysql > select user ()

+-+

| | user () |

+-+

| | root@localhost |

+-+

1 row in set (0.00 sec)

Mysql >

Mysql > select user,host from mysql.user

+-+ +

| | user | host |

+-+ +

| | root | 127.0.0.1 | |

| | root |:: 1 |

| | localhost |

| | root | localhost |

| | web02 |

| | root | web02 |

+-+ +

6 rows in set (0.00 sec)

Mysql >

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report