LNMP架构--linux7.4+nginx1.13.9+mysql5.7.20+php7.1.10

一、 环境
安装包下载地址:http://nginx.org/en/download.html
service firewalld stop
systemctl disable firewalld
将安装包通过WinSCP传到虚拟机


二、 nginx安装
yum -y install \
gcc \
gcc-c++ \
make \
pcre-devel \
zlib-devel
[[email protected] ~]# useradd -M -s /sbin/nologin nginx //创建程序用户nginx,不能登录,没有家目录
[[email protected] ~]# tar xzvf nginx-1.13.9.tar.gz
[[email protected] ~]# cd nginx-1.13.9
[[email protected] nginx-1.13.9]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module //日志分析模块
[[email protected] nginx-1.13.9]# make && make install //编译及安装
[[email protected] nginx-1.13.9]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ //为nginx可执行程序做软连接,让系统可识别

nginx -t //配置文件语法检查
nginx //启动服务
killall -1 nginx //安全重启
killall -3 nginx //停止服务

----------------------------------------制作管理角本---------------------------
[[email protected] nginx-1.13.9]# vi /etc/init.d/nginx
#!/bin/bash

chkconfig: 35 99 20 //3,5级别自动运行,第99个进程开启,第20个进程结束

description: Nginx Service Control Script

PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.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
:x
[[email protected] nginx-1.13.9]# chmod +x /etc/init.d/nginx //给管理脚本添加执行权限
[[email protected] nginx-1.13.9]# chkconfig --add nginx //将nginx添加到chkconfig系统管理工具中

------------------------下面对nginx配置文件进行初始配置-------------------
[[email protected] nginx-1.13.9]# vi /usr/local/nginx/conf/nginx.conf
user nginx nginx; //修改nginx启动进程的属主和属组
worker_processes 1; //CPU核数,几核便设为几
error_log logs/error.log info; //修改错误日志的级别
注释:日志级别共有这几种:debug info notice warn error crit 其中规则是向上记录,即info级别的日志会涵盖notice warn error crit,低级的包涵高级的,不放在配置文件里面

events {
use epoll; //新增此行 默认使用select/poll
worker_connections 1024; //表示1个进程允许1024个连接,如果设置超过1024则需要修改ulimit上限,否则报错(ulimit -n 65500//查看和更改系统本地打开资源数
ulimit -n 65500 >> /etc/rc.local)
log_format main //定义日志格式 把前面的#号去掉
[[email protected] nginx-1.13.9]# service nginx restart
配置完之后重启,现在nginx服务器已经可以支持访问了

------------------------------------配置nginx自带的日志统计模块------------------------------------
[[email protected] nginx-1.13.9]# vi /usr/local/nginx/conf/nginx.conf
location ~ /status {
stub_status on;
access_log off;
}
[[email protected] nginx-1.13.9]# service nginx reload
[[email protected] nginx-1.13.9]# cat /usr/local/nginx/logs/access.log
浏览器:http://IP/status //当前的活动连接数,已处理的连接数,成功的TCP握手次数,已处理的请求数。

------------------------以下配置nginx的验证功能----------------------------

[[email protected] nginx-1.13.9]# yum install httpd-tools -y //安装apache的工具,借助工具创建访问用户
[[email protected] nginx-1.13.9]# htpasswd -c /usr/local/nginx/passwd.db jack //创建数据库验证文件,并把jack用户添加进去
New password:输密码
Re-type new password:确认密码
Adding password for user jack

[[email protected] nginx-1.13.9]# chmod 400 /usr/local/nginx/passwd.db //提高数据安全性
[[email protected] nginx-1.13.9]# chown nginx /usr/local/nginx/passwd.db //更改属主
[[email protected] nginx-1.13.9]# vi /usr/local/nginx/conf/nginx.conf
location / {
root html;
index index.html index.htm;
allow 192.168.80.0/24;
deny all;
auth_basic "secret";
auth_basic_user_file /usr/local/nginx/passwd.db; //注意这边的文件必须与上面创建的数据库验证文件统一
}
[[email protected] nginx-1.13.9]# service nginx restart
再次访问需要输入用户名和密码


