码迷,mamicode.com
首页 > 其他好文 > 详细

nginx负载均衡J2EE项目

时间:2019-05-16 10:49:57      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:项目   --help   bz2   RoCE   ref   ps aux   日志   upstream   net   

一、安装nginx-1.10.1.tar.gz

     1、下载:nginx-1.10.1.tar.gz    放到/usr/local目录下;提供官网地址:http://nginx.org/ 
                      a、命令下载:wget http://nginx.org/download/nginx-1.10.1.tar.gz
                      b、自己百度找;
     2、解压:tar -zxvf nginx-1.10.1.tar.gz 
     3、安装:[root@localhost nginx-1.10.1]# ./configure --prefix=/usr/local/nginx
                    安装一般会报错,缺少PCRE库和zlib库
                    a、安装PCRE库和zlib库
                          [root@localhost nginx-1.10.1]#: yum -y install pcre
                          [root@localhost nginx-1.10.1]#: yum -y install pcre-devel
                          [root@localhost nginx-1.10.1]# yum -y  install zlib
                          [root@localhost nginx-1.10.1]# yum -y  install zlib-devel
                    b、如果安装PCRE和zlib库失败,linux自带系统缺少库,自己上网下载
                          pcre-8.41.tar.bz2和zlib-1.2.11.tar.gz;
        4、安装好PCRE和Zlib后,执行
              [root@localhost nginx-1.10.1]# ./configure --prefix=/usr/local/nginx
              [root@localhost nginx-1.10.1]# make
              [root@localhost nginx-1.10.1]# make install
         5、安装完成:nginx目录说明:4个目录
                            -conf 配置文件
                            -html 网页文件
                            -logs 日志文件
                           -sbin 主要二进制文件
 
二、启动nginx,默认启动的是80端口,
            [root@Base nginx]# ./sbin/nginx -c ./conf/nginx.conf        //等同于[root@localhost nginx]# ./sbin/nginx
               如果80被占用、把占用80端口的软件或者服务关闭即可
               1)查看 netstat --help
                      netstat -antp
                 [root@localhost nginx]# netstat -antp
                  Active Internet connections (servers and established)
                   Proto Recv-Q Send-Q Local Address  Foreign Address    State   PID/Program name    
                   tcp      0       0 0.0.0.0:80              0.0.0.0:*  LISTEN      11129/nginx: master 
                 [root@localhost nginx]# kill -9 11129   //杀进程
 
三、关闭nginx 
              [root@localhost nginx]# ps aux|grep nginx    //查看进程
               root     12879  0.0  0.0  20480   612 ?        Ss   21:31   0:00 nginx: master process ./sbin/nginx
               nobody   12881  0.0  0.0  23008  1376 ?        S    21:31   0:00 nginx: worker process
               root     13236  0.0  0.0 112664   972 pts/0    R+   21:47   0:00 grep --color=auto nginx
               [root@localhost nginx]# kill -QUIT 12879
                          
四、反向代理和负载均衡
         1、为了不影响nginx.conf,在/usr/local/nginx/conf文件夹下新建一个配置文件,
             ps:用命令来新建
            [root@Base conf]# touch fzjh.conf
 
          2、在fzjh.conf文件里面写,注意绿色字体是注释,不要写到文件里面;
user nobody;
worker_processes 4;
events{
     worker_connections 1024;
     }
http{
     upstream ems {
         ip_hash;                          #避免系统session导致的问题,同一个客户端只连接一个服务器
         server 10.152.234.72:8080;
         server 10.152.234.73:80;
     }
     server {
         listen 80;
         location / {
             proxy_pass http://ems;           #ems和上面的ems要保持一致
             proxy_set_header Host $host;     #这是解决访问的时候DNS的问题,总是导致ip地址为ems
         }
     }
}
             
         3、启动负载均衡,注意使用的是80端口,把nginx.conf关闭掉,再测试这个
         [root@Base nginx]# ./sbin/nginx -c ./conf/fzjh.conf

 

nginx负载均衡J2EE项目

标签:项目   --help   bz2   RoCE   ref   ps aux   日志   upstream   net   

原文地址:https://www.cnblogs.com/ygkeke/p/10874042.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!