Struts 2 Customize Theme & Freemarker Template 客制佈景與模板 說明了Struts2 的 tags 是可以自行客制成自已想要的佈景,現在來說明如何使用 FreeMarker 來制作 Struts2 屬於自已建作的 tag libs.

工具:

eclipse : Version: Mars Release (4.5.0) Build id: 20150621-1200

pom.xml:

struts2-core: 2.5.8

struts-annotations: 1.0.5 (不可以用 1.0.6 會出現 tlibVersion Missing 的錯誤)

commons-logging: 1.2

jsp-api : 2.2

javax.servlet-api : 4.0.1

 

Step 01:  建立一個空的 maven project

tag_01

tag_02

 

Step 02: 建立客制的 class: HtmlTag.java 在 package com.easyui.struts2.views.jsp.ui 下

package com.easyui.struts2.views.jsp.ui;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.components.Component;
import org.apache.struts2.views.jsp.ui.AbstractClosingTag;

import com.easyui.struts2.components.Html;
import com.opensymphony.xwork2.util.ValueStack;

public class HtmlTag extends AbstractClosingTag {

    @Override
    public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
        
        return new Html(stack, req, res);
    }

}

 

Step 03 : 建立客制的 class: Html.java 在 package com.easyui.struts2.components , 此檔主要是要產生 .tld 的標籤描述檔, 以及告訴 freemarker 要讀取那一個 ftl , 此範例是要有 html.ftl 與 html-close.ftl 這兩個檔案.

package com.easyui.struts2.components;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.components.ClosingUIBean;
import org.apache.struts2.views.annotations.StrutsTag;

import com.opensymphony.xwork2.util.ValueStack;

@StrutsTag(
        name="html",
        tldTagClass="com.easyui.struts2.views.jsp.ui.HtmlTag",
        description="建立一個空的 HTML 結構",
        allowDynamicAttributes=true)
public class Html extends ClosingUIBean {

    public Html(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
        super(stack, request, response);
        
    }

    @Override
    public String getDefaultOpenTemplate() {        
        return "html";
    }

    @Override
    protected String getDefaultTemplate() {        
        return "html-close";
    }

}

註:

1. 在 pom.xml 中需加入 struts-annotations: 1.0.5 才可以使用 annotations 描述

2. @StrutsTag: annotation for marking a Struts tag
3. @StrutsTagAttribute: annotation for marking an attribute of a Struts tag

 

Step 04: 建立此 tags (標籤) 的 templates & theme

1. 建立 package: template.easyui 並撰寫 html.ftl 與 html-close.ftl

2. 建立 空的 package: template.easyui.html 用來存放 Tobago plugin 自動產生的相關樣版檔案

html.ftl 檔

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>${parameters.title}</title>  
</head>
<body>

 

html-close.ftl 檔


</body>
</html>

 

Step 05: 用 Tobago plugin  建立 TLD file 及使用 Maven 產生這個 taglib 的 jar 檔

請看附註二

 

Step 06: 佈署 (Deploy taglib in your Web application) , 將這個 taglib 的 jar 檔放在 WEB-INF/lib 下

記得要在 struts.xml 裡加入 <constant name="struts.ui.theme" value="easyui"/> , 這樣才會去讀取 JAR 檔 template.easyui 裡的 ftl 檔案

 

Step 07: JSP 裡使用客製的 tag libs

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="i" uri="/esayui-tags" %>

<i:html title="Basic Layout - jQuery EasyUI Demo">

hi easyui-tags

    <s:form action="Login">
        <s:textfield key="username"/>
        <s:password key="password" />
        <s:submit/>
    </s:form>


</i:html>

 

附註:

一、 Struts2 taglibs Introduction

Few words about the elements of the Struts2 UI component framework should help to understand better the scenario.

JSP Tag: implementation of the JSP tag (e.g TextFieldTag). Notice Struts2 has also Velocity and FreeMarker tags

UI Component: actual implementation of the behavior of the component (e.g TextField)

Template: FreeMarker template which renders the html markup (e.g. <input type=”text”….)

Theme: collection of templates (e.g. simple or ajax)

 

二、整個專案結構如下

tag_03  

註:

1. 在 pom.xml 中需加入 tobago 描述, 才會自動產生目錄: src/main/resources/META-INF 的 easyui-tags.tld 描述檔及 package: template.easyui.html 裡的 html.html

2. 目前 的編譯器 complier 需用 JDK 1.7.x 版才會成功,   JDK1.8.x 會無法產生 easyui-tags.tld 描述檔 及相關的樣版檔

tag_04  

3. Tobago plugin 在 pom.xml 的設定如下:

<plugin>
    <groupId>org.apache.myfaces.tobago</groupId>
    <artifactId>maven-apt-plugin</artifactId>                            
    <configuration>
        <A>
                   uri=/esayui-tags,tlibVersion=${project.version},jspVersion=2.0,shortName=easyui,displayName="EasyUI Tags",
                   outFile=${basedir}/src/main/resources/META-INF/${project.artifactId}.tld,
                   description="EasyUI Tags",
                   outTemplatesDir=${basedir}/src/main/java/template/easyui/html                
        </A>
        <resourceTargetPath>target</resourceTargetPath>
        <fork>false</fork>
        <force>true</force>
        <nocompile>true</nocompile>
        <showWarnings>true</showWarnings>
        <factory>
            org.apache.struts.annotations.taglib.apt.TLDAnnotationProcessorFactory
        </factory>
        <target>1.5</target>
        <includes>
            <include>**/*.java</include>
        </includes>
    </configuration>
    <executions>
        <execution>
            <phase>compile</phase>
            <goals>
                <goal>execute</goal>
            </goals>
        </execution>
    </executions>
</plugin>

 


 三、 完整的 pom.xml 檔

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.gu.apps</groupId>
  <artifactId>easyui-tags</artifactId>
  <version>1.0-SNAPSHOT</version>
  <name>easyui-tags</name>
  <dependencies>
      <dependency>
          <groupId>org.apache.struts</groupId>
          <artifactId>struts2-core</artifactId>
          <version>2.3.24.1</version>
      </dependency>
      <dependency>
          <groupId>org.apache.struts</groupId>
          <artifactId>struts-annotations</artifactId>
          <version>1.0.5</version>
      </dependency>
      <dependency>
          <groupId>commons-logging</groupId>
          <artifactId>commons-logging</artifactId>
          <version>1.2</version>
      </dependency>
      <dependency>
          <groupId>javax.servlet.jsp</groupId>
          <artifactId>jsp-api</artifactId>
          <version>2.1</version>
      </dependency>
      <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>javax.servlet-api</artifactId>
          <version>3.1.0</version>
      </dependency>
  </dependencies>
  <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
 
  <build>
      <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <encoding>UTF-8</encoding>
                <source>1.5</source>
                <target>1.5</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.myfaces.tobago</groupId>
            <artifactId>maven-apt-plugin</artifactId>                            
            <configuration>
                <A>
                       uri=/esayui-tags,tlibVersion=${project.version},jspVersion=2.0,shortName=easyui,displayName="EasyUI Tags",
                       outFile=${basedir}/src/main/resources/META-INF/${project.artifactId}.tld,
                       description="EasyUI Tags",
                       outTemplatesDir=${basedir}/src/main/java/template/easyui/html                
                </A>
                <resourceTargetPath>target</resourceTargetPath>
                <fork>false</fork>
                <force>true</force>
                <nocompile>true</nocompile>
                <showWarnings>true</showWarnings>
                <factory>
                    org.apache.struts.annotations.taglib.apt.TLDAnnotationProcessorFactory
                </factory>
                <target>1.5</target>
                <includes>
                    <include>**/*.java</include>
                </includes>
            </configuration>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>execute</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>        
      </plugins>
    <resources>
           <resource>
               <directory>src/main/java</directory>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>               
           </resource>
           <resource>
               <directory>src/main/resources</directory>
           </resource>          
       </resources>    
      <finalName>easyui-tags</finalName>
      <defaultGoal>install</defaultGoal>
  </build>
