Nginx做负载均衡和TOMCAT简单集群
                1.下载安装nginx及其依赖包
                
                
                
                安装nginx准备工作必须先安装依赖包:wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
                
                解压:tar zxvf pcre-8.35.tar.gz
                
                进入目录:cd pcre-8.35
                
                配置: ./configure
                
                编译安装:    make && make install
                
                下载:wget http://nginx.org/download/nginx-1.6.2.tar.gz
                解压:tar zxvf nginx-1.6.2.tar.gz
                
                
                进入目录:cd nginx-1.6.2
                
                配置:/configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/pcre-8.35
                
                编译:make
                
                安装: make install
                
                查看版本:/usr/local/nginx/sbin/nginx -v
                
                创建ngingx运行时使用的用户:  /usr/sbin/groupadd nginx
                                             /usr/sbin/useradd -g nginx nginx
                                            
                配置nginx.conf:
                
                user www www;
                worker_processes 2; #设置值和CPU核心数一致
                error_log /usr/local/webserver/nginx/logs/nginx_error.log crit; #日志位置和日志级别
                pid /usr/local/webserver/nginx/nginx.pid;
                #Specifies the value for maximum file descriptors that can be opened by this process.
                worker_rlimit_nofile 65535;
                events
                {
                use epoll;
                worker_connections 65535;
                }
                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';

#charset gb2312;
                
                server_names_hash_bucket_size 128;
                client_header_buffer_size 32k;
                large_client_header_buffers 4 32k;
                client_max_body_size 8m;
                
                sendfile on;
                tcp_nopush on;
                keepalive_timeout 60;
                tcp_nodelay on;
                fastcgi_connect_timeout 300;
                fastcgi_send_timeout 300;
                fastcgi_read_timeout 300;
                fastcgi_buffer_size 64k;
                fastcgi_buffers 4 64k;
                fastcgi_busy_buffers_size 128k;
                fastcgi_temp_file_write_size 128k;
                gzip on;
                gzip_min_length 1k;
                gzip_buffers 4 16k;
                gzip_http_version 1.0;
                gzip_comp_level 2;
                gzip_types text/plain application/x-javascript text/css application/xml;
                gzip_vary on;

#limit_zone crawler $binary_remote_addr 10m;
                #下面是server虚拟主机的配置
                server
                {
                listen 80;#监听端口
                server_name localhost;#域名
                index index.html index.htm index.php;
                root /usr/local/webserver/nginx/html;#站点目录
                  location ~ .*\.(php|php5)?$
                {
                  #fastcgi_pass unix:/tmp/php-cgi.sock;
                  fastcgi_pass 127.0.0.1:9000;
                  fastcgi_index index.php;
                  include fastcgi.conf;
                }
                location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$
                {
                  expires 30d;
                # access_log off;
                }
                location ~ .*\.(js|css)?$
                {
                  expires 15d;
                # access_log off;
                }
                access_log off;
                }

}
                
                
                检查nginx配置文件nginx.conf正确命令:
                /usr/local/webserver/nginx/sbin/nginx -t
                
                启动nginx:
                /usr/local/webserver/nginx/sbin/nginx
                
                打开浏览器输入ip地址进入到nginx欢迎页说明配置成功,
                启动过程中会报错,解决办法进入/etc/sysconf/iptable配置其他端口或通过lsof -i:80端口看那个在占80端口,然后将其杀死即可解决。
                改配置文件记得重启。
                
                /usr/local/webserver/nginx/sbin/nginx -s reload            # 重新载入配置文件
                /usr/local/webserver/nginx/sbin/nginx -s reopen            # 重启 Nginx
                /usr/local/webserver/nginx/sbin/nginx -s stop              # 停止 Nginx
                
                2.下载安装tomcat
                
                此命令一步安装:wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-7/v7.0.82/bin/apache-tomcat-7.0.82.tar.gz
                (记得配置先要下载好jdk才行)
                //补充说明,为了辨别是否是不同tomcat可以进入tomcat目录下webapps中的ROOT修改index.jsp即可达到目的
                3.修改nginx配置文件
                
                #user  nobody;  
                worker_processes  1;  
                  
                #error_log  logs/error.log;  
                #error_log  logs/error.log  notice;  
                #error_log  logs/error.log  info;  
                  
                #pid        logs/nginx.pid;  
                  
                  
                events {  
                    use epoll;  
                    worker_connections  1024;  
                }  
                  
                  
                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  0;  
                    keepalive_timeout  65;  
                      
                    #说明:端口必须保持一致
                    upstream servers{  
                    server 120.25.56.93:8080;  
                    server 120.25.58.50:8080;    
                    }  
                    #gzip  on;  
                  
                    server {  
                        listen       8084;  
                        server_name  120.76.112.207;  
                  
                        #charset koi8-r;  
                  
                        #access_log  logs/host.access.log  main;  
                  
                        location / {  
                           proxy_pass  http://servers;  
                       proxy_set_header Host $host;  
                       proxy_set_header X-Real-IP $remote_addr;  
                       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
                        }  
                  
                        #error_page  404              /404.html;  
                  
                        # redirect server error pages to the static page /50x.html  
                        #  
                        error_page   500 502 503 504  /50x.html;  
                        location = /50x.html {  
                            root   html;  
                        }  
                  
                        # proxy the PHP scripts to Apache listening on 127.0.0.1:80  
                        #  
                        #location ~ \.php$ {  
                        #    proxy_pass   http://127.0.0.1;  
                        #}  
                  
                        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000  
                        #  
                        #location ~ \.php$ {  
                        #    root           html;  
                        #    fastcgi_pass   127.0.0.1:9000;  
                        #    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       8000;  
                    #    listen       somename:8080;  
                    #    server_name  somename  alias  another.alias;  
                  
                    #    location / {  
                    #        root   html;  
                    #        index  index.html index.htm;  
                    #    }  
                    #}  
                  
                  
                    # HTTPS server  
                    #  
                    #server {  
                    #    listen       443 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;  
                    #    }  
                    #}  
                  
                }

