云计算架构学习之LNMP架构部署、架构拆分、负载均衡-会话保持
一.LNMP架构部署
1.1. LNMP服务搭建






1.磁盘信息
2.内存
3.负载信息
4.Nginx你们公司都用来干嘛
5.文件句柄(文件描述符 打开文件最大数量)
6.你处理过系统中的漏洞吗 SSH漏洞
7.你写过什么shell脚本
8.监控通过什么告警 zabbix
具体监控哪些内容
9.mysql redis查询
你好HR我这边面完了,但是面试官啥技术都没问题.我也不知道是啥问题。要不您这边先沟通一下,有什么问题您给我联系。
1.2. 测试PHP和mysql说起来的连通性
```bash
#需要再php的配置文件中写入数据库的IP+端口+用户名+密码可以测试是否连接数据库
[root@web01 conf.d]# cat /code/mysql.php
<?php
$servername = "localhost";
$username = "root";
$password = "lzy123.com";
// 创建连接
$conn = mysqli_connect($servername, $username, $password);
// 检测连接
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "小哥哥,php可以连接MySQL...";
?>
<img style='width:100%;height:100%;' src=/31.png>
#注意苍姐姐需要自己准备
浏览器访问:
php.oldboy.com/mysql.php
```


1.3. 安装部署wordpress流程
``bash 1.创建nginx配置文件 [root@web01 conf.d]# cp php.conf wp.conf [root@web01 conf.d]# cat wp.conf server { listen 80; server_name www.wp.com; root /code/wordpress;
location / {index index.php index.html;}location ~ \.php$ {fastcgi_pass 127.0.0.1:9000;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}
}
2.测试nginx [root@web01 conf.d]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
3.重启生效 [root@web01 conf.d]# systemctl restart nginx
4.创建代码目录 [root@web01 conf.d]# mkdir /code/wordpress
5.下载wordpress代码 [root@web01 conf.d]# cd /code/wordpress/ [root@web01 wordpress]# wget https://cn.wordpress.org/wordpress-5.0.3-zhCN.tar.gz [root@web01 wordpress]# tar xf wordpress-5.0.3-zhCN.tar.gz
6.解压代码 [root@web01 wordpress]# tar xf wordpress-5.0.3-zh_CN.tar.gz [root@web01 wordpress]# mv wordpress/* .
7.hosts解析 10.0.0.7 www.wp.com 浏览器访问业务 ```


vim /etc/php-fpm.d/www.conf


1.4. 安装部署知乎业务
``bash 1.配置Nginx [root@web01 conf.d]# cat zh.conf server { listen 80; server_name www.zh.com; root /code/zh;
location / {index index.php index.html;}location ~ \.php$ {fastcgi_pass 127.0.0.1:9000;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}
}
[root@web01 conf.d]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [root@web01 conf.d]# systemctl restart nginx
2.创建代码目录 [root@web01 conf.d]# mkdir /code/zh [root@web01 conf.d]# cd /code/zh
3.上传代码 [root@web01 zh]# ll total 24648 -rw-r--r-- 1 root root 25238972 Aug 7 09:28 WeCenterV3.6.2.zip [root@web01 zh]# unzip WeCenterV3.6.2.zip 4.解压代码 [root@web01 zh]# chown -R www.www ../zh
5.安装部署 windows-hosts解析 10.0.0.7 www.zh.com
6.创建数据库zh [root@web01 ~]# mysql -uroot -plzy123.com -e "create database zh;" [root@web01 ~]# mysql -uroot -plzy123.com -e "show databases;" +--------------------+ | Database | +--------------------+ | informationschema | | mysql | | performanceschema | | wordpress | | zh | +--------------------+
```




