Archive

Archive for December, 2011

Linux下方便的块设备查看工具lsblk

December 5th, 2011 3 comments

原创文章,转载请注明: 转载自系统技术非业余研究

本文链接地址: Linux下方便的块设备查看工具lsblk

之前在Linux下看有什么块设备,通常都用fdisk什么的或者直接ls /dev/ 人肉去看看, 很土,不方便。 前二天在江枫的网站上看到了介绍的lsblk,这玩意不错,推荐给大家。
这个工具属于util-linux-ng包,在RHEL 6.1上是安装好的啦,直接用就好。 ubuntu高版本下也有。

这个工具最大的特别是把所有的块设备列出,而且还能显示他们之间的依赖关系,演示下:

$ uname -r
2.6.32-131.0.15.el6.x86_64
$ lsblk
NAME   MAJ:MIN RM   SIZE RO MOUNTPOINT
sda      8:0    0   931G  0 
├─sda1   8:1    0   128M  0 /boot
├─sda2   8:2    0   3.9G  0 /
├─sda3   8:3    0     2G  0 [SWAP]
├─sda4   8:4    0     1K  0 
├─sda5   8:5    0   9.8G  0 /usr
├─sda6   8:6    0   9.8G  0 /var
├─sda7   8:7    0   3.9G  0 /opt
├─sda8   8:8    0   3.9G  0 /tmp
└─sda9   8:9    0 897.6G  0 /home
sdc      8:32   0 148.5G  0 
└─md0    9:0    0   594G  0 /u01
sdd      8:48   0 148.5G  0 
└─md0    9:0    0   594G  0 /u01
sde      8:64   0 148.5G  0 
└─md0    9:0    0   594G  0 /u01
sdb      8:16   0 148.5G  0 
└─md0    9:0    0   594G  0 /u01
sr0     11:0    1  1024M  0 

看出来md0依赖于sdb, sdc,sdd,sde, 而sda1依赖sda,很爽!

祝玩得开心!

Post Footer automatically generated by wp-posturl plugin for wordpress.

Categories: Linux, 工具介绍 Tags: ,

巧用Netcat方便网络程序开发

December 5th, 2011 4 comments

原创文章,转载请注明: 转载自系统技术非业余研究

本文链接地址: 巧用Netcat方便网络程序开发

首先介绍下NC,这个号称网络瑞士军刀的工具。

What is Netcat?

Netcat is a featured networking utility which reads and writes data across network connections, using the TCP/IP protocol.
It is designed to be a reliable “back-end” tool that can be used directly or easily driven by other programs and scripts. At the same time, it is a feature-rich network debugging and exploration tool, since it can create almost any kind of connection you would need and has several interesting built-in capabilities.

It provides access to the following main features:

* Outbound and inbound connections, TCP or UDP, to or from any ports.
* Featured tunneling mode which allows also special tunneling such as UDP to TCP, with the possibility of specifying all network parameters (source port/interface, listening port/interface, and the remote host allowed to connect to the tunnel.
* Built-in port-scanning capabilities, with randomizer.
* Advanced usage options, such as buffered send-mode (one line every N seconds), and hexdump (to stderr or to a specified file) of trasmitted and received data.
* Optional RFC854 telnet codes parser and responder.

项目主页:http://netcat.sourceforge.net/
Wiki: http://en.wikipedia.org/wiki/Netcat

再看下我们如何使用NC:
在RHEL服务器里面NC是标配,无需用户自己安装,手册也很全 man nc就好了。

之前在开发服务端程序的时候经常用nc来发报文,模拟客服端的行为, 省的自己写个客户端的麻烦,比如:

$ echo -n "GET / HTTP/1.0\r\n\r\n" | nc host.example.com 80
$ nc [-C] localhost 25 << EOF
HELO host.example.com
MAIL FROM: <user@host.example.com>
RCPT TO: <user2@host.example.com>
DATA
Body of email.
.
QUIT
EOF

这二天从鸣嵩那里学了招模拟服务端的行为, 在调查自己的客户端的时候很方便,来看下:

#模拟服务端
$ nc -l 1234
hello
#模拟客户端
$ nc 127.0.0.1 1234
hello

NC还有其他的功能,读者自己来挖掘!

祝玩得开心!

Post Footer automatically generated by wp-posturl plugin for wordpress.

Categories: Linux, 工具介绍 Tags:

gen_tcp接受链接时enfile的问题分析及解决

December 5th, 2011 1 comment

原创文章,转载请注明: 转载自系统技术非业余研究

本文链接地址: gen_tcp接受链接时enfile的问题分析及解决

最近我们为了安全方面的原因,在RDS服务器上做了个代理程序把普通的MYSQL TCP连接变成了SSL链接,在测试的时候,皓庭同学发现Tsung发起了几千个TCP链接后Erlang做的SSL PROXY老是报告gen_tcp:accept返回{error, enfile}错误。针对这个问题,我展开了如下的调查:

首先man accept手册,确定enfile的原因,因为gen_tcp肯定是调用accept系统调用的:

EMFILE The per-process limit of open file descriptors has been reached.
ENFILE The system limit on the total number of open files has been reached.

从文档来看是由于系统的文件句柄数用完了,我们顺着来调查下:

$ uname -r
2.6.18-164.el5
$ cat /proc/sys/fs/file-nr 
2040    0       2417338
$ ulimit -n
65535

由于我们微调了系统的文件句柄,具体参考这里 老生常谈: ulimit问题及其影响, 这些参数看起来非常的正常。
先看下net/socket.c代码:
Read more…

Post Footer automatically generated by wp-posturl plugin for wordpress.