Linux进阶-网站架构部署(LNMP)
网站架构部署LNMP
- 1)网站架构组成介绍
- 2)网站架构工作原理
- 3)服务部署过程
- 4)PHP部署过程
- 5)需要将LNMP架构进行串联
- 6)企业动态资源发布过程
1)网站架构组成介绍
LNMP:
L:Linux N:Nginx M:MySQL P:PHPNginx/Apache:需要重点阐述一下,它多用于网站用户访问,用HTML代码语言,在用户和网站中间起到起到桥梁的作用(网络服务搬运工),作为中间件发挥着不可提代的作用
Nginx/Apache通常可以直接识别静态资源文件(比如CSS(定义网页样式,排版),Js),也可以对动态资源文件(比如PHP,JAVA,Python,go)可以提供动态代码解析服务
2)网站架构工作原理
①用户发出网站服务请求
②服务端接收请求,并判断资源信息a.静态信息:由nginx静态网站服务进行处理,将站点目录中资源信息进行传输b.动态信息:nginx利用fastcgi接口转发给PHP服务
③PHP服务收到动态资源请求方式一:直接识别动态代码文件,进行翻译或者解析,转换成HTML代码信息方式二:和数据库建立连接,读取或存储数据信息,再将PHP代码转换成HTML代码进行响应
④nginx服务收到PHP响应HTML静态资源代码信息,再转发给浏览器
⑤客户端浏览器识别HTML信息,加载显示网站页面
3)服务部署过程
Linux中:/tmp/目录权限是1(t)777系统安全优化:yum优化
Nginx中:确定Nginx站点目录权限信息,属主权限设置好确认好Nginx配置信息,Nginx -t
4)PHP部署过程
第一个历程:确认系统是否已经存在了PHP相关程序
rpm -qa|grep php*
yum remove -y php-xxx(直接从第二历程开始演示)第二个历程:更新PHP软件下载源
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
[root@test-201 ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@test-201 ~]# yum install -y php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcryp
第三个历程:PHP程序相关软件下载安装
yum install -y php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb
[root@test-201 ~]# yum install -y php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb
PS:PHP编译安装过程(由于我yum安装,编译安装忽略)
https://www.cnblogs.com/ksy-c/p/12785238.html第四个历程:启动PHP程序服务
systemctl start php-fpm
确认服务是否启动:
1)查看服务进程信息 ps -ef|grep php
2)查看服务端口信息 netstat -lntup
[root@test-201 ~]# ps -ef|grep php
root 79315 1 0 10:04 ? 00:00:01 php-fpm: master process (/etc/php-fpm.conf)
apache 79316 79315 0 10:04 ? 00:00:00 php-fpm: pool www
apache 79317 79315 0 10:04 ? 00:00:00 php-fpm: pool www
apache 79318 79315 0 10:04 ? 00:00:00 php-fpm: pool www
apache 79319 79315 0 10:04 ? 00:00:00 php-fpm: pool www
apache 79320 79315 0 10:04 ? 00:00:00 php-fpm: pool www
root 79738 79697 0 16:23 pts/1 00:00:00 grep --color=auto php
[root@test-201 ~]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 79315/php-fpm: mast
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 8400/mysqld
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 76968/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 7127/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 7207/master
tcp6 0 0 :::22 :::* LISTEN 7127/sshd
tcp6 0 0 ::1:25 :::* LISTEN 7207/master
udp 0 0 127.0.0.1:323 0.0.0.0:* 6284/chronyd
udp6 0 0 ::1:323 :::* 6284/chronyd
TCP:传输控制协议 面向连接网络协议(可以保证数据传输可靠性) 用途:HTTP访问网站页面 FTP 邮件服务UDP:用户报文协议 无连接网络协议 (可以保证数据传输效率) 用途:DNS解析 视频通讯 语言通讯-l 列表显示端口和服务进程信息-n 以数字方式显示信息-t 显示tcp信息的端口和服务进程信息-u 显示udp信息的端口和服务进程信息-p 显示服务进程信息MySQL部署安装:简单方便 -- mariadbMysql==mariadb
第一个历程:安装程序软件
yum install -y mariadb mariadb-server
[root@test-201 ~]#yum install -y mariadb mariadb-server
第二个历程:启动数据库程序并简单配置
systemctl start mariadbmysqladmin -uroot password "oldboy123" --- 设置密码信息
drop database test; --- 删除无用数据库
delete from user where user=""; --- 删除无用数据库用户信息
[root@test-201 ~]# systemctl start mariadb
[root@test-201 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 5.5.65-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)]> quit
Bye
[root@test-201 ~]# mysqladmin -uroot password "oldboy123"
[root@test-201 ~]# mysql -uroot -poldboy123
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 5.5.65-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)]> show databases-> ;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.04 sec)MariaDB [(none)]> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
MariaDB [test]> drop databse test;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'databse test' at line 1
MariaDB [test]> drop database test;
Query OK, 4 rows affected (0.35 sec)MariaDB [(none)]> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| | test-201 |
| root | test-201 |
+------+-----------+
6 rows in set (0.05 sec)MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
MariaDB [mysql]> delete from user where user="";
Query OK, 2 rows affected (0.18 sec)MariaDB [mysql]> delete from user where host="::1";
Query OK, 1 row affected (0.27 sec)MariaDB [mysql]> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | localhost |
| root | test-201 |
+------+-----------+
3 rows in set (0.00 sec)MariaDB [mysql]> delete from user where host="test-201";
Query OK, 1 row affected (0.00 sec)
5)需要将LNMP架构进行串联
nginx 和 php进行串联
第一个历程:让nginx和php建立关系
server {listen 80 default_server;server_name bbs.oldboy.com;root /html/bbs;index index.php index.html; location ~ \.php$ { --- 匹配客户端访问php动态资源信息fastcgi_pass 127.0.0.1:9000; --- 将动态资源请求抛送给后端PHP程序root /html/bbs; --- 告知PHP程序,默认资源信息保存目录fastcgi_index index.php; --- 在PHP收到Nginx发送消息后,没有特殊指定动态资源文件,默认处理index.php首页文件fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; --- 可以精准告知PHP需要处理文件路径信息include fastcgi_params;}
}第二个历程:进行测试验证
在站点目录中,创建php动态代码文件
502 表示前段服务正常 nginx 但是后端服务不能接受前端服务请求php 和 数据库进行串联 -- 利用php代码进行串联
<?php$servername = "localhost";$username = "root";$password = "oldboy123";//$link_id=mysql_connect('主机名','用户','密码');//mysql -u用户 -p密码 -h 主机$conn = mysqli_connect($servername, $username, $password);if ($conn) {echo "mysql successful by root !\n";}else{die("Connection failed: " . mysqli_connect_error());}
?>
演示:
[root@test-201 /etc/nginx/conf.d]# cd /html/bbs
[root@test-201 /html/bbs]# vim test.php
[root@test-201 /html/bbs]# vim test.php
[root@test-201 /html/bbs]# ll /tmp/ -d
drwxrwxrwt. 12 root root 4096 Sep 29 11:30 /tmp/
[root@test-201 /html/bbs]# nginx -t
nginx: [emerg] directive "location" has no opening "{" in /etc/nginx/conf.d/bbs.conf:7
nginx: configuration file /etc/nginx/nginx.conf test failed
[root@test-201 /html/bbs]# vi bbs.conf
[root@test-201 /html/bbs]# cd /etc/nginx/conf.d/
[root@test-201 /etc/nginx/conf.d]# vi bbs.conf
[root@test-201 /etc/nginx/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@test-201 /etc/nginx/conf.d]# systemctl restart nginx
[root@test-201 /etc/nginx/conf.d]# cd /html/bbs/
[root@test-201 /html/bbs]# ls
index.html test.php
[root@test-201 /html/bbs]# cat test.php
<?php
phpinfo();
?>
[root@test-201 /html/bbs]# systemctl start php-fpm
[root@test-201 /html/bbs]# cd /etc/nginx/conf.d/
[root@test-201 /etc/nginx/conf.d]# cat bbs.confserver { listen 80; #指定服务监听端口信息 用于接收用户访问请求server_name bbs.oldboy.com; #指定网站域名信息root /html/bbs; #指定服务站点目录index index.php index.html; #指定首页文件信息 会进行默认加载location ~ \.php$ { #匹配客户端访问php动态资源信息fastcgi_pass 127.0.0.1:9000; #将动态资源请求抛送给后端PHP程序root /html/bbs; #告知PHP程序,默认资源信息保存目录fastcgi_index index.php; #在PHP收到Nginx发送消息后,没有特殊指定动态资源文件,默认处理index.php首页文件fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #可以精准告知PHP需要处理文件路径信息include fastcgi_params; }
}
[root@test-201 /etc/nginx/conf.d]#
第二个历程:进行测试验证
在站点目录中,创建php动态代码文件
502 表示前段服务正常 nginx 但是后端服务不能接受前端服务请求php 和 数据库进行串联 -- 利用php代码进行串联
<?php$servername = "localhost";$username = "root";$password = "oldboy123";//$link_id=mysql_connect('主机名','用户','密码');//mysql -u用户 -p密码 -h 主机$conn = mysqli_connect($servername, $username, $password);if ($conn) {echo "mysql successful by root !\n";}else{die("Connection failed: " . mysqli_connect_error());}
?>
演示:
[root@test-201 /etc/nginx/conf.d]# cd /html/bbs/
[root@test-201 /html/bbs]# cat test.php
[root@test-201 /html/bbs]# vim test_mysql.php
[root@test-201 /html/bbs]# cat test_mysql.php
<?php$servername = "localhost";$username = "root";$password = "oldboy123";//$link_id=mysql_connect('主机名','用户','密码');//mysql -u用户 -p密码 -h 主机$conn = mysqli_connect($servername, $username, $password);if ($conn) {echo "mysql successful by root !\n";}else{die("Connection failed: " . mysqli_connect_error());}
?>i
6)企业动态资源发布过程
第一个历程:获取网站动态资源代码 上传解压
[root@test-201 /html/bbs]# unzip Discuz_X3.4_SC_UTF8【20200818】.zip
第二个历程:进行网站初始化过程 (开源)
环境检查过程 需求进行指定目录授权 chown
创建库和用户过程 创库sql 授权sql
[root@test-201 /html/bbs]# cd upload/
[root@test-201 /html/bbs/upload]# vi /etc/nginx/conf.d/bbs.conf
[root@test-201 /html/bbs/upload]# cat /etc/nginx/conf.d/bbs.confserver { listen 80; #指定服务监听端口信息 用于接收用户访问请求server_name bbs.oldboy.com; #指定网站域名信息root /html/bbs/upload; #指定服务站点目录index index.php index.html; #指定首页文件信息 会进行默认加载location ~ \.php$ {fastcgi_pass 127.0.0.1:9000;root /html/bbs/upload;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params; }
}
[root@test-201 /html/bbs/upload]# systemctl restart nginx
选择我同意
修改允许上传文件最大值
[root@test-201 /html/bbs/upload]# vi /etc/php.ini
[root@test-201 /html/bbs/upload]# systemctl restart php-fpm
修改目录文件属主权限
[root@test-201 /html/bbs/upload]# ll config/ -d
drwxr-xr-x 2 root root 90 Aug 18 23:35 config/
[root@test-201 /html/bbs/upload]# chown -R apache.apache config/
[root@test-201 /html/bbs/upload]# ll config/
total 20
-rw-r--r-- 1 apache apache 10028 Aug 18 23:36 config_global_default.php
-rw-r--r-- 1 apache apache 1663 Aug 18 23:36 config_ucenter_default.php
-rw-r--r-- 1 apache apache 1 Aug 18 23:36 index.htm
[root@test-201 /html/bbs/upload]# vim /etc/nginx/nginx.conf
[root@test-201 /html/bbs/upload]# systemctl restart nginx
[root@test-201 /html/bbs/upload]# ps -ef|grep nginx
root 80326 1 0 20:03 ? 00:00:00 nginx: master process /usr/sbin/nginx
apache 80327 80326 0 20:03 ? 00:00:00 nginx: worker process
root 80329 78844 0 20:04 pts/0 00:00:00 grep --color=auto nginx
[root@test-201 /html/bbs/upload]# chown -R apache.apache data/
[root@test-201 /html/bbs/upload]# chown -R apache.apache uc_server/
[root@test-201 /html/bbs/upload]# chown -R apache.apache uc_client/
[root@test-201 /html/bbs/upload]#
其中 vim /etc/nginx/nginx.conf修改的内容为:
然后点击下一步
创建bbs数据库,用户,密码
[root@test-201 /html/bbs/upload]# mysql -uroot -poldboy123
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 28
Server version: 5.5.65-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)]> create database bbs;
Query OK, 1 row affected (0.00 sec)MariaDB [(none)]> grant all on bbs.* to 'bbs'@'localhost' identified by 'oldboy123';
Query OK, 0 rows affected (0.10 sec)MariaDB [(none)]> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| bbs | localhost |
| root | localhost |
+------+-----------+
3 rows in set (0.00 sec)MariaDB [(none)]> select user,host,password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host | password |
+------+-----------+-------------------------------------------+
| root | localhost | *FE28814B4A8B3309DAC6ED7D3237ADED6DA1E515 |
| bbs | localhost | *FE28814B4A8B3309DAC6ED7D3237ADED6DA1E515 |
| root | 127.0.0.1 | |
+------+-----------+-------------------------------------------+
3 rows in set (0.00 sec)MariaDB [(none)]> quit
Bye
[root@test-201 /html/bbs/upload]# mysql -ubbs -poldboy123;
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 29
Server version: 5.5.65-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)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| bbs |
+--------------------+
2 rows in set (0.00 sec)MariaDB [(none)]>
第三个历程:测试访问看看
测试能不能发帖
发布成功,奈斯!
Linux进阶-网站架构部署(LNMP)相关推荐
- Nginx架构篇(一)动态网站架构、LNMP、FastCGI、nginx+fastcgi运行原理
一.动态网站架构 资源文件识别 语言识别 框架识别 index.php 开源的php Window/Linux+nginx+php+mysql index.py 开源的python Window/Li ...
- 大型网站 linux,大型网站架构演变
之前也有一些介绍大型网站架构演变的文章,例如LiveJournal的.ebay的,都是非常值得参考的,不过感觉他们讲的更多的是每次演变的结果,而没有很详细的讲为什么需要做这样的演变,再加上近来感觉有不 ...
- 综合架构-网站架构LNMP
综合架构-网站架构LNMP 网站的LNMP架构是什么 网站的LNMP架构部署 LNMP架构原理 实现LNMP之间建立关系 部署搭建网站页面(代码上线) 关于LNMP的疑问 网站的LNMP架构是什么 L ...
- 项目:部署LNMP动态网站
部署LNMP动态网站 问题 部署LNMP动态网站,实现以下目标: 安装LNMP平台相关软件 配置Nginx实现动静分离 配置数据库,创建账户与密码 上线Wordpress代码 使用Wordpress后 ...
- 第20章 使用LNMP架构部署动态网站环境
章节概述: 本章节将从Linux系统的软件安装方式讲起,带领读者分辨RPM软件包与源码安装的区别.并能够理解它们的优缺点. Nginx是一款相当优秀的用于部署动态网站的服务程序,Nginx具有不错的稳 ...
- Nginx网站服务与LNMP架构部署(详解)
Nginx网站服务与LNMP架构部署 1.Nginx服务基础 2.编译安装Ngiax 3.Nginx的运行控制 4.配置文件nginx.conf 5.Nginx虚拟主机 6.LNMP架构部署 1.源码 ...
- CentOS 6.7 源码搭建LNMP架构部署动态网站环境
源码搭建LNMP架构部署动态网站环境 Nginx 简介 Nginx是一款相当优秀的用于部署动态网站的服务程序,Nginx具有不错的稳定性.丰富的功能以及占用较少的系统资源等独特特性. Nginx (& ...
- LinuxProbe 0x20 使用LNMP架构部署动态网站环境
LNMP动态网站部署架构是一套由Linux + Nginx + MySQL + PHP组成的动态网站系统解决方案,具有免费.高效.扩展性强且资源消耗低等优良特性,目前正在被广泛使用. 源码包程序 在R ...
- Linux云计算架构-使用LNMP架构部署Discuz论坛
文章目录 Linux云计算架构-使用LNMP架构部署Discuz论坛 1. 配置LNMP环境 2. 安装Discuz_X3.4 Linux云计算架构-使用LNMP架构部署Discuz论坛 1. 配置L ...
最新文章
- 怎么样做一个合格而又可爱的面试官
- 【Netty】传输(Transport)
- 程序、进程、线程的关系
- vue 修改模板{{}}标签_详解Vue 动态添加模板的几种方法
- 126. Word Ladder II
- static关键字 void和void指针 函数指针
- 利用mongodb开发lbs应用实践【转】
- 网页上使用按键代替鼠标点击按钮
- Goonie企业竞争情报系统评为选中国优秀网络应用软件奖
- Unspeakable joy : rejoicing in early modern England【翻译】
- SwiftUI 如何同时处理2个手势SimultaneousGesture(教程含代码)
- 第八篇 :微信公众平台开发实战Java版之如何网页授权获取用户基本信息
- android pppd参数介绍,android 3G pppd 调试记录
- 一起自学SLAM算法:8.1 Gmapping算法
- npm包本地离线安装
- 在线Json转Dart
- 【Unity】Mesh网格编程(三)万能网格几何形体
- 微信小程序获取实时定位(记录)
- C#毕业设计——基于C#+asp.net+sqlserver的网络商店销售管理系统设计与实现(毕业论文+程序源码)——销售管理系统
- 一个关于android旋转屏幕界面的方法
热门文章
- 燕麦云何洋开讲|《我的前半生》是燕麦云的宣传片?!
- Java 被黑的最惨的一次
- html表格最大显示行数6,table表格(支持条件格式、排序、格式化、链接、统计等一堆功能)...
- php生成word设置纸张,PHP生成Word文档的方法
- 基础复习十五、网络编程(2)
- .Net验证15位身份证格式
- 2022-2027年中国樱桃种植及深加工行业发展监测及投资战略研究报告
- 【计算机科学】和【软件工程】有什么区别?就业前景如何?
- 查找Active Directory域账号频繁锁定的原因
- 自学日记:设计模式-工厂模式