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 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.mfbz.cn/a/875119.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

研1日记9

1.理解conv1d和conv2d a. 1和2处理的数据不同&#xff0c;1维数据和图像 b. 例如x输入形状为(32,19,512)时&#xff0c;卷积公式是针对512的&#xff0c;而19应该变换为参数中指定的输出通道。 2.“SE块”&#xff08;Squeeze-and-Excitation Block&#xff09;它可以帮助模…

JAVA:对称加密技术的详细指南

请关注微信公众号&#xff1a;拾荒的小海螺 博客地址&#xff1a;http://lsk-ww.cn/ 1、简述 对称加密是一种加密算法&#xff0c;其中加密和解密使用相同的密钥。其主要特点是速度快、效率高&#xff0c;适用于大数据量的加密需求。对称加密算法通常用于保护数据的机密性和完…

Scratch中秋节游戏——玉兔收集月饼

小虎鲸Scratch资源站-免费Scratch作品源码,素材,教程分享平台! 中秋节将至&#xff0c;想要在这个团圆的日子里增添一点趣味和创意吗&#xff1f;小虎鲸Scratch资源站为大家带来了一款独具特色的中秋节游戏——玉兔收集月饼&#xff01;这款Scratch游戏不仅充满了节日的气氛&am…

小琳AI课堂:MASS模型——革新自然语言处理的预训练技术

大家好&#xff0c;这里是小琳AI课堂。今天我们来聊聊一个在自然语言处理&#xff08;NLP&#xff09;领域非常热门的话题——MASS模型&#xff0c;全称是Masked Sequence to Sequence Pre-training for Language Generation。这是华为诺亚方舟实验室在2019年提出的一种创新模型…

【重学 MySQL】十八、逻辑运算符的使用

【重学 MySQL】十八、逻辑运算符的使用 AND运算符OR运算符NOT运算符异或运算符使用 XOR 关键字使用 BIT_XOR() 函数注意事项 注意事项 在MySQL中&#xff0c;逻辑运算符是构建复杂查询语句的重要工具&#xff0c;它们用于处理布尔类型的数据&#xff0c;进行逻辑判断和组合条件…

MySQL之库和表操作

目录 一&#xff1a;对库的操作 1.创建数据库 2.查看数据库列表 3.显示创建数据库的语句 4.删除数据库 5.字符集与校验集 6.确认当前所处的数据库 7.修改数据库 8.备份和恢复 9.查看连接情况 二:对表的操作 1.创建表 2.查看表 3.删除表 4.修改表 接下来的日…

终端文件管理神器 !!!【送源码】

项目简介 nnn是一款专为命令行爱好者打造的高效终端文件管理器。它以其超小的体积、几乎零配置的要求以及卓越的速度表现而著称。nnn不仅适用于Linux、macOS、BSD等操作系统&#xff0c;还能够在诸如树莓派、Android上的Termux、WSL、Cygwin等多个平台运行。它遵循POSIX标准&am…

Linux——解压大型zip文件报错:bad zipfile offset (local header sig) 的解决方法

一、现象描述 完整一行报错信息&#xff1a; error: invalid compressed data to inflate file #14: bad zipfile offset (local header sig) 二、解决办法 利用 -F 去修复&#xff1a; zip -F xxx.zip --out large.zip得到&#xff1a; 解压&#xff1a; unzip large.zi…

Python爱心射线(完整代码)

目录 系列目录 写在前面​ 完整代码 下载代码 代码分析 写在后面 系列目录 序号直达链接表白系列1Python制作一个无法拒绝的表白界面2Python满屏飘字表白代码3

代码随想录训练营Day2 | 209.长度最小的子数组 | 59.螺旋矩阵II | 58. 区间和

1. 学习滑动窗口 2.学习标准输入输出模式 3.学习文档代码随想录 (programmercarl.com) 数组总结 Leetcode 209.长度最小的子数组 题目描述&#xff1a; 给定一个含有 n 个正整数的数组和一个正整数 target 。 找出该数组中满足其总和大于等于 target 的长度最小的 子数组…

Unity Addressables 使用说明(二)管理 Addressables

