join连接字段

join命令可以讲多个相同字段的文件结合到一起

NAME
       join - join lines of two files on a common field
SYNOPSIS
       join [OPTION]... FILE1 FILE2

DESCRIPTION
       For each pair of input lines with identical join fields, write a line to standard output.  The default join field is the first,
       delimited by whitespace.  When FILE1 or FILE2 (not both) is -, read standard input.

       -a FILENUM
              print unpairable lines coming from file FILENUM, where FILENUM is 1 or 2, corresponding to FILE1 or FILE2

       -e EMPTY
              replace missing input fields with EMPTY

       -i, --ignore-case ignore differences in case when comparing fields

       -j FIELD
              equivalent to ?.1 FIELD -2 FIELD?

       -o FORMAT
              obey FORMAT while constructing output line

       -t CHAR
              use CHAR as input and output field separator

       -v FILENUM
              like -a FILENUM, but suppress joined output lines

       -1 FIELD
join on this FIELD of file 1
       -2 FIELD
              join on this FIELD of file 2

       --help display this help and exit

       --version
              output version information and exit
[root@localhost shell]# cat tt1
test	100
test1	80
test2	90
[root@localhost shell]# cat tt2
test	yingyu
test1	shuxue
test2	yuwen
[root@localhost shell]# join tt1 tt2
test 100 yingyu
test1 80 shuxue
test2 90 yuwen

使用sed创建目录和简单匹配替换

sed 创建目录结构。

 find /shell/a/ -type d -print | sed 's;/shell/a/;/shell/b/;' | sed 's/^/mkdir /'
mkdir /shell/b/
mkdir /shell/b/p
find 查找目录, -type 是指定类型为目录,并打印出来
sed 's;/shell/a/;/shell/b/;' 修改名称,这里使用分号做为定界符
sed 's/^mkdir /'  插入mkdir 命令
也可以使用后向引用:
[root@localhost shell]# find /shell/ -type d -print | sed 's;/\(shell\)/a/;\1/c/;' |sed 's/^/mkdir /'
mkdir /shell/
mkdir /shell/a
mkdir shell/c/p
mkdir /shell/b
mkdir /shell/b/p
[root@localhost shell]# grep ^root passwd
root:x:0:0:root:/root:/bin/bash
[root@localhost shell]# sed -n '\:root: s;;Root;p' passwd
Root:x:0:0:root:/root:/bin/bash
改变定界符,以:开始查找的模式,而分号为扮演s命令的定界符角色
[root@localhost shell]# echo "123" | sed 's/1*/b/'    #替换第一个匹配成的
b23
[root@localhost shell]# echo "123" | sed 's/1*/b/g'    #替换所有匹配成功的
b2b3b

三大WEB服务器对比分析(apache ,lighttpd,nginx)转载

一.软件介绍(apache  lighttpd  nginx)

1. lighttpd

Lighttpd是一个具有非常低的内存开销,cpu占用率低,效能好,以及丰富的模块等特点。lighttpd是众多OpenSource轻量级的web server中较为优秀的一个。支持FastCGI, CGI, Auth, 输出压缩(output compress), URL重写, Alias等重要功能。

Lighttpd使用fastcgi方式运行php,它会使用很少的PHP进程响应很大的并发量。

Fastcgi的优点在于:

·         从稳定性上看, fastcgi是以独立的进程池运行来cgi,单独一个进程死掉,系统可以很轻易的丢弃,然后重新分配新的进程来运行逻辑.

·         从安全性上看, fastcgi和宿主的server完全独立, fastcgi怎么down也不会把server搞垮,

·         从性能上看, fastcgi把动态逻辑的处理从server中分离出来, 大负荷的IO处理还是留给宿主server, 这样宿主server可以一心一意作IO,对于一个普通的动态网页来说, 逻辑处理可能只有一小部分, 大量的图片等静态IO处理完全不需要逻辑程序的参与(注1) Read the rest of this entry »

linux lvm快速建立逻辑卷,简单快照,以及应用

今天就写一篇关于lvm 逻辑卷的文章,本人对于lvm知道的也不是很多,只是根据想要实现的功能,用到了lvm快照。

LVM介绍:

LVM(Logical Volume Manager)即逻辑卷管理器,它最先是在Linux 2.4内核中被集成到内核中去的,它的出现改变了传统的磁盘空间管理理念。以往在安装操作系统时需要规划好分区大小,即使利用了RAID技术也要规划好每个分区的大小,因为一旦分好区后要改变其大小是非常困难的事情。在Windows下有大家熟悉的Partition Magic工具可以用来调整分区大小,但它有一个缺点是要么在调整前要关闭系统或调整后重启系统。

