预配置说明:
该系统是centos7
m1.xsllqs.com的地址是192.168.1.107。
c1.xsllqs.com的地址是192.168.1.114。
c2.xsllqs.com的地址是192.168.1.113。
Tomcat安装需要与JDK一起工作,其中包括甲骨文JDK和开放的JDK。
OracleJDK8下载地址:http://www.Oracle.com/technetwork/cn/Java/javase/downloads/JDK8-downloads-2133151-zhs.html
tomcat的下载地址:http://tomcat.apache.org/
C1.xsllqs.com(192.168.1.114)下载安装jdk(建议本地加载上传)和tomcat。
[root@c1 ~]# wget http://download.oracle.com/otn-pub/java/jdk/8u73-b02/jdk-8u73-linux-x64.rpm [root@c1 ~]# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.0.36/bin/apache-tomcat-8.0.36.tar.gz [root@c1 ~]# ls apache-tomcat-8.0.36.tar.gz jdk-8u73-linux-x64.rpm [root@c1 ~]# yum install jdk-8u73-linux-x64.rpm [root@c1 ~]# vim /etc/profile.d/java.sh export JAVA_HOME=/usr/java/latest export PATH=$JAVA_HOME/bin:$PATH [root@c1 ~]# . /etc/profile.d/java.sh [root@c1 ~]# java -version java version "1.8.0_73" [root@c1 ~]# tar xf apache-tomcat-8.0.36.tar.gz -C /usr/local [root@c1 ~]# cd /usr/local/ [root@c1 local]# ln -sv apache-tomcat-8.0.36 tomcat "tomcat" -> "apache-tomcat-8.0.36" [root@c1 tomcat]# vim /etc/profile.d/tomcat.sh export CATALINA_HOME=/usr/local/tomcat export PATH=$CATALINA_HOME/bin:$PATH [root@c1 tomcat]# . /etc/profile.d/tomcat.shC2.xsllqs.com(192.168.1.113)下载并安装jdk和tomcat
[root@c2 ~]# wget http://download.oracle.com/otn-pub/java/jdk/8u73-b02/jdk-8u73-linux-x64.rpm [root@c2 ~]# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.0.36/bin/apache-tomcat-8.0.36.tar.gz [root@c2 ~]# ls apache-tomcat-8.0.36.tar.gz jdk-8u73-linux-x64.rpm [root@c2 ~]# yum install jdk-8u73-linux-x64.rpm [root@c2 ~]# vim /etc/profile.d/java.sh export JAVA_HOME=/usr/java/latest export PATH=$JAVA_HOME/bin:$PATH [root@c2 ~]# . /etc/profile.d/java.sh [root@c2 ~]# java -version java version "1.8.0_73" [root@c2 ~]# tar xf apache-tomcat-8.0.36.tar.gz -C /usr/local [root@c2 ~]# cd /usr/local/ [root@c2 local]# ln -sv apache-tomcat-8.0.36 tomcat "tomcat" -> "apache-tomcat-8.0.36" [root@c2 tomcat]# vim /etc/profile.d/tomcat.sh export CATALINA_HOME=/usr/local/tomcat export PATH=$CATALINA_HOME/bin:$PATH [root@c2 tomcat]# . /etc/profile.d/tomcat.sh 二、修改tomcat配置文件 [root@c1 tomcat]# cd /usr/local/tomcat/webapps/ [root@c1 webapps]# mkdir myapp/{lib,classes,WEB-INF,META-INF} -pv [root@c1 webapps]# cd myapp/添加c1和c2的主页文件
[root@c1 myapp]# vim indix.jsp <%@ page language="java" %> <html> <head><title>Tomcat1</title></head> <body> <h1><font color="red">c1.xsllqs.com</font></h1> <table align="centre" border="1"> <tr> <td>Session ID</td> <% session.setAttribute("xsllqs.com","xsllqs.com"); %> <td><%= session.getId() %></td> </tr> <tr> <td>Created on</td> <td><%= session.getCreationTime() %></td> </tr> </table> </body> </html> [root@c2 myapp]# vim indix.jsp <%@ page language="java" %> <html> <head><title>Tomcat2</title></head> <body> <h1><font color="blue">c2.xsllqs.com</font></h1> <table align="centre" border="1"> <tr> <td>Session ID</td> <% session.setAttribute("xsllqs.com","xsllqs.com"); %> <td><%= session.getId() %></td> </tr> <tr> <td>Created on</td> <td><%= session.getCreationTime() %></td> </tr> </table> </body> </html>修改Tomcat-user.XML(C1和c2都必须更改)
[root@c1 conf]# vim /usr/local/tomcat/conf/tomcat-users.xml #在</tomcat-users>中添加 <role rolename="manager-gui"/> <role rolename="admin-gui"/> <user username="tomcat" password="<tomcat>" roles="manager-gui,admin-gui"/>修改server.XML(C1和c2都必须更改)
[root@c1 conf]# vim /usr/local/tomcat/conf/server.xml #修改主配置文件,appBase后面是应用的相对路径也可以是绝对路径 <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> #这里是访问日志的设置 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> #这里设置Context调用msm需要的组件,m1为主c2为备,因为我这里只有3台机器所以把c2作为备,正常情况是4台,2台memcached和2台tomcat <Context path="/myapp" docBase="/usr/local/tomcat/webapps/myapp" reloadable="true"> <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager" memcachedNodes="m1:192.168.1.107:11211,c2:192.168.1.113:11211" failoverNodes="m1" requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$" transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory" /> </Context>测试文件
[root@c1 ~]# catalina.sh configtest [root@c2 ~]# catalina.sh configtest [root@c1 ~]# catalina.sh start [root@c2 ~]# catalina.sh start 三、安装msm并在c1和c2上下载msm需要的jar包。
[root@c1 ~]# wget http://repo1.maven.org/maven2/de/javakaffee/msm/memcached-session-manager/1.9.4/memcached-session-manager-1.9.4.jar [root@c1 ~]# wget http://repo1.maven.org/maven2/de/javakaffee/msm/memcached-session-manager-tc8/1.9.4/memcached-session-manager-tc8-1.9.4.jar [root@c1 ~]# wget http://repo1.maven.org/maven2/de/javakaffee/msm/msm-javolution-serializer/1.9.4/msm-javolution-serializer-1.9.4.jar [root@c1 ~]# wget http://repo1.maven.org/maven2/net/spy/spymemcached/2.11.1/spymemcached-2.11.1.jar [root@c1 ~]# wget http://www.java2s.com/Code/JarDownload/javolution/javolution-5.4.3.1.jar.zip [root@c1 ~]# mv javolution-5.4.3.1.jar memcached-session-manager-1.9.4.jar memcached-session-manager-tc8-1.9.4.jar msm-javolution-serializer-1.9.4.jar spymemcached-2.11.1.jar /usr/local/tomcat/lib/Memcached安装在m1和c2上
[root@m1 ~]# yum install memcached [root@c2 ~]# yum install memcachedM1安装nginx并修改nginx的配置文件
[root@m1 ~]# yum install nginx [root@m1 ~]# vim /etc/nginx/nginx.conf #server外加入 upstream tcsrvs { server 192.168.1.114:8080; server 192.168.1.113:8080; } #server内加入 location ~* \.(jsp|do)$ { proxy_pass http://tcsrvs; } [root@m1 ~]# nginx -t启动服务
[root@m1 ~]# systemctl start nginx.service [root@m1 ~]# systemctl start memcached [root@c2 ~]# systemctl start memcached 四、测试欢迎分享,转载请注明来源:内存溢出
评论列表(0条)