apache2和jk和tomcat安装笔记-ubuntu

摘要:摘要: 在ubuntu上安装apache2和jk代理纵向tomcat的集群小记

Ubuntu是个很奇怪的系统。。。安装完的路径完全和官网下载安装的不一样

 

 

Tomcat一定要用7.0.5X 别的有的不好使各种报错

环境变量里一定要有JAVA_HOME,PATH里一定包含JAVA_HOME

1 (71).jpg

cat /etc/hosts

127.0.0.1 localhost

127.0.0.1 umw

127.0.0.1 192.168.0.121

网络对应关系需要把局域网ip对应本地ip

 

如果想获取客户端真实的ip应该添加remoteip这个模块

 

apt-get install apache2 libapache2-mod-jk

安装apache2和jk

 

Apache2的jk插件在/etc/apache2/mods-avalibale/jk.conf

而jk的workers.propertiy在/etc/libapache2-mod-jk/workers.propertiy

在property里指定java环境和多个tomcat

workers.java_home=/usr/lib/jvm/java7

worker.list=loadbalancer,jkstatus

worker.tomcat1.type=ajp13

worker.tomcat1.host=localhost

worker.tomcat1.port=8009

worker.tomcat1.lbfactor=1

worker.tomcat1.socket_keepalive=1

 

worker.tomcat2.type=ajp13

worker.tomcat2.host=localhost

worker.tomcat2.port=9009

worker.tomcat2.lbfactor=1

worker.tomcat2.socket_keepalive=1

worker.jkstatus.type=status

worker.loadmanager.sticky_session=True

worker.loadbalancer.type=lb

worker.loadbalancer.balance_workers=tomcat1,tomcat2

这个status一定要这么写 哎 累死我了各种试

 

在/etc/apache2/mods-avalibale/jk.conf编辑如下

加上

JkMount /* loadbalancer

JkMount /jkstatus jkstatus

 

找到 Deny from all注释掉

下面改为 Allow from all

 

 

Tomcat的配置

conf目录下

编辑web.xml

最后一行</web-app>上面加上<distributable/>

(使多个session共享)

在server.xml里配置session和端口

<Connector port="8080" protocol="HTTP/1.1"

connectionTimeout="20000"

redirectPort="8443" />

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

这两句 第一个tomcat不用变 第二个改端口可以分别是 9090和9009,响应的端口改为9443

找到engine标签 换成一下配置

jvmRoute第二个tomcat写tomcat2

Receiver的address改为自己局域网的ip,port第二个tomcat改为4002

如果你不是在一台机器上布置两个tomcat,就不用改

 

<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">

 

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"

channelSendOptions="8">

 

<Manager className="org.apache.catalina.ha.session.DeltaManager"

expireSessionsOnShutdown="false"

notifyListenersOnReplication="true"/>

 

<Channel className="org.apache.catalina.tribes.group.GroupChannel">

<Membership className="org.apache.catalina.tribes.membership.McastService"

address="228.0.0.4"

port="45564"

frequency="500"

dropTime="3000"/>

<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"

address="192.168.0.121"

port="4001"

autoBind="100"

selectorTimeout="5000"

maxThreads="6"/>

 

<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">

<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>

</Sender>

<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>

<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>

</Channel>

 

<Valve className="org.apache.catalina.ha.tcp.ReplicationValve"

filter=""/>

<Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>

 

<Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"

tempDir="/tmp/war-temp/"

deployDir="/tmp/war-deploy/"

watchDir="/tmp/war-listen/"

watchEnabled="false"/>

 

<ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>

<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>

</Cluster>

 

 

Apache2的配置

在/etc/apache2/apache2.conf里

空白处加

ServerName localhost:80

DirectoryIndex index.html index.htm index.shtml index.cgi index.php index.php3 index.pl index.xhtml

在/etc/apache2/site-avaliable里编辑000-default.conf设置两个tomcat的虚拟主机目录

为了可以通过端口访问两个tomcat,如果不想让两个tomcat暴露的话不需要设置这个虚拟主机

<VirtualHost *:8080>

ServerAdmin webmaster@localhost

DocumentRoot /opt/tomcat5/webapps

ErrorLog /var/log/apache2/idealerror.log

LogLevel warn

CustomLog /var/log/apache2/idealaccess.log combined

<Directory "/opt/tomcat5/webapps/">

Options FollowSymLinks

AllowOverride None

Order allow,deny

Allow from all

</Directory>

</VirtualHost>

<VirtualHost *:9090>

ServerAdmin webmaster@localhost

DocumentRoot /opt/tomcat6/webapps

ErrorLog /var/log/apache2/idea2error.log

LogLevel warn

CustomLog /var/log/apache2/idea2access.log combined

<Directory "/opt/tomcat6/webapps/">

Options FollowSymLinks

AllowOverride None

Order allow,deny

Allow from all

</Directory>

</VirtualHost>

先启动tomcat再启动apache restart

直接访问局域网地址192.168.0.121就会跳转到其中一台tomcat的主页

访问http://192.168.0.121/jkstatus就可以查看apache2的状态

然后你就可以吧项目考到tomcat的webapps目录下来(两个tomcat都要考哦),重启tomcat访问项目

 

Apache2的相关命令

/etc/init.d/apache2 force-reload 重载

/etc/init.d/apache2 restart 重启

a2enmod添加插件(可查看jk是否被启用)

a2dismod卸载插件

错误日志文件 在var/log/apache2文件夹中其中有mod_jk的日志文件,

也可以查看tomcat目录下的logs文件夹内的localhost_access_log.2014-12-03.txt文件来查看tomcat与apache之间的通讯信息(比较多 看的眼花缭乱的)