一、配置glassfish环境变量
1、vi /gfv3/glassfish/config/asenv.conf
AS_JAVA="/usr/local/jdk"
2、 配置系统jdk环境
vi /etc/profile
HOSTNAME=`/bin/hostname`
HISTSIZE=1000
if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
INPUTRC=/etc/inputrc
fi
JAVA_HOME=/usr/local/jdk
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC HISTCONTROL
[gf1@dmgr bin]$ source /etc/profile
二、das
[gf1@dmgr bin]$ chown -R was1.gfgroup /g*
[gf1@dmgr bin]$ chmod 755 -R /g*
[gf1@dmgr bin]$ vim /gfv3/glassfish/config/asenv.conf
AS_JAVA="/usr/local/jdk"
[gf1@dmgr bin]$ ./asadmin create-domain --adminport 6862 --domaindir /glassfish dmgr
[gf1@dmgr bin]$ ./asadmin start-domain --domaindir /glassfish
[gf1@dmgr bin]$ ./asadmin --host 10.10.230.238 --port 6862 enable-secure-admin
[gf1@dmgr bin]$ ./asadmin --host 10.10.230.238 --port 6862 change-admin-password
[gf1@dmgr bin]$ ./asadmin stop-domain --domaindir /glassfish
[gf1@dmgr bin]$ ./asadmin delete-domain domain1
[gf1@dmgr bin]$ ./asadmin start-domain --domaindir /glassfish
密码保存到文件后的启动方法*****
[was1@dm02 bin]$./asadmin --host 10.10.230.238 --port 6862 --user admin --passwordfile gfpass stop-domain --domaindir /glassfish/
[was1@dm02 bin]$./asadmin --host 10.10.230.238 --port 6862 --user admin --passwordfile gfpass start-domain --domaindir /glassfish/
三、das与agent间通信
1、创建认证
[gf1@mg_htl_01 bin]$ ssh-keygen -t rsa
[gf1@mg_htl_01 bin]$ ssh-copy-id -i /home/was1/.ssh/id_rsa.pub [email protected]
四、控制台上建立集群
1、建立集群: dm02c01
./asadmin --host 10.10.230.238 --port 6862 create-cluster dm02c01
2、在机器A host1(或控制台)上先后执行
◆建立nodeagent: dm02n01s01
./asadmin --host 10.10.230.238 --port 6862 create-node-ssh --nodehost 10.10.230.220 --nodedir /glassfish dm02n01s01
◆在集群 dm02c01,节点dm02n01s01上建立instance : dm02c01s01
./asadmin --host 10.10.230.238 --port 6862 create-instance--nodeagent dm02n01s01 --cluster dm02c01 dm02c01s01
◆./asadmin --host 10.10.230.238 --port 6862 start-instance dm02c01s01
◆./asadmin --host 10.10.230.238 --port 6862 stop-instance dm02c01s01
3、在机器B host2(或控制台)上先后执行
◆建立nodeagent: dm02n01s02
./asadmin --host 10.10.230.238 --port 6862 create-node-ssh --nodehost 10.10.230.220 --nodedir /glassfish dm02n01s02
◆在集群 dm02c01,节点dm02n01s02上建立instance : dm02c01s02
./asadmin --host 10.10.230.238 --port 6862 create-instance --nodeagent dm02n01s02 --cluster dm02c01 dm02c01s02
◆./asadmin --host 10.10.230.238 --port 6862 start-instance dm02c01s02
◆./asadmin --host 10.10.230.238 --port 6862 stop-instance dm02c01s02
四、Enable mod_jk
./asadmin --host 10.10.230.238 --port 6862 create-network-listener --target dm02c01-config --protocol http-listener-1 --listenerport ${AJP_PORT} --jkenabled true jk_lsrn
./asadmin --host 10.10.230.238 --port 6862 create-jvm-options --target dm02c01-config "-DjvmRoute=\${AJP_INSTANCE_NAME}"
./asadmin --host 10.10.230.238 --port 6862 create-threadpool --minthreadpoolsize 5 --maxthreadppplsize 150 jk-thread-pool
./asadmin --host 10.10.230.238 --port 6862 create-system-properties --target dm02c01s01 AJP_PORT=8011
./asadmin --host 10.10.230.238 --port 6862 create-system-properties --target dm02c01s01 AJP_INSTANCE_NAME=dm02c01s01
./asadmin --host 10.10.230.238 --port 6862 create-system-properties --target dm02c01s02 AJP_PORT=8011
./asadmin --host 10.10.230.238 --port 6862 create-system-properties --target dm02c01s02 AJP_INSTANCE_NAME=dm02c01s02
AJP_INSTANCE_NAME(不在实例属性增加也可以)
AJP_PORT(不在实例属性增加也可以)
不用组播我刚才配通了,dm01c06,在集群属性里加上 GMS_LISTENER_PORT 29096和 GMS_DISCOVERY_URI_LIST generate 就可以了。
在日志里有如下信息:
[#|2014-04-29T12:18:50.361+0800|INFO|glassfish3.1.2|ShoalLogger|_ThreadID=16;_ThreadName=Thread-2;|GMS1092: GMS View Change Received for group: dm01c06 : Members in view for ADD_EVENT(before change analysis) are :
1: MemberId: dm01c06s01, MemberType: CORE, Address: 10.10.12.31:29096:228.9.117.241:14513:dm01c06:dm01c06s01
2: MemberId: dm01c06s02, MemberType: CORE, Address: 10.10.12.51:29096:228.9.117.241:14513:dm01c06:dm01c06s02
测试地址:http://10.10.5.163/cluster/HaJsp.jsp
GMS可以用以下2种方式:
1、UDP组播
If GMS should use UDP multicast for broadcasting messages and if GlassFish Server
instances in a cluster are located on different hosts, the following conditions must be
met:
■ The DAS host and all hosts for the instances must be on the same subnet.
■ UDP multicast must be enabled for the network. To test whether multicast is
enabled, use the validate-multicast(1) subcommand.
2、自动发现集群
If GMS should use TCP without multicast, you must configure GMS to locate the
instances to use for discovering the cluster. For more information, see Discovering a
Cluster When Multicast Transport Is Unavailable.
五、部署应用的4种方式
1、可以直接将war或ear放在glassfishdomain/domain1/autodeploy目录下,glassfish启动后会自动部署
2、是通过命令asadmin deploy部署应用, 另外 asadmin updeploy 卸载应用
通过asadmin deploy --help 和 asadmin undeploy --help 获得更多帮助
3、通过glassfish管理控制台
4、目录部属方式:即将WEB应用目录直接copy到glassfishdomains/domain1/applications/下
然后通过命令:glassfishbin/asadmin deploydir full_path/applications/your_app
指定集群部署:
./asadmin --host 10.10.230.238 --port 6862 --user admin --passwordfile gfpass deploy --target dm02c01 /glassfish/dmgr/autodeploy/hello.war
取消部署:
[was1@dm02 bin]$ ./asadmin --host 10.10.230.238 --port 6862 --user admin --passwordfile gfpass undeploy --target dm02c01 hello
六、集群操作指令
[was1@dm02 bin]$ ./asadmin --host 10.10.230.238 --port 6862 --user admin --passwordfile gfpass stop-cluster dm02c01
[was1@dm02 bin]$ ./asadmin --host 10.10.230.238 --port 6862 --user admin --passwordfile gfpass start-cluster dm02c01
七、apache安装
[root@apache-dmgr conf]# cat ../build/config.nice
"./configure" "--prefix=/usr/local/apache2" "--enable-proxy" "--enable-rewrite" "--with-apr=/usr/local/apr" "--with-apr-util=/usr/local/apr-util" "--enable-so" "--enable-speling" "--enable-exception-hook" "--enable-proxy-http" "--enable-proxy-ajp" "--enable-headers" "--enable-deflate" "--enable-ssl" "--enable-usertrack"
配置apache的配置文件httpd.conf:
#LoadModule rewrite_module modules/mod_rewrite.so
#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule usertrack_module modules/mod_usertrack.so
MOD_JK代理apache:
[root@apache-dmgr conf]# vim ./httpd.conf
<IfModule mod_usertrack.c>
CookieTracking on
CookieDomain .mangocity.com
CookieExpires "1 weeks"
CookieName SessionID
CookieStyle Cookie
</IfModule>
LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/work7118.properties
JkLogFile logs/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
#options
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"
JkMountCopy ALL
JkMount /ceshi/* dm02c01
JkMount /cluster/* dm02c01
[root@pingtai-test2 modules]# vim /usr/local/apache_jk/conf/work7118.properties
worker.list=dm02c04,dm02c12
worker.dm02c04s03.type=ajp13
worker.dm02c04s03.host=10.10.12.62
worker.dm02c04s03.port=8014
worker.dm02c04s03.lbfactor=50
worker.dm02c04s03.socket_keepalive=true
worker.dm02c04s03.socket_timeout=90
worker.dm02c04s04.type=ajp13
worker.dm02c04s04.host=10.10.12.82
worker.dm02c04s04.port=8014
worker.dm02c04s04.lbfactor=50
worker.dm02c04s04.socket_keepalive=true
worker.dm02c04s04.socket_timeout=90
worker.dm02c04.type=lb
worker.dm02c04.sticky_session=1
worker.dm02c04.balance_workers=dm02c04s03,dm02c04s04
[root@pingtai-test2 modules]# vim /usr/local/apache_jk/conf/work7118.properties
worker.list=dm02c01,dm02c02
worker.dm02c01s01.type=ajp13
worker.dm02c01s01.host=10.10.35.194
worker.dm02c01s01.port=8011
worker.dm02c01s01.socket_keepalive=1
worker.dm02c01s01.socket_connect_timeout=10000
worker.dm02c01s01.lbfactor=50
worker.dm02c01s01.connection_pool_timeout=3600
worker.dm02c01s01.connection_pool_size=2560
worker.dm02c01s01.connect_timeout=3000
worker.dm02c01s01.reply_timeout=0
worker.dm02c01s01.ping_mode=A
worker.dm02c01s01.ping_timeout=10000
worker.dm02c01s02.type=ajp13
worker.dm02c01s02.host=10.10.35.197
worker.dm02c01s02.port=8011
worker.dm02c01s02.socket_keepalive=1
worker.dm02c01s02.socket_connect_timeout=10000
worker.dm02c01s02.lbfactor=50
worker.dm02c01s02.connection_pool_timeout=3600
worker.dm02c01s02.connection_pool_size=2560
worker.dm02c01s02.connect_timeout=3000
worker.dm02c01s02.reply_timeout=0
worker.dm02c01s02.ping_mode=A
worker.dm02c01s02.ping_timeout=10000
worker.dm02c01.type=lb
worker.dm02c01.balance_workers=dm02c01s01,dm02c01s02
worker.dm02c01.sticky_session=1
worker.dm02c01.sticky_session_force=0
worker.dm02c01.method=N
worker.retries=3
worker.dm02c01.session_cookie=JSESSIONID
worker.status.type=status
worker.dm02c02s01.type=ajp13
worker.dm02c02s01.host=10.10.35.194
worker.dm02c02s01.port=8012
worker.dm02c02s01.socket_keepalive=1
worker.dm02c02s01.socket_connect_timeout=10000
worker.dm02c02s01.lbfactor=50
worker.dm02c02s01.connection_pool_timeout=3600
worker.dm02c02s01.connection_pool_size=2560
worker.dm02c02s01.connect_timeout=3000
worker.dm02c02s01.reply_timeout=0
worker.dm02c02s01.ping_mode=A
worker.dm02c02s01.ping_timeout=10000
worker.dm02c02s02.type=ajp13
worker.dm02c02s02.host=10.10.35.197
worker.dm02c02s02.port=8012
worker.dm02c02s02.socket_keepalive=1
worker.dm02c02s02.socket_connect_timeout=10000
worker.dm02c02s02.lbfactor=50
worker.dm02c02s02.connection_pool_timeout=3600
worker.dm02c02s02.connection_pool_size=2560
worker.dm02c02s02.connect_timeout=3000
worker.dm02c02s02.reply_timeout=0
worker.dm02c02s02.ping_mode=A
worker.dm02c02s02.ping_timeout=10000
worker.dm02c02.type=lb
worker.dm02c02.balance_workers=dm02c02s01,dm02c02s02
worker.dm02c02.sticky_session=1
worker.dm02c02.sticky_session_force=0
worker.dm02c02.method=N
worker.retries=3
worker.dm02c02.session_cookie=JSESSIONID
worker.status.type=status
备注:
创建并配置workers.properties文件
vi /usr/local/apache2/conf/workers.properties
worker.list=wlb , jkstatus
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13
worker.worker1.lbfactor=1
# Define preferred failover node for worker1
#worker.worker1.redirect=worker2
worker.worker2.port=8909
worker.worker2.host=localhost
worker.worker2.type=ajp13
worker.worker2.lbfactor=1
# Disable worker2 for all requests except failover
#worker.worker2.activation=disabled
worker.wlb.type=lb
worker.wlb.balance_workers=worker1,worker2
worker.jkstatus.type=status
以上注释掉的两行如果开启,则worker2成为worker1的备用,在worker1不可用的情况下才会向worker2请求
VHOSTS代理服务器:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/var/www/html"
ServerName mpmweb.mangocity.com
ErrorLog logs/mpmweb.com-error_log
CustomLog logs/mpmweb.com-access_log combined
CustomLog "|/usr/sbin/rotatelogs /var/log/httpd/mpmweb.mangocity.com-access_log-%Y-%m-%d 86400 480" combined
RewriteEngine on
RewriteRule ^/(.*) http://10.10.7.118/cluster/$1 [P,L]
ProxyPreserveHost On
ProxyPassReverseCookiePath /cluster /
</VirtualHost>
mod_JK:
[root@pingtai-test2 apache-2.0]# yum install libtool
[root@pingtai-test2 apache-2.0]# ln -s /usr/bin/libtool /usr/local/apache_jk/build/libtool
[root@pingtai-test2 opt]# cd ./tomcat-connectors-1.2.37-src/native/
[root@pingtai-test2 native]# ./buildconf.sh
[root@pingtai-test2 apache-2.0]# ./configure --with-apxs=/usr/local/apache_jk/bin/apxs
[root@pingtai-test2 apache-2.0]# make
[root@pingtai-test2 apache-2.0]# pwd
/opt/tomcat-connectors-1.2.37-src/native/apache-2.0
[root@pingtai-test2 apache-2.0]# ./configure --with-apxs=/usr/local/apache_jk/bin/apxs
You have new mail in /var/spool/mail/root
八、修改控制台登陆密码
进入控制台后选择常见任务下的“域”--"管理员口令"
九、证书安装
[was1@pingtai-test2 config]$ /usr/local/jdk/bin/keytool -import -alias cmpay_ipos10086cn -keystore cacerts.jks -file /tmp/10086.cer
[was1@pingtai-test2 config]$ /usr/local/jdk/bin/keytool -list -keystore cacerts.jks
十、web应用修改参数
描述符文件名:
|
WEB-INF/glassfish-web.xml
|
|
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd"> <glassfish-web-app> <context-root>/MpmWeb</context-root> <session-config> <session-manager persistence-type="replicated"> <manager-properties> <property name="persistenceFrequency" value="web-method"/> <property name="reapIntervalSeconds" value="30"/> <property name="relaxCacheVersionSemantics" value="true"/> </manager-properties> <store-properties> <property name="persistenceScope" value="session"/> </store-properties> </session-manager> </session-config> <parameter-encoding default-charset="UTF-8" /> </glassfish-web-app>
|
描述符文件名:
|
WEB-INF/web.xml
|
|
<?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <display-name>essServer</display-name> <distributable/> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/spring-configuration/*.xml /WEB-INF/deployerConfigContext.xml </param-value> </context-param> <!-- place this into the contextConfigLocation to enable remote services /WEB-INF/remoteServices.xml, classpath:org/codehaus/xfire/spring/xfire.xml place this into the contextConfigLocation to enable the event publishing --> <!-- - Location of the Log4J config file, for initialization and refresh checks. - Applied by Log4jConfigListener. --> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>classpath:log4j.properties</param-value> </context-param> <context-param> <param-name>log4jExposeWebAppRoot</param-name> <param-value>false</param-value> </context-param> <context-param> <param-name>edu.yale.its.tp.cas.serviceTimeout</param-name> <param-value>30</param-value> </context-param> <filter> <filter-name>CAS Client Info Logging Filter</filter-name> <filter-class>org.inspektr.common.web.ClientInfoThreadLocalFilter</filter-class> </filter> <filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>springSecurityFilterChain</filter-name> <url-pattern>/services/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>CAS Client Info Logging Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- - Configures Log4J for this web app. - As this context specifies a context-param "log4jConfigLocation", its file path - is used to load the Log4J configuration, including periodic refresh checks. - - Would fall back to default Log4J initialization (non-refreshing) if no special - context-params are given. - - Exports a "web app root key", i.e. a system property that specifies the root - directory of this web app, for usage in log file paths. - This web app specifies "cas.root" (see log4j.properties file). --> <!-- Leave the listener commented-out if using JBoss --> <listener> <listener-class> org.springframework.web.util.Log4jConfigListener </listener-class> </listener> <!-- - Loads the CAS ApplicationContext. - The deployer choice here is how to handle Throwables thrown by Spring's - ContextLoaderListener. The Spring ContextLoaderListener will throw an exception when the - application context cannot be loaded, say because the bean XML files are not valid XML or do not - refer to real classes and properties or because a bean configured via Spring throws an exception - at construction, property setting, or on an afterPropertiesSet() lifecycle method. - - If you'd like these errors to be fatal and prevent the CAS servlet context from loading at all, - use org.springframework.web.context.ContextLoaderListener. - - If you'd like these errors to result in all requests for CAS getting a "CAS is Unavailable" response, - use org.jasig.cas.web.init.SafeContextLoaderListener --> <listener> <listener-class> org.jasig.cas.web.init.SafeContextLoaderListener </listener-class> </listener> <!-- - This is the Spring dispatcher servlet which delegates all requests to the - Spring WebMVC controllers as configured in cas-servlet.xml. - - The choice made above about how to handle a broken ApplicationContext at - context initialization applies here as well, since this servlet is load-on-startup. - - If you'd like these errors to be fatal and prevent the CAS servlet from loading at all, - use org.springframework.web.servlet.DispatcherServlet. - - If you'd like these errors to result in all requests for CAS getting a "CAS is Unavailable" response, - use org.jasig.cas.web.init.SafeDispatcherServlet --> <servlet> <servlet-name>cas</servlet-name> <servlet-class> org.jasig.cas.web.init.SafeDispatcherServlet </servlet-class> <init-param> <param-name>publishContext</param-name> <param-value>false</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet> <servlet-name>restlet</servlet-name> <servlet-class>com.noelios.restlet.ext.spring.RestletFrameworkServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <!-- validate code : simplecaptcha <servlet> <servlet-name>SimpleCaptcha</servlet-name> <servlet-class>nl.captcha.servlet.SimpleCaptchaServlet</servlet-class> <init-param> <param-name>width</param-name> <param-value>200</param-value> </init-param> <init-param> <param-name>height</param-name> <param-value>60</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>SimpleCaptcha</servlet-name> <url-pattern>/validateCodeImg</url-pattern> </servlet-mapping> --> <servlet> <servlet-name>captchaServlet</servlet-name> <servlet-class> org.mangocube.cas.web.captcha.DelegatingServletProxy </servlet-class> <init-param> <param-name>targetServletBean</param-name> <param-value>captchaServlet</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>restlet</servlet-name> <url-pattern>/v1/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>captchaServlet</servlet-name> <url-pattern>/validateCodeImg</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>cas</servlet-name> <url-pattern>/login</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>cas</servlet-name> <url-pattern>/logout</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>cas</servlet-name> <url-pattern>/validate</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>cas</servlet-name> <url-pattern>/serviceValidate</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>cas</servlet-name> <url-pattern>/samlValidate</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>cas</servlet-name> <url-pattern>/proxy</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>cas</servlet-name> <url-pattern>/proxyValidate</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>cas</servlet-name> <url-pattern>/CentralAuthenticationService</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>cas</servlet-name> <url-pattern>/services/add.html</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>cas</servlet-name> <url-pattern>/services/viewStatistics.html</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>cas</servlet-name> <url-pattern>/services/logout.html</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>cas</servlet-name> <url-pattern>/services/loggedOut.html</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>cas</servlet-name> <url-pattern>/services/manage.html</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>cas</servlet-name> <url-pattern>/services/edit.html</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>cas</servlet-name> <url-pattern>/openid/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>cas</servlet-name> <url-pattern>/services/deleteRegisteredService.html</url-pattern> </servlet-mapping> <session-config> <!-- Default to 5 minute session timeouts --> <session-timeout>5</session-timeout> </session-config> <error-page> <exception-type>org.springframework.context.ApplicationContextException</exception-type> <location>/WEB-INF/view/jsp/brokenContext.jsp</location> </error-page> <error-page> <error-code>500</error-code> <location>/WEB-INF/view/jsp/errors.jsp</location> </error-page> <error-page> <error-code>404</error-code> <location>/</location> </error-page> <error-page> <error-code>403</error-code> <location>/WEB-INF/view/jsp/default/ui/casBlockedView.jsp</location> </error-page> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app>
|