• 原创:LNMP架构部署个人博客网站 禁止转载复制


    nginx编译安装步骤

        ①. 检查软件安装的系统环境

             cat /etc/redhat-release

                  uname -r

                                     

        ②. 安装nginx的依赖包(pcre-devel openssl-devel)---假设不进行安装

            yum install -y pcre-devel openssl-devel  

             ③. 下载nginx软件---1.10.2 复制链接地址(统一位置进行下载)        

            mkdir -p /home/oldboy/tools

            cd /home/oldboy/tools

            wget -q http://nginx.org/download/nginx-1.10.3.tar.gz

                  说明:软件很小,用心查看一下

          

          ④. 编译安装软件步骤

            a. 解压要编译安装的软件(解压软件---配置(./configure)---做菜(编译 make)---上菜(安装 make install))

               tar xf nginx-1.10.2.tar.gz

    ps -ef |grep sshd

    id www   #查看用户

    uid=666(www) gid=666(www) groups=666(www)

    userdel -r www  #删除虚拟用户

    useradd www -s /sbin.nologin -M  #创建虚拟用户

    id www

               cd nginx-1.10.2

               ls (里面的内容就是源代码(config readme安装说明)---默认编译会安装到/usr/local目录)

               useradd -s /sbin/nologin -M www                                                                                    <--- 创建web服务程序www用户

               ./configure --prefix=/application/nginx-1.10.2 --user=www --group=www --with-http_stub_status_module  --with-http_ssl_module      #配置文件

    echo $?

                     (编译参数说明后续补充说明)

               make   编译

    echo $?

               make install    编译安装

                     软件编译过程中,利用返回值,判断操作是否正确

               echo $?

                cd /application/

               ln -s /application/nginx-1.10.2  /application/nginx                                  <--- 安装完成一个软件要做一个软链接

            b. 启动nginx软件程序进行测试

               /application/nginx/sbin/nginx

               lsof -i:80

    netstat -lntup|grep 80    查看80端口

               浏览器访问 10.0.0.8:80

               至此软件安装完毕:

    04:

        ③. nginx软件使用过程中疑难杂症(参考教案说明)

            · Nginx启动的疑难杂症汇总

        ④. nginx软件排查问题三部曲说明

             a 在客户端上ping服务器端IP,检查链路是否通畅

                  b 在客户端上telnet服务器端IP、端口,检查链路访问是否通畅

                  c 在客户端上wget检测模拟页面访问是否正常

    ## nginx命令说明

    # nginx 启动方法

    [root@web01 application]# /application/nginx/sbin/nginx

    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

    nginx: [emerg] still could not bind()

    [root@web01 application]#

    # nginx 停止方法

    [root@web01 application]# /application/nginx/sbin/nginx -s stop

    [root@web01 application]# ps -ef|grep nginx

    root       4283   1773  0 21:52 pts/0    00:00:00 grep --color=auto nginx

    [root@web01 application]# netstat -lntup|grep 80

    [root@web01 application]# /application/nginx/sbin/nginx

    [root@web01 application]#

    # nginx 重启方法(平滑)

    [root@web01 application]# /application/nginx/sbin/nginx -s reload

    # nginx 配置文件语法检查

    [root@web01 application]# /application/nginx/sbin/nginx -t

    nginx: the configuration file /application/nginx-1.10.3/conf/nginx.conf syntax is ok

    nginx: configuration file /application/nginx-1.10.3/conf/nginx.conf test is successful

    mysql软件

        mysql软件下载地址信息: www.mysql.com   mirrors.sohu.com

        mysql软件下载完毕后,查看mysql解压后目录文件大小

        讲解安装mysql步骤

          1) 下载解压mysql二进制软件包

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

            #解压数据库压缩包

        2) 添加mysql程序运行时的管理用户

            useradd -s /sbin/nologin  -M mysql

            #创建虚拟用户

        3) 将mysql解压后的程序包搬家到程序目录下,并进行重命名

            mkdir -p /application/

              #创建程序目录

    mv /server/tools/mysql-5.6.34-*-x86_64 /application/mysql-5.6.34

              #将程序搬迁

        4) 为mysql服务程序创建软链接

            ln -s /application/mysql-5.6.34/ /application/mysql

             #创建软连接

        5) 让mysql用户管理 /application/mysql/

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

             ## 用虚拟用户管理

        6)  初始化数据库

            #1. 确认软件安装在哪里

            #2. 确认数据存放在哪里

            #3. 确认MySQL使用的用户谁?

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

                       ==================================================================================================

                      

            下面是解释

    To start mysqld at boot time you have to copy

            support-files/mysql.server to the right place for your system

            mysql启动脚本 默认放在support-files/mysql.server 

           

            记得给MySQL设置个密码

            PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

            To do so, start the server, then issue the following commands:

            创建密码的代码

     /application/mysql/bin/mysqladmin -u root          password 'new-password'

              远程创建密码

    /application/mysql/bin/mysqladmin -u root -h web01 password 'new-password'

                       ==================================================================================================                  

        7) 复制启动脚本 授权

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

            chmod +x /etc/init.d/mysqld

        8) 修改启动脚本 和 mysql命令中的路径

            sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe /etc/init.d/mysqld

            #将默认的东西改为自己的  将后面两个配置文件的全部都`修改

        9)  复制默认的配置文件

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

          

     /etc/init.d/mysqld start                #启动

            至此,mysql数据库安装与启动完成;可以检测进程和服务端口,确认mysql服务是否启动正确

            

                        

        讲解管理mysql数据库        

        1) 进入与退出mysql数据库方法:

                 /application/mysql/bin/mysql

                 =============================================

                       扩展知识:登录数据库命令简化方法

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

            source /etc/profile

            which mysql

                 =============================================

            退出数据库时,尽量不要用ctrl+c进行退出mysql 用ctrl+d进行退出

        2) 设置mysql服务开机自启动    

            ####11.加入开机自启动

            chkconfig --add mysqld

            chkconfig mysqld on

        3) 设置mysql数据库登录用户名与密码

            ####12.给MySQL root用户设置密码

            /application/mysql/bin/mysqladmin -u root password 'oldboy123'

            mysql  -u   root -p  oldboy123

           

                       初级 添加删除系列

            #创建数据库

            create database wordpress;

            #删除数据库

            drop database wordpress;

            #############################################################################################################

    02:LNMP PHP软件安装

        讲解安装PHP步骤

        1) 解决PHP软件的依赖关系

            yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel -y

            yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel -y

            rpm -qa zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel

                #查看是否下载成功

            libiconv软件安装--和字符集转换相关的软件

          

     #mkdir -p /server/tools

            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

            make

            make install

            cd ../

           

                       和数据加密相关的三个软件安装

            #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

                      

          2) 下载解压PHP软件

    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/

    --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

            #Generating files

            #configure: creating ./config.status

            #creating main/internal_functions.c

            #creating main/internal_functions_cli.c

            #+--------------------------------------------------------------------+

            #| License:                                                           |

            #| This software is subject to the PHP License, available in this     |

            #| distribution in the file LICENSE.  By continuing this installation |

            #| process, you are bound by the terms of this license agreement.     |

            #| If you do not agree with the terms of this license, you must abort |

            #| the installation process at this point.                            |

            #+--------------------------------------------------------------------+

            #

            #Thank you for using PHP.

    make  

            make install            <- 创建目录,生成程序文件信息

                       了解FastCGI

                      

          3) PHP软件程序创建软链接

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

          4) 配置php解析文件/配置php-fpm配置文件

            #上边是开发用的 下面是运维用的

    cd /server/tools/php-5.5.32

            cp php.ini-production /application/php/lib/php.ini

                       php.ini-production 与 php.ini-development 文件区别关系对比

                       扩展:文件比较命令 diff zdiff vimdiff windows上的文件比较

            cd /application/php/etc/

            cp php-fpm.conf.default php-fpm.conf

                      

          5) 启动php-fpm程序

                 /application/php/sbin/php-fpm

        )6检查

            lsof -i :9000                    <--- 确认php 9000端口是否正确启动

            ps -ef|grep php-fpm

                      

    03:wordpress博客站点部署配置

        1) 修改nginx配置文件,使nginx程序与php程序建立联系

            vim extra/blog.conf

            server {

                    listen       80;

                    server_name  blog.etiantian.org;

                    location / {

                                root   html/blog;

                                index  index.php index.html index.htm;   <-- 需要注意编辑修改默认首页文件  index 

                    }

                    location ~* .*.(php|php5)?$ {         #主要添加下面这行

                                root html/blog;

                                fastcgi_pass  127.0.0.1:9000;

                                fastcgi_index index.php;

                                include fastcgi.conf;

                    }

            }                

                       说明:利用nginx的location区块实现动态请求与静态请求的分别处理

                      

    实例

    [root@web01 extra]# pwd

    /application/nginx/conf/extra

    [root@web01 extra]# cat blog.conf

    server {

            listen       80;

            server_name  blog.etiantian.org;

            location / {

                root   html/blog;

                index   index.php index.html index.htm;

            }

            location ~* .*.(php|php5)?$ {

                root html/blog;

                fastcgi_pass  127.0.0.1:9000;

                fastcgi_index index.php;

                include fastcgi.conf;

            }

        }

        2) 编辑nginx与php连通性测试文件,并进行测试

            echo '<?php phpinfo(); ?>'        >/application/nginx/html/blog/test_info.php   #创建测试文件

          

     测试站点

            curl  http://blog.etiantian.org/index.html            <-- 静态请求站点文件信息测试    

            curl  http://blog.etiantian.org/test_info.php         <-- 动态请求站点文件信息测试

            说明:当php服务停止时,9000端口信息消失,即停止PHP错误报502错误

                       linux系统测试完毕后,建议利用浏览器进行最终测试,测试效果更明显些

     

        3) 编辑php与mysql连通性测试文件,并进行测试

               a. 创建数据库

                          mysql   -u  root -p  oldboy123;       #进入数据库

                          show databases;                      <--- 查看当前数据库信息

                          create database wordpress;             

            

    实例        

    mysql> mysql -uroot -poldboy123;

    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql -uroot -poldboy123' at line 1

    mysql>    create database wordpress;

    Query OK, 1 row affected (0.53 sec)

                  b. 添加用户信息            

                         grant all on wordpress.* to 'wordpress'@'localhost' indentified by 'oldboy123';

                          grant all on wordpress.* to 'wordpress'@'172.16.1.%' indentified by 'oldboy123';

                          flush privileges;

                          drop user wordpress@'172.16.1.8';    <--- 删除用户信息

                          select user,host from mysql.user;    <--- 查看用户信息

                          mysql -uwordpress -p123456           <--- 测试创建的用户连接

               show databases;                      <--- 查看当前数据库信息

    实例

    mysql> show databases;

    +--------------------+

    | Database           |

    +--------------------+

    | information_schema |

    | mysql              |

    | performance_schema |

    | test               |

    | wordpress          |

    +--------------------+

    5 rows in set (0.33 sec)

    mysql> grant all on wordpress.* to 'wordpress'@'10.0.0.%' identified by 'oldboy123';

    Query OK, 0 rows affected (0.47 sec)

    mysql> select user,host from mysql.user;

    +-----------+-----------+

    | user      | host      |

    +-----------+-----------+

    | wordpress | 10.0.0.%  |

    | root      | 127.0.0.1 |

    | root      | ::1       |

    |           | localhost |

    | root      | localhost |

    |           | web01     |

    | root      | web01     |

    +-----------+-----------+

    7 rows in set (0.00 sec)

                  c. 测试php与数据库连通性

                          vim test_mysql.php

    <?php

    //$link_id=mysql_connect('主机名','用户','密码');

    //mysql -u用户 -p密码 -h 主机

    $link_id=mysql_connect('localhost','wordpress','oldboy123') or mysql_error();

    if($link_id){

                 echo "mysql successful by oldboy ! ";

                }else{

                 echo mysql_error();

                }

    ?>

    curl blog.etiantian.org/test_mysql.php       <-- 测试php与数据库的连通性

                      

        4) 下载部署wordpress博客程序(https://cn.wordpress.org/   英文官网:https://www.wordpress.org/ )   

                       wget https://cn.wordpress.org/wordpress-4.5.1-zh_CN.tar.gz

            tar xf wordpress-4.5.1-zh_CN.tar.gz

            mv wordpress/* /application/nginx/html/blog/

            chown -R www.www /application/nginx/html/blog/

                       注意:确认hosts文件进行了解析

                       浏览器页面进行wordpress部署          

                       vim wp-config.php  可以修改wordpress上的数据库连接参数信息

                      

    04:wordpress博客站点数据库迁移

        迁移数据库:利用数据库备份命令

        1) 备份数据库数据库信息

            mysqldump -uroot -poldboy123 --all-databases >/tmp/bak.sql

            ll /tmp/bak.sql -h

            scp /tmp/bak.sql 172.16.1.51:/tmp/

        2) 恢复数据库数据库信息                  

            ##db01

            mysql -uroot -poldboy123 </tmp/bak.sql

            ###db01添加新的用户

            grant all on wordpress.* to wordpress@'172.16.1.0/255.255.255.0' identified by 'oldboy123';

            flush privileges;

            mysql -uwordpress -poldboy123 -h 172.16.1.51

        3) 数据库迁移完毕,修改网站连接数据库的配置文件

            mysql -uwordpress -poldboy123 -h 172.16.1.51       <-- 修改配置文件之前,先测试网站web服务器与迁移后的数据库连通性    

                       vim wp-config.php                                  <-- 修改wordpress上的数据库连接参数信息

                       /** MySQL主机 */

                       define('DB_HOST','172.16.1.51')                    <-- 修改连接的主机信息,将localhost修改为172.16.1.51

                       说明:web服务器数据库此时可以关闭了

                      

    05. 进行数据迁移到NFS共享服务器

        01:先将原有目录中数据移出

            cd /application/nginx/html/blog/wp-content/uploads

            mkdir /tmp/wordpress_backup -p

            mv ./* /tmp/wordpress_backup/

       

        02:NFS服务器上配置创建共享目录

            vim /etc/exports

            /data 172.16.1.0/24(rw,sync,all_squash)

            showmount -e 172.16.1.31

            mount -t nfs 172.16.1.31:/data /mnt/

           

            showmount -e 172.16.1.31

            mount -t nfs 172.16.1.31:/data/ ./uploads/

            mv /tmp/wordpress_backup/* ./

     

  • 相关阅读:
    java 编码问题
    关于时间
    页面
    关于微信
    01-jQuery的介绍
    15-BOM
    14-定时器
    13-JS中的面向对象
    12-关于DOM操作的相关案例
    购物车练习
  • 原文地址:https://www.cnblogs.com/dsab/p/7518299.html
Copyright © 2020-2023  润新知