星期四, 11月 18, 2004

桂林遊

2004年11月6日至2004年11月10日共五天 , 與父母及老婆參加鳳凰旅行社至桂林遊玩.

其中印象比較深刻的是坐船遊漓江,真不愧是百里畫廊,沿途風光相當漂亮,真像是置身於山水畫中.
張藝謀導演的印象劉三姐實景表演真是精彩,令人難忘!
堯山更是不可不去,坐覽車大約20分鐘上堯山,觀看整個桂林,飄渺之間,如詩如畫.

在桂林買東西,大概都可以標價的2折價錢購買到,不殺價就是冤大頭了 :P

星期二, 10月 19, 2004

壓縮 MS SQL 2000 中的資料檔及交易明細檔

use 資料庫名稱
Backup Log 資料庫名稱 with Truncate_only
DBCC ShrinkDataBase (資料庫名稱) --壓縮資料檔 --> *.mdf
DBCC ShrinkFile (資料庫名稱_log) --壓縮交易紀錄檔 --> *.ldf


http://charlesbc.blogspot.tw/2011/01/sql-server-log.html
SQL Server 2008

到了 SQL Server 2008,Trancate_only 的指令正式被取消了。由於資料庫的復原模式為簡單的情形下是不記錄所有的 log資料的。我們可以利用這一點清除 log 資料。因此,替代的方法,是將資料庫的復原模式先換成簡單模式,再調整為完整。指令如下

use master
go

--備份目前的 log
backup log DatabaseName to disk='c:\db.log' WITH NOFORMAT
--將資料庫復原模式切換到簡單模式
ALTER DATABASE DatabaseName SET RECOVERY SIMPLE WITH NO_WAIT


--找到 DatabaseNameLog 的值
use DatabaseName
go
select name from sys.database_files
where type_desc = 'log'

--縮減 log file 到 1MB
DBCC SHRINKFILE(DatabaseNameLog, 1)


--將資料庫復原模式切換到完整模式
USE [master]
GO
ALTER DATABASE [DatabaseName] SET RECOVERY FULL WITH NO_WAIT

星期二, 10月 05, 2004

Freebsd and Debian

前一陣子因工作需求,同時使用Freebsd與Debian,
Freebsd 的 port 與 Debian 的 apt 都相當好用,
只不過同時使用這兩個作業系統時,常會指令混淆~~ :-)

星期五, 8月 27, 2004

使用nagios 配合 twsms 監測系統

先說明, 以下是用 debian 完成 , 安裝細節不多說
還有必須先至 http://www.twsms.com 購買通數
這只是簡單說明, 詳細使用還請自行查看 Document

1. 先安裝好 apache2
2. 安裝 nagios
apt-get install nagios
使用 htpasswd2 建立使用者
例如要建立 miles 這個使用者
htpasswd -c /etc/nagios/htpasswd.users miles
輸入密碼即可
chmod 640 htpasswd.users


3. nagios 的設定檔是在 /etc/nagios

4. 設定好 apache2 與 nagios 的連結

cd /etc/apache2/conf.d
ln -s /etc/nagios/apache.conf nagios
/etc/init.d/apache2 restart



5. 修改 nagios 設定檔
cd /etc/nagios
先修改nagios.cfg
大部份用預設值即可, 我是只修改
admin_email=nagios
admin_pager=pagenagios
這兩項的值, 改為我需要的Email
6. 修改 cgi.cfg
主要是修改有關 authorized 的選項即可
修改為之前用htpasswd2建立的使用者

7. 修改 contactgroups.cfg
這是設定系統聯絡人群組
例如我的設定

# 'linux-admins' contact group definition
define contactgroup{
contactgroup_name linux-admins
alias Linux Administrators
members nagios,miles
}


表是 linux-admins 這個系統群組的人員有nagios及miles

8. 修改 contacts.cfg
例如我的設定

# 'miles' contact definition
define contact{
contact_name miles
alias Nagios Admin
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-by-sms
host_notification_commands host-notify-by-email
email my@email.server
}


其中 service_notification_commands notify-by-sms
當中的 notify-by-sms , 等一下在misccommands.cfg 中會加上
這是指當service有問題時,如何通知系統人員

9. 修改 hostgroups.cfg
這是設定主機群組
例如我的設定檔

# 'linux-boxes' host group definition
define hostgroup{
hostgroup_name linux-boxes
alias Linux Servers
contact_groups linux-admins
members debian,Mandrake
}


表示 linux-boxes 這個主機群組包括debian及Mandrake這兩台主機, 其系統聯絡人群組為 linux-admins
linux-admins 包括兩位人員miles及nagios , 這在之前已設定過了

