lamp->lnmp
nginx
survey.netcraft.net
查看各大网站使用的web服务器,使用下面的命令
# curl -I www.sina.com
结论:现在大型网站几乎统一都使用nginx或nginx做二次开发的版本(如tengine,OpenResty等)

nginx相对于apache的优势?
资源占用少
支持大并发
================================================================================================
centos7.3平台下rpm版单机lnmp的搭建
第一步:准备
1,主机名
2,关闭firewalld,selinux
3,关闭NetworkManager,并配置静态ip
4,配置本地yum,epel源,163源
5,时间同步 第二步:安装lnmp相关的rpm包
# yum install mariadb mariadb-server php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash nginx php-fpm php-pecl-zendopcache
  此处安装的软件其实就是mysql(mariadb)和nginx和php的一些模块。安装php也可以直接yum install php* 将所有的模块安装
第三步:
启动mariadb,并登录验证
# systemctl start mariadb.service
# systemctl status mariadb.service
# systemctl enable mariadb.service
# mysql --登录确认能使用 第四步:确认php安装模块(modules),并按需求进行模块的增加或删除,对php配置文件进行优化(可选)
# php -m --查看已经安装的php模块,如果还有需要的模块没有安装,则使用yum install php-xxx去安装相应的模块
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dom
ereg
exif
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
json
ldap
libxml
mbstring
mhash
mysql
mysqli
odbc
openssl
pcntl
pcre
PDO
pdo_mysql
PDO_ODBC
pdo_sqlite
Phar
posix
readline
Reflection
session
shmop
SimpleXML
sockets
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlrpc
xmlwriter
xsl
Zend OPcache
zip
zlib
[Zend Modules]
Zend OPcache
# ls /usr/lib64/php/modules/ --所有安装的模块路么都在此目录下
bcmath.so json.so odbc.so pdo_sqlite.so sysvsem.so xmlwriter.so
curl.so ldap.so opcache.so phar.so sysvshm.so xsl.so
dom.so mbstring.so pdo_mysql.so posix.so wddx.so zip.so
fileinfo.so mysqli.so pdo_odbc.so sqlite3.so xmlreader.so
gd.so mysql.so pdo.so sysvmsg.so xmlrpc.so /etc/php.ini --php主配置文件,如果要进行相应的优化修改或者是以源码编译的方式编出的模块需要加到php里的都需要修改此配置文件 第五步:
优化php-fpm,并启动(php-fpm为php的fastcgi模式,简单来说就是php的服务模式)
# vim /etc/php-fpm.d/www.conf --打开php-fpm主配置文件并进行优化(以下优化在生产环境视具体情况而定)
12 listen = /var/run/fastcgi/fastcgi.socket --原来是监听127.0.0.1:9000也是可以的,我这里换成socket来做(本机连接可以使用socket或tcp/ip协议方式,远程连接只能使用tcp/ip协议方式)
218 php_flag[display_errors] = on --打开php错误显示功能
39 user = nginx --用户与组和跑nginx服务的用户一致,避免权限问题
41 group = nginx
31 listen.owner = nginx
32 listen.group = nginx --socket文件的权限设置。用户与组和跑nginx服务的用户一致,避免权限问题(如果前面使用的是tcp/ip的方式,这里就注释就好)
33 listen.mode = 0666
60 pm = dynamic --对于专用服务器,pm可以设置为static。如果选择static,则由pm.max_children指定固定的子进程数。如果选择dynamic,则可以动态调整下面几个参数
70 pm.max_children = 64  --子进程最大数,我这里只是参考值(看系统资源决定,视实际环境测试后调整,下几个参数也一样)
75 pm.start_servers = 20  --启动时默认启动的进程数
80 pm.min_spare_servers = 5 --保证空闲进程数最小值,如果空闲进程小于此值,则创建新的子进程
85 pm.max_spare_servers = 35 --保证空闲进程数最大值,如果空闲进程大于此值,此进行清理
160 rlimit_files = 65535 --打开的文件描述符数量,不能大于系统的限制(系统可以使用ulimit命令查看和设置)
(注意:前面的数字是行号,不是说需要在配置文件里面写入) 建立fastcgi模式的socket产生的目录,与上面的配置对应
# mkdir /var/run/fastcgi
# chown nginx.nginx /var/run/fastcgi/
设置系统打开的文件描述符数量,与上面的配置对应
# ulimit -n
1024
# ulimit -SHn 65535
# echo "ulimit -SHn 65535" >> /etc/rc.local 启动php-fpm服务
# systemctl start php-fpm.service
# systemctl status php-fpm.service
# systemctl enable php-fpm.service 第六步:
--nginx的配置文件的一个基本结构如下:
常见基本配置(如跑服务进程的用户,启动进程数,log,pid等)
events {
事件(优化并发数,网络IO模型选择)
} http {
针对所有server的全局配置
server {
虚拟主机一
}
server {
虚拟主机二
}
} 配置nginx(nginx参数实在太多,这里先简要配置)
我这里的配置结果如下
# cat /etc/nginx/nginx.conf |grep -v '#'
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf; events {
worker_connections 1024;
} http {
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 /var/log/nginx/access.log main; 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; server {
listen 80 default_server;
listen [::]:80 default_server;
server_name 172.16.25.2;
root /usr/share/nginx/html;
index index.php index.html; include /etc/nginx/default.d/*.conf; error_page 404 /404.html;
location = /40x.html {
} error_page 500 502 503 504 /50x.html;
location = /50x.html {
} location ~ \.php$ {
fastcgi_pass unix:/var/run/fastcgi/fastcgi.socket;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
} 启动nginx服务
# systemctl start nginx.service
# systemctl status nginx.service
# systemctl enable nginx.service 第七步:
测试nginx是否工作正常,是否能支持php
在nginx家目录里加上php测试页
# vim /usr/share/nginx/html/test.php
<?php
phpinfo();
?>
找一个有firefox的客户端分别访问下面页面进行测试
http://172.16.25.2/
http://172.16.25.2/test.php 第八步:
安装discuz论坛并测试 (相关软件包共享在 笔记目录/program/lnmp_soft/ 目录)
1,解压discuz到nginx家目录
# mkdir /usr/share/nginx/html/discuz/
# unzip Discuz_X3.3_SC_UTF8.zip -d /usr/share/nginx/html/discuz/
# cd /usr/share/nginx/html/discuz/
# mv upload/* .
# rm upload/ -rf 2,然后使用firefox用下面的路径来安装
http://172.16.25.2/discuz 3,环境检查这一步,有些目录和文件权限需要修改(下面直接使用简单方式全改成nginx的owner和group)
# chown nginx.nginx /usr/share/nginx/html/discuz -R 4,mariadb数据库授权
# mysql
MariaDB [(none)]> create database lnmp_discuz; --创建一个库,用于存放将要安装的discuz论坛的表
MariaDB [(none)]> grant all on lnmp_discuz.* to 'lnmpdiscuz'@'localhost' identified by '123'; --授权一个用户,用于discuz论坛程序连接mysql
MariaDB [(none)]> flush privileges; 5,http://172.16.25.2/discuz/路径填上对应的数据库地址,库,用户,密码。开始安装 6,访问http://172.16.25.2/discuz/测试论坛 ==================================================================================
补充一:
memcache介绍与安装
memcache是一个开源分布式的内存对象缓存系统(redis与其类似).一般放在web程序与数据库,帮助缓存程序取数据库的数据。
client
|
    正向代理(静态)

因特网
|
squid或varnish(静态)
|
nginx

php-factcgi(opcache做php代码缓存)
|
memcache或redis
|
mysql(query_cache) # yum install memcached php-pecl-memcache --前面是memcached主程序包,后面是php支持memcache的模块包 # systemctl start memcached.service
# systemctl status memcached.service
# systemctl enable memcached.service
# systemctl restart php-fpm.service --重启php-fpm,让php支持memcache模块生效 # lsof -i:11211
上面是安装完memcached后,可以让开发人员使用。
如果是像discuz这种开源论坛安装完后,我没有开发能力,如何让discuz使用memcache? 使用安装时的admin用户和密码登陆后台http://172.16.25.2/discuz/admin.php
点全局--》性能优化--》内存优化
可以看到memcache是支持,但是关闭的 把关闭状态改成打开的方法为:
# vim /usr/share/nginx/html/discuz/config/config_global.php
25 $_config['memory']['memcache']['server'] = '127.0.0.1'; --把这个IP127.0.0.1配上(如果memcache在另一台机器上,就写它的IP) 保存后,再刷新后台的内存优化界面状态就变为打开了
==========================================================================
# yum install redis php-pecl-redis
# systemctl restart php-fpm.service # vim /etc/redis.conf
daemonize yes --改为yes,表示运行成daemon模式 # systemctl start redis.service
# systemctl status redis.service
# systemctl enable redis.service
# systemctl restart php-fpm.service --重启php-fpm,让php支持redis模块生效 # lsof -i:6379 使用安装时的admin用户和密码登陆后台http://172.16.25.2/discuz/admin.php 点全局--》性能优化--》内存优化
可以看到redis是支持,但是关闭的 把关闭状态改成打开的方法为:
# vim /usr/share/nginx/html/discuz/config/config_global.php
19 $_config['memory']['redis']['server'] = '127.0.0.1'; 再回到web去刷新,就可以看到redis是支持并且打开状态了
=====================================================================
把单机lnmp分离成多机
client nginx php(fastcgi) opcache memcache或redis mysql client CDN
squid或varnish squid或varnish nginx_web nginx_web php(fastcgi) php(fastcgi) memcache或redis memcache或redis
mysql主 mysql从1 mysql从2
写 读 读
==============================================================================

lnmp架构搭建实例的更多相关文章

  1. 企业级LNMP架构搭建实例(基于Centos6.x)

    1.1 部署LNMP架构说明 1.1.1 LNMP架构内容 01.部署linux系统 02.部署nginx网站服务 03.部署mysql数据库服务 04.部署php动态解析服务 1.1.2 配置LNM ...

  2. 基于LNMP架构搭建wordpress博客之安装架构说明

    架构情况 架构情况:基于LNMP架构搭建wordpress系统 软件包版本说明: 系统要求 :  CentOS-6.9-x86_64-bin-DVD1.iso PHP版本  :  php-7.2.29 ...

  3. 部署企业LNMP架构搭建bbs

    部署企业LNMP架构 1===============部署Nginx 2===============安装及部署Mysql数据库 3===============安装PHP解析环境 4======== ...

  4. Linux系统下LNMP架构搭建

    一.防火墙状态: 1.查看防火墙状态: systemctl status firewalld service iptables status firewall-cmd --state 2.永久有效开启 ...

  5. LNMP架构搭建

    目录 一:LNMP架构简介 1.Nginx与uwsgi 二:django框架+python 1.创建用户 2.安装依赖包 3.安装uwsgi和django 4.测试python 5.创建django项 ...

  6. Linux LNMP架构搭建

    一.搭建LNMP基本架构 1.L(http) N(nginx) M(mysql) P(php) 2.安装顺序 Mysql-->PHP-->Nginx 3.安装包 Discuz_3. htt ...

  7. springmvc整合redis架构搭建实例

    新换环境,又有新东西可以学习了,哈皮! 抽空学习之余看了一下redis,个人对Springmvc的爱是忠贞不渝,所以整理了一下Springmvc整合redis的环境搭建.分享学习. 第一步: 创建ma ...

  8. 基于LNMP架构搭建wordpress个人博客

    搭建过程 注意防火墙和selinux的影响可以先关闭. 一.安装nginx # 1.更改nginx源安装nginx [root@web01 ~]# vi /etc/yum.repos.d/nginx. ...

  9. LNMP系统服务搭建过程详解

    和LAMP不同的是LNMP中的N指的是Nginx(类似于Apache的一种web服务软件)其他都一样.目前这种环境应用的也是非常之多.Nginx设计的初衷是提供一种快速高效多并发的web服务软件.在静 ...

随机推荐

  1. Squid配置之使用帐号密码验证

      转自: https://blog.csdn.net/atco/article/details/43448885   1.安装squid使用root用户进行操作.先使用rpm检测是否已经安装了sql ...

  2. css实现三栏自适应布局(两边固定,中间自适应)以及优缺点

    方法一:绝对定位(absolute + margin) 原理:给左右两边的元素设置absolute,这样左右两边的元素脱离标准文档流的控制,中间的元素自然会上来,然后给中间的元素设置margin留出左 ...

  3. 4 HttpServletResponse 与 HttpServletRequest

    Web 服务器收到一个http请求,会针对每个请求创建一个HttpServletRequest 和 HttpServletReponse 对象,response用于向客户端发送数据,request用于 ...

  4. VMware与CentOS的安装与Linux简单指令

    一 . VMware与CentOS系统安装 下载CentOS系统的ISO镜像 # 官方网站,国外网站,下载速度会很慢 www.centos.org # 由于国外的下载速度慢,我们可以使用国内的镜像源 ...

  5. 在windows 7上安装TensorFlow

    TensorFlow是一个开源软件库,用于各种感知和语言理解任务的机器学习.目前被50个团队用于研究和生产许多Google商业产品,如语音识别.Gmail.Google 相册和搜索,其中许多产品曾使用 ...

  6. playframework 编译打包过程失败

    root@mytest:/data# play war p2p-master --exclude tmp:logs:test:eclipse -o /data/a/sp2p~ _ _ ~ _ __ | ...

  7. 使用Guava cache构建本地缓存

    前言 最近在一个项目中需要用到本地缓存,在网上调研后,发现谷歌的Guva提供的cache模块非常的不错.简单易上手的api:灵活强大的功能,再加上谷歌这块金字招牌,让我毫不犹豫的选择了它.仅以此博客记 ...

  8. LR运行负载测试场景-笔记

    控制虚拟用户的行为:通用如图方式 查看用户的运行信息 在控制器释放前释放集合点用户 记录运行时注释---scenario-execution notes Vuser 对话框:初始化.运行.停止运行用户 ...

  9. SQL字段类型bit 查询时注意

    sql 查询时  字段=1 或 字段=0 c# 里也是

  10. How to RAMDISK on macOS

    diskutil erasevolume HFS+ 'RAM Disk' `hdiutil attach -nomount ram://8388608`