nginx负载均衡J2EE项目

一、安装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

 

转载于:https://www.cnblogs.com/ygkeke/p/10874042.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值