Centos8部署LNMP架构

LNMP架构

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

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

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@WSX

Re-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 -p

Enter password:    \\输入密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.13 Source distribution

Copyright (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

新增以下内容
<?php
    phpinfo();
?>

7.重启Nginx服务。

复制代码
systemctl restart nginx

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

相关推荐
Liang_GaRy41 分钟前
心路历程-三个了解敲开linux的大门
linux·运维·服务器
星霜笔记2 小时前
Docker 部署 MariaDB+phpMyAdmin+Nextcloud 完整教程
运维·数据库·docker·容器·mariadb
一只栖枝5 小时前
华为 HCIE 大数据认证中 Linux 命令行的运用及价值
大数据·linux·运维·华为·华为认证·hcie·it
wuicer7 小时前
ubuntu 20.04 安装anaconda以及安装spyder
linux·运维·ubuntu
小晶晶京京9 小时前
day34-LNMP详解
linux·运维·服务器
喂完待续9 小时前
Apache Hudi:数据湖的实时革命
大数据·数据仓库·分布式·架构·apache·数据库架构
fengyehongWorld10 小时前
Linux crontab定时任务
linux·运维
碎像10 小时前
Linux上配置环境变量
linux·运维·服务器
sunflower_w12 小时前
linux I2C核心、总线与设备驱动
linux·运维·服务器
myzzb12 小时前
基于uiautomation的自动化流程RPA开源开发演示
运维·python·学习·算法·自动化·rpa