找回密码
 立即注册
搜索
查看: 475|回复: 3

[L/WNAMP] LNMP 终极优化-----------删除

  [复制链接]
匿名
匿名  发表于 2023-2-9 16:13 |阅读模式
最终效果:


另外,如果是laravel这种重量级框架的话,可以参考:https://learnku.com/articles/18782 的文章。


接招:
Linux参数:1、#disable selinux
sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config


2、yum install ntp


3、linux最大文件打开数的默认值很低,必须修改的高一些


编辑文件:/etc/security/limits.conf

# End of file
root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535


4、系统中开启HugePages
sysctl vm.nr_hugepages=512
分配512个预留的大页内存
$ cat /proc/meminfo  | grep Huge
AnonHugePages:    106496 kB
HugePages_Total:     512
HugePages_Free:      504
HugePages_Rsvd:       27
HugePages_Surp:        0
Hugepagesize:       2048 kB


5.调整内核参数。经过一番折腾,tps有提升,但是不稳定,通过sysctl调整内核参数则稳定了。
vim /etc/sysctl.conf

net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_rmem = 4096        87380   4194304
net.ipv4.tcp_wmem = 4096        16384   4194304

net.ipv4.tcp_max_syn_backlog = 65536
net.core.netdev_max_backlog = 32768
net.core.somaxconn = 32768

net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216

net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2

net.ipv4.tcp_tw_recycle = 1
#net.ipv4.tcp_tw_len = 1
net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800

#net.ipv4.tcp_fin_timeout = 30
#net.ipv4.tcp_keepalive_time = 120
net.ipv4.ip_local_port_range = 1024 65535
 

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
匿名
匿名  发表于 2023-2-9 16:14
nginx配置优化:


nginx.conf:



events {

    use epoll;

    worker_connections 204800;

}


http{ 

    client_header_buffer_size    4k;

    large_client_header_buffers  4 4k;

    open_file_cache max=102400 inactive=60s;

    open_file_cache_valid 80s;



    fastcgi_connect_timeout 300;

    fastcgi_send_timeout 300;

    fastcgi_read_timeout 300;

    fastcgi_buffer_size 64k;

    fastcgi_buffers 8 64k;



    fastcgi_temp_path /dev/shm/fastcgi_temp; 

    fastcgi_cache_path /dev/shm/fastcgi_cache levels=1:2 keys_zone=cfcache:10m inactive=50m max_size=256; 

    fastcgi_cache_key "$request_method://$host$request_uri"; 

    fastcgi_cache_methods GET HEAD; 

    fastcgi_cache   cfcache;  //开启FastCGI缓存并且为其制定一个名称。 

    fastcgi_cache_valid 200 302 301 1h; 

    fastcgi_cache_valid   any 5m;   //为指定应答代码指定缓存时间,这里指定200 302 301应答缓存1小时,其余任何应答缓存5分钟 

    fastcgi_cache_min_uses  1;  //缓存在fastcgi_cache_path内文件在inactive参数值时间内的最少使用次数,如上例,这里在50分钟内某文件1次也没有被使用,那么这个文件将被移除。 

    fastcgi_cache_use_stale error  timeout invalid_header http_500;//对于error timeout invalid_header http_500等类型的应答内容不缓存 

    fastcgi_ignore_client_abort on;//忽略客户端终止请求 


    gzip on;

    gzip_min_length 1k;

    gzip_buffes 16 64k;

    gzip_http_version 1.1;

    gzip_comp_level 6;

    gzip_types text/plain application/x-javascript text/css application/javascript text/javascript image/jpeg image/gif image/png application/xml application/json;

    gzip_vary on;

    gzip_disable "MSIE [1-6].(?!.*SV1)";


匿名
匿名  发表于 2023-2-9 16:15
mysql配置优化:(这里弱化了,后期再补上)


long_query_time=2

log-slow-queries= /usr/local/webserver/mysql/logs/slowquery.log 

max_connections=200

key_buffer_size 

匿名
匿名  发表于 2023-2-9 16:18
PHP配置篇:


php.ini:



# 设置错误日志的路径

error_log = /var/log/php-fpm/error.log

 

# 引入www.conf文件中的配置

include=/usr/local/php7/etc/php-fpm.d/*.conf

 

# 设置主进程打开的最大文件数

rlimit_files = 102400


zend_extension=opcache.so

opcache.enable=1

opcache.memory_consumption=128

opcache.interned_strings_buffer=8

opcache.max_accelerated_files=4000

opcache.vilidate_timestamps=0

opcache.revalidate_freq=300

opcache.fast_shutdown=1

opcache.huge_code_pages=1

opcache.file_cache=/tmp




php-fpm.conf:


pid = run/php-fpm.pid

# 设置错误日志的路径

error_log = /var/log/php-fpm/error.log

 

 

# 设置主进程打开的最大文件数

rlimit_files = 65535


emergency_restart_threshold 10

emergency_restart_interval 1m

process_control_timeout 10s



www.conf:


# listen = 127.0.0.1:9000 

listen = /var/run/php-fpm/php-fpm.sock


listen.allowed_clients = 127.0.0.1

slowlog = /var/log/php-fpm/php-slow.log  

request_slowlog_timeout = 10s  

request_terminate_timeout = 30   


pm = dynamic 

pm.max_children = 25

# pm.start_servers不能小于pm.min_spare_servers,推荐为最大的pm.max_children的%10

pm.start_servers = 8

pm.min_spare_servers = 5

pm.max_spare_servers = 10

pm.max_requests = 10240



您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|学习笔记

GMT+8, 2024-10-28 20:30 , Processed in 0.024458 second(s), 14 queries , APCu On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表