centos fcgi centos镜像
大家好,关于centos fcgi很多朋友都还不太明白,不过没关系,因为今天小编就来为大家分享关于centos镜像的知识点,相信应该可以解决大家的一些困惑和问题,如果碰巧可以解决您的问题,还望关注下本站哦,希望对各位有所帮助!
真心求助.nginx错误
Nginx服务器错误一般有以下几点原因:
1、请求的header过大。nginx默认的header长度上限是4k,如果超过了这个值,nginx会直接返回400错误.
解决方法:配置nginx.conf相关设置。可以通过以下2个参数来调整header上限:
client_header_buffer_size 16k;large_client_header_buffers 4 16k。
2、上传文件过程中出现错误。这时浏览器显示“413 Request Entity Too Large”。这是因为没有设置client_max_body_size,这个参数默认只是1M,也就是说发布的文章内容大小不能超过1M。
解决方法:增加如下两行到nginx.conf的http{}段,增大nginx上传文件大小限制:设置允许发布内容为8M:client_max_body_size 8M;client_body_buffer_size 128k。
另外如果运行的是php,那么还要检查php.ini,这个大小client_max_body_size要和php.ini中的如下值的最大值一致或者稍大,这样就不会因为提交数据大小不一致出现的错误:post_max_size= 8M;upload_max_filesize= 6M。
修改完配置后,别忘记重新加载。
3、客户端在为等到服务器相应返回前就关闭了客户端描述符。一般出现在客户端设置超时后,服务器主动关闭。
解决方法:根据实际Nginx后端服务器的处理时间修改客户端超时时间。
4、脚本错误(php语法错误、lua语法错误)。
解决方法:查看nginx_err_log php_err_log。
5、访问量过大,系统资源限制,不能打开过多文件。磁盘空间不足。(access log开启可能导致磁盘满溢,服务器主动关闭)。
解决方法:修改/etc/sysctl.conf文件,并使用下面的命令确认:#sysctl-p。要使 limits.conf文件配置生效,必须要确保 pam_limits.so文件被加入到启动文件中。
6、后端服务无法处理,业务中断。
解决方法:从后端日志获取错误原因,解决后端服务器问题。
7、后端服务器在超时时间内,未响应Nginx代理请求。
解决方法:根据后端服务器实际处理情况,调正后端请求超时时间。
8、网站页面缓存过大。
解决方法:配置nginx.conf相关设置:fastcgi_buffers 8 128k;send_timeout 60。
高并发nginx,需要注意哪些配置
参考下面的《nginx配置高并发》
一、一般来说nginx配置文件中对优化比较有作用的为以下几项:
1.worker_processes8;
nginx进程数,建议按照cpu数目来指定,一般为它的倍数(如,2个四核的cpu计为8)。
2.worker_cpu_affinity0000000100000010000001000000100000010000001000000100000010000000;
为每个进程分配cpu,上例中将8个进程分配到8个cpu,当然可以写多个,或者将一
个进程分配到多个cpu。
3.worker_rlimit_nofile65535;
这个指令是指当一个nginx进程打开的最多文件描述符数目,理论值应该是最多打开文
件数(ulimit-n)与nginx进程数相除,但是nginx分配请求并不是那么均匀,所以最好与ulimit-n的值保持一致。
现在在linux2.6内核下开启文件打开数为65535,worker_rlimit_nofile就相应应该填写65535。
这是因为nginx调度时分配请求到进程并不是那么的均衡,所以假如填写10240,总并发量达到3-4万时就有进程可能超过10240了,这时会返回502错误。
查看linux系统文件描述符的方法:
[root@web001~]#sysctl-a|grepfs.file
fs.file-max=789972
fs.file-nr=5100789972
4.useepoll;
使用epoll的I/O模型
(
补充说明:
与apache相类,nginx针对不同的操作系统,有不同的事件模型
A)标准事件模型
Select、poll属于标准事件模型,如果当前系统不存在更有效的方法,nginx会选择select或poll
B)高效事件模型
Kqueue:使用于FreeBSD4.1+,OpenBSD2.9+,NetBSD2.0和MacOSX.使用双处理器的MacOSX系统使用kqueue可能会造成内核崩溃。
Epoll:使用于Linux内核2.6版本及以后的系统。
/dev/poll:使用于Solaris711/99+,HP/UX11.22+(eventport),IRIX6.5.15+和Tru64UNIX5.1A+。
Eventport:使用于Solaris10.为了防止出现内核崩溃的问题,有必要安装安全补丁。
)
5.worker_connections65535;
每个进程允许的最多连接数,理论上每台nginx服务器的最大连接数为worker_processes*worker_connections。
6.keepalive_timeout60;
keepalive超时时间。
7.client_header_buffer_size4k;
客户端请求头部的缓冲区大小,这个可以根据系统分页大小来设置,一般一个请求头的大小不会超过1k,不过由于一般系统分页都要大于1k,所以这里设置为分页大小。
分页大小可以用命令getconfPAGESIZE取得。
[root@web001~]#getconfPAGESIZE
4096
但也有client_header_buffer_size超过4k的情况,但是client_header_buffer_size该值必须设置为“系统分页大小”的整倍数。
8.open_file_cachemax=65535inactive=60s;
这个将为打开文件指定缓存,默认是没有启用的,max指定缓存数量,建议和打开文件数一致,inactive是指经过多长时间文件没被请求后删除缓存。
9.open_file_cache_valid80s;
这个是指多长时间检查一次缓存的有效信息。
10.open_file_cache_min_uses1;
open_file_cache指令中的inactive参数时间内文件的最少使用次数,如果超过这个数字,文件描述符一直是在缓存中打开的,如上例,如果有一个文件在inactive时间内一次没被使用,它将被移除。
二、关于内核参数的优化:
net.ipv4.tcp_max_tw_buckets=6000
timewait的数量,默认是180000。
net.ipv4.ip_local_port_range=102465000
允许系统打开的端口范围。
net.ipv4.tcp_tw_recycle=1
启用timewait快速回收。
net.ipv4.tcp_tw_reuse=1
开启重用。允许将TIME-WAITsockets重新用于新的TCP连接。
net.ipv4.tcp_syncookies=1
开启SYNCookies,当出现SYN等待队列溢出时,启用cookies来处理。
net.core.somaxconn=262144
web应用中listen函数的backlog默认会给内核参数的net.core.somaxconn限制到128,而nginx定义的NGX_LISTEN_BACKLOG默认为511,所以有必要调整这个值。
net.core.netdev_max_backlog=262144
每个网络接口接收数据包的速率比内核处理这些包的速率快时,允许送到队列的数据包的最大数目。
net.ipv4.tcp_max_orphans=262144
系统中最多有多少个TCP套接字不被关联到任何一个用户文件句柄上。如果超过这个数字,孤儿连接将即刻被复位并打印出警告信息。这个限制仅仅是为了防止简单的DoS攻击,不能过分依靠它或者人为地减小这个值,更应该增加这个值(如果增加了内存之后)。
net.ipv4.tcp_max_syn_backlog=262144
记录的那些尚未收到客户端确认信息的连接请求的最大值。对于有128M内存的系统而言,缺省值是1024,小内存的系统则是128。
net.ipv4.tcp_timestamps=0
时间戳可以避免序列号的卷绕。一个1Gbps的链路肯定会遇到以前用过的序列号。时间戳能够让内核接受这种“异常”的数据包。这里需要将其关掉。
net.ipv4.tcp_synack_retries=1
为了打开对端的连接,内核需要发送一个SYN并附带一个回应前面一个SYN的ACK。也就是所谓三次握手中的第二次握手。这个设置决定了内核放弃连接之前发送SYN+ACK包的数量。
net.ipv4.tcp_syn_retries=1
在内核放弃建立连接之前发送SYN包的数量。
net.ipv4.tcp_fin_timeout=1
如果套接字由本端要求关闭,这个参数决定了它保持在FIN-WAIT-2状态的时间。对端可以出错并永远不关闭连接,甚至意外当机。缺省值是60秒。2.2内核的通常值是180秒,3.可以按这个设置,但要记住的是,即使机器是一个轻载的WEB服务器,也有因为大量的死套接字而内存溢出的风险,FIN-WAIT-2的危险性比FIN-WAIT-1要小,因为它最多只能吃掉1.5K内存,但是它们的生存期长些。
net.ipv4.tcp_keepalive_time=30
当keepalive起用的时候,TCP发送keepalive消息的频度。缺省是2小时。
三、下面贴一个完整的内核优化设置:
vi/etc/sysctl.confCentOS5.5中可以将所有内容清空直接替换为如下内容:
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=4096873804194304
net.ipv4.tcp_wmem=4096163844194304
net.core.wmem_default=8388608
net.core.rmem_default=8388608
net.core.rmem_max=16777216
net.core.wmem_max=16777216
net.core.netdev_max_backlog=262144
net.core.somaxconn=262144
net.ipv4.tcp_max_orphans=3276800
net.ipv4.tcp_max_syn_backlog=262144
net.ipv4.tcp_timestamps=0
net.ipv4.tcp_synack_retries=1
net.ipv4.tcp_syn_retries=1
net.ipv4.tcp_tw_recycle=1
net.ipv4.tcp_tw_reuse=1
net.ipv4.tcp_mem=94500000915000000927000000
net.ipv4.tcp_fin_timeout=1
net.ipv4.tcp_keepalive_time=30
net.ipv4.ip_local_port_range=102465000
使配置立即生效可使用如下命令:
/sbin/sysctl-p
四、下面是关于系统连接数的优化
linux默认值openfiles和maxuserprocesses为1024
#ulimit-n
1024
#ulimit–u
1024
问题描述:说明server只允许同时打开1024个文件,处理1024个用户进程
使用ulimit-a可以查看当前系统的所有限制值,使用ulimit-n可以查看当前的最大打开文件数。
新装的linux默认只有1024,当作负载较大的服务器时,很容易遇到error:toomanyopenfiles。因此,需要将其改大。
解决方法:
使用ulimit–n65535可即时修改,但重启后就无效了。(注ulimit-SHn65535等效ulimit-n65535,-S指soft,-H指hard)
有如下三种修改方式:
1.在/etc/rc.local中增加一行ulimit-SHn65535
2.在/etc/profile中增加一行ulimit-SHn65535
3.在/etc/security/limits.conf最后增加:
*softnofile65535
*hardnofile65535
*softnproc65535
*hardnproc65535
具体使用哪种,在CentOS中使用第1种方式无效果,使用第3种方式有效果,而在Debian中使用第2种有效果
#ulimit-n
65535
#ulimit-u
65535
备注:ulimit命令本身就有分软硬设置,加-H就是硬,加-S就是软默认显示的是软限制
soft限制指的是当前系统生效的设置值。hard限制值可以被普通用户降低。但是不能增加。soft限制不能设置的比hard限制更高。只有root用户才能够增加hard限制值。
五、下面是一个简单的nginx配置文件:
userwwwwww;
worker_processes8;
worker_cpu_affinity000000010000001000000100000010000001000000100000
01000000;
error_log/www/log/nginx_error.logcrit;
pid/usr/local/nginx/nginx.pid;
worker_rlimit_nofile204800;
events
{
useepoll;
worker_connections204800;
}
http
{
includemime.types;
default_typeapplication/octet-stream;
charsetutf-8;
server_names_hash_bucket_size128;
client_header_buffer_size2k;
large_client_header_buffers44k;
client_max_body_size8m;
sendfileon;
tcp_nopushon;
keepalive_timeout60;
fastcgi_cache_path/usr/local/nginx/fastcgi_cachelevels=1:2
keys_zone=TEST:10m
inactive=5m;
fastcgi_connect_timeout300;
fastcgi_send_timeout300;
fastcgi_read_timeout300;
fastcgi_buffer_size4k;
fastcgi_buffers84k;
fastcgi_busy_buffers_size8k;
fastcgi_temp_file_write_size8k;
fastcgi_cacheTEST;
fastcgi_cache_valid2003021h;
fastcgi_cache_valid3011d;
fastcgi_cache_validany1m;
fastcgi_cache_min_uses1;
fastcgi_cache_use_staleerrortimeoutinvalid_headerhttp_500;
open_file_cachemax=204800inactive=20s;
open_file_cache_min_uses1;
open_file_cache_valid30s;
tcp_nodelayon;
gzipon;
gzip_min_length1k;
gzip_buffers416k;
gzip_http_version1.0;
gzip_comp_level2;
gzip_typestext/plainapplication/x-javascripttext/cssapplication/xml;
gzip_varyon;
server
{
listen8080;
server_namebackup.aiju.com;
indexindex.phpindex.htm;
root/www/html/;
location/status
{
stub_statuson;
}
location~.*\.(php|php5)?$
{
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
includefcgi.conf;
}
location~.*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$
{
expires30d;
}
log_formataccess'$remote_addr--$remote_user[$time_local]"$request"'
'$status$body_bytes_sent"$http_referer"'
'"$http_user_agent"$http_x_forwarded_for';
access_log/www/log/access.logaccess;
}
}
阿里云上的centos 7.2怎么yum安装php 5.6
因之前通过网易的 centos镜像,将阿里云的 centos升级到最新版了,乘自己的项目尚未开始正式开发,遂将所有的相应环境都升级到最高。
查看 centos版本:
[root@iZ23d~]# cat/etc/centos-release
CentOS Linux release 7.2.1511(Core)
1、删除之前的 php版本:
[root@iZ23d~]# yum remove php* php-common
Loaded plugins: langpacks
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
No Match for argument: php-5.4.16
No Match for argument: php-5.4.16.tar.gz
No Match for argument: php-7.0.1RC1
No Match for argument: php-7.0.1RC1.tar.gz
No Match for argument: phpMyAdmin-4.4.0.tar.gz
No Match for argument: php-common
No Packages marked for removal
2、rpm安装 Php7相应的 yum源:
[root@iZ23d~]# rpm-Uvh
Retrieving
warning:/var/tmp/rpm-tmp.LhJKKR: Header V4 RSA/SHA1 Signature, key ID 62e74ca5: NOKEY
Preparing...################################# [100%]
package webtatic-release-7-3.noarch is already installed
3、直接yum安装php7:
[root@iZ23d~]# yum install php70w
Loaded plugins: langpacks
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Resolving Dependencies
--> Running transaction check
。。。【省略】
Warning: RPMDB altered outside of yum.
Installing: php70w-common-7.0.0-1.w7.x86_64 1/3
Installing: php70w-cli-7.0.0-1.w7.x86_64 2/3
Installing: php70w-7.0.0-1.w7.x86_64 3/3
Verifying: php70w-7.0.0-1.w7.x86_64 1/3
Verifying: php70w-common-7.0.0-1.w7.x86_64 2/3
Verifying: php70w-cli-7.0.0-1.w7.x86_64 3/3
Installed:
php70w.x86_64 0:7.0.0-1.w7
Dependency Installed:
php70w-cli.x86_64 0:7.0.0-1.w7 php70w-common.x86_64 0:7.0.0-1.w7
Complete!
4、检查 php版本:
[root@iZ23d~]# php-v
PHP 7.0.0(cli)(built: Dec 2 2015 20:42:32)( NTS)
Copyright(c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright(c) 1998-2015 Zend Technologies
[root@iZ23d2e6hoqZ~]#
以上显示安装成功!
5、重启 Apache,查看 phpinfo:
[root@iZ23d~]# systemctl restart httpd.service
检查phpinfo:
PHP Version 7.0.0
SystemLinux iZ23d 3.10.0-229.11.1.el7.x86_64#1 SMP Thu Aug 6 01:06:18 UTC 2015 x86_64
Build DateDec 2 2015 20:43:38
Server APIApache 2.0 Handler
Virtual Directory Supportdisabled
Configuration File(php.ini) Path/etc
Loaded Configuration File/etc/php.ini
Scan this dir for additional.ini files/etc/php.d
Additional.ini files parsed/etc/php.d/bz2.ini,/etc/php.d/calendar.ini,/etc/php.d/ctype.ini,/etc/php.d/curl.ini,/etc/php.d/exif.ini,/etc/php.d/fileinfo.ini,/etc/php.d/ftp.ini,/etc/php.d/gettext.ini,/etc/php.d/gmp.ini,/etc/php.d/iconv.ini,/etc/php.d/json.ini,/etc/php.d/phar.ini,/etc/php.d/shmop.ini,/etc/php.d/simplexml.ini,/etc/php.d/sockets.ini,/etc/php.d/tokenizer.ini,/etc/php.d/xml.ini,/etc/php.d/zip.ini
PHP API20151012
PHP Extension20151012
Zend Extension320151012
Zend Extension BuildAPI320151012,NTS
PHP Extension BuildAPI20151012,NTS
Debug Buildno
Thread Safetydisabled
Zend Signal Handlingdisabled
Zend Memory Managerenabled
Zend Multibyte Supportdisabled
IPv6 Supportenabled
DTrace Supportenabled
Registered PHP Streamshttps, ftps, compress.zlib, php, file, glob, data, http, ftp, compress.bzip2, phar, zip
Registered Stream Socket Transportstcp, udp, unix, udg, ssl, sslv3, sslv2, tls, tlsv1.0, tlsv1.1, tlsv1.2
Registered Stream Filterszlib.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk, bzip2.*, convert.iconv.*
This program makes use of the Zend Scripting Language Engine:
Zend Engine v3.0.0, Copyright(c) 1998-2015 Zend Technologies
Configuration
apache2handler
Apache VersionApache/2.4.6(CentOS)
Apache API Version20120211
Server Administratorxxxxxx@xxxxxx.com
Hostname:Portxxxx.xxxxx.xxx:0
User/Groupapache(48)/48
Max RequestsPer Child: 0- Keep Alive: on- Max Per Connection: 100
TimeoutsConnection: 60- Keep-Alive: 15
Virtual ServerYes
Server Root/etc/httpd
Loaded Modulescore mod_so http_core mod_access_compat mod_actions mod_alias mod_allowmethods mod_auth_basic mod_auth_digest mod_authn_anon mod_authn_core mod_authn_dbd mod_authn_dbm mod_authn_file mod_authn_socache mod_authz_core mod_authz_dbd mod_authz_dbm mod_authz_groupfile mod_authz_host mod_authz_owner mod_authz_user mod_autoindex mod_cache mod_cache_disk mod_data mod_dbd mod_deflate mod_dir mod_dumpio mod_echo mod_env mod_expires mod_ext_filter mod_filter mod_headers mod_include mod_info mod_log_config mod_logio mod_mime_magic mod_mime mod_negotiation mod_remoteip mod_reqtimeout mod_rewrite mod_setenvif mod_slotmem_plain mod_slotmem_shm mod_socache_dbm mod_socache_memcache mod_socache_shmcb mod_status mod_substitute mod_suexec mod_unique_id mod_unixd mod_userdir mod_version mod_vhost_alias mod_dav mod_dav_fs mod_dav_lock mod_lua prefork mod_proxy mod_lbmethod_bybusyness mod_lbmethod_byrequests mod_lbmethod_bytraffic mod_lbmethod_heartbeat mod_proxy_ajp mod_proxy_balancer mod_proxy_connect mod_proxy_express mod_proxy_fcgi mod_proxy_fdpass mod_proxy_ftp mod_proxy_http mod_proxy_scgi mod_proxy_wstunnel mod_ssl mod_systemd mod_cgi mod_perl mod_php7
以上显示 php7安装成功!