</project>

 

 

參考:

https://bodez.wordpress.com/2009/03/13/customising-struts2-jsp-tags/

文章標籤

MIS 發表在 痞客邦 留言(0) 人氣()

Struts 2 使用 FreeMarker 來作模板(Template) ,預設的模板是 xhtml (可以解開 struts2-core-2.3.x.x.jar 取得),若要客制佈景(Theme)與模板(Template),需要下列幾個步驟。

預計想要達成的效果有

1. Freemarker Template 中可以使用 Struts 的 tag

2. Customize Theme 客製顏色佈景

 

一、Freemarker Template 中可以使用 Struts 的 tag 實作步驟:

Step 01:  解壓 struts2-core-2.3.x.x.jar 取得 struts-tags.tld 並放在專案(project)的 WEB-INF 下,整個專案目錄如下

struts2-freemarker  

 

Step 02: 修改 web.xml  ,加入 JspSupportServlet 配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="struts_blank" version="2.4"
         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">
  <display-name>Struts Blank-MIS</display-name>

  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>
      org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    </filter-class>
  </filter>

  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

    <servlet>  
        <servlet-name>JspSupportServlet</servlet-name>  
        <servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class>  
              <!--配置JspSupportServlet啟動-->  
        <load-on-startup>1</load-on-startup>  
    </servlet>  

  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
</web-app>

Step 03: 在 Freemarker Template 頁面,加入要使明的 taglib,這樣就可以在 template: fmLogin.ftl 中使用 struts2 內建的 tag 標籤,例:<@s.form action="Login.action">

<#assign s=JspTaglibs["/WEB-INF/struts-tags.tld"] />  
<html>  
<head>  
<title>登錄頁面</title>

<style type="text/css">
    .errorsBg{
        background-color:#fdd;
        color:red;    
        border: 1px solid;
    }
    
    .errorMessage{
        padding:0px 8px;
    }
    
    table{
        border-spacing: 4px;
    }
    td{
        padding:4px;
    }
</style>

</head>  
<body>  
    請輸入用戶名和密碼來登錄<br>  
    <@s.form action="Login.action">  
        <@s.textfield name="username" label="用戶名"/>  
        <@s.textfield name="password" label="密碼"/>  
        <@s.submit value="提交"/>  
    </@s.form>  
</body>  
</html>

 

二、 Customize Theme 客製顏色佈景,客制佈景以 polinwei 為例

Step 01: 建立 package: src/main/java/template/polinwei ,解壓 struts2-core-2.3.x.x.jar 取得 lib\struts2-core-2.3.24.1\template 下目錄 xhtml 的所有檔案放入此 polinwei 目錄下。

struts2-customize-theme  

Step 02: 在 struts.xml 定義要使用的 theme: struts.ui.theme 與 template 目錄: struts.ui.templateDir

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
        "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
    <constant name="struts.enable.DynamicMethodInvocation" value="false"/>
    <constant name="struts.devMode" value="true"/>

    <constant name="struts.ui.theme" value="polinwei" />
    <constant name="struts.ui.templateDir" value="template" />   

    <package name="demo" namespace="/demo" extends="struts-default">
        <action name="Login" class="com.demo.FMTestAction">
            <result name="input" type="freemarker">/WEB-INF/demo/fmLogin.ftl</result>
            <result name="success" type="freemarker">/WEB-INF/demo/fmLoginSuccess.ftl</result>
        </action>

    </package>

    <!-- Add addition packages and configuration here. -->

</struts>

 

Step 03: 開始客制佈景

a. Create a new error-message.ftl file to display the error message.

error-message.ftl

<#--
        Only show message if errors are available.
        This will be done if ActionSupport is used.
-->
<#assign hasFieldErrors = parameters.name?? && fieldErrors?? && fieldErrors[parameters.name]??/>
<#if hasFieldErrors>
<#list fieldErrors[parameters.name] as error>
   <span class="errorMessage" errorFor="${parameters.id}">${error?html}</span><#t/>
</#list>
</#if>

 

b. Modify the controlheader.ftl by adding a new “errorsBg” class to “td” tag if errors exists.

controlheader.ftl

<#include "/${parameters.templateDir}/polinwei/controlheader-core.ftl" />
    <td
<#if hasFieldErrors>
    class="errorsBg" <#t/>
</#if>
<#if parameters.align??>
    align="${parameters.align?html}"<#t/>
</#if>
><#t/>

 

c. Modify the controlheader-core.ftl by delete many unnecessary tags and add a new “errorsBg” class to “td” tag if errors exists.

controlheader-core.ftl

<#--
        Only show message if errors are available.
        This will be done if ActionSupport is used.
-->
<#assign hasFieldErrors = parameters.name?? && fieldErrors?? && fieldErrors[parameters.name]??/>
<#--
        if the label position is top,
        then give the label its own row in the table
-->
<tr>

<td class="tdLabel <#t/>
<#--
<#if hasFieldErrors>
errorsBg"<#t/>
</#if>
-->
><#rt/>

<#if parameters.label??>
    <label <#t/>
<#if parameters.id??>
        for="${parameters.id?html}" <#t/>
</#if>
<#if hasFieldErrors>
        class="errorLabel"<#t/>
<#else>
        class="label"<#t/>
</#if>
 ><#t/>

<#if parameters.required?default(false) && parameters.requiredposition?default("right") != 'right'>
    <span class="required">*</span><#t/>
</#if>
${parameters.label?html}<#t/>
<#if parameters.required?default(false) && parameters.requiredposition?default("right") == 'right'>
        <span class="required">*</span><#t/>
</#if>

</label><#t/>
</#if>

</td><#lt/>

 

d. Modify the text.ftl & password.ftl by adding a new template file “error-message.ftl” after the “simple/text.ftl“.

text.ftl

<#include "/${parameters.templateDir}/${parameters.theme}/controlheader.ftl" />
<#include "/${parameters.templateDir}/simple/text.ftl" />
<#include "/${parameters.templateDir}/polinwei/error-message.ftl" />
<#include "/${parameters.templateDir}/xhtml/controlfooter.ftl" />

password.ftl

<#include "/${parameters.templateDir}/${parameters.theme}/controlheader.ftl" />
<#include "/${parameters.templateDir}/simple/password.ftl" />
<#include "/${parameters.templateDir}/polinwei/error-message.ftl" />
<#include "/${parameters.templateDir}/xhtml/controlfooter.ftl" />

 

 

e. Put the CSS in your view page to format the error message.

<#assign s=JspTaglibs["/WEB-INF/struts-tags.tld"] />  
<html>  
<head>  
<title>登錄頁面</title>

<style type="text/css">
    .errorsBg{
        background-color:#fdd;
        color:red;    
        border: 1px solid;
    }
    
    .errorMessage{
        padding:0px 8px;
    }
    
    table{
        border-spacing: 4px;
    }
    td{
        padding:4px;
    }
</style>

</head>  
<body>  
    請輸入用戶名和密碼來登錄<br>  
    <@s.form action="Login.action">  
        <@s.textfield name="username" label="用戶名"/>  
        <@s.textfield name="password" label="密碼"/>  
        <@s.submit value="提交"/>  
    </@s.form>  
</body>  
</html> 

 

這樣就可以有自已客制的佈景了.

 

