您的位置:首页 > 运维架构 > Nginx

nginx代理负载均衡简单

2016-04-28 17:04 393 查看
安装nginx
wget http://nginx.org/download/nginx-1.10.0.tar.gz
tar xf nginx-1.10.0.tar.gz
cd nginx-1.10.0
./configure --user=nginx --group=nginx --prefix=/application/nginx.1.10.0 --with-http_stub_status_module --with-http_ssl_module
make
make isntall
ln -s /application/nginx.1.10.0/ /application/nginx
useradd nginx -s /sbin/nologin -M
/application/nginx/sbin/nginx -t
/application/nginx/sbin/nginx
egrep -v "#|^$" nginx.conf.default > nginx.conf
vim nginx.conf
http{
upstream backend {
ip_hash; 登陆后,始终在一台服务器
server 192.168.10.11:80 max_fails=3 fail_timeout=30s;
server 192.168.10.16:80 max_fails=3 fail_timeout=30s;
}
server {
listen 80;
server_name www.hequan.com;
index index.html index.htm;
location / {
proxy_pass http://backend; }
}
这个时候打开192.168.10.10,就是轮询rr的方式,访问11和16了。
测试
for n in `seq 100` ; do curl 192.168.10.10; sleep 2 ;done
lnmp-----------www.hequan.com
lamp-www.hequan.com
lnmp-----------www.hequan.com
lamp-www.hequan.com
关掉一个服务器后,访问正常,不影响。这个服务器正常后,会自动加入到里面。提供访问。
每个服务器都把登陆信息写到本地,会影响到用户登陆,来回登陆的情况。
lb层可以做会话保持(小流量可以) 为了防止,可以 加入ip_hash;登陆后,始终在一台服务器
软件层sesson复制
共享例如memcache
cookies配合session 把用户级会话信息缓存在用户本地



本文出自 “何全” 博客,请务必保留此出处http://hequan.blog.51cto.com/5701886/1768714
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: