LNMP架构部署
准备工作
关闭防火墙和selinux
[root@localhost ~]# systemctl disable --now firewalld.service
[root@localhost ~]# vim /etc/selinux/config
SELINUX=disabled
[root@localhost ~]# setenforce 0
[root@localhost ~]# reboot
创建源码包存放目录并下载源码包
[root@localhost ~]# mkdir /usr/src/soft
[root@localhost ~]# cd /usr/src/soft/
[root@localhost soft]# wget https://nginx.org/download/nginx-1.20.1.tar.gz
[root@localhost soft]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
[root@localhost soft]# wget https://www.php.net/distributions/php-7.4.28.tar.gz
[root@localhost soft]# ls
mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz nginx-1.20.1.tar.gz php-7.4.28.tar.gz
nginx
创建nginx用户
[root@localhost ~]# useradd -r -M -s /sbin/nologin nginx
安装依赖包
[root@localhost ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make
[root@localhost ~]# yum -y groups mark install 'Development Tools'
创建日志存放目录
[root@localhost ~]# mkdir -p /var/log/nginx
[root@localhost ~]# chown -R nginx.nginx /var/log/nginx
解压软件包
[root@localhost soft]# tar xf nginx-1.20.1.tar.gz -C /usr/local/
编译安装
[root@localhost nginx-1.20.1]# ./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.20.1]# make && make install
配置环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@localhost ~]# . /etc/profile.d/nginx.sh
启动nginx
[root@localhost ~]# nginx
[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 [::]:22 [::]:*
编写service文件
[root@localhost ~]# vim /lib/systemd/system/nginx.service
[Unit]
Description=Nginx server daemon
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/n