參考:

http://www.mkyong.com/struts2/working-with-struts-2-theme-template/

 

文章標籤

MIS 發表在 痞客邦 留言(0) 人氣()

上章 JBoss EAP6.x Domain Cluster + mod_cluster-1.2.6 Load Balancer 說完如何建構 EAP 的 cluster 後,再來說一下SSL;現在的網站與使用者間的資料傳輸安全性,大都已逐漸都加入了 SSL ,而企業級有很多網站,這時可以用 Wildcard SSL Certificate 更加有彈性, SSL 憑證的建置步驟大致如下圖:

 

ssl  

 

瞭解建置與使用步驟後,來實作一下,SSL 的憑證以 https://ssl.comodo.com/wildcard-ssl-certificates.p... 為例作示範

Step 01: 產生私鑰 Private Key,指令 openssl genrsa -out server.key 2048 (不對私鑰作密碼保護)

[root@eap-dev jboss]# pwd
/opt/jboss
[root@eap-dev jboss]# rpm -qa | grep openssl
openssl-1.0.1e-42.el7.x86_64
openssl-libs-1.0.1e-42.el7.x86_64

[root@eap-dev jboss]# openssl genrsa -out server.key 2048
Generating RSA private key, 2048 bit long modulus
............+++
...........................+++
e is 65537 (0x10001)

註:若 option 有加入 -des3 則代表要對私鑰作密碼保護如下

[root@eap-dev jboss]# openssl genrsa -des3 -out server.key 2048
Generating RSA private key, 2048 bit long modulus
....+++
.........+++
e is 65537 (0x10001)
Enter pass phrase for server.key:
Verifying - Enter pass phrase for server.key:

 server-key  

 

Step 02:產生CSR檔,並填入憑證資料,指令 openssl req –new –key server.key –out xxx.CSR