这在普通PC机上使用还行,要在提供不间断服务的服务器上使用就会造成服务中断,不过这个问题在Linux下随着LV技术的出现一切都得到解决,LV可以在不用重启系统的情况动态增加可用空间大小,不过前提得是使用热插拔硬盘,或事先将硬盘装入而不使用。本文我将使用名词LV(可不是LV包)而不是LVM,因为LV才是主角。 Read the rest of this entry »

centos linux 内核升级,内核编译步骤

Centos 内核升级,升级步骤记录

linux kernel 主页:www.kernel.org

下载:wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.39.4.tar.bz2

1.查看当前系统的版本:

[root@xyly ~]# uname  -a
Linux xyly 2.6.18-164.el5 #1 SMP Thu Sep 3 03:28:30 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux

当前系统内核版本为2.6.18-164.el5,而下载的kernel 版本为2.6.39.4

2,内核的编译步骤。

[root@xyly ~]#cd /usr/src

[root@xyly ~]# tar jxvf linux-2.6.39.4.tar.bz2

[root@xyly ~]# cd  linux-2.6.39.4

[root@xyly linux-2.6.39.4]# make mrproper                          #去除内核的依赖关系及编译后的垃圾信息 Read the rest of this entry »

linux ssh 密钥认证自动登录

SSH简介:

传统的网络服务程序,SSH的英文全称是 Secure Shell,通过使用ssh,可以对所有的传输的数据进行加密,这样既可以防止攻击又可以防止IP欺骗。

SSH 提供2种级别的安全验证

1,基于口令的安全验证,这也是我们常用的一种,只要知道用户名和密码,就可以远程登陆到远程主机上。

2,基于密钥的安全认证,就是说用户必须为自己创建一对密钥,并把公用密钥放到需要访问的服务器上。

2种安全级别的验证,后者相对比前者更安全一些,第二种级别不需要在网络上传递口令。

SSH密钥认证登录配置 Read the rest of this entry »

nginx转发apache,apache获取真实ip地址

1.在nginx.conf中的http 中添加以下内容

proxy_set_header      Host $host;
proxy_set_header      X-Real-IP $remote_addr;
proxy_set_header      X-Forwarded-For $proxy_add_x_forwarded_for;

或者加上include 在当前目录下有个proxy.conf  也可以,写法如下:

include proxy.conf;

2.下载apache的第三方模块 mod_rpaf

下载地址:http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz

安装mod_rpaf

tar zxf mod_rpaf-0.6.tar.gz
cd mod_rpaf-0.6
/usr/local/webserver/apache/bin/apxs -i -c -n mod_rpaf-2.0.so mod_rpaf-2.0.c    #apache 2.x 安装方法(1.x的有全区别)

安装完毕,开始配置apache的http.conf配置文件,添加一下内容:

LoadModule rpaf_module modules/mod_rpaf-2.0.so

RPAFenable On
RPAFsethostname On
RPAFproxy_ips 192.168.1.253 127.0.0.1 #填写你nginx web 转发的ip地址
RPAFheader X-Forwarded-For

保存,重启 nginx apache 即可!

Centos linux 上安装Perl DBD::mysql驱动

Perl连接数据库需要安装DBI模块和相应数据库的DBD驱动,Linux上默认安装的Perl是没有该模块的,所以要手动安装。

另外要注意的是,安裝过程会用到 mysql_config 指令。所以用 源码 安裝 MySQL 则可以正常启动,但如果 MySQL 是用 RPM 安裝,就要确定你有 mysql-devel 套件,沒裝的话可至 MySQL 的下载页面下载你目前版本的「Libraries and header files」。

下载dbd:http://search.cpan.org/CPAN/authors/id/C/CA/CAPTTOFU/DBD-mysql-4.020.tar.gz

开始安装:

tar zxvf DBD-mysql-4.020.tar.gz
cd DBD-mysql-4.020
perl Makefile.PL --testdb=test --testuser=root --testpassword=123456 --testhost=xyly --with-mysql=/usr/local/webserver/mysql/ --mysql_config=/usr/local/webserver/mysql/bin/mysql_config
###安装的时候要注意设置你的用户名和密码,可以看下help,perl Makefile.PL --help
make
make test
make install
简单的安装就到此为止了,如果是别的系统,请参照官方手册:http://cpansearch.perl.org/src/RUDY/DBD-mysql-2.9003/INSTALL.html