http://618119.com
新的blog rss訂閱地址: http://feed.feedsky.com/lizongbo
從最早的 http://blog.csdn.net/lizongbo,
到 http://blog.donews.com/lizongbo
再到http://www.aygfsteel.com/lizongbo
現(xiàn)在終于擁有自己的域名和獨(dú)立的blog了。 閱讀全文
lizongbo 的 編程學(xué)習(xí)http://618119.com |
置頂隨筆 #
2007年10月16日 #
2007年10月13日 #
mysql 雙機(jī)熱備配置
1.下載mysql-noinstall-5.0.45-win32.zip
2.解壓到E:\mysql,然后將文件夾E:\mysql\mysql-noinstall-5.0.45-win32改為E:\mysql\master
3.再解壓到E:\mysql,然后將文件夾E:\mysql\mysql-noinstall-5.0.45-win32改為E:\mysql\slave
4.復(fù)制E:\mysql\master\my-small.ini為E:\mysql\master\my.ini
編輯內(nèi)容:,增加log-bin和binlog-do-db參數(shù)
示例如下:
#skip-networking
server-id = 1
# Uncomment the following if you want to log updates
#log-bin=mysql-bin
log-bin=mysql-bin
binlog-do-db = testdb1 #需同步數(shù)據(jù)庫 testdb1
binlog-do-db = testdb2 #需同步數(shù)據(jù)庫 testdb2
5.復(fù)制E:\mysql\slave\my-small.ini為E:\mysql\slave\my.ini
編輯內(nèi)容:,修改端口,
port = 3310
示例如下:
[client]
#password = your_password
port = 3310
socket = /tmp/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3310
socket = /tmp/mysql.sock
skip-locking
key_buffer = 16K
max_allowed_packet = 1M
table_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 64K
#skip-networking
server-id = 2
# Uncomment the following if you want to log updates
#log-bin=mysql-bin
master-host=127.0.0.1
master-user=root
master-password=
master-port=3306
replicate-do-db=testdb1
replicate-do-db=testdb2
6.保存 E:\mysql\master\my.ini.和E:\mysql\slave\my.ini
7.在命令行下運(yùn)行E:\mysql\master\bin\mysqld.exe,
Microsoft Windows XP [版本 5.1.2600]
(C) 版權(quán)所有 1985-2001 Microsoft Corp.
E:\mysql\master\bin>mysqld
8.再新開命令行,運(yùn)行E:\mysql\slave\bin\mysqld.exe
Microsoft Windows XP [版本 5.1.2600]
(C) 版權(quán)所有 1985-2001 Microsoft Corp.
E:\mysql\slave\bin>mysqld
071013 21:41:06 [Warning] The syntax for replication startup options is deprecat
ed and will be removed in MySQL 5.2. Please use 'CHANGE MASTER' instead.
9.用mysql 客戶端 HeidiSQL連接到 127.0.0.1的3306,創(chuàng)建數(shù)據(jù)庫testdb1和testdb2,
并在數(shù)據(jù)庫中新建表,然后插入一些數(shù)據(jù).
10.客戶端連接 到 127.0.0.1的3310,可以看見數(shù)據(jù)庫testdb1和testdb2,且數(shù)據(jù)庫中的數(shù)據(jù)與master的數(shù)據(jù)庫數(shù)據(jù)一致.
11.t查看 E:\mysql\master\data\mysql-bin.000001 和E:\mysql\master\data\mysql-bin.index,可以看到被記錄的sql操作,
4.4.6 Tomcat HTTPS配置
在server.xml里配置:
tomcat普通的https配置
<Connector port="8443"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="conf/.keystore"
keystorePass="lizongbo">
</Connector>
Tomcat使用apr之后的ssl雙向認(rèn)證配置如下:
<Connector port="8443" maxHttpHeaderSize="8192" protocol="HTTP/1.1"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100" scheme="https" secure="true"
clientAuth="true" <!--雙向驗(yàn)證-->
SSLEngine="on" bufferSize="8192"
SSLEnabled="true"
SSLProtocol="all"
SSLCipherSuite="ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL"
SSLCertificateFile="..\conf\ca\www.crt"
SSLCertificateKeyFile="..\conf\ca\www.key"
SSLCACertificateFile="..\conf\ca\ca.crt"
SSLCACertificatePath="..\conf\ca"
SSLVerifyDepth="15"
SSLVerifyClient="require"
/>
4.6.6 Squid HTTPS
squid.conf中加上:
https_port 3443 cert=D:/ca/www.crt key=D:/ca/www.key
4.7.6 LightTPD HTTPS
首先使用copy命令把 key和crt合并為一個(gè)文件,
D:\ca>copy /b www.key+www.crt www.pem
然后配置如下:
$SERVER["socket"] == ":443" {
ssl.engine = "enable"
ssl.pemfile = "D:/ca/www.pem"
ssl.ca-file = "D:/ca/ca.crt"
server.name = "www"
server.document-root = "D:/httpsdosc"
server.errorlog = "httpserror.log"
accesslog.filename = "httpsaccess.log"
}
(下面的雙向驗(yàn)證沒有測試是否可用)
如需啟用雙向驗(yàn)證,則還需下面的配置參數(shù):
ssl.verify-peer = "enable"
ssl.verify-depth = 1
參考:http://trac.lighttpd.net/trac/ticket/921
2007年10月10日 #
2007年8月29日 #
1.取出discuz的當(dāng)前文件夾路徑.
2.根據(jù)php版本,對于小于4.1.0的php,設(shè)置相應(yīng)的變量.
3.載入全局函數(shù)庫 global.func.php
4.判斷網(wǎng)頁機(jī)器人,對于不允許的機(jī)器人,返回403
5.過濾cookie
6.初始化變量
$charset = $dbcharset = $forumfounders = $metakeywords = $extrahead = '';
$plugins = $hooks = $admincp = array();
7.載入全局配置 config.inc.php
8.判斷 論壇防御級別 作處理.
10.載入數(shù)據(jù)庫的class庫.
11.生成網(wǎng)站路徑 boardurl
12.獲取真實(shí)ip到 onlineip
13.正則解析ip
14.加載論壇配置參數(shù)緩存 /forumdata/cache/cache_settings.php
15.將settings中的變量轉(zhuǎn)換為全局變量.
16.判斷是否啟用gzip壓縮.
17.判斷l(xiāng)oadctrl負(fù)載參數(shù),對于非windows下超過負(fù)載的 情況,返回系統(tǒng)忙錯(cuò)誤.
18.對于幾個(gè)固定的請求,加載已經(jīng)生成的緩存數(shù)據(jù).
19.連接數(shù)據(jù)庫.
20.判斷用戶的安全提問
21.
附件下載流程 attachment.php
1.處理 common.inc.php 流程
2.檢查Referer頭信息
3.檢查每日下載限制時(shí)間 periodscheck
4.查詢附件信息檢查附件是否存在
5.判斷是否允許下載
6.判斷是否已經(jīng)購買
7.執(zhí)行購買操作.
8.執(zhí)行下載
1.搭建php版運(yùn)行環(huán)境,包括數(shù)據(jù)庫和discuz php版本的運(yùn)行,用于觀察了解
2.搭建java web應(yīng)用基礎(chǔ)庫,
3.對沒有主鍵的標(biāo)增加主鍵,用工具生成dao 層代碼.(注意jdbc的url里需要寫上charset)
4.生成logic層代碼
5.對應(yīng)每個(gè)控制層的php,轉(zhuǎn)換成對應(yīng)的spring mvc中的controller. 先從簡單的faq.php做起
action映射使用.php后綴.
視圖層使用jsp+jstl.
由于原有模板是以.htm方式存在的,
在轉(zhuǎn)換成jsp方式時(shí),對其中很多通用的代碼,可以通過替換的方式直接轉(zhuǎn)換為jstl語法的.
步驟如下:
1.首先將所有的htm文件名替換成jsp,
在命令行下運(yùn)行 rename *.htm *.jsp即可.
2.將bbs\forumdata\cache\style_1.php中的css變量TABLEWIDTH等,
替換成類似${crtStyles['TABLEWIDTH']}的jstl語法.
全部只能手工替換
3.將*.jsp中的{lang forum_favorite}等替換成類似 <fmt:message key="faq" bundle="${forum_favorite}"/>
使用正則表達(dá)式進(jìn)行替換:
editplus中的 查找內(nèi)容為: {lang (.+)},替換內(nèi)容為:<fmt:message key="faq" bundle="${\1}"/>
Jbuilder中的查找內(nèi)容為 \{lang (.+)\},Pattern為:Regular Expressions,
替換內(nèi)容為:(暫時(shí)未寫出來,打算寫程序進(jìn)行替換操作)
用java程序替換的核心代碼為:
//替換樣式變量
content = content.replaceAll("FORMHASH", "formhash");
//替換樣式變量 ${crtStyle['TABLEWIDTH']}
content = content.replaceAll("\\{([A-Z0-9]+)\\}", "\\${crtStyle\\['$1'\\]}");
//替換國際化定義
//content = content.replaceAll("\\{lang (.+?)\\}",
// "<fmt:message key=\"$1\" bundle=\"\\$\\{templates\\}\"/>");
//對標(biāo)簽屬性里的值暫時(shí)不替換
content = content.replaceAll("([^\"])\\{lang (.+?)\\}",
"$1<fmt:message key=\"$2\" bundle=\"\\$\\{templates\\}\"/>");
//替換單層的屬性訪問
content = content.replaceAll("\\$([a-z]+?)\\[([a-z]+?)\\]",
"\\$\\{$1\\['$2'\\]\\}");
//替換標(biāo)題部分的聲明
content = content.replaceAll("\\{template header\\}",
"<%@page pageEncoding=\"UTF-8\" " +
"contentType=\"text/html;" +
" charset=UTF-8\"%>\n"
+ "<%@include file=\"/WEB-INF/" +
"inc/taglibs.jspf\"%>\n" +
"<jsp:include flush=\"true\" " +
"page=\"header.jsp\"/>\n");
////替換底部部分的聲明
content = content.replaceAll("\\{template footer\\}",
"\n<jsp:include flush=\"true\" " +
"page=\"footer.jsp\"/>");
//替換其它引用聲明
content = content.replaceAll("\\{template (.+?)\\}",
"\n<jsp:include flush=\"true\" " +
"page=\"$1.jsp\"/>");
//替換url定義
content = content.replaceAll("\\$indexname", "\\${settings.indexname}");
//替換網(wǎng)站名字
content = content.replaceAll("\\$bbname", "\\${settings.bbname}");
//替換導(dǎo)航標(biāo)簽
content = content.replaceAll("\\$navigation", "\\${navigation}");
//替換一些變量
//content = content.replaceAll("\\$pid", "\\${pid}");
content = content.replaceAll("\\$([a-z_]+)(\"|<|\\))", "\\${$1}$2");
前言:discuz是一個(gè)很流行的 php論壇,一時(shí)好奇,打算學(xué)習(xí)并將其功能用java實(shí)現(xiàn)。
但是個(gè)人精力有限,只試著做了很小的一點(diǎn)功能。
但是在此過程中總結(jié)了一些經(jīng)驗(yàn):
需要轉(zhuǎn)換實(shí)現(xiàn)機(jī)制的模塊
1.計(jì)劃任務(wù)
由于php受語言限制,必須靠外界的訪問去觸發(fā)計(jì)劃任務(wù),而java則可以通過qutarz來做定時(shí)任務(wù).
因此可以采取spring配置 qutarz的方式去設(shè)置定時(shí)任務(wù).
2.風(fēng)格機(jī)制
使用.jsp,使用jstl語法,允許用戶寫jstl
依然按目錄存放到templates目錄下,每個(gè)風(fēng)格為一個(gè)文件夾.
3.緩存機(jī)制
使用oscache 標(biāo)簽 來緩存頁面的方式.
4.特殊標(biāo)簽的解析 hidden標(biāo)簽,reply標(biāo)簽
采取在顯示的時(shí)候,進(jìn)行 jsp:include page="/tag/hidden.jsp" 這樣的方式來實(shí)現(xiàn).
5.日歷選擇框: 使用jscalendar
6.頁面gzip壓縮,使用專門的gzip過濾器.
7.全文檢索,使用compass.
8.視圖層的模板.
discuz 已經(jīng)使用了 mvc的模式,只是使用自己開發(fā)的模板技術(shù),
D:\xampp\htdocs\bbs\templates每個(gè)文件夾為一個(gè)主題,每個(gè)主題內(nèi)對應(yīng)的是各種視圖的htm.
因此在用java實(shí)現(xiàn)的時(shí)候,使用spring mvc ,
視圖層使用jsp來展示.
其中頁面的布局分為三段
{template header} 是最上面的導(dǎo)航部分
{template footer} 是最下方的版權(quán)申明等部分.
中間部分為各具體模塊的視圖.
后臺則是使用的固定框架,然后來合成內(nèi)容的.
9.國際化支持
discuz使用的是 .lang.php定義數(shù)組的方式實(shí)現(xiàn)的,而且一次只支持一種語言
而java開發(fā)則使用I18N方式.多種語言均使用同一個(gè)系統(tǒng).
1.php的array功能非常強(qiáng)大,而java中只能用map和list結(jié)合起來處理.
2.在一個(gè)http請求中php的變量幾乎都是全局生效,而jstl中,則可以放到requestScope中.
1.discuz的有些表的主鍵不是自動增長的,因此不能夠生成@GeneratedValue(strategy = GenerationType.AUTO)的注釋.
這些表有: new String[] {
"validating", "trades", "relatedthreads", "pushedthreads", "polls",
"onlinetime", "memberspaces", "memberfields", "forumfields",
"admingroups", "adminactions", "activities"}
2.mysql的hibernate dao單元測試中,insert是無法回滾的,而delete卻可以不操作數(shù)據(jù)庫,
因此crud單元測試的時(shí)候,導(dǎo)致不停的插入數(shù)據(jù)卻沒有刪除數(shù)據(jù).
解決辦法,在 crud 測試方法的最后加上一行代碼: this.setComplete();
3.mysql的jdbc需要幾個(gè)特殊設(shè)置
a.字符編碼集必須指定.
b.對于"0000-00-00" 這樣的默認(rèn)日期,在轉(zhuǎn)化成java.sql.Date的時(shí)候會出錯(cuò),因此需要加上個(gè)zeroDateTimeBehavior屬性.
datasource.url=jdbc:mysql://localhost:3306/discuz?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
4.mysql的jdbc驅(qū)動存在bug : http://bugs.mysql.com/bug.php?id=22215
在usergroups 表中, readaccess字段是 tinyint(3)類型,而有值為200的,mysql的jdbc就會報(bào)錯(cuò),說數(shù)字越界了.
java.sql.SQLException: '200' in column '1' is outside valid range for the
datatype TINYINT.
暫時(shí)無解決辦法,采取修改200為20回避之.
(update:后來使用Short代替byte類型)
discuz 已經(jīng)使用了 mvc的模式,只是使用自己開發(fā)的模板技術(shù),
D:\xampp\htdocs\bbs\templates每個(gè)文件夾為一個(gè)主題,每個(gè)主題內(nèi)對應(yīng)的是各種視圖的htm.
因此在用java實(shí)現(xiàn)的時(shí)候,使用spring mvc ,
視圖層使用jspx來展示.
其中頁面的布局分為三段
{template header} 是最上面的導(dǎo)航部分
{template footer} 是最下方的版權(quán)申明等部分.
中間部分為各具體模塊的視圖.
后臺則是使用的固定框架,然后來合成內(nèi)容的.
2007年1月22日 #
2007年1月17日 #