Tomcat集群之Apache篇(一)

来源:互联网 发布:刷水软件 编辑:程序博客网 时间:2024/06/06 03:51

整理:郭胜凯
时间:2016-09-13

这段儿时间对技术的执着有点儿消沉,想想玩儿IT这么长时间了,还没有发过集群方面的文章,因为工作职位比较特殊,现在也很少用到这方面的知识。时间长了怕跟不上技术的脚步了。今天借此详细的整理一下Tomcat的一些集群部署。

说道tomcat集群,大家第一时间想到的可能是Nginx,不错我从不排斥他,在我没有进入Java圈儿的时候,我就已经开始玩儿Nginx了。这篇文建不错Nginx的介绍,主要讲解Apache与Tomcat的集群整合篇。

Apache的下载

1、 下载apache直接进入apache的官网即可,尽量不要从第三方下载站下载,毕竟这玩儿意儿是部署在服务器上的,用户安全第一,不能像自己电脑一样想干啥干啥。(http://httpd.apache.org/)进入官网后,找到合适自己的apache版本,点击download进入下载页面。

Apache官网

2、 下载页会给你列出相关的下载项,因为我在windows上面部署,我这里选Files for Microsoft Windows

Apache下载页

3、 进入这个页面后,会有更详细的列表供你选择,我这里选择第一个

Apache下载详情

Apache的一些问题整理

1、管理员模式运行cmd,将httpd.exe添加到系统服务。
将Apache添加到系统服务
2、且看这里,服务添加完成后,爆了一个错误:在测试apache服务的时候选下了如下错误:
Errors reported here must be corrected before the service can be started.
httpd.exe: Syntax error on line 39 of E:/server/Apache24/conf/httpd.conf: ServerRoot must be a valid directory
如果出现该错误,修改apache/conf/httpd.conf的ServerRoot的值。将${SRVROOT}修改为Apache目录
(搜索SRVROOT)

## ServerRoot: The top of the directory tree under which the server's# configuration, error, and log files are kept.## Do not add a slash at the end of the directory path.  If you point# ServerRoot at a non-local disk, be sure to specify a local disk on the# Mutex directive, if file-based mutexes are used.  If you wish to share the# same ServerRoot for multiple httpd daemons, you will need to change at# least PidFile.## 服务器所在路径Define SRVROOT "E:/server/Apache24"#ServerRoot "${SRVROOT}"ServerRoot "E:/server/Apache24"## Mutex: Allows you to set the mutex mechanism and mutex file directory# for individual mutexes, or change the global defaults## Uncomment and change the directory if mutexes are file-based and the default# mutex file directory is not on a local disk or is not appropriate for some# other reason.## Mutex default:logs

4、 修改完毕后,启动Apache服务,启动报错,如下图:

Apache启动报错

右键计算机->管理->事件查看器->Apache Service 发现在加载模块mod_actions.so时未找到。

事件查看器错误详情

因此,在此修改httpd.conf,将mod_actions.so改为实体路径。

## Dynamic Shared Object (DSO) Support## To be able to use the functionality of a module which was built as a DSO you# have to place corresponding `LoadModule' lines at this location so the# directives contained in it are actually available _before_ they are used.# Statically compiled modules (those listed by `httpd -l') do not need# to be loaded here.## Example:# LoadModule foo_module modules/mod_foo.so##LoadModule access_compat_module modules/mod_access_compat.soLoadModule actions_module E:/server/Apache24/modules/mod_actions.so

5、 重启Apache服务,发现同样错误,继续在事件查看器中查找错误详情,并解决之。

(PS:这里我不详细的说遇到什么错误该用什么什么方法去解决,因为这样说起来的话,文字量就非常大了,上面我已经给出了一个错误的解决过程,其他错误基本上都可以这样排查。其实文字量大是一方面的原因,最大的一个原因还是因为咱们玩儿程序的不像背课文一样死记硬背,必须要有自己的思量。最起码遇到问题要尝试着自己去排除。不能盲目依赖别人。技术是无止境的,大家都会面对改不完的bug敲不完的代码。因此我只会简单的说一下httpd.conf的一些配置。希望对诸位有所帮助。)

循环修改之,启动完毕:

启动Apache服务

Httpd.conf的一些配置说明

Apache是大多数人公认的最好的web服务器之一,但是他也是很多人头疼的服务器之一。一些有心人士将其封装成一套完整的、一键式的、傻瓜化的集成环境。这样的确省掉了很多麻烦,但是要想进一步的了解apache,恐怕还是要手动配置一些东西的。顺便发一下刚才我遇到的错误吧,很多很多!

事件查看器错误列表

遇到问题不丧气、不逃避,要面对问题并解决它。遇到新技术坚持学习,掌握熟练使用它并知道他的原理,是每个程序员必须具备的素质。
多余的废话不多说,接下来是httpd.conf文件的一下常用的配置,或许在这里你会找到一些问题的解决方案。

# 服务器所在路径Define SRVROOT "E:/server/Apache24"#ServerRoot "${SRVROOT}"ServerRoot "E:/server/Apache24"
#配置端口#Listen 12.34.56.78:80Listen 80
## ServerName :当apache有域名指向时,用来确定服务器地址。# This can often be determined automatically, but we recommend you specify# it explicitly to prevent problems during startup.## If your host doesn't have a registered DNS name, enter its IP address here.#ServerName localhost:80
## DocumentRoot: The directory out of which you will serve your# documents. By default, all requests are taken from this directory, but# symbolic links and aliases may be used to point to other locations.##配置WEB文档根目录DocumentRoot "E:/server/Apache24/htdocs"<Directory "E:/server/Apache24/htdocs">    #Options指令:可以定义服务器的一些特性,可选值为 "None", "All"。None表示不应用所有特性 ,All表示 MultiViews 除外的所有特性     #    # 也包括以下任意组合:    #   Indexes                 //当没有找到索引页面时,则显示目录结构    #   Includes                //允许使用mod_include模块来扩展apache的支持范围    #   FollowSymLinks          //当首页为多级目录时,允许通过连接访问上级目录    #   SymLinksifOwnerMatch    //当一个连接和这个连接指向的路径的所有者是同一用户时,FollowSymLinks才会生效    #   ExecCGI                 //允许使用mod_cgi模块执行CGI脚本。    #   MultiViews              //允许使用mod_negotiation模块提供内容自动协商的"多重视图"。(多重视图指:同一路径有可能返回不同类型的视图,可能是text/html类型,也可能是stram类型之类的)    #    # Note that "MultiViews" must be named *explicitly* --- "Options All"    # doesn't give it to you.    #    # The Options directive is both complicated and important.  Please see    # http://httpd.apache.org/docs/2.4/mod/core.html#options    # for more information.    #    Options Indexes FollowSymLinks    #    # AllowOverride指令:包含"None"、"All"    # 这个指令是控制是否开启Apache的URIRewrite(URI重写)服务,如果值为None,则将忽视.htaccess文件    # 否则必须在.htaccess中配置重写规则。通常情况下,AllowOverride的值为None    #     # 其他可选值有    #   AuthConfig                  //允许使用与认证授权相关的指令    #   FileInfo                    //允许使用控制文档类型的指令、控制文档元数据的指令、mod_rewrite中的指令和mod_actions中的Action指令。一般要开启URI重写的话,会有该项    #   Indexes                     //允许使用控制目录索引的指令    #   ……    AllowOverride None    #    # Require指令:访问控制。    #   下面是一些常用的Require表达式    #   Require all denied                              //拒绝所有    #   Require all granted                             //允许所有    #   Require host example.org                        //允许example.org的所有请求    #   Require env env-var [env-var] ...               //允许,匹配环境变量中任意一个    #   Require method http-method [http-method] ...    //允许,特定的HTTP方法    #   Require expr expression                         //允许,表达式为true    #   Require user userid [ userid ] ...              //允许,特定用户    #   Require group group-name [group-name] ...       //允许,特定用户组    #   Require valid-user                              //允许,有效用户    #   Require ip 10 172.20 192.168.2                  //允许 特定IP    #    Require all granted</Directory>
## 设置目录的索引文件# 例如index.html#<IfModule dir_module>    DirectoryIndex index.html</IfModule>
## 某些特殊路径的通行证,类似拦截器的机制,例如.htaccess文件就不允许访问#<Files ".ht*">    Require all denied</Files>
## ErrorLog:错误日志配置# ErrorLog: The location of the error log file.# If you do not specify an ErrorLog directive within a <VirtualHost># container, error messages relating to that virtual host will be# logged here.  If you *do* define an error logfile for a <VirtualHost># container, that host's errors will be logged there and not here.#ErrorLog "logs/error.log"## LogLevel:日志信息配置,配置日志的输出范围,分别为:# debug, info, notice, warn, error, crit,alert, emerg.#LogLevel warn#配置日志的输出格式<IfModule log_config_module>    #    # The following directives define some format nicknames for use with    # a CustomLog directive (see below).    #    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined    LogFormat "%h %l %u %t \"%r\" %>s %b" common    <IfModule logio_module>      # You need to enable mod_logio.c to use %I and %O      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio    </IfModule>    #    # The location and format of the access logfile (Common Logfile Format).    # If you do not define any access logfiles within a <VirtualHost>    # container, they will be logged here.  Contrariwise, if you *do*    # define per-<VirtualHost> access logfiles, transactions will be    # logged therein and *not* in this file.    #    CustomLog "logs/access.log" common    #    # If you prefer a logfile with access, agent, and referer information    # (Combined Logfile Format) you can use the following directive.    #    #CustomLog "logs/access.log" combined</IfModule>
#路径配置<IfModule alias_module>    #    # Redirect: 将某个地址重定向,例如我可以将/mi这个路径重定向到我的博客    # Example:    # Redirect mi http://www.baidu.com/    #    # Alias: 映射某个地址到指定地址。比如我可以把我的博客项目映射到/blog目录下    # Example:    # Alias "D:/server/myblog" "/blog"    #    # If you include a trailing / on /webpath then the server will    # require it to be present in the URL.  You will also likely    # need to provide a <Directory> section to allow access to    # the filesystem path.    #ScriptAlias:处理器映射器。将某个路径映射到某个处理器上面去。    # ScriptAlias: This controls which directories contain server scripts.     # ScriptAliases are essentially the same as Aliases, except that    # documents in the target directory are treated as applications and    # run by the server when requested rather than as documents sent to the    # client.  The same rules about trailing "/" apply to ScriptAlias    # directives as to Alias.    #    ScriptAlias /cgi-bin/ "${SRVROOT}/cgi-bin/"    #这里多余的不多说,详情请参阅http://httpd.apache.org/docs/current/mod/mod_alias.html</IfModule>

这里先说这么多,还有许多配置我会在后面提到。之前说到Apache已经启动,这是我们来访问localhost页面,得到如下如:

Apache访问页面

如果弹出这个页面,说明apache初步配置成功了。
那么接下来咱们看《Tomcat集群之Apache篇(二)》!

PS:
真的不能怪阿海啰嗦。也许有人会说一个apache下载安装就能讲这么一大篇儿,其实阿海已经尽力压缩了。但毕竟不是所有人都对apache那么熟悉,比如说我,我其实就不太懂apache,真的不吹。相信还有好多人这样,所以阿海讲的尽量不会太抽象,能提到的尽量提一下。尤其是对于新学者,希望能够耐心的读完,不要浮躁必竟apache这东西是个细心活儿,稍微一不注意就可能会出点儿小问题。

本篇结束。

0 0