Skip to content


linux下自动校时

在root用户下编辑启动脚本

vi /etc/rc.d/rc.local #加一句

/usr/bin/rdate -s time-a.nist.gov

ntp比较麻烦点 crontab 可能造成时间不连续

time-a.nist.gov 注:美国NIST守时中心 time.join.uni-muenster.de

Posted in linux 维护优化, 技术.


memcached 和imagemagick安装

www.danga.com 下载

  • memcached-1.1.13.tar.gz — Sep 9, 2006

wget http://www.danga.com/memcached/dist/memcached-1.1.13.tar.gz tar -zxvf memcached-1.1.13.tar.gz cd memcached-1.1.13 sudo ./configure –prefix=/opt/memcahed sudo make sudo make install /opt/memcached/bin/memcached -d -m 2

imagemagick

Jpeg v6b、libPng、FreeType 的要在安装imagemagick之前先装好,否则imagemagick没法读取jpeg和png图片

wget ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz

tar zxvf jpegsrc.v6b.tar.gz

cd jpeg-6b

./configure –prefix=/usr/local/jpeg-6b –enable-shared –enable-static make mkdir /usr/local/jpeg-6b mkdir /usr/local/jpeg-6b/include mkdir /usr/local/jpeg-6b/lib mkdir /usr/local/jpeg-6b/bin mkdir /usr/local/jpeg-6b/man mkdir /usr/local/jpeg-6b/man/man1 make install

 ———————————————————————-

wget http://download.savannah.gnu.org/releases/freetype/freetype-2.3.5.tar.gz

tar zxvf freetype-2.3.5.tar.gz

cd freetype-2.3.5.tar.gz

./configure –prefix=/usr/local/freetype

make

make install

cp /usr/local/freetype/include/freetype2/freetype/* /usr/local/include/


wget http://www.zlib.net/zlib-1.2.3.tar.gz

tar zxvf zlib-1.2.3.tar.gz

cd zlib-1.2.3

./configure –prefix=/usr/local/zlib

make

make install


wget http://jaist.dl.sourceforge.net/sourceforge/libpng/libpng-1.2.29.tar.gz

 tar zxvf libpng-1.2.29.tar.gz

 cd libpng-1.2.29

./configure  prefix=/usr/local/libpng

make

make install


http://www.imagemagick.org/script/install-source.php#unix

wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz

tar zxvf ImageMagick.tar.gz

cd ImageMagick-6.3.1 sudo ./configure –prefix=/usr/local/imagemagick –enable-shared –enable-lzw –with-modules LDFLAGS=’-L/usr/local/imagemagick/lib -R/usr/local/imagemagick/lib’  CPPFLAGS=”-I/usr/local/ jpeg-6b/include -I/usr/local/libpng/include -I/usr/local/freetype/include -I/usr/local/freetype/include/freetype2″ LDFLAGS=”-L/usr/local/lib -L/usr/local/jpeg-6b/lib -L/usr/local/libpng/lib -L/usr/local/freetype/lib” sudo make sudo make install

/sbin/ldconfig /usr/local/imagemagick/lib

/usr/local/imagemagick/bin/convert logo: logo.gif

Posted in Imagemagick, Memcached/redis.

Tagged with , .


bash

单引号(‘)双引号(“) 反斜杠()

$(command) command 命令替換(command substitution),推荐用$() ${}

meta

  • IFS:由 或 或 三者之一組成(我們常用 space )。
  • CR:由 產生。 IFS 是用來拆解 command line 的每一個詞(word)用的,因為 shell command line 是按詞來處理的。 而 CR 則是用來結束 command line 用的,這也是為何我們敲 命令就會跑的原因。 除了 IFS 與 CR ,常用的 meta 還有: = : 設定變量。 $ : 作變量或運算替換(請不要與 shell prompt 搞混了)。 > :重導向 stdout。 < :重導向 stdin。 |:命令管線。 & :重導向 file descriptor ,或將命令置於背境執行。 ( ):將其內的命令置於 nested subshell 執行,或用於運算或命令替換。 { }:將其內的命令置於 non-named function 中執行,或用在變量替換的界定範圍。 ; :在前一個命令結束時,而忽略其返回值,繼續執行下一個命令。 && :在前一個命令結束時,若返回值為 true,繼續執行下一個命令。 || :在前一個命令結束時,若返回值為 false,繼續執行下一個命令。 !:執行 history 列表中的命令 ….

$ A=ls $ B=la $ C=/tmp $ $A -$B $C

export variable

showvar() { var=${str=expr} echo \$var is $var echo \$str is $str } 变量null,unset,not null的差别

=和:=的差别

fork source exec 的差别

( ) 將 command group 置於 sub-shell 去執行,也稱 nested sub-shell。 { } 則是在同一個 shell 內完成,也稱為 non-named command group。 所謂的 function ,就是用一個名字去命名一個 command group ,然後再調用這個名字去執行 command group 。 從 non-named command group 來推斷,大概你也可以猜到我要說的是 { } 了吧 在 bash 中,function 的定義方式有兩種: 方式一:

function function_name { command1 command2 command3 …. }

方式二:

fuction_name () { command1 command2 command3 …. }

${ } 的一些特異功能: 假設我們定義了一個變量為: file=/dir1/dir2/dir3/my.file.txt 我們可以用 ${ } 分別替換獲得不同的值: ${file#/}:拿掉第一條 / 及其左邊的字串:dir1/dir2/dir3/my.file.txt ${file##/}:拿掉最後一條 / 及其左邊的字串:my.file.txt ${file#.}:拿掉第一個 . 及其左邊的字串:file.txt ${file##.}:拿掉最後一個 . 及其左邊的字串:txt ${file%/}:拿掉最後條 / 及其右邊的字串:/dir1/dir2/dir3 ${file%%/}:拿掉第一條 / 及其右邊的字串:(空值) ${file%.}:拿掉最後一個 . 及其右邊的字串:/dir1/dir2/dir3/my.file ${file%%.}:拿掉第一個 . 及其右邊的字串:/dir1/dir2/dir3/my 記憶的方法為: [list]# 是去掉左邊(在鑑盤上 # 在 $ 之左邊) % 是去掉右邊(在鑑盤上 % 在 $ 之右邊) 單一符號是最小匹配﹔兩個符號是最大匹配。[/list] ${file:0:5}:提取最左邊的 5 個字節:/dir1 ${file:5:5}:提取第 5 個字節右邊的連續 5 個字節:/dir2

我們也可以對變量值裡的字串作替換: ${file/dir/path}:將第一個 dir 提換為 path:/path1/dir2/dir3/my.file.txt ${file//dir/path}:將全部 dir 提換為 path:/path1/path2/path3/my.file.txt

利用 ${ } 還可針對不同的變數狀態賦值(沒設定、空值、非空值): ${file-my.file.txt} :假如 $file 沒有設定,則使用 my.file.txt 作傳回值。(空值及非空值時不作處理) ${file:-my.file.txt} :假如 $file 沒有設定或為空值,則使用 my.file.txt 作傳回值。 (非空值時不作處理) ${file+my.file.txt} :假如 $file 設為空值或非空值,均使用 my.file.txt 作傳回值。(沒設定時不作處理) ${file:+my.file.txt} :若 $file 為非空值,則使用 my.file.txt 作傳回值。 (沒設定及空值時不作處理) ${file=my.file.txt} :若 $file 沒設定,則使用 my.file.txt 作傳回值,同時將 $file 賦值為 my.file.txt 。 (空值及非空值時不作處理) ${file:=my.file.txt} :若 $file 沒設定或為空值,則使用 my.file.txt 作傳回值,同時將 $file 賦值為 my.file.txt 。 (非空值時不作處理) ${file?my.file.txt} :若 $file 沒設定,則將 my.file.txt 輸出至 STDERR。 (空值及非空值時不作處理) ${file:?my.file.txt} :若 $file 沒設定或為空值,則將 my.file.txt 輸出至 STDERR。 (非空值時不作處理)

tips: 以上的理解在於, 你一定要分清楚 unset 與 null 及 non-null 這三種賦值狀態. 一般而言, : 與 null 有關, 若不帶 : 的話, null 不受影響, 若帶 : 則連 null 也受影響.

還有哦,${#var} 可計算出變量值的長度: ${#file} 可得到 27 ,因為 /dir1/dir2/dir3/my.file.txt 剛好是 27 個字節…

接下來,再為大家介稍一下 bash 的組數(array)處理方法。 一般而言,A=”a b c def” 這樣的變量只是將 $A 替換為一個單一的字串, 但是改為 A=(a b c def) ,則是將 $A 定義為組數… bash 的組數替換方法可參考如下方法: ${A[@]} 或 ${A[]} 可得到 a b c def (全部組數) ${A[0]} 可得到 a (第一個組數),${A[1]} 則為第二個組數… ${#A[@]} 或 ${#A[]} 可得到 4 (全部組數數量) ${#A[0]} 可得到 1 (即第一個組數(a)的長度),${#A[3]} 可得到 3 (第四個組數(def)的長度) A[3]=xyz 則是將第四個組數重新定義為 xyz …

接下來,再為大家介稍一下 bash 的組數(array)處理方法。 一般而言,A=”a b c def” 這樣的變量只是將 $A 替換為一個單一的字串, 但是改為 A=(a b c def) ,則是將 $A 定義為組數… bash 的組數替換方法可參考如下方法: ${A[@]} 或 ${A[]} 可得到 a b c def (全部組數) ${A[0]} 可得到 a (第一個組數),${A[1]} 則為第二個組數… ${#A[@]} 或 ${#A[]} 可得到 4 (全部組數數量) ${#A[0]} 可得到 1 (即第一個組數(a)的長度),${#A[3]} 可得到 3 (第四個組數(def)的長度) A[3]=xyz 則是將第四個組數重新定義為 xyz …

諸如此類的…. 能夠善用 bash 的 $( ) 與 ${ } 可大大提高及簡化 shell 在變量上的處理能力哦~~~ ^_^

好了,最後為大家介紹 $(( )) 的用途吧:它是用來作整數運算的。 在 bash 中,$(( )) 的整數運算符號大致有這些:

      • / :分別為 “加、減、乘、除”。 % :餘數運算 & | ^ !:分別為 “AND、OR、XOR、NOT” 運算。

例: [code]$ a=5; b=7; c=2 $ echo $(( a+bc )) 19 $ echo $(( (a+b)/c )) 6 $ echo $(( (ab)%c)) 1[/code]

在 $(( )) 中的變量名稱,可於其前面加 $ 符號來替換,也可以不用,如: $(( $a + $b * $c)) 也可得到 19 的結果

此外,$(( )) 還可作不同進位(如二進位、八進位、十六進位)作運算呢,只是,輸出結果皆為十進位而已: echo $((16#2a)) 結果為 42 (16進位轉十進位) 以一個實用的例子來看看吧: 假如當前的 umask 是 022 ,那麼新建文件的權限即為: [code]$ umask 022 $ echo “obase=8;$(( 8#666 & (8#777 ^ 8#$(umask)) ))” | bc 644[/code]

事實上,單純用 (( )) 也可重定義變量值,或作 testing: a=5; ((a++)) 可將 $a 重定義為 6 a=5; ((a–)) 則為 a=4 a=5; b=7; ((a < b)) 會得到 0 (true) 的返回值。 常見的用於 (( )) 的測試符號有如下這些: [list]:大於 =:大於或等於 ==:等於 !=:不等於[/list] 不過,使用 (( )) 作整數測試時,請不要跟 [ ] 的整數測試搞混亂了

Posted in shell, 技术.

Tagged with .


tinymce在ie6下表现比较差

extended_valid_elements无法使用,HTML代码编辑时内容会消失. IE6下在贴word文档时不能正确转换,ie7和FF下没有问题 IE7下会出现Ø ,FF下没事 讨论http://drupal.org/node/32883 解决方法是入库时用PHP替换http://tinymce.moxiecode.net/punbb/viewtopic.php?id=4352

Posted in Others, 技术.


apache rewrite 针对目录转向

恭喜公司.com再此被百度收录。 网站改版后,由于目录和文件命名的改变,以前收录的URL就是404了,现需转发至资料备份服务器。 使用php的话效率低了,所以用apache直接转发。

  #笨方法 Redirect temp /doc/ http://222.222.222.222/doc/ Redirect temp /news/ http://222.222.222.222/news/ Redirect temp /parttimetalent/ http://222.222.222.222/parttimetalent/ Redirect temp /fulltimetalent/ http://222.222.222.222/fulltimetalent/ Redirect temp /person/ http://222.222.222.222/person/ Redirect temp /ebook/ <a href="http://222.222.222.222/ebook/http://222.222.222.222/ebook/ </coolcode>

#使用正则 RedirectMatch temp ^/(doc|news|parttimetalent|fulltimetalent|person|ebook)/(.*) http://222.222.222.222/$1/$2

#反向代理;对图片、js等目录都需处理,比较麻烦 #需开启proxy_module和proxy_http_module,费资源 ProxyPass /doc/ http://222.222.222.222/doc/ ProxyPass /Include/ http://222.222.222.222/Include/ ProxyPassReverse /doc/ http://222.222.222.222/doc/

关于在转向时使用301还是302,可以参考 http://www.chinamyhosting.com/seoblog/2006/04/12/301-redirect/

如果想收录新站就用301,保持原站索引用302

Posted in Apache, 技术.

Tagged with , .


apache 进程 cpu 和 找不到图片

发布新版首页时,高峰时 task达到800,cpu 60% keepAlive off后 下降至3百多到,cpu 10~40%. 补上一张找不到的ICON后 下降至3百不到,cpu 10%.

404的图片对apache的进程和cpu还是有点影响的,10~30%左右

Posted in Apache, 其它, 分析报告, 技术.

Tagged with .


apache关闭某目录的PHP解析

可以在http.conf的目录区域增加”php_flag engine”参数,关闭对某个目录的php解析,起到保护的作用。

    DocumentRoot /opt/htdocs/www     ServerName local.c1gstudio.com     php_flag engine Off     AddOutputFilterByType DEFLATE text/html text/plain text/xml

 

关闭后php文件将会变成可下载的纯文本文件,所以请小心使用。

Posted in Apache, PHP, 技术.

Tagged with , .


apache下rewrite防盗链

在http.conf中添加模块

LoadModule rewrite_module modules/mod_rewrite.so #可能需要的其它相关模块 LoadModule mime_module modules/mod_mime.so LoadModule setenvif_module modules/mod_setenvif.so LoadModule headers_module modules/mod_headers.so

rewrite方式 可以自定的我内容,如显示友好的图片 可以地址中带URL进行破解 充许空referer 在根目录下新建allow目录存放允许访问的内容,如leech.gif

RewriteEngine on RewriteCond %{REQUEST_URI} ^/allow RewriteRule ^.*$ – [L] RewriteCond %{REQUEST_FILENAME} \.(gif|jpg|jpeg|png|swf|css|rar|zip)$ [NC] RewriteCond %{HTTP_REFERER} !^$ [NC] #空referer RewriteCond %{HTTP_REFERER} !192.168.1.111 [NC] RewriteCond %{HTTP_REFERER} !192.168.1.221 [NC] RewriteCond %{HTTP_REFERER} !domain\.com [NC] RewriteCond %{HTTP_REFERER} !domain\.net [NC] RewriteCond %{HTTP_REFERER} !anotherdomain\.com [NC] RewriteRule (.*) /allow/leech.gif [R,NC,L]

SetEnv方式 直接转到403页面去,如果请求是图片的话,那就是一个红X

SetEnvIfNoCase Referer “^http://192.168.1.111″/ local_ref=1 SetEnvIfNoCase Referer “^http://192.168.1.221″/ local_ref=1 SetEnvIfNoCase Referer “^http://.*\.domain\.com” local_ref=1 SetEnvIfNoCase Referer “.*\.domain\.com” local_ref=1 SetEnvIfNoCase Referer “^http://domain.com”/ local_ref=1 SetEnvIfNoCase Referer “^http://*\.domain\.net” local_ref=1 SetEnvIfNoCase Referer “.*\.domain\.net” local_ref=1 SetEnvIfNoCase Referer “^http://domain\.net”/ local_ref=1 SetEnvIfNoCase Referer “^http://*\.anotherdomain\.com” local_ref=1 SetEnvIfNoCase Referer “.*\.anotherdomain\.com” local_ref=1 SetEnv NoLOG 1 Order Allow,Deny Allow from env=local_ref

参考 http://blogsdiy.org/2007-04/prevent-hotlinking/

Posted in Apache, 技术.

Tagged with , .


iptables小记

开启 /etc/init.d/iptables start

关闭 /etc/init.d/iptables stop

设定每次开启不启动该服务项目,可以使用 chkconfig 来关闭。 chkconfig iptables off

查看当前iptables iptables -L

保存规则 iptables-save > /etc/sysconfig/iptables

恢复规则 iptables-restore < /etc/sysconfig/iptables

禁止123.456.789.0-123.456.789.255的流进和流出 iptables -t filter -A INPUT -s 123.456.789.0/24 -j DROP iptables -t filter -A OUTPUT -d 123.456.789.0/24 -j DROP

删除规则 iptables -t filter -D OUTPUT -d 123.456.789.0/24 -j DROP

禁止流进ip段 iptables -I INPUT -s 211.0.0.0/8 -j DROP

iptables -I INPUT -s 211.1.0.0/16 -j DROP iptables -I INPUT -s 211.2.0.0/16 -j DROP iptables -I INPUT -s 211.3.0.0/16 -j DROP

iptables -I INPUT -s 61.37.80.0/24 -j DROP iptables -I INPUT -s 61.37.81.0/24 -j DROP

默认策略: iptables -P INPUT ACCEPT iptables -P OUTPUT DROP iptables -P FORWARD DROP 接受所有ssh连接: iptables -A INPUT -p tcp -m tcp -s 0/0 –dport 22 -j ACCEPT 管理FTP连接: iptables -A INPUT -p tcp -m tcp –dport 21 -j ACCEPT iptables -A INPUT -p tcp -s 127.0.0.1/8 -d 0/0 –destination-port 20 –syn -j ACCEPT iptables -A INPUT -p tcp -s 127.0.0.1/8 -d 0/0 –destination-port 21 –syn -j ACCEPT

监视SNMP: iptables -A INPUT -p udp -m udp –dport 161 -j ACCEPT iptables -A INPUT -p udp -m udp –sport 1023:2999 -j ACCEPT 管理POP电子邮件: iptables -A INPUT -p tcp -m tcp –dport 110 -j ACCEPT –syn HTTPS服务: iptables -A INPUT -p tcp -m tcp –dport 443 -j ACCEPT –syn SMTP连接: iptables -A INPUT -p tcp -m tcp –dport 25 -j ACCEPT –syn 管理HTTP: iptables -A INPUT -p tcp -m tcp –dport 80 -j ACCEPT –syn 管理MySQL数据库: iptables -A INPUT -p tcp -m tcp –dport 3306 -j ACCEPT –syn iptables -A INPUT -p udp -m udp –dport 3306 -j ACCEPT

IMAP邮件服务: iptables -A INPUT -p tcp -m tcp –dport 143 -j ACCEPT –syn

管理DNS服务: iptables -A INPUT -p tcp -m tcp –dport 53 -j ACCEPT –syn iptables -A INPUT -p udp -m udp –dport 53 -j ACCEPT iptables -A INPUT -p udp -m udp -s 0/0 -d 0/0 –sport 53 -j ACCEPT

管理本地主机连接: iptables -A INPUT -i lo -j ACCEPT -m tcp

丢弃所有其它的新请求: iptables -A INPUT -p tcp -m tcp -j REJECT –syn iptables -A INPUT -p udp -m udp -j REJECT

防止SYN洪水攻击: iptables -A INPUT -p tcp –syn -m limit –limit 5/second -j ACCEPT

屏蔽恶意主机(比如,192.168.0.8): iptables -A INPUT -p tcp -m tcp -s 192.168.0.8 -j DROP

检查防火墙日志: iptables -A INPUT -j LOG –log-level alert iptables -A INPUT -j LOG –log-prefix “Dropped: ”

做 NAT: iptables -A POSTROUTING -t nat -o eth0 -s 192.168.1.0/24 -d 0/0 -j MASQUERADE iptables -A FORWARD -t filter -o eth0 -m state –state NEW,ESTABLISHED,RELATED -j ACCEPT iptables -A FORWARD -t filter -i eth0 -m state –state ESTABLISHED,RELATED -j ACCEPT

清空所有规则: iptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -X

http://bbs.chinaunix.net/thread-216752-1-1.html

Posted in Linux 命令, 技术.

Tagged with .


前端开发工程师的工具箱 2007-09-25

来自TAOBAO的UED推荐

http://docs.google.com/Present?docid=dgr8f7vc_46gmggrv&fs=true

Google Presentation 目前的功能相比PowerPoint还很简单,只能插入图片和文本,不支持动画。但相信这些功能很快就会出现。

creasemonkey fiddle Internet Explorer Developer Toolbar ie7pro firebug yslow web develop

Posted in HTML/XHTML/CSS, 技术.