二.架构拆分
2.1 LNMP架构拆分
```bash
Nginx请求动态数据的流程
[root@web01 conf.d]# cat wp.conf
server {
listen 80;
server_name www.wp.com;
root /code/wordpress;
location / {
index index.php index.html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
用户请求www.wp.com/ 则location /匹配返回index.php给浏览器
浏览器重新发起请求www.wp.com/index.php,正好匹配到第二个location 转发给PHP服务进行解析
2.2 数据库拆分流程

```bash
1.准备51服务器,安装mysql服务
[root@db01 ~]# yum -y install mariadb-server
2.启动数据库
[root@db01 ~]# systemctl start mariadb
3.web01导出数据库所有数据
[root@web01 ~]# mysqldump -uroot -plzy123.com -A > all.sql
检查导出的库是否正确
vim all.sql # 搜索下你发布的博文是否在sql语句
4.将all.sql拷贝到51服务器
[root@web01 ~]# scp all.sql 10.0.0.51:/root/
5.db51服务器将all.sql导入数据库
[root@db01 ~]# ll
total 2180
-rw-r--r-- 1 root root 2232120 Dec 11 09:23 all.sql
[root@db01 ~]# mysql -uroot < all.sql
[root@db01 ~]# systemctl restart mariadb
查看数据库信息
[root@db01 ~]# mysql -uroot -plzy123.com
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.3.39-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)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| wordpress |
| zh |
+--------------------+
5 rows in set (0.001 sec)
6.数据库为了安全,禁止root远程连接.必须使用普通账号进行远程连接
测试root远程连接
[root@web01 ~]# mysql -h172.16.1.51 -uroot -plzy123.com
ERROR 1130 (HY000): Host '172.16.1.7' is not allowed to connect to this MariaDB server
# 授权lzy普通账号密码为lzy123.com 管理所有库和所有的表
[root@db01 ~]# mysql -uroot -plzy123.com
MariaDB [(none)]> grant all on *.* to lzy@'%' identified by 'lzy123.com';
Query OK, 0 rows affected (0.001 sec)
测试lzy普通账号远程连接
[root@web01 ~]# mysql -h 172.16.1.51 -ulzy -plzy123.com
7.直接修改业务代码的数据信息指向到10.0.0.51
[root@web01 wordpress]# grep -r 'lzy123.com' ./*
./wp-config.php:define('DB_PASSWORD', 'lzy123.com');
#修改连接信息 主机信息172.16.1.51 远程连接用户 lzy 而不能使用root
[root@web01 wordpress]# grep -C6 'DB_USER' wp-config.php
// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
/** WordPress数据库的名称 */
define('DB_NAME', 'wordpress');
/** MySQL数据库用户名 */
define('DB_USER', 'lzy');
/** MySQL数据库密码 */
define('DB_PASSWORD', 'lzy123.com');
/** MySQL主机 */
define('DB_HOST', '172.16.1.51');
8.停止web01的数据库
[root@web01 ~]# systemctl stop mariadb
[root@web01 ~]# systemctl disable mariadb






2.3 静态数据共享
```bash
1.安装nfs服务
yum -y install nfs-utils
2.配置nfs服务
vim /etc/exports
/data/wp 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
创建目录和用户
groupadd -g666 www
useradd -u666 -g666 -M -s /sbin/nologin www
mkdir /code/wp -p
chown www.www /data/wp
3.启动nfs服务
systemctl start nfs
systemctl enable nfs
4.将完整的图片拷贝到31服务器
[root@web02 ~]# scp -r /code/wordpress/wp-content/uploads/* 10.0.0.31:/data/wp/
web服务器挂载nfs
web01:
[root@web01 ~]# mount -t nfs 172.16.1.31:/data/wp /code/wordpress/wp-content/uploads/
[root@web01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 459M 0 459M 0% /dev
tmpfs 475M 0 475M 0% /dev/shm
tmpfs 475M 43M 432M 9% /run
tmpfs 475M 0 475M 0% /sys/fs/cgroup
/dev/sda3 48G 4.3G 44G 9% /
tmpfs 475M 0 475M 0% /tmp
/dev/sda1 195M 122M 74M 63% /boot
tmpfs 95M 0 95M 0% /run/user/0
172.16.1.31:/data/wp 48G 3.8G 45G 8% /code/wordpress/wp-content/uploads
加入开机自动挂载
WEB02:
[root@web02 ~]# mount -t nfs 172.16.1.31:/data/wp /code/wordpress/wp-content/uploads/
[root@web02 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 459M 0 459M 0% /dev
tmpfs 475M 0 475M 0% /dev/shm
tmpfs 475M 6.8M 468M 2% /run
tmpfs 475M 0 475M 0% /sys/fs/cgroup
/dev/sda3 48G 4.1G 44G 9% /
tmpfs 475M 0 475M 0% /tmp
/dev/sda1 195M 122M 74M 63% /boot
tmpfs 95M 0 95M 0% /run/user/0
172.16.1.31:/data/wp 48G 3.8G 45G 8% /code/wordpress/wp-content/uploads
加入开机自动挂载
```


2.4 代理介绍