10. 修改 hosts.cfg
第一項中的
# Generic host definition template
建議使用預設值
只要在其後面加上
例如我的設定檔

# 'linux' host definition
define host{
use generic-host ; Name of host template to use host_name debian
alias realserver
address 192.168.1.226
check_command check-host-alive
max_check_attempts 10
notification_interval 120
notification_period 24x7
notification_options d,u,r
}


其中 check_command check-host-alive 是表示要檢查系統是否存活, 可在checkcommands.cfg 找到相關資訊
# Generic service definition template
11. 修改 services.cfg
同樣的, 建議以下也使用預設值
# Generic service definition template

然後加上有關設定, 例如

# Service definition
define service{
use generic-service ; Name of service template to use
host_name debian
service_description HTTP is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 5
retry_check_interval 1
contact_groups linux-admins
notification_interval 120
notification_period 24x7
notification_options w,u,c,r
check_command check_http
}


表示要對 debian這台主機監測 http的服務
其系統聯絡人群組是linux-admins

12. 修改 misccommands.cfg
使其系統有問題時能用手機簡訊通知
在檔案中加上

# 'notify-by-sms' command definition
define command{
command_name notify-by-sms
command_line /usr/bin/printf "%b" "pw:yourpasswd\nmobile:09xxxxxxxx" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" yourid.sms@twsms.com
}


其中 yourpasswd 就是指你在 twsms中的密碼,
yourid就是帳號,09xxxxxxxx 就是你的手機號碼

13. 檢查 nagios 的設定檔是否正確
nagios -v nagios.cfg
如果沒問題, 啟動 /etc/init.d/nagios start

14. 進入 http://your.server.name/nagios
輸入之前設定的帳號密碼

15. 記得要 Enable checks of this host 和
Enable checks of this service
Enable notifications for this host
Enable notifications for this service
如此系統有問題時才會通知喔
_________________

星期五, 8月 20, 2004

使用 rsync 來做備份

rsync 的安裝方式很簡單, 在此就不多說
設定檔也很簡單, 也不詳述
client 端執行 rsync 時並不需要是 root , 一般 user 也可以
目的端的目錄權限必須設定好, 否則備份會有問題喔
例如:
在 server 端中的 rsyncd.conf 中設定 ,
[webs]
path = /var/www/test
auth users=miles
uid=miles
gid=users

在 clinet 端執行
rsync -avzP --delete --password-file=/home/miles/rsync/rsyncd.secrets
/var/www/test/ miles@my.server::webs

則其中server 端的 /var/www/test 目錄必須要能有 miles:users 的讀寫權限喔

星期日, 7月 25, 2004

挪威的森林

剛剛開車時聽到廣播傳來伍佰的歌曲-挪威的森林
讓我又想起以前在高雄岡山當兵時的情形,
當時剛下部隊,很菜,被派到大門口支援一分鐘待命班,
那時後一個快退伍的下士班長每天都用他那台破破的隨身聽
播放伍佰的歌曲.
真是一段很令人難忘的軍旅生活~~

陸軍獨立64旅戰車742營部連.

星期五, 7月 23, 2004

分離式冷氣還是比較好

上星期在家裡的另外一間房間安裝了分離式冷氣,
以方便若家人或朋友來住時就有冷氣可吹.
果然還是分離式的冷氣較好, 吹一下子房間就很涼了.
這幾天剛好家人來, 正好派上用場~~

星期四, 7月 22, 2004

使用 Google Web APIs 及 php 實現網站內容全文檢索

使用 Google Web APIs 及 php 實現網站內容全文檢索
1. 先至
http://www.google.com/apis/
申請一個帳號 , 並且取得一組序號

2. 至 http://www.digitalpoint.com/tools/search/
下載 search.zip , 並將其解壓縮至網頁目錄

3. 修改 results.php
將 $key="1234567890";
更改為 google 給你的那一組序號

將 $site="www.yoursite.com"
更改為你想要查詢的網站

4. 編寫測試網頁
在同一目錄下, 編寫一個網頁 mysearch.big5
其內容為

<HTML>
<HEAD>
<META NAME="Content-Type" Content="text/html; charset=utf-8">
<TITLE>mnoGoSearch: </TITLE>
</HEAD>
測試 Google Web APIs <hr>
<FORM METHOD="get" ACTION="results.php">
<INPUT TYPE="text" NAME="q" VALUE="">
<INPUT TYPE="submit" VALUE="Search!">
</FORM>

然後將其內容轉成 utf-8 格式
iconv -f big5 -t utf-8 mysearch.big5 > mysearch.htm

5. 測試網頁
連接到 mysearch.htm , 隨便敲個關鍵字試看看

6. 詳細說明
http://www.digitalpoint.com/tools/search/

