首页 > 其他分享 >LNMP构建

LNMP构建

时间:2022-09-04 01:13:24浏览次数:53  
标签:-- LNMP nginx 构建 mysql php root localhost

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

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

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

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

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

准备环境,关闭防火墙,selinux,配好yum源

 

部署nginx

 

 

 

 

# 下载nginx
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://nginx.org/download/nginx-1.22.0.tar.gz

# 下载 依赖包
[root@localhost src]# dnf -y install pcre-devel openssl openssl-devel gd-devel  gcc gcc-c++ make
[root@localhost ~]# yum -y groups mark install 'Development Tools'  #包组可以下也可以不下

# 创建系统用户
[root@localhost src]# useradd -r -M -s /sbin/nologin nginx
[root@localhost src]# id nginx
uid=994(nginx) gid=991(nginx) groups=991(nginx)

# 创建日志存放目录
[root@localhost ~]# mkdir -p /var/log/nginx
[root@localhost ~]# chown -R nginx.nginx /var/log/nginx/
[root@localhost ~]# ll -d /var/log/nginx/
drwxr-xr-x 2 nginx nginx 6 Sep  4 06:40 /var/log/nginx/

# 编译安装
[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
debug  kernels  nginx-1.22.0.tar.gz
[root@localhost src]# tar xf nginx-1.22.0.tar.gz   # 解压
[root@localhost src]# ls
debug  kernels  nginx-1.22.0  nginx-1.22.0.tar.gz  
[root@localhost src]# cd nginx-1.22.0    #进到解压目录
[root@localhost nginx-1.22.0]# ./configure \   
 --prefix=/usr/local/nginx \
 --user=nginx \
 --group=nginx \
 --with-debug \
 --with-http_ssl_module \
 --with-http_realip_module \
 --with-http_image_filter_module \
 --with-http_gunzip_module \
 --with-http_gzip_static_module \
 --with-http_stub_status_module \
 --http-log-path=/var/log/nginx/access.log \
 --error-log-path=/var/log/nginx/error.log
[root@localhost nginx-1.22.0]# nproc   # 查看核心数
1
[root@localhost nginx-1.22.0]# make && make install

#设置环境变量
[root@localhost nginx-1.22.0]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh  #设置环境变量
[root@localhost nginx-1.22.0]# source /etc/profile.d/nginx.sh  # 读一下这个文件
[root@localhost nginx-1.22.0]# which nginx   #此时就可以找到它了
/usr/local/nginx/sbin/nginx

# 启动 nginx
[root@localhost nginx-1.22.0]# nginx
[root@localhost nginx-1.22.0]# ss -antl
State     Recv-Q    Send-Q       Local Address:Port        Peer Address:Port    Process
LISTEN    0         128                0.0.0.0:80               0.0.0.0:*
LISTEN    0         128                0.0.0.0:22               0.0.0.0:*
LISTEN    0         128                   [::]:22                  [::]:*

//服务控制方式,使用nginx命令
    -t  //检查配置文件语法
    -v  //输出nginx的版本
    -c  //指定配置文件的路径
    -s  //发送服务控制信号,可选值有{stop|quit|reopen|reload}

[root@localhost nginx-1.22.0]# vim /usr/local/nginx/conf/nginx.conf   # 进到主配置文件
#取消注释,开启反向代理
location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME   /$document_root$fastcgi_script_name;  #此行修改
            include        fastcgi_params;
        }


# 配置 PHP 网页
[root@localhost nginx-1.22.0]# cd /usr/local/nginx/html/
[root@localhost html]# ls
50x.html  index.html
[root@localhost html]# vim index.php

<?php
        phpinfo();
?>

#停掉以后在重新启动
[root@localhost html]# nginx -s stop;nginx
[root@localhost html]# nginx -s reload
[root@localhost html]# ss -antl
State     Recv-Q    Send-Q       Local Address:Port        Peer Address:Port    Process
LISTEN    0         128                0.0.0.0:80               0.0.0.0:*
LISTEN    0         128                0.0.0.0:22               0.0.0.0:*
LISTEN    0         128                   [::]:22                  [::]

# 设置开机自启
[root@localhost html]# cd /usr/lib/systemd/system
[root@localhost system]# cp sshd.service nginxd.service
[root@localhost system]#  vim nginxd.service
[Unit]
Description=nginx server daemon
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

