Lnmp搭建(三台主机)

本文详细介绍了如何在三台主机上部署LNMP环境,包括nginx的安装与配置,mysql的安装,php的安装,以及如何连接nginx和php。在部署过程中,特别提到了php端和nginx端的设置,并对可能出现的报错问题进行了测试和访问。
摘要由CSDN通过智能技术生成

Lnmp搭建(三台主机)



环境说明:

系统 IP 需要安装的服务
centos8 192.168.174.168 nginx-1.20.2
centos8 192.168.174.171 mysql-5.7
centos8 192.168.174.173 php-8.1.11

nginx安装与配置

nginx安装
//首先关闭防火墙和selinux
[root@nginx ~]# setenforce 0
[root@nginx ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@nginx ~]# systemctl disable  --now firewalld.service 
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

//创建用户
[root@nginx ~]# useradd -rMs /sbin/nologin nginx

//安装所需要的依赖包
[root@nginx ~]# dnf -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make wget vim

//下载nginx源码包,并解压
	
[root@nginx ~]# wget http://nginx.org/download/nginx-1.20.2.tar.gz
[root@nginx ~]# tar -xf nginx-1.20.2.tar.gz 
[root@nginx ~]# cd nginx-1.20.2/
[root@nginx nginx-1.20.2]#

//准备安装
##在配置前我们其实可以隐藏一下nginx版本号,以防版本泄露
[root@nginx nginx-1.20.2]# vim src/core/nginx.h 
#define NGINX_VERSION      "111"    //修改这个参数隐藏nginx版本号

//开始配置
[root@nginx nginx-1.20.2]# ./configure \
> --prefix=/usr/local/nginx \              //指定安装路径
> --user=nginx \                           //指定用户和组
> --group=nginx \                          
> --with-debug \                           //开启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

//开启编译安装
[root@nginx nginx-1.20.2]# make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install
.........

//安装成功
[root@nginx nginx-1.20.2]# cd /usr/local/nginx/
[root@nginx nginx]# ls
conf  html  logs  sbin
nginx配置
//配置环境变量
[root@nginx nginx]# echo "export PATH=$PATH:/usr/local/nginx/sbin" > /etc/profile.d/nginx.sh
[root@nginx nginx]# source /etc/profile.d/nginx.sh
	
//启动服务
[root@nginx nginx]# nginx
[root@nginx nginx]# ss -anlt
State      Recv-Q     Send-Q          Local Address:Port           Peer Address:Port     Process     
LISTEN     0          128                   0.0.0.0:22                  0.0.0.0:*                    
LISTEN     0          128                   0.0.0.0:80                  0.0.0.0:*                    
LISTEN     0          128                      [::]:22                     [::]:*                    

//关闭服务,编写service文件,并设置服务开机自启
[root@nginx nginx]# nginx -s stop
[root@nginx nginx]# ss -anlt
State      Recv-Q     Send-Q          Local Address:Port           Peer Address:Port     Process     
LISTEN     0          128                   0.0.0.0:22                  0.0.0.0:*                    
LISTEN     0          128                      [::]:22                     [::]:*                    

[root@nginx nginx]# cat > /usr/lib/systemd/system/nginx.service << EOF
> [Unit]
> Description=nginx server daemon
> After=network.target 
>  
> [Service]
><
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值