lnmp架构

lnmp架构

nginx的安装

//nginx 下载地址http://nginx.org/download/nginx-1.22.0.tar.gz 我是提前下好了
[root@lnmp ~]# cd /usr/src/
[root@lnmp src]# ls
debug  kernels  nginx-1.22.0.tar.gz
//创建nginx主和组,并创建日志存放目录
[root@lnmp src]# useradd -r -M -s /sbin/nologin nginx
[root@lnmp src]# mkdir /var/log/nginx
[root@lnmp src]# chown -R nginx.nginx /var/log/nginx/
[root@lnmp src]# ll -d /var/log/nginx/
drwxr-xr-x. 2 nginx nginx 6 Sep  3 11:50 /var/log/nginx/
//安装依赖包
[root@lnmp src]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make
[root@lnmp src]# tar xf nginx-1.22.0.tar.gz 
[root@lnmp src]# ls
debug  kernels  nginx-1.22.0  nginx-1.22.0.tar.gz
[root@lnmp src]# cd nginx-1.22.0
//进行编译安装
[root@lnmp 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@lnmp nginx-1.22.0]# make && make install
//配置nginx
[root@lnmp ~]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@lnmp ~]# source /etc/profile.d/nginx.sh 
[root@lnmp ~]# nginx 
[root@lnmp ~]# 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@lnmp ~]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@lnmp ~]# setenforce 0

在这里插入图片描述

