每月彙整: 2009 年 12 月

快快樂樂打造你自已的port

以我自已弄的Net-POP3-SSLWrapper為例
# mkdir /root/Net-POP3-SSLWrapper

# vim Makefile

# New ports collection makefile for: p5-Net-POP3-SSLWrapper
# Date created: 16 December 2009
# Whom: johnpupu 
#
# $FreeBSD$
#

PORTNAME= Net-POP3-SSLWrapper
PORTVERSION= 0.02
CATEGORIES= mail perl5
MASTER_SITES= CPAN
PKGNAMEPREFIX= p5-

MAINTAINER= johnpupu@gmail.com
COMMENT= Perl extension for simple POP3S wrapper for Net::POP3

BUILD_DEPENDS= ${SITE_PERL}/IO/Socket/SSL.pm:${PORTSDIR}/security/p5-IO-Socket-SSL

PERL_CONFIGURE= yes

MAN3= Net::POP3::SSLWrapper.3

.include <bsd.port.mk>

整個Makefile 我是看相同類型的port的Makefile 來參考的

#vim pkg-descr

This is a port of Net-POP3-SSLWrapper.

WWW: http://search.cpan.org/dist/Net-POP3-SSLWrapper/

#fetch http://search.cpan.org/CPAN/authors/id/T/TO/TOKUHIROM/Net-POP3-SSLWrapper-0.02.tar.gz
#mv Net-POP3-SSLWrapper-0.02.tar.gz /usr/ports/distfiles
#cd /root/Net-POP3-SSLWrapper
#make makesum
這樣/root/Net-POP3-SSLWrapper 目錄裡應該就會有 Makefile, distinfo, pkg-descr 三個檔案
#cd /root/Net-POP3-SSLWrapper
#portlint -a ### 檢查Makefile 有沒有問題
#cp -Rp /root/Net-POP3-SSLWrapper /root/Net-POP3-SSLWrapper.new
#/root/create_pkg.sh /root/Net-POP3-SSLWrapper /root/Net-POP3-SSLWrapper.new
#cp /root/Net-POP3-SSLWrapper.new/pkg-plist /root/Net-POP3-SSLWrapper
這樣 應該就差不多了

然後 寫個測試的perl 看看有沒有問題
我原先的Makefile 是沒寫到BUILD_DEPENDS= ${SITE_PERL}/IO/Socket/SSL.pm:${PORTSDIR}/security/p5-IO-Socket-SSL
是看測試的perl 說沒有這個module 才去補上這個dependency

送pr …
#shar `find /root/Net-POP3-SSLWrapper -print` > ~/Net-POP3-SSLWrapper.shar
#send-pr -a ~/Net-POP3-SSLWrapper.shar -c 長輩的e-mail

PS:
1.
create_pkg.sh 請參考
http://blog.wu-boy.com/2009/11/18/1843/

2.
http://www.freebsd.org/doc/zh_TW/books/porters-handbook/plist-autoplist.html
這個自動產生pkg-plist的指令請在bash 底下run
csh 跑不起來..

3.我還沒驗證重作一遍…..不確定過程是完全沒少的

4.
得cls_bsd長輩指點
可以用
ports-mgmt/porttools
來檢查port 對不對
就直接在port 資料夾裡
port test 就會列出是否有錯誤了

5.
Q:
WARN: Makefile: “BUILD_DEPENDS” has to appear earlier.

A:
RUN_DEPENDS和BUILD_DEPENDS
中間不要有空行

6.
要是出現
FATAL: Makefile: duplicated manpage entry Net::POP3::SSLWrapper.3: content of MAN3 will be automatically added to pkg-plist.
表示沒把pkg-plist 中的man文件刪掉
所以請把pkg-plist 中的man 幹掉

手冊寫到
The MAN[1-9LN] variables will automatically add any manpages to pkg-plist (this means you must not list manpages in the pkg-plist——see generating PLIST for more).

