LNMP环境部署
- 软件规划
件 版本 Nginx Nginx 1.16.1 MySQL MySQL 5.7.28 PHP PHP 7.0.33
- 系统规划
操作系统:CentOS Linux release 7.3.1611
主机 IP地址 node07.host.com 172.24.248.19 node08.host.com 172.24.248.20 node09.host.com 172.24.248.21
WEB服务器也称为WWW(WORLD WIDE WEB)服务器,主要功能是提供网上信息浏览服务。 WWW 是 Internet的多媒体信息查询工具,是 Internet 上近年才发展起来的服务,也是发展最快和目前用的最广泛的服务。正是因为有了WWW工具,才使得近年来 Internet 迅速发展,且用户数量飞速增长。
Nginx (“engine x”) 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,第一个公开版本0.1.0发布于2004年10月4日。其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。
它已经在众多流量很大的俄罗斯网站上使用了很长时间,这些网站包括Yandex、Mail.Ru、VKontakte,以及Rambler。据Netcraft统计,在2012年8月份,世界上最繁忙的网站中有11.48%使用Nginx作为其服务器或者代理服务器。目前互联网主流公司360、百度、新浪、腾讯、阿里等,目前中国互联网企业70%以上公司都在使用nginx作为自己的web服务器。
Nginx特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好。
Nginx由内核和模块组成,其中,内核的设计非常微小和简洁,完成的工作也非常简单,仅仅通过查找配置文件将客户端请求映射到一个location block(location是Nginx配置中的一个指令,用于URL匹配),而在这个location中所配置的每个指令将会启动不同的模块去完成相应的工作。
Nginx相对于Apache优点
:1) 高并发响应性能非常好,官方Nginx处理静态文件并发5w/s 2) 反向代理性能非常强。(可用于负载均衡) 3) 内存和cpu占用率低。(为Apache的1/5-1/10) 4) 对后端服务有健康检查功能。 5) 支持PHP cgi方式和fastcgi方式。 6) 配置代码简洁且容易上手。
Nginx由内核和模块组成,其中,内核的设计非常微小和简洁,完成的工作也非常简单,仅仅通过查找配置文件将客户端请求映射到一个location block(location是Nginx配置中的一个指令,用于URL匹配),而在这个location中所配置的每个指令将会启动不同的模块去完成相应的工作.
Nginx的模块从结构上分为核心模块、基础模块和第三方模块
:核心模块:HTTP模块、EVENT模块和MAIL模块 基础模块:HTTP Access模块、HTTP FastCGI模块、HTTP Proxy模块和HTTP Rewrite模块, 第三方模块:HTTP Upstream Request Hash模块、Notice模块和HTTP Access Key模块。 Nginx的高并发得益于其采用了epoll模型,与传统的服务器程序架构不同,epoll是linux内核2.6以后才出现的。Nginx采用epoll模型,异步非阻塞,而Apache采用的是select模型: Select特点:select 选择句柄的时候,是遍历所有句柄,也就是说句柄有事件响应时,select需要遍历所有句柄才能获取到哪些句柄有事件通知,因此效率是非常低。 epoll的特点:epoll对于句柄事件的选择不是遍历的,是事件响应的,就是句柄上事件来就马上选择出来,不需要遍历整个句柄链表,因此效率非常高
- 环境依赖
[[email protected] ~]# yum -y install vim lrzsz tree screen psmisc lsof tcpdump wget ntpdate gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel net-tools iotop bc zip unzip zlib-devel bash-comletion nfs-utils automake libxml2 libxml2-devel libxslt libxslt-devel perl perl-ExtUtils-Embed gd-devel GeoIP GeoIP-devel GeoIP-data
- 编译安装nginx
[[email protected] /usr/local/src]# tar xf nginx-1.16.1.tar.gz [[email protected] /usr/local/src]# useradd nginx -s /sbin/nologin -u 2000 [[email protected] /usr/local/src]# cd nginx-1.16.1 [[email protected] /usr/local/src/nginx-1.16.1]# cat src/core/nginx.h |grep NGINX_VER #define NGINX_VERSION "1.16.1" define NGINX_VER "nginx/" NGINX_VERSION #开启server_tokens显示此信息 [[email protected] /usr/local/src/nginx-1.16.1]# cat src/http/ngx_http_header_filter_module.c |grep "NGINX_VER_BUILD" static u_char ngx_http_server_build_string[] = "Server: " NGINX_VER_BUILD CRLF; #关闭server_tokens显示此信息 [[email protected] /usr/local/src/nginx-1.16.1]# [[email protected] /usr/local/src/nginx-1.16.1]# ./configure --prefix=/apps/nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_image_filter_module --with-http_geoip_module --with-http_gunzip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module [[email protected] /usr/local/src/nginx-1.16.1]# make && make install
- 配置nginx,自定义json日志,error页面,并启动nginx
[[email protected] /apps/nginx/conf]# egrep -v "#|^$" nginx.conf user nginx; worker_processes 2; worker_cpu_affinity 01 10; error_log /apps/nginx/logs/error.log error; pid /apps/nginx/logs/nginx.pid; worker_priority 0; worker_rlimit_nofile 65536; events { worker_connections 65536; use epoll; accept_mutex on; multi_accept on; } http { include mime.types; default_type application/octet-stream; log_format access_json '{"@timestamp":"$time_iso8601",' '"host":"$server_addr",' '"clientip":"$remote_addr",' '"size":$body_bytes_sent,' '"responsetime":$request_time,' '"upstreamtime":"$upstream_response_time",' '"upstreamhost":"$upstream_addr",' '"http_host":"$host",' '"uri":"$uri",' '"domain":"$host",' '"xff":"$http_x_forwarded_for",' '"referer":"$http_referer",' '"tcp_xff":"$proxy_protocol_addr",' '"http_user_agent":"$http_user_agent",' '"status":"$status"}'; access_log /apps/nginx/logs/access_json.log access_json; sendfile on; keepalive_timeout 65 65; server_tokens off; server { listen 80; server_name localhost; charset utf-8; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } include /apps/nginx/conf/conf.d/*.conf; } [[email protected] /apps/nginx/conf]# [[email protected] /apps/nginx]# cd html/ [[email protected] /apps/nginx/html]# echo "access page error" > error.html [[email protected] /apps/nginx/html]# chown nginx.nginx -R /apps/nginx/ # 查看版本以及编译参数 [[email protected] ~]# /apps/nginx/sbin/nginx -V nginx version: nginx/1.16.1 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/apps/nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_image_filter_module --with-http_geoip_module --with-http_gunzip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module # 检查nginx配置语法是否正确 [[email protected] ~]# /apps/nginx/sbin/nginx -t nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok nginx: configuration file /apps/nginx/conf/nginx.conf test is successful [[email protected] ~]# # 启动nginx [[email protected] ~]# /apps/nginx/sbin/nginx
- 页面验证nginx
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-gk6DeCFP-1612149734988)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20210126173130434.png)]
- 二进制安装mysql
[[email protected] ~]# tar xf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz [[email protected] ~]# ln -sv /usr/local/mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql-5.6.36 "/usr/local/mysql-5.6.36" -> "/usr/local/mysql-5.6.36-linux-glibc2.5-x86_64" [[email protected] ~]# useradd mysql -s /sbin/nologin [[email protected] ~]# mkdir -pv /opt/mysql /var/lib/mysql mkdir: 已创建目录 "/opt/mysql" [[email protected] ~]# chown -R mysql.mysql /opt/mysql /var/lib/mysql -R
- 初始化数据库
[[email protected] ~]# /usr/local/mysql-5.6.36/scripts/mysql_install_db --user=mysql --datadir=/opt/mysql --basedir=/usr/local/mysql-5.6.36 [[email protected] ~]# cp /usr/local/mysql-5.6.36/support-files/mysql.server /etc/init.d/mysqld [[email protected] ~]# chmod a+x /etc/init.d/mysqld
- 配置文件
[[email protected] /usr/local/mysql-5.6.36]# cat my.cnf [mysqld] basedir = /usr/loca/mysql datadir = /opt/mysql port = 3306 # server_id = ..... socket = /opt/mysql/mysql.sock user=mysql symbolic-links=0 innodb_file_per_table=1 max_connections=10000 [client] port=3306 socket = /var/lib/mysql/mysql.sock [mysqld_safe] log-error=/usr/local/mysql/log/mysqld.log pid-file=/tmp/mysql.sock [[email protected] /usr/local/mysql-5.6.36]# [[email protected] /usr/local/mysql-5.6.36/log]# touch mysqld.log [[email protected] /usr/local/mysql-5.6.36]# ./mysql.server start Starting MySQL..... SUCCESS!
- 软件环境依赖
[[email protected] ~]# yum -y install pcre pcre-devel openssl openssl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison libevent automake libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel openjpeg bzip2 bzip2-devel
- 解压安装
[[email protected] /usr/local/src]# wget https://museum.php.net/php7/php-7.2.15.tar.gz [[email protected] /usr/local/src]# tar xf php-7.2.15.tar.gz [[email protected] /usr/local/src]# cd php-7.2.15 [[email protected] /usr/local/src/php-7.2.15]# ./configure --prefix=/apps/php-7.2.15 --with-config-file-path=/apps/php-7.2.15/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-pear --with-curl --with-png-dir --with-freetype-dir --with-iconv --with-mhash --with-zlib --with-xmlrpc --with-xsl --with-openssl --with-mysqli --with-pdo-mysql --disable-debug --enable-zip --enable-sockets --enable-soap --enable-inline-optimization --enable-xml --enable-ftp --enable-exif --enable-wddx --enable-bcmath --enable-calendar --enable-shmop --enable-dba --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-libxml --with-gd --with-jpeg-dir --with-bz2 --with-mcrypt --enable-gd-native-ttf --enable-fastcgi --enable-pdo --enable-mbstring --enable-exif --enable-opcache --enable-mbregex --enable-pcntl --with-gettext --enable-session --enable-ctype --enable-dom --with-libdir=lib64 --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --disable-fileinfo [[email protected] /usr/local/src/php-7.2.15]# make && make install
- 生成配置文件
[[email protected] ~]# cd /apps/php-7.2.15/etc/php-fpm.d/ [[email protected] /apps/php-7.2.15/etc/php-fpm.d]# cp www.conf.default www.conf [[email protected] /apps/php-7.2.15/etc/php-fpm.d]# cp /usr/local/src/php-7.2.15/php.ini-production /apps/php-7.2.15/etc/php.ini [[email protected] /apps/php-7.2.15/etc/php-fpm.d]# useradd www -s /sbin/nologin -u 1001 [[email protected] /apps/php-7.2.15/etc/php-fpm.d]# cat www.conf [www] user = www group = www listen = 127.0.0.1:9000 listen.allowed_clients = 127.0.0.1 pm = dynamic pm.max_children = 50 pm.start_servers = 30 pm.min_spare_servers = 30 pm.max_spare_servers = 35 pm.status_path = /status ping.path = /ping ping.response = pong access.log = log/$pool.access.log slowlog = log/$pool.log.slow [[email protected] /apps/php-7.2.15/etc/php-fpm.d]# [[email protected] /apps/php-7.2.15/etc]# mkdir /apps/php-7.2.15/log [[email protected] /apps/php-7.2.15/etc]# cp php-fpm.conf.default php-fpm.conf [[email protected] /apps/php-7.2.15/etc]#
- 启动并验证php-fpm
[[email protected] ~]# /apps/php-7.2.15/sbin/php-fpm -t [29-Jan-2021 13:59:28] NOTICE: configuration file /apps/php-7.2.15/etc/php-fpm.conf test is successful # 验证php-fpm [[email protected] ~]# /apps/php-7.2.15/sbin/php-fpm -c /apps/php-7.2.15/etc/php.ini [[email protected] ~]# netstat -lntp |grep 9000 tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 1630/php-fpm: maste
- 准备测试页
[[email protected] ~]# cat /apps/nginx/html/index.php <?php phpinfo(); ?> [[email protected] ~]#
- 整合php
[[email protected] ~]# cat /apps/nginx/conf/nginx.conf|egrep -v "#|^$" user nginx; worker_processes 2; worker_cpu_affinity 01 10; error_log /apps/nginx/logs/error.log error; pid /apps/nginx/logs/nginx.pid; worker_priority 0; worker_rlimit_nofile 65536; events { worker_connections 65536; use epoll; accept_mutex on; multi_accept on; } http { include mime.types; default_type application/octet-stream; log_format access_json '{"@timestamp":"$time_iso8601",' '"host":"$server_addr",' '"clientip":"$remote_addr",' '"size":$body_bytes_sent,' '"responsetime":$request_time,' '"upstreamtime":"$upstream_response_time",' '"upstreamhost":"$upstream_addr",' '"http_host":"$host",' '"uri":"$uri",' '"domain":"$host",' '"xff":"$http_x_forwarded_for",' '"referer":"$http_referer",' '"tcp_xff":"$proxy_protocol_addr",' '"http_user_agent":"$http_user_agent",' '"status":"$status"}'; access_log /apps/nginx/logs/access_json.log access_json; sendfile on; keepalive_timeout 65 65; server_tokens off; server { listen 80; server_name localhost; charset utf-8; location / { root html; index index.php index.html index.htm; if ($http_user_agent ~ "ApacheBench|WebBench|TurnitinBot|Sogou web spider|Grid service"){ return 403; } } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } include /apps/nginx/conf/conf.d/*.conf; } [[email protected] ~]#
- 重启nginx,验证php
[[email protected] ~]# /apps/nginx/sbin/nginx -t nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok nginx: configuration file /apps/nginx/conf/nginx.conf test is successful [[email protected] ~]# /apps/nginx/sbin/nginx -s reload
- 修改配置文件,在配置文件增加虚拟主机,配置参数和虚拟主机一旦很多,很容易很长,采用多配置分开的模式如在nginx.conf http模块中引用
[[email protected] ~]# cd /apps/nginx/conf/ include /apps/nginx/conf/conf.d/*.conf;
- 增加虚拟主机访问节点配置
[[email protected] /apps/nginx/conf]# mkdir conf.d [[email protected] /apps/nginx/conf/conf.d]# cat pc.conf server { listen 80; server_name 172.24.248.20; location / { root /data/nginx/html/pc; index index.html; } location /images { root /data/nginx/images; index index.html; } error_page 500 502 503 504 404 /error.html; location = /error.html{ root html; } } [[email protected] /apps/nginx/conf/conf.d]# [[email protected] /data/nginx]# cat /data/nginx/images/index.html images [[email protected] /data/nginx]# cat /data/nginx/html/pc/index.html pc web [[email protected] /data/nginx]# curl 172.24.248.20 pc web [[email protected] /data/nginx]# curl 172.24.248.20/images images png
总结:
LNMP整体安装相对比较简单,而源码安装需要提前准备好源码包以及环境依赖。另外环境安装可以不需要过多去关注,更多的则是配置方面,因为安装好之后就不会在去处理,当然安装的方式分可选择自动化运维工具一键安装,也可以使用脚本一键安装。
文章浏览阅读331次。第一部分:准备工作1 安装虚拟机2 安装centos73 安装JDK以上三步是准备工作,至此已经完成一台已安装JDK的主机第二部分:准备3台虚拟机以下所有工作最好都在root权限下操作1 克隆上面已经有一台虚拟机了,现在对master进行克隆,克隆出另外2台子机;1.1 进行克隆21.2 下一步1.3 下一步1.4 下一步1.5 根据子机需要,命名和安装路径1.6 ..._创建一个hadoop项目
文章浏览阅读1.7k次。心脏滴血漏洞HeartBleed CVE-2014-0160 是由heartbeat功能引入的,本文从深入码层面的分析该漏洞产生的原因_heartbleed代码分析
文章浏览阅读1.4k次。前言ofd是国家文档标准,其对标的文档格式是pdf。ofd文档是容器格式文件,ofd其实就是压缩包。将ofd文件后缀改为.zip,解压后可看到文件包含的内容。ofd文件分析工具下载:点我下载。ofd文件解压后,可以看到如下内容: 对于xml文件,可以用文本工具查看。但是对于印章文件(Seal.esl)、签名文件(SignedValue.dat)就无法查看其内容了。本人开发一款ofd内容查看器,..._signedvalue.dat
文章浏览阅读1.8w次,点赞29次,收藏313次。整体系统设计本设计主要是对ADC和DAC的使用,主要实现功能流程为:首先通过串口向FPGA发送控制信号,控制DAC芯片tlv5618进行DA装换,转换的数据存在ROM中,转换开始时读取ROM中数据进行读取转换。其次用按键控制adc128s052进行模数转换100次,模数转换数据存储到FIFO中,再从FIFO中读取数据通过串口输出显示在pc上。其整体系统框图如下:图1:FPGA数据采集系统框图从图中可以看出,该系统主要包括9个模块:串口接收模块、按键消抖模块、按键控制模块、ROM模块、D.._基于fpga的信息采集
文章浏览阅读2.5w次。1.背景错误信息:-- [http-nio-9904-exec-5] o.s.c.n.z.filters.post.SendErrorFilter : Error during filteringcom.netflix.zuul.exception.ZuulException: Forwarding error at org.springframework.cloud..._com.netflix.zuul.exception.zuulexception
文章浏览阅读358次。1.介绍图的相关概念 图是由顶点的有穷非空集和一个描述顶点之间关系-边(或者弧)的集合组成。通常,图中的数据元素被称为顶点,顶点间的关系用边表示,图通常用字母G表示,图的顶点通常用字母V表示,所以图可以定义为: G=(V,E)其中,V(G)是图中顶点的有穷非空集合,E(G)是V(G)中顶点的边的有穷集合1.1 无向图:图中任意两个顶点构成的边是没有方向的1.2 有向图:图中..._给定一个邻接矩阵未必能够造出一个图
文章浏览阅读321次。(十二)、WDS服务器安装通过前面的测试我们会发现,每次安装的时候需要加域光盘映像,这是一个比较麻烦的事情,试想一个上万个的公司,你天天带着一个光盘与光驱去给别人装系统,这将是一个多么痛苦的事情啊,有什么方法可以解决这个问题了?答案是肯定的,下面我们就来简单说一下。WDS服务器,它是Windows自带的一个免费的基于系统本身角色的一个功能,它主要提供一种简单、安全的通过网络快速、远程将Window..._doc server2012上通过wds+mdt无人值守部署win11系统.doc
文章浏览阅读219次。python–xlrd/xlwt/xlutilsxlrd只能读取,不能改,支持 xlsx和xls 格式xlwt只能改,不能读xlwt只能保存为.xls格式xlutils能将xlrd.Book转为xlwt.Workbook,从而得以在现有xls的基础上修改数据,并创建一个新的xls,实现修改xlrd打开文件import xlrdexcel=xlrd.open_workbook('E:/test.xlsx') 返回值为xlrd.book.Book对象,不能修改获取sheett_xlutils模块可以读xlsx吗
文章浏览阅读8.2w次,点赞267次,收藏656次。运行Selenium出现'WebDriver' object has no attribute 'find_element_by_id'或AttributeError: 'WebDriver' object has no attribute 'find_element_by_xpath'等定位元素代码错误,是因为selenium更新到了新的版本,以前的一些语法经过改动。..............._unresolved attribute reference 'find_element_by_id' for class 'webdriver
文章浏览阅读198次。一:模态窗口//父页面JSwindow.showModalDialog(ifrmehref, window, 'dialogWidth:550px;dialogHeight:150px;help:no;resizable:no;status:no');//子页面获取父页面DOM对象//window.showModalDialog的DOM对象var v=parentWin..._jquery获取父window下的dom对象
文章浏览阅读1.7w次,点赞15次,收藏129次。算法(algorithm)是解决一系列问题的清晰指令,也就是,能对一定规范的输入,在有限的时间内获得所要求的输出。 简单来说,算法就是解决一个问题的具体方法和步骤。算法是程序的灵 魂。二、算法的特征1.可行性 算法中执行的任何计算步骤都可以分解为基本可执行的操作步,即每个计算步都可以在有限时间里完成(也称之为有效性) 算法的每一步都要有确切的意义,不能有二义性。例如“增加x的值”,并没有说增加多少,计算机就无法执行明确的运算。 _算法
文章浏览阅读1.5k次,点赞18次,收藏26次。网络安全的标准和规范是网络安全领域的重要组成部分。它们为网络安全提供了技术依据,规定了网络安全的技术要求和操作方式,帮助我们构建安全的网络环境。下面,我们将详细介绍一些主要的网络安全标准和规范,以及它们在实际操作中的应用。_网络安全标准规范