[root@eap-dev jboss]# openssl req -new -key server.key -out EAP-DEV.CSR
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:TW
State or Province Name (full name) []:Taiwan
Locality Name (eg, city) [Default City]:Taichung
Organization Name (eg, company) [Default Company Ltd]:xxxxxx Industrial Corp.
Organizational Unit Name (eg, section) []:Information Technology
Common Name (eg, your name or your server's hostname) []:*.xxxxxx.com
Email Address []:tech.admin@xxxxxx.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

 server-csr  
 

 產生的 CSR 內容,類似下圖

server-csr-content  

 

Step 03: 向CA: comodo.com 申請憑證

 Comodo-ssl-wildcard  

COMODO驗證成功後會收到 yourDomainName.crt 和 yourDomainName.ca-bundle 兩個檔案:

a.  Step 01: 產生私鑰 Private Key 的 server.key 複製到 /etc/ssl/ssl.key/ 

b. 由COMODO拿到的兩個檔案: STAR_yourDomainName.crtSTAR_yourDomainName.ca-bundle 複製到 /etc/ssl/ssl.crt/ 

 

以上三個步驟只要作一次即可,未來只要將這三個檔案: server.keySTAR_yourDomainName.crtSTAR_yourDomainName.ca-bundle 複製到其它主機內即可有 SSL 的保護。

 

Step 04: 修改/opt/jboss/httpd/httpd/conf/httpd.conf,打開註解 Include extra/httpd-ssl.conf,套用ssl 的設定檔。並修改extra/httpd-ssl.conf,修改以下資訊

Listen 443

<VirtualHost _default_:443>

#   SSL Engine Switch:
#   Enable/Disable SSL for this virtual host.
SSLEngine on

#   Server Certificate:
SSLCertificateFile "/etc/ssl/ssl.crt/STAR_xxxxxx_com.crt"

#   Server Private Key:
SSLCertificateKeyFile "/etc/ssl/ssl.key/server.key"

#   Server Certificate Chain:
SSLCertificateChainFile "/etc/ssl/ssl.crt/STAR_xxxxxx_com.ca-bundle"

</VirtualHost>

 

Step 04: 修改/opt/jboss/httpd/httpd/conf/httpd.conf,打開註解 Include extra/httpd-vhosts.conf,套用 vhosts 的設定檔。並修改extra/httpd-vhosts.conf,修改以下資訊

<VirtualHost *:80>
    ServerAdmin tech.admin@xxxxxx.com
    DocumentRoot "/opt/jboss/httpd/htdocs/htdocs"
    ServerName eap-dev.xxxxxx.com
    ServerAlias www.eap-dev.xxxxxx.com
    ErrorLog "logs/eap-dev-error_log"
    CustomLog "logs/eap-dev-access_log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin tech.admin@xxxxxx.com
    DocumentRoot "/opt/jboss/httpd/htdocs/htdocs"
    ServerName bpm-dev.xxxxxx.com
    ErrorLog "logs/bpm-dev-error_log"
    CustomLog "logs/bpm-dev-access_log" common
</VirtualHost>

 

以上整個建置就完成了.  

文章標籤

MIS 發表在 痞客邦 留言(0) 人氣()

VCenter 5.5 install on Windows Server 2012R2 with oracle database ,有幾個要注意的地方,在此僅記錄重點。安裝的順序可以使用 Simple Install ,或是單獨逐一依 Custom Install 安裝。

vcenter55_install_welcome_page  

 

環境:

1. windows server 2012 R2 多國語言;注意安裝時,1. 預設語言要切換為 英文 才不會有錯誤 2. VCenter 的 Host 要先加入AD網域,Vcenter 的權限才有辦法選到 AD 網域的帳號,不然就要用帳號: administrator@vsphere.local 登入 https://vcenter:9443/vsphere-client 到 SSO 作設定了

2. VCcenter 5.5 :VMware-VIMSetup-all-5.5.0-VMware vCenter Server 5.5 Update 2e and modules-2646481-20150401.iso

3. Oracle DataBase: 11gR2_11204_WIN64

安裝注意事項:

一、 依序安裝 vCenter Single Sign-on , vSphere Web Client , vShpere Inventory Service 時,不會連結到oracle database ;只有安裝 vCenter Server 才會連結到 Oracle DB,但 vCenter Single Sign-on 的 Administrator 密碼要記得,後續安裝都會用到它。

vCenter_Single_Sign_On  

例如:vCenter Server 安裝時

vCenterSSO  

 

二、vCenter Service 使用Windows 本機系統帳戶

vCenterService  

 

三、 vCenter 安裝後第一次用 vShpere Client 登入會有錯誤。

vcenter55_first_client_login  

 

1. 使用 google Chrome 需先登入 vShpere web clinet: https://vc55.gu.com:9443/vsphere-client ,使用帳號:administrator@vsphere.local 登入

vsphere_chrome_web_login  

2. 在 vCenter Servers 中選擇主機 VC55 加入 本機AD網域 的 administrator 權限

vCenter_Add_AD_Account  

 

四、使用 Oracle 11gR2 取代 MSSQL Express 作為 vCenter 的資料庫
註:( 對於小型安裝 "最多 5 台主機和 50 台虛擬機器",您可以使用配套的 Microsoft SQL Server 2008 Express 資料庫 )

1. 安裝 Oracle DB ,選擇 建立並設定資料庫。若是選擇 只安裝資料庫軟體 ,則之後必需利用指令 netca 建立 Listener ,可利用 lsnrctl status 確認一下 Listener 是否已正常工作;再利用指令 dbca 建立資料庫。

vCenter_oracleDB_install_01  

 選擇項目如下,後安裝

vCenter_oracleDB_install_02  

2. 測試連線到資料庫 vcdb 沒有問題。指令: sqlplus 帳號/密碼@資料庫 as sysdba

vCenter_oracleDB_install_03  

查詢資料庫的檔案: select name from v$datafile;

vCenter_oracleDB_install_04  

 

3. vCenter Server 系統必須具有 64 位元 DSN,通過 ODBC 資料來源建立一個系統 DSN:vcdb,如圖

vCenter_oracleDB_install_06  

 

4.  建立 vCenter 專屬的 TABLESPACE "VPX"

執行下列指令碼。該指令碼位於 vCenter Server 安裝套件的 /installation directory/vCenter-Server/dbschema/DB_and_schema_creation_scripts_oracle.txt 檔案中。

CREATE SMALLFILE TABLESPACE "VPX" DATAFILE '/u01/app/oracle/oradata/vcdb/vpx01.dbf'
SIZE 1G AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED LOGGING EXTENT MANAGEMENT LOCAL SEGMENT
SPACE MANAGEMENT AUTO;

對於 Windows 安裝,請變更 vpx01.dbf 檔案的目錄路徑,如下。

CREATE SMALLFILE TABLESPACE "VPX" DATAFILE 'C:\APP\ORACLE\ORADATA\VCDB\vpx01.dbf' SIZE 1G AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED LOGGING EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;

vCenter_oracleDB_install_05  

 

5. 設定 Oracle 資料庫使用者: VPXADMIN

執行下列 SQL 命令,建立具有正確權限的 vCenter Server 資料庫使用者。該指令碼位於 vCenter Server 安裝套件的 /installation directory/vCenter-Server/dbschema/DB_and_schema_creation_scripts_oracle.txt 檔案中。

在此範例中,使用者名稱為 VPXADMIN。

CREATE USER "VPXADMIN" PROFILE "DEFAULT" IDENTIFIED BY "oracle" DEFAULT TABLESPACE "VPX" ACCOUNT UNLOCK;
grant connect to VPXADMIN;
grant resource to VPXADMIN;
grant create view to VPXADMIN;
grant create sequence to VPXADMIN;
grant create table to VPXADMIN;
grant create materialized view to VPXADMIN;
grant execute on dbms_lock to VPXADMIN;
grant execute on dbms_job to VPXADMIN;
grant select on dba_tablespaces to VPXADMIN;
grant select on dba_temp_files to VPXADMIN;
grant select on dba_data_files to VPXADMIN;
grant unlimited tablespace to VPXADMIN;
alter user "VPXADMIN" quota unlimited on "VPX";

 

6.  安裝 vCenter Server 時選 通過 ODBC 資料來源建立的 System DSN:vcdb

vCenter_oracleDB_install_08  

輸入剛建立的 VPXADMIN 帳號及密碼

vCenter_oracleDB_install_09  

 

其它的依指示依序執行即可建立 VCenter 5.5 install on Windows Server 2012R2 with oracle database

以上是 vCenter 使用 Oracle Database 11gR2 的安裝方法

 

 

x. (選擇性) 使用指令碼建立 Oracle 資料庫結構描述

vCenter_oracleDB_install_07  

先切換到 vCenter Server 安裝套件 /installation directory/vCenter-Server/dbschema 目錄,再執行 D:\vCenter-Server\dbschema>sqlplus vpxadmin/oracle@vcdb

然後執行下列 dbschema 指令碼

1. 在 SQL*Plus 中,依序對資料庫執行下列指令碼。


@VCDB_oracle.SQL
@VCDB_views_oracle.SQL
@insert_stats_proc_oracle.sql
@load_stats_proc_oracle.sql
@purge_stat2_proc_oracle.sql
@purge_stat3_proc_oracle.sql
@purge_usage_stats_proc_oracle.sql
@stats_rollup1_proc_oracle.sql
@stats_rollup2_proc_oracle.sql
@stats_rollup3_proc_oracle.sql
@cleanup_events_oracle.sql
@delete_stats_proc_oracle.sql
@load_usage_stats_proc_oracle.sql
@TopN_DB_oracle.sql
@calc_topn1_proc_oracle.sql
@calc_topn2_proc_oracle.sql
@calc_topn3_proc_oracle.sql
@calc_topn4_proc_oracle.sql
@clear_topn1_proc_oracle.sql
@clear_topn2_proc_oracle.sql
@clear_topn3_proc_oracle.sql
@clear_topn4_proc_oracle.sql
@rule_topn1_proc_oracle.sql
@rule_topn2_proc_oracle.sql
@rule_topn3_proc_oracle.sql
@rule_topn4_proc_oracle.sql
@process_license_snapshot_oracle.sql
@l_purge_stat2_proc_oracle.sql
@l_purge_stat3_proc_oracle.sql
@l_stats_rollup1_proc_oracle.sql
@l_stats_rollup2_proc_oracle.sql
@l_stats_rollup3_proc_oracle.sql

2. (選擇性) 您也可以執行下列指令碼來啟用資料庫健全狀況監控。

@job_dbm_performance_data_oracle.sql
@process_performance_data_oracle.sql

3. 對於所有受支援的 Oracle Server 版本,執行下列指令碼可在資料庫上設定排定的工作。

@job_schedule1_oracle.sql
@job_schedule2_oracle.sql
@job_schedule3_oracle.sql
@job_cleanup_events_oracle.sql
@job_topn_past_day_oracle.sql
@job_topn_past_week_oracle.sql
@job_topn_past_month_oracle.sql
@job_topn_past_year_oracle.sql

您現在即擁有與 vCenter Server 相容的資料庫結構描述。

 

參考:

https://pubs.vmware.com/vsphere-55/index.jsp#com.vmware.vsphere.install.doc/GUID-55F7FFDB-01B8-4C18-AA89-DC28BD9B1E9F.html

 

附註:

vCenter Server 支援的資料庫的組態說明

資料庫類型

組態說明

Microsoft SQL Server 2008 R2 Express

可以用於小型部署 (最多 5 台主機和 50 台虛擬機器) 的配套資料庫。

SQL Server 定序模式:SQL_Latin1_General_CP1_CI_AS。

ODBC 系統 DSN 最低版本:SQL Native Client 10.0 (版本 2009.100.4000.00),可從 microsoft.com 下載中心免費下載。

備註

vCenter Server Appliance 不支援此資料庫。

Microsoft SQL Server 2008

請確保機器具有有效的 ODBC DSN 項目。

SQL Server 定序模式:SQL_Latin1_General_CP1_CI_AS。

ODBC 系統 DSN 最低版本:SQL Native Client 10.0 (版本 2009.100.4000.00),可從 microsoft.com 下載中心免費下載。

備註

vCenter Server Appliance 不支援此資料庫。

Microsoft SQL Server 2012 SP1

請確保機器具有有效的 ODBC DSN 項目。

Oracle 11g 和 12c

請確保機器具有有效的 ODBC DSN 項目。

完成 vCenter Server 安裝後,請採取下列步驟:

將最新的修補程式套用到 Oracle 用戶端和伺服器。

將 Oracle JDBC 驅動程式 (ojdbc14.jar 或 ojdbc5.jar) 複製到 vCenter Server 安裝目錄的 tomcat\lib 子目錄中:vCenter install location\Infrastructure\tomcat\lib

在 Windowss [系統管理工具] 控制台的 [服務] 區段中,重新啟動 VMware VirtualCenter Management Webservices 服務。

vCenter Server 安裝程式會嘗試將 Oracle JDBC 驅動程式從 Oracle 用戶端位置複製到 vCenter Server 安裝目錄。如果在 Oracle 用戶端位置中找不到 Oracle JDBC 驅動程式,則 vCenter Server 安裝程式會提示您手動複製檔案。您可以從 oracle.com 網站下載該檔案。

文章標籤

MIS 發表在 痞客邦 留言(0) 人氣()

在網頁上實作倒數計時讓使用者知道多久會被導向到另一個網站,這個功能常會用在網站改網址或者是要告知一些重要事項。作法如下:

jQuery: jquery-1.11.1.min.js

jquery.countdown: jquery.countdown.min.js

下載上面兩個 java script,然後再寫一個網頁 index.html,內容如下即可。請修改紅色標示的地方。

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<META HTTP-EQUIV="Refresh" CONTENT="15;URL=https://bpm.polinwei.com">
<title>Welcome BPM (Business Process Management, BPM) 企業流程管理系統</title>

<link href="style.css" rel="stylesheet" type="text/css">

<script src="jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="jquery.countdown.min.js"></script>
<script type="text/javascript">

$(document).ready(function() {
    val = 15 * 1000;
    selectedDate = new Date().valueOf() + val;
    $('.clock').countdown(selectedDate, function(event) {
           $(this).html(event.strftime('%S'));
         });
});    

</script>

<style type="text/css">
<!--
body {
    background-color: #e1dbcd;
    margin: 0px;    
    background-repeat: repeat-x;
}
-->
</style>

</head>
<body>


<div id="content">
    <p><span class="text_black"> Attention</span></p>
    
    <span class="text_bold">eSystem New URL</span>? ?<br>
    <p><span class="text">
    esystem's URL will be changed to <a href="https://bpm.polinwei.com"> https://bpm.polinwei.com</a> in 2015/11/16 , Please noted.
    </span></p>
    <p><span class="text_bold_nounderline">This page will redirect to new page in <span class="clock"></span> sec.</p>
    <p> PS: BPM - Business Process Management </p>
    
    <br/>
    <p><span class="text_black"> 請注意 </span></p>
    <p><span class="text_bold">eSystem 網址即將變更</span>? ?</p>
    <p><span class="text">
    esystem 網址將於2015/11/16更新為 <a href="https://bpm.polinwei.com">https://bpm.polinwei.com</a>,請將該網址加到你的最愛。
    </span></p>   
    <p><span class="text_bold_nounderline">該網頁將於<span class="clock"></span>秒後自動轉址。</span></p>
    <p> 註: 企業流程管理 BPM(Business Process Management, BPM)</p>
    
</div>

</body>
</html>
文章標籤

MIS 發表在 痞客邦 留言(0) 人氣()

 

一、
從 SQL Server Management Studio
在資料庫上按右鍵->「屬性」->「選項」->「復原模式」,改成「簡單」模式
或是下指令
ALTER DATABASE 資料庫名稱 SET RECOVERY SIMPLE
MSSQL_Option_simple   
 
二、
use 資料庫名稱
GO
DBCC SHRINKFILE('LDF的邏輯名稱',2)
其中的LDF的邏輯名稱,可以下以下指令取得
select * from sys.database_files
通常都是:資料庫名稱_log
MSSQL_file_logicFile   

 

範例指令:

use Application_Registry_Service_DB_a3763f11049a4d59b45c9ee164c3e626

GO

DBCCSHRINKFILE('Application_Registry_Service_DB_a3763f11049a4d59b45c9ee164c3e626_log',2)


 
三、
將資料庫「復原模式」改回「完整」
或是下指令
ALTER DATABASE 資料庫名稱 SET RECOVERY FULL

文章標籤

MIS 發表在 痞客邦 留言(0) 人氣()

Apache 網頁伺服器 (Apache Web Server) 上要如何設定以啟用壓縮功能,將輸出的網頁或資源檔案做壓縮後再送往瀏覽器端。也就是,開啟 mod_deflate 壓縮輸出的網頁或資源檔案以節省頻寬 (一般可省 2~3 倍以上)。

以下的範例說明瀏覽器和網頁伺服器間對於支援壓縮功能是如何溝通的:

瀏覽器:在送往伺服器的 HTTP 要求中會含有一個 Accept-Encoding 欄位說明自己支援的壓縮機制有哪些 (各壓縮機制以逗號「,」分開):

Accept
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding
gzip, deflate
Accept-Language
en-US,zh-TW;q=0.8,zh;q=0.5,en;q=0.3
Connection
keep-alive
Cookie
JSESSIONID="t5mGUd87rGbXsUQX1ij9M09s.slave:slave-server-one"; LtpaToken=AAECAzU2MDBGQ0VCNTYwMTI3MUJDTj1wb2x
DNT
1
Host
eap.globeunion.com
Referer
http://eap.globeunion.com/GUSSH/
User-Agent
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0



網頁伺服器:如果伺服器支援一個或多個瀏覽器所列的壓縮機制,則輸出的資料會被這一個或多個壓縮機制處理後送往瀏覽器,然後送出的 HTTP 回應中會含有一個 Content-Encoding 欄位說明用了資料被那些壓縮機制 (各壓縮機制以逗號「,」分開):

Cache-Control
No-Cache
Connection
Keep-Alive
Content-Encoding
gzip
Content-Length
6980
Content-Type
text/html;charset=UTF-8
Date
Tue, 22 Sep 2015 08:01:40 GMT
Expires
Thu, 01 Jan 1970 00:00:00 GMT
Keep-Alive
timeout=5, max=99
Pragma
No-Cache
Vary
Accept-Encoding
X-Powered-By
JSP/2.2


如下圖:




如何設定 Apache 網頁伺服器以啟用壓縮功能

0. 確認 Apache 網頁有安裝 deflate 模組
1. 在 httpd.conf 設定檔中確認 deflate 模組有設定載入,並且有做以下設定:
…..
LoadModule expires_module modules/mod_expires.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
…..
# 2015/09/22, added by polin wei
<IfModule mod_deflate.c>
DeflateCompressionLevel 9
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript application/javascript application/x-httpd-php
AddOutputFilter DEFLATE js css gif

#Instead of blacklist, we use a whitelist:
BrowserMatch ^MSIE [6-9] gzip

</IfModule>

<LocationMatch ".*\.jsp$">
     ForceType text/html
</LocationMatch>



2. 重新啟動 Apache 網頁伺服器:sudo service httpd restart
在上面的設定範例中,我們用最高的壓縮等級 (CompressionLevel) 9 (可用的數值 1 ~ 9),其實到 5 左右就有不錯的壓縮比例。而對於要根據檔案類型去啟用壓縮功能的列在「AddOutputFilterByType DEFLATE」之後;而對於要根據檔案“附檔名名稱”去啟用壓縮功能的列在「AddOutputFilter DEFLATE」之後。

文章標籤

MIS 發表在 痞客邦 留言(0) 人氣()

在wildfly的standalone.xml內中
約在83行左右,確認該行<subsystem xmlns="urn:jboss:domain:logging:2.0">下是否有加入
     <use-deployment-logging-config value="false"/>
 
EAP的設定大致相同,但加入的參數不同,約在88行左右
  <subsystem xmlns="urn:jboss:domain:logging:1.5">在之下,加入
   <add-logging-api-dependencies value="false"/>

以上設定,表單即不會因多次開啟而造成死當。
https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6.4/pdf/Migration_Guide/JBoss_Enterprise_Application_Platform-6.4-Migration_Guide-en-US.pdf     第17頁中表示因要排除第三方(log4j)的依賴性,所以要設成false,不然會有問題,不過不曉得跟死當有什麼直接關係,
但是補上該設定,系統是可以working的。
不過還滿好奇的是wildfly的console仍會秀出,但EAP的console始終沒有秀出我們的consoel。持續查找中。

文章標籤

MIS 發表在 痞客邦 留言(0) 人氣()

為了讓 WEB APP 不因一台主機當機而影響作業,開始架構二台 JBOSS 主機,並利用 JBOSS plug in 在 Apache 的 mod_cluster-1.2.6 來作 Load Balancer

版本:

JDK:jdk-8u45-linux-x64.rpm

JBOSS EAP 6.4

Apache & mod_cluster 1.2.6.Final : http://downloads.jboss.org/mod_cluster//1.2.6.Final/linux-i686/mod_cluster-1.2.6.Final-src-ssl.tar.gz

環境:

domain Master :192.168.30.100

domain Slave:192.168.30.101

EAPDomainCluster  

一、開始安裝 JDK

Step 01: 移除 OpenJDK

[root@localhost ~]# rpm -qa | grep java
[root@localhost ~]# yum remove java*

 

Step 02:安裝 JDK

[root@localhost tmp]# rpm -ivh jdk-8u45-linux-x64.rpm

[root@bm tmp]# java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

[root@bm tmp]# javac -version
javac 1.8.0_45

 

Step 03:編輯「/etc/profile」檔案,在最後加入

export JAVA_HOME=/usr/java/jdk1.8.0_45
export JRE_HOME=/usr/java/jdk1.8.0_45/jre
export ANT_HOME=/opt/apache-ant-1.7.0
export JBOSS_HOME=/opt/jboss-eap-6.4
export APACHE_HOME=/opt/jboss/httpd

export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH:$ANT_HOME/bin
export CLASSPATH=$CLASSPATH:.:$JAVA_HOME/lib:$JRE_HOME/lib

 

二、開始安裝 JBoss EAP 6.4

Step 01:上傳 jboss-eap-6.4.0.zip 並解壓於 /opt 下

[root@bm tmp]# unzip jboss-eap-6.4.0.zip
[root@bm tmp]# mv jboss-eap-6.4 /opt

 

Step 02:重開主機,並啟動 JBOSS Domain Mode 作測試( Master 與 Slave 作同樣的動作)

[root@bm tmp]# $JBOSS_HOME/bin/domain.sh

 

三、開始作 Domain Configuration 設定

 ■ Interface config on master(192.168.30.100)

 

Step 01:修改 vi domain/configuration/host.xml
初始值如下:

<interfaces>
    <interface name="management">
        <inet-address value="${jboss.bind.address.management:127.0.0.1}"/>
    </interface>
    <interface name="public">
       <inet-address value="${jboss.bind.address:127.0.0.1}"/>
    </interface>
    <interface name="unsecure">
        <!-- Used for IIOP sockets in the standard configuration.
             To secure JacORB you need to setup SSL -->
        <inet-address value="${jboss.bind.address.unsecure:127.0.0.1}"/>
    </interface>
</interfaces>

變更如下

<interfaces>
    <interface name="management">
        <inet-address value="${jboss.bind.address.management:192.168.30.100}"/>
    </interface>
    <interface name="public">
       <inet-address value="${jboss.bind.address:192.168.30.100}"/>
    </interface>
    <interface name="unsecure">
        <!-- Used for IIOP sockets in the standard configuration.
             To secure JacORB you need to setup SSL -->
        <inet-address value="${jboss.bind.address.unsecure:192.168.30.100}"/>
    </interface>
</interfaces>

 

Step02:建立 Domain Mode 主機間溝通用專用的帳號:domainAdmin,並取得 secret key
增加管理帳號:domainAdmin
密碼:password

[root@localhost bin]# ./add-user.sh

What type of user do you wish to add?
 a) Management User (mgmt-users.properties)
 b) Application User (application-users.properties)
