nginx服务器 IP 192.168.5.204
web服务器1 IP 192.168.5.203
web服务器 IP 192.168.5.206
1.在nginx服务器 安装Nginx所需的pcre-devel库
#tar jxvf pcre-4.2.tar.bz2
#cd pcre-4.2
#./configure &&make &&make install
利用TCMalloc优化Nginx的性能
2.安装libunwind库
[root@vmvare01 ~]# tar zxvf libunwind-1.0.1.tar.gz
[root@vmvare01 ~]# cd libunwind-1.0.1
[root@vmvare01 libunwind-1.0.1]# CFLAGS=-fPIC ./configure
[root@vmvare01 libunwind-1.0.1]#make CFLAGS=-fPIC
[root@vmvare01 libunwind-1.0.1]#make CFLAGS=-fPIC install
3.安装goole-perftools
[root@vmvare01 ~]# cd google-perftools-1.9
[root@vmvare01 google-perftools-1.9]# ./configure
[root@vmvare01 google-perftools-1.9]# make && make install
[root@vmvare01~]# echo "/usr/local/lib" >/etc/ld.so.conf.d/usr_local_lib.conf
[root@vmvare01 ~]# ldconfig
4.编译安装Nginx
[root@vmvare01 ~]# cd nginx-1.4.7
[root@vmvare01 nginx-1.4.7] # ./configure --prefix=/opt/nginx\
--with-http_stub_status_module\ #nginx状态监控模块
--with-http_ssl_module\ #https 支持模块
--with-http_flv_module\ #流媒体支持模块
--with-http_gzip_static_module\ #gzip支持模块
--with-google_perftools_module #goole-perftools支持模块
[root@vmvare01 nginx-1.4.7]#Make && make install
5.为google-perftools添加线程目录
[root@vmvare01 ~]# mkdir /tmp/tcmalloc
[root@vmvare01 ~]#chmod 0777 /tmp/tcmalloc
6.修改nginx主配置文件
在pid这行下面加添如下代码
#vim /opt/nginx/conf/nginx.conf
#pid
google_perftools_profiles /tmp/tcmalloc; (分号)
7.启动nginx服务即可加载goole-perftools
#/opt/nginx/sbin/nginx
#echo "/opt/nginx/sbin/nginx >>/etc/rc.local"
6.验证goole-perftools是否已加载
#lsof -n | grep tcmalloc
nginx 18710 nobody 10w REG 8,1 0 1146886 /tmp/tcmalloc.18710
注:nginx.conf中 worker_processes的值为1,因此开启了1个nginx线程。
8.配置反向代理负载均衡
在nginx服务器 (192.168.8.64)
#vim /opt/nginx/conf/nginx.conf
使用upstream自定义负载均衡名字 "myserver",添加虚拟主机
设置server 指定端口和nginx本机IP ,设置location,匹配网页位置和规则
其中nginx服务器的 /opt/nginx/conf/proxy.conf(默认无此文件,创建并填写以下内容)
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
重启nginx服务