• 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)配置本地源文件;

    1. vi /etc/yum.repos.d/base.repo #使用vi编辑器编辑本地源文件
    2. [base-app]
    3. name=base-app
    4. baseurl=file:///mnt/cdrom/BaseOS
    5. enabled=1
    6. gpgcheck=0
    7. [base-AppStream]
    8. name=base-AppStream
    9. baseurl=file:///mnt/cdrom/AppStream
    10. enabled=1
    11. gpgcheck=0

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

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

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

    1. dnf clean all
    2. 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服务开机自启;

    1. systemctl enable --now nginx
    2. systemctl start nginx

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

    1. systemctl enable --now mysqld
    2. systemctl start mysqld

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

    1. systemctl enable --now php-fpm
    2. systemctl start php-fpm

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

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

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

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

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

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

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

    1. vim /etc/nginx/nginx.conf
    2. 找到location / {}该行,修改成以下内容:
    3. location / {
    4. root html;
    5. index index.php index.html index.htm;
    6. }
    7. location ~ \.php$ {
    8. root html;
    9. fastcgi_index index.php;
    10. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    11. fastcgi_pass 127.0.0.1:9000;
    12. include fastcgi_params;
    13. }

    6.编辑PHP界面文件。

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

    cd /usr/share/nginx/html/

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

    1. vim index.php
    2. 新增以下内容
    3. phpinfo();
    4. ?>

    7.重启Nginx服务。

    systemctl restart nginx

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

  • 相关阅读:
    线上接口流量突增,快要扛不住了
    LabVIEW编程LabVIEW开发吉时利Keithley 7001开关例程与相关资料
    CS云函数及上线提醒
    Arcgis进阶篇(1)——安装Arcgis Enterprise,创建sde库
    数字孪生助力智慧城市、楼宇、园区场景数字化系统建设
    【大画数据结构】第二话 —— 无头单链表的基本操作
    AJAX之数据交换
    Gen-AI时代天下英雄谁主沉浮?赛场见!卷起来!
    云e办(后端)——邮件发送(员工入职时发送邮件)
    ABAP学习笔记之——第四章:模块化程序
  • 原文地址:https://blog.csdn.net/weixin_47460431/article/details/134473186