httpd与tomcat组合配置注意事项

  • Post author:
  • Post category:其他



第一步:


先是 安装apache系列

yum -y install httpd.x86_64 //++++++++++++++++++++++++++

yum -y install httpd-devel.x86_64 //+++++++++++++++++++++++++

运行# httpd -v 查看 版本,如:


第二步

安装jdk,设置JAVA-HOME、CLASS-PATH


第三步

根据httpd版本,下载mod_jk


http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/

解压下载的

tomcat-connectors-1.2.46-src.tar.gz

# tar -xzvf

tomcat-connectors-1.2.46-src.tar.gz

查看是否有安装 gcc

#rpm -q gcc

[root@192 ~]# rpm -q gcc

gcc-4.8.5-44.el7.x86_64

如果没有则用yum安装

#yum -y install gcc

接着进入native文件夹

# cd /opt/tomcat-connectors-1.2.42-src/native

# ./configure –with-apxs=/usr/bin/apxs(此处apxs地址可能不一样,可用命令” whereis apxs “来查看)

# make

#make install

#cd apache-2.0

#cp mod_jk.so /etc/httpd/modules/mod_jk.so


第四步

下载tomcat:

https://archive.apache.org/dist/tomcat/tomcat-9/

根据自己的需求下载tomcat


第五步

(最重要):整合Apache和Tomcat

进入apache安装路径下的conf文件夹,创建两个文件,mod_jk.conf以及workers.properties。

mod_jk.conf 内容如下:

#加载 mod_jk.so 文件,放置在最上

#加载 mod_jk.so 文件,放置在最上

LoadModule jk_module /etc/httpd/modules/mod_jk.so

#加载 tomcat 参数配置文件

JkWorkersFile /etc/httpd/conf/workers.properties

#日志保存文件

JkLogFile /var/log/httpd/mod_jk.log

#日志等级

JkLogLevel info

JkLogStampFormat “[%a %b %d %H:%M:%S %Y]”

JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

#JkRequestLogFormat “%w %V %T”

#######请求拦截, controller负载均衡控制器名称