(a):
Enter the details of the new user to add.
Using realm 'ManagementRealm' as discovered from the existing property files.
Username : domainAdmin
Password requirements are listed below. To modify these restrictions edit the add-user.properties configuration file.
 - The password must not be one of the following restricted values {root, admin, administrator}
 - The password must contain at least 8 characters, 1 alphabetic character(s), 1 digit(s), 1 non-alphanumeric symbol(s)
 - The password must be different from the username
Password : password
Re-enter Password : password
What groups do you want this user to belong to? (Please enter a comma separated list, or leave blank for none)[  ]:
About to add user 'domainMaster' for realm 'ManagementRealm'
Is this correct yes/no? yes
Added user 'domainMaster' to file '/opt/jboss-eap-6.3/standalone/configuration/mgmt-users.properties'
Added user 'domainMaster' to file '/opt/jboss-eap-6.3/domain/configuration/mgmt-users.properties'
Added user 'domainMaster' with groups  to file '/opt/jboss-eap-6.3/standalone/configuration/mgmt-groups.properties'
Added user 'domainMaster' with groups  to file '/opt/jboss-eap-6.3/domain/configuration/mgmt-groups.properties'
Is this new user going to be used for one AS process to connect to another AS process?
e.g. for a slave host controller connecting to the master or for a Remoting connection for server to server EJB calls.
yes/no? yes
To represent the user add the following to the server-identities definition <secret value="SkJvc3NFQVA2LjM=" />

 