MnoGoSearch 網站內容全文檢索

MnoGoSearch 網站內容全文檢索
網頁:
http://www.mnogosearch.org/

MnoGoSearch 3.2 版以後已支援雙位元的字碼 , 如繁體中文, 簡體中文, 日文等等

安裝方式:

請先至 http://www.mnogosearch.org/下載軟體

將其解壓縮後, 執行 ./configure --help 可以查看其相關設定

例如要使用postgresql的資料庫, 並加入雙位元字的支援, 則下

./configure --with-extra-charsets=all --with-pgsql

執行make , 如果沒有問題, 則執行 make install

預設程式會安裝在 /usr/local/mnogosearch 中

將 /usr/local/mnogosearch/bin/search.cgi 覆製到 Apache 的cgi-bin目錄中

建立一個資料庫, createdb mnoGoSearch

初始化此資料庫 /usr/local/mnogosearch/sbin/indexer -Ecreate

cd /usr/local/mnogosearch/etc/

cp indexer.conf-dist indexer.conf , 然後修改indexer.conf

重點是修改

#DBAddr mysql://foo:bar@localhost/mnogosearch/?dbmode=single



LocalCharset 使用UTF-8 , 及加上

LoadChineseList BIG5 /usr/local/mnogosearch/etc/TraditionalChinese.freq

最後修改

Server http://your.server.name/

cp langmap.conf-dist langmap.conf; cp search.htm-dist search.htm; cp stopwords.conf-dist stopwords.conf

修改search.htm

重點是修改

#DBAddr mysql://foo:bar@localhost/udm/?dbmode=single

DBAddr pgsql://yourname:yourpassword@localhost/mnoGoSearch/?dbmode=single

#LocalCharset iso-8859-1

LocalCharset utf-8

#BrowserCharset iso-8859-1

BrowserCharset big5

執行 /usr/local/mnogosearch/sbin/indexer -a

測試 http://your.server.name/cgi-bin/search.cgi

於 Mandrake 9.2上安裝SASL for postfix

於 Mandrake 9.2上安裝SASL for postfix
必要套件
cyrus-sasl-2.1.15-4mdk
libsasl2-devel-2.1.15-4mdk
libsasl2-2.1.15-4mdk
libsasl2-plug-login-2.1.15-4mdk
libsasl2-plug-plain-2.1.15-4mdk

SASL的設定
1.cd /usr/lib/sasl2
2.vi smtpd.conf , 其內容為
pwcheck_method: saslauthd
mech_list:plain login
3.查看saslauthed 是否有啟動,若沒有, 則執行 service saslauthed start

pam的設定
1. cd /etc/pam.d
2. ln -s imap smtp
3. ln -s imap mail

POSTFIX 的設定
1. vi /etc/postfix/master.cf
將 smtp inet n - y - - smtpd
改為 smtp inet n - n - - smtpd

2.
vi /etc/postfix/main.cf

broken_sasl_auth_clients = yes
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain =
smtpd_recipient_restrictions = permit_mynetworks ,permit_sasl_authenticated, check_relay_domains
smtpd_sasl_security_options = noanonymous

測試
1. 先產生密碼, 例如帳號 test , 密碼為 5555, 則執行
printf 'testtest5555' | mmencode
然後將結果複製起來, 例如是: @#$%!@#%
2. 重新啟動 postfix
/etc/rc.d/init.d/postfix restart

3. telnet localhost 25
ehlo localhost
auth plain @#$%!@#%




使用 iptables 設定基本的單機版防火牆

使用 iptables 設定基本的單機版防火牆

#!/bin/sh# 簡單的單機版防火牆設定範例
# 重設所有的規則
iptables -F
iptables -t nat -F
iptables -t mangle -F
# 定義預設的規則
iptables -P FORWARD DROP
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
# 允許所有本機的連線
iptables -A INPUT -i lo -j ACCEPT
# 允許 ssh 連線 , 其他的服務請自行設定
iptables -A INPUT -i eth0 -p tcp --dport 22 -j ACCEPT
# iptables -A INPUT -i eth0 -p tcp --dport 23 -j ACCEPT
# iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT
# iptables -A INPUT -p tcp -d 192.168.1.226 -j ACCEPT
# 是否要紀錄log
# iptables -A INPUT -p tcp -d 0.0.0.0/24 -j LOG --log-prefix "DROP_AAA__ " --log-level info
# iptables -A INPUT -p tcp --dport 1:65535 -j LOG --log-prefix "DROP_BBB__ " --log-level info
# 允許所有本機主動的連線
iptables -A INPUT -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
# 拒絕所有非本機主動的連線
iptables -A INPUT -i eth0 -m state --state NEW,INVALID -j DROP