云计算架构学习之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.oldboy.com/mysql.php \`\`\` ![](https://i-blog.csdnimg.cn/direct/3599e69f09664398941f1edae568e7e7.png) ![](https://i-blog.csdnimg.cn/direct/2b531e8a81ec42e6be4c1f7523769be0.png) ### 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-zh*CN.tar.gz \[root@web01 wordpress\]# tar xf wordpress-5.0.3-zh*CN.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 浏览器访问业务 \`\`\` ![](https://i-blog.csdnimg.cn/direct/e1c24e782c3c42058cd489c0893e4c73.jpeg) ![](https://i-blog.csdnimg.cn/direct/8edc26cacdf54ae2889c321a13707bdf.png) vim /etc/php-fpm.d/www.conf ![](https://i-blog.csdnimg.cn/direct/02db5fdac1a34fdb93b604554364ad19.png) ![](https://i-blog.csdnimg.cn/direct/76debbd67dda46e7b593f29fa171e5d5.jpeg) ### 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 WeCenter*V3.6.2.zip \[root@web01 zh\]# unzip WeCenter*V3.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 \| +--------------------+ \| information*schema \| \| mysql \| \| performance*schema \| \| wordpress \| \| zh \| +--------------------+ \`\`\` ![](https://i-blog.csdnimg.cn/direct/e9e85be9b3024bdb8dababa422a3b431.png) ## ![](https://i-blog.csdnimg.cn/direct/5324156a66dd48068748586d8bf3f7c3.png) ![](https://i-blog.csdnimg.cn/direct/4bdd79bf9059402181957e55cb617218.png) ![](https://i-blog.csdnimg.cn/direct/bc91632ac2ce4323b60a1cfcc5d4a37e.png) ![](https://i-blog.csdnimg.cn/direct/61218362900d4349bfc2166c2913fe7b.png) ## 二.架构拆分 ### 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 数据库拆分流程 !\[image-20241211090739833\](day35-%E6%9E%B6%E6%9E%84%E6%8B%86%E5%88%86.assets/image-20241211090739833.png) \`\`\`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 ![](https://i-blog.csdnimg.cn/direct/d541a71423e64a68bcf9a46e87b0804c.png) ![](https://i-blog.csdnimg.cn/direct/1282c7733da947b78afba984e27ca8e4.png) ![](https://i-blog.csdnimg.cn/direct/478903be4c7640f39d16fccd6ee4f9a6.png) ![](https://i-blog.csdnimg.cn/direct/35482f31588f47c2baf9b812e3392c70.png) ### ![](https://i-blog.csdnimg.cn/direct/bee87dcd25c9473ab5fe95d9522e8ce9.png) ![](https://i-blog.csdnimg.cn/direct/73e3fa94148a4542b02937adab1722e8.png) ![](https://i-blog.csdnimg.cn/direct/2dacd52b39dc4a70987382b81b1239f7.png) ### 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 加入开机自动挂载 \`\`\` ![](https://i-blog.csdnimg.cn/direct/88c8d2efcc3241969020d07960f04750.png) ![](https://i-blog.csdnimg.cn/direct/baf08858d9144b0f84b518a7aaefce06.png) ### 2.4 代理介绍 ### 2.5 代理服务器配置 ### 2.6 配置负载均衡 ### 三.负载均衡-会话保持 ### 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 负载均衡知识点小结

相关推荐
Z字小熊饼干爱吃保安8 分钟前
nginx介绍和几种安装方法
linux·运维·nginx·云计算
s_little_monster28 分钟前
【Linux】线程控制函数
linux·运维·服务器·经验分享·笔记·学习·学习方法
十年之少31 分钟前
粘性定位(position:sticky)——微信小程序学习笔记
笔记·学习·微信小程序
人不走空1 小时前
Kubernetes核心架构:从组件协同到工作原理
云原生·架构·k8s
姝孟1 小时前
Linux学习笔记 1
linux·笔记·学习
AWS官方合作商1 小时前
基于AWS的大模型调用场景:10大成本优化实战方案
云计算·gpu算力·aws
dg10112 小时前
go-zero学习笔记(六)---gozero中间件介绍
笔记·学习·golang
一个天蝎座 白勺 程序猿2 小时前
大数据(7.4)Kafka存算分离架构深度实践:解锁对象存储的无限潜能
大数据·架构·kafka
Dovis(誓平步青云)3 小时前
【数据结构】排序算法(下篇·终结)·解析数据难点
c语言·数据结构·学习·算法·排序算法·学习方法·推荐算法
苜柠6 小时前
Shell脚本的学习
学习