4.重新启动nginx

[root@iZ94phz01rnZ sbin]# ./nginx -s reload  
                    [root@iZ94phz01rnZ sbin]# ./nginx -s reopen

nginx做负载均衡和tomcat简单集群的更多相关文章

  1. 使用nginx做负载均衡的session共享问题

    查了一些资料,看了一些别人写的文档,总结如下,实现nginx session的共享PHP服务器有多台,用nginx做负载均衡,这样同一个IP访问同一个页面会被分配到不同的服务器上,如果session不 ...

  2. nginx做负载均衡配置文件

    nginx做负载均衡是在反向代理的基础上做的,代码如下: ## Basic reverse proxy server ## ## Apache backend for www.baidu.com ## ...

  3. 死磕nginx系列--使用nginx做负载均衡

    使用nginx做负载均衡的两大模块: upstream 定义负载节点池. location 模块 进行URL匹配. proxy模块 发送请求给upstream定义的节点池. upstream模块解读 ...

  4. K2使用Nginx做负载均衡

    K2使用Nginx做负载均衡 K2目前是支持Load Balancing这种方式,来做负载均衡,也可以使用F5来做负载均衡,但这次我使用nginx来实现K2的负载均衡 下载nginx 请下载nginx ...

  5. 解决docker中使用nginx做负载均衡时并发过高时的一些问题

    # 解决docker中使用nginx做负载均衡时并发过高时的一些问题 1.问题产生原因: 由于通过nginx作为负载均衡服务,在访问并发数量达到一定量级时jmeter报错. nginx日志关键信息:a ...

  6. 消费者用nginx做负载均衡,提供者用zookeeper自带功能实现负载均衡

    公司的项目基于阿里的Dubbo微服务框架开发.为了符合相关监管部门的安全要求,公司购买了华东1.华东2两套异地服务器,一套是业务服务器,一套是灾备服务器.准备在这两套服务器上实现Dubbo的分布式服务 ...

  7. Nginx+Keepalived负载均衡+后端LNMP网站集群

    Centos6.4 x86,4台,地址是10.10.10.11-14,vip给的100,目标是在13和14安装nginx+keepalived,11和12安装nginx+mysql+php,做为web ...

  8. nginx做负载均衡 tomcat获得客户端真实ip

    因项目需要做tomcat2台机器的负载均衡,配置好负载环境后,发现tomcat的日志一律是我前置nginx代理服务器的ip 通过百度教材发现需要修改nginx的配置文件,修改代理头信息,传递给后方,后 ...

  9. 生产环境使用nginx做负载均衡配置的五种策略

    nginx的upstream目前支持5种方式的分配1.轮询(默认) 每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除. 2.weight指定轮询几率,weight和访 ...

随机推荐

  1. php下载远程图片到本地

    在使用 PHP 做简单的爬虫的时候,我们经常会遇到需要下载远程图片的需求,所以下面来简单实现这个需求1:使用curl 比如我们有下面这两张图片: $images = [ 'https://img.al ...

  2. (4)Jquery1.8.3快速入门_基本选择器

    一.Jquery选择器: 基本选择器: 1.id                           #id      根据元素的id获取的唯一元素. 2.class                  ...

  3. Java框架之Spring(一)

    在学习Spring之前,需要回忆一下工厂模式.下面会演示一段代码,自己体会.之所以要工厂模式是因为他有一个好处,很像Spring的用法.在实际开发中,new对象对于一个开发人员来说是一件非常需要小心谨 ...

  4. Apollo源码阅读笔记(一)

    Apollo源码阅读笔记(一) 先来一张官方客户端设计图,方便我们了解客户端的整体思路. 我们在使用Apollo的时候,需要标记@EnableApolloConfig来告诉程序开启apollo配置,所 ...

  5. JavaScript--fullPage.js插件

    GitHub:https://github.com/alvarotrigo/fullPage.js FullPage.js是一个基于JQuery的插件,可以很方便的制作出全屏网站; 一 特点: 1.支 ...

  6. js 复制文本到粘贴板

    //html 在iOS Safari中,剪贴板API有一些限制(实际上是安全措施):   于安全原因,iOS Safari只允许容器中的document.execCommand('copy')文本co ...

  7. GIS性能策略

    当一个地理平台上线运行,我们经常会遇到这些问题:1.系统刚上线时速度较快,一段时间后访问较慢?2.在地理平台目前的配置下,发布多少个服务才合理?一个服务配置多少个实例数才合适?这些问题,都涉及整个地理 ...

  8. MVC与单元测试实践之健身网站(五)-系统信息、前台入口

    Fit项目停滞了一段时间,现在继续吧.上一篇完成了动作文本和配图的添加.编辑等内容.接下来要完成的是后台的最后一个模块:系统信息:以及前台的入口:关于注册.登录.修改密码等. 一 系统信息 a) 用户 ...

  9. spring资源访问接口和资源加载接口

    spring 资源访问接口 JDK提供的资源访问类,如java.net.URL.File等,不能很好地满足各种资源的访问需求,比如缺少从类路径或者Web容器的上下文中获取资源的操作类. 鉴于此,spr ...

  10. Expo大作战(三十九)--expo sdk api之 DocumentPicker,Contacts(获取手机联系人信息),Branch

    简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人 ...