两台Nginx代理四台tomcat教程

195.203.1.1 安装tomcat nginx
195.203.1.2 安装tomcat nginx
195.203.1.3 安装tomcat
195.203.1.4安装tomcat

(1)首先安装tomcat

(2)解压tomcat
[root@localhost tomcat]# tar -xzvf apache-tomcat-6.0.48.tar.gz

(3)将tomcat重命名
[root@localhost tomcat]# mv apache-tomcat-6.0.48 tomcat6.0

(4)启动tomcat
[root@localhost bin]# ./startup.sh

(5)验证tomcat是否已经被成功安装。
curl http://localhost:8080/index.html
页面出现tomcat首页的内容,tomcat安装成功!

[同理在其他的三台服务器上面安装tomcat]
添加用户组 和用户

groupadd nginx
useradd -g nginx nginx

然后安装nginx
(1)将nginx安装包放到/usr/local 目录下
(2)将其解压
(3)tar -zxvf nginx-1.10.2.tar.gz
(4)将nginx-1.10.2.tar.gz重命名
(5)mv nginx-1.10.2.tar.gz nginx
(6)进入nginx目录下
(7)进入conf目录下将nginx.conf移动到nginx目录下然后对其进行修改
(8)修改内容如下:

user nginx nginx;
worker_processses 2;
errpr_log /usr/local/nginx/logs/nginx_error.log;
pid /usr/local/nginx/logs/nginx.pid;
events{
worker_connections 65535;
}

然后将server里面的servername改为与之相对应的IP
(9)然后进行初始化配置
(10)./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_sslmodule --with-http_sub_module --with-http_stub_status_module
此时可能会遇到的问题:

||cp conf/nginx.conf 'user/local/nginx/conf/' cp :'conf/nginx.conf' and 'user/local/nginx/conf/nginx.conf' are the sane file

则可以输入以下内容:
(11)./configure --prefix =/usr/local/nginx/ --conf-path=/usr/local/nginx/nginx.conf
(12)make
(13)make install
(14)然后启动nginx
(15)进入/nginx/sbin 目录下
(16)./nginx
(17)此时可能遇到的问题是:

./nginx:error while loading shared libraries:libpre.so.1 accnot open shared object file :No such file or directory

如果出现以上问题则解决方法如下:
建立软链接:ln -s /usr/local/lib/libpre.so.1 /lib64/
(18)再次启动nginx ./nginx 启动nginx成功
(19)访问nginx
(20)curl http://localhost:80/
(21)即可以出现nginx的欢迎页面
注意:启动nginx命令:./nginx 关闭nginx命令:./nginx -s stop
这样tomcat和nginx都安装成功。
开始配置nginx和tomcat的负载均衡
(1)这里只需要修改/nginx 目录下的nginx.conf 配置文件即可。
(2)配置内容如下:
(3)在http的大括号里面的access_log下面加上以下内容:

upstream tomcatsserver 198.203.180.46:8080;
server 198.203.180.47:8080;
server 198.203.180.48:8080;
server 198.203.180.49:8080;
}

(4)然后在location /{}里加入以下内容:

root html;
index index.html index.htm;
proxy_pass http://tomcats;
proxy_redirect default;

(5)到此为止负载均衡配置完成。
(6)此时将四台服务器的tomcat都开启,然后开启两台nginx。
然后在nginx服务器上面分别访问
curl http://localhost/
就可以随机访问四台tomcat的欢迎页面了。

  • 4
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值