lnmp:
l:linux系统
n:nginx前端页面
m:mysql数据库 账号密码,等等都是保存在这个数据库里面
p:php---------------nginx擅长处理的是静态页面,页面登入账号,需要请求到数据库,通过php把动态请求转发到数据库
my.cnf: mysql的主配置文件
php.ini 主配置文件
php-fpm.conf 进程服务器的的配置文件
www.conf 扩展配置文件
第一步:安装mysql数据库
apt install -y libaio1 libncurses5



[client]
port = 3306
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
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION



./mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data










第二步安装php


apt-get install -y libgd-dev libjpeg8-dev libpng-dev libfreetype6-dev libxml2-dev zlib1g-dev libcurl4-openssl-dev libssl-dev libonig-dev libsqlite3-dev


./configure \
--prefix=/usr/local/php: 指定PHP的安装目录为/usr/local/php。
--with-mysql-sock=/usr/local/mysql/mysql.sock: 指定MySQL的Unix socket文件路径,用于与MySQL数据库建立连接。
--with-mysqli: 启用MySQLi扩展,用于支持MySQL数据库。
--with-zlib: 启用Zlib库,用于压缩和解压缩数据。
--with-curl: 启用cURL库,用于支持对URL的操作,如下载文件等。
--with-gd: 启用GD库,用于处理图像。
--with-jpeg-dir: 指定JPEG库的路径,用于GD库对JPEG格式图片的处理。
--with-png-dir: 指定PNG库的路径,用于GD库对PNG格式图片的处理。
--with-freetype-dir: 指定FreeType库的路径,用于GD库对字体的支持。
--with-openssl: 启用OpenSSL库,用于支持SSL加密和HTTPS协议。
--enable-fpm: 启用PHP-FPM(FastCGI Process Manager),用于提供更高效的PHP进程管理和请求处理。
--enable-mbstring: 启用多字节字符串支持,用于处理多字节字符集的操作。
--enable-xml: 启用XML支持,用于处理XML文档和数据。
--enable-session: 启用会话支持,用于在不同页面间保持用户会话状态。
--enable-ftp: 启用FTP支持,用于对FTP服务器进行操作。
--enable-pdo: 启用PDO(PHP Data Objects),用于支持数据库访问的统一接口。
--enable-tokenizer: 启用Tokenizer扩展,用于对字符串进行分词处理。
--enable-zip: 启用Zip扩展,用于对ZIP文件进行操作。























CREATE DATABASE bbs;
CREATE USER 'bbsuser'@'%' IDENTIFIED BY 'admin123';
GRANT ALL PRIVILEGES ON bbs.* TO 'bbsuser'@'%';
FLUSH PRIVILEGES;
CREATE USER 'bbsuser'@'localhost' IDENTIFIED BY 'admin123';
GRANT ALL PRIVILEGES ON bbs.* TO 'bbsuser'@'localhost';
FLUSH PRIVILEGES;
exit

<?php
$link=mysqli_connect('192.168.233.61','bbsuser','admin123');
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
?>

第三步安装discuz














nginx的优化:
1、隐藏版本号
server_token off; 通用方法编译, apt yum 都可以用
只是隐藏版本,服务名称还在
修改源码文件:仅限于编译安装
server_token on;
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
2、nginx的日志分割:
nginx本身没有设计日志分割的工具,运维人员自己进行处理和分割
使用shell脚本实现日志分割:



定时任务

3、nginx页面压缩:
对文件进行压缩的功能,节约带宽,提高访问速度
http_gzip_module

图片的缓存

4、keepalive_timeout
http1.1之后特有的模式,keepalive模式,主流的前端软件都支持keepalive。
数据传送完毕之后,连接不是立刻断开。而是一段时间之内保存连接,无需再进行三次握手
如果需要传输数据,可以继续使用这个连接。
连接保持的时间一般在60-180秒,keepalive的连接保持的时间太长,会占用过多的系统资源,影响性能。
连接保持
会话保持:
我们和服务端建立连接之后,在一定时间保持登入或固定的状态,保证在浏览时,数据一致。
连接保持是关于连接的控制
会话保持是关于交互的控制
client_header_timeout 80;客户端向服务端发送一个完整请求头的超时时间。nginx就会返回408
client_body_timeout 80;
客户端和服务端建立连接之后,没有在规定时间内发送一个完整的请求体,或者没有请求任何内容,nginx也会返回408
5、nginx的并发处理
1、worker_processes 4 #修改为内核数量的2倍或一致,一般设置4个,不能超过8个,超过8个性能会下降
2、worker_cpu_affinity将nginx的进程绑定到cpu的核心,防止cpu之间的切换,提高性能。
对外访问

6、timewait回收机制:
timewait是tcp连接当中的一种正常状态。
http1.1版本多了一个连接保持。
timewait状态下,tcp连接处于等待连接,等待一个持续的时间,确保双方的数据尽可能的传输完毕。
两个目的:
1、确保连接时被可靠的关闭,即便是四次挥手之后,对方有可能还有数据未处理完毕,在timewait阶段可以保证数据依然被正确的处理,防止旧的数据包影响其他新的连接
2、避免出现连接复用的问题:如果timewait不存在,或者时间较短,旧的连接可能依然处于网络之中,有可能被认为新的连接。
当服务器上有大量的短链接频繁的创建和销毁,或者处理大量并发连接时,time_wait就会出现堆积。
如果堆积的数量太多,需要系统能够尽快的把time_wait回收。
/etc/sysctl.conf 修改内核配置的文件
尽快回收 centos支持,ubuntu内核不支持

fin-wait-1:终止等待1,表示应用程序已经发送了连接关闭的请求,正在等待另一段的确认
fin-wait-2:表示另一端以及确认连接关闭的请求,正在等待另一端发送连接关闭的请求
net.ipv4.tcp_tw_recycle=1
在NAT环境中,地址转换,会加速系统回收timewait,在nat环境中,源地址会发生变化,他总是基于源ip地址进行识别,多个客户端使用一个相同的外部ip地址时,连接混肴的情况,导致客户端无法正确连接。
7、配置防盗链:
防止别的用户通过连接的方式盗用网站的图片

cd html/ vim index.html

vim /etc/hosts

vaild_referers 设置信任的网站可以正常的使用图片
none:允许没有http_refer的请求, www.xy104.com/ls.jpg=www.xy104.com
blocked:允许不是http:/开头的请求,http:/www.xy104.com=www.xy104.com
$invalid_referer: 不是信任的网站的地址,就是认为是真,true,为真执行 rewrite就是重写,重定向访问:http:/www.xy104.com/error.png
cd html/ vim index.html

vim /etc/hosts
