手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Mac 环境下搭建Nginx + Tomcat集群

[日期:2014-06-23] 来源:oschina.net   作者:陈袁 [字体:大 中 小]

Mac 环境下搭建 Nginx + Tomcat集群, Nginx + Tomcat集群是大家常用的一种搭配, 好处有很多, 而我做这个的初衷就2个目的, 1: 解决tomcat的复杂均衡问题, 2. 当我上线的时候, 启动tomcat, 能够做到外部访问不间断。

CentOS 6.2实战部署Nginx+MySQL+PHP http://www.linuxidc.com/Linux/2013-09/90020.htm

使用Nginx搭建WEB服务器 http://www.linuxidc.com/Linux/2013-09/89768.htm

搭建基于Linux6.3+Nginx1.2+PHP5+MySQL5.5的Web服务器全过程 http://www.linuxidc.com/Linux/2013-09/89692.htm

CentOS下搭建Nginx+Tomcat实现集群负载与session复制 http://www.linuxidc.com/Linux/2013-04/82210.htm

下面开始我们的步骤:

第一步: 安装我们的Nginx, Mac上是利用brew安装的;

[linuxidc@www.linuxidc.com:~]$ brew install nginx
==> Installing nginx dependency: pcre
==> Downloading http://downloads.sourceforge.net/project/pcre/pcre/8.34/pcre-8.3 ######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/pcre/8.34 --enable-utf8 --enable-unic
==> make
==> make test
==> make install /usr/local/Cellar/pcre/8.34: 140 files, 4.1M, built in 58 second>
==> Installing nginx

差不多就这一步, 我们看看是够安装成功:

[linuxidc@www.linuxidc.com:~]$ nginx -V
nginx version: nginx/1.4.4
TLS SNI support enabled
configure arguments: --prefix=/usr/local/Cellar/nginx/1.4.4 --with-http_ssl_module --with-pcre --with-ipv6 --sbin-path=/usr/local/Cellar/nginx/1.4.4/bin/nginx --with-cc-opt=-I/usr/local/include --with-ld-opt=-L/usr/local/lib --conf-path=/usr/local/etc/nginx/nginx.conf --pid-path=/usr/local/var/run/nginx.pid --lock-path=/usr/local/var/run/nginx.lock --http-client-body-temp-path=/usr/local/var/run/nginx/client_body_temp --http-proxy-temp-path=/usr/local/var/run/nginx/proxy_temp --http-fastcgi-temp-path=/usr/local/var/run/nginx/fastcgi_temp --http-uwsgi-temp-path=/usr/local/var/run/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/var/run/nginx/scgi_temp --http-log-path=/usr/local/var/log/nginx/access.log --error-log-path=/usr/local/var/log/nginx/error.log --with-http_gzip_static_module

能看见, 这里安装的是 1.4.4版本的.

顺便告诉大家, brew安装的文件路径一般默认在:

[linuxidc@www.linuxidc.com:Cellar]$ pwd
/usr/local/Cellar

然而, nginx的真正路径在:

[linuxidc@www.linuxidc.com:nginx]$ pwd
/usr/local/etc/nginx

我们启动nginx服务器:

[linuxidc@www.linuxidc.com:~]$ sudo nginx
Password:
nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
nginx: [emerg] still could not bind()

输入你的个人密码, 就算是启动了:

这就算启动了. 很简单吧~

如果是查看nginx启动进程

[linuxidc@www.linuxidc.com:~]$ ps -ef|grep nginx
    0  8220    1  0  9:07PM ??        0:00.00 nginx: master process nginx
  502  8322  8220  0  9:34PM ??        0:00.87 nginx: worker process
  502  8323  8220  0  9:34PM ??        0:00.15 nginx: worker process
  502  8704  8598  0  8:27PM ttys000    0:00.00 grep nginx

关闭nginx服务器:

[linuxidc@www.linuxidc.com:~]$ sudo nginx -s stop

============= 现在就差不多把nginx的安装说明白了. OK吗?

第二步: 我们在本机部署2台Tomcat容器, 并且要正常跑起来. 具体看看:

你需要下载一个Tomcat, 这个我觉得不需要在说怎么下载Tomcat了吧..我一般会去官方下载tar包.

apache-tomcat-7.0.37

下载之后, 我们将名字修改为:

drwxr-xr-x  16 linuxidc  staff  544 Jun 21 18:39 tomcat-7-2
drwxr-xr-x  16 linuxidc  staff  544 Jun 21 18:41 tomcat-7-3

我这里暂且从2开始取名吧~ 因为我本地还有一个tomcat-7-1, 自己开发用的. 反正这只是一个文件夹的名字而已, 应该不会造成混淆. 我们就以 tomcat-7-2, tomcat-7-3, 开举例子:

如果需要让2台Tomcat同时启动, 我们是需要修改配置文件的, 因为Tomcat绑定的端口号是唯一的, 其实我们就是让他们的端口号不冲突而已. 这样子就能跑起2台Tomcat了.

更多详情见请继续阅读下一页的精彩内容: http://www.linuxidc.com/Linux/2014-06/103565p2.htm

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款