LNMP cluster architecture articles

                  LNMP simple deployment architecture introduces articles

Introduce a .LNMP

1 the distal end and back-end web services series storage services

2. The main process to achieve dynamic request php

working principle:

L:linux  N:nginx  M:mysql   P:php

Two, lnmp deployment

My environment: centos6.9 + nginx + mysql5.6 + php5 NFS file storage system

1. Installation linux deployment system (not presented here)

  To complete the basic optimization operation (turn off the firewall, turn off selinuxn the / tmp directory permissions set to 1777)

2. Deploy nginx service

  Here ignore ...................

3. Install the deployment mysql

  Three methods of installation: yum deploy, compile and install the source code, binary package installation

  This method describes the binary installation:

  The first mileage: Download and extract the installation package mysql

    mysql official download link address: ftp://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-5.6/

    Upload mysql software program, carried out using the software to upload xftp

    tar xf mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz

    mv mysql-5.6.34-linux-glibc2.5-x86_64 /application/mysql-5.6.34 (my installation directory / application / mysql you pick)

  Second mileage: Create a soft link program

    ln -sf /application/mysql-5.6.34/ /application/mysql

  Third mileage: Create a database user management and authorization to data directory

    useradd -s mysql /sbin/nologin -M

    chown -R mysql.mysql /application/mysql/data/

  Fourth mileage: initialize the database service

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

  Fifth mileage: Start mysql service

  

/application/mysql/support-files/mysql.server /etc/init.d/ CP mysqld 

Sed -ri ' S # / usr / local # / file application # G ' /etc/init.d/mysqld / file application / MySQL / bin / mysqld_safe (the default path into your own installation directory) 

cp /application/mysql/support-files/my-default.cnf / etc / my.cnf

 /etc/init.d/mysqld Start

 

  The sixth mileage: Set the root user password database

    / Application / mysql / bin / mysqladmin -uroot password "password =="

    / Application / mysql / bin / mysql -uroot -poldboy123 (too hard to knock up their own soft link)

4. PHP installation and deployment

  The first mileage: dependency resolution PHP software 

    -y install zlib-devel yum libxml2-devel-Turbo libjpeg libjpeg-devel-devel libiconv FreeType-devel libpng-devel-devel gd-devel libcurl-devel libxslt- devel 

    libiconv software installation --- character set conversion library (default may not installing a) 

    cd / Server / Tools 

     # wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz 

    tar zxf libiconv -1.14.tar. GZ 

    cd libiconv -1.14 

    ./configure = --prefix / usr / local / libiconv 

    the make && the make install 

    If yum installed, note yum update source at 

    # wget -O /etc/yum.repos.d/epel.repo          
           HTTP: //mirrors.aliyun.com/repo/epel-6.repo

    yum -y install libmcrypt-devel mhash mcrypt

    rpm -qa libmcrypt-devel mhash mcrypt

 

 

  Second mileage: PHP unzip software download

    php官方网站下载:php.net

     cd /server/tools/

    tar xf php-5.5.32.tar.gz

    cd php-5.5.32

    ./configure \
    --prefix=/application/php-5.5.32 \
    --with-mysql=/application/mysql-5.6.34 \
    --with-pdo-mysql=mysqlnd \
    --with-iconv-dir=/usr/local/libiconv \
    --with-freetype-dir \
    --with-jpeg-dir \
    --with-png-dir \
    --with-zlib \
    --with-libxml-dir=/usr \
    --enable-xml \
    --disable-rpath \
    --enable-bcmath \
    --enable-shmop \
    --enable-sysvsem \
    --enable-inline-optimization \
    --with-curl \
    --enable-mbregex \
    --enable-fpm \
    --enable-mbstring \
    --with-mcrypt \
    --with-gd \
    --enable-gd-native-ttf \
    --with-openssl \
    --with-mhash \
    --enable-pcntl \
    --enable-sockets \
    --with-xmlrpc \
    --enable-soap \
    --enable-short-tags \
    --enable-static \
    --with-xsl \
    --with-fpm-user=www \
    --with-fpm-group=www \
    --enable-ftp \
    --enable-opcache=no

    ##为了防错(配置下以下信息)

    ln -s /application/mysql/lib/libmysqlclient.so.18  /usr/lib64/

    touch ext/phar/phar.phar

    #编译安装

    make && make install

    ln -s /application/php-5.5.32/ /application/php

 

   Third mileage: Setting PHP configuration file

    php.ini php-fpm.ini
    cp php.ini-production /application/php-5.5.32/lib/
    cd /application/php/etc/
    cp php-fpm.conf.default php-fpm.con

 

  Fourth mileage: Start php Service

    /application/php/sbin/php-fpm
    netstat -lntup|grep php

 

5.php software in conjunction with mysql and nginx

5.1, and binding mysql

  Write .php file

  

? < PHP
     // $ link_id = mysql_connect ( 'hostname', 'user', 'password'); 
    // MySQL password -h host -u user -p 
    $ link_id = mysql_connect ( 'localhost', 'root', ' oldboy123 ') or mysql_error ();
     IF ( $ link_id ) {
                  echo "MySQL successful by Oldboy \ n-!" ; 
                } the else {
                  echo  mysql_error (); 
                }
 >?

 

5.2, php combined with nginx

  Nginx configuration file written nginx.conf

nginx and php combine: preparation of nginx configuration file LOCATION 
       LOCATION .. ~ * * \ (php | php5) $ {? 
          fastcgi_pass   127.0.0.1:9000 ; #php service default port 9000 
          fastcgi_index index.php; 
          the include fastcgi.conf; 
       }

 

  

6, the deployment of a website

  The first mileage: download and upload website code

  Second mileage: decompression program code, the program will save the code to the site directory and nginx authorization

  E.g:

       tar xf wordpress-4.7.3-zh_CN.tar.gz 
       mv wordpress/* /application/nginx/html/blog/
       chown -R www.www /application/nginx/html/blog/

 

 

 

   Third mileage: direct access to the website, initialize operation

    Create a database:

    create database 

    Create a user connection data information

     grant all on wordpress.* to '用户名'@'localhost' identified by '密码'; 

     select user,host from mysql.user;  

 

7. LNMP architecture, data migration

   In the production environment, we finally need to migrate data to back-end storage server, the separation of static and dynamic resources

   Here a brief Ha! ! !

  01. LNMP database schema migration services

   Migrating database: use the database backup command (mysql mysqladmin mysqldump)

   1) backup database database information   

For example: 
the mysqldump -uroot--p-Databases password --all> / tmp / bak.sql 
LL /tmp/bak.sql - H 
SCP /tmp/bak.sql 172.16 . 1.51 : / tmp / # pushed to a remote database server

 

   2) restore the database information database   

-poldboy123-uroot-MySQL </ tmp / bak.sql 
### DB01 add a new user 
Grant All ON WordPress. * to username @ ' 172.16.1.0/255.255.255.0 ' IDENTIFIED by ' password ' ; 
flush privileges; 
MySQL - -poldboy123 -h uwordpress 172.16 . 1.51

  3) database migration is complete, modify the configuration file of the site database connection

    I am here for the php program to connect the database configuration file

MySQL -u user name -p password -h 172.16.1.51 <- before modifying the configuration file, test the database connectivity web site after the server migration     
vim WP <-config.php - database connection parameters on the modification information wordpress
 / * * the MySQL host * / 
 DEFINE ( 'DB_HOST', '172.16.1.51') <- modify connection host information, to modify the localhost 172.16.1.51 
 Description: web server database can now be closed

 

  4) Stop the MySQL server nginx service  

 /etc/init.d/mysql stop

 

 

  02. LNMP data architecture migration to NFS storage instructions

    01: first data out of the original directory

cd / the Application / nginx / HTML / Blog / WP-Content / uploads # file path resources at my site directory 
mkdir / tmp / wordpress_backup - the p- 
mv . / * / tmp / wordpress_backup /

 

  note:

    What location data stored locally, acquisition method
    ①. Web page by right-clicking, access to resources address information
    ②. Find command using the 5 -mmin
    ③. Using the directory data service monitoring changes inotify

  02: configuration creates a shared directory on the NFS server

  

Vim / etc / Exports
 / Data 172.16.1.0/24(rw,sync, the all_squash) 
the showmount -e 172.16.1.31 
Mount -t 172.16.1.31:/data NFS / mnt / # on the web server         
the showmount -e 172.16.1.31 
Mount nfs 172.16.1.31:/data/ ./uploads/ -t # the nfs shared directory on the server to mount local 
 mv / tmp / wordpress_backup / * ./ # restore the backup of the data before

 

Guess you like

Origin www.cnblogs.com/xh-0205/p/11127641.html