苹果相关

浏览模式: 标准 | 列表 | 图文
proftpd 问答

proftpd 问答

Frequently Asked Questions
Question: Why do I see the following when my proftpd starts up?

  getaddrinfo 'hostname' error: No address associated with hostname   warning: unable to determine IP address of 'hostname' 

Answer: This error is ProFTPD's way of reporting that it was unsuccessful in resolving hostname to an IP address. Fixing this is a matter of configuring DNS for that hostname: properly set up an IP address for that DNS name in your DNS server, use a DNS name that has an IP address, or (as a quick fix/last resort) add that DNS name to your /etc/hosts file. The proper solution depends largely on the circumstances.

Question: If proftpd resolves any DNS names to IP addresses when it starts up, and I am using dynamic IP addresses which change after my proftpd has started, will proftpd see my new IP addresses?
Question: Unfortunately not. ProFTPD has no easy way of handling dynamic IP addresses by itself. One way of dealing with this situation is to restart proftpd periodically, which will force it to re-parse its configuration and thus re-resolve all IP addresses.

Question: What if I do not want proftpd to use DNS to resolve the hostname to an IP address because I am in an environment where there is no DNS at all?
Answer: In ProFTPD 1.3.3rc1, support for a new -S command-line option was added. This option can be used to specify the IP address of the host machine. By default, proftpd attempts to resolve the host IP address by using DNS resolution of the hostname. However, in cases where DNS is not configured for the host machine, this approach does not work.

To specify the desired IP address, use -S when starting proftpd, e.g.:

  /usr/local/sbin/proftpd -S 1.2.3.4 ... 

And if you want proftpd to listen on all interfaces, you can specify a wildcard socket using an IP address of 0.0.0.0:

/usr/local/sbin/proftpd -S 0.0.0.0 ...

Note that will also mean that, in your proftpd.conf, any <VirtualHost> sections will need to use IP addresses, not DNS names.

aliyun 安装 ftp(proftpd)

aliyun 安装 ftp(proftpd)

有了服务器,怎么着都得装个Ftp吧,否则,必须得让人用ssh连接来上传文件 ?
于是我找了proftpd,因为比较简单vsftpd太麻烦了。proftpd的教程很简单

1、先apt-get update,apt-get upgrade
2、apt-get install proftpd-basic proftpd-mod-mysql
3、修改 /etc/proftpd/proftpd.conf
因为原内容都注释了,所以直接在文件的最后加上:

DefaultRoot ~
Include /etc/proftpd/sql.conf
RequireValidShell off

4、添加一个组,和一个用户:

groupadd -g 2001 ftpgroup
useradd -u 2001 -s /bin/false -d /bin/null -c "proftpd user" -g ftpgroup ftpuser

5、去mysql里增加一个用户,如proftpd/proftpdpass,建一个数据库,如:proftpd
6、插入表结构:

CREATE TABLE ftpgroup (
groupname varchar(16) NOT NULL default '',
gid smallint(6) NOT NULL default '2001',
members varchar(16) NOT NULL default '',
KEY groupname (groupname)
) ENGINE=MyISAM COMMENT='ProFTP group table';

CREATE TABLE ftpuser (
id int(10) unsigned NOT NULL auto_increment,
userid varchar(32) NOT NULL default '',
passwd varchar(32) NOT NULL default '',
uid smallint(6) NOT NULL default '2001',
gid smallint(6) NOT NULL default '2001',
homedir varchar(255) NOT NULL default '',
shell varchar(16) NOT NULL default '/sbin/nologin',
count int(11) NOT NULL default '0',
accessed datetime NOT NULL default '0000-00-00 00:00:00',
modified datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (id),
UNIQUE KEY userid (userid)
) ENGINE=MyISAM COMMENT='ProFTP user table';

7、修改/etc/proftpd/modules.conf,去掉两行注释:

LoadModule mod_sql.c
LoadModule mod_sql_mysql.c

8、修改/etc/proftpd/sql.conf

