Linux——分离部署,分化压力

news2024/9/27 5:55:00

PQS/TPS  每秒请求数/ 每秒事务数     // 流量衡量参数

可以根据预估QPS 和 服务器的支持的最高QPS 对照计算 就可以得出 需要上架的服务器的最小数量

PV 页面浏览数    UV 独立用户访问量     // 对于网站的总体访问量

response time   响应时间      // 每个请求的响应时间     

lnmp 分离部署 分化压力

nginx - 一个节点  192.168.110.133

php 一个节点 192.168.110.138

db 一个节点 192.168.110.22

实验topo

实验过程

nginx节点:

[root@nginx ~]# dnf  -y install nginx 
[root@nginx ~]# systemctl enable nginx.service 
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
[root@nginx ~]# systemctl status firewalld.service 
● firewalld.service - firewalld - dynamic firewall daemon
     Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; preset: enabled)
     Active: active (running) since Tue 2024-09-10 09:12:37 CST; 2h 34min ago
       Docs: man:firewalld(1)
   Main PID: 924 (firewalld)
      Tasks: 2 (limit: 24434)
     Memory: 42.1M
        CPU: 1.275s
     CGroup: /system.slice/firewalld.service
             └─924 /usr/bin/python3 -s /usr/sbin/firewalld --nofork --nopid

Sep 10 09:12:36 localhost systemd[1]: Starting firewalld - dynamic firewall daemon...
Sep 10 09:12:37 localhost systemd[1]: Started firewalld - dynamic firewall daemon.
[root@nginx ~]# systemctl stop firewalld.service 
[root@nginx ~]# setenforce 0
[root@nginx ~]# vim /etc/exports 
/usr/share/nginx/html *(rw)
[root@nginx ~]# cat /usr/share/nginx/html/index.php 
<?php
phpinfo();
?>
[root@nginx ~]# yum -y install nfs-utils
[root@nginx ~]# systemctl start nfs-server

php:

php:
[root@php ~]# dnf -y install php php-fpm 
[root@php ~]# systemctl stop firewalld.service 
[root@php ~]# setenforce 0
[root@php ~]# systemctl start php-fpm 
[root@php ~]# dnf -y install nfs-utils
root@php ~]# showmount -e 192.168.110.133
Export list for 192.168.110.133:
/usr/share/nginx/html *
[root@php ~]# mkdir -p /usr/local/nginx/html
[root@php ~]# chown apache -R /usr/share/nginx
[root@php ~]# mount 192.168.110.133:/usr/share/nginx/html /usr/share/nginx/html/
[root@php ~]# vim /etc/php-fpm.d/www.conf

// 修改php-fpm 监听本地与nginx同一网段的IPv4地址和9000端口

// 如果只写9000 代表监听所有地址的9000端口

// 允许访问的地址列表中添加nginx的ip地址

[root@php ~]# systemctl start php-fpm.service

返回nginx节点,进行动静分离的配置:

[root@nginx ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@nginx ~]# systemctl reload nginx.service 

验证nginx转发php脚本给php-fpm 节点解析
[root@nginx ~]# curl -I 127.0.0.1/index.php
HTTP/1.1 200 OK
Server: nginx/1.20.1
Date: Tue, 10 Sep 2024 05:49:32 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/8.0.30

如果访问出现问题,结合日志进行排错。

nginx 访问日志: /var/log/nginx/access.log

错误日志:/var/log/nginx/error.log

php-fpm  日志: /var/log/php-fpm/error.log

配置php连接数据库