Interface config on slave(192.168.30.101)

Step 01:修改 vi domain/configuration/host.xml 相關的值如下

<?xml version='1.0' encoding='UTF-8'?>
<host name="slave" xmlns="urn:jboss:domain:1.6">
    <management>
        <security-realms>
            <security-realm name="ManagementRealm">
                    <server-identities>
                       <secret value="SkJvc3NFQVA2LjM=" />
                    </server-identities>
                    <authentication>
                        <properties path="mgmt-users.properties" relative-to="jboss.domain.config.dir"/>
                    </authentication>
                <authorization map-groups-to-roles="false">
                    <properties path="mgmt-groups.properties" relative-to="jboss.domain.config.dir"/>
                </authorization>               
            </security-realm>
            <security-realm name="ApplicationRealm">
                <authentication>
                    <local default-user="$local" allowed-users="*" skip-group-loading="true" />
                    <properties path="application-users.properties" relative-to="jboss.domain.config.dir" />
                </authentication>
                <authorization>
                    <properties path="application-roles.properties" relative-to="jboss.domain.config.dir"/>
                </authorization>
            </security-realm>
        </security-realms>
        <audit-log>
            <formatters>
               <json-formatter name="json-formatter"/>
            </formatters>
            <handlers>
                <file-handler name="host-file" formatter="json-formatter" relative-to="jboss.domain.data.dir" path="audit-log.log"/>
                <file-handler name="server-file" formatter="json-formatter" relative-to="jboss.server.data.dir" path="audit-log.log"/>
            </handlers>
            <logger log-boot="true" log-read-only="false" enabled="false">
               <handlers>
                  <handler name="host-file"/>
               </handlers>
            </logger>
            <server-logger log-boot="true" log-read-only="false" enabled="false">
                <handlers>
                    <handler name="server-file"/>
                </handlers>
            </server-logger>
        </audit-log>
        <management-interfaces>
            <native-interface security-realm="ManagementRealm">
                <socket interface="management" port="${jboss.management.native.port:9999}"/>
            </native-interface>
            <http-interface security-realm="ManagementRealm">
                <socket interface="management" port="${jboss.management.http.port:9990}"/>
            </http-interface>
        </management-interfaces>
    </management>

    <domain-controller>
       <remote host="192.168.30.100" port="9999" security-realm="ManagementRealm" username="domainAdmin" />
       <!-- Alternative remote domain controller configuration with a host and port -->
       <!-- <remote host="${jboss.domain.master.address}" port="${jboss.domain.master.port:9999}" security-realm="ManagementRealm"/> -->
    </domain-controller>
    <interfaces>
        <interface name="management">
            <inet-address value="${jboss.bind.address.management:192.168.30.101}"/>
        </interface>
        <interface name="public">
           <inet-address value="${jboss.bind.address:192.168.30.101}"/>
        </interface>
        <interface name="unsecure">
            <!-- Used for IIOP sockets in the standard configuration.
                 To secure JacORB you need to setup SSL -->
            <inet-address value="${jboss.bind.address.unsecure:192.168.30.101}"/>
        </interface>
    </interfaces>
     <jvms>
        <jvm name="default">
          <heap size="64m" max-size="256m"/>
          <permgen size="256m" max-size="256m"/>
            <jvm-options>
                <option value="-server"/>
            </jvm-options>
       </jvm>
     </jvms>
    <servers>
        <server name="slave-one" group="other-server-group">
            <!-- Remote JPDA debugging for a specific server
            <jvm name="default">
              <jvm-options>
                <option value="-agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=n"/>
              </jvm-options>
           </jvm>
           -->
        </server>
        <server name="slave-two" group="other-server-group" auto-start="true">
            <!-- server-two avoids port conflicts by incrementing the ports in
                 the default socket-group declared in the server-group -->
            <socket-bindings port-offset="150"/>
        </server>
        <server name="slave-three" group="other-server-group" auto-start="false">
            <!-- server-three avoids port conflicts by incrementing the ports in
                 the default socket-group declared in the server-group -->
            <socket-bindings port-offset="250"/>
        </server>
    </servers>