SQLBackend mysql
SQLAuthTypes Crypt
#下面一行就是用户名密码
SQLConnectInfo 数据库@localhost 用户名 密码
SQLUserInfo ftpuser userid passwd uid gid homedir shell
SQLGroupInfo ftpgroup groupname gid members
# Update count every time user logs in
SQLLog PASS updatecount
SQLNamedQuery updatecount UPDATE "countcount=count+1, accessed=now() WHERE userid='%u'" ftpuser
SQLLog STOR,DELE modified
SQLNamedQuery modified UPDATE "modified=now() WHERE userid='%u'" ftpuser

9、插入用户:

INSERT INTO `ftpgroup` (`groupname`, `gid`, `members`) VALUES ('ftpgroup', 2001, 'ftpuser');
INSERT INTO `ftpuser` ( `userid`, `passwd`, `uid`, `gid`, `homedir`, `shell`, `count`) VALUES ( 'username', ENCRYPT('password'), 2001, 2001, '/var/www/www.example.com/', '/sbin/nologin', 0);

10、重启proftpd:/etc/init.d/proftpd restart
上面这段其实是来自:http://www.sysadminworld.com/2011/install-proftpd-with-mysql-backend-on-debian-ubuntu/

--------EOF---

至此,上面的内容基本上就能够登录成功了,如果还是失败,建议先停掉proftpd,然后运行proftpd -nd6,查看错误信息,比如我就看到了这个:

Mar 09 00:22:29 test proftpd[8850] test (0.0.0.0[0.0.0.0]): notice: unable to use '~/' [resolved to '/server/wwwroot/htdocs/']: Permission denied
Mar 08 16:22:29 test proftpd[8850] test (0.0.0.0[0.0.0.0]): Preparing to chroot to directory '~/'
Mar 08 16:22:29 test proftpd[8850] test (0.0.0.0[0.0.0.0]): chroot to '~/' failed for user 'xxxxxx': Operation not permitted
Mar 08 16:22:29 test proftpd[8850] test (0.0.0.0[0.0.0.0]): error: unable to set default root directory
Mar 08 16:22:29 test proftpd[8850] test (0.0.0.0[0.0.0.0]): FTP session closed.

我靠,这个怎么办?

这时候我又请vampire帮忙了。他就帮我检查了一下,做了几个处理:

1、vim /etc/groups ,在www-data:x:33后面加了:www-data:x:33:ftpgroup ,表示权限跟着www-data,因为我们的ftp目录里的文件都是基于www-data的

2、修改/etc/proftpd/proftpd.conf,改其中的:user / group ,都改成www-data

3、还是/etc/proftpd/proftpd.conf ,改 Umask ,原来是Umask 022 022,去掉一个022

4、因为我的www-data是gid是33,所以刚才在数据库里插的gid统统换成33,而不是原来的2001,这时候再登录其实还是不正常。

5、最重要的一个,在刚才的sql.conf里面,加入:SQLMinID 33,这个玩意要参考:http://www.proftpd.org/docs/directives/linked/config_ref_SQLMinID.html,我晶,这个东西,居然在默认的sql.conf里是没有这一行的。果然还是vampire有经验。因为www-data的gid是33,所以sqlminid就是33了。

这时候,终于一切正常了。折腾了好久。。。

aliyun二三事

aliyun二三事

最近在试用阿里云,但是遇到了一些问题。
我在安装数据库的时候,是通过apt-get install mysql-server进行安装的,然而我安装完后,想将数据存储到额外挂载的磁盘时,却发现数据不能写入。。。
因为我老是启动失败。。所以看了下LOG,LOG是说写入目录失败。
于是请vampire帮忙看了一下,他测试了mysql_install_db,但是。。。

# mysql_install_db --datadir=/server/software/mysql_data
Installing MySQL system tables...
130308 16:14:25 [Warning] Can't create test file /server/software/mysql_data/AY130304113437124704.lower-test
130308 16:14:25 [Warning] Can't create test file /server/software/mysql_data/AY130304113437124704.lower-test
ERROR: 1005 Can't create table 'db' (errno: 13)
130308 16:14:25 [ERROR] Aborting

130308 16:14:25 [Note] /usr/sbin/mysqld: Shutdown complete


Installation of system tables failed! Examine the logs in
/server/software/mysql_data for more information.

You can try to start the mysqld daemon with:

shell> /usr/sbin/mysqld --skip-grant &

and use the command line tool /usr/bin/mysql
to connect to the mysql database and look at the grant tables:

