|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
小知识:Linux是一个基于POSIX和UNIX的多用户、多任务、支持多线程和多CPU的操作系统。
媒介:
因为办事器apache抗不住今朝的并发.加上前端squid设置装备摆设后,成绩仍然没法处理.而页面法式年夜部门是静态.没法应用fastcgi来处置.是以想应用nginx做为反向署理apache.全部设置装备摆设装置进程很简略.在斟酌高并发的情形下,在装置前就做了些优化.今朝设置装备摆设能抗住3000以上并发.似乎不是特殊年夜哦?呵~~但足以~~只是还有大批499成绩..等待有人跟我评论辩论处理
第1部门:装置
1树立用户及组
/usr/sbin/groupaddwww
/usr/sbin/useradd-gwwwwww
2装置pcre让nginx支撑rewrite便利今后所需
wgetftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.8.tar.gz
tarzxvfpcre-7.8.tar.gz
cdpcre-7.8/
./configure
make&&makeinstall
3装置nginx
wgethttp://sysoev.ru/nginx/nginx-0.7.58.tar.gz
tarzxvfnginx-0.7.58.tar.gz
cdnginx-0.7.58/
./configure--user=www--group=www--prefix=/usr/local/webserver/nginx--with-http_stub_status_module--with-http_ssl_module--with-cc-opt=-O2--with-cpu-opt=opteron
make&&makeinstall
#留意上文中的--with-cc-opt=-O2--with-cpu-opt=opteron这是编译器优化,今朝最经常使用的是-02而不是3.前面对应CPU的型号,可参照:http://wiki.gentoo.tw/index.php/HOWTO_CFLAG
第2部门:设置装备摆设及优化设置装备摆设文件
1nginx.conf设置装备摆设文件:
userwwwwww;
worker_processes4;
#[debug|info|notice|warn|error|crit]
error_log/usr/local/webserver/nginx/logs/nginx_error.logcrit;
pid/usr/local/webserver/nginx/nginx.pid;
#Specifiesthevalueformaximumfiledescriptorsthatcanbeopenedbythisprocess.
worker_rlimit_nofile51200;
events
{
useepoll;
worker_connections51200;
}
http
{
includemime.types;
default_typeapplication/octet-stream;
source_charsetGB2312;
server_names_hash_bucket_size256;
client_header_buffer_size256k;
large_client_header_buffers4256k;
#sizelimits
client_max_body_size50m;
client_body_buffer_size256k;
client_header_timeout3m;
client_body_timeout3m;
send_timeout3m;
#参数都有所调剂.目标是处理署理过程当中涌现的一些502499毛病
sendfileon;
tcp_nopushon;
keepalive_timeout120;#参数加年夜,以处理做署理时502毛病
tcp_nodelayon;
includevhosts/upstream.conf;
includevhosts/bbs.linuxtone.conf;
}
2upstream.conf设置装备摆设文件(这也是做负载的设置装备摆设办法)
upstream.conf
upstreambbs.linuxtone.com{
server192.168.1.4:8099;
}
3站点设置装备摆设文件
bbs.linuxtone.conf
server
{
listen80;
server_namebbs.linuxtone.conf;
charsetGB2312;
indexindex.htmlindex.htm;
root/date/wwwroot/linuxtone/;
location~^/NginxStatus/{
stub_statuson;
access_logoff;
}
location/{
root/date/wwwroot/linuxtone/;
proxy_redirectoff;
proxy_set_headerHost$host;
proxy_set_headerX-Real-IP$remote_addr;
proxy_set_headerREMOTE-HOST$remote_addr;
proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;
client_max_body_size50m;
client_body_buffer_size256k;
proxy_connect_timeout30;
proxy_send_timeout30;
proxy_read_timeout60;
proxy_buffer_size256k;
proxy_buffers4256k;
proxy_busy_buffers_size256k;
proxy_temp_file_write_size256k;
proxy_next_upstreamerrortimeoutinvalid_headerhttp_500http_503http_404;
proxy_max_temp_file_size128m;
proxy_passhttp://bbs.linuxtone.com;
}
#参数都有所调剂.目标是处理署理过程当中涌现的一些502499毛病
#Addexpiresheaderforstaticcontent
location~*.(jpg|jpeg|gif|png|swf)${
if(-f$request_filename){
root/date/wwwroot/linuxtone/;
expires1d;
break;
}
}
log_formataccess$remote_addr-$remote_user[$time_local]"$request"
$status$body_bytes_sent"$http_referer"
"$http_user_agent"$http_x_forwarded_for;
access_log/exp/nginxlogs/bbs.linuxtone_access.logaccess;
}
注:第二种署理方法
nginx处置下图片,html等静态的器械.其它静态由apache处置.是以apache也须要做一些参数调剂.
设置图片等过时时光.减缓要求.
假如源与nginx在统一台机械建议应用以下办法:
location/{
proxy_passhttp://192.168.1.4:8099/;
proxy_redirectdefault;
}
针对分歧的目次停止署理把上面的设置装备摆设放到根目次署理的下面
location/linuxtone/{
proxy_passhttp://192.168.1.4:8099/linuxtone/;
proxy_redirectdefault;
}
4源设置装备摆设
<VirtualHost192.168.1.4:8099>
ServerAdminliuyu105#gmail.com
DocumentRoot/date/wwwroot/linuxtone
ServerNamebbs.linuxtone.com
ErrorLoglogs/linuxtone_error_log
CustomLog"|/usr/local/sbin/cronologlogs/linuxtone_access_log.%Y%m%d"combined
</VirtualHost>
第3部门:源的优化
1apache-mpm.conf
<IfModulempm_prefork_module>
StartServers15
MinSpareServers15
MaxSpareServers30
ServerLimit2536
MaxClients2048
MaxRequestsPerChild1500
</IfModule>
2apache-keepalive
Timeout120#与nginx的坚持一至
KeepAliveOn
MaxKeepAliveRequests400
KeepAliveTimeout7
第4部门:PHP的优化
优化一:将PHP由之前的xcache换成eaccelerator
1装置
wgethttp://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.tar.bz2
tarjxvfeaccelerator-0.9.5.3.tar.bz2
cdeaccelerator-0.9.5.3/
/usr/local/webserver/php/bin/phpize
./configure--enable-eaccelerator=shared--with-php-config=/usr/local/php5/bin/php-config
make
makeinstall
注:PHP路径以装置为准!
2设置装备摆设
sed-is#extension_dir="./"#extension_dir="/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/"
extension="memcache.so"
#/etc/php.ini
sed-is#output_buffering=Off#output_buffering=On#/etc/php.ini
sed-i"s#;always_populate_raw_post_data=On#always_populate_raw_post_data=On#g"/etc/php.ini
设置装备摆设eAccelerator加快PHP:
mkdir-p/usr/local/webserver/eaccelerator_cache
vi/etc/php.ini
按shift+g键跳到设置装备摆设文件的最末尾,加上以下设置装备摆设信息:
[eaccelerator]
zend_extension="/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="128"
eaccelerator.cache_dir="/usr/local/webserver/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="300"
eaccelerator.shm_prune_period="120"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
优化二:接洽开辟从新编译php削减php的模块.以削减php过程所占用内存数.这块虽然影响不年夜,但也有必定的感化.编译前也能够参照nginx的编译器优化方法装置.
第5部门:测试并启动nginx
ulimit-SHn51200
/usr/local/webserver/nginx/sbin/nginx-t
/usr/local/webserver/nginx/sbin/nginx
第6部门:nginx日记切割剧本
#!/bin/bash
#Thisscriptrunat00:00
#TheNginxlogspath
logs_path="/exp/nginxlogs/"
mkdir-p${logs_path}$(date-d"yesterday"+"%Y")/$(date-d"yesterday"+"%m")/
mv${logs_path}bbs.linuxtone_access.log${logs_path}$(date-d"yesterday"+"%Y")/$(date-d"yesterday"+"%m")/bbs.linuxtone_access_$(date-d"yesterday"+"%Y%m%d").log
kill-USR1`cat/usr/local/webserver/nginx/nginx.pid`
crontab-e
0000***/bin/bash/usr/local/webserver/nginx/sbin/cut_nginx_log.sh
小知识:Linux同时具有字符界面和图形界面。在字符界面用户可以通过键盘输入相应的指令来进行操作。 |
|