</host>

 

Step 02:Domain Mode 是聽從 Master 主機,所以將 Slave 的 domain.xml 更名為 domain.xml.move

mv $JBOSS_HOME/domain/configuration/domain.xml $JBOSS_HOME/domain/configuration/domain.xml.move

 

四、Cluster Configuration 使用 mod_cluster 1.2.6.Final

Step 01: 安裝 apache,到 http://mod-cluster.jboss.org/downloads 下載 mod_cluster-1.2.6.Final-linux2-x64-ssl.tar.gz
將 mod_cluster-1.2.6.Final-linux2-x64-ssl.tar.gz 上載到Server後解壓

[root@eap-master tmp]# tar -xzvf mod_cluster-1.2.6.Final-linux2-x64-ssl.tar.gz
[root@eap-master tmp]# cp –rp /tmp/opt/jboss /opt

 

Step 02:  分別修改 192.168.30.100 & 192.168.30.101 Apache 的 httpd.conf

修改 Master(192.168.30.100) 的 mod_cluster:vi $APACHE_HOME/httpd/conf/httpd.conf

ServerName eap-master.globeunion.com:80

<VirtualHost 192.168.30.100:80>
  <Directory />
    Order deny,allow
    Deny from all
    Allow from all
  </Directory>
  <Location /cluster_manager>
    SetHandler mod_cluster-manager
    Order deny,allow
    Deny from all
    Allow from all
  </Location>
</VirtualHost>

Listen 192.168.30.100:6666
#ManagerBalancerName mycluster   
ManagerBalancerName other-server-group
<VirtualHost 192.168.30.100:6666>
  <Directory />
    Order deny,allow
      Deny from all
      Allow from all
  </Directory>
  ServerAdvertise on http://192.168.30.100:6666
  EnableMCPMReceive
</VirtualHost>

 

修改 Slave(192.168.30.101) 的 mod_cluster:vi $APACHE_HOME/httpd/conf/httpd.conf

ServerName eap-slave.globeunion.com:80

# MOD_CLUSTER_ADDS
# Adjust to you hostname and subnet.
<IfModule manager_module>
    <VirtualHost 192.168.30.101:80>
      <Directory />
        Order deny,allow
        Deny from all
        Allow from all
      </Directory>
      <Location /cluster_manager>
        SetHandler mod_cluster-manager
        Order deny,allow
        Deny from all
        Allow from all
      </Location>
    </VirtualHost>

    Listen 192.168.30.101:6666
    #ManagerBalancerName mycluster   
    ManagerBalancerName other-server-group
    <VirtualHost 192.168.30.101:6666>
      <Directory />
        Order deny,allow
          Deny from all
          Allow from all
      </Directory>
      ServerAdvertise on http:// 192.168.30.101:6666
      EnableMCPMReceive
    </VirtualHost>
</IfModule>

 

Step 03:修改192.168.30.100-Master 的 domain.xml 裡的 profile name="full-ha":

vi domain/configuration/domain.xml 相關的值如下

<profile name="full-ha">
<subsystem xmlns="urn:jboss:domain:messaging:1.4">
    <hornetq-server>
        <cluster-user>domainAdmin</cluster-user>
        <cluster-password>password</cluster-password>
        <persistence-enabled>true</persistence-enabled>
        <journal-type>NIO</journal-type>
        <journal-min-files>2</journal-min-files>
        <connectors>
            <netty-connector name="netty" socket-binding="messaging"/>
            <netty-connector name="netty-throughput" socket-binding="messaging-throughput">
                <param key="batch-delay" value="50"/>
            </netty-connector>
            <in-vm-connector name="in-vm" server-id="0"/>
        </connectors>
 
    </hornetq-server>
</subsystem>
<subsystem xmlns="urn:jboss:domain:modcluster:1.2">
    <mod-cluster-config advertise-socket="modcluster" connector="ajp" proxy-list="192.168.30.100:6666,192.168.30.101:6666" balancer="mycluster">
        <dynamic-load-provider>
            <load-metric type="busyness"/>
        </dynamic-load-provider>
    </mod-cluster-config>
</subsystem>
<subsystem xmlns="urn:jboss:domain:web:2.2" default-virtual-server="default-host" native="false" instance-id="${jboss.node.name}">
    <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
    <connector name="ajp" protocol="AJP/1.3" scheme="http" socket-binding="ajp"/>
    <virtual-server name="default-host" enable-welcome-root="true">
        <alias name="localhost"/>
        <alias name="example.com"/>
    </virtual-server>
</subsystem>
</profile>

 

五、關閉防火牆

[root@bm bin]# systemctl list-unit-files | grep fire

firewalld.service enabled

[root@bm bin]# systemctl disable firewalld.service

 

六、相關服務手動啟動

#Apache Server Start/Stop

$APACHE_HOME/sbin/apachectl start/stop/status

#JBOSS EAP Server Start

$JBOSS_HOME/bin/domain.sh

#JBOSS EAP Domain 管理介面

http://192.168.30.100:9990/console

 

 

七、將 Apache Server 設定成 Service

Step 01:copy apachectl 到 /etc/init.d

[root@eap-master init.d]# cp /opt/jboss/httpd/sbin/apachectl /etc/init.d

 

Step 02: 修改 /etc/init.d/apachectl

#!/bin/sh

在第二行加入以下兩句:

# chkconfig: 2345 80 90
# description:auto_run

第一行,告訴系統使用的shell,所以的shell腳本都是這樣。
第二行,chkconfig後面有三個參數2345,80和90告 訴chkconfig程式,需要在rc2.d~rc5.d目錄下,創建名字為 S80auto_run的檔連接,連接到/etc/rc.d/init.d目錄下的的auto_run腳本。第一個字元是S,系統在啟動的時候,運行腳 本auto_run,就會添加一個start參數,告訴腳本,現在是啟動模式。同時在rc0.d和rc6.d目錄下,創建名字為K90auto_run的 檔連接,第一個字元為K,個系統在關閉系統的時候,會運行auto_run,添加一個stop,告訴腳本,現在是關閉模式。
注意上面的三行是中,第二、三行是必須的,否則在運行chkconfig --add auto_run時,會報錯。

完整如下:

