部署tomcat及负载均衡
实验案例:
通常情况下,一台Tomcat站点由于可能出现单点故障及无法应付过多客户复杂多样的请求等问题,不能单独应用于生产环境下,所以我们需要一套更可靠的解决方案 来完善Web站点架构。Nginx是一款非常优秀的http服务器软件,它能够支持高达50000个并发连接数的响应,拥有强大的静态资源处理能力,运行稳定,并且内存、CPU等系统资源消耗非常低。目前很多大型网站都应用Nginx服务器作为后端网站程序的反向代理及负载均衡器,来提升整个站点的负载并发能力。本案例我们将讲解以Nginx作为负载均衡器,Tomcat作为应用服务器的负载群集的设置方法。
实验拓扑
实验步骤:
一.tomcat服务器1配置
1)查看JDK是否安装
2)安装配置Tomcat
①解压/apache-tomcat-7.0.54.tar.gz包
[root@centos01 ~]# tar zxvf /mnt/apache-tomcat-7.0.54.tar.gz
②移动文件夹
[root@centos01 ~]# mv apache-tomcat-7.0.54/ /usr/local/tomacat
③启动tomcat
[root@centos01 ~]# /usr/local/tomacat/bin/startup.sh
④查看服务运行状态
⑤打开浏览器测试
⑥创建一个web目录
[root@centos01 ~]# mkdir -p /web/webapp1
⑦创建一个测试网页
[root@centos01 ~]# echo “This is a test1 page” > /web/webapp1/index.jsp
⑧修改Tomcat的server.xml文件
⑨关闭Tomcat,在重新启动
[root@centos01 ~]# /usr/local/tomacat/bin/shutdown.sh
[root@centos01 ~]# /usr/local/tomacat/bin/startup.sh
网页测试
二.Tomcat服务器2配置(配置和tomcat1一样)
[root@centos02 ~]# tar zxvf /mnt/apache-tomcat-7.0.54.tar.gz
[root@centos02 ~]# mv apache-tomcat-7.0.54/ /usr/local/tomcat
[root@centos02 ~]# mkdir -p /web/webapp1
[root@centos02 ~]# echo “this is a test2 page” > /web/webapp1/index.jsp
[root@centos02 ~]# vim /usr/local/tomcat/conf/server.xml
测试
三.Nginx服务器配置
1)安装软件包
[root@centos03 ~]# yum -y install pcre-devel zlib-devel openssl-devel
2)解压并安装nginx
[root@centos03 ~]# groupadd www
[root@centos03 ~]# useradd -g www www -s /bin/false
[root@centos03 ~]# tar zxvf /mnt/nginx-1.6.0.tar.gz -C /usr/src/
[root@centos03 ~]# cd /usr/src/nginx-1.6.0/
[root@centos03 nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-file-aio --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module
[root@centos03 nginx-1.6.0]# make && make install
3)配置nginx.conf
[root@centos03 nginx-1.6.0]# vim /usr/local/nginx/conf/nginx.conf
- 检查nginx配置文件是否正确
[root@centos03 ~]# /usr/local/nginx/sbin/nginx -t
5)启动nginx服务
[root@centos03 ~]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
6)查看nginx服务进程
四.测试负载均衡效果