使用nginx实现负载均衡和动静分离php
yum -y install gcc gcc-c++ autoconf automake zib zib-devel openssl openssl-devel pcre pcre-devel
cd /usr/local/src/ wget http://nginx.org/download/nginx-1.8.0.tar.gz tar zxvf nginx-1.8.0.tar.gz cd nginx-1.8.0/ ./configure --prefix=/usr/local/nginx-1.8.0 --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module
make -j 4 && make install useradd -u 8000 -s /sbin/nologin nginx /usr/local/nginx-1.8.0/sbin/nginx echo "/usr/local/nginx-1.8.0/sbin/nginx &" >> /etc/rc.local
nginx的操做html
cd /usr/local/nginx-1.8.0/sbin/ ./nginx -t ./nginx -s reload|stop
cd /usr/local/nginx-1.8.0/conf/ cp nginx.conf nginx.conf.back vim nginx.conf user nginx nginx; // 在 location {...}内添加如下内容 if ($request_uri ~* \.html$){ proxy_pass http://htmlservers; } if ($request_uri ~* \.php$){ proxy_pass http://phpservers; } proxy_pass http://picservers;
upstream htmlservers { server 192.168.221.20:80; server 192.168.221.30:80; } upstream phpservers { server 192.168.221.20:80; server 192.168.221.30:80; } upstream picservers { server 192.168.221.20:80; server 192.168.221.30:80; }
检测语法,从新加载nginx.confnginx
../sbin/nginx -t ../sbin/nginx -s reload
yum install httpd php -y
在网站根目录下建立如下文件
启动 httpdc++
service httpd start
安装httpd php,在网站根目录下建立 index.html,test.php,1.png,启动httpd服务vim
中止 192.168.221.20机器上的httpd服务,再次访问后端
这样就会一直访问到192.168.221.30上的站点服务器
yum install httpd-tools -y //安装ab命令 ab -n 1000 -c 1000 http://192.168.221.10/index.html
ulimit -n //系统默认一个进程最多同时容许打开1024个文件 1024
设置进程最多同时容许打开的默认文件个数为2000负载均衡
ulimit -n 2000
这样就能够解决报错问题ide