ref.
http://www.freebsd.org/doc/zh_TW/books/porters-handbook/index.html
http://blog.wu-boy.com/2009/11/18/1843/
http://blog.wu-boy.com/2009/09/22/1670/
http://www.ptt.cc/man/FreeBSD/DEBD/D160/M.1135705310.A.E5B.html
http://blog.dragon2.net/2009/12/17/912.php

benchmarking with sysbench on X3650 M2

手邊剛好有x3650m2的機器
順手測了一下…FreeBSD 7.1 i386 & FreeBSD 8.0 AMD64
Jeff Roberson弄一下..XD
就沒圖先看數據吧…

CPU: Intel(R) Xeon(R) CPU E5520 @ 2.27GHz (2266.76-MHz 686-class CPU)
real memory = 2137583616 (2038 MB)==>其實這台機器有12G, 不過i386只抓得到2G
avail memory = 2081353728 (1984 MB)
RAID 5 / 四顆 IBM 43W7538 146.8GB 10Krpm SAS
RAID controller MR10i

——————7.1 i386 ———————–

uname -a
FreeBSD ms1.xxx.xxx.xx 7.1-RELEASE-p9 FreeBSD 7.1-RELEASE-p9 #0: Tue Dec 15 15:53:44 CST 2009 root@xxx.xxx.xxx:/usr/obj/usr/src/sys/GENERIC i386

mysql-server-5.0.77

[sourcecode language=’sh’]
sysbench –test=oltp –num-threads=5 –mysql-user=root –max-time=60 –mysql-db=test –max-requests=0 –oltp-read-only=on run
[/sourcecode]