组织和管理 Addressables 的主要方式是使用组&#xff08;groups&#xff09;和配置文件&#xff08;profiles&#xff09;。本节概述了如何使用这些工具来有效地管理 Addressables。 【概述】管理 Addressables 在决定如何管理项目中的资源之前&#xff0c;先熟悉资源如何创…

CCF推荐A类会议和期刊总结(计算机网络领域)- 2022

CCF推荐A类会议和期刊总结&#xff08;计算机网络领域&#xff09;- 2022 在中国计算机学会&#xff08;CCF&#xff09;的推荐体系中&#xff0c;A类会议和期刊代表着计算机网络领域的顶尖水平。这些会议和期刊不仅汇集了全球顶尖的研究成果&#xff0c;还引领着该领域的前沿发…

Python操作ES集群API(增删改查等)

前言&#xff1a;本博客仅作记录学习使用&#xff0c;部分图片出自网络&#xff0c;如有侵犯您的权益&#xff0c;请联系删除 学习B站博主教程笔记&#xff1a; 最新版适合自学的ElasticStack全套视频&#xff08;Elk零基础入门到精通教程&#xff09;Linux运维必备—Elastic…

【信号】信号的保存

信号的保存 信号其他相关常见概念 实际执行信号的处理动作称为信号递达(Delivery) 信号从产生到递达之间的状态,称为信号未决(Pending)。 进程可以选择阻塞 (Block )某个信号。 被阻塞的信号产生时将保持在未决状态,直到进程解除对此信号的阻塞,才执行递达的动作.注意,阻塞和…

[数据集][目标检测]智慧农业草莓叶子病虫害检测数据集VOC+YOLO格式4040张9类别

数据集格式&#xff1a;Pascal VOC格式YOLO格式(不包含分割路径的txt文件&#xff0c;仅仅包含jpg图片以及对应的VOC格式xml文件和yolo格式txt文件) 图片数量(jpg文件个数)&#xff1a;4040 标注数量(xml文件个数)&#xff1a;4040 标注数量(txt文件个数)&#xff1a;4040 标注…

linux 安装redis

1. 更新系统和安装依赖 sudo apt update sudo apt install build-essential tcl2. 下载 Redis 源码(没有opt文件夹&#xff0c;则先创建opt文件夹) cd /opt wget http://download.redis.io/releases/redis-6.2.6.tar.gz3. 解压和编译 Redis 解压下载的文件&#xff0c;并进入…

Error: PostCSS plugin autoprefixer requires PostCSS 8.

引言 uniapp坑之使用vue-cli 拉去官方模板出错 版本&#xff1a; node:v14.15.0 npm:6.14.8 Vue CLI v5.0.8 拉取官方模板运行直接报错 原因: 通用说明是&#xff1a; autoprefixer 是版本过高 话说官方咋不解决这个插件问题&#xff0c;那位大佬知道原因 解决&#xff1a;…

OJ 括号生成

题目&#xff1a; 数字 n 代表生成括号的对数&#xff0c;请你设计一个函数&#xff0c;用于能够生成所有可能的并且 有效的 括号组合。 示例&#xff1a; 代码分析&#xff1a; class Solution { public://进行回溯调用vector<string> generateParenthesis(int n) {if(…

Vue 项目hash和history模式打包部署与服务器配置

你好&#xff0c;我是沐爸&#xff0c;欢迎点赞、收藏、评论和关注。 在开发 Vue 项目时&#xff0c;Vue Router 提供了两种模式来创建单页面应用&#xff08;SPA&#xff09;的 URL&#xff1a;hash 模式和 history 模式。 简单说下两者的主要区别&#xff1a; hash 模式下的…

麦克风哪款好,领夹麦克风十大品牌,无线领夹麦克风推荐

在直播与Vlog盛行的今天&#xff0c;一款高质量的无线领夹麦克风无疑是内容创作者们提升音质、展现专业度的关键装备。传统有线麦克风及部分品质参差的无线领夹麦&#xff0c;虽能在一定程度上传递声音&#xff0c;却难以克服信号干扰、音质失真等技术瓶颈。更要警惕的是&#…