当前位置: 首页 > news >正文

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

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 daemonLoaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; preset: enabled)Active: active (running) since Tue 2024-09-10 09:12:37 CST; 2h 34min agoDocs: man:firewalld(1)Main PID: 924 (firewalld)Tasks: 2 (limit: 24434)Memory: 42.1MCPU: 1.275sCGroup: /system.slice/firewalld.service└─924 /usr/bin/python3 -s /usr/sbin/firewalld --nofork --nopidSep 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 ServerCopyright (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 ServerCopyright (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 ServerCopyright (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 还有数据库 进行水平扩展时,应该怎么做?

相关文章:

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

PQS/TPS 每秒请求数/ 每秒事务数 // 流量衡量参数 可以根据预估QPS 和 服务器的支持的最高QPS 对照计算 就可以得出 需要上架的服务器的最小数量 PV 页面浏览数 UV 独立用户访问量 // 对于网站的总体访问量 response time 响应时间 // 每个请求的响应时间…...

javaaaa

1 飞机票 代码实现&#xff1a; import java.util.Scanner; public class F1 {public static void main(String[] args) {Scanner input new Scanner(System.in);System.out.print("请输入票价&#xff1a; ");double jia input.nextDouble();System.out.print(&…...

游戏开发引擎___unity位置信息和unlit shader(无光照着色器)的使用,以桌子的渲染为例

unity是左手坐标系 1.位置信息 1.1 代码 using System.Collections; using System.Collections.Generic; using UnityEngine;public class positionTest : MonoBehaviour {public Camera Camera;private void OnGUI(){//世界坐标系&#xff0c;GUI里的标签GUI.Label(new Rec…...

反向沙箱的功能特点

在这个信息化飞速发展的时代&#xff0c;企业的数据安全面临着前所未有的挑战。员工的无意操作、恶意软件的潜伏、甚至是敌对势力的网络攻击&#xff0c;都可能成为企业数据安全的致命威胁。深信达SPN反向沙箱为您筑起了一道坚不可摧的数据安全防线&#xff01; 来百度APP畅享高…...

可测试,可维护,可移植:上位机软件分层设计的重要性

互联网中&#xff0c;软件工程师岗位会分前端工程师&#xff0c;后端工程师。这是由于互联网软件规模庞大&#xff0c;从业人员众多。前后端分别根据各自需求发展不一样的技术栈。那么上位机软件呢&#xff1f;它规模小&#xff0c;通常一个人就能开发一个项目。它还有必要分前…...

构造函数与析构函数的执行顺序

对象作为成员变量的构造函数与析构函数 当一个类包含另一个类的对象作为成员时&#xff0c;这些成员对象的构造函数会在包含它们的对象的构造函数之前被调用&#xff0c;而它们的析构函数则会在包含它们的对象的析构函数之后被调用。成员对象的构造函数和析构函数的调用顺序与…...

Vue框架;Vue中的选择和循环结构;Vue数据类型;Vue中的事件和动态属性;Vue子组件通过导入在主组件显示在网页;Vue中主组件向子组件传递数据

一&#xff0c;Vue简介 前端现在比较火的三大框架就是&#xff1a;vue &#xff0c;React&#xff0c;Angular。在国内使用最多的还是&#xff1a; vue >React >Angular Vue (发音为 /vjuː/&#xff0c;类似 view) 是一款用于构建用户界面的 JavaScript 框架。它基于标准…...

懒人笔记-opencv4.8.0篇

懒人笔记-opencv4.8.0篇 前言1、卸载 opencv3.4.31.1 cmake1.2 编译过程1.3 卸载1.4 检查代码是否卸载干净 2、安装 opencv4.8.02.1 安装依赖2.2 创建编译目录2.3 设置编译选项2.4 执行编译命令2.5 环境配置2.5.1、环境配置添加库路径2.5.2 更新系统2.5.3 配置bash2.5.4 保存退…...

解决uniapp视频video组件进入全屏再退出全屏后,cover-view失效的问题

给cover-view一个变量如isCloseBtnShow&#xff0c;通过v-if&#xff08;不要用v-show&#xff09;来控制显示隐藏。监听video全屏事件&#xff0c;全屏时&#xff0c;设置变量为false,退出全屏时再设为true&#xff0c;这样每次退出全屏,cover-view会重新加载。被覆盖的问题就…...

ip属地河北切换北京

我们知道&#xff0c;每当电脑或手机连接网络时&#xff0c;都会分配到一个网络IP地址&#xff0c;这个IP地址通常与设备所在的地区网络相关联。然而&#xff0c;出于业务或个人需求&#xff0c;有时我们需要将本机的IP地址切换到其他城市。例如要将IP属地河北切换北京&#xf…...

fpga入门名词(1)

这是第一代FPGA ,在 FPGA&#xff08;现场可编程门阵列&#xff09;设计中&#xff0c;LCA&#xff08;逻辑单元阵列&#xff09;通常由几个关键组件构成&#xff0c;包括 IOB、CLB 和 Interconnect。以下是这些组件的简要说明&#xff1a; 1. IOB&#xff08;Input/Output B…...

设计模式-行为型模式-访问者模式

访问者模式难以实现&#xff0c;且应用该模式可能会导致代码可读性变差&#xff0c;可维护性变差&#xff0c;除非必要&#xff0c;不建议使用&#xff1b; 1.访问者模式定义 允许在运行时将一个或多个操作应用于一组对象&#xff0c;将操作与对象结构分离&#xff1b; 访问者…...

探索Oracle数据库的多租户特性:架构、优势与实践

在云计算和大数据时代&#xff0c;多租户架构成为数据库设计中的一个重要趋势。Oracle数据库的多租户选项&#xff08;Multitenant&#xff09;允许单个数据库实例支持多个独立数据库&#xff08;称为容器数据库和可插拔数据库&#xff09;&#xff0c;每个数据库都有自己的数据…...

Hack The Box-Sightless

总体思路 CVE-2022-0944->密码破解->chrome调试->PHP-FPM命令执行 信息收集&端口利用 nmap -sSVC sightless.htbStarting Nmap 7.94SVN ( https://nmap.org ) at 2024-09-11 08:40 CST Nmap scan report for sightless.htb Host is up (0.84s latency). Not sh…...

Linux驱动开发-字符设备驱动开发

linux 驱动开发1. 驱动程序的类型2. 驱动开发流程字符设备驱动 1. 基本概念2. 字符设备驱动的基本结构 架构字符设备驱动开发中常用的 API示例以下代码加入了设备类和设备实例的创建 linux 驱动开发 1. 驱动程序的类型 在 Linux 中&#xff0c;驱动程序主要有以下几种类型&am…...

好用的电脑录屏软件有哪些?推荐4款专业工具。

不同系统的电脑上面带有的录屏功能不一样&#xff0c;比如win10上面有Xbox game bar,Mac系统则用的是QuickTime Player&#xff0c;或者是使用快捷键“CommandShift5”。但更方便的&#xff0c;我自己认为是使用一些专业的录屏软件&#xff0c;他门的录制模式多&#xff0c;兼容…...

web基础之XSS

一、搭建XSS平台 安装 1、我这里安装在本地的Phpstudy上&#xff0c;安装过程就是一路下一步&#xff08;可以改安装路径&#xff09;&#xff0c;附上下载链接&#xff1a; # 官网&#xff1a;https://www.xp.cn/download.html# 蓝莲花 - github下载 https://github.com/fi…...

目标检测-小目标检测方法

小目标检测是计算机视觉中的一个挑战性问题&#xff0c;因为小目标往往在图像中占据的像素较少&#xff0c;容易被背景或其他物体干扰。为了有效地进行小目标检测&#xff0c;研究人员和工程师提出了多种方法和算法来提高检测精度。以下是一些针对小目标检测的有效方式和算法&a…...

连接数据库(以MySQL为例)

文章目录 前言一、数据库是什么&#xff1f;二、连接步骤 1.手动导入驱动包2.连接数据库总结 前言 面对应用程序的开发&#xff0c;普遍需要保存用户的海量数据。保存粮的库叫粮库&#xff0c;保存水的库叫水库&#xff0c;那么保存数据的库自然叫数据库。有了数据库&#xff0…...

Mysql高级教程

1.安装部署 安装依赖性&#xff1a; [rootmysql-node10 ~]# dnf install cmake gcc-c openssl-devel ncurses-devel.x86_64 libtirpc-devel-1.3.3-8.el7_4.x86_64.rpm rpcgen.x86_64 下载并解压源码包 [rootmysql-node10 ~]# tar zxf mysql-boost-5.7.44.tar.gz [rootmysql-no…...

MFC内存泄露

1、泄露代码示例 void X::SetApplicationBtn() {CMFCRibbonApplicationButton* pBtn GetApplicationButton();// 获取 Ribbon Bar 指针// 创建自定义按钮CCustomRibbonAppButton* pCustomButton new CCustomRibbonAppButton();pCustomButton->SetImage(IDB_BITMAP_Jdp26)…...

23-Oracle 23 ai 区块链表(Blockchain Table)

小伙伴有没有在金融强合规的领域中遇见&#xff0c;必须要保持数据不可变&#xff0c;管理员都无法修改和留痕的要求。比如医疗的电子病历中&#xff0c;影像检查检验结果不可篡改行的&#xff0c;药品追溯过程中数据只可插入无法删除的特性需求&#xff1b;登录日志、修改日志…...

DAY 47

三、通道注意力 3.1 通道注意力的定义 # 新增&#xff1a;通道注意力模块&#xff08;SE模块&#xff09; class ChannelAttention(nn.Module):"""通道注意力模块(Squeeze-and-Excitation)"""def __init__(self, in_channels, reduction_rat…...

高频面试之3Zookeeper

高频面试之3Zookeeper 文章目录 高频面试之3Zookeeper3.1 常用命令3.2 选举机制3.3 Zookeeper符合法则中哪两个&#xff1f;3.4 Zookeeper脑裂3.5 Zookeeper用来干嘛了 3.1 常用命令 ls、get、create、delete、deleteall3.2 选举机制 半数机制&#xff08;过半机制&#xff0…...

CRMEB 框架中 PHP 上传扩展开发:涵盖本地上传及阿里云 OSS、腾讯云 COS、七牛云

目前已有本地上传、阿里云OSS上传、腾讯云COS上传、七牛云上传扩展 扩展入口文件 文件目录 crmeb\services\upload\Upload.php namespace crmeb\services\upload;use crmeb\basic\BaseManager; use think\facade\Config;/*** Class Upload* package crmeb\services\upload* …...

SpringTask-03.入门案例

一.入门案例 启动类&#xff1a; package com.sky;import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cache.annotation.EnableCach…...

Spring AI与Spring Modulith核心技术解析

Spring AI核心架构解析 Spring AI&#xff08;https://spring.io/projects/spring-ai&#xff09;作为Spring生态中的AI集成框架&#xff0c;其核心设计理念是通过模块化架构降低AI应用的开发复杂度。与Python生态中的LangChain/LlamaIndex等工具类似&#xff0c;但特别为多语…...

项目部署到Linux上时遇到的错误(Redis,MySQL,无法正确连接,地址占用问题)

Redis无法正确连接 在运行jar包时出现了这样的错误 查询得知问题核心在于Redis连接失败&#xff0c;具体原因是客户端发送了密码认证请求&#xff0c;但Redis服务器未设置密码 1.为Redis设置密码&#xff08;匹配客户端配置&#xff09; 步骤&#xff1a; 1&#xff09;.修…...

MySQL账号权限管理指南:安全创建账户与精细授权技巧

在MySQL数据库管理中&#xff0c;合理创建用户账号并分配精确权限是保障数据安全的核心环节。直接使用root账号进行所有操作不仅危险且难以审计操作行为。今天我们来全面解析MySQL账号创建与权限分配的专业方法。 一、为何需要创建独立账号&#xff1f; 最小权限原则&#xf…...

回溯算法学习

一、电话号码的字母组合 import java.util.ArrayList; import java.util.List;import javax.management.loading.PrivateClassLoader;public class letterCombinations {private static final String[] KEYPAD {"", //0"", //1"abc", //2"…...