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

news/2024/9/18 19:25:19/ 标签: 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 还有数据库 进行水平扩展时,应该怎么做?


http://www.ppmy.cn/news/1526798.html

相关文章

3176. 求出最长好子序列 I

3176. 求出最长好子序列 I 题目链接&#xff1a;3176. 求出最长好子序列 I 代码如下&#xff1a; class Solution { public:int maximumLength(vector<int>& nums, int k){unordered_map<int, vector<int>> fd;vector<int> mx(k 2);for (int n…

Java项目: 基于SpringBoot+mybatis+maven校园资料分享平台(含源码+数据库+答辩PPT+毕业论文)

一、项目简介 本项目是一套基于SpringBootmybatismaven校园资料分享平台 包含&#xff1a;项目源码、数据库脚本等&#xff0c;该项目附带全部源码可作为毕设使用。 项目都经过严格调试&#xff0c;eclipse或者idea 确保可以运行&#xff01; 该系统功能完善、界面美观、操作简…

如何建立一个Webservice WSDL的简单例子(完整例子)

一&#xff1a;根据对方给的wsdl 的接口地址创建Web 的逻辑端口 1&#xff1a;例如这个用C#写的Web 2.我们需要在SAP里建立一个Service Consumers 的服务记得后缀要加?wsdl 2&#xff1a;然后就会生成对应方法的出参 入参 返回的消息根据接口方法来判断 二&#xff1a;如何通…

计算机三级 - 数据库技术 - 第十四章 数据仓库与数据挖掘 笔记

第十四章 数据仓库与数据挖掘 内容提要&#xff1a; 了解数据仓库相关技术了解数据仓库的设计、建造、运行及维护了解OLAP及多维数据模型了解数据挖掘技术 决策支持系统(DSS)&#xff1a;综合利用大量数据有机组合众多模型(数学模型和数据处理模型)&#xff0c;通过人机交互&a…

观察者模式,回调函数,事件调度

观察者模式 定义 是一种行为型设计模式&#xff0c;它定义了一种一对多的依赖关系&#xff0c;当一个对象的状态发生改变时&#xff0c;其所有依赖于它的对象都会收到通知并自动更新。 主题&#xff08;Subject&#xff09;&#xff1a;也称为被观察者&#xff0c;维护一个观…

ASP.NET Core 入门教学二十八 linux打包部署

在Linux上打包和部署ASP.NET Core应用程序涉及几个步骤。以下是一个详细的指南&#xff0c;帮助你在Linux系统上完成这一过程。 1. 准备工作 确保你的Linux系统已经安装了以下软件&#xff1a; .NET SDK&#xff08;用于构建应用程序&#xff09;.NET Runtime&#xff08;用…

华为地图服务 - 如何开启和展示“我的位置”? -- HarmonyOS自学10

一. 场景介绍 本章节将向您介绍如何开启和展示“我的位置”功能&#xff0c;“我的位置”指的是进入地图后点击“我的位置”显示当前位置点的功能。效果如下&#xff1a; 二. 接口说明 “我的位置”功能主要由MapComponentController的方法实现&#xff0c;更多接口及使用方法…

MacOS Catalina 从源码构建Qt6.2开发库之01: 编译Qt6.2源代码

安装xcode&#xff0c; cmake&#xff0c; ninja brew install node mac下安装OpenGL库并使之对各项目可见 在macOS上安装OpenGL通常涉及到安装一些依赖库&#xff0c;如MGL、GLUT或者是GLEW等&#xff0c;同时确保LLVM的OpenGL框架和相关工具链的兼容性。以下是一个基本的安装…

深入理解Go语言中的接口定义与使用

在Go语言的编程实践中&#xff0c;接口&#xff08;Interface&#xff09; 是一个强大而灵活的特性&#xff0c;它允许我们定义一组方法&#xff0c;而不需要指定这些方法的具体实现。通过接口&#xff0c;我们可以将不同类型的值组合在一起&#xff0c;只要它们实现了接口中定…

Docker | 轻松管理容器:Portainer安装与使用指南

引言 在Docker的世界中&#xff0c;管理容器、镜像、网络和卷可能会变得复杂&#xff0c;特别是当项目规模扩大时。幸运的是&#xff0c;Portainer提供了一个简单而强大的可视化界面来管理Docker环境。本文将带你了解如何安装和使用Portainer&#xff0c;让你的容器管理变得更…