#!/bin/sh
# chkconfig: 2345 80 90
# description:auto_run
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# Apache control script designed to allow an easy command line interface
# to controlling Apache.  Written by Marc Slemko, 1997/08/23
#
# The exit codes returned are:
#   XXX this doc is no longer correct now that the interesting
#   XXX functions are handled by httpd
#    0 - operation completed successfully
#    1 -
#    2 - usage error
#    3 - httpd could not be started
#    4 - httpd could not be stopped
#    5 - httpd could not be started during a restart
#    6 - httpd could not be restarted during a restart
#    7 - httpd could not be restarted during a graceful restart
#    8 - configuration syntax error
#
# When multiple arguments are given, only the error from the _last_
# one is reported.  Run "apachectl help" for usage info
#
ARGV="$@"
#
# |||||||||||||||||||| START CONFIGURATION SECTION  ||||||||||||||||||||
# --------------------                              --------------------
#
# the path to your httpd binary, including options if necessary
HTTPD='/opt/jboss/httpd/sbin/httpd'
#
# pick up any necessary environment variables
if test -f /opt/jboss/httpd/sbin/envvars; then
  . /opt/jboss/httpd/sbin/envvars
fi
#
# a command that outputs a formatted text version of the HTML at the
# url given on the command line.  Designed for lynx, however other
# programs may work.  
LYNX="lynx -dump"
#
# the URL to your server's mod_status status page.  If you do not
# have one, then status and fullstatus will not work.
STATUSURL="http://localhost:80/server-status"
#
# Set this variable to a command that increases the maximum
# number of file descriptors allowed per child process. This is
# critical for configurations that use many file descriptors,
# such as mass vhosting, or a multithreaded server.
ULIMIT_MAX_FILES="ulimit -S -n `ulimit -H -n`"
# --------------------                              --------------------
# ||||||||||||||||||||   END CONFIGURATION SECTION  ||||||||||||||||||||

# Set the maximum number of file descriptors allowed per child process.
if [ "x$ULIMIT_MAX_FILES" != "x" ] ; then
    $ULIMIT_MAX_FILES
fi

ERROR=0
if [ "x$ARGV" = "x" ] ; then
    ARGV="-h"
fi

case $ARGV in
start|stop|restart|graceful|graceful-stop)
    $HTTPD -k $ARGV
    ERROR=$?
    ;;
startssl|sslstart|start-SSL)
    echo The startssl option is no longer supported.
    echo Please edit httpd.conf to include the SSL configuration settings
    echo and then use "apachectl start".
    ERROR=2
    ;;
configtest)
    $HTTPD -t
    ERROR=$?
    ;;
status)
    $LYNX $STATUSURL | awk ' /process$/ { print; exit } { print } '
    ;;
fullstatus)
    $LYNX $STATUSURL
    ;;
*)
    $HTTPD $ARGV
    ERROR=$?
esac

exit $ERROR

 

Step 03: 強制設成 Service

[root@eap-master init.d]# chkconfig --add apachectl

[root@eap-master init.d]# chkconfig --list apachectl

這樣 apache 除了會自動開機啟動外,還可以直接下 service apachectl start/stop 啟動

 

八、設定 建立 JBoss EAP 的 Domain 為 Service

Step 01: copy jboss-as.conf 到 /etc/jboss-as/ ;copy jboss-as-domain.sh 到 /etc/init.d/

[root@bm etc]# cp /opt/jboss-eap-6.4/bin/init.d/jboss-as.conf /etc/jboss-as/

[root@bm jboss-as]# cp /opt/jboss-eap-6.4/bin/init.d/jboss-as-domain.sh /etc/init.d/


Step 02: 修改 /etc/jboss-as/jboss-as.conf

# The username who should own the process.
#
JBOSS_USER=root

# The amount of time to wait for startup
#
STARTUP_WAIT=30

# The amount of time to wait for shutdown
#
# SHUTDOWN_WAIT=30

# Location to keep the console log
#
# JBOSS_CONSOLE_LOG=/var/log/jboss-as/console.log

 

Step 03: 修改 /etc/init.d/jboss-as-domain.sh

#!/bin/sh
#
# JBoss domain control script
#
# chkconfig: - 80 20
# description: JBoss AS Domain
# processname: domain
# pidfile: /var/run/jboss-as/jboss-as-domain.pid
# config: /etc/jboss-as/jboss-as.conf

# Source function library.
. /etc/init.d/functions

# Load Java configuration.
#[ -r /etc/java/java.conf ] && . /etc/java/java.conf
#export JAVA_HOME

# Load JBoss AS init.d configuration.
if [ -z "$JBOSS_CONF" ]; then
  JBOSS_CONF="/etc/jboss-as/jboss-as.conf"
fi

[ -r "$JBOSS_CONF" ] && . "${JBOSS_CONF}"

# Set defaults.

if [ -z "$JBOSS_HOME" ]; then
  JBOSS_HOME=/opt/jboss-eap-6.4
fi
export JBOSS_HOME

 

Step 04: 註冊 JBOSS 成 Service

[user@host init.d]$ sudo chkconfig --add jboss-as-domain.sh

[user@host init.d]$ sudo chkconfig --level 2345 jboss-as-domain.sh on #設置 jboss-as-domain.sh 在運行級別為2、3、4、5的情況下都是on(開啟)的狀態

 

 這樣子就可以兩台相互備援了.

 

附註:

■ 若同一個環境有不同的 mod_cluster, 為了不要互相引響,可以在 mod_cluster 的httpd.conf 加入 allow 作限制如下:vi $APACHE_HOME/httpd/conf/httpd.conf

## 2015/09/22 added by polin wei
<VirtualHost 192.168.30.100:80>
  <Directory />
    Order deny,allow
    Deny from all
    Allow from all
  </Directory>
  <Location /cluster_manager>
    SetHandler mod_cluster-manager
    Order deny,allow
    Deny from all
    Allow from 192.168.30.
  </Location>
</VirtualHost>

Listen 192.168.30.100:6666
#ManagerBalancerName mycluster   
ManagerBalancerName other-server-group
<VirtualHost 10.10.2.52:6666>
  <Directory />
    Order deny,allow
      Deny from all
      Allow from 192.168.30.100
      Allow from 192.168.30.101
  </Directory>
  ServerAdvertise on http://192.168.30.100:6666
  EnableMCPMReceive
</VirtualHost>

 

 

 

 

 

參考:

http://wiki.lunarpages.com/Allow_and_Deny_by_IP_Address

 

文章標籤

MIS 發表在 痞客邦 留言(0) 人氣()

PTC 的 Windchill 是一個開發圖文管理與專案管理系統,為了有效管理帳號,可以與 windows Server 的 AD 作整合密碼認證。

環境:

Windchill v10.2

windows Server AD: 2003

AD Server資訊如下:
HostName:ad.wei.com
Ldap user:pdm2adldap
Ldap pwd:pdm2adldap

作法:

step 01:開啟windchill shell,進入D:\ptc\windchill_10.2\HTTPServer\,執行下列的指令

ant -f webAppConfig.xml addAuthProvider -DappName=Windchill -DldapUrl="ldap://ad.wei.com:389/DC=wei,DC=com?SAMAccountName?sub?(objectClass=*)" -DproviderName=WeiAD -DbindDn=pdm2adldap -DbindPwd=pdm2adldap

註:若 port:389 登入認證有問題,則用 AD 的 GC port:3268

step 02:修改 D:\ptc\Windchill_10.2\HTTPServer\conf\extra\app-Windchill-Auth.xconf

在# Authenticated resources 下,在每一個 LocationMatch 中的 AuthBasicProvider 中,把 Windchill-WeiAD 放到第一個位置

winchill-ad-auth  

重新啟動Apache即可

 

文章標籤

MIS 發表在 痞客邦 留言(0) 人氣()