JkMount /servlet/* controller

JkMount /*.jsp controller

JkMount /*.do controller

JkMount /* controller

############## end #######################

接着:

其中,前两个参数(JkWorkerFile和JkLogFile(cd /var/log/httpd/ 之后 touch mod_jk.log))具体的值会因为apache安装路径的不同而不同,此处需写入自己的apache服务器的路径。

文件末尾的几行JkMount意思是将符合条件的文件交给Tomcat处理。中间则是一些常规参数的设置。

workers.properties内容如下

#server

worker.list = controller

#========tomcat========

worker.tomcat.port=8009 #端口号与tomcat一致

worker.tomcat.host=localhost

worker.tomcat.type=ajp13

worker.tomcat.lbfactor = 1

#========tomcat2========

#worker.tomcat2.port=9009 #端口号与tomcat一致

#worker.tomcat2.host=localhost

#worker.tomcat2.type=ajp13

#worker.tomcat2.lbfactor = 1

#========controller=负载均衡控制器名称=======

worker.controller.type=lb

worker.controller.balanced_workers=tomcat #多个tomcat以”,”隔开

worker.controller.sticky_session=false

worker.controller.sticky_session_force=1

#worker.controller.sticky_session=1


第六步:


在/etc/httpd/conf/httpd.conf 最后边加上如下表示把这个文件载入

Include /etc/httpd/conf/mod_jk.conf

开启8080端口

firewall-cmd –permanent –add-port=8080/tcp

firewall-cmd –reload


第七步:


保存之后重启Apache和Tomcat。

service httpd restart

对于tomcat的启动要进入到tomcat文件夹下边

cd conf

vi server.xml

<Engine name=”Catalina” defaultHost=”localhost” jvmRoute=”controller”>

1

解开tomcat中对于8009端口的枷锁

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

1

cd /opt/tomcat/bin

sh startup.sh

如果是重启{sh startup.sh sh startdown.sh}

如果出现Apache启动报错,那可能是mod_jk.so文件的版本跟Apache版本不符合,需要重新下载,编译。

访问页面的时候用http://192.168.200.2:8080

因为apache的是80 duankou

tomcat的是8080端口

打开默认网页之后是 /opt/tomcat/webapps/Root 下的index.jsp

可以在这个目录下创建对应的测试网页

# vi test.jsp

<html>

<body>

<center>Now time is: <%=new java.util.Date()%></center>

</body>

</html>


注意:

当启动httpd时,有以下报错时,可以按以下方法解决

#systemctl start httpd

报错:

Job for httpd.service failed because the control process exited with error code. See “systemctl status httpd.service” and “journalctl -xe” for details.


运行:


#journalctl -xe


— Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel



— Unit session-20.scope has finished starting up.



— The start-up result is done.

6月 15 13:07:46 192.168.0.129 sshd[3726]: pam_unix(sshd:session): session opened for user root by (uid=0)

6月 15 13:07:46 192.168.0.129 systemd-logind[685]: New session 20 of user root.

— Subject: A new session 20 has been created for user root

— Defined-By: systemd

— Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel

— Documentation: http://www.freedesktop.org/wiki/Software/systemd/multiseat



— A new session with the ID 20 has been created for the user root.



— The leading process of the session is 3726.

6月 15 13:07:46 192.168.0.129 systemd[1]: Starting Session 20 of user root.

— Subject: Unit session-20.scope has begun start-up

— Defined-By: systemd

— Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel



— Unit session-20.scope has begun starting up.

6月 15 13:07:47 192.168.0.129 dbus[658]: [system] Activating service name=’org.freedesktop.problems’ (using servicehelper)

6月 15 13:07:47 192.168.0.129 dbus-daemon[658]: dbus[658]: [system] Activating service name=’org.freedesktop.problems’ (using servicehelper)

6月 15 13:07:47 192.168.0.129 dbus[658]: [system] Successfully activated service ‘org.freedesktop.problems’

6月 15 13:07:47 192.168.0.129 dbus-daemon[658]: dbus[658]: [system] Successfully activated service ‘org.freedesktop.problems’

6月 15 13:08:07 192.168.0.129 polkitd[649]: Registered Authentication Agent for unix-process:3779:805927 (system bus name :1.116 [/usr/bin/pkttyagent –notify-

6月 15 13:08:07 192.168.0.129 systemd[1]: Cannot add dependency job for unit microcode.service, ignoring: Unit is not loaded properly: Invalid argument.

6月 15 13:08:07 192.168.0.129 systemd[1]: Starting The Apache HTTP Server…

— Subject: Unit httpd.service has begun start-up

— Defined-By: systemd

— Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel



— Unit httpd.service has begun starting up.

6月 15 13:08:07 192.168.0.129 systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE

6月 15 13:08:07 192.168.0.129 kill[3786]: kill: cannot find process “”

6月 15 13:08:07 192.168.0.129 dbus[658]: [system] Activating service name=’org.fedoraproject.Setroubleshootd’ (using servicehelper)

6月 15 13:08:07 192.168.0.129 systemd[1]: httpd.service: control process exited, code=exited status=1

6月 15 13:08:07 192.168.0.129 dbus-daemon[658]: dbus[658]: [system] Activating service name=’org.fedoraproject.Setroubleshootd’ (using servicehelper)

6月 15 13:08:07 192.168.0.129 systemd[1]: Failed to start The Apache HTTP Server.

— Subject: Unit httpd.service has failed

— Defined-By: systemd

— Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel



— Unit httpd.service has failed.



— The result is failed.

6月 15 13:08:07 192.168.0.129 systemd[1]: Unit httpd.service entered failed state.

6月 15 13:08:07 192.168.0.129 systemd[1]: httpd.service failed.

6月 15 13:08:07 192.168.0.129 polkitd[649]: Unregistered Authentication Agent for unix-process:3779:805927 (system bus name :1.116, object path /org/freedeskto

6月 15 13:08:09 192.168.0.129 dbus[658]: [system] Successfully activated service ‘org.fedoraproject.Setroubleshootd’

6月 15 13:08:09 192.168.0.129 dbus-daemon[658]: dbus[658]: [system] Successfully activated service ‘org.fedoraproject.Setroubleshootd’

6月 15 13:08:12 192.168.0.129 setroubleshoot[3792]: SELinux is preventing /usr/sbin/httpd from write access on the file /var/log/httpd/jk-runtime-status.3785.

6月 15 13:08:12 192.168.0.129 python[3792]: SELinux is preventing /usr/sbin/httpd from write access on the file /var/log/httpd/jk-runtime-status.3785.

*****  Plugin catchall (100. confidence) suggests   **************************

If you believe that httpd should be allowed write access on the jk-runtime-status.3785 file by default.

Then you should report this as a bug.

You can generate a local policy module to allow this access.

Do

allow this access for now by executing:

# ausearch -c ‘httpd’ –raw | audit2allow -M my-httpd

# semodule -i my-httpd.pp

运行:

# ausearch -c ‘httpd’ –raw | audit2allow -M my-httpd


# semodule -i my-httpd.pp

然后再启动httpd,#systemctl start httpd   一切正常



版权声明:本文为jingde528原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。