初识nginx负载均衡

环境:

主机三台,系统centos,一个为nginx服务器(1)180.150.184.156,另外两台发布tomcat服务(2)180.150.184.202(3)180.150.184.203。

(1)

nginx安装:

yum -y install nginx


修改nginx配置文件nginx.conf

vim /etc/nginx/nginx.conf


user              nginx;
worker_processes  4;


error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;


pid        /var/run/nginx.pid;




events {
    use epoll;
    worker_connections  1024;
}




http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;


    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';



    access_log  /var/log/nginx/access.log  main;


    sendfile        on;
    #tcp_nopush     on;


    #keepalive_timeout  0;
    keepalive_timeout  65;


    #gzip  on;


    # Load config files from the /etc/nginx/conf.d directory
    # The default server is in conf.d/default.conf
    include /etc/nginx/conf.d/*.conf;


    upstream 180.150.184.156 {
     server 180.150.184.202:8080 weight=1;
     server 180.150.184.203:8080 weight=6;
#     server 180.150.184.204:8080 weight=3;
    }


server {
listen      80;
server_name  180.150.184.156;
location / {
proxy_pass http://180.150.184.156;

}

}

}

(2)(3)分别安装jdk  tomcat。分别发布简单的rest接口作为测试使用,接口地址:

http://180.150.184.202:8080/historylife/rest/index;

http://180.150.184.203:8080/historylife/rest/index

启动tomcat。

启动nginx:  service nginx start.

访问:http://180.150.184.156:80/historylife/rest/index 按照轮询算法,将按照1:6的比例分别转发请求到(2)(3)服务器。






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值