shell> /usr/bin/mysql -u root mysql
mysql> show tables

Try 'mysqld --help' if you have problems with paths. Using --log
gives you a log in /server/software/mysql_data that may be helpful.

Please consult the MySQL manual section
'Problems running mysql_install_db', and the manual section that
describes problems on your OS. Another information source are the
MySQL email archives available at http://lists.mysql.com/.

Please check all of the above before mailing us! And remember, if
you do mail us, you MUST use the /usr/scripts/mysqlbug script!

oh shit,还是安装不了。试了很多都没有用。最后从官方下载了5.6的包进行安装。居然就OK了。我靠,这个源是cn.ubuntu的源啊。。。苦逼了。
所幸问题解决了。

多谢vampire,同时各位朋友也注意下。如果真的不行,也可以尝试从网上直接下载源码编译,要么。就换成中科大的源,然后再upgrade。中科大的更新比较快。

但因为要修改内容和启动参数还是有点危险的。。。

为debian增加apt-add-repository功能

ubuntu下面有一个很不错的功能,它能够使你很方便 的添加ppa的源,那就是apt-add-repository
在我之前写的一篇博客里就有介绍此功能(关于gearman的),但在debian系统上就无法适用,因为debian下没有此功能
于是找了ubuntu下的apt-add-repository的代码,cp了一份到debian下面,但不能运行。所以google了一下,发现这么一段代码就OK了:

