一.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
\`\`\`


### 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 浏览器访问业务 \`\`\`


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 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 \| +--------------------+
\`\`\`

## 



## 二.架构拆分
### 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




### 


### 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 代理服务器配置
### 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 负载均衡知识点小结