OLTP test statistics:
queries performed:
read: 6075594
write: 0
other: 867942
total: 6943536
transactions: 433971 (7232.78 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 6075594 (101258.95 per sec.)
other operations: 867942 (14465.56 per sec.)
Test execution summary:
total time: 60.0006s
total number of events: 433971
total time taken by event execution: 293.7474
per-request statistics:
min: 0.47ms
avg: 0.68ms
max: 1.16ms
approx. 95 percentile: 0.79ms
Threads fairness:
events (avg/stddev): 86794.2000/4495.36
execution time (avg/stddev): 58.7495/0.10

[sourcecode language=’sh’]
sysbench –test=oltp –num-threads=10 –mysql-user=root –max-time=60 –mysql-db=test –max-requests=0 –oltp-read-only=on run
[/sourcecode]

OLTP test statistics:
queries performed:
read: 9777810
write: 0
other: 1396830
total: 11174640
transactions: 698415 (11640.11 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 9777810 (162961.49 per sec.)
other operations: 1396830 (23280.21 per sec.)
Test execution summary:
total time: 60.0007s
total number of events: 698415
total time taken by event execution: 590.1649
per-request statistics:
min: 0.48ms
avg: 0.85ms
max: 205.14ms
approx. 95 percentile: 0.98ms
Threads fairness:
events (avg/stddev): 69841.5000/1335.06
execution time (avg/stddev): 59.0165/0.02

[sourcecode language=’sh’]
sysbench –test=oltp –num-threads=15 –mysql-user=root –max-time=60 –mysql-db=test –max-requests=0 –oltp-read-only=on run
[/sourcecode]

OLTP test statistics:
queries performed:
read: 12752964
write: 0
other: 1821852
total: 14574816
transactions: 910926 (15181.88 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 12752964 (212546.30 per sec.)
other operations: 1821852 (30363.76 per sec.)
Test execution summary:
total time: 60.0009s
total number of events: 910926
total time taken by event execution: 886.4647
per-request statistics:
min: 0.56ms
avg: 0.97ms
max: 402.33ms
approx. 95 percentile: 1.01ms
Threads fairness:
events (avg/stddev): 60728.4000/606.53
execution time (avg/stddev): 59.0976/0.02

[sourcecode language=’sh’]
sysbench –test=oltp –num-threads=20 –mysql-user=root –max-time=60 –mysql-db=test –max-requests=0 –oltp-read-only=on run
[/sourcecode]

OLTP test statistics:
queries performed:
read: 13327272
write: 0
other: 1903896
total: 15231168
transactions: 951948 (15865.47 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 13327272 (222116.62 per sec.)
other operations: 1903896 (31730.95 per sec.)
Test execution summary:
total time: 60.0012s
total number of events: 951948
total time taken by event execution: 1186.0876
per-request statistics:
min: 0.64ms
avg: 1.25ms
max: 994.84ms
approx. 95 percentile: 1.99ms
Threads fairness:
events (avg/stddev): 47597.4000/2590.43
execution time (avg/stddev): 59.3044/0.04

[sourcecode language=’sh’]
sysbench –test=oltp –num-threads=30 –mysql-user=root –max-time=60 –mysql-db=test –max-requests=0 –oltp-read-only=on run
[/sourcecode]

OLTP test statistics:
queries performed:
read: 8234198
write: 0
other: 1176314
total: 9410512
transactions: 588157 (9802.05 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 8234198 (137228.77 per sec.)
other operations: 1176314 (19604.11 per sec.)
Test execution summary:
total time: 60.0034s
total number of events: 588157
total time taken by event execution: 1791.4983
per-request statistics:
min: 0.59ms
avg: 3.05ms
max: 1020.70ms
approx. 95 percentile: 7.91ms
Threads fairness:
events (avg/stddev): 19605.2333/3866.54
execution time (avg/stddev): 59.7166/0.06

[sourcecode language=’sh’]
sysbench –test=oltp –num-threads=40 –mysql-user=root –max-time=60 –mysql-db=test –max-requests=0 –oltp-read-only=on run
[/sourcecode]

OLTP test statistics:
queries performed:
read: 6483008
write: 0
other: 926144
total: 7409152
transactions: 463072 (7717.23 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 6483008 (108041.20 per sec.)
other operations: 926144 (15434.46 per sec.)
Test execution summary:
total time: 60.0050s
total number of events: 463072
total time taken by event execution: 2393.3892
per-request statistics:
min: 0.62ms
avg: 5.17ms
max: 1218.90ms
approx. 95 percentile: 11.50ms
Threads fairness:
events (avg/stddev): 11576.8000/390.35
execution time (avg/stddev): 59.8347/0.02

——————-8.0 AMD 64—————————-

uname -a
mysql-server-5.1.41

FreeBSD ms2.xxx.xxx.xx 8.0-RELEASE FreeBSD 8.0-RELEASE #0: Sat Nov 21 15:02:08 UTC 2009 root@mason.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64

[sourcecode language=’sh’]
sysbench –test=oltp –num-threads=5 –mysql-user=root –max-time=60 –mysql-db=test –max-requests=0 –oltp-read-only=on run
[/sourcecode]

OLTP test statistics:
queries performed:
read: 6130026
write: 0
other: 875718
total: 7005744
transactions: 437859 (7297.57 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 6130026 (102166.01 per sec.)
other operations: 875718 (14595.14 per sec.)
Test execution summary:
total time: 60.0006s
total number of events: 437859
total time taken by event execution: 296.7323
per-request statistics:
min: 0.51ms
avg: 0.68ms
max: 1.45ms
approx. 95 percentile: 0.77ms
Threads fairness:
events (avg/stddev): 87571.8000/2867.68
execution time (avg/stddev): 59.3465/0.03

[sourcecode language=’sh’]
sysbench –test=oltp –num-threads=10 –mysql-user=root –max-time=60 –mysql-db=test –max-requests=0 –oltp-read-only=on run
[/sourcecode]

OLTP test statistics:
queries performed:
read: 9962218
write: 0
other: 1423174
total: 11385392
transactions: 711587 (11859.65 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 9962218 (166035.11 per sec.)
other operations: 1423174 (23719.30 per sec.)
Test execution summary:
total time: 60.0007s
total number of events: 711587
total time taken by event execution: 593.2102
per-request statistics:
min: 0.50ms
avg: 0.83ms
max: 2.41ms
approx. 95 percentile: 0.93ms
Threads fairness:
events (avg/stddev): 71158.7000/2261.35
execution time (avg/stddev): 59.3210/0.01

[sourcecode language=’sh’]
sysbench –test=oltp –num-threads=15 –mysql-user=root –max-time=60 –mysql-db=test –max-requests=0 –oltp-read-only=on run
[/sourcecode]

OLTP test statistics:
queries performed:
read: 13259092
write: 0
other: 1894156
total: 15153248
transactions: 947078 (15784.37 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 13259092 (220981.20 per sec.)
other operations: 1894156 (31568.74 per sec.)
Test execution summary:
total time: 60.0010s
total number of events: 947078
total time taken by event execution: 889.9460
per-request statistics:
min: 0.63ms
avg: 0.94ms
max: 20.56ms
approx. 95 percentile: 1.06ms
Threads fairness:
events (avg/stddev): 63138.5333/1133.73
execution time (avg/stddev): 59.3297/0.01

[sourcecode language=’sh’]
sysbench –test=oltp –num-threads=20 –mysql-user=root –max-time=60 –mysql-db=test –max-requests=0 –oltp-read-only=on run
[/sourcecode]

OLTP test statistics:
queries performed:
read: 13220214
write: 0
other: 1888602
total: 15108816
transactions: 944301 (15737.99 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 13220214 (220331.79 per sec.)
other operations: 1888602 (31475.97 per sec.)
Test execution summary:
total time: 60.0014s
total number of events: 944301
total time taken by event execution: 1190.1741
per-request statistics:
min: 0.74ms
avg: 1.26ms
max: 563.96ms
approx. 95 percentile: 1.87ms
Threads fairness:
events (avg/stddev): 47215.0500/2867.47
execution time (avg/stddev): 59.5087/0.03

[sourcecode language=’sh’]
sysbench –test=oltp –num-threads=30 –mysql-user=root –max-time=60 –mysql-db=test –max-requests=0 –oltp-read-only=on run
[/sourcecode]

OLTP test statistics:
queries performed:
read: 13463828
write: 0
other: 1923404
total: 15387232
transactions: 961702 (16027.97 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 13463828 (224391.57 per sec.)
other operations: 1923404 (32055.94 per sec.)
Test execution summary:
total time: 60.0015s
total number of events: 961702
total time taken by event execution: 1789.5202
per-request statistics:
min: 0.81ms
avg: 1.86ms
max: 681.42ms
approx. 95 percentile: 2.84ms
Threads fairness:
events (avg/stddev): 32056.7333/2107.91
execution time (avg/stddev): 59.6507/0.03

[sourcecode language=’sh’]
sysbench –test=oltp –num-threads=40 –mysql-user=root –max-time=60 –mysql-db=test –max-requests=0 –oltp-read-only=on run
[/sourcecode]

OLTP test statistics:
queries performed:
read: 12487580
write: 0
other: 1783940
total: 14271520
transactions: 891970 (14865.73 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 12487580 (208120.26 per sec.)
other operations: 1783940 (29731.47 per sec.)
Test execution summary:
total time: 60.0018s
total number of events: 891970
total time taken by event execution: 2390.2678
per-request statistics:
min: 0.89ms
avg: 2.68ms
max: 726.19ms
approx. 95 percentile: 3.32ms
Threads fairness:
events (avg/stddev): 22299.2500/1868.45
execution time (avg/stddev): 59.7567/0.02

apache-worker&php5&mod_fastcgi

[sourcecode language=’sh’]
cd /usr/ports/www/apache22
make WITH_MPM=worker install clean
[/sourcecode]

[sourcecode language=’sh’]
cd /usr/ports/lang/php5; make install clean
[/sourcecode]

[sourcecode language=’sh’]
cd /usr/ports/www/mod_fastcgi
make install clean
[/sourcecode]

httpd.conf 中新增or把註解拿掉這兩行
LoadModule fastcgi_module libexec/apache22/mod_fastcgi.so
Include etc/apache22/extra/httpd-mpm.conf

編輯
/usr/local/etc/apache22/extra/httpd-mpm.conf
[sourcecode language=’sh’]
ThreadLimit 512
StartServers 1
MaxClients 512
MinSpareThreads 1
MaxSpareThreads 512
ThreadsPerChild 512
MaxRequestsPerChild 0
[/sourcecode]

新增/usr/local/etc/apache22/Includes/fastcgi.conf
[sourcecode language=’sh’]
AddType application/x-httpd-php .php

ScriptAlias /php-fcgi “/usr/local/bin/php-cgi”

FastCgiServer “/usr/local/bin/php-cgi” -initial-env PHP_FCGI_CHILDREN=32


Options ExecCGI FollowSymLinks
SetHandler fastcgi-script
Order allow,deny
Allow from all

Action application/x-httpd-php /php-fcgi
[/sourcecode]

ps
若之前php 是用php5_module來啟的話
記得把相關的php 都重編…
不然會一直出現
kernel: pid 86212 (php-cgi), uid 80: exited on signal 11
若一直出現這個就先把extension 都先拔掉

ref.
http://blog.wu-boy.com/2008/09/13/388/
http://blog.gslin.org/archives/2008/08/17/1624/
wens’s comment on http://blog.gslin.org/archives/2008/08/17/1624/

dovecot-lda

dovecot.conf

auth default {
  socket listen {
    master {
      # Master socket provides access to userdb information. It's typically
      # used to give Dovecot's local delivery agent access to userdb so it 
      # can find mailbox locations.
      path = /var/run/dovecot/auth-master
      mode = 0600
      # Default user/group is the one who started dovecot-auth (root)
      user = vmail
      group = mail
    }
  }
}

master.cf

dovecot unix - n n - - pipe
flags=DRhu user=vmail:vmail argv=/usr/local/libexec/dovecot/deliver -f ${sender} -d ${recipient}

mail.cf

dovecot_destination_concurrency_limit = 1
dovecot_destination_recipient_limit = 1
virtual_transport = dovecot

dovecot-sql.conf

user_query = SELECT concat(/home/mbox/', maildir) AS home, 'maildir:/home/mbox/%u' AS mail , 150 AS uid, 150 AS gid FROM mailbox WHERE username = '%u' AND active = '1'

password_query = SELECT username AS user, password, concat('/home/mbox/', maildir) AS userdb_home, 'maildir:/home/mbox/%u' AS userdb_mail, 150 AS userdb_uid, 150 AS userdb_gid FROM mailbox WHERE username = '%u' AND active = '1'

ref.
http://wiki.dovecot.org/LDA/Postfix

Q:
Dec 12 02:28:15 mail dovecot: deliver(johnpupu@example.tw): Fatal: setgid(125(postfix)) failed with euid=143(dovecot), gid=6(mail), egid=6(mail): Operation not permitted

A:
像這樣的uid錯誤就是,dovecot-sql.conf 這個 uid 和master.cf中設的user id 沒不一樣造成的..

Q:
Dec 12 16:36:07 mail dovecot: deliver(johnpupu@example.tw): mail_location: Ambiguous mail location setting, don’t know what to do with it: /home/mbox/johnpupu@example.tw (try prefixing it with mbox: or maildir:)

A:
請乖乖的在dovecot-sql.conf把
maildir: 加在你的/home/mbox/%u 前面
就好了…

Q:
Relative home directory paths not supported (user johnpupu@example.tw): maildir:/home/mbox/johnpupu@example.tw

A:
這個問題就是user_query 的home 設錯了..
請設成
SELECT concat(‘/home/mbox/’, maildir) AS home,
就好了….
把mail_debug=yes 打開會看的滿清楚的