广告位!
很适用的工具(推荐) Good tool to recommend
2006年12月15日星期五
opencms中多站点的配置
opencms官方文档中有一篇关于整合opencms,Apache,tomcat管理多站点的文章--“Integrating OpenCms, Tomcat and the Apache webserver with mod_proxy”,这些天按照文档说明自己动手配置了一下,现在把心得体会写出来,以供opencms的研究者,使用者参考,批评指正。
官方文档的主旨是:运用Apache的Mod_proxy实现opencms的动态静态资源分离,由apache直接存储静态资源,tomcat处理请求中的动态资源,并去除前缀/opencm/opencms,我的配置测试环境是:
tool | version |
gentoo linux | 2.6 |
apache | 2.0 |
tomcat | 5.5 |
mysql | 4.1 |
opencms | 6.2 |
在作任何文件的配置修改之前,请最好作个备份!配置步骤如下:
1. 在你的域名服务中设置你的域名,稍后安装及配置过程中将会用到。我的域名是在/etc/hosts 文件中设置的:
127.0.0.1 localhost localhost.localdomain 192.168.0.136 www.lxbing.com 192.168.0.136 ww.example.com 192.168.0.136 www.doc.com |
2. 清除tomcat下/webapps目录中的全部应用,关闭tomcat,把opencms.war包改为ROOT.war,拷入 /webapps目录,因为tomcat默认的应用是ROOT,这样就去除了路径中的第一个opencms。启动tomcat,按步骤安装 opencms。 可以通过http://www.lxbing.com:8080/setup 也可以用http://Ip:8080/setup
进行安装。
3. 安装完毕后你可以通过http://Ip:8080/opencms/system/login进入opencms的工作区,可以看到还有一个/opencms存在于路径中。
找到 ${TOMCAT_HOME}/webapps/ROOT/WEB-INF/config/opencms-importexport.xml文件,编辑节点 staticexport/rendersettings 中的部分内容,去除上下文环境,因为现在opencms已经作为tomcat的默认应用了,说以它的默认上下文环境就是根目录,编辑后的节点中的相关内容为:
|
4. 修改${TOMCAT_HOME}/webapps/ROOT/WEB-INF/config/opencms-system.xml 文件,配置opencms中的多个站点,在节点system/sites 中设置需要配置的站点(所谓站点就是opencms中的microsite文件类型),由于测试用的opencms是新安装的,所以我以oepncms中 的/default/,/demopages/,/alkacon-documentation/ 为例,具体配置如下:
uri="/sites/default/demopages/"/> uri="/sites/default/alkacon-documentation/"/>
|
注意:在这种配置中,所以站点的 uri 都必须在 /site/default/目录下,否则,会报错,我没尝试过能否把/site/default/ 该为根目录/ 或是其他意义的目录,如何有人作过这方面的配置测试,希望能拿出来让大家学习! 每个站点的域名必须是在你的域名服务中定义过的,否则,会报错。
5. 配置 ${TOMCAT_HOME}/conf/ 中的server.xml 文件.
|
6. 配置 /etc/Apaches2/中的 httpd.conf文件,使用能支持mod_proxy模块
LoadModule alias_module modules/mod_alias.so LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so |
7. 配置apache 中的虚拟主机
NameVirtualHost *:80
ProxyPass /opencms/ http://www.example.com/ ProxyPass /resources/ http://localhost:8082/resources/ ProxyPass / http://localhost:8082/opencms/
ProxyPass /opencms/ http://www.lxbing.com/ ProxyPass /resources/ http://localhost:8081/resources/ ProxyPass /export/ http://localhost:8081/export/ ProxyPass / http://localhost:8081/opencms/
ProxyPass /opencms/ ! ProxyPass /resources/ http://localhost:8088/resources/ ProxyPass / http://localhost:8088/opencms/ |
在这个配置中,www.lxbing.com 代理的是 http://localhost:8081/opencms/,这个页面有一个链接到opencms登录页面的链接,如果按照官方文档中的说明配置为:
ProxyPass /opencms/ ! RedirectPermanent /opencms/ http://${DOMAIN_NAME}/ |
将无法登录opencms工作区,真确的配置为:
ProxyPass /opencms/ http://${DOMAIN_NAME}/ RedirectPermanent /opencms/ http://${DOMAIN_NAME}/ |
在配置虚拟主机时应注意 ServerName,DocumentRoot,以及 /resources/, /export/,现在配置完成,可以通过域名访问opencms中的站点了,但是apache和tomcat是怎么分别管理静态,动态资源的,我还不大明白,是不是我的配置中有什么不妥的地方,请大家多多指教!
Posted by
Bean
at
04:00
0
comments
Apache+Tocat虚拟主机的配置Apache+(Apache+Tomcat)多重代理的配置
Apache Virtual Host
one of the most important facilities in Apache is the ability to run 'Virtual Host',the term Virtual Host refers to the practice of maintaining more than one server on one machine,it is essential way to deploy multiple web services - eache of them with different host name and urls,Example, many companies desired to share a web server of containning multiple domains for different applications(wwww.example1.com for a applicaton,and www.example2.com for the other application),without desiring the vistor to know any extra path information(IP,port etc),because of high security request.by this way,you don't need to by more new machine for every application,it can highly improve optimization of the server.
In this issues we explain how to go about setting up a virtual host on your machine, what you need to do to get the hostname working, and how to configure Apache.Of course, we assume that you have already installing and running Tomcat and Apache servers in your computer.There has two method to implement 'Virtual Host', name-based or IP-based virtual hosts.
Apache was one of the first servers to support IP-based virtual hosts right out of the box. Versions 1.1 and later of Apache support both, IP-based and name-based virtual hosts (vhosts). The latter variant of virtual hosts is sometimes also called host-based or non-IP virtual hosts.
Host-based
my system environment for this configuration is:server | version |
gentoo linux | 2.6 |
Apache | 2.0 |
Tomcat | 5.0 and 5.5 |
Your server has a single IP address, and multiple aliases (CNAMES) point to this machine in DNS. You want to run a web server for www.example1.com and www.example2.org on this machine.
Note
Creating virtual host configurations on your Apache server does not magically cause
DNS entries to be created for those host names. You must have the names in DNS, resolving
to your IP address, or nobody else will be able to see your web site. You can put entries
in your hosts file for local testing, but that will work only from the machine with those
hosts entries.
192.168.0.136 www.lxbing.com
192.168.0.136 www.example.com
192.168.0.136 www.example1.com
"8080" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75" proxyName="www.example1.com" proxyPort="80"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" />
"8081"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75" proxyName="www.lxbing.com" proxyPort="80"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000" useURIValidationHack="false"
disableUploadTimeout="true" />
"8082"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75" proxyName="www.example.com" proxyPort="80"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000" useURIValidationHack="false"
disableUploadTimeout="true" />
"8009"
enableLookups="false" redirectPort="8443" debug="0"
protocol="AJP/1.3" />
Apache provide a mode called mod_proxy,which can enable apache to service like a proxy server.thus, we can deliver the specific request to Tomcat server. it needn't to be configed like web connector mod_jk, in order to active this,we should do some configuration as follow:
- modify Apache configuration to contains mod_proxy module,if you create it from source,the easy way is add "--enable-module=proxy" to command line "./configure".
- if you don't install mod_proxy module, you can upload it using command below,in the file /etc/apache2/httpd.conf
LoadModule alias_module modules/mod_alias.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
specific request to tomcat server.
NameVirtualHost *:80
"/var/www/localhost/htdocs/">
Order allow,deny
Allow from all
ServerName www.example.com
ServerName www.lxbing.com
ServerName www.example2.com
DocumentRoot "/var/www/localhost/htdocs/"ProxyPass /xwiki http://192.168.0.136:8081/xwiki
ProxyPassReverse /xwiki http://192.168.0.136:8081/xwikiProxyPass /example http://192.168.0.136:8082/example
ProxyPassReverse /example http://192.168.0.136:8082/exampleProxyPass /example2 http://192.168.0.136:8080/example2
ProxyPassReverse /example2 http://192.168.0.136:8080/example2
ProxyPass told apache to delive url-request (example:http://192.168.0.136/xwiki) to tomcat,which is listenning different port,corresponding to different applications in tomcat. Above is my configuration in my apache and tomcat for testing, and below is offical configuration, it defined different virtual-host in individual node:
Server configuration
# Ensure that Apache listens on port 80
Listen 80# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
DocumentRoot /www/example1
ServerName www.example1.com# Other directives here
DocumentRoot /www/example2
ServerName www.example2.org# Other directives here
At beginning, I config follow the offical document,but it allways only listen the frist vistual host. so I config them in a single visturalhost node.it works well. when you configging, please take care for to port, and the NameVirtualHost key word. NamevirtualHost must be same as VirtualHost,and don't to loss "NameVirtualHost" keyword.
NameVirtualHost *:80or
NameVirtualHost www.****.com
After finish these config ,reboot apache and tomcat. you can visit the applications via proxy server apache.like this http://192.168.0.136/xwiki, it autom turn to wwww.lxbing.com/xwiki. it works well.
multiple proxy-servers for handling remote request for application in individual pc
if there are multiple application in differnt computers, and a single Apache in a computer communicate to DNS, a request for a application in the other computer, what can we do? in this case, we have deliver the request from one proxy server to the other proxy server, to bring it into effect ,we must config the subproxy server frist, then config main proxy server to listen subproxy server. the mothod of configuration for subproxy is the similar with whan I references before. Now we are focus on the configuration of main proxy server.
In this example of totoring, we have three servers,main proxy server:192.168.0.9 with apache communicating to DNS, subproxy server: 192.168.0.136 with a application xwiki (we do the proxy before with it),192.168.0.4 with a application tsalex.
- defined the domain name in the DNS server in 192.168.09 server. config file //192.168.0.9/etc/hosts like this
192.168.0.4 www.alexcaro.com
192.168.0.9 www.xiancaro.com
192.168.0.136 www.lxbing.com
- config file 00_defined_vhost.conf in file //192.168.0.9/etc/apache2/vhosts.d, of course, apache in main server must contains the necessary module reference as above,if not, upload it. After configuration,the virtualhost node looks like follow:
NameVirtualHost *:80
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
var/www/localhost/htdocs>
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
ProxyRequests Off
ProxyVia OnProxyPass /tsalex http://www.alexcaro.com/tsalex
ProxyPass /xwiki http://www.lxbing.com/xwiki
DocumentRoot /var/www/localhost/htdocs
DirectoryIndex index.php index.html index.htm
LogLevel warn
HostNameLookups off
when a request to main proxy server apache in server 192.168.0.9 with a contents /tsalex, the main proxy server delived it to subproxy server apache 192.168.0.4 (domain name www.alexcaro.com) and reply http://www.alexcaro.com/tsalex to the request. if a request with content is /xwiki, it will be turned to subproxy server in 192.168.0.136 and return http://www.lxbing.com/xwiki.
mod_proy module
This module implements a proxy/gateway for Apache. It implements proxying capability for FTP, CONNECT (for SSL), HTTP/0.9, HTTP/1.0, and HTTP/1.1. The module can be configured to connect to other proxy modules for these and other protocols.
Apache's proxy features are divided into several modules in addition to mod_proxy: mod_proxy_http, mod_proxy_ftp and mod_proxy_connect. Thus, if you want to use one or more of the particular proxy functions, load mod_proxy and the appropriate module(s) into the server (either statically at compile-time or dynamically via the LoadModule directive).
In addition, extended features are provided by other modules. Caching is provided by mod_cache and related modules. The ability to contact remote servers using the SSL/TLS protocol is provided by the SSLProxy* directives of mod_ssl. These additional modules will need to be loaded and configured to take advantage of these features.
http://httpd.apache.org/docs/2.0/mod/mod_proxy.html
http://lamp.linux.gov.cn/Apache/ApacheMenu/mod/mod_proxy.html
IP-based
I am configuration for testing only using Host-based, and the other way is Ip-based alse can implement virtual host. As the term IP-based indicates, the server must have a different IP address for each IP-based virtual host. This can be achieved by the machine having several physical network connections, or by use of virtual interfaces which are supported by most modern operating systems (see offical documentation for details, these are frequently called "ip aliases", and the "ifconfig" command is most commonly used to set them up).if you want to know more about that, please see:http://httpd.apache.org/docs/2.0/vhosts/ip-based.html
http://www.apacheweek.com/features/vhost
http://apache.active-venture.com/vhosts/ip-based.html
mod_jk
Virtual host is a way to connect apache with tomcat,and there is a other way we reference above - mod_jk,the connecting of application /tsalex in server 192.168.0.4 is made with mod_jk(made by alexandria group in xiancaro).mod_jk is a replacement to the elderly mod_jserv. It is a completely new Tomcat-Apache plug-in that handles the communication between Tomcat and Apache. if any one want to know more about it ,please seeoffical mod_jk documnt
for finishing the configuration,I accept some help from others ,thanks to haitao jiang,jim and members of alexandria. the documents below you can consult, if you have interesting in doing the configuration work
http://lamp.linux.gov.cn/Apache/ApacheMenu/index.html
http://tomcat.jaxwiki.org/proxy-howto.html
http://httpd.apache.org/docs/1.3/vhosts/ip-based.html
http://httpd.apache.org/docs/2.0/vhosts/examples.html
Posted by
Bean
at
03:59
0
comments
gentoo liux portage的同步
gentoo中很多工具都是通portage中的境象文件与相应站点联系起来的,你可以通过emerge命令自动完成"下载工具的源代码-编译-生成可执 行文件-安装" 这一系列动作.而随着时间的进展,可能官方站点对portage中的文件进行了更新,你本机上的portage如果未能和其同步,在你试图从新安装工具 时,可能会遇到麻烦,或是无法安装新版本的工具.
gentoo 系统中/etc/make.conf文件中设定了同步
# These settings were set by the catalyst build script that automatically built this stage
# Please consult /etc/make.conf.example for a more detailed example
CFLAGS="-march=athlon-xp -O2 -pipe -fomit-frame-pointer"
CHOST="i686-pc-linux-gnu"
CXXFLAGS="${CFLAGS}"
USE="X -xdm -kdm kde qt alsa hal -gnome gtk curl eds java -ldap -mozilla -nas xml2 zlib"
#MAKEOPTS="-j21"
#FEATURES="distcc buildpkg"
#CCACHE_SIZE="2G"
#DISTCC_DIR="/tmp/distcc"
LINGUAS="zh_CN hy"
SYNC="rsync://rsync.namerica.gentoo.org/gentoo-portage"
RSYNC_EXCLUDEFROM="/etc/portage/rsync_excludes"
这 里设定本机portage与官方站点同步,你也可以设定与局域网内某台机器同步,最好是网内的机器和服务器同步,服务器与官方站点同步,这样更新 portage相对比较快,因为如果网速较慢各台机子都与站点同步,更新起来很慢,如果只要服务器与官方站点同步,随时保持服务器上的portage是最 新的,网内的机器就可以随时快速更新portage了.
网内的机子要与其他机子同步,只需修改:SYNC="rsync://rsync.namerica.gentoo.org/gentoo-portage"
SYNC="rsync://192.168.0.xxx/gentoo-portage"
然后执行命令:
#emerge sync
Posted by
Bean
at
03:58
0
comments
linux下mysql数据库服务器远程访问问题
前些日子,在gentoo下部署了一个j2ee项目:在两天独立的主机上部署OpenCms,一台做应用服务器,另一台做数据库服务器.我的环境是 jdk5.0+tomcat5+mysql4.1.以前多次在一台主机上做过opencms的部署,很顺手! 在两台主机上安装还是头一次,本想应该没什么难度,但是在链接mysql数据库时老是无法链接到远程机,原来默认情况下mysql安装中为了安全因素,没 有赋予root用户远程访问权限,必须为mysql手动创建一个远程访问用户,然后通过次用户的参数实现opencms远程链接mysql .
首先,以root进入mysql,创建远程访问用户remote,这个用户除了有远程访问权限外,还据有于root相同的其他权限.
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 67 to server version: 4.0.18
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
mysql> GRANT ALL ON *.* TO remote@'%' IDENTIFIED BY 'secret' WITH GRANT OPTION;
Query OK, 0 rows affected (0.04 sec)
mysql>
然后些改mysql配置文件让它监听外部ip端口,些改 /etc/mysql/my.cnf 文件中的一下部分:
# keep secure by default!
bind-address = 127.0.0.1
port = 3306
把 bind-address改为本机的实际ip.
详细信息请参考http://forums.gentoo.org/viewtopic-t-365627-highlight-connect+mysql+remote+client.html
Posted by
Bean
at
03:56
0
comments