Archive for 二月, 2007

It takes years maybe decades to master the commands available to you at the Linux shell prompt. Here are 10 that you will have never heard of or used. They are in no particular order. My favorite is mkfifo.

\r\n
    \r\n
  1. pgrep, instead of:
    # ps -ef | egrep \’^root \’ | awk \’{print $2}\’\r\n1\r\n2\r\n3\r\n4\r\n5\r\n20\r\n21\r\n38\r\n39\r\n…\r\n
    \r\n

    You can do this:

    # pgrep -u root\r\n1\r\n2\r\n3\r\n4\r\n5\r\n20\r\n21\r\n38\r\n39\r\n…\r\n
    \r\n
  2. pstree, list the processes in a tree format. This can be VERY useful when working with WebSphere or other heavy duty applications.
    # pstree\r\ninit-+-acpid\r\n     |-atd\r\n     |-crond\r\n     |-cups-config-dae\r\n     |-cupsd\r\n     |-dbus-daemon-1\r\n     |-dhclient\r\n     |-events/0-+-aio/0\r\n     |          |-kacpid\r\n     |          |-kauditd\r\n     |          |-kblockd/0\r\n     |          |-khelper\r\n     |          |-kmirrord\r\n     |          `-2*[pdflush]\r\n     |-gpm\r\n     |-hald\r\n     |-khubd\r\n     |-2*[kjournald]\r\n     |-klogd\r\n     |-kseriod\r\n     |-ksoftirqd/0\r\n     |-kswapd0\r\n     |-login—bash\r\n     |-5*[mingetty]\r\n     |-portmap\r\n     |-rpc.idmapd\r\n     |-rpc.statd\r\n     |-2*[sendmail]\r\n     |-smartd\r\n     |-sshd—sshd—bash—pstree\r\n     |-syslogd\r\n     |-udevd\r\n     |-vsftpd\r\n     |-xfs\r\n     `-xinetd\r\n
    \r\n
  3. bc is an arbitrary precision calculator language. Which is great. I found it useful in that it can perform square root operations in shell scrīpts. expr does not support square roots.
    # ./sqrt\r\nUsage: sqrt number\r\n# ./sqrt 64\r\n8\r\n# ./sqrt 132112\r\n363\r\n# ./sqrt 1321121321\r\n36347\r\n
    \r\n

    Here is the scrīpt:

    # cat sqrt\r\n#!/bin/bash\r\nif [ $# -ne 1 ]\r\nthen\r\n        echo \’Usage: sqrt number\’\r\n        exit 1\r\nelse\r\n        echo -e \”sqrt($1)\\nquit\\n\” | bc -q -i\r\nfi\r\n
    \r\n
  4. split, have a large file that you need to split into smaller chucks? A mysqldump maybe? split is your command. Below I split a 250MB file into 2 megabyte chunks all starting with the prefix LF_.
    # ls -lh largefile\r\n-rw-r–r–  1 root root 251M Feb 19 10:27 largefile\r\n# split -b 2m largefile LF_\r\n# ls -lh LF_* | head -n 5\r\n-rw-r–r–  1 root root 2.0M Feb 19 10:29 LF_aa\r\n-rw-r–r–  1 root root 2.0M Feb 19 10:29 LF_ab\r\n-rw-r–r–  1 root root 2.0M Feb 19 10:29 LF_ac\r\n-rw-r–r–  1 root root 2.0M Feb 19 10:29 LF_ad\r\n-rw-r–r–  1 root root 2.0M Feb 19 10:29 LF_ae\r\n# ls -lh LF_* | wc -l\r\n126\r\n
    \r\n
  5. nl numbers lines. I had a scrīpt doing this for me for years until I found out about nl.
    # head wireless.h\r\n/*\r\n * This file define a set of standard wireless extensions\r\n *\r\n * Version :    20      17.2.06\r\n *\r\n * Authors :    Jean Tourrilhes – HPL\r\n * Copyright (c) 1997-2006 Jean Tourrilhes, All Rights Reserved.\r\n */\r\n\r\n#ifndef _LINUX_WIRELESS_H\r\n# nl wireless.h | head\r\n     1  /*\r\n     2   * This file define a set of standard wireless extensions\r\n     3   *\r\n     4   * Version :    20      17.2.06\r\n     5   *\r\n     6   * Authors :    Jean Tourrilhes – HPL\r\n     7   * Copyright (c) 1997-2006 Jean Tourrilhes, All Rights Reserved.\r\n     8   */\r\n\r\n     9  #ifndef _LINUX_WIRELESS_H\r\n
    \r\n
  6. mkfifo is the coolest one. Sure you know how to create a pipeline piping the output of grep to less or maybe even perl. But do you know how to make two commands communicate through a named pipe?

    \r\n

    First let me create the pipe and start writing to it:

    \"mkfifo pipe\” src=\”http://bashcurescancer.com/media/10-linux-commands-youve-never-used/mkfifo-write-to-pipe.png\” width=640> \r\n

    Then read from it:

    \"cat \r\n
  7. ldd, want to know which Linux thread library java is linked to?
    # ldd /usr/java/jre1.5.0_11/bin/java\r\n        libpthread.so.0 => /lib/tls/libpthread.so.0 (0x00bd4000)\r\n        libdl.so.2 => /lib/libdl.so.2 (0x00b87000)\r\n        libc.so.6 => /lib/tls/libc.so.6 (0x00a5a000)\r\n        /lib/ld-linux.so.2 (0x00a3c000)\r\n
    \r\n
  8. col, want to save man pages as plain text?
    # PAGER=cat\r\n# man less | col -b > less.txt\r\n
    \r\n
  9. xmlwf, need to know if a XML document is well formed? (A configuration file maybe..)
    # curl -s \’http://bashcurescancer.com\’ > bcc.html\r\n# xmlwf bcc.html\r\n# perl -i -pe \’s@<br/>@<br>@g\’ bcc.html\r\n# xmlwf bcc.html\r\nbcc.html:104:2: mismatched tag\r\n
    \r\n
  10. lsof lists open files. You can do all kinds of cool things with this. Like find which ports are open:
    # lsof | grep TCP\r\nportmap    2587   rpc    4u     IPv4       5544                 TCP *:sunrpc (LISTEN)\r\nrpc.statd  2606  root    6u     IPv4       5585                 TCP *:668 (LISTEN)\r\nsshd       2788  root    3u     IPv6       5991                 TCP *:ssh (LISTEN)\r\nsendmail   2843  root    4u     IPv4       6160                 TCP badhd:smtp (LISTEN)\r\nvsftpd     9337  root    3u     IPv4      34949                 TCP *:ftp (LISTEN)\r\ncupsd     16459  root    0u     IPv4      41061                 TCP badhd:ipp (LISTEN)\r\nsshd      16892  root    3u     IPv6      61003                 TCP badhd.mshome.net:ssh->kontiki.mshome.net:4661 (ESTABLISHED)\r\n
    \r\n

    Note: OpenBSD 101 pointed out that \”lsof -i TCP\” a better way to obtain this same information. Thanks!


    \r\n

    Or find the number of open files a user has. Very important for running big applications like Oracle, DB2, or WebSphere:

    # lsof | grep \’ root \’ | awk \’{print $NF}\’ | sort | uniq | wc -l\r\n179\r\nNote: an anonymous commenter pointed out that you can replace sort | uniq with \”sort -u\”. This is true, I forgot about the -u flag. Thanks!

配置Apache代理
代理服务器(proxyserver)是安装于防火墙上的应用程序,它把防火墙内部的局域网连接到Intemet上。代理服务器的功能如下。
●监视通过防火墙的数据包并记录传输信息。
●对通过防火墙的数据包地址进行过滤。
●提供文件缓存功能。
代理服务器可以根据所代理的服务类型分类,例如HTtP代理和FFP代理等。我们以HTTP代理为例,介绍代理服务器的功能。当局域网中的客户机使用HTIT代理服务器时,它的HTTP请求将被发送到代理服务器中,而不是直接发送到源地址。如果代理服务器配置了文件缓存功能,在接受到客户请求时,首先在缓存中检查是否有用户需要的内容。如果缓存中没有,就要从HTTP源地址检索,再把相应内容返回给用户。以后,如果用户再请求相同的内容,代理服务器将直接从缓存中提取。

\r\n

配置ApacheHTTP代理

\r\n

Apache作为WWW服务器软件,在内部提供了HTFP代理功能。下面我们将介绍Apache代理的配置方法:

\r\n

(1)修改文件/etc/httpd/conf/httpd.conf,在其中添加与代理和缓存相关的功能。与代理缓存有关的关键字如下所示。

\r\n

httpa.conf文件中与代理缓存有关的关键字
ProxyRequests On/Off 启用或者禁用Apache代理功能