策略路由与路由策略的区别

&#x1f423;个人主页 可惜已不在 &#x1f424;这篇在这个专栏 华为_可惜已不在的博客-CSDN博客 &#x1f425;有用的话就留下一个三连吧&#x1f63c; 目录 一、主体不同 二、方式不同 三、规则不同 四、定义和基本概念 一、主体不同 1、路由策略&#xff1a;是为了改…

[图解]强化自测题解析-总纲(一)02 抵制建模的心态

1 00:00:00,530 --> 00:00:02,270 今天我们来看 2 00:00:02,590 --> 00:00:06,270 强化自测题&#xff0c;总纲一的第二道题 3 00:00:07,260 --> 00:00:09,260 抵制建模的心态的题目 4 00:00:11,250 --> 00:00:11,860 单选题 5 00:00:13,430 --> 00:00:14,9…

【排序算法】之基数排序

一、算法介绍 基数排序是一种非比较型整数排序算法&#xff0c;其原理是将整数按低位到高位或者高位到低位的顺序&#xff0c;依次根据每一位的数值进行排序。通常情况下&#xff0c;基数排序会使用桶排序来处理每一位上的数值。 实现方法主要有如下&#xff1a; 最高位优先(…

基于鸿蒙API10的RTSP播放器(九:进度总结)

一、前言 基于鸿蒙API10和三方库ijkpalyer2.0.4&#xff0c;实现RTSP流的流畅播放&#xff0c;支持H.264和H.265硬编码&#xff0c;既可以在基于X86的模拟机上运行&#xff0c;也可以在基于armabi-v7a的真机上运行。 二、已实现功能 视频画面尺寸调整&#xff08;2:1比例&am…

小米,B站网络安全岗位笔试题目+答案

《网安面试指南》http://mp.weixin.qq.com/s?__bizMzkwNjY1Mzc0Nw&mid2247484339&idx1&sn356300f169de74e7a778b04bfbbbd0ab&chksmc0e47aeff793f3f9a5f7abcfa57695e8944e52bca2de2c7a3eb1aecb3c1e6b9cb6abe509d51f&scene21#wechat_redirect 《Java代码审…

redis基本数据结构-set

文章目录 1. set的基本介绍1.1. set底层结构之hash表的简单介绍1.2. 常用命令 2. 常见的业务场景2.1. 标签系统2.2. 社交网络好友关系 1. set的基本介绍 参考链接&#xff1a;https://mp.weixin.qq.com/s/srkd73bS2n3mjIADLVg72A redis 的 set 数据结构是一个无序的集合&#…

CSS 图片廊:打造精美视觉体验

CSS 图片廊&#xff1a;打造精美视觉体验 随着互联网技术的发展&#xff0c;网页设计越来越注重用户体验和视觉效果的呈现。CSS&#xff08;层叠样式表&#xff09;作为网页设计的重要工具&#xff0c;能够帮助开发者创建出既美观又实用的图片展示效果。本文将详细介绍如何使用…

html+css+js网页设计 旅游 龙门石窟4个页面

htmlcssjs网页设计 旅游 龙门石窟4个页面 网页作品代码简单&#xff0c;可使用任意HTML辑软件&#xff08;如&#xff1a;Dreamweaver、HBuilder、Vscode 、Sublime 、Webstorm、Text 、Notepad 等任意html编辑软件进行运行及修改编辑等操作&#xff09;。 获取源码 1&#…

学习笔记(一)

前言 一、对象 1、由类建模而成&#xff0c;是消息、数据和行为的组合 2、可以接收和发送消息&#xff0c;并利用消息进行彼此的交互。消息要包含传送给对象接收的信息 3、类的实例化&#xff1a;把类转换为对象的过程叫类的实例化。 4、对象的特性 (1) 对象有状态&#…

关于HarmonyOS的学习

day33 一、模块化 1.node模块化 let listMode require(./modules/list)let {index, tab} require(./modules/tab) ​// console.log(listMode)// console.log(tabMode) ​// console.log(listMode.index)// console.log(tabMode.index) ​// listMode.list() ​// console.…