cd /usr/local/tomcat1/webapps/ROOT/

tar -zxvf nginx-1.14.2.tar.gz -C /usr/local

一、Linux配置Nginx

一、下载Nginx

  方式1:从http://nginx.org/en/download.html上下载稳定版,解压安装

  方式2:直接在Linux上用命令下载: wget http://nginx.org/download/nginx-1.10.2.tar.gz
  -bash: wget: command not found

  安装wget:
  yum -y install wget

  再执行下载nginx

二、解压安装包&重命名   

  tar -zxvf nginx-1.14.2.tar.gz -C /usr/local

  mv nginx-1.14.2 nginx

三、编译

  1、cd 到nginx目录下

  2、安装相关组件

  • yum install -y pcre pcre-devel
  • yum install -y zlib zlib-devel
  • yum install -y openssl openssl-devel

  这是提示缺少c++环境 ,用 yum install gcc-c++ 安装一下,再执行 ./configure,然后又报错了:

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using –without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using –with-pcre= option.

没装伪静态模块需要pcre库
解决方法:
yum install -y pcre pcre-devel

还有可能出现:
错误提示:./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library. You can either disable the module by using
–without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
–with-http_ssl_module –with-openssl= options.

解决办法:
yum -y install openssl openssl-devel

最后 ./configure

执行make 编译:

然后:make install  报错:

问题原因: 直接把安装包重命名成nginx了,安装文件没有路径了。

解决办法如下:

删除nginx 文件夹
rm -rf nginx

重新解决源码
tar -zxvf nginx-1.10.2.tar.gz

cd /usr/local/nginx-1.10.2

生成Makefile文件

  ./configure --prefix=/usr/local/nginx

编译源码
make

安装
make install

这里不必要太纠结,只要 /usr/local/ 下出现了 /nagix文件就ok,进入 cd /usr/local/nginx/sbin 下,启动 ./nginx

问题1:出现端口占用,nginx一般是80端口,要么把其他的kill掉,要么更改nginx的端口

1、kill掉其他的之前,要知道哪个占用了:用 lsof -i:80可以查看,这里是之前的lamp占用了

2、我们可以修改nginx自身的监听端口,vi /usr/local/nginx/conf/nginx.conf  ,将listen 80,改为自己要的就行,我们这里改81

  

server {
listen ;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
}

之后进入我们的ip:81就可以访问:

二、Linux配置Tomcat

  1、下载

  下载地址:https://tomcat.apache.org/download-90.cgi

  这里我们用tomcat 9 吧,下载后,一样放到 /usr/local 下,解压两份,一份作为 tomcat1 , 一份为 tomcat 2 这两份,用来做负载均衡

  解压: tar -zxvf apache-tomcat-9.0.13.tar.gz -C /usr/local

  重命名: mv apache-tomcat-9.0.13 tomcat1

  

  2、配置:

  修改其中一个tomcat2 的端口信息,tomcat1则不需要修改

  cd /usr/local/tomcat2/conf

  vi server.xml

  改以下三个端口为:8006,8081,8099

<Server port="" shutdown="SHUTDOWN">
<Connector port="" protocol="HTTP/1.1"
<Connector port="" protocol="AJP/1.3" redirectPort="" />

  3、分别更改两个 tomcat下默认的jsp页面
  cd /usr/local/tomcat1/webapps/ROOT/

  vi index.jsp
  

  在body中添加一行html 代码,用于区分是哪个tomcat下的页面。

  4、启动两个tomcat

  

  cd /usr/local/tomcat1/bin

  ./startup.sh

  打开本地的ip:8080和ip:8081可以看到,两个页面都有提示信息:

但是8080 被占用,我们用8081和8082:8081

8082

这样,就是安装成功啦!

三、Nginx配置Tomcat负载均衡

  1、安装好nginx的情况下

  2、修改配置文件
  cd /usr/local/nginx/conf
  vi nginx.conf
  添加ngnix分配策略(权重策略)

  

upstream   dangdang.com {
server 192.168.66.129: weight=; //tomcat1 的ip和端口
server 192.168.66.129: weight=; //tomcat2 的ip和端口
}

整个文件的信息如下:

