Joe Horn 的啟示錄
Joe Horn's Blog
  • LinkedIn
  • Facebook
  • Instagram
  • GitHub
  • Docker Hub
RSS
  • VPS Referrals
  • My Plurk
  • My Plurk Bot

8 月 25 2015

調整 Apache HTTPD & Apache Tomcat & nginx 的 content cache & compression

前陣子調整了一些 Apache HTTPD & Tomcat & nginx 的 cache 機制與內容壓縮機制,稍微紀錄一下。

Apache HTTPD 的 cache:

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/gif "access plus 1 month"
  ExpiresByType image/jpeg "access plus 1 month"
  ExpiresByType image/png "access plus 1 month"
  ExpiresByType text/css "access plus 1 month"
</IfModule>

Apache HTTPD 的壓縮:

<IfModule mod_deflate.c>
  DeflateCompressionLevel 9
  AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php
  AddOutputFilter DEFLATE js css
</IfModule>

Apache Tomcat 的 cache(在 application 的 web.xml 做調整):

  <filter>
    <filter-name>ExpiresFilter</filter-name>
    <filter-class>org.apache.catalina.filters.ExpiresFilter</filter-class>
    <init-param>
      <param-name>ExpiresByType image</param-name>
      <param-value>access plus 1 month</param-value>
    </init-param>
    <init-param>
      <param-name>ExpiresByType text/css</param-name>
      <param-value>access plus 1 month</param-value>
    </init-param>
    <init-param>
      <param-name>ExpiresByType application/javascript</param-name>
      <param-value>access plus 1 month</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>ExpiresFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
  </filter-mapping>

Apache Tomcat 的壓縮(在 conf/server.xml 做調整):

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               compression="on" compressableMimeType="text/html,text/xml,text/plain,text/css,application/javascript"
               redirectPort="8443" />

nginx 的 cache(在 server tag 內做調整):

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    expires 1M;
}

nginx 的壓縮(在 http tag 內做調整):

gzip_vary on;
gzip_proxied any;
gzip_comp_level 9;
gzip_buffers 8 32k;
gzip_http_version 1.0;
gzip_types text/plain text/css application/json
           application/javascript application/x-javascript text/javascript
           text/xml application/xml application/rss+xml application/atom+xml application/rdf+xml;

大概就調這些,其他多媒體檔案就看需求了…

By Joe Horn • WWW 0 • Tags: Apache HTTPD, Apache Tomcat, cache, compression, deflate, gzip, nginx

3 月 4 2015

勞保局的自然人憑證元件…

現在都什麼時候了… 是沒有人在用嗎? O_o

By Joe Horn • Life, WWW 0

12 月 30 2014

Crucial M550 on Lenovo L412

從數據看來,也是受限於界面速度,但 4k 對齊與 AHCI 設定等等的 tuning 影響頗大。

調整前:

調整後:

4k-64Thrd 的寫入差距頗大…

By Joe Horn • Computer Hardware 0 • Tags: Crucial, L412, Lenovo, M550, SSD

12 月 14 2014

rsyslog daemon 在 OpenVZ guest 瘋狂佔用 CPU resource

剛幫忙解掉的問題。
某台建立在 OpenVZ 的 Ubuntu 的 rsyslog daemon process 瘋狂佔用 CPU resource。
log 看到的狀況是這樣:

...
Dec 14 06:25:13 Linux rsyslogd-2177: rsyslogd[internal_messages]: 1134916 messages lost due to rate-limiting
Dec 14 06:25:13 Linux rsyslogd: imklog: error reading kernel log - shutting down: Bad file descriptor
Dec 14 06:25:13 Linux rsyslogd: message repeated 498 times: [imklog: error reading kernel log - shutting down: Bad file descriptor]
Dec 14 06:25:19 Linux rsyslogd-2177: rsyslogd[internal_messages]: 1114295 messages lost due to rate-limiting
Dec 14 06:25:19 Linux rsyslogd: imklog: error reading kernel log - shutting down: Bad file descriptor
Dec 14 06:25:19 Linux rsyslogd: message repeated 498 times: [imklog: error reading kernel log - shutting down: Bad file descriptor]
Dec 14 06:25:25 Linux rsyslogd-2177: rsyslogd[internal_messages]: 1805432 messages lost due to rate-limiting
Dec 14 06:25:25 Linux rsyslogd: imklog: error reading kernel log - shutting down: Bad file descriptor
Dec 14 06:25:25 Linux rsyslogd: message repeated 498 times: [imklog: error reading kernel log - shutting down: Bad file descriptor]
...

把 /etc/rsyslog.conf 下列這行註解掉,重新啟動 rsyslog 就搞定了… :-)

$ModLoad imklog   # provides kernel logging support

By Joe Horn • Linux 0 • Tags: Linux, OpenVZ, rsyslog, Ubuntu

11 月 30 2014

[MySQL] shrink ibdata file

最近幫忙處理某台 MySQL 5.0 server,做了個小實驗,寫個文章把處理過程紀錄下來。

因為該 server 沒有 innodb_file_per_table 這個設定,所有的 InnoDB 資料都放在 ibdata 這個檔案裡,而我們希望能讓該 server 持續運作,盡可能在不停機的狀況下,把 InnoDB 的資料切開。

實驗後,我們透過這些步驟完成切割/轉移:

  1. 確認舊的 server 有開啟 binlog,準備跑 replication。
  2. 用 Percona XtraBackup 備份舊的 MySQL 資料庫。
  3. 準備新機器,把備份檔丟到新的 server。
  4. 在新機器的 my.cnf 加入 innodb_file_per_table 設定,把 MySQL daemon 跑起來。
  5. 在新機器用以下指令把 InnoDB table 挑出來:
    SELECT `TABLE_SCHEMA`, `TABLE_NAME` FROM `TABLES` WHERE `ENGINE`='InnoDB' ORDER BY `TABLE_SCHEMA`,`TABLE_NAME`;
  6. 在新機器用 mysqldump 匯出 table schema & data :
    mysqldump -u root -pMY_PASSWORD --max_allowed_packet=512M -Cx --opt TABLE_SCHEMA TABLE_NAME > TMP_DIR/TABLE_SCHEMA.TABLE_NAME.sql
  7. 在新機器 drop 掉已匯出的 table:
    DROP TABLE `TABLE_SCHEMA`.`TABLE_NAME`;
  8. 停掉新機器的 MySQL daemon,把 datadir 的 ib* 搬走,再啟動 MySQL daemon。
  9. 重新匯入 table:
    mysql -u root -pMY_PASSWORD TABLE_SCHEMA < TMP_DIR/TABLE_SCHEMA.TABLE_NAME.sql
  10. 用 CHANGE MASTER TO … 指令開始讓新機器的 MySQL 成為舊 server 的 SLAVE。
  11. 同步完成後,找時間讓舊的 server 退下,讓新的 server 佔用舊機器的 IP。
  12. 在新機器的 MySQL 執行 RESET SLAVE,停掉 replication。

By Joe Horn • Database 0 • Tags: ibdata, innodb_file_per_table, MySQL, mysqldump, shrink, XtraBackup

7 月 10 2014

[PHP] 自製金錢分攤函式

近日在工作上應該會需要計算金錢分攤,簡單寫了個 PHP 函式備用。

function shareAmount( $amount , $shares ) {
    $arr = array();
    if ( is_numeric($amount) && is_int($shares) ) {
        $precision = is_int($amount) ? 0 : strlen(substr($amount, strpos($amount, '.')+1));
        for ( $i = $shares; $i > 0; $i-- ) {
            $val = round( $amount / $i , $precision );
            array_push( $arr , $val );
            $amount -= $val;
        }
    }
    return $arr;
}

執行結果大概像這樣:

// var_dump( shareAmount(101,3) );
array(3) {
  [0]=>
  float(34)
  [1]=>
  float(34)
  [2]=>
  float(33)
}

// var_dump( shareAmount(0.5101,3) );
array(3) {
  [0]=>
  float(0.17)
  [1]=>
  float(0.1701)
  [2]=>
  float(0.17)
}

我在資料庫沒看到大數,所以就沒考慮 BC Math,直接用 is_numeric() 了… :p

By Joe Horn • PHP 0 • Tags: PHP

5 月 4 2014

Javascript 的變數範圍

最近在微調部門某個 PHP 專案程式,該專案使用 ExtJS 作前端介面 framework …
整理這個專案內的 Javascript 程式讓我覺得… 應該有不少人忽略,或是不在意 Javascript 的變數定義方式。

先來看這串程式碼:

執行結果:

這張圖有趣就在第 40, 41 行程式碼執行的結果差異,以及 42, 43 行程式碼執行的結果差異。
在 Javascript 不透過 var 進行定義之變數,皆為全域變數;但透過 var 定義之變數就有變數範圍。
這兩種變數定義方式影響瀏覽器開啟網頁後的記憶體耗用量,以及 Javascript engine 進行 GC 的效率與結果,不得不慎呀…

By Joe Horn • Javascript 0 • Tags: Garbage collection, GC, Javascript, variable scope

3 月 4 2014

Sencha Touch 使用心得

