linux tomcat+nginx负载均衡
2015-01-05 16:24
106 查看
架构说明
192.168.10.124安装nginx作为负载机器
192.168.10.125安装tomcat
192.168.10.126安装tomcattomcat安装
省略
nginx安装部署
1编译环境
nginx可以使用各平台的默认包来安装,本文是介绍使用源码编译安装,包括具体的编译参数信息。
正式开始前,编译环境gccg++开发库之类的需要提前装好,这里默认你已经装好。
ububtu平台编译环境可以使用以下指令
apt-getinstallbuild-essential
apt-getinstalllibtool
centos平台编译环境使用如下指令
安装make:
yum-yinstallgccautomakeautoconflibtoolmake
安装g++:
yuminstallgccgcc-c++
.2选定源码目录
可以是任何目录,本文选定的是/usr/local/src
cd/usr/local/src
5.3安装PCRE库
1)下载最新的PCRE源码包,使用下面命令下载编译和安装PCRE包:
2)cd/usr/local/src
3)wget'target='_blank'>ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gz[/code] 4)tar-zxvfpcre-8.34.tar.gz5)cdpcre-8.346)./configure7)make8)makeinstall.4安装zlib库
1)http://zlib.net/zlib-1.2.8.tar.gz下载最新的zlib源码包,使用下面命令下载编译和安装zlib包:2)cd/usr/local/src3)wget'target='_blank'>http://zlib.net/zlib-1.2.8.tar.gz[/code] 4)tar-zxvfzlib-1.2.8.tar.gz5)cdzlib-1.2.86)./configure7)make8)makeinstall5
安装ssl(某些vps默认没装ssl)cd/usr/local/srcwget'target='_blank'>http://www.openssl.org/source/openssl-1.0.1c.tar.gz[/code] tar-zxvfopenssl-1.0.1c.tar.gz56安装nginx
Nginx一般有两个版本,分别是稳定版和开发版,您可以根据您的目的来选择这两个版本的其中一个,下面是把Nginx安装到/usr/local/nginx目录下的详细步骤:cd/usr/local/srcwget'target='_blank'>http://nginx.org/download/nginx-1.4.2.tar.gz[/code] tar-zxvfnginx-1.4.2.tar.gzcdnginx-1.4.2./configure--sbin-path=/usr/local/nginx/nginx\--conf-path=/usr/local/nginx/nginx.conf\--pid-path=/usr/local/nginx/nginx.pid\--with-http_ssl_module\--with-pcre=/usr/local/src/pcre-8.34\--with-zlib=/usr/local/src/zlib-1.2.8\--with-openssl=/usr/local/src/openssl-1.0.1cmakemakeinstall--with-pcre=/usr/src/pcre-8.34指的是pcre-8.34的源码路径。--with-zlib=/usr/src/zlib-1.2.7指的是zlib-1.2.7的源码路径。安装成功后/usr/local/nginx目录下如下fastcgi.confkoi-winnginx.conf.defaultfastcgi.conf.defaultlogsscgi_paramsfastcgi_paramsmime.typesscgi_params.defaultfastcgi_params.defaultmime.types.defaultuwsgi_paramshtmlnginxuwsgi_params.defaultkoi-utfnginx.confwin-utf5.6启动
1)确保系统的80端口没被其他程序占用,运行/usr/local/nginx/nginx命令来启动Nginxnetstat-ano|grep80修改/usr/local/nginx/conf/nginx.conf
#usernobody;
worker_processes1;
#error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;
#pidlogs/nginx.pid;
events{
worker_connections1024;
}
http{
includemime.types;
default_typeapplication/octet-stream;
#log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'
#'$status$body_bytes_sent"$http_referer"'
#'"$http_user_agent""$http_x_forwarded_for"';
#access_loglogs/access.logmain;
sendfileon;
#tcp_nopushon;
#keepalive_timeout0;
keepalive_timeout65;
#gzipon;
##此处添加要关联的tomcat地址:端口redis3是本机的hostaneme
upstreamredis3{
server192.168.10.125:8080;
server192.168.10.126:8080;
}
server{
listen80;
server_nameredis3;
#charsetkoi8-r;
#access_loglogs/host.access.logmain;
location/{
roothtml;
indexindex.htmlindex.htm;
proxy_passhttp://redis3;##此处redis是本机的
hostnameproxy_set_headerX-Real-IP$remote_addr;
client_max_body_size100m;
}
#error_page404/404.html;
#redirectservererrorpagestothestaticpage/50x.html
#
error_page500502503504/50x.html;
location=/50x.html{
roothtml;
}
#proxythePHPscriptstoApachelisteningon127.0.0.1:80
#
#location~\.php${
#proxy_passhttp://127.0.0.1;#}
#passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000
#
#location~\.php${
#roothtml;
#fastcgi_pass127.0.0.1:9000;
#fastcgi_indexindex.php;
#fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;
#includefastcgi_params;
#}
#denyaccessto.htaccessfiles,ifApache'sdocumentroot
#concurswithnginx'sone
#
#location~/\.ht{
#denyall;
#}
}
#anothervirtualhostusingmixofIP-,name-,andport-basedconfiguration
#
#server{
#listen8000;
#listensomename:8080;
#server_namesomenamealiasanother.alias;
#location/{
#roothtml;
#indexindex.htmlindex.htm;
#}
#}
#HTTPSserver
#
#server{
#listen443;
#server_namelocalhost;
#sslon;
#ssl_certificatecert.pem;
#ssl_certificate_keycert.key;
#ssl_session_timeout5m;
#ssl_protocolsSSLv2SSLv3TLSv1;
#ssl_ciphersHIGH:!aNULL:!MD5;
#ssl_prefer_server_cipherson;
#location/{
#roothtml;
#indexindex.htmlindex.htm;
#}
#}
}
[code]
然后启动nginx访问如果出现tomcat的访问页代表配置ok
相关文章推荐
- linux lvs 的DR 模式CENTOS 4.4 三台linux 的http负载均衡安装步骤
- Linux系统负载均衡集群系统解决方案---LVS
- linux 双网卡绑定(bonding)实现负载均衡或故障转移
- 使用nginx来负载均衡,本文在window与linux下配置nginx实现负载
- linux下实现nginx的负载均衡
- 三台centos 5 linux lvs 的DR 模式http负载均衡安装步骤
- 主机多网卡负载均衡-HP-APA,sun-multipathing,linux-bond
- linux 双网卡绑定(bonding)实现负载均衡或故障转移
- linux 双网卡绑定(bonding)实现负载均衡或故障转移
- Linux 网络负载均衡的实现
- linux 下 MySQL-Proxy 实现 MySQL 的负载均衡和读写分离实现
- Discuz!NT负载均衡解决方案(HA)之---LVS(Linux Virtual Server) 推荐
- 19个心得 明明白白说Linux下的负载均衡
- Linux DNS的负载均衡及子域委派
- Linux下基于DNS的多机均衡负载的实现
- 使用Linux实现负载均衡
- 转帖---负载均衡---在window与linux下配置nginx
- 负载均衡解决方案(HA)之---LVS(Linux Virtual Server)
- linux 双网卡绑定(bonding)实现负载均衡或故障转移
- Linux中Apache+Tomcat+JK实现负载均衡和群集的完整过程