[root@db-mariadb ~]# dnf -y install mariadb mariadb-server
[root@db-mariadb ~]# systemctl stop firewalld.service 
[root@db-mariadb ~]# setenforce 0
[root@db-mariadb ~]# systemctl start mariadb.service 
[root@db-mariadb ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.5.22-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> set password=password('redhat');
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> exit
Bye
[root@db-mariadb ~]# ss -anput | grep mysql
[root@db-mariadb ~]# ss -anput | grep mariadb
tcp   LISTEN 0      80                  *:3306                *:*     users:(("mariadbd",pid=35118,fd=19))                 
[root@db-mariadb ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.5.22-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> select user,host from mysql.user;
+-------------+-----------+
| User        | Host      |
+-------------+-----------+
| mariadb.sys | localhost |
| mysql       | localhost |
| root        | localhost |
+-------------+-----------+
3 rows in set (0.002 sec)

MariaDB [(none)]> grant all on *.* to root@192.168.110.138 identified by 'redhat';
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> select user,host from mysql.user;
+-------------+-----------------+
| User        | Host            |
+-------------+-----------------+
| root        | 192.168.110.138 |
| mariadb.sys | localhost       |
| mysql       | localhost       |
| root        | localhost       |
+-------------+-----------------+
4 rows in set (0.001 sec)

MariaDB [(none)]> 

在php上安装php-mysqlnd 模块,并验证可以连接数据库

[root@php ~]# dnf -y install mariadb
[root@php ~]# mysql -h 192.168.110.22 -u root -predhat
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 10.5.22-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> exit
Bye
[root@php ~]# dnf -y install php-mysqlnd

 切换到nginx 节点上,添加php连接数据库的脚本程序文件

[root@nginx ~]# cat /usr/share/nginx/html/db.php 
<?php
//创建连接
$servername = "192.168.110.22";
$username = "root";
$passwd = "redhat";
 
//检测连接
$conn = mysqli_connect($servername,$username,$passwd);
 
if(!$conn){
    die("connection failed:" . mysqli_connect_errno());
}else{
    echo "成功连接数据库";
    mysqli_close($conn);
}
?>

在php节点查看文件是否同步,已经能否运行该脚本程序

[root@php ~]# ls /usr/share/nginx/html/db.php 
/usr/share/nginx/html/db.php
[root@php ~]# php /usr/share/nginx/html/db.php 
成功连接数据库

通过浏览器验证访问

[root@nginx ~]# curl 192.168.110.133/db.php
成功连接数据库

如果是lnamp 一般采用为apache 服务器前设置代理服务实现动静分离,apache 主要处理动态请求。

在对nginx 、 php 还有数据库 进行水平扩展时,应该怎么做?

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2125865.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

828华为云征文 | Flexus X实例与Harbor私有镜像仓库的完美结合

前言 华为云828企业上云节&#xff0c;Flexus X实例携手Harbor私有镜像仓库&#xff0c;共创云上安全高效新生态&#xff01;Flexus X以其卓越性能与稳定性&#xff0c;为Harbor提供了理想的运行环境。Harbor作为领先的私有镜像仓库&#xff0c;与Flexus X完美结合&#xff0c;…

[OpenGL]使用OpenGL绘制三角形

一、简介 本文介绍了如何在linux/win(wsl2)环境下&#xff0c;使用GLFWGLAD实现绘制三角形。 本文内容基本根据LearnOpengGL-入门-你好&#xff0c;三角形整理完成&#xff0c;读者也可以参考LearnOpengGL-入门-你好&#xff0c;三角形自行学习如何使用OpenGL绘制三角形。 按…

【人工智能学习笔记】3_2 机器学习基础之机器学习经典算法介绍

线性回归算法的定义和任务类型 定义:线性回归是利用数理统计中回归分析,来确定两种或两种以上变量间相互依赖的定量关系的一种统计分析方法任务类型:回归应用场景:异常指标监控 农业贷款监控过拟合和欠拟合 定义:过拟合和欠拟合用来度量模型泛化能力的直观表现欠拟合:模型…

笔记共享平台|基于Java+vue的读书笔记共享平台系统(源码+数据库+文档)

笔记共享平台|读书笔记共享平台系统 目录 基于Javavue的读书笔记共享平台系统 一、前言 二、系统设计 三、系统功能设计 四、数据库设计 五、核心代码 六、论文参考 七、最新计算机毕设选题推荐 八、源码获取&#xff1a; 博主介绍&#xff1a;✌️大厂码农|毕设布道…

基于大数据的科研热点分析与挖掘系统

温馨提示&#xff1a;文末有 CSDN 平台官方提供的学长 QQ 名片 :) 1. 项目简介 科研活动的快速发展产生了大量的学术文献&#xff0c;如何从这些文献中提炼出有价值的科研热点和趋势成为了一个重要的问题。本项目旨在开发一个基于大数据的科研热点分析可视化系统&#xff0c;采…

微模块冷通道动环监控:智能化数据中心管理利器@卓振思众

在现代数据中心和机房管理中&#xff0c;微模块冷通道动环监控系统的引入&#xff0c;标志着对冷却和环境管理的新纪元。这一系统不仅提升了数据中心的运维效率&#xff0c;还对设备的安全性和稳定性提供了强有力的保障。本文将详细探讨微模块冷通道动环监控的功能和其在数据中…

Missing package to enable rendering OpenAI Gym in Colab

题意&#xff1a;“缺少用于在 Colab 中渲染 OpenAI Gym 的软件包。” 问题背景&#xff1a; Im attempting to render OpenAI Gym environments in Colab via a Mac using the StarAI code referenced in previous questions on this topic. However, it fails. The key erro…

基于开源WQ装备知识图谱的智能问答全流程构建

基于知识图谱的智能问答系统是一种利用知识图谱结构化数据来回答自然语言问题的技术。知识图谱存储了实体&#xff08;如人、地点、物品等&#xff09;及其之间的关系&#xff0c;允许智能系统查询相关的信息并推理答案。 1、知识图谱的智能问答系统核心流程&#xff1a; 问题…

如何通过海外云手机提升运营效率

随着技术的不断进步&#xff0c;市场上出现了越来越多的提高跨国电商运营效率的应用&#xff0c;海外云手机就是其中一个。海外云手机的优势体现在多个方面&#xff0c;那么如何通过使用海外云手机来提升运营效率&#xff1f;可以从以下几个方面了解。 首先&#xff0c;海外云手…

中国人民银行:数字人民币交易额已达7万亿元!中俄考虑使用国家数字货币进行双边结算!

近年来&#xff0c;数字货币的迅速发展引起了全球的广泛关注。中国人民银行&#xff08;PBOC&#xff09;近日透露&#xff0c;数字人民币&#xff08;e-CNY&#xff09;的交易额已接近1万亿美元&#xff0c;这标志着中国在数字货币领域的重大进展。同时俄罗斯也表示&#xff0…

shader 案例学习笔记之mix函数

mix函数&#xff1a; 在两个值之间进行插值&#xff1b; 使用&#xff1a; #ifdef GL_ES precision mediump float; #endifuniform vec2 u_resolution; uniform float u_time;vec3 colorA vec3(0.149,0.141,0.912); vec3 colorB vec3(1.0,0.83,0.224);void main(){vec2 st…

生成你想要的测试数据,除了用这6款工具,还能用AI

在软件测试中&#xff0c;测试数据是测试用例的基础&#xff0c;对测试结果的准确性和全面性有着至关重要的影响。因此&#xff0c;在进行软件测试时&#xff0c;需要生成测试数据以满足测试场景和要求。 本文将介绍什么情况下需要生成测试数据&#xff0c;常用的测试数据生成…

路径规划与轨迹跟踪系列算法学习 MATLAB 模型预测控制MPC

下面这张图的程序 019 路径规划与轨迹跟踪是自动驾驶汽车、无人机以及其他自动化系统中的关键技术之一。MATLAB 提供了丰富的工具箱来实现这些功能&#xff0c;其中模型预测控制&#xff08;Model Predictive Control, MPC&#xff09;是一种广泛使用的路径跟踪控制方法。下面是…

快速搭建最简单的前端项目vue+View UI Plus

1 引言 ‌‌Vue是一套用于构建Web前端界面的渐进式JavaScript框架。‌‌它以其易学易用、性能出色、灵活多变而深受开发者喜爱&#xff0c;并且与其他前端框架&#xff08;如‌React和‌Angular&#xff09;相比&#xff0c;在国内市场上受到了广泛的认可和使用。点击进入官方…

【线程池】Java 线程池 ThreadPoolExecutor 类源码介绍

文章目录 前言线程池是什么线程池解决了哪些问题本文主要讲述什么感谢读者 线程池 UML 类图ThreadPoolExecutor 内部设计核心参数内部类任务队列拒绝策略 ThreadPoolExecutor 源码线程池生命周期线程池构造函数execute() 【提交任务】addWorker() 方法 【添加工作线程并启动】了…

【微服务】⭐️华为云obs功能抽取到公共服务,供所有项目使用

目录 &#x1f378;前言 &#x1f37b;一、公共服务搭建 &#x1f37a;二、代码实现 1.工具类编写 2.项目引入使用 &#x1f379;三、章末 &#x1f378;前言 小伙伴们大家好&#xff0c;上次讲了如何本地对接华为云Obs对象存储服务&#xff0c;在本地项目中通过sdk引入调用…

【QT】常用控件-下

欢迎来到Cefler的博客&#x1f601; &#x1f54c;博客主页&#xff1a;折纸花满衣 &#x1f3e0;个人专栏&#xff1a;QT 目录 &#x1f449;&#x1f3fb;QComboBox&#x1f449;&#x1f3fb; QSpinBox&#x1f449;&#x1f3fb;QDateTimeEdit&#x1f449;&#x1f3fb;QD…

时序预测 | MATLAB实现BKA-XGBoost(黑翅鸢优化算法优化极限梯度提升树)时间序列预测

时序预测 | MATLAB实现BKA-XGBoost(黑翅鸢优化算法优化极限梯度提升树)时间序列预测 目录 时序预测 | MATLAB实现BKA-XGBoost(黑翅鸢优化算法优化极限梯度提升树)时间序列预测预测效果基本介绍模型描述程序设计参考资料 预测效果 基本介绍 Matlab实现BKA-XGBoost时间序列预测&a…

datasophon升级海豚调度dolphinscheduler为3.2.2

一、参考博主升级3.2.1文章&#xff1a;datasophon升级海豚调度为3.2.1_海豚调度3.2.2 mysql包找不到-CSDN博客 二、升级后woker-server启动报错如下&#xff1a; 原因是worker-server下conf/common.properties中的&#xff1a;resource.storage.typeNONE&#xff0c; 解决很简…

如何划分类/单一职权原则SRP

参考&#xff1a;单一职责 -- 每个类只负责一个功能_每个类应该只负责一个功能,遵循单一职责原则。-CSDN博客 类有且只有一个原因需要修改它&#xff0c;这样的才是一个结构简洁的类。 结合上面的例子&#xff0c;需要注意的点&#xff1a; 1.比如搜索数据库&#xff0c;需要…