三、 以下配置虚拟主机功能
-----------基于域名----------IP和端口都相同但是域名不相同----------
[[email protected] nginx-1.13.9]# vi /usr/local/nginx/conf/nginx.conf
“在最后一行上面插入,最后一行是个},结尾共4个}”
server {
listen 80;
server_name www.aa.com;
charset utf-8;
access_log logs/aa.access.log main;
location / {
root /usr/local/nginx/html;
index index.html index.htm;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
server {
listen 80;
server_name www.bc.com;
charset utf-8;
access_log logs/bc.access.log main;
location / {
root /var/www/bc;
index index.html index.htm;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
下面的去掉注释
http {
include mime.types;
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"‘;

[[email protected] nginx-1.13.9]# mkdir /var/www/aa -p
[[email protected] nginx-1.13.9]# mkdir /var/www/bc
在两个虚拟主机的网站目录添加主页
[[email protected] nginx-1.13.9]# vi /var/www/aa/index.html
<h1>www.aa.com</h1>
[[email protected] nginx-1.13.9]# vi /var/www/bc/index.html
<h1>www.bc.com</h1>
修改微软的hosts文件进行虚拟主机测试:
windows xp/2003/vista/2008/7/8用户HOSTS文件是在“c:\windows\system32\drivers\etc
hosts文件加上此句:192.168.80.102 www.aa.com www.bc.com
[[email protected] nginx-1.13.9]# nginx –t
[[email protected] nginx-1.13.9]# service nginx restart
[[email protected] nginx-1.13.9]# killall -1 nginx

四、 安装MySQL
[[email protected] ~]# yum -y install ncurses ncurses-devel bison cmake
[[email protected] ~]# useradd -s /sbin/nologin mysql //手动建一个账号
[[email protected] ~]# tar xf mysql-boost-5.7.20.tar.gz -C /opt/ //解压的目录要足够大,不然会报错
[[email protected] mysql-5.7.20]# cd /opt/mysql-5.7.20/
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ //指定sock文件的路劲
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \ //数据文件夹
-DWITH_BOOST=boost \
-DWITH_SYSTEMD=1
[[email protected] mysql-5.7.20]# make && make install
[[email protected] mysql-5.7.20]# chown -R mysql:mysql /usr/local/mysql/
[[email protected] mysql-5.7.20]# vi /etc/my.cnf
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES //固定格式
:x
[[email protected] mysql-5.7.20]# chown mysql:mysql /etc/my.cnf
[[email protected] mysql-5.7.20]# echo ‘PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH‘ >> /etc/profile //把这两个路径添加到环境变量中,并放到profile文件中使之开机自运行,否则不生效
[[email protected] mysql-5.7.20]# echo ‘export PATH‘ >> /etc/profile //也可以软链接
[[email protected] mysql-5.7.20]# source /etc/profile //立即生效
[[email protected] mysql-5.7.20]# cd /usr/local/mysql/
bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data //mysql初始化
[[email protected] mysql]# cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
[[email protected] mysql]# systemctl daemon-reload
[[email protected] mysql]# systemctl start mysqld
[[email protected] mysql]# netstat -anpt | grep 3306
[[email protected] mysql]# systemctl enable mysqld
[[email protected] mysql]# mysqladmin -u root -p password "123"
Enter password:(初始密码是空,直接回车就好)
[[email protected] mysql]# mysql -u root –p
mysql>
mysql>
mysql> quit
Bye
五、 安装PHP
[[email protected] mysql]# yum -y install \
libjpeg \
libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 \
libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel //安装需要支持的插件

[[email protected] ~]# yum -y install bzip2
[[email protected] ~]# tar xjvf php-7.1.10.tar.bz2 -C /opt/
[[email protected] ~]# cd /opt/php-7.1.10
[[email protected] php-7.1.10]# ./configure \
--prefix=/usr/local/php \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \ //配置协作
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip \ //支持压缩
--enable-fpm //支持动态页面fpm功能 (注意这个要手打,直接复制容易失败)

[[email protected] php-7.1.10]# make && make install
[[email protected] php-7.1.10]# cp php.ini-development /usr/local/php/lib/php.ini //复制php配置文件模板作为php配置文件
[[email protected] php-7.1.10]# vi /usr/local/php/lib/php.ini //编辑php配置文件
mysqli.default_socket = /usr/local/mysql/mysql.sock //编辑mysql的sock文件位置
date.timezone = Asia/Shanghai //选择时区
[[email protected] php-7.1.10]# /usr/local/php/bin/php –m //验证安装的模块
-----------配置及优化FPM模块--------
[[email protected] php-7.1.10]# cd /usr/local/php/etc/
[[email protected] etc]# cp php-fpm.conf.default php-fpm.conf //复制php的fpm模块的配置文件模板为配置文件。php只识别php-fpm.conf为配置文件
[[email protected] etc]# cd /usr/local/php/etc/php-fpm.d/
[[email protected] php-fpm.d]# cp www.conf.default www.conf //复制fpm的www配置文件模板为配置文件,fpm只识别www.conf的配置文件
[[email protected] php-fpm.d]# cd /usr/local/php/etc/
[[email protected] etc]# vi php-fpm.conf //配置fpm模块
pid = run/php-fpm.pid //将分号去掉
;user = nginx
;group = nginx //添加user和group
[[email protected] etc]# /usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini //启动fpm模块
[[email protected] etc]# netstat -anpt | grep 9000
[[email protected] etc]# ln -s /usr/local/php/bin/* /usr/local/bin/ //将php的可执行程序放到系统可识别环境中便于执行
[[email protected] etc]# ps aux | grep -c "php-fpm" //统计进程数
-----更新启动脚本,让fpm模块也可进行启动管理----------
[[email protected] etc]# vi /etc/init.d/nginx
#!/bin/bash

chkconfig: 35 99 20

description: Nginx Service Control Script

PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
PROG_FPM="/usr/local/php/sbin/php-fpm"
PIDF_FPM="/usr/local/php/var/run/php-fpm.pid"
case "$1" in
start)
$PROG
$PROG_FPM
;;
stop)
kill -s QUIT $(cat $PIDF)
kill -s QUIT $(cat $PIDF_FPM)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac
exit 0
-------------------以下是让nginx支持PHP功能--------------
[[email protected] etc]# vi /usr/local/nginx/conf/nginx.conf
location ~ .php$ {
root /usr/local/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; //注意目录名称,为网站根目录必须为绝对路径
include fastcgi_params;
}
[[email protected] etc]# vi /usr/local/nginx/html/index.php
<?php
phpinfo();
?>
[[email protected] etc]# nginx -t
[[email protected] etc]# service nginx restart
注意,为了防止干扰,需要把虚拟主机配置删除
在网页测试“http://192.168.80.193/index.php

-----------------------------------下面测试数据库工作是否正常---------------------
[[email protected] etc]# mysql -u root -p
Enter password:密码
mysql> CREATE DATABASE bbs; //创建数据库为bbs
mysql> GRANT all ON bbs.
TO ‘bbsadm‘@‘%‘ IDENTIFIED BY ‘admin123‘; //将数据库所有权限给bbsadm,密码为admin123
mysql> GRANT all ON bbs.* TO ‘bbsadm‘@‘localhost‘ IDENTIFIED BY ‘admin123‘; //允许
mysql> flush privileges; //刷新权限
mysql> quit
[[email protected] etc]# vi /usr/local/nginx/html/index.php
<?php
$link=mysqli_connect(‘192.168.80.102‘,‘bbsadm‘,‘admin123‘);
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
?>
在网页测试“http://IP/index.php

---------------------以下安装论坛---------------------------
[[email protected] etc]# yum install -y unzip
[[email protected] etc]# unzip Discuz_X3.4_SC_UTF8_0101.zip -d /opt //解压缩
[[email protected] ~]# cd /opt/dir_SC_UTF8/ //进入解压目录
[[email protected] dir_SC_UTF8]# cp -r upload/ /usr/local/nginx/html/bbs
[[email protected] dir_SC_UTF8]# cd /usr/local/nginx/html/bbs
[[email protected] bbs]# chown -R root:nginx ./config/
[[email protected] bbs]# chown -R root:nginx ./data/
[[email protected] bbs]# chown -R root:nginx ./uc_client/
[[email protected] bbs]# chown -R root:nginx ./uc_server/
[[email protected] bbs]#
[[email protected] bbs]# chmod -R 777 ./config/
[[email protected] bbs]# chmod -R 777 ./data/
[[email protected] bbs]# chmod -R 777 ./uc_client/
[[email protected] bbs]# chmod -R 777 ./uc_server/
访问http://IP/bbs/install/index.php //安装论坛





访问地址为http://IP/bbs/index.php

http://IP/bbs/admin.php //管理后台

-------------------------------------配置动静分离---------------------------
删除访问控制

Nginx主机上面配置:将b.jpg传到服务器
[[email protected] html]# vi /usr/local/nginx/conf/nginx.conf
location ~ .php$ {
proxy_pass http://192.168.80.101;
} //把PHP动态请求转给192.168.80.101
[[email protected] html]# rm index.php
[[email protected] html]# service nginx restart

Apache服务器上面配置:
[[email protected] ~]# cd /usr/local/httpd/htdocs/
[[email protected] htdocs]# vi index.html
<html>
<body>
<img src="http://192.168.80.102/b.jpg"&gt;
</body>
</html>
[[email protected] htdocs]# service httpd restart
浏览器输nginx服务器ip测试:

Nginx服务器修改:
[[email protected] html]# vi /usr/local/nginx/conf/nginx.conf
location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ {
root html;
expires 1d;
} //这些静态内容从本地读取
[[email protected] html]# service nginx restart
Apache服务器上面配置:
[[email protected] htdocs]# vi /usr/local/httpd/htdocs/index.php
<html>
<body>
<img src=" b.jpg">
</body>
</html>
[[email protected] htdocs]# service httpd restart

抓包测试:

原文地址:http://blog.51cto.com/13572519/2083783

时间: 2024-10-10 03:28:51

LNMP架构--linux7.4+nginx1.13.9+mysql5.7.20+php7.1.10的相关文章

笔记本安装centos7 php7.1.7 nginx1.13.2 mysql5.7 iptables

一.安装准备 首先由于nginx的一些模块依赖一些lib库,所以在安装nginx之前,必须先安装这些lib库,这些依赖库主要有g++.gcc.openssl-devel.pcre-devel和zlib-devel 所以执行如下命令安装 [html] view plaincopy $ yum install gcc-c++ $ yum install pcre pcre-devel $ yum install zlib zlib-devel $ yum install openssl openss

CentOS 6.2编译安装Nginx1.2.0+MySQL5.5.25+PHP5.3.13

CentOS 6.2编译安装Nginx1.2.0+MySQL5.5.25+PHP5.3.132013-10-24 15:31:12标签:服务器 防火墙 file 配置文件 written 一.配置好IP.DNS .网关,确保使用远程连接工具能够连接服务器 二.配置防火墙,开启80端口.3306端口1    vi/etc/sysconfig/iptables #编辑防火墙配置文件1    -A INPUT -m state --state NEW -m tcp -p tcp --dport 80

centos7.2+php7.0.10+mysql5.7.14+nginx1.10.1搭建LNMP环境

一.准备工作: 软件默认下载在/usr/local/src下,安装在/app/local下的php.mysql.nginx.data目录下,安装顺序按照nginx->mysql->php进行 编译工具集: yum install -y wget gcc gcc-c++ autoconf automake cmake bison m4 libxml2 libxml2-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel pcre

搭建基于Linux6.3+Nginx1.2+PHP5+MySQL5.5的Web服务器全过程----转载

之前的Web服务器都是通过yum搭建的,想要添加新模块或者更新某些软件都很不方便(牵一发而动全身啊!).所以,现在准备将环境改为源码编译安装,这样便于调整,性能上也会比yum方式好很多.以下是我的安装步骤,我的系统是CentOS 6.3 64位. 注意:本文所以配置都是基于第二步所下载的软件版本,安装其他版本不保证会成功 推荐阅读: 生产环境实用之LNMP架构的编译安装+SSL加密实现 http://www.linuxidc.com/Linux/2013-05/85099.htm LNMP 全功

高性能Web服务之lnmp架构应用

传统上基于进程或线程模型架构的web服务通过每进程或每线程处理并发连接请求,这势必会在网络和I/O操作时产生阻塞,其另一个必然结果则是对内存或CPU的利用率低下.生成一个新的进程/线程需要事先备好其运行时环境,这包括为其分配堆内存和栈内存,以及为其创建新的执行上下文等.这些操作都需要占用CPU,而且过多的进程/线程还会带来线程抖动或频繁的上下文切换,系统性能也会由此进一步下降. 在设计的最初阶段,nginx的主要着眼点就是其高性能以及对物理计算资源的高密度利用,因此其采用了不同的架构模型.受启发

第20章 使用LNMP架构部署动态网站环境

章节概述: 本章节将从Linux系统的软件安装方式讲起,带领读者分辨RPM软件包与源码安装的区别.并能够理解它们的优缺点. Nginx是一款相当优秀的用于部署动态网站的服务程序,Nginx具有不错的稳定性.丰富的功能以及占用较少的系统资源等独特特性. 通过部署Linux+Nginx+MYSQL+PHP这四种开源软件,便拥有了一个免费.高效.扩展性强.资源消耗低的LNMP动态网站架构了. 本章目录结构 20.1 源码安装程序 20.2 部署LNMP架构 20.2.1 配置Mysql服务 20.2.

源码编译安装lnmp架构

lnmp的架构 lnmp架构为:linux +nginx +mysql+php/perl/python,我们将只用linux(rhel6.5)+nginx+mysql+php构建企业web架构 环境:RHEL6.5 iptables -F selinux is  disabled 注意:在搭建lnmp环境前,必须检测系统内部不能存在相关的软件:(纯净搭建) #rpm -qa | grep php #rpm -qa | grep httpd #rpm -qa | grep mysql 1.ngin

Linux中详细搭建Lnmp架构

环境说明 ip 需要安装的程序 192.168.209.12 nginx mysql php *lnmp架构的安装的顺序* ①安装nginx ②安装mysql ③安装php ④最后配置nginx和创建php测试程序 ⑤验证 *******************①安装nginx*********************** 1.//创建系统用户nginx [[email protected] ~]# useradd -r -M -s /sbin/nologin nginx //安装依赖环境 [[

LNMP架构之Discuz论坛(实战!!)

LNMP架构 LNMP平台就是Linux,Nginx,MySQL,PHP的组合架构,需要Linux服务器,MySQL服务器,PHP解析环境 构成组件 Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统. Nginx是一个高性能的HTTP和反向代理服务器. Mysql是一个小型关系型数据库管理系统. PHP是一种在服务器端执行的嵌入HTML文档的脚本语言. LAMP优势 Nginx性能稳定.功能丰富.运维简单.处理静态文件速度快且消耗系统资源极少,小巧高效. 一,在Windo