# 设置开机自启
[root@localhost system]# systemctl daemon-reload  #读取一下
[root@localhost ~]# systemctl enable --now nginxd  # 设置开机自启
[root@localhost ~]# systemctl status nginxd
● nginxd.service - nginx server daemon
   Loaded: loaded (/usr/lib/systemd/system/nginxd.service; enabled; vendor preset: disable>
   Active: active (running) since Sun 2022-09-04 07:14:01 CST; 11s ago
  Process: 26939 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=0/SUCCESS)
 Main PID: 26940 (nginx)
    Tasks: 2 (limit: 11202)
   Memory: 2.5M
   CGroup: /system.slice/nginxd.service
           ├─26940 nginx: master process /usr/local/nginx/sbin/nginx
           └─26941 nginx: worker process

 

 

 部署mysql

 

 

 

 

 

 

 

 

 

 

# 安装依赖包
[root@localhost ~]# dnf -y install ncurses-compat-libs openssl-devel openssl cmake mariadb-devel

# 创建mysql系统用户
[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql
[root@localhost ~]# id mysql
uid=993(mysql) gid=990(mysql) groups=990(mysql)

# 把提前下载好的包拖进来
[root@localhost ~]# ls
anaconda-ks.cfg  mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz
[root@localhost ~]# mv mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz /usr/src/
[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
debug    mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz  nginx-1.22.0.tar.gz
kernels  nginx-1.22.0

# 解压软件至/usr/local/
[root@localhost src]# tar xf mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz -C /usr/local/
[root@localhost src]# cd /usr/local/
[root@localhost local]# ls
bin  games    lib    libexec                              nginx  share
etc  include  lib64  mysql-8.0.12-linux-glibc2.12-x86_64  sbin   src
[root@localhost local]# mv mysql-8.0.12-linux-glibc2.12-x86_64 mysql
[root@localhost local]# ll -d mysql/
drwxr-xr-x 9 root root 129 Sep  4 07:29 mysql/

# 修改目录/usr/local/mysql的属主属组
[root@localhost local]# chown -R mysql.mysql mysql
[root@localhost local]# ll -d mysql/
drwxr-xr-x 9 mysql mysql 129 Sep  4 07:29 mysql/

# 添加环境变量
[root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost local]# source /etc/profile.d/mysql.sh   #读取一下这文件,也可以用. /etc/profile.d/mysql.sh的方式
[root@localhost local]# which mysqld
/usr/local/mysql/bin/mysqld

# 配置include
[root@localhost local]# ln -s /usr/local/mysql/include /usr/include/mysql

# 配置 man 文档
[root@localhost local]# vim /etc/man_db.conf
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/mysql/man  # 加入此行

# 映射库文件
[root@localhost local]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@localhost local]# ldconfig   #让它生效

# 建立数据存放目录
[root@localhost local]# mkdir -p /opt/data 
[root@localhost local]# cd
[root@localhost ~]# chown -R mysql.mysql /opt/data/  #更改属主属组为mysql
[root@localhost ~]# ll /opt/data/ -d
drwxr-xr-x 2 mysql mysql 6 Sep  4 07:38 /opt/data/

# 初始化数据库
[root@localhost ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
2022-09-03T23:40:05.023692Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.12) initializing of server in progress as process 27491
2022-09-03T23:40:05.833844Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: sdWqHF.lP8!u
2022-09-03T23:40:06.304126Z 0 [System] [MY-013170] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.12) initializing of server has completed
零时密码:sdWqHF.lP8!u

# 生成配置文件
[root@localhost ~]# vim /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve

# 配置服务启动脚本
[root@localhost ~]# cd /usr/local/mysql/support-files/
[root@localhost support-files]# cp mysql.server /etc/init.d/mysqld
[root@localhost support-files]# ll /etc/init.d/mysqld
-rwxr-xr-x 1 root root 10576 Sep  4 07:42 /etc/init.d/mysqld

# 设置所有者所属组为mysql
[root@localhost support-files]# chown -R mysql.mysql  /etc/init.d/mysqld
[root@localhost support-files]# ll /etc/init.d/mysqld
-rwxr-xr-x 1 mysql mysql 10576 Sep  4 07:42 /etc/init.d/mysqld

# 
[root@localhost ~]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/opt/data