#!/bin/bash
if [ $# -eq 1 ]
then
ppa_name=`echo "$1" | cut -d":" -f2 -s`
if [ -z "$ppa_name" ]
then
echo "PPA name not found"
echo "Utility to add PPA repositories in your debian machine"
echo "$0 ppa:user/ppa-name"
else
echo "$ppa_name"
echo "deb http://ppa.launchpad.net/$ppa_name/ubuntu lucid main" >> /etc/apt/sources.list
apt-get update >> /dev/null 2> /tmp/apt_add_key.txt
key=`cat /tmp/apt_add_key.txt | cut -d":" -f6 | cut -d" " -f3`
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys $key
rm -rf /tmp/apt_add_key.txt
fi
else
echo "Utility to add PPA repositories in your debian machine"
echo "$0 ppa:user/ppa-name"
fi

将这段内容存成apt-add-repository,然后cp到/usr/bin目录下,并且chmod +x 这个文件,让它有可执行的权限。
再接着使用apt-add-repository 来添加源就OK了
这个自定义的版本,在添加完源后,还会将source.list进行了修改。比ubuntu还人性化。。
参考:
1.http://cptbtptp.blog.51cto.com/3228046/620036
2.http://jolin.2001.blog.163.com/blog/static/89912172011485354567/
两篇内容细看,其实就是一样的。。

svn: E220001: Unreadable path encountered; access denied

svn: E220001: Unreadable path encountered; access denied

发现svn的代码有更新,却忘了与上次对比。于是svn与上一版本对比的时候就出现了标题的错误:
svn: E220001: Unreadable path encountered; access denied

其实解决方法很简单,在conf/svnserve.conf中。找到anonaccess = read这一行,(默认是注释掉的)
加入一行 anonaccess = none

再试一下,就会发现正常了。

这应该算是svn的BUG了。拜托,就算你不支持anon这样的匿名用户,你好歹默认为NONE这种值你总要存在吧。不存在 就直接造成无法访问,没权限了。

ubuntu下安装gearman及扩展

ubuntu下安装gearman及扩展

Ubuntu下面安装gearman以及php的gearman扩展是需要注意一下的。
不是默认的安装就直接OK
apt-get install gearman
安装完gearman后。使用pecl install gearman安装。这时候会提示你安装新版 的libgearman
如果你直接搜索apt-cache search libgearman,会发现有很多,但其实一个都不是。。不用上当了

OK,怎么办?有人也问过这个问题:http://stackoverflow.com/questions/13312207/installing-gearman-php-extension-on-debian-6
有人这么回复 :

The reason that this doesn't work is that as the error message says, the most recent version of the PHP extension requires libgearman-1.0 (which is why the directory is named 1.0). You'll need to be at least on wheezy (which is the version after debian 6 / squeeze) to get libgearman-1.0.

It might also be a solution to compile libgearman from source, and then use checkinstall to create a debian package that you install afterwards, or use the gearman developer ppa available at https://launchpad.net/~gearman-developers/+archive/ppa. We've built libgearman, gearmand and the PHP extension on a wide variety of distributions (including Debian, Ubuntu, RHEL4 and SL6) and used checkinstall to get a proper package available.

嗯,打开这个网址。
在最上面有提醒你怎么将PPA将入源里:

Adding this PPA to your system

You can update your system with unsupported packages from this untrusted PPA by adding ppa:gearman-developers/ppa to your system's Software Sources. (Read about installing)

OK,那我们开始吧:

apt-add-repository ppa:gearman-developers/ppa

然后,你根据你的版本,将源加到你的source.list文件里:
vim /etc/apt/source.list
加入:

deb http://ppa.launchpad.net/gearman-developers/ppa/ubuntu precise main  deb-src http://ppa.launchpad.net/gearman-developers/ppa/ubuntu precise main 

然后:apt-get update
apt-get upgrade
会提醒你需要升级gearman到最新版 本
这时候再:
pecl install gearman
然后就直接安装成功,会提示你怎么操作:
Build process completed successfully
Installing '/usr/lib/php5/20090626+lfs/gearman.so'
install ok: channel://pecl.php.net/gearman-1.1.1
configuration option "php_ini" is not set to php.ini location
You should add "extension=gearman.so" to php.ini
按照提示操作完后,重启apache。
在命令行下执行:
# php -i |grep gearman
gearman
gearman support => enabled
libgearman version => 0.40
wow...安装成功。
就是这么简单
apache 限制IP访问

apache 限制IP访问

这是一个小笔记。以前也记过,只是后来忘了。其实就几行代码而已:

<directory xxx>
# 设置可以访问服务器的IP
Allow From 192.168.1.12 220.133.*.*/255.255.255.255
Order deny,allow
Deny from all
</directory>

上面的URL中更加详细 我这个只是一个简单的demo而已。

发发对84的牢骚

刚才看到群里有人在说84(burst)的VPS,我也发发牢骚吧
一年前买了个84的vps,那时候大家都说它便宜,不错。于是我就信了。
因为买一年会有一个优惠,所以我一下子就买了一年的。然后问题就来了

用了2个月,都还不错,但第三个月开始,有一天突然不能访问了。去控制面板一看,关机了。于是reboot
过两天发现又关机了。又reboot,然后当天晚上又关机了。

这TMD太让人纠结了。开始我想,可能是我的系统有问题吧?于是更新补丁,结果第二天还是关机了。难道ubuntu有漏洞?于是我装了一个gentoo,什么软件都没有装,就空着。2天后还是关机了。我晶啊。

今天我想上去看看。结果。。。控制面板也登录不了了,用户名和密码不都是后台自动提供的吗?为什么这也登录不了。
这年头。84真让人郁闷。

如果还有人让我推荐VPS,84我是绝对不会再推荐的了。价格其实现在看来相对于其他的VPS供应商,也没有便宜到哪里去。

busybox

busybox

最近买了一个UIS2000,也就是一个NAS设备了。因为内置了linux操作系统。所以就想着用它来做一些其他的事情,比如备份,比如做个小网站之类的。
但是功能确实不够强大,于是同事建议我下载一个最新的busybox,因为功能更强大。于是我查了一下busybox是干嘛的,用法怎么样,看了一下。哇塞,好方便啊。。。。。。

busybox是一个集成了一百多个最常用linux命令和工具的软件,他甚至还集成了一个http服务器和一个telnet服务器, 而所有这一切功能却只有区区1M左右的大小.我们平时用的那些linux命令就好比是分立式的电子元件,而busybox就好比是一个集成电路,把常用的 工具和命令集成压缩在一个可执行文件里,功能基本不变,而大小却小很多倍,在嵌入式linux应用中,busybox有非常广的应用,另外,大多数 linux发行版的安装程序中都有busybox的身影,安装linux的时候案ctrl+alt+F2就能得到一个控制台,而这个控制台中的所有命令都 是指向busybox的链接.
Busybox的小身材大作用的特性,给制作一张软盘的linux带来了及大方便.
---
关键,它真的很小,带的功能却不少,什么bzip,tar,cat,vi等等常用的都带了。。crontab 都有了。。。。ftpd,httpd,我晕啊。还有什么是它没有的?
----
安装软件也很方便,先./busybox --list,看看有多少功能。然后。。。
可以这样用busybox
#busybox ls
他的功能就相当运行ls命令
最常用的用法是建立指向busybox的链接,不同的链接名完成不同的功能.
#ln -s busybox ls
#ln -s busybox rm
#ln -s busybox mkdir

然后分别运行这三个链接:
#./ls
#./rm
#./mkdir

就可以分别完成了ls rm 和mkdir命令的功能.虽然他们都指向同一个可执行程序busybox
但是只要链接名不同,完成的功能就不同,busybox就是这么的神奇.
很多linux网站都提供busybox的源代码下载.

-----
下面的东东对我来说用不太倒,但我还是贴一下,供有心人做测试:
3,配置busybox

busybox的配置程序和linux内核菜单配置方式简直一模一样.熟悉用make menuconfig方式配置linux内核的朋友很容易上手.

#cp busybox-1.00.tar.gz /babylinux
#cd /babylinux
#tar xvfz busybox-1.00.tar.gz
#cd busybox-1.00
#make menuconfig

下面是需要编译进busybox的功能选项,其他的可以根据需要自选,但是同样不要太贪心.
General Configuration应该选的选项
Show verbose applet usage messages
Runtime SUID/SGID configuration via /etc/busybox.conf

Build Options
Build BusyBox as a static binary (no shared libs)
这个选项是一定要选择的,这样才能把busybox编译成静态链接的可执行文件,运行时才独立于其他函数库.否则必需要其他库文件才能运行,在单一个linux内核不能使他正常工作.

Installation Options
Don't use /usr
这个选项也一定要选,否则make install 后busybox将安装在原系统的/usr下,这将覆盖掉系统原有的命令.选择这个选项后,make install后会在busybox目录下生成一个叫_install的目录,里面有busybox和指向他的链接.

其他选项都是一些linux基本命令选项,自己需要哪些命令就编译进去,一般用默认的就可以了.

配置好后退出并保存.

4,编译并安装busybox

#make
#make install

编译好后在busybox目录下生成子目录_install,里面的内容:
drwxr-xr-x 2 root root 4096 11月 24 15:28 bin
lrwxrwxrwx 1 root root 11 11月 24 15:28 linuxrc -> bin/busybox
drwxr-xr-x 2 root root 4096 11月 24 15:28 sbin
其中可执行文件busybox在bin目录下,其他的都是指向他的符号链接.
我编译出来的busybox可执行文件是935K,加上符号链接,整个_install目录是952K.加上845K的内核不是已经超过1440K了吗?别担心,我们将对整个根文件系统做大幅度的压缩.
-------上面的大部分内容都不是我写的,我只是做了一个简单的COPY。
不过我现在用的很爽。同事也编译了一个PHP,在我不会写bash的时候,我就准备用这个php来完成一些我的脚本了。只保留了两个文件:php和php-cgi。但我觉得php-cgi可能也用不到。。。一个纯php就足够了。黑黑
上面的大部分内容来自:http://hi.baidu.com/pylctstsddhistr/item/36cc0cbd3f44799d19469708

Linux运维常用命令

微博上,@IT程序猿微博达人贴出了常用命令,他说:【Linux运维常用命令】实际运维中经常需要用到的命令,很实用。http://t.cn/zl8wFGQ

看了一下图,确实很常用。
每个-web-开发者都应该知道的关于-url-编码的知识---技术翻译---开源中国社区.pdf

1.删除0字节文件
find-type f -size 0 -exec rm -rf {} ;

2.查看进程
按内存从大到小排列
ps -e -o "%C : %p : %z : %a"|sort -k5 -nr

3.按cpu利用率从大到小排列
ps -e -o "%C : %p : %z : %a"|sort -nr

4.打印说cache里的URL
grep -r -a jpg /data/cache/* | strings | grep "http:" |awk-F'http:' '{print "http:"$2;}'

5.查看http的并发请求数及其TCP连接状态:
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'

6.sed-i '/Root/s/no/yes/' /etc/ssh/sshd_config sed在这个文里Root的一行,匹配Root一行,将no替换成yes.

7.1.如何杀掉mysql进程:
ps aux |grep mysql |grep -v grep|awk '{print $2}' |xargs kill -9 (从中了解到awk的用途)

killall -TERM mysqld

kill -9 `cat /usr/local/apache2/logs/httpd.pid`试试查杀进程PID

8.显示运行3级别开启的服务:
ls /etc/rc3.d/S* |cut-c 15- (从中了解到cut的用途,截取数据)

9.如何在编写SHELL显示多个信息,用EOF
cat << EOF
+--------------------------------------------------------------+
| === Welcome to Tunoff services === |
+--------------------------------------------------------------+
EOF

10. for的巧用(如给mysql建软链接)
cd /usr/local/mysql/bin
for i in *
do ln /usr/local/mysql/bin/$i /usr/bin/$i
done

11.取IP地址:
ifconfig eth0 |grep "inet addr:" |awk '{print $2}'|cut -c 6-或者

ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'

12.内存的大小:
free -m |grep "Mem" | awk '{print $2}'

13.
netstat -an -t | grep ":80" | grep ESTABLISHED | awk '{printf "%s %sn",$5,$6}' | sort

14.查看Apache的并发请求数及其TCP连接状态:
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'

15.因为同事要统计一下服务器下面所有的jpg的文件的大小,写了个shell给他来统计.原来用xargs实现,但他一次处理一部分,搞的有多个总和....,下面的命令就能解决啦.
find / -name *.jpg -exec wc -c {} ;|awk '{print $1}'|awk '{a+=$1}END{print a}'

CPU的数量(多核算多个CPU,cat /proc/cpuinfo |grep -c processor)越多,系统负载越低,每秒能处理的请求数也越多。

---------------------------------------------------------------------------------------
16 CPU负载 # cat /proc/loadavg
检查前三个输出值是否超过了系统逻辑CPU的4倍。

18 CPU负载 #mpstat 1 1
检查%idle是否过低(比如小于5%)

19内存空间 # free
检查free值是否过低也可以用# cat /proc/meminfo

20 swap空间 # free
检查swap used值是否过高如果swap used值过高,进一步检查swap动作是否频繁:
# vmstat 1 5
观察si和so值是否较大

21磁盘空间 # df -h
检查是否有分区使用率(Use%)过高(比如超过90%)如发现某个分区空间接近用尽,可以进入该分区的挂载点,用以下命令找出占用空间最多的文件或目录:
# du -cks * | sort -rn | head -n 10

22磁盘I/O负载 # iostat -x 1 2
检查I/O使用率(%util)是否超过100%

23网络负载 # sar -n DEV
检查网络流量(rxbyt/s, txbyt/s)是否过高

24网络错误 # netstat -i
检查是否有网络错误(drop fifo colls carrier)也可以用命令:# cat /proc/net/dev

25网络连接数目 # netstat -an | grep -E “^(tcp)” | cut -c 68- | sort | uniq -c | sort -n

26进程总数 # ps aux | wc -l
检查进程个数是否正常(比如超过250)

27可运行进程数目 # vmwtat 1 5
列给出的是可运行进程的数目,检查其是否超过系统逻辑CPU的4倍

28进程 # top -id 1
观察是否有异常进程出现

29网络状态检查DNS,网关等是否可以正常连通

30用户 # who | wc -l
检查登录用户是否过多(比如超过50个)也可以用命令:# uptime

31系统日志 # cat /var/log/rflogview/*errors
检查是否有异常错误记录也可以搜寻一些异常关键字,例如:
# grep -i error /var/log/messages
# grep -i fail /var/log/messages

32核心日志 # dmesg
检查是否有异常错误记录

33系统时间 # date
检查系统时间是否正确

34打开文件数目 # lsof | wc -l
检查打开文件总数是否过多

35日志 # logwatch –print配置/etc/log.d/logwatch.conf,将Mailto设置为自己的email地址,启动mail服务(sendmail或者postfix),这样就可以每天收到日志报告了。
缺省logwatch只报告昨天的日志,可以用# logwatch –print –range all获得所有的日志分析结果。
可以用# logwatch –print –detail high获得更具体的日志分析结果(而不仅仅是出错日志)。

36.杀掉80端口相关的进程
lsof -i :80|grep -v "PID"|awk '{print "kill -9",$2}'|sh

37.清除僵死进程。
ps -eal | awk '{ if ($2 == "Z") {print $4}}' | kill -9

38.tcpdump抓包,用来防止80端口被人攻击时可以分析数据
# tcpdump -c 10000 -i eth0 -n dst port 80 > /root/pkts

39.然后检查IP的重复数并从小到大排序注意"-t +0"中间是两个空格
# less pkts | awk {'printf $3"n"'} | cut -d. -f 1-4 | sort | uniq -c | awk {'printf $1" "$2"n"'} | sort -n -t +0

40.查看有多少个活动的php-cgi进程
netstat -anp | grep php-cgi | grep ^tcp | wc -l

chkconfig --list | awk '{if ($5=="3:on") print $1}'

41.kudzu查看网卡型号
kudzu --probe --class=network

匹配中文字符的正则表达式:[u4e00-u9fa5]
评注:匹配中文还真是个头疼的事,有了这个表达式就好办了

匹配双字节字符(包括汉字在内):[^x00-xff]
评注:可以用来计算字符串的长度(一个双字节字符长度计2,ASCII字符计1)

匹配空白行的正则表达式:ns*r
评注:可以用来删除空白行

匹配HTML标记的正则表达式:<(S*?)[^>]*>.*?</1>|<.*? />
评注:网上流传的版本太糟糕,上面这个也仅仅能匹配部分,对于复杂的嵌套标记依旧无能为力

匹配首尾空白字符的正则表达式:^s*|s*$
评注:可以用来删除行首行尾的空白字符(包括空格、制表符、换页符等等),非常有用的表达式

匹配Email地址的正则表达式:w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*
评注:表单验证时很实用

匹配网址URL的正则表达式:[a-zA-z]+://[^s]*
评注:网上流传的版本功能很有限,上面这个基本可以满足需求

匹配帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线):^[a-zA-Z][a-zA-Z0-9_]{4,15}$
评注:表单验证时很实用

匹配国内电话号码:d{3}-d{8}|d{4}-d{7}
评注:匹配形式如0511-4405222或021-87888822

匹配腾讯QQ号:[1-9][0-9]{4,}
评注:腾讯QQ号从10000开始

匹配中国邮政编码:[1-9]d{5}(?!d)
评注:中国邮政编码为6位数字

匹配身份证:d{15}|d{18}
评注:中国的身份证为15位或18位

匹配ip地址:d+.d+.d+.d+

评注:提取ip地址时有用

匹配特定数字:
^[1-9]d*$ //匹配正整数
^-[1-9]d*$ //匹配负整数
^-?[1-9]d*$ //匹配整数
^[1-9]d*|0$ //匹配非负整数(正整数+ 0)
^-[1-9]d*|0$ //匹配非正整数(负整数+ 0)
^[1-9]d*.d*|0.d*[1-9]d*$ //匹配正浮点数
^-([1-9]d*.d*|0.d*[1-9]d*)$ //匹配负浮点数
^-?([1-9]d*.d*|0.d*[1-9]d*|0?.0+|0)$ //匹配浮点数
^[1-9]d*.d*|0.d*[1-9]d*|0?.0+|0$ //匹配非负浮点数(正浮点数+ 0)
^(-([1-9]d*.d*|0.d*[1-9]d*))|0?.0+|0$ //匹配非正浮点数(负浮点数+ 0)
评注:处理大量数据时有用,具体应用时注意修正

匹配特定字符串:
^[A-Za-z]+$ //匹配由26个英文字母组成的字符串
^[A-Z]+$ //匹配由26个英文字母的大写组成的字符串
^[a-z]+$ //匹配由26个英文字母的小写组成的字符串
^[A-Za-z0-9]+$ //匹配由数字和26个英文字母组成的字符串
^w+$ //匹配由数字、26个英文字母或者下划线组成的字符串
评注:最基本也是最常用的一些表达式

那个看内存从小到大的还真不知道。。。。那个取IP地址的,在现在的VPN一键安装包中很常见。我现在写脚本都是用PHP来实现的。现在有了这个,以后考虑用Bash写的时候就有很多参考了。