opencms 安裝細節探討

引入:html

由於項目需求,咱們要用到openCMS。雖然之前用過不少相似的內容管理系統相似Vignette,Fatwire,可是openCMS雖然大致功能差很少,具體並沒用過,因此這裏作了一些研究,會陸續把這些研究心得分享出來。這裏先從openCMS安裝講起,雖然簡單,但也有一些值得探討的問題。java


安裝亮點1:不能夠重複配置openCMS。mysql

咱們知道,第一次運行openCMS須要作配置,配置的請求URL是:http://localhost:8080/opencms/setup/ ,可是運行第一次以後就不能夠運行第二次了,理由是在安裝過程當中,它會去調用CmsSetupBean類的prepareSetup10()方法:sql

/**
     * Prepares step 10 of the setup wizard.<p>
     */
   publicvoidprepareStep10() {
 
        if (isInitialized()) {
            // lock the wizard for further use 
            lockWizard();
            // save Properties to file "opencms.properties" 
            saveProperties(getProperties(),CmsSystemInfo.FILE_PROPERTIES, false);
 
            setSchemaGeneration(false);
            m_peristenceConfigurator.save();
        }
    }

而這個方法會去調用lockWizard()方法後保存opencms.properties讓其生效,lockWizard方法的實現就是把opencms.properties中key爲wizard.enabled設爲false:數據庫

publicvoidlockWizard() {
 
        setExtProperty("wizard.enabled", CmsStringUtil.FALSE);
}

這會致使咱們的opencms.properties被更改:服務器

#
# Enable/Disable OpenCms Setup Wizard
# The wizard sets the flag to false after the setup.
# To use the wizard again, reset it manually to true.
# By setting no value, wizard can always be used.
#################################################################################
wizard.enabled=false

而下次運行時候,它會去判斷此屬性,判斷點在CmsAutoSetup類的main()方法中調用的run()方法的第一行:app

/**
     * Performs the setup.<p>
     * @throws Exception 
     */
   publicvoidrun() throwsException {
 
        if (m_bean.getWizardEnabled()) {
 
            longtimeStarted = System.currentTimeMillis();
 
            CmsSetupTests setupTests = new CmsSetupTests();
           …
        }
}



安裝亮點2: 正確設置max_allowed_packet這個mysql系統變量的大小。less

在opencms安裝過程當中,它會對一些DB變量作檢查,其代碼以下:ide

/**
     * Returns an optional warning message ifneeded, <code>null</code> if not.<p>
     * 
     * @param db the selected database key
     * 
     * @return html warning, or <code>null</code> if no warning
     */
   publicString checkVariables(String db) {
 
        StringBuffer html = new StringBuffer(512);
        if (m_con == null){
            return null; // prior error,trying to get a connection
        }
        Exception exception = null;
        if (db.equals("mysql")){
            String statement = "SELECT @@max_allowed_packet;";
            Statement stmt = null;
            ResultSet rs = null;
            longmaxAllowedPacket = 0;
            try {
                stmt = m_con.createStatement();
                rs = stmt.executeQuery(statement);
                if (rs.next()) {
                    maxAllowedPacket = rs.getLong(1);
                }
            } catch (Exception e) {
                exception = e;
            } finally {
                if (stmt != null){
                    try {
                        stmt.close();
                    } catch (SQLException e) {
                        // ignore
                    }
                }
            }
            if (exception == null){
                intmegabyte = 1024 * 1024;
                if (maxAllowedPacket > 0) {
                    html.append("<p>MySQL system variable <code>'max_allowed_packet'</code>is set to ");
                    html.append(maxAllowedPacket);
                    html.append(" Byte (");
                    html.append((maxAllowedPacket / megabyte) + "MB).</p>\n");
                }
                html.append("<p>Please note that it will not be possible for OpenCms tohandle files bigger than this value in the VFS.</p>\n");
                intrequiredMaxAllowdPacket = 16;
                if (maxAllowedPacket < (requiredMaxAllowdPacket * megabyte)){
                    m_errors.add("<p><b>Your <code>'max_allowed_packet'</code>variable is set to less than "
                        + (requiredMaxAllowdPacket* megabyte)
                        + " Byte("
                        + requiredMaxAllowdPacket
                        + "MB).</b></p>\n"
                        + "<p>The required value for running OpenCms isat least "
                        + requiredMaxAllowdPacket
                        + "MB."
                        + "Please change your MySQL configuration (in the<code>my.ini</code> or <code>my.cnf</code>file).</p>\n");
                }
            } else {
                html.append("<p><i>OpenCms was not able to detect the value of your<code>'max_allowed_packet'</code>variable.</i></p>\n");
                html.append("<p>Please note that it will not be possible for OpenCms tohandle files bigger than this value.</p>\n");
                html.append("<p><b>The recommended value for running OpenCms is 16MB,please set it in your MySQL configuration (in your<code>my.ini</code> or <code>my.cnf</code>file).</b></p>\n");
                html.append(CmsException.getStackTraceAsString(exception));
            }
        }
        if (html.length() == 0) {
            return null;
        }
        return html.toString();
    }

從這裏能夠看出,對於數據庫是mysql的情形,它會先去執行數據庫查詢讀取max_allowed_packet的值,這個變量主要讓mysql限制服務器接受的單個數據包的大小(由於在openCMS中,常常要存富文本內容,因此這個值仍是要設置大點爲好),而且若是它<16MB, 則報錯our max_allowed_packet variable is set to less than 16MB。而默認的mysql這個值配置是4MB,因此第一次setup出錯。咱們在my.ini中將其改成30MB,這樣才過了這關:ui

wKiom1R6f1XxxiwOAAEsVJYPJ_0634.jpg



安裝亮點3:opencms中資產的存儲。

opencms中,這些資產都是以BLOB形式存儲的:

wKioL1R6f4GSuLD4AAK72Iz3D_c513.jpg

相關文章
相關標籤/搜索