当前位置: 首页 > news >正文

Centos8部署LNMP架构

LNMP架构

        LNMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写。L指Linux,N指Nginx,M一般指MySQL,也可以指MariaDB,P一般指PHP,也可以指Perl或Python。

1.Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。代表版本有:debian、centos、ubuntu、fedora、gentoo等。

2.Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。

3.Mysql是一个小型关系型数据库管理系统。

4.PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。

这四种软件均为免费开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统。

部署过程

1.初始化Centos8虚拟机系统。

(1)通过命令挂载Centos8操作镜像;

mount /dev/cdrom /mnt/cdrom

(2)配置本地源文件;

vi /etc/yum.repos.d/base.repo   #使用vi编辑器编辑本地源文件[base-app]
name=base-app
baseurl=file:///mnt/cdrom/BaseOS
enabled=1
gpgcheck=0[base-AppStream]
name=base-AppStream
baseurl=file:///mnt/cdrom/AppStream
enabled=1
gpgcheck=0

(3)创建备份源目录,将/etc/yum.repos.d下以Centos-*开头的源文件移动至备份源目录;

mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/Centos-*  /etc/yum.repos.d/bak/

(4)使用dnf命令清理,再加载缓存;

dnf clean all
dnf makecache

2.安装LNMP架构基础服务。

        由于Centos8上可以直接通过dnf/yum命令对Nginx、MySQL、PHP服务进行安装,本文中将直接使用本地安装。

(1)使用dnf命令安装Nginx;

dnf install -y nginx

(2)使用dnf命令安装MySQL;

dnf install -y mysql*

(3)使用dnf命令安装PHP及依赖包;

dnf install -y php php-fpm

3.通过systemctl命令设置服务开机自启。

(1)通过systemctl命令设置Nginx服务开机自启;

systemctl enable --now nginx
systemctl start nginx

(2)通过systemctl命令启动Mysql服务,并设置开机自启;

systemctl enable --now mysqld
systemctl start mysqld

(3)通过systemctl命令启动并设置PHP服务开机自启;

systemctl enable --now php-fpm
systemctl start php-fpm

4.设置MySQL数据服务器配置。

(1)初始化数据库,将密码设置为'1qaz@WSX';

mysql_secure_installation     \\初始化mysqld服务New password:     \\输入1qaz@WSXRe-enter new password: Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.Remove anonymous users? (Press y|Y for Yes, any other key for No) : ... skipping.Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.Disallow root login remotely? (Press y|Y for Yes, any other key for No) : ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.Remove test database and access to it? (Press y|Y for Yes, any other key for No) : ... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.Reload privilege tables now? (Press y|Y for Yes, any other key for No) : ... skipping.
All done! 

(2)测试连接数据库,成功进入数据库服务器;

mysql -uroot -pEnter password:    \\输入密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.13 Source distributionCopyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> 

5.配置Nginx与PHP间的连接。

(1)使用vim编辑器编辑Nginx服务的主配置文件;

vim /etc/nginx/nginx.conf找到location / {}该行,修改成以下内容:location / {root html;index index.php index.html index.htm;}location ~ \.php$ {root    html;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;fastcgi_pass  127.0.0.1:9000;include       fastcgi_params;}

6.编辑PHP界面文件。

(1)使用cd命令切换至/usr/share/nginx/html目录下;

cd /usr/share/nginx/html/

(2)使用vim编辑器编辑index.php网站页面;

vim index.php新增以下内容
<?phpphpinfo();
?>

7.重启Nginx服务。

systemctl restart nginx

8.在浏览器上输入IP地址,出现PHP页面,代表LNMP架构搭建成功。

相关文章:

  • php使用Session实现简单购物车功能
  • git commmit type格式
  • 小程序静默授权获取unionid
  • Jenkins 配置节点交换内存
  • java:简单入门定时任务的几种方式Timer、Quartz、Spring Task
  • 隐式类型转化
  • 使用Arrays.asList与不使用的区别
  • 2-Python与设计模式--工厂类相关模式
  • docker通过挂载conf文件启动redis
  • 【传智杯】儒略历、评委打分、萝卜数据库题解
  • 【开源】基于JAVA的车险自助理赔系统
  • LeetCode Hot100 108.将有序数组转为二叉搜索树
  • CSS画一条线
  • IDEA不支持Java8了怎么办?
  • maven打包项目,然后给其他项目引用
  • [原]深入对比数据科学工具箱:Python和R 非结构化数据的结构化
  • android高仿小视频、应用锁、3种存储库、QQ小红点动画、仿支付宝图表等源码...
  • Codepen 每日精选(2018-3-25)
  • HTTP--网络协议分层,http历史(二)
  • PhantomJS 安装
  • python学习笔记-类对象的信息
  • spring boot下thymeleaf全局静态变量配置
  • ubuntu 下nginx安装 并支持https协议
  • vue 配置sass、scss全局变量
  • 海量大数据大屏分析展示一步到位:DataWorks数据服务+MaxCompute Lightning对接DataV最佳实践...
  • 快速构建spring-cloud+sleuth+rabbit+ zipkin+es+kibana+grafana日志跟踪平台
  • 前端面试之闭包
  • 少走弯路,给Java 1~5 年程序员的建议
  • 实现简单的正则表达式引擎
  • puppet连载22:define用法
  • ​【C语言】长篇详解,字符系列篇3-----strstr,strtok,strerror字符串函数的使用【图文详解​】
  • ​ubuntu下安装kvm虚拟机
  • # MySQL server 层和存储引擎层是怎么交互数据的?
  • #常见电池型号介绍 常见电池尺寸是多少【详解】
  • $.ajax()方法详解
  • (Matalb时序预测)WOA-BP鲸鱼算法优化BP神经网络的多维时序回归预测
  • (编译到47%失败)to be deleted
  • (蓝桥杯每日一题)平方末尾及补充(常用的字符串函数功能)
  • (六)Hibernate的二级缓存
  • (论文阅读23/100)Hierarchical Convolutional Features for Visual Tracking
  • (收藏)Git和Repo扫盲——如何取得Android源代码
  • (四)Tiki-taka算法(TTA)求解无人机三维路径规划研究(MATLAB)
  • (算法)Travel Information Center
  • (淘宝无限适配)手机端rem布局详解(转载非原创)
  • (学习日记)2024.03.25:UCOSIII第二十二节:系统启动流程详解
  • (转)【Hibernate总结系列】使用举例
  • (转)3D模板阴影原理
  • (转)IIS6 ASP 0251超过响应缓冲区限制错误的解决方法
  • (轉貼) VS2005 快捷键 (初級) (.NET) (Visual Studio)
  • .bat文件调用java类的main方法
  • .NET Framework 3.5中序列化成JSON数据及JSON数据的反序列化,以及jQuery的调用JSON
  • .Net Memory Profiler的使用举例
  • .NET 事件模型教程(二)
  • .Net转前端开发-启航篇,如何定制博客园主题
  • ??如何把JavaScript脚本中的参数传到java代码段中