linux(ubuntu)下搭建nginx,tomcat负载均衡环境搭建
来源:互联网 发布:淘宝美工在哪里做 编辑:程序博客网 时间:2024/06/07 06:03
随着用户访问量增加以及单台服务器处理能力瓶颈,集群可以很好的解决这个问题,集群也可以保证在单台服务器宕机系统也可以正常运行。负载均衡就是让一个集群(多台机器处理相同的业务)的机器的使用率尽可能平均。比较常用场景:一是web服务器集群,例如用户访问了www.yasin.ac.cn这个网站,通过负载均衡分配的其中一个web容器服务器进行相关的处理。另一个场景就是RPC服务中客户端请求服务也会加入负载均衡功能。
关于nginx的作用的我就不详细介绍,网上资料很多,主要利用它的反向代理以及负载均衡算法实现软件的服务均衡环境。
这里在ubuntu16.04系统下搭建这个环境,由于没有多台机器环境,我这里采用了同一台电脑安装多个tomcat的方法(分配了两个端口)
tomcat下载地址,修改其端口,并修改webapps的ROOT的内容,用于区别两个tomcat
接下来安装nginx,nginx必须需要pcre,gzip模块,可选ssl模块
最后在编译安装nginx
获取pcre编译安装包,在http://www.pcre.org/上可以获取当前最新的版本
解压缩pcre-xx.tar.gz包。
进入解压缩目录,执行./configure。
编译安装命令:
make & make install
获取openssl编译安装包,在http://www.openssl.org/source/上可以获取当前最新的版本。
解压缩openssl-xx.tar.gz包。
进入解压缩目录,执行./config。
make & make install
获取zlib编译安装包,在http://www.zlib.net/上可以获取当前最新的版本。
解压缩openssl-xx.tar.gz包。
进入解压缩目录,执行./configure。
make & make install
获取nginx,在http://nginx.org/en/download.html上可以获取当前最新的版本。
解压缩nginx-xx.tar.gz包。
进入解压缩目录,执行./configure
make & make install
nginx在编译安装后到目录/usr/local/nginx中
配置nginx文件,在安装目录下的conf文件中有nginx.conf配置文件
#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 { 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; gzip on; upstream example.com{ #集群地址 server 127.0.0.1:8080 weight=1;#单个服务地址及其权重,这个权重是默认负载均衡算法的值,越大越容易被访问 server 127.0.0.1:8081 weight=2; } server { listen 80;#nginx端口 server_name localhost;#host name #charset koi8-r; #access_log logs/host.access.log main; location / {# root html;# index index.html index.htm; proxy_pass http://example.com;#代理指向 proxy_redirect default; } #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; # } #}}
启动两个tomcat,可以事先参看其效果,如上两图所示
接下来在/usr/local/nginx/sbin目中运行nginx脚本启动nginx,
这里可以看到通过这个nginx可以访问到两个tomcat
这里只是简单介绍了nginx环境的搭建,关于更多的负载均衡策略会继续深入学习,如有不当之处,需要巨巨们斧正。
- linux(ubuntu)下搭建nginx,tomcat负载均衡环境搭建
- Nginx搭建Tomcat负载均衡环境
- nginx+tomcat负载均衡搭建
- Nginx+Tomcat搭建负载均衡
- Nginx+Tomcat搭建负载均衡
- Nginx+Tomcat搭建负载均衡
- 搭建nginx+tomcat+Java的负载均衡环境
- 搭建nginx+tomcat+Java的负载均衡环境
- 搭建nginx+tomcat+Java的负载均衡环境
- 搭建nginx+tomcat+Java的负载均衡环境
- 搭建nginx+tomcat+Java的负载均衡环境
- docker-compose搭建Nginx+Tomcat负载均衡环境
- 开发人员学Linux(5):CentOS7编译安装Nginx并搭建Tomcat负载均衡环境
- windows下nginx+tomcat+memcache负载均衡集群搭建
- nginx+tomcat+memcached负载均衡集群搭建详细笔记(下)
- nginx+tomcat+memcached负载均衡集群搭建详细笔记(下)
- windows下nginx+tomcat+memcache负载均衡集群搭建
- CentOS下nginx+tomcat负载均衡集群的搭建
- 仿网易音乐听歌识曲-麦克风动画
- JSP和Servlet之间跳转总结
- sshfs轻松实现文件系统挂载
- Linux中的vim的配置
- 省队集训Round2 DAY3
- linux(ubuntu)下搭建nginx,tomcat负载均衡环境搭建
- iOS编程基础-Swift(三)-变量与简单类型
- Linux Command Line and....ch15(呈现数据)
- @QueryParam和@PathParam比较
- 找出数组中的最大值方法总结
- Struts接收请求参数
- 移动端APM性能监控学习笔记
- Win32API学习笔记第六章(二)
- 211. Add and Search Word