环境为Centos7 nginx1.14 mysql5.7 php7
一,安装Nginx (yum装,快速)
yum install nginx
二,优化nginx (方便后期工作,如果纯为测试的话,不用)
1, cat nginx.conf

user www;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

include /usr/lib/nginx/modules/*.conf;

events {
worker_connections 2048;
}

http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$http_host" ';

log_format json '{"@timestamp":"$time_iso8601",'
'"clientip":"$http_x_forwarded_for",'
'"remote_user":"$remote_user",'
'"request":"$request",'
'"method":"$request_method",'
'"status":"$status",'
'"code":"$status",'
'"size":"$body_bytes_sent",'
'"referer":"$http_referer",'
'"agent":"$http_user_agent",'
'"host":"$http_host",'
'"remote_addr":"$remote_addr",'
'"responsetime":"$request_time",'
'"upstreamtime":"$upstream_response_time",'
'"url":"$uri",'
'"request_filename":"$request_filename",'
'"index":"$fastcgi_script_name"}';

access_log /var/log/nginx/access.log json;

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;

include /etc/nginx/mime.types;
default_type application/octet-stream;

include /etc/nginx/conf.d/*.conf;

}

2, cat conf.d/optimize.conf (把优化参数写到这里)

server_tokens off; #并不会让nginx执行的速度更快,关闭它可隐藏错误页面中的nginx版本号
charset utf-8,gbk; #字符
#sendfile on;
#tcp_nopush on; #在一个数据包里发送所有头文件,而不一个接一个的发送
#tcp_nodelay on; #不缓存数据,而是一段一段的发送
#keepalive_timeout 65; #给客户端分配keep-alive链接超时时间,服务器将在这个超时时间过后关闭链接,将它设置低些可以让ngnix持续工作的时间更长

autoindex off; #开启或者关闭列出目录中文件的功能
autoindex_exact_size off; #默认为 on,以 bytes 为单位显示文件大小;切换为 off 后,以可读的方式显示文件大小,单位为 KB、MB 或者 GB
autoindex_localtime on; #默认为 off,以 GMT 时间作为显示的文件时间;切换为 on 后,以服务器的文件时间作为显示的文件时间

large_client_header_buffers 8 12k;
client_max_body_size 2000m; #文件限制大小
client_header_buffer_size 128k;
client_body_buffer_size 256k;
client_body_timeout 1200s; #请求体的超时时间
client_header_timeout 1200s; #请求头的超时时间
send_timeout 1200s; #指定客户端的响应超时时间,如果在这段时间内,客户端没有读取任何数据,nginx就会关闭连接。
reset_timedout_connection on; #关闭不响应的客户端连接。这将会释放那个客户端所占有的内存空间

fastcgi_buffer_size 256k;
fastcgi_buffers 16 256k;
fastcgi_busy_buffers_size 512k;
fastcgi_temp_file_write_size 512k;
fastcgi_connect_timeout 900s; #链接
fastcgi_read_timeout 1800s; #读取;是指fastcgi进程向nginx进程发送response的整个过程的超时时间
fastcgi_send_timeout 1800s; #发请求;是指nginx进程向fastcgi进程发送request的整个过程的超时时间
fastcgi_intercept_errors off;

open_file_cache max=100000 inactive=20s; # 打开缓存的同时也指定了缓存最大数目,以及缓存的时间
open_file_cache_valid 300s; # 在open_file_cache中指定检测正确信息的间隔时间
open_file_cache_min_uses 2; #open_file_cache中指令参数不活动时间期间里最小的文件数
open_file_cache_errors on;

proxy_connect_timeout 600; #说明该指令设置与upstream server的连接超时时间,有必要记住,这个超时不能超过75秒
proxy_read_timeout 600; #说明该指令设置与代理服务器的读超时时间。它决定了nginx会等待多长时间来获得请求的响应。这个时间不是获得整个response的时间,而是两次reading操作的时间
proxy_send_timeout 600;
proxy_buffer_size 64k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;

gzip on; #告诉nginx采用gzip压缩的形式发送数据,这将会减少我们发送的数据量
gzip_comp_level 7; #压缩级别,1-9,数字越大压缩的越好,时间也越长
gzip_min_length 1024; #不压缩临界值,大于1024的才压缩
gzip_buffers 4 16k; #用于压缩缓存
gzip_types text/plain application/x-javascript text/css text/javascript text/xml image/x-icon image/bmp; #压缩级别,1-9,数字越大压缩的越好,时间也越长
gzip_vary on;
gzip_static on;
gzip_proxied any; # 压缩所有的请求
gzip_disable "MSIE [1-6]\.";

cat conf.d/default.conf

server {
listen 80;
root /var/www/html;
index index.html index.htm index.php;
server_name _;
error_page 500 502 503 504 /50x.html;

location = /50x.html {
root /var/lib/nginx/html;
}

location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
此处的php设置可根据情况而定

启动nginx
systcemctl start nginx

开机自启
systcemctl enable nginx

三 、安装MySql(5.7)

centos7默认不支持mysql,默认支持的是mariadb,mariadb是mysql一个开源分支。

1、卸载mariadb,否则安装mysql会出现冲突

执行命令
rpm -qa | grep mariadb 列出所有被安装的mariadb rpm 包;

执行命令
rpm -e --nodeps 包名称(比如:rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64) 逐个将所有列出的mariadb rpm 包给卸载掉

2、添加官方的yum源:
以centos7安装mysql5.6为例:
vim /etc/yum.repos.d/mysql-community.repo
[mysql56-community]

name=MySQL 5.6 Community Server

baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/

enabled=1

gpgcheck=0

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

centos7安装mysql5.7:baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/

centos6安装mysql5.6:baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/

centos6安装mysql5.7:baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/

3、安装MySql
yum install mysql-community-server

4、启动
systcemctl start mysql

6,配置密码:
mysqladmin -u root -p password "12345566"
初始密码为空,直接按回车即可
注意:mysql5.7的初始密码是随机生成的,放在了 /var/log/mysqld.log
使用命令 grep ‘temporary password’ /var/log/mysqld.log 读出来即可。

7、配置权限
mysql> grant all on *.* to 'root'@'%' identified by '12345566';

四、安装php7

1、检查当前安装的PHP包
yum list installed | grep php
如果有,就删除 yum remove

2、安装
#rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
#rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
如果想删除,重新装:
rpm -qa | grep webstatic
rpm -e 上面搜索到的包即可

#yum install php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-mysql.x86_64 php70w-pdo.x86_64
如果想安装更多的扩展,继续加其它的

安装php-fpm
yum install php70w-fpm php70w-opcache

3、设置php-fpm启动用户
因为要和nginx通信,所以要和nginx的启动用户一样,
user=nginx
group=nginx

4、启动php-fpm
systcemctl start php-fpm
设置开机自启:
#systemctl enable php-fpm
#systemctl daemon-reload

超详解的LNMP搭建并优化的更多相关文章

  1. 详解intellij idea搭建SSM框架(spring+maven+mybatis+mysql+junit)(下)

    在上一篇(详解intellij idea 搭建SSM框架(spring+maven+mybatis+mysql+junit)(上))博文中已经介绍了关于SSM框架的各种基础配置,(对于SSM配置不熟悉 ...

  2. html5的float属性超详解(display,position, float)(文本流)

    html5的float属性超详解(display,position, float)(文本流) 一.总结 1.文本流: 2.float和绝对定位都不占文本流的位置 3.普通流是默认定位方式,就是依次按照 ...

  3. HTML中DOM核心知识有哪些(带实例超详解)

    HTML中DOM核心知识有哪些(带实例超详解) 一.总结: 1.先取html元素,然后再对他进行操作,取的话可以getElementById等 2.操作的话,可以是innerHtml,value等等 ...

  4. Mysql超详解

    Mysql超详解 一.命令框基本操作及连接Mysql 找到Mysql安装路径,查看版本 同时按快捷键win+R会弹出一个框,在框中输入cmd 点击确定后会出现一个黑框,这是命令框,我们的操作要在这命令 ...

  5. Mybatis案例超详解(上)

    Mybatis案例超详解(上) 前言: 本来是想像之前一样继续跟新Mybatis,但由于种种原因,迟迟没有更新,快开学了,学了一个暑假,博客也更新了不少,我觉得我得缓缓,先整合一些案例练练,等我再成熟 ...

  6. Python3调用C程序(超详解)

    Python3调用C程序(超详解) Python为什么要调用C? 1.要提高代码的运算速度,C比Python快50倍以上 2.对于C语言里很多传统类库,不想用Python重写,想对从内存到文件接口这样 ...

  7. JUC中的AQS底层详细超详解

    摘要:当你使用java实现一个线程同步的对象时,一定会包含一个问题:你该如何保证多个线程访问该对象时,正确地进行阻塞等待,正确地被唤醒? 本文分享自华为云社区<JUC中的AQS底层详细超详解,剖 ...

  8. bitmap--Bitmap详解与Bitmap的内存优化

    一.Bitmap: Bitmap是Android系统中的图像处理的最重要类之一.用它可以获取图像文件信息,进行图像剪切.旋转.缩放等操作,并可以指定格式保存图像文件. 常用方法: public voi ...

  9. Appium+python自动化(三十)- 实现代码与数据分离 - 数据配置-yaml(超详解)

    简介 本篇文章主要介绍了python中yaml配置文件模块的使用让其完成数据和代码的分离,宏哥觉得挺不错的,于是就义无反顾地分享给大家,也给大家做个参考.一起跟随宏哥过来看看吧. 思考问题 前面我们配 ...

随机推荐

  1. Redis教程(Linux)

    这里汇总了从简单的安装到较为复杂的配置,由浅入深的学习redis... 一 , 安装 1) redis扩展安装 从官网上下载扩展压缩包 wget http://pecl.php.net/get/red ...

  2. oracle事务的四个特性(ACID)

    事务产生的背景 当在PL/SQL中同时操作多个SQL语句,比如通过DML语句添加.修改或删除数据时,如何确保数据库数据不会因为意外而倒置错误数据是一个非常重要的问题. 以仓库发料系统为例,如果某一张领 ...

  3. Oracle Profile 配置文件

    Profile是用户的配置文件,它是密码限制,资源限制的命名集合.利用profile 可以对数据库用户进行基本的资源管理,密码管理. 1 创建profile 的语法 create profile pr ...

  4. Setting property 'source' to 'org.eclipse.jst.jee.server:hczm' did not find a matching property

  5. Eclipse中修改jsp、html……的编码格式

    一般如果使用的是Eclipse的默认编码格式,在我们保存的时候会提示选择保存的编码格式,保存后英文没有问题,但是中文就会乱码. 修改方式是: Windows——>Preferences——> ...

  6. java学习之—链表(2)

    /** * 双端链表操作 * Create by Administrator * 2018/6/14 0014 * 下午 2:05 **/ class Link1 { public long dDat ...

  7. Nginx安装- CentOS7

    1.确认是否具备安装环境 g++  -v 如果不打印则不具备. 解决办法:联网执行如下命令 yum install gcc yum install gcc-c++ 2.需要材料 pcre-8.37.t ...

  8. rbac组件引用

    一. 批量操作思路 # 待新增 路由系统中有,但是数据库中还没有 路由系统的集合 - 数据库中权限集合 # 待更新 路由系统中有,数据库中也有, 只是更改了一些信息 路由系统的集合 & 数据库 ...

  9. 将大数组里面的小数组平行展开的实现(Making a flat list out of list of lists in Python)

    今天在生成数据的时候遇到了这个需求,其实写一个for循环可以很容易解决这个问题,但是无论是性能还是酷炫程度上都不行 所以顺手搜索了一下. 例子是将 l = [[1, 2, 3], [4, 5, 6], ...

  10. nginx 卸载后重新安装/etc/nginx配置文件没了,cannot open /etc/nginx/nginx.conf (No such file or directory)

    sudo apt-get --purge remove nginx-common sudo apt-get --purge remove nginx* sudo apt-get autoremove ...