#user  nobody;
worker_processes ; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections ;
} http {
include 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 logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout ;
keepalive_timeout ; #gzip on;
  upstream dangdang.com {
    server 192.168.66.129:8081 weight=1; //tomcat1 的ip和端口
    server 192.168.66.129:8082 weight=1; //tomcat2 的ip和端口
  }
server {
listen ;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
       proxy_pass   http://dangdang.com;
} #error_page /.html; # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen ;
# listen somename:;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#} }

结果:一直刷新

结果1:

结果2:

Linux配置Nginx+Tomcat负载均衡的更多相关文章

  1. Linux下Nginx+Tomcat负载均衡和动静分离配置要点

    本文使用的Linux发行版:CentOS6.7 下载地址:https://wiki.centos.org/Download 一.安装Nginx 下载源:wget http://nginx.org/pa ...

  2. Linux记录-Nginx+Tomcat负载均衡配置

    Nginx负载均衡配置及策略: 轮询(默认) 优点:实现简单缺点:不考虑每台服务器的处理能力配置示例如下:upstream www.xxx.com {# 需要负载的server列表server www ...

  3. linux+nginx+tomcat负载均衡,实现session同步

    linux+nginx+tomcat负载均衡,实现session同步 花了一个上午的时间研究nginx+tomcat的负载均衡测试,集群环境搭建比较顺利,但是session同步的问题折腾了几个小时才搞 ...

  4. Nginx + Tomcat 负载均衡配置详解

    Nginx常用操作指南一.Nginx 与 Tomcat 安装.配置及优化1. 检查和安装依赖项 yum -y install gcc pcre pcre-devel zlib zlib-devel o ...

  5. nginx+tomcat负载均衡

    最近练习nginx+tomcat负载均衡.根据一些资料整理了大体思路,最终实现了1个nginx+2个tomcat负载均衡. 安装JDK 1>进入安装目录,给所有用户添加可执行的权限 #chmod ...

  6. windows配置nginx实现负载均衡集群

    windows配置nginx实现负载均衡集群2014-08-20 09:44:40   来源:www.abcde.cn   评论:0 点击:617 网上大部分关于nginx负载均衡集群的教程都是lin ...

  7. 配置nginx的负载均衡

    1.1   什么是负载均衡 负载均衡 建立在现有网络结构之上,它提供了一种廉价有效透明的方法扩展网络设备和服务器的带宽.增加吞吐量.加强网络数据处理能力.提高网络的灵活性和可用性. 负载均衡,英文名称 ...

  8. 【nginx】配置Nginx实现负载均衡

    一文中已经提到,企业在解决高并发问题时,一般有两个方向的处理策略,软件.硬件,硬件上添加负载均衡器分发大量请求,软件上可在高并发瓶颈处:数据库+web服务器两处添加解决方案,其中web服务器前面一层最 ...

  9. 【高可用HA】Nginx (1) —— Mac下配置Nginx Http负载均衡(Load Balancer)之101实例

    [高可用HA]Nginx (1) -- Mac下配置Nginx Http负载均衡(Load Balancer)之101实例 nginx版本: nginx-1.9.8 参考来源: nginx.org [ ...

  10. 配置Nginx实现负载均衡

    在关于高并发负载均衡一文中已经提到,企业在解决高并发问题时,一般有两个方向的处理策略,软件.硬件,硬件上添加负载均衡器分发大量请求,软件上可在高并发瓶颈处:数据库+web服务器两处添加解决方案,其中w ...

随机推荐

  1. UVA11090 Going in Cycle!!(二分判负环)

    UVA11090 Going in Cycle!! 二分答案,用spfa判负环. 注意格式:图不一定连通. 复杂度$O(nmlog(maxw-minw))$ #include<iostream& ...

  2. QT+qtablewidget自定义表头【合并单元格】

    1.把下列文件放在工程中[已上传到我的文件中] 2.代码 auto *headview = new HHeadViewClass(Qt::Horizontal, ui.tableWidget); he ...

  3. CodeForces - 55D Beautiful numbers(数位DP+Hash)题解

    题意:美丽数定义:一个正数能被所有位数整除.求给出一个范围,回答这个范围内的美丽数. 思路:一个数能被所有位数整除,换句话说就是一个数能整除所有位数的LCM,所以问题就转化为一个数能否被所有位数的LC ...

  4. 解决QML Window 增加radius效果

    做开发时,突然遇到 一个需要模态展示的对话框,做出来后,发现还要radius属性,增加时发现,Window控件不支持这个属性.如果是以前,原本就打算放弃了,但想一下,这种应该是支持的,既然接口上没有, ...

  5. redis的过期策略以及内存淘汰机制

    redis采用的是定期删除+惰性删除策略. 为什么不用定时删除策略? 定时删除,用一个定时器来负责监视key,过期则自动删除.虽然内存及时释放,但是十分消耗CPU资源.在大并发请求下,CPU要将时间应 ...

  6. Filter实现session超时自动跳转到login页,超过试用期不许登录

    新建一个过滤器 package com.autumn.filter; import com.autumn.pojo.Users; import javax.servlet.*; import java ...

  7. python批量给云主机配置安全组

    python批量给云主机配置安全组 用公有云的思路去思考去实现一个安全稳定.可伸缩和经济的业务构架,云运维是有别与传统运维的,比如说了解公有云的都知道安全组的概念,安全组跟防火墙功能很相似,那我的机器 ...

  8. c primer plus 5 读书笔记1

    C语言是一种融合了控制特性的语言,是一种快速.高效.紧凑.可移植性的语言. 使用C语言的7个步骤:定义程序目标.设计程序.编写代码.编译程序.运行程序.测试和调试程序.维护和修改程序. c程序是由一个 ...

  9. 99%的人都理解错了HTTP中GET与POST的区别(转自知乎)

    作者:Larry链接:https://zhuanlan.zhihu.com/p/22536382来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. GET和POST是HTT ...

  10. 剑指offer+名企面试官精讲典型编程题,28题扩展题

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...