#设置开机自启
[root@localhost ~]# chkconfig --add mysqld  #添加mysqld要开机自启
[root@localhost ~]# chkconfig mysqld on   #打开mysqld开机自启的功能
[root@localhost ~]# service mysqld start   # 启动
Starting MySQL.Logging to '/opt/data/localhost.localdomain.err'.
 SUCCESS!
[root@localhost ~]# ss -antl
State     Recv-Q    Send-Q       Local Address:Port        Peer Address:Port    Process
LISTEN    0         128                0.0.0.0:80               0.0.0.0:*
LISTEN    0         128                0.0.0.0:22               0.0.0.0:*
LISTEN    0         70                       *:33060                  *:*
LISTEN    0         128                      *:3306                   *:*
LISTEN    0         128                   [::]:22                  [::]:*

# 登录修改密码
[root@localhost ~]# mysql -uroot -p'sdWqHF.lP8!u'   
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.12

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> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.09 sec)   #新版本的mysql更改密码的命令换了,不支持函数了

mysql> quit

# 验证密码
[root@localhost ~]# mysql -uroot -p'123456'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.12 MySQL Community Server - GPL

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>

 

部署php

 

 

 

 

#  下载软件包
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://www.php.net/distributions/php-8.0.23.tar.gz

# 安装依赖包
[root@localhost src]#  dnf -y install  libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel  pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel sqlite-devel libzip-devel php-mysqlnd 

# 安装 oniguruma 包
[root@localhost ~]# dnf -y install http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm
[root@localhost src]# ls
debug    mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz  nginx-1.22.0.tar.gz
kernels  nginx-1.22.0                                php-8.0.23.tar.gz

# 解压
[root@localhost src]# tar xf php-8.0.23.tar.gz
[root@localhost src]# ls
debug                                       nginx-1.22.0         php-8.0.23.tar.gz
kernels                                     nginx-1.22.0.tar.gz
mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz  php-8.0.23

# 编译安装php
[root@localhost src]# cd php-8.0.23
[root@localhost php-8.0.23]# ./configure --prefix=/usr/local/php8 \
--with-config-file-path=/etc \
--enable-fpm \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-openssl \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--enable-exif  \
--enable-ftp \
--enable-gd \
--with-jpeg \
--with-zlib-dir \
--with-freetype \
--with-gettext \
--enable-json \
--enable-mbstring \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-readline \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--with-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-pcntl \
--enable-posix
[root@localhost php-8.0.23]# make
[root@localhost php-8.0.23]# make install

# 设置环境变量
[root@localhost php-8.0.23]# echo 'export PATH=/usr/local/php8/bin:$PATH' > /etc/profile.d/php8.sh
[root@localhost php-8.0.23]# source /etc/profile.d/php8.sh
[root@localhost php-8.0.23]# which php
/usr/local/php8/bin/php

# 设置头文件
[root@localhost ~]# ln -s /usr/local/php8/include /usr/include/php8

#设置库文件
[root@localhost ~]# echo '/usr/local/php8/lib' > /etc/ld.so.conf.d/php8.conf
[root@localhost ~]# ldconfig

# 查看版本
[root@localhost ~]# php -v
PHP 8.0.23 (cli) (built: Sep  4 2022 08:26:51) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.23, Copyright (c) Zend Technologies

# 配置php-fpm
[root@localhost ~]# cd /usr/src/php-8.0.23
# 这个文件已存在所以要加上\表示覆盖
[root@localhost php-8.0.23]# \cp php.ini-production /etc/php.ini
[root@localhost php-8.0.23]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-8.0.23]# ll -d /etc/init.d/php-fpm
-rw-r--r-- 1 root root 2402 Sep  4 08:33 /etc/init.d/php-fpm
[root@localhost php-8.0.23]# chmod +x /etc/init.d/php-fpm  #增加执行权限
[root@localhost php-8.0.23]# ll -d /etc/init.d/php-fpm
-rwxr-xr-x 1 root root 2402 Sep  4 08:33 /etc/init.d/php-fpm

[root@localhost php-8.0.23]# cd /usr/local/php8/etc
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
[root@localhost etc]# cd  php-fpm.d
[root@localhost php-fpm.d]# cp www.conf.default www.conf

[root@localhost ~]# vim /usr/local/php8/etc/php-fpm.d/www.conf
user = nginx
group = nginx  # 修改如下