[root@lnmp ~]# cd /usr/lib/systemd/system
[root@lnmp system]# cp sshd.service nginx.service
[root@lnmp system]# vi nginx.service 
Documentation=man:sshd(8) man:sshd_config(5)
Wants=sshd-keygen.tar`get
EnvironmentFile=-/etc/crypto-policies/back-ends/opensshserver.config
EnvironmentFile=-/etc/sysconfig/sshd
ExecStart=/usr/local/nginx/sbin/nginx
Restart=on-failure
RestartSec=42s
KillMode=process
[Unit]
Description=nginx server daemon
After=network.target 

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecReload=/usr/local/nginx/sbin/nginx -s reload

[Install]
WantedBy=multi-user.target
[root@lnmp system]# systemctl daemon-reload
[root@lnmp system]# systemctl status nginx
● nginx.service - nginx server daemon
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
[root@lnmp system]# 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@lnmp system]# nginx -s stop
[root@lnmp system]# systemctl enable --now nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
[root@lnmp system]# systemctl status nginx
● nginx.service - nginx server daemon
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2022-09-03 13:02:19 CST; 3s ago
  Process: 39274 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=0/SUCCESS)
 Main PID: 39275 (nginx)

mysql二进制安装

//mysql 下载地址https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
[root@lnmp ~]# useradd -r -M -s /sbin/nologin mysql //创建用户
[root@lnmp ~]# yum -y install ncurses-compat-libs ncurses-devel openssl-devel openssl cmake mariadb-devel
[root@lnmp src]# ls
debug    mysql-8.0.20-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@lnmp src]# tar xf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz -C /usr/local/
[root@lnmp src]# cd /usr/local/
[root@lnmp local]# ls
bin  games    lib    libexec                              nginx  share
etc  include  lib64  mysql-8.0.20-linux-glibc2.12-x86_64  sbin   src
[root@lnmp local]# mv mysql-8.0.20-linux-glibc2.12-x86_64 mysql
[root@lnmp local]# chown -R mysql.mysql mysql //修改目录/usr/local/mysql的属主属组
[root@lnmp local]# ll -d mysql/
drwxr-xr-x. 9 mysql mysql 129 Sep  3 12:45 mysql/
//添加环境变量 头文件 man文件
[root@lnmp local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh 
[root@lnmp local]# source /etc/profile.d/mysql.sh 
[root@lnmp local]# which mysql
/usr/local/mysql/bin/mysql
[root@lnmp local]# ln -s /usr/local/mysql/include /usr/include/mysql
[root@lnmp local]# vi /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@lnmp local]# ldconfig 
[root@lnmp local]# vi /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@lnmp ~]# mkdir -p /opt/data
[root@lnmp ~]# chown -R mysql.mysql /opt/data/
[root@lnmp ~]# ll /opt/
total 0
drwxr-xr-x. 2 mysql mysql 6 Sep  3 12:55 data
//初始化数据库 添加-insecure 初始化是不生成密码可以免密登录
[root@lnmp ~]# mysqld --initialize-insecure --user mysql --datadir /opt/data 
2022-09-03T04:57:52.794989Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.20) initializing of server in progress as process 39150
2022-09-03T04:57:52.812873Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-09-03T04:57:54.088964Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-09-03T04:57:55.572208Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
//生成配置文件
[root@lnmp ~]# cat /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@lnmp ~]# cd /usr/local/mysql/
[root@lnmp mysql]# ls
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@lnmp mysql]# cd support-files/
[root@lnmp support-files]# cp mysql.server mysqld
[root@lnmp support-files]# chown -R mysql.mysql mysqld
[root@lnmp support-files]# ll
total 32
-rwxr-xr-x. 1 mysql mysql 10576 Sep  3 13:05 mysqld
-rwxr-xr-x. 1 mysql mysql  1061 Mar 26  2020 mysqld_multi.server
-rw-r--r--. 1 mysql mysql  2048 Mar 27  2020 mysql-log-rotate
-rwxr-xr-x. 1 mysql mysql 10576 Mar 27  2020 mysql.server
[root@lnmp support-files]# vi mysqld
basedir=/usr/local/mysql
datadir=/opt/data
[root@lnmp support-files]# /usr/local/mysql/support-files/mysqld start
Starting MySQL.Logging to '/opt/data/lnmp.err'.
. SUCCESS! 
[root@lnmp support-files]# 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                      *:3306                   *:*                
LISTEN    0         128                   [::]:22                  [::]:*                
LISTEN    0         70                       *:33060                  *:*                //修改密码
[root@lnmp ~]# mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.20 MySQL Community Server - GPL

Copyright (c) 2000, 2020, 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 'test111';
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye
//使用修改之后的密码登录
[root@lnmp ~]# mysql -uroot -ptest111
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.20 MySQL Community Server - GPL

Copyright (c) 2000, 2020, 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> 
//设置开机自启
[root@lnmp ~]# cd /usr/lib/systemd/system
[root@lnmp system]# cp sshd.service mysqld.service
[root@lnmp system]# vi mysqld.service 
[Unit]
Description=mysql server daemon
Wants=sshd-keygen.target

[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysqld start
ExecStop=/usr/local/mysql/support-files/mysqld stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
[root@lnmp system]#  systemctl daemon-reload
[root@lnmp system]# pkill mysql
[root@lnmp system]# 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@lnmp system]# systemctl enable --now mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@lnmp system]# systemctl status mysqld
● mysqld.service - mysql server daemon
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disab>
   Active: active (running) since Sat 2022-09-03 13:10:34 CST; 10s ago
  Process: 39590 ExecStart=/usr/local/mysql/support-files/mysqld start (code=exited, sta>
 Main PID: 39603 (mysqld_safe)
    Tasks: 40 (limit: 11201)

php编译安装

//下载地址 https://www.php.net/distributions/php-8.0.23.tar.gz
//准备工作 安装php包和依赖包
[root@lnmp ~]# cd /usr/src/
[root@lnmp src]# ls
debug    mysql-8.0.20-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@lnmp src]# tar xf php-8.0.23.tar.gz 
[root@lnmp src]# ls
debug                                       nginx-1.22.0         php-8.0.23.tar.gz
kernels                                     nginx-1.22.0.tar.gz
mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz  php-8.0.23
[root@lnmp src]# dnf -y install libxml2 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 php-mysqlnd sqlite-devel http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm libzip-devel
[root@lnmp src]# cd php-8.0.23
[root@lnmp php-8.0.23]# ./configure --prefix=/usr/local/php8 \
>    --with-config-file-path=/etc \
>    --enable-fpm \
>    --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-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

+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE. By continuing this installation  |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+
Thank you for using PHP.
[root@lnmp php-8.0.23]# make && make install
//创建环境变量
[root@lnmp php-8.0.23]# echo 'export PATH=/usr/local/php8/bin:$PATH' > /etc/profile.d/php8.sh
[root@lnmp php-8.0.23]# source /etc/profile.d/php8.sh 
[root@lnmp php-8.0.23]# which php
/usr/local/php8/bin/php
//配置php-fpm
[root@lnmp php-8.0.23]# \cp php.ini-production /etc/php.ini //将生产环境文件 复制到etc下
[root@lnmp php-8.0.23]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@lnmp php-8.0.23]# chmod +x /etc/rc.d/init.d/php-fpm  //此文件需要执行权限所以复制过去要看是否有执行(x)权限
[root@lnmp php-8.0.23]#  cp /usr/local/php8/etc/php-fpm.conf.default /usr/local/php8/etc/php-fpm.conf  //将php-fpm.conf.default 复制一份名为php-fpm.conf
[root@lnmp php-8.0.23]# cp /usr/local/php8/etc/php-fpm.d/www.conf.default /usr/local/php8/etc/php-fpm.d/www.conf  //将www.conf.default 复制一份名为www.conf
//开启服务检查端口
[root@lnmp php-8.0.23]# service php-fpm start
Starting php-fpm  done
[root@lnmp php-8.0.23]# 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                      *:3306                   *:*                
LISTEN    0         128                   [::]:22                  [::]:*                
LISTEN    0         70                       *:33060                  *:*               

配置nginx

//创建php测试页面
[root@lnmp ~]# vi /usr/local/nginx/html/index.php
<?php
    phpinfo();
?>
//修改nginx主配置文件
[root@lnmp conf]# pwd 
/usr/local/nginx/conf
[root@lnmp conf]# vi nginx.conf
...
location / {
            root   html;
            index  index.php index.html index.htm;  //在index后面添加index.php,表示优先访问php页面
        }
...
//将以下内容取消注释并修改
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;
        }
...
//重启nginx
[root@lnmp conf]# nginx -s stop
[root@lnmp conf]# nginx

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值