标签:负载 users manager term 版本 class ble tst not
1.安装jdk环境[root@hyj test]# vi index.jsp
[root@hyj test]# cat index.jsp
<html>
<head>
<title>test page</title>
</head>
<body>
<%
out.println("please just don‘t let me die !");
%>
</body>
</html>
//修改tomcat2的端口,否则端口起冲突。配置文件为:server.xml
[root@hyj ~]# cd /usr/local/tomacat2/tomcat2/
[root@hyj tomcat2]# ls
bin conf lib logs README.md RUNNING.txt webapps
BUILDING.txt CONTRIBUTING.md LICENSE NOTICE RELEASE-NOTES temp work
[root@hyj tomcat2]# cd conf/
[root@hyj conf]# ls
catalina.policy jaspic-providers.xml server.xml web.xml
catalina.properties jaspic-providers.xsd tomcat-users.xml
context.xml logging.properties tomcat-users.xsd
[root@hyj conf]# vi server.xml
//启动tomcat
[root@hyj ~]# /usr/local//tomacat1/tomcat1/bin/catalina.sh start
Using CATALINA_BASE: /usr/local/tomacat1/tomcat1
Using CATALINA_HOME: /usr/local/tomacat1/tomcat1
Using CATALINA_TMPDIR: /usr/local/tomacat1/tomcat1/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomacat1/tomcat1/bin/bootstrap.jar:/usr/local/tomacat1/tomcat1/bin/tomcat-juli.jar
Tomcat started.
[root@hyj ~]# /usr/local//tomacat2/tomcat2/bin/catalina.sh start
Using CATALINA_BASE: /usr/local/tomacat2/tomcat2
Using CATALINA_HOME: /usr/local/tomacat2/tomcat2
Using CATALINA_TMPDIR: /usr/local/tomacat2/tomcat2/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomacat2/tomcat2/bin/bootstrap.jar:/usr/local/tomacat2/tomcat2/bin/tomcat-juli.jar
Tomcat started.
//关闭防火墙
[root@hyj ~]# systemctl stop firewalld
[root@hyj ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@hyj ~]# setenforce 0
//输入192.168.56.12:8080 访问
//输入192.168.56.12:8080/test 访问
//第二台tomcat
//输入192.168.56.12:8090访问
//输入192.168.56.12:8090/test访问
//在主机192.168.56.11上搭建nginx
使用nginx实现负载均衡,修改配置文件即可。
[root@heyuanjie ~]# vi /usr/local/nginx/conf/nginx.conf
upstream tomcat {
server 192.168.56.12:8080;
server 192.168.56.12:8090;
}
定义好upstream后,需要在server段内添加如下内容:
location / {
proxy_pass http://tomcat;
}
以上两段内容中的tomcat名可以自定义,但需要做到见名知意,并且两者要对应一样。
修改完配置文件检查语法错误,并重启服务
[root@heyuanjie ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@heyuanjie ~]# nginx -s reload
//输入192.168.56.11访问
由于默认访问的是webapps目录下ROOT目录下的 index.jsp文件,所以会出现下面界面。
[root@hyj ~]# ls /usr/local/tomacat1/tomcat1/webapps/
docs examples host-manager manager ROOT
输入192.168.56.11/test则可实现效果
刷新访问界面
也可以修改ROOT目录下的index.jsp文件
[root@hyj ~]# cd /usr/local/tomacat1/tomcat1/webapps/ROOT/
[root@hyj ROOT]# mv index.jsp index.bak
[root@hyj ROOT]# vim index.jsp
[root@hyj ROOT]# cat index.jsp
<html>
<head>
<title>test page</title>
</head>
<body>
<%
out.println("i hope not so far");
%>
</body>
</html>
[root@hyj ~]# cd /usr/local/tomacat2/tomcat2/webapps/ROOT/
[root@hyj ROOT]# mv index.jsp index.bak
[root@hyj ROOT]# vim index.jsp
[root@hyj ROOT]# cat index.jsp
<html>
<head>
<title>test page</title>
</head>
<body>
<%
out.println("please just don‘t let me die !");
%>
</body>
</html>
输入ip192.168.56.11访问
刷新下访问界面:
标签:负载 users manager term 版本 class ble tst not
原文地址:http://blog.51cto.com/13729085/2170748