Ubuntu22.04 搭建 LNMP+Redis

一、环境准备

1、服务版本

Linux 采用 Ubuntu 22.04

Nginx 采用 Nginx-1.24.0 安装目录/opt/nginx
Mysql 采用 Mysql-5.7.23 安装目录/opt/mysql
PHP   采用 PHP-7.3.5 安装目录/opt/php

Redis  采用 Redis 5.0.12

2、配置apt源
# 备份
cp /etc/apt/sources.list{,_bak}

# 修改源文件如下
deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
3、测试
apt-get update
apt-get install wget

二、部署Nginx服务

1、下载第三方依赖
apt-get install zlib1g zlib1g-dev libpcre3 libpcre3-dev openssl libssl-dev build-essential libtool gcc make
2、下载Nginx源码包
wget https://nginx.org/download/nginx-1.24.0.tar.gz
3、解压
tar -zxvf nginx-1.24.0.tar.gz
4、编译三部曲

4.1 创建工作目录

mkdir -p /opt/nginx

4.2 执行编译脚本

# 进入解压目录
cd 解压目录/nginx-1.24.0
 
# 执行编译脚本
./configure --prefix=/opt/nginx --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --with-http_stub_status_module --with-threads --with-file-aio

4.3 编译

make

4.4 安装

make install
5、配置环境变量
ln -s /opt/nginx/sbin/nginx /usr/bin/nginx
 
# 创建Nginx工作用户
useradd -r -s /sbin/nologin nginx
6、修改配置环境
vi /opt/nginx/conf/nginx.conf
 
# 修改配置如下
# 工作用户为nginx
user  nginx;
worker_processes  2;
 
error_log  logs/error.log;
 
pid        logs/nginx.pid;
 
 
events {
    worker_connections  1024;
}
 
 
http {
    include       mime.types;
    default_type  application/octet-stream;
 
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
 
    access_log  logs/access.log  main;
 
    sendfile        on;
    #tcp_nopush     on;
 
    keepalive_timeout  65;
 
    gzip  on;
    # gzip压缩等级,有1-9级,级别越高压缩率越高,但传输时间越久
    gzip_comp_level 4;
    # gzip支持压缩的文件类型
    gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript applicatio

你可能感兴趣的:(Linux,redis,数据库,mysql,linux)