# 启动php-fpm 、 并开机自启
[root@localhost ~]# service php-fpm start
Starting php-fpm  done
[root@localhost ~]# ss -antl
State     Recv-Q    Send-Q       Local Address:Port        Peer Address:Port    Process
LISTEN    0         128              127.0.0.1:9000             0.0.0.0:*
LISTEN    0         128                0.0.0.0:80               0.0.0.0:*
LISTEN    0         128                0.0.0.0:22               0.0.0.0:*
LISTEN    0         70                       *:33060                  *:*
LISTEN    0         128                      *:3306                   *:*
LISTEN    0         128                   [::]:22                  [::]:*
[root@localhost ~]# chkconfig --add php-fpm
[root@localhost ~]# chkconfig php-fpm on

#设置优先访问php页面
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
index index.php index.html index.htm;  # index后面添加index.php

#更新配置文件
[root@localhost ~]# nginx -s reload

# 最后验证能不能都开机自启
[root@localhost ~]# reboot
WARNING! The remote SSH server rejected X11 forwarding request.
Last login: Sun Sep  4 06:34:26 2022 from 192.168.6.1
[root@localhost ~]# ss -antl
State     Recv-Q    Send-Q       Local Address:Port        Peer Address:Port    Process
LISTEN    0         128                0.0.0.0:80               0.0.0.0:*
LISTEN    0         128                0.0.0.0:22               0.0.0.0:*
LISTEN    0         128              127.0.0.1:9000             0.0.0.0:*
LISTEN    0         128                   [::]:22                  [::]:*
LISTEN    0         70                       *:33060                  *:*
LISTEN    0         128                      *:3306                   *:*

 

访问

 

标签:--,LNMP,nginx,构建,mysql,php,root,localhost
From: https://www.cnblogs.com/sunyiming023654/p/16654111.html

相关文章

  • 4-《从零开始构建企业级推荐系统》读书笔记
    第1章推荐系统的时代背景为什么需要推荐系统流量利用长尾挖掘用户体验技术储备推荐什么东西只要是具有非普适性特点的东西,就可以用来做推荐,将其个性化推荐......
  • ASP.NET Core 实战-8.使用标签助手构建表单
    显示动态数据是许多Web应用程序的一个重要方面,但它通常只是故事的一半。除了向用户显示数据之外,您通常还需要用户能够将数据提交回您的应用程序。例如,您可以使用数据来......
  • 自定义控件——视图的构建过程——视图的绘制方法
    视图绘制有两种方法,分别是onDraw和dispatchDraw,它们的区别主要有下列两点: (1)onDraw既可用于普通控件,也可用于布局类视图;而dispatchDraw专门用于布局类视图,像线性布局Line......
  • 自定义控件——视图的构建过程——视图的测量方法
              对于wrap_content形式的宽高,App需要测量它们的实际长度,需要测量的实体主要有3种:  (1)文本尺寸测量文本尺寸分为文本的宽度和高度,需根......
  • 软件工程导论——构建模型类型
    2022-09-02构建模型的类型有:1、瀑布模型瀑布模型是像一个下台阶的形式。有过渡阶段。包括需求分析,设计,开发,集成,测试等方面。 图1-1瀑布模型图 2、快速原型模型......
  • 构建计算机视觉 WebApp — Flask、OpenCV 和 MongoDB
    构建计算机视觉WebApp—Flask、OpenCV和MongoDB作为一名数据科学家,具备一些软件工程技能已成为就业市场中一项非常重要的技能。如果您可以构建模型,我建议您提高简单......
  • lnmp部署
    一,安装nginx1.安装nginx依赖库yuminstalllrzszwgetgitmakecmakegccgcc-c++pcrepcre-developensslopenssl-develncurses-devellibaiobisongitncurses......
  • Jenkins使用Maven构建Java项目
    Jenkins使用Maven构建Java项目什么是MavenMaven是一个项目管理和综合工具。Maven提供给开发人员构建一个完整的生命周期框架。开发团队可以自动完成该项目的基础设施建......
  • 基于开源方案构建统一的文件在线预览与office协同编辑平台的架构与实现历程
    基于开源方案构建统一的文件在线预览与office协同编辑平台的架构与实现历程 大家好,又见面了。在构建业务系统的时候,经常会涉及到对附件的支持,继而又会引申出对附件在......
  • Docker镜像构建
    Docker镜像构建目录Docker镜像构建Dockercommit基于本地模板导入Dockerfile​ Docker镜像可以通过Dockerhub或者阿里云等仓库中获取,这些镜像是由官方或者社区人员提供......