LNAP平台概述
LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。
Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。代表版本有:debian、centos、ubuntu、fedora、gentoo等。
Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。
Mysql是一个小型关系型数据库管理系统。
PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。
这四种软件均为免费开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统。
系统环境:CentOS 6.5 64位
LNMP一键安装
Nginx
nginx介绍:https://baike.baidu.com/item/nginx/3817705?fr=aladdin
Nginx源码包下载:http://nginx.org/en/download.html
安装步骤:
1.安装依赖包
yum -y install pcre-devel zlib-devel
2.创建运行Nginx服务的用户和组
useradd -M -s /sbin/nologin nginx
3.编译安装Nginx
tar zxvf nginx-1.12.1.tar.gz -C /usr/src/ #解包
cd /usr/src/nginx-1.12.1/
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx #配置
make && make install #编译并且安装
4.优化执行路径
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
5.Nginx的使用
1)检查配置文件和查看Nginx的版本号
nginx -t #检查配置文件
nginx -v(小写) #查看版本
nginx -V(大写) #查看详细信息
2)启动、停止Nginx
nginx #启动Nginx
killall -s HUP nginx #重新加载Nginx
killall -s QUIT nginx #停止Nginx服务:主程序Nginx支持标准的进程信号,通过kill或killall命令发送HUP信号表示重载配置,QUIT表示退出进程,KILL信号表示杀死进程(通过 " -s " 选项指定信号种类);当Nginx运行时,PID号默认存放在logs/目录下的nginx.pid文件中;Nginx运行时会产生两个或多个 进程(一个主进程,多个工作进程)
3)创建启动脚本
#!/bin/bash
#chkconfig: - 99 20
#description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx" #主程序路径
PIDF="/usr/local/nginx/logs/nginx.pid" #PID存放路径
case "$1" in
start)
$PROG
;;
stop)
kill -s QUIT $(cat $PIDF)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac
exit 0
chmod +x /etc/init.d/nginx //赋予执行权限
chkconfig --add nginx //添加为系统服务
6.配置文件(nginx.conf)
#全局配置:
#user nobody; #运行用户
worker_processes 1; #工作进程数量
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#全局错误日志及PID文件
#pid logs/nginx.pid;
#I/O事件配置
events {
#use epoll #epoll是多路复用IO(I/O Multiplexing)中的一种方式,仅用于linux2.6以上内核,可以大大提高nginx的性能
worker_connections 1024; #单个后台worker process进程的最大并发链接数,每个进程处理4096个连接
}
http {
include mime.types; #设定mime类型,类型由mime.type文件定义
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; #sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件,对于普通应用,必须设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为 off,以平衡磁盘与网络I/O处理速度,降低系统的uptime
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65; #连接超时时间
#gzip on; #开启gzip压缩
client_header_buffer_size 128k;
large_client_header_buffers 4 128k; #设定请求缓冲
#设定虚拟主机配置
server {
listen 80; #侦听端口
server_name localhost; #定义域名
#charset koi8-r; #定义字符编码
#access_log logs/host.access.log main; #设定本虚拟主机的访问日志
#默认请求
location / {
root html; #站点目录
index index.html index.htm; #定义首页索引文件的名称
}
#error_page 404 /404.html; #定义404错误页面
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
} #定义错误提示页面
#静态文件,nginx自己处理
location ~ ^/(images|javascript|js|css|flash|media|static)/ {
expires 30d; #过期30天,静态文件不怎么更新,过期可以设大一点,如果频繁更新,则可以设置得小一点。
}
#php脚本全由自己处理
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
#PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI默认配置
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
#禁止访问 .htxxx 文件
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
}
7.创建一个站点
修改配置文件部分内容
server {
listen 80;
server_name localhost;
charset utf-8;
access_log logs/host.access.log main;
location / {
root /www;
index index.html index.htm;
}
8.创建站点目录和index.html文件,测试
MYSQL、PHP
同LAMP