Category: Linux

  • 代理服务器与 NAT 主机的差异

    以下内容来自鸟哥的linux私房菜

    或许您已经发现了一件事,那就是:在内部局域网络使用私有 IP 的 Client 端不论透过 Proxy 或者 NAT 均可以直接取得 WWW 这个 Internet 的服务,那么 NAT 与 Proxy 有没有什么不同的地方啊?他们不都是可以让内部的 Client 连接出去吗?其实这两个玩意儿差异性是『相当大』的:

    * NAT 是一个利用 TCP/IP 的 packet filter ( 封包过滤机制 )来进行封包处理的一个机制,所以他是『直接分析 TCP/IP 』,所以在设定防火墙的时候,他的弹性比较高,只要能过 NAT 这一关,那么大部分的网络服务都可以使用,因为 TCP/IP 是比较底层的协议啊!要知道的是,TCP/IP 上头还有 port 、还有 IP 等等的信息,单是 port 就可以让我们使用很多的不同的协议了!例如 port 20, 21 是 FTP 啊, 80 是 WWW 啊等等的!所以 NAT 能做的事情事很多的!

    * 至于 Proxy 就不一样了, Proxy 主要透过类似 Squid 这一类的软件来达成的一个服务,基本上,一般来说他是透过 port 3128 来进行数据的监听与传输,单是看到这个 port 3128 就应该要晓得他仅是一个 daemon 而已。Proxy 已经是应用层这个阶段的网络项目了,所以他并没有去分析 TCP 的封包,只要 Client 来源合乎他的需求 (例如 IP 是被支持的 ) ,那么他将透过 daemon 的功能帮使用者达成使用者所想要的任务!所以说,能不能做某些事情,与 Proxy 服务器上面负责的那个 daemon 是有关的!万一 daemon 无法进行 FTP 数据的取得,那么您再怎么努力的尝试上网也是枉然的啊!
    这样说有没有比较有点概念了呢?NAT 是由较底层的网络去进行分析的工作,至于通过 NAT 的封包是干嘛用的, NAT 不去管他!至于 proxy 则主要是由一个 daemon 的功能达成的,所以必需要符合该 daemon 的需求,才能达到某些功能!

    谈完了这些基本的原理之后,我们可得来玩一玩 Proxy 了吧?!事实上,目前有很多的 Proxy 软件,例如 apache 也有提供 proxy 模块的功能喔!但是,最好不要用 Apache 当作您的 Proxy server ,因为…..效能真的太差了~会让您的网络停顿的更厉害~目前 Proxy 的服务器软件当中,以 squid 这个咚咚最出名,会出名的原因是因为他的效能高!真的很不错的一套软件,所以底下我们就针对 squid 来做说明吧!

    通过学习Linux iptables Pocket Reference这本书,对NAT有更进一步了解。

    NAT也就是当包通过本机时,包的地址和/或端口的修改。这个修改可以是包的来源或目的地,也可以是介于之间。

    NAT需要connection tracking,而这又需要包是全可见的。如果防火墙包含着多个电脑,注意不要破坏connection tracking.

    NAT可用于基于地址和端口的操作的一系列功能,同时可以以组来操作

     

  • 不把svn认证保存在本机

    Caching passwords on disk?That’s terrible!You should never do that!”Subversion

    开发者认识到这种担心的合理性,所以 Subversion 使用操作系统和环境提供的机制来减少泄露这些信息的风险。

    下面是在大多数平台上的做法:

    windows平台:

    On Windows,the Subversion client stores passwords in the %APPDATA%/Subversion/auth/ directory.

    On Windows 2000 and later,the standard Windows cryptography services are used toencrypt the password on disk.Because the encryption key is managed by Windows and is tied tothe user’s own login credentials,only the user can decrypt the cached password.(Note that if the user’s Windows account password is reset by an administrator,all of the cached passwords becomeundecipherable.The Subversion client will behave as though they don’t exist,prompting forpasswords when required.)

    Mac OS平台:

    Similarly,on Mac OS X,the Subversion client stores all repository passwords in the login keyring(managed by the Keychain service),which is protected by the user’s account password.Userpreference settings can impose additional policies,such as requiring that the user’s account passwordbe entered each time the Subversion password is used.

    类unix平台:

    For other Unix-like operating systems,no standard “keychain”services exist.However,the Subversionclient knows how to store password securely using the “GNOME Keyring”and “KDE Wallet”services.Also,before storing unencrypted passwords in the ~/.subversion/auth/caching area,theSubversion client will ask the user for permission to do so.Note that the auth/caching area is stillpermission-protected so that only the user (owner)can read data from it,not the world at large.The operating system’s own file permissions protect the passwords from other non-administrativeusers on the same system,provided they have no direct physical access to the storage media of thehome directory,or backups thereof.Of course,for the truly paranoid,none of these mechanisms meets the test of perfection.So forthose folks willing to sacrifice convenience for the ultimate in security,Subversion provides variousways of disabling its credentials caching system altogether.

    你可以关闭凭证缓存,只需要一个简单的命令,使用参数–no-auth-cache:

    $svn commit -F log_msg.txt –no-auth-cacheAuthentication realm:<svn://host.example.com:3690>example realmUsername:joePassword for ‘joe’:Adding newfileTransmitting file data .

    通过配置文件禁用:
    Or,if you want to disable credential caching permanently,you can edit the config file in yourruntime configuration area and set the store-auth-creds option to no.This will prevent thestoring of credentials used in any Subversion interactions you perform on the affected computer.Thiscan be extended to cover all users on the computer,too,by modifying the system-wide runtimeconfiguration area (described in 第 1.1 节 “配置区布局”).

    [auth]store-auth-creds =no

  • svnbook-1.6-zh-r3600.pdf书摘

    下载地址:http://code.google.com/p/i18n-zh/downloads/detail?name=svnbook-1.6-zh-r3600.pdf

    用kindle touch摘书真是方便啊,就是有点小。

     

    但是 Subversion 可以用来管理任何类型的数据 —图像,音乐,数据库,文档等等。对于 Subversion,数据就是数据而已。

    并行版本系统(CVS) Concurrent Versions System

    一个自上至下的学习者会喜欢略读文档,得到对系统工作原理的总体看法;然后她才会开始实际使用软件。而一个自下至上的学习者,是通过实践学习的人,她希望快速的开始使用软件,自己领会软件的使用,只在必要时读取相关章节。大多数图书会倾向于针对某一类读者,而本书毫无疑问倾向于自上至下的方法(如果你阅读了本节,那你也一定是一个自上至下的学习者!)。然而,如果你是自下至上的人,不要失望。本书以 Subversion 为主题的广泛观察进行组织,每个章节都包含了大量可以尝试的详细实例。如果你希望马上开工,没有耐心等待,你可以看附录 A,Subversion

    许多人将版本控制系统当作一种神奇的“时间机器”。

    他们不想在版本控制方法学中开垦处女地,他们只是希望修正CVS。他们决定Subversion应符合CVS的特性,并保留相同的开发模型,但不再重复CVS的一些显著缺陷。尽管 Subversion 并不需要成为 CVS 的完全替代品。

    经过14个月的编码,2001年8月31日,Subversion 能够“自己管理自己”了,开发者停止使用CVS 保存 Subversion 的代码,而使用 Subversion 本身。

    一切都要归结到一条重要的因素:用户交流。当用户交流贫乏,语法和语义的冲突就会增加,没有系统可以强制用户完美的交流,没有系统可以检测语义上的冲突,所以没有任何证据能够承诺锁定系统可以防止冲突,实践中,锁定除了约束了生产力,并没有做什么事。

    svnsync

  • linux显示最后一行的几种方法

    1. tail -n 1 filename
    2. tail -1 filename
    3. sed -n '$p' filename
    4. awk 'END {print}' filename

    如果想显示文本的某一行,比如说第五行:

    awk '{ if(NR==5)print}' filename

    在shell中用变量LineNo代替行号,注意单双引号

    awk "{ if(NR==$LineNo)print}" filename

    5.如果要动态的显示最后一行

     tailf -1 filename

    或几行

     tail -f filename
  • tar命令使用的几个例子

    常用命令:

    -c 创建包
    -x 解包
    -t 列出包中的内容
    -r 增加文件到指定包中
    -u 更新包中的文件

    可选命令:

    -j 使用bzip2
    -z 使用gzip
    -Z 使用compress
    -f  后面跟包的文件名
    -v  显示执行过程
    -C 指定解包后的路径

    例一:tar打包文件(并用gzip压缩)

    tar vczf a.tar.gz hello

    例二:tar不解压 查看目录结构

    tar tvf a.tar.gz | grep ^d

    例三:除了/var/www/clients这个文件夹,打包/var/www中的所有文件和文件夹

    tar vczf www.tar.gz /var/www/ --exclude=clients

    如果要排除多个可以一直加

    --exclude dir1 --exclude a.log --exclude *.jpg

    例四:解压tar.bz2文件

    首先:
    bzip2 -d mono-2.10.tar.bz2
    执行完发现只有一个mono-2.10.tar
    现在再执行
    tar -xvf mono-2.10.tar
    就得到了mono-2.10文件夹

    或直接使用

    tar jxf mono-2.10.tar.bz2

    例五:将多个文件夹打包

    tar -czf abc.tar.gz /home/a /home/b /home/c

    例六:分卷压缩及合并,Linux下备份网站数据,由于目录abc打包成一个文件会比较大,所以想分卷压缩成每个100M的文件,方便下载。

    分卷压缩,使用tar+split组合,进入目录上级目录,执行:
    tar cvzf - abc | split -b 100m
    会产生以x开头的文件,然后把x开头的文件传输到目标地
    合并
    cat x* > abc.tar.gz
    解压
    tar xvzf abc.tar.gz

    例七:解压tar文件

    file命令查看结果是POSIX tar archive格式,使用命令

    tar xvf xxx.tar

    例八:使用tar打包时不使用绝对路径

    如:tar vczf jpuyy.tar.gz /home/jpuyy/

    会提示”tar: Removing leading `/’ from member names”,解压时会在当前目录解压成home/jpuyy。如果想要解压到/home/jpuyy,则使用-C /指令,即

    tar vxzf jpuyy.tar.gz -C /

    例九:提取tar.gz中的指定一个文件,先找到这个文件

    tar tvf redis-2.6.14.tar.gz | grep redis_init_script
    -rwxrwxr-x root/root 1098 2013-06-20 16:36 redis-2.6.14/utils/redis_init_script

    然后执行

    tar xzf redis-2.6.14.tar.gz redis-2.6.14/utils/redis_init_script

    得到想要指定文件。

    例九:只将目录内部的文件打包,不包括顶层目录

    tar czf workspace.tar.gz -C /path/to/workspace .
    

    参考:http://xiaobin.net/200911/tar-removing-leading-slash-from-member-name/

    题外话

    使用gzip压缩

    gzip jpuyy-backup-20121212.sql

    使用gzip解压

    gzip -d jpuyy-backup-20121212.sql.gz
  • cut使用的几个例子

    cut用来截取字符串

    例一:

    以’>’为分段,截取第2段

    如ls -l我的配置文件得到它的真实路径,看到输出的可以以’>’分隔

    jpuyy@www:~$ ls -l jpuyy.com.conf
    lrwxrwxrwx 1 root root 52 2012-03-08 18:03 jpuyy.com.conf ->../sites-available/jpuyy.com.conf

    则执行(-d代表分隔符,可任意发挥,默认TAB;-f代表是第几段,后面可跟子参数N,N-,N-M,-M)

    jpuyy@www:~$ ls -l jpuyy.com.conf | cut -d'>' -f 2
     ../sites-available/jpuyy.com.conf

    例二:取得文件中每行中特定的几个字符

    截取m-n之间字符,语法:

    cut -c m-n filename

    -c后面可跟子参数有N,N-,N-M,-M

    例子:

    cut -c 3-5 /etc/passwd