您的位置:首页 > 运维架构 > Tomcat

linux tomcat+nginx负载均衡

2015-01-05 16:24 106 查看



架构说明

192.168.10.124安装nginx作为负载机器

192.168.10.125安装tomcat

192.168.10.126安装tomcat



tomcat安装

省略

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.gz

5)cdpcre-8.34

6)./configure

7)make

8)makeinstall




.4安装zlib库

1)http://zlib.net/zlib-1.2.8.tar.gz下载最新的zlib源码包,使用下面命令下载编译和安装zlib包:

2)cd/usr/local/src

3)wget'target='_blank'>http://zlib.net/zlib-1.2.8.tar.gz[/code]
4)tar-zxvfzlib-1.2.8.tar.gz

5)cdzlib-1.2.8

6)./configure

7)make

8)makeinstall




5
安装ssl(某些vps默认没装ssl)

cd/usr/local/src

wget'target='_blank'>http://www.openssl.org/source/openssl-1.0.1c.tar.gz[/code]
tar-zxvfopenssl-1.0.1c.tar.gz




56安装nginx

Nginx一般有两个版本,分别是稳定版和开发版,您可以根据您的目的来选择这两个版本的其中一个,下面是把Nginx安装到/usr/local/nginx目录下的详细步骤:

cd/usr/local/src

wget'target='_blank'>http://nginx.org/download/nginx-1.4.2.tar.gz[/code]
tar-zxvfnginx-1.4.2.tar.gz

cdnginx-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.1c

make

makeinstall

--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.default

fastcgi.conf.defaultlogsscgi_params

fastcgi_paramsmime.typesscgi_params.default

fastcgi_params.defaultmime.types.defaultuwsgi_params

htmlnginxuwsgi_params.default

koi-utfnginx.confwin-utf





5.6启动

1)确保系统的80端口没被其他程序占用,运行/usr/local/nginx/nginx命令来启动Nginx

netstat-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

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: