• 动静分离LNMP


    目录

    安装LNMP

    搭建wordpress

    搭建WeCenter


            根据需求实现动静分离,当客户端访问nginx网站服务时,静态网页nginx本机反馈,动态网页访问PHP,所以需要在nginx服务器中部署论坛后需要拷贝到PHP服务器中。但是如果有NFS或GFS服务器时可以把nginx和php指定文件服务器。

     

    安装LNMP

    • 安装nginx 

            所需安装包如下:

     

            安装并启动:

    1. [root@nginx ~]# rpm -ivh /media/nginx-rpm/*.rpm --nodeps --force
    2. [root@nginx ~]# systemctl start nginx
    3. [root@nginx ~]# systemctl enable nginx
    4. Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
    • 安装php 

            所需安装包如下:

     

             安装并启动:

    1. [root@nginx ~]# rpm -ivh /media/php-rpm/*.rpm --nodeps --force
    2. [root@nginx ~]# systemctl start php-fpm
    3. [root@nginx ~]# systemctl enable php-fpm
    4. Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
    • 安装mysql(mariadb)

            所需安装包如下:

     

            安装mysql并启动

    1. [root@nginx ~]# rpm -ivh /media/mysql5.6-rpm/*.rpm --nodeps --force
    2. [root@nginx ~]# systemctl start mysqld
    3. [root@nginx ~]# systemctl enable mysqld
    4. 创建mysql密码
    5. [root@nginx ~]# mysqladmin -uroot password
    6. New password: //输入新密码
    7. Confirm new password: //再次输入新密码

    应用安装

            本次php可以搭建两个应用wordpress和wecenter,两个app搭建一个论坛即可。如搭建两个app需要测试机本地解析域名,通过域名访问虚拟主机

    搭建wordpress

    注意:下面操作注意看服务器名称。

            1. php服务器下载并解压wordpree包到/下并解压授权。

    1. [root@php ~]# cp -rp /media/wordpress-4.9.4-zh_CN.zip /
    2. [root@php ~]# cd /
    3. [root@php /]# unzip wordpress-4.9.4-zh_CN.zip
    4. [root@php /]# chmod -R 777 /wordpress

            2.nginx服务器创建虚拟主机配置文件

    1. [root@nginx /]# vim /etc/nginx/conf.d/blog.conf
    2. server {
    3.         listen 80;
    4.         server_name www.blog.com;
    5.         root /wordpress;
    6.         index index.php index.html;
    7.         location ~ \.php$ {
    8.                         root /wordpress;
    9.                         fastcgi_pass 192.168.1.6:9000; //指定php服务器IP
    10.                         fastcgi_index index.php;                        
    11. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    12.                 include fastcgi_params;
    13.                 }
    14.         }
    15. [root@nginx /]# nginx -t
    16. nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    17. nginx: configuration file /etc/nginx/nginx.conf test is successful
    18. [root@nginx /]# systemctl restart nginx

            3.mysql服务器创建blog数据库和管理用户

    1. [root@mysql ~]# mysql -uroot -p123
    2. //省略部分内容
    3. mysql> create database blog;
    4. Query OK, 1 row affected (0.00 sec)
    5. mysql> grant all on blog.* to lisi@'%' identified by '123456';
    6. Query OK, 0 rows affected (0.00 sec)
    7. mysql> exit
    8. Bye

            4.PHP服务器修改配置文件后把PHP服务器中的/wordpress文件复制到nginx服务器中。

    1. [root@php ~]# vim /wordpress/wp-config-sample.php
    2. /** WordPress数据库的名称 */
    3. define('DB_NAME', 'blog');
    4. /** MySQL数据库用户名 */
    5. define('DB_USER', 'lisi');
    6. /** MySQL数据库密码 */
    7. define('DB_PASSWORD', '123456');
    8. /** MySQL主机 */
    9. define('DB_HOST', '192.168.1.5');
    10. [root@php /]# cd /wordpress/
    11. [root@php wordpress]# mv wp-config-sample.php wp-config.php 
    12. [root@php wordpress]# scp -rp /wordpress root@192.168.1.4:/
    13. [root@php ~]# vim /etc/php-fpm.d/www.conf  //修改下面两行内容
    14. listen = 192.168.1.6:9000 //PHP服务器IP
    15. listen.allowed_clients = 192.168.1.4 //web服务器IP,表示允许web主机访问php服务器
    16. [root@php ~]# systemctl restart php-fpm

            5.通过客户端服务器验证

    注意下面使用测试机1.10访问。

            因为只搭建了第一个app,所以直接访问IP即可,如多个app需要通过修改本机hosts文件或者搭建DNS访问 。http://192.168.1.4,后台网址为http://192.168.1.4/wp-admin。根据下图点击(现在就开始!)。

     

            创建站点标题,用户名密码后点击安装。

            登录管理用户密码后即进入账户首页,根据自己需求添加或修改即可。

     

    搭建WeCenter

            1.安装

    1. [root@php ~]# mkdir /zh
    2. [root@php ~]# cp -rp /media/WeCenter_3-3-4.zip /zh
    3. [root@php ~]# cd /zh
    4. [root@php zh]# unzip WeCenter_3-3-4.zip
    5. [root@php zh]# chmod -R 777 /zh

            2.nginx服务器创建虚拟主机配置文件

    1. [root@nginx ~]# vim /etc/nginx/conf.d/zh.conf
    2. server {
    3.         listen 80;
    4.         server_name www.zh.com;
    5.         root /zh;
    6.         index index.php index.html;
    7.         location ~ \.php$ {
    8.                 root /zh;                fastcgi_pass 192.168.1.6:9000;
    9.                 fastcgi_index index.php;
    10.                 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    11.                 include fastcgi_params;
    12.                 }
    13.         }
    14. [root@nginx ~]# nginx -t
    15. nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    16. nginx: configuration file /etc/nginx/nginx.conf test is successful
    17. [root@nginx ~]# systemctl restart nginx

            3.mysql服务器创建zh数据库和管理用户

    1. mysql> create database zh;
    2. Query OK, 1 row affected (0.00 sec)
    3. mysql> grant all on zh.* to zh@'%' identified by '123456';
    4. Query OK, 0 rows affected (0.00 sec)
    5.         4.PHP服务器修改配置文件后把PHP服务器中的/zh文件复制到nginx服务器中。
    6. [root@php ~]# cd /zh/system/config/
    7. [root@php config]# mv system.php databaes.php
    8. [root@php config]# vim databaes.php  //添加下面文档
    9. $config['charset'] = 'utf8mb4';^M
    10. $config['prefix'] = 'aws_';^M
    11. $config['driver'] = 'MySQLi';^M
    12. $config['master'] = array (
    13.   'charset' => 'utf8mb4',
    14.   'host' => '192.168.1.5', //数据库主机IP
    15.   'username' => 'zh', //用户名
    16.   'password' => '123456', //用户密码
    17.   'dbname' => 'zh', //数据库名称
    18. );^M
    19. $config['slave'] = false;^M
    20. [root@php config]# systemctl restart php-fpm
    21. [root@php config]# scp -rp /zh root@192.168.1.4:/

            5.验证

            访问http://www.zh.com查看配置无误后点击下一步,输入{数据库主机,账号,密码,名称}后点击开始安装。

            新建管理员用户密码,输入邮箱号后点击完成。

  • 相关阅读:
    算法训练day41|动态规划 part03(LeetCode343. 整数拆分、96.不同的二叉搜索树)
    JSP语法①——JSP筑基
    爬取基金收盘价并用pyecharts进行展现
    浅谈Foxmail邮件迁移
    Docker(三)-Docker常用命令
    2022编译原理期末考试 回忆版
    C语言学生宿舍水电费信息管理系统
    AOF是什么?
    掌动智能云网络流量分析的重要性
    汉字转拼音
  • 原文地址:https://blog.csdn.net/qq_61116007/article/details/128045048