LNMP架构
LNMP平台就是Linux,Nginx,MySQL,PHP的组合架构,需要Linux服务器,MySQL服务器,PHP解析环境
构成组件
Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。
Nginx是一个高性能的HTTP和反向代理服务器。
Mysql是一个小型关系型数据库管理系统。
PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。
一、 编译安装Nginx
1、将压缩包导入主机中
2、解压源码包,并查看
[root@localhost ~]# ls
Discuz_X3.4_SC_UTF8.zip nginx-1.12.2.tar.gz
mysql-boost-5.7.20.tar.gz php-7.1.20.tar.gz
[root@localhost ~]# tar zxvf nginx-1.12.2.tar.gz ##解压Nginx源码包
3、安装编译需要的环境组件包
[root@localhost ~]# yum -y install \
gcc \ ##c语言
gcc-c++ \ ##c++语言
pcre-devel \ ##pcre语言工具
zlib-devel ##数据压缩用的函式库
4、创建程序用户nginx并编译Nginx
[root@localhost ~]# useradd -M -s /sbin/nologin nginx ##创建程序用户,安全不可登陆状态
[root@localhost ~]# id nginx
uid=1001(nginx) gid=1001(nginx) 组=1001(nginx)
[root@localhost ~]# cd nginx-1.12.0/ ##切换到nginx目录下
[root@localhost nginx-1.12.0]# ./configure \ ##配置nginx
> --prefix=/usr/local/nginx \ ##安装路径
> --user=nginx \ ##用户名
> --group=nginx \ ##用户组
> --with-http_stub_status_module ##状态统计模块
5、编译和安装
[root@localhost nginx-1.12.0]# make && make install ##编译和安装
6、优化nginx启动脚本,以便于系统识别
[root@localhost nginx]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ ##创建软连接让系统识别nginx启动脚本
[root@localhost nginx]# nginx -t ##检查配置文件的语法问题
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost nginx]# nginx ##开启ngnix
[root@localhost nginx]# netstat -ntap | grep 80 ##查看端口,nginx已经开启
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 39620/nginx: master
[root@localhost nginx]# systemctl stop firewalld.service ##关闭防火墙
[root@localhost nginx]# setenforce 0
[root@localhost nginx]# nginx ##开启
7、制作管理脚本,便于使用service管理使用
[root@localhost nginx]# cd /etc/init.d/ ##切换到启动配置文件目录
[root@localhost init.d]# ls
functions netconsole network README
[root@localhost init.d]# vim nginx ##编辑启动脚本文件
#!/bin/bash
#chkconfig: - 99 20 ##注释信息
#description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx" ##设置变量为nginx命令文件
PIDF="/usr/local/nginx/logs/nginx.pid" ##设置变量PID文件 进程号为5346
case "$1" in
start)
$PROG ##开启服务
;;
stop)
kill -s QUIT $(cat $PIDF) ##关闭服务
;;
restart) ##重启服务
$0 stop
$0 start
;;
reload) ##重载服务
kill -s HUP $(cat $PIDF)
;