這陣子在進行一個 mobile web 開發專案;我們對 Ext JS 還算熟悉,故選擇採用同公司的產品:Sencha Touch。
我們沒使用過,決定先進行 prototyping,看能挖出多少可用、好用的元件。
目前第一版趨近完成,我先寫篇心得分享,順道幫自己留個筆記;請路過看到的前輩、高手們不吝給予指教啦~ (羞)

目前是 2014 年 3 月初,已釋出的 Sencha Touch 最新 GPL 版本是 2.3.1,但堪用的是 2.1.1。
Sencha Touch 僅支援 WebKit based 網頁瀏覽器,大致上就是這些。

More

By Joe Horn • Javascript 0 • Tags: Ext.field.DatePicker, Ext.MessageBox, Ext.Msg, Sencha Touch

2 月 22 2014

[Apache Tomcat] Enhance security

我沒有在使用 Apache Tomcat 的後台,佈署軟體/程式都是透過 scp/sftp/ftp 等方式做傳輸。
所以在解開 Apache Tomcat 的壓縮檔之後,我會執行以下指令,把不必要的檔案清掉,增強安全性:

cd apache-tomcat-* && \
/bin/rm -rf webapps/docs webapps/examples webapps/host-manager webapps/manager && \
/bin/rm -f webapps/ROOT/*.gif webapps/ROOT/*.xml webapps/ROOT/*.ico webapps/ROOT/*.txt webapps/ROOT/*.svg && \
/bin/cat /dev/null > webapps/ROOT/index.jsp &&
/bin/cat /dev/null > webapps/ROOT/index.html

By Joe Horn • Computer Software 0 • Tags: Apache Tomcat, security

2 月 14 2014

[實測] Plextor M5M 256GB mSATA SSD (PX-256M5M) on Lenovo T420s

前幾天幫我在家用的 Lenovo T420s 裝上新的 mSATA SSD,用 AS SSD Benchmark 跑了些數據,貼在這裡做個紀錄。

受限於 T420s 的介面速度,Plextor M5M 256GB mSATA SSD 的效能沒有完全發揮。

對照組,T420s 原廠給的 7mm 2.5″ 7200rpm HDD。

雖然 SSD 的效能沒有完全發揮,用來當系統碟的爽度依然很高啊… 8-)

By Joe Horn • Computer Hardware 0 • Tags: Lenovo, M5M, mSATA, Plextor, SSD, T420s

«‹ 3 4 5 6›»

Site Info

All content on this Blog is licensed under CC BY-NC-SA 4.0

About Me

profile for Joe Horn at Stack Overflow, Q&A for professional and enthusiast programmers


My mail!

獅子座

Coffee Powered!

F1 fans

motoGP fans

Linkin Park

I am a Taiwanese!

Recent Comments

  • Avatar of johnpupu johnpupu: PHP 還有這個 phpsavant.c……
  • Avatar of Jerry Jerry: 这个不是foreach的问题。 0 ==……
  • Avatar of Joe Horn Joe Horn: 看來問題在 if ... else ..……
  • Avatar of jnlin jnlin: 因為 'b' 被轉型成 0 了…
  • Avatar of 路人 路人: 跟 foreach 沒有關係 ?…
  • Avatar of bill bill: 註冊表那裡要設定 BasicAuthLe……
  • Avatar of 虫 虫: .svn 的檔案減少可以增加在 wind……
  • Avatar of mars mars: 如果說寫程式是理性極致的話,那寫小說就是……
  • Avatar of Joe Horn Joe Horn: 已更新文章。…
  • Avatar of jackcal jackcal: joehorn.idv.tw關於轉貼 h……

Post Categories

  • About My Sites (16)
  • Computer Hardware (29)
  • Computer Software (45)
  • Database (23)
  • FreeBSD (21)
  • Funny (14)
  • Life (23)
  • Linux (5)
  • Mail (19)
  • Network (12)
  • Programing (40)
    • .NET (5)
    • JAVA (2)
    • Javascript (6)
    • PHP (29)
  • Thoughts (34)
  • Windows (13)
  • WWW (79)
    • phpBB (7)
    • WordPress (18)

Blogroll

  • 這裡沒有美食

Tags Cloud

AMD Apache benchmarking Bloglines Coppermine DNSBL eAccelerator fio Firefox free FreeBSD Gmail Google HDD Hsin-chu HTTPS IE Intel Javascript Lenovo Longhorn Microsoft MySQL Office Percona XtraBackup performance PHP phpBB pirate Postfix restaurant RSS security sendmail software SpamAssassin SSL Subversion Taiwan theme translation VPS Windows WordPress Yahoo

Ads

↑

© Joe Horn 的啟示錄 2025
Powered by WordPress • Themify WordPress Themes