####lnmp架构的搭建——源码编译(Mysql,php,nginx)####

LNMP架构介绍:

  • LNMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写(L指Linux,N指Nginx,M一般指MySQL,也可以指MariaDB,P一般指PHP,也可以指Perl或Python)
    LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。
    Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。代表版本有:debian、centos、ubuntu、fedora、gentoo等。
    Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。
    Mysql是一个小型关系型数据库管理系统。
    PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。
    这四种软件均为免费开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统。

LNMP工作原理:

特点:
Nginx是一个小巧而高效的Linux下的Web服务器软件,是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler 站点开发的,已经在一些俄罗斯的大型网站上运行多年,相当的稳定。
Nginx性能稳定、功能丰富、运维简单、处理静态文件速度快且消耗系统资源极少。

优点:
作为 Web 服务器:相比 Apache,Nginx 使用更少的资源,支持更多的并发连接,体现更高的效率。
作为负载均衡服务器:Nginx 既可以在内部直接支持Rails和PHP,也可以支持作为 HTTP代理服务器对外进行服务。Nginx 用C编写,不论是系统资源开销还是CPU使用效率都比Perlbal要好的多。
作为邮件代理服务器:Nginx同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器),Last/fm 描述了成功并且美妙的使用经验。
Nginx 安装非常的简单,配置文件非常简洁(还能够支持perl语法)。Nginx支持平滑加载新的配置,还能够在不间断服务的情况下进行软件版本的升级。

实验环境:rhel7.3虚拟机,firewalld 、selinux关闭状态
########源码编译安装nginx########

[root@westos1 lnmp]# tar zxf  nginx-1.15.9.tar.gz  ##解压nginx-1.15.9.tar.gz
[root@westos1 lnmp]# cd nginx-1.15.9   ##切换到解压后的 nginx-1.15.9目录会有生成文件
[root@westos1 ~]# cd /root/lnmp/nginx-1.15.9/src/core
[root@westos1 core]# vim nginx.h  #编辑该文件只是为了nginx安装
#define nginx_version      1015009
#define NGINX_VERSION      "1.15.9"
#define NGINX_VER          "nginx/"   #只更改这一处 不显示nginx的版本信息
[root@westos1 nginx-1.15.9]# vim auto/cc/gcc  #编辑该文件只是为了nginx安装
171  #debug  #注释是为了nginx最小安装
172 #CFLAGS="$CFLAGS -g"
[root@westos1 nginx-1.15.9]# ./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module   ##指定在/usr/local/lnmp/nginx 位置 增加http_ssl_module模块    
checking for OS
 + Linux 3.10.0-514.el7.x86_64 x86_64

checking for C compiler ... not found
[root@westos1 nginx-1.15.9]#yum install -y gcc  ##编译过程中会出现报错,缺少的软件安装上就可以了
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system,
[root@westos1 nginx-1.15.9]#  yum install -y pcre-devel
./configure: error: SSL modules require the OpenSSL library.
[root@westos1 nginx-1.15.9]#  yum install -y openssl-devel
[root@westos1 nginx-1.15.9]# make && make install   ##编译完成后安装

安装成功后会有以下文件生成
在这里插入图片描述

[root@westos1 nginx]# cd conf/
[root@westos1 conf]# vim nginx.conf
#user  nobody;   ##添加用户  
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
[root@westos1 conf]# id nginx  ##源码编译不会自动生成用户id
id: nginx: no such user
[root@westos1 conf]# useradd nginx  ##添加用户
[root@westos1 conf]# id nginx  ##用户id
uid=1001(nginx) gid=1001(nginx) groups=1001(nginx)
[root@westos1 conf]# vim nginx.conf
user  nginx  nginx;   ##添加用户名或id都可以
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

为了nginx操作方便,做个软链接

[root@westos1 conf]# cd /usr/local/lnmp/nginx/sbin/   ##切换到这个目录
[root@westos1 sbin]# ln -s /usr/local/lnmp/nginx/sbin/  /usr/local/sbin/  ##将/usr/local/lnmp/nginx/sbin/ 连接到 /usr/local/sbin/ 下
[root@westos1 sbin]# ln -s /usr/local/lnmp/nginx/sbin/  /usr/local/bin/ ##将/usr/local/lnmp/nginx/sbin/ 连接到 /usr/local/bin/ 下
[root@westos1 sbin]# cd 
[root@westos1 ~]# ls
lnmp
[root@westos1 ~]# ln -s /usr/local/lnmp/nginx/sbin/nginx /usr/local/sbin/   ##将/usr/local/lnmp/nginx/sbin/nginx连接到 /usr/local/sbin/ 下
[root@westos1 ~]# nginx   ##打开nginx
[root@westos1 ~]# nginx 
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
^C
[root@westos1 ~]# netstat -antlp   ##查看端口
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      16736/nginx: master    ##端口打开
tcp        0      0 0.0.0.0:22             
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值