2.5 代理服务器配置
```bash
1.配置仓库
[root@lb01 ~]# scp 10.0.0.7:/etc/yum.repos.d/nginx.repo /etc/yum.repos.d/
2.安装nginx
[root@lb01 ~]# yum -y install nginx
3.配置代理
[root@lb01 conf.d]# vim lb.conf
server {
listen 80;
server_name www.wp.com;
location / {
proxy_pass http://10.0.0.7;
}
}
[root@lb01 conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@lb01 conf.d]# systemctl restart nginx
4.windowshosts指向到10.0.0.5
10.0.0.5 www.wp.com
```
2.6 配置负载均衡
```bash
[root@lb01 nginx]# vim conf.d/lb.conf
upstream webs {
server 172.16.1.7;
server 172.16.1.8;
}
server {
listen 80;
server_name www.wp.com;
location / {
proxy_pass http://webs;
include proxy_params;
}
}
[root@lb01 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@lb01 nginx]# systemctl restart nginx
```bash
[root@lb01 conf.d]# cat lb.conf
upstream webs {
server 172.16.1.7;
server 172.16.1.8;
}
server {
listen 80;
server_name www.wp.com;
location / {
proxy_pass http://webs;
include proxy_params;
}
}
server {
listen 80;
server_name www.test.com;
location / {
proxy_pass http://webs;
include proxy_params;
}
}
[root@lb01 conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@lb01 conf.d]# systemctl restart nginx
web01配置静态页面
[root@web01 conf.d]# cat test.conf
server {
listen 80;
server_name www.test.com;
location / {
root /code/test;
index index.html;
}
}
[root@web01 conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
snginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web01 conf.d]# systemctl restart nginx
[root@web01 conf.d]# mkdir /code/test
[root@web01 conf.d]# echo web01..... > /code/test/index.html
三.负载均衡-会话保持
3.1 NFS不能直接挂载

3.2 反向代理解析


3.3 负载均衡调度算法


3.4 Nginx编译安装

3.5 会话保持


3.6 部署phpmyadmin

3.7 配置PHP文件SESSION指向redis

3.8 配置phpRedis模块

3.9 负载均衡知识点小结

相关文章:
云计算架构学习之LNMP架构部署、架构拆分、负载均衡-会话保持
一.LNMP架构部署 1.1. LNMP服务搭建 1.磁盘信息 2.内存 3.负载信息 4.Nginx你们公司都用来干嘛 5.文件句柄(文件描述符 打开文件最大数量) 6.你处理过系统中的漏洞吗 SSH漏洞 7.你写过什么shell脚本 8.监控通过什么告警 zabbix 具体监控哪些内容 9.mysql redis查询 你好H…...
Python案例--暂停与时间格式化
在编程中,时间的处理是一个常见的需求。无论是日志记录、任务调度还是数据时间戳的生成,正确地获取和格式化时间都至关重要。Python 提供了强大的时间处理模块,其中 time 模块是基础且广泛使用的工具之一。本文将通过一个简单的示例ÿ…...
【javaweb项目idea版】蛋糕商城(可复用成其他商城项目)
该项目虽然是蛋糕商城项目,但是可以复用成其他商城项目或者购物车项目 想要源码的uu可点赞后私聊 技术栈 主要为:javawebservletmvcc3p0idea运行 功能模块 主要分为用户模块和后台管理员模块 具有商城购物的完整功能 基础模块 登录注册个人信息编辑…...
git gui 笔记
这里写目录标题 1. [下载安装git](https://blog.csdn.net/jiesunliu3215/article/details/111559125)2. [下载Git Gui](https://git-scm.com/downloads)3. 上传下载代码4. 创建版本5. 版本切换-checkout参考狂神说 git教程 -讲的是真的好gitee的git帮助 其他 1. 下载安装git 2…...
使用 Docker 运行 Oracle Database 23ai Free 容器镜像并配置密码与数据持久化
使用 Docker 运行 Oracle Database 23ai Free 容器镜像并配置密码与数据持久化 前言环境准备运行 Oracle Database 23ai Free 容器基本命令参数说明示例 注意事项高级配置参数说明 总结 前言 Oracle Database 23ai Free 是 Oracle 提供的免费版数据库,基于 Oracle …...
PyQt6医疗多模态大语言模型(MLLM)实用系统框架构建初探(下.代码部分)
医疗 MLLM 框架编程实现 本医疗 MLLM 框架结合 Python 与 PyQt6 构建,旨在实现多模态医疗数据融合分析并提供可视化界面。下面从数据预处理、模型构建与训练、可视化界面开发、模型 - 界面通信与部署这几个关键部分详细介绍编程实现。 6.1 数据预处理 在医疗 MLLM 框架中,多…...
salesforce公式字段 ISBLANK 函数和 <> NULL的区别
在 Salesforce 公式字段中,ISBLANK 函数和 <> NULL 的作用都可以用来检查字段是否有值,但它们的行为有一些显著的区别。以下是它们的详细对比和适用场景: 1. 基本区别 功能ISBLANK<> NULL主要作用检查字段是否为空(适…...
微服务学习-服务调用组件 OpenFeign 实战
1. OpenFeign 接口方法编写规范 1.1. 在编写 OpenFeign 接口方法时,需要遵循以下规范 1.1.1.1. 接口中的方法必须使用 RequestMapping、GetMapping、PostMapping 等注解声明 HTTP 请求的类型。 1.1.1.2. 方法的参数可以使用 RequestParam、RequestHeader、PathVa…...
关于安卓greendao打包时报错问题修复
背景 项目在使用greendao的时候,debug安装没有问题,一到打包签名就报了。 环境 win10 jdk17 gradle8 项目依赖情况 博主的greendao是一个独立的module项目,项目目前只适配了java,不支持Kotlin。然后被外部集成。greendao版本…...
Ansible自动化运维实战--通过role远程部署nginx并配置(8/8)
文章目录 1、准备工作2、创建角色结构3、编写任务4、准备配置文件(金甲模板)5、编写变量6、编写处理程序7、编写剧本8、执行剧本Playbook9、验证-游览器访问每台主机的nginx页面 在 Ansible 中,使用角色(Role)来远程部…...
RGB 转HSV空间颜色寻找色块
文章目录 前言一、绿色确定二、红色确定总结 前言 提示:这里可以添加本文要记录的大概内容: 项目需要: 将RGB颜色空间转换为HSV颜色空间以寻找颜色,主要基于以下几个原因: 直观性: HSV颜色空间更符合人类…...
Spring Boot - 数据库集成04 - 集成Redis
Spring boot集成Redis 文章目录 Spring boot集成Redis一:redis基本集成1:RedisTemplate Jedis1.1:RedisTemplate1.2:实现案例1.2.1:依赖引入和属性配置1.2.2:redisConfig配置1.2.3:基础使用 2&…...
C++红黑树详解
文章目录 红黑树概念规则为什么最长路径不超过最短路径的二倍?红黑树的时间复杂度红黑树的结构插入叔叔节点情况的讨论只变色(叔叔存在且为红)抽象的情况变色单旋(叔叔不存在或叔叔存在且为黑)变色双旋(叔叔不存在或叔叔存在且为黑…...
与机器学习相关的概率论重要概念的介绍和说明
概率论一些重要概念的介绍和说明 1、 试验 (1)试验是指在特定条件下,对某种方法、技术、设备或产品(即,事物)进行测试或验证的过程。 (2)易混淆的概念是,实验。实验&…...
60.await与sleep的原理分析 C#例子 WPF例子
在异步任务中使用Thread.Sleep会阻塞当前线程,因其是同步操作,暂停线程执行而不释放资源。这与异步编程旨在避免线程阻塞的目的相冲突。尽管异步方法可能包含其他await调用,Thread.Sleep仍会立即阻塞线程,妨碍其处理其他任务或响应…...
数据库连接池是如何工作的?
连接池是一种用于管理和复用连接(如数据库连接或网络连接)的技术,广泛应用于数据库操作和网络请求中,以提高应用程序的性能和资源利用率。以下是连接池的工作原理和机制的详细解释: 连接池的工作原理 1. 初始化阶段 在应用程序启动时,连接池会根据配置参数预先创建一定…...
2025年01月26日Github流行趋势
项目名称:onlook 项目地址url:https://github.com/onlook-dev/onlook项目语言:TypeScript历史star数:4871今日star数:207项目维护者:Kitenite, drfarrell, iNerdStack, abhiroopc84, apps/dependabot项目简…...
C语言的灵魂——指针(1)
指针是C语言的灵魂,有了指针C语言才能完成一些复杂的程序;没了指针就相当于C语言最精髓的部分被去掉了,可见指针是多么重要。废话不多讲我们直接开始。 指针 一,内存和地址二,编址三,指针变量和地址1&#…...
vue2和vue3指令
Vue 2 和 Vue 3 的指令系统非常相似,但 Vue 3 在指令方面进行了优化和扩展。以下是 Vue 2 和 Vue 3 中指令的对比: 1. 通用指令 这些指令在 Vue 2 和 Vue 3 中都可以使用,功能一致: 指令说明v-bind绑定 HTML 属性或组件 propsv-…...
【超详细】ELK实现日志采集(日志文件、springboot服务项目)进行实时日志采集上报
本文章介绍,Logstash进行自动采集服务器日志文件,并手把手教你如何在springboot项目中配置logstash进行日志自动上报与日志自定义格式输出给logstash。kibana如何进行配置索引模式,可以在kibana中看到采集到的日志 日志流程 logfile-> l…...
【位运算】消失的两个数字(hard)
消失的两个数字(hard) 题⽬描述:解法(位运算):Java 算法代码:更简便代码 题⽬链接:⾯试题 17.19. 消失的两个数字 题⽬描述: 给定⼀个数组,包含从 1 到 N 所有…...
1688商品列表API与其他数据源的对接思路
将1688商品列表API与其他数据源对接时,需结合业务场景设计数据流转链路,重点关注数据格式兼容性、接口调用频率控制及数据一致性维护。以下是具体对接思路及关键技术点: 一、核心对接场景与目标 商品数据同步 场景:将1688商品信息…...
学校招生小程序源码介绍
基于ThinkPHPFastAdminUniApp开发的学校招生小程序源码,专为学校招生场景量身打造,功能实用且操作便捷。 从技术架构来看,ThinkPHP提供稳定可靠的后台服务,FastAdmin加速开发流程,UniApp则保障小程序在多端有良好的兼…...
Keil 中设置 STM32 Flash 和 RAM 地址详解
文章目录 Keil 中设置 STM32 Flash 和 RAM 地址详解一、Flash 和 RAM 配置界面(Target 选项卡)1. IROM1(用于配置 Flash)2. IRAM1(用于配置 RAM)二、链接器设置界面(Linker 选项卡)1. 勾选“Use Memory Layout from Target Dialog”2. 查看链接器参数(如果没有勾选上面…...
Spring AI 入门:Java 开发者的生成式 AI 实践之路
一、Spring AI 简介 在人工智能技术快速迭代的今天,Spring AI 作为 Spring 生态系统的新生力量,正在成为 Java 开发者拥抱生成式 AI 的最佳选择。该框架通过模块化设计实现了与主流 AI 服务(如 OpenAI、Anthropic)的无缝对接&…...
【JavaSE】绘图与事件入门学习笔记
-Java绘图坐标体系 坐标体系-介绍 坐标原点位于左上角,以像素为单位。 在Java坐标系中,第一个是x坐标,表示当前位置为水平方向,距离坐标原点x个像素;第二个是y坐标,表示当前位置为垂直方向,距离坐标原点y个像素。 坐标体系-像素 …...
uniapp中使用aixos 报错
问题: 在uniapp中使用aixos,运行后报如下错误: AxiosError: There is no suitable adapter to dispatch the request since : - adapter xhr is not supported by the environment - adapter http is not available in the build 解决方案&…...
华硕a豆14 Air香氛版,美学与科技的馨香融合
在快节奏的现代生活中,我们渴望一个能激发创想、愉悦感官的工作与生活伙伴,它不仅是冰冷的科技工具,更能触动我们内心深处的细腻情感。正是在这样的期许下,华硕a豆14 Air香氛版翩然而至,它以一种前所未有的方式&#x…...
AI+无人机如何守护濒危物种?YOLOv8实现95%精准识别
【导读】 野生动物监测在理解和保护生态系统中发挥着至关重要的作用。然而,传统的野生动物观察方法往往耗时耗力、成本高昂且范围有限。无人机的出现为野生动物监测提供了有前景的替代方案,能够实现大范围覆盖并远程采集数据。尽管具备这些优势…...
安卓基础(Java 和 Gradle 版本)
1. 设置项目的 JDK 版本 方法1:通过 Project Structure File → Project Structure... (或按 CtrlAltShiftS) 左侧选择 SDK Location 在 Gradle Settings 部分,设置 Gradle JDK 方法2:通过 Settings File → Settings... (或 CtrlAltS)…...