\r\n

Proxyremote path URL remote server 定义此代理服务器的远程代理。当用户请求与URL匹配时,就使用remote server作为远程代理服务器。

\r\n

其中remote server的格式是: protocol://hostname[:port],由于Apache只能代理HTTP服务,所以protocol值恒为HTTP

\r\n

ProxyPass path URL允许把远程服务器镜像到本地服务器中。这时,本地代理服务器好像是远程代理服务器的一个镜像

\r\n

ProxyBlock word/hostname/domain 代理服务器过滤功能。在ProxyBlock关键字以后定义了一组词语、节点名称和域名。如果用户的HTYP请求中包含了这里的词语、节点名称或者域名,请求将被过滤掉

\r\n

CacheRoot directory 代理缓存的根目录

\r\n

CacheSize size代理缓存大小,以KB为单位

\r\n

CacheGcInterval time每隔time小时检查缓存区,如果缓存占用空间超过CacheSize设置的上限,就删除文件缓存中的文件最多保存time小时,这里定义了文件的过期时间

\r\n

CacheLastModifiedFactor factor如果没有定义文件过期时间,就按照下面的公式计算:过期时间=最近一次修改的时间间隔*factor

\r\n

CacheDirLevels levels缓存中子目录的层数

\r\n

CacheDirLenSth lenSth代理缓存子目录名的字母数

\r\n

CacheDefauhExpire time 如果文件是通过一个不支持过期时间的协议获取的,则使用time作为过期时间

\r\n

NoCache word/hostname/domain 在NoCache关键字以后定义了一组词语、节点名称和域名。包含这些词语、节点名称或者域名的HTFP文件将不被缓存

\r\n

(2)修改文件/etc/httpd/conL/access.conf,在其中添加对代理目录的访问控制。下面是一个实例。

\r\n

<Directory proxy:*>
<Limit GET PUT DELECT CONNECT POST OPTIONS
order deny,allow
deny from all
allow from.company.com
</Limit>
</Directory>
(3)确认CacheRoot关键字指定的缓存目录已经存在。
重新启动hnpd,缓存功能就可以生效了。

\r\n

 

\r\n

 

\r\n

配置Apache逆向代理
我们通过一个实例介绍Apache逆向代理的配置方法。假设在企业内部网络中有WWW服务器,我们希望这台服务器能够通过连接到Intemet的防火墙提供对外部的WWW服务。
这种把WWW服务器设在网络内部的方法可以把WWW服务器与外部世界隔离,提高安全性。这时,我们需要在防火墙上也安装Apache服务器,使用它提供对WWW服务器的代理访问。同时,结合我们前面介绍的虚拟主机技术,把防火墙作为Apache虚拟主机,使得防火墙上的主页不会被访问到。内部局域网中的WWW服务器
IP地址为192.168.1.2,防火墙主机内部IP地址为192.168.1.1,外部IP地址为202.5.83.124。

\r\n

配置防火墙上Apache的步骤如下。

\r\n

(1)在/etc/httpd/conf/httPd.conf文件中添加虚拟主机配置。
NameVirtualHost 202.5.83.124
servername www.company.com
errorlog/var/log/httpd/error—log
transferlog/var/log/httpd/access—log
rewriteengine On
proxyrequests off
usecanonicalname off
rewriterule^/(.*)$http://192.168.1.2$ 1 [P,L]

\r\n

(2)配置局域网中的DNS服务器,把www.company.com指向202.5.83.124。这样,所有对IP地址202.5.83.124的访问都会被重新导向到内部WWW服
务器中。我们还需要对局域网内部WWW服务器的配置进行修改,具体步骤如下。
1]Apache采用默认配置,主目录为/home/httpd/html,主机域名为company.com.cn,别名为www.company.com,并且在srm.conf中添加以下别名
定义。
Alias /pub/home/ftp/pub/
DefaultType application/octet—stream

\r\n

2]在/etc/hnpd/conf/access.conf中增加一项。
Options lndexes
AllowOverride AuthConfiq
order allow,deny
allow from all

\r\n

3]在/home/ftp/pub目录下放人.htaccess文件,内容如下。
#cat.htaccess
AuthName Branch Office Public Software Download Area
AuthType Basic
AuthUserFile /etc/.usrpasswd
require valid-user

\r\n

4]执行如下命令:
#htpasswd -c /etc/.usrpasswd user1

\r\n

分别创建允许访问/pub文件服务的不同的外部用户名和口令。

wget只能单线程,没办法有效利用带宽。找了prozilla 1.36 for debian的包,不支持大于2g文件,新版本老是编译不过。

\r\n

axel也不支持大于2g,后来好不容易找到myget,可能放在cron里不执行。今天才发现aria2,哈哈。小乐一下

\r\n

同时发现CNZZ昨天统计总量突破7亿/天,再次小乐一下。

昨晚听闻一好友的父亲离故,事情之突然,令我为之一震,随之伤感十分。因是十分要好的朋友,她家也去过好几次,与伯父见过几次面。年纪也不算高,只可惜突然离去。好友的小弟也还未成家,不过姐弟俩也都差不多到成家的时候了,也应该是老人享福的,却。。。。。

\r\n

但愿人长久,伯父好好安息吧。但愿伯母能坚强。

干锅这种吃法,不知道算不算南方特有的呢?
我们在外面的排挡或者饭店吃饭时,尤其是在排挡,经常会点干锅。
干锅可以做很多种菜,干锅鸡、鸭、兔、羊等等……
通常是肉腌制好,先炸过,放调料炒香,煮好,然后直接放锅里,锅底垫一些蒜苗,或者是直接放锅里。开小火慢慢的煮,要不停的翻动,要是太干了,就加啤酒,一面吃,一面加啤酒。煮得锅里滋滋的直冒烟,香喷喷的让人止不住口呀!
等肉肉吃得差不多后,加上高汤,然后烫一些蔬菜、蘑菇,或者粉之类的DD。
是一种非常过瘾的吃法哦!
最近吃一般的汤水火锅多了,就穿插着干锅吃吃,做了一次鸡肉的,一次鸭肉的,做法基本上是一样的,就一起发上来了。另外还做了一次干锅豆腐鱼头火锅,不过那次是用葡萄酒做的,也蛮好吃呢,可惜那次是家里来客人做的,太匆忙了没拍照片。下次再做一次拍给大家看。呵呵……

\r\n

因为怕麻烦,所以肉没有过油锅,但是味道也不赖哦!要是稍微炸过一下呢,肉咬起来会更加香一点。

\r\n

\r\n

材料:
鸡肉砍小块,用姜、盐、酱油腌制好(或者根据自己的口味,可以再加一点酱料和糖)
啤酒一瓶
水发木耳、香菇
葱、蒜、辣椒、香菜、蒜苗及一些自己喜欢的配菜。

\r\n

\r\n

首先,将水发的木耳和香菇放到干净的锅里,控干水分。盛起。

\r\n

\r\n

锅里放油,爆香葱头、蒜、辣椒。
然后将鸡肉倒进去,不要急着翻,慢慢煎到肉金黄了,再翻一面,继续煎。
煎到两面都金黄,肉的水分稍干。
(如果能先过油是最香的啦)

\r\n

\r\n

把肉拨到旁边,把控干水分的木耳和香菇倒进锅里的余油里。炒一下,放一点盐。

\r\n

然后和鸡肉捞在一起翻炒。\r\n

\r\n

然后,倒大概1/3瓶或者半瓶啤酒,盖上盖子焖。

\r\n

\r\n

焖到汤汁基本收干。

\r\n

\r\n

锅里铺好蒜苗,LG爱吃蒜苗,放多一点,嘿嘿!

\r\n

看我准备一些的配料:P
粉利(好象就是北方人常说的年糕)
豆苗,大白菜,香菇,炸好的芋头丸子,鱼丸。
另外还有金针菇,没拍上来。

\r\n

\r\n

完成!