Nanjing Linux User Group

May 19, 2012

alswl

《写给大家看的设计书》读后感

我读过两本关于视觉设计的书,一本是《写给程序员的Web设计书》, 这是第二本《写给大家看的设计书》

写给大家看的设计书

我对前者的评价是「作者花了大约25%的篇幅来讲述设计理念和方法,这也是我真正想看的部分。 本来想从书中获取更多布局、色彩、字体的内容,发现还是太少了。图灵系的书翻译不错。」

相对应的,《写给大家看的设计书》是我真心想看的设计入门书。作者的文字功底好,经验丰富, 范例适合,取材广泛,总之,是不可多得的一本好书。

书中提到了设计四大原则:亲密性 / 对齐 / 重复 / 对比。依靠这四个原则, 就可以设计出效果不错的出版物(包括书籍、文档、幻灯片、网页等等)

  • 对比(Contrast):对比的基本思想是,要避免页面上的元素过于相似,如果元素 (字体、颜色、大小、线宽、形状、空间等)不相同,那就干脆让它们截然不同。 要让页面引人注目,对比通常是最重要的一个因素,正是它能使读者首先看到这个页面。

  • 重复(Repetition):让设计中的视觉要素在整个作品中重复出现。 可以重复颜色、形状、材质、空间关系、线宽、字体、大小和图片,等等。 这样依赖,既能增加条理性,还可以加强统一性。

  • 对齐(Alignment):任何东西都不能在页面上随意安放。 每个元素都应当与页面的另一个元素有某种视觉联系。这样能建立一种清晰、 精巧而且清爽的外观。

  • 亲密性(Proximity):彼此相关的项应当靠近,归组在一起。 如果多个项相互之间存在很近的亲密性,它们就会成为一个视觉单元, 而不是多个孤立的元素。这有助于组织信息,减少混乱,为读者提供清晰的结构。

除了设计的四大原则,书中还花费 1/3 的篇幅介绍西文字体, 看完可以对字体有一些初步认识。唯一遗憾的是,中文字体属于 CJK 体系, 书中没有介绍。

西文字体主要分

  • Oldstyle
  • Modern
  • Slab serif
  • Sans serif
  • Script
  • Decorative

我认为做产品的、做前端的,或者对艺术和美感兴趣的(比如我),都应该读一读这本书。

May 19, 2012 10:10 AM

May 18, 2012

王宇希

目录下的隐藏文件

$ cp -a /home/jaseywang/. /tmp/
$ cp /home/jaseywang/.[^.]* /tmp/

注意:下面这种方式是错误的,这会复制本级目录以及上层目录的内容:
$ cp -a /home/jaseywang/.* /tmp/

由此引申的,ls, rm, mv 等都是一个原理。

$ rm -rf /home/jaseywang/.??*
$ find /home/jaseywang/ -iname ".*" -maxdepth 1 -type f
$ find /home/jaseywang/ -iname ".*" -maxdepth 1 -type d
$ find /home/jaseywang/ -iname ".*" -maxdepth 1 -type f -delete
$ find /home/jaseywang/ -iname ".*" -maxdepth 1 -type f -exec rm {} \;
$ find /home/jaseywang/ -iname ".*" -maxdepth 1 -type d -exec rm -rf {} \;

 

by jaseywang at May 18, 2012 07:42 AM

May 17, 2012

alswl

关于 NetworkManager / PolicyKit / ConsoleKit 的那些屌事

在使用 Awesome 的过程中,我又遇到了一个老问题「NetworkManager 在非 Gnome 环境启动后,会无法 添加 / 删除 / 编辑 无线连接」。明眼人一看就知道, 这是权限的问题。

问题描述

我的环境是 ArchLinux / xmonad 0.10 / awesome v3.4.11 / GDM 3.4.1 / NetworkManager 0.9.4.0, 下面我用 awesome 做示例,其他非 Gnome WM 也应该是类似配置。

我的 WM 启动流程是: 通过 GDM 启动 xmonad / awesome,启动 xsession 是 /usr/share/xsessions/awesome.desktop, 内容如下

1
2
3
4
5
6
[Desktop Entry]
Name=Awesome
Comment=This session logs you into Awesome
Type=Application
Exec=ck-launch-session dbus-launch $HOME/.start-session.sh awesome
TryExec=/usr/bin/awesome

$HOME/.start-session.sh 中的作用是启动 nm-appletexec awesome

启动之后的情况是 NetworkManager 无线 编辑/删除 按钮变灰无法点击,或者可以点击, 但是会发生 insufficient privileges 错误。

insufficient privileges

问题原因

这个问题是由 PolicyKit 和 ConsoleKit 启动不当引起的。

PolicyKit 是:

PolicyKit allows fine-tuned capabilities in desktop enviroment. Traditionally only privilaged user (root) was allowed to configure network. However while in server enviroment it is reasonable assumption it would be too limiting to not allowed to connect to hotspot on laptop. Still however you may not want to give full privilages to this person (like installing programs) or you want to limit options for some people (for example on your children laptops only ‘trusted’ networks with parential filters can be used). As far as I remember it works like:

  • Program send message to daemon via dbus about action
  • Daemon uses PolicyKit libraries/configuration (in fact PolicyKit daemon) to determine if user is allowed to perform action. It may happen that the certain confition must be fullfilled (like entering password or hardware access).
  • Deamon performs action according to it (returns auth error or perform action)

ConsoleKit 是:

In short consolekit is service which tracks user sessions (i.e. where user is logged in). It allows switching users without logging out [many user can be logged in on the same hardware at the same time with one user active]. It is also used to check if session is “local” i.e. if user have direct access to hardware (which may be considered more secure then remote access).

参考:What are ConsoleKit and PolicyKit? How do they work?

所以简而言之,ConsoleKit 是用来管理用户会话的,PolicyKit 是用来处理用户申请特殊权限的, 他们两个经常工作在一起。

有个 PolicyKit 认证 API 教程可以一看:

我的这个问题就是由于 PolicyKit 无法正确授权引起的。

问题解决

我开始吭次吭次的 Google,一会就找到了 Arch Wiki 中 NetworkManager 的解决办法:

1
exec ck-launch-session dbus-launch wm

写的很清楚,使用 ck-launch-sessiondbus-launch 来加载 WM。但是我已经使用 ck-launch-session 来启动 WM 了。

随后我把怀疑的目光放到 /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1 这个程序给系统提供 PolicyKit 权限认证,请求时候会让用户输入密码,如下图:

PolicyKit Agent

可惜还是不行。

我甚至还参考Using gnome keyring in xmonad 试图手工建立一个 Gnome Keyring。事实证明,Gnome Keyring 和这个问题无关。

最后,我用 ck-list-sessions 命令查看运行的用户 Session,发现同时运行着两个, 一个处于 Active,一个不处于 Active,这下真相大白了:GDM 启动时候会自己启动 ck-launch-session,不用自己手动启动,否则会造成两个会话而无法正确授权。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Session2:
  unix-user = '1000'
  realname = 'Jason Ti'
  seat = 'Seat1'
  session-type = ''
  active = TRUE
  x11-display = ':0'
  x11-display-device = '/dev/tty7'
  display-device = ''
  remote-host-name = ''
  is-local = TRUE
  on-since = '2012-05-17T00:54:31.706019Z'
  login-session-id = '2'
Session3:
  unix-user = '1000'
  realname = 'Jason Ti'
  seat = 'Seat1'
  session-type = ''
  active = False
  x11-display = ':0'
  x11-display-device = '/dev/tty7'
  display-device = ''
  remote-host-name = ''
  is-local = TRUE
  on-since = '2012-05-17T00:54:33.3465302Z'
  login-session-id = '2'

修正 /usr/share/xsessions/awesome.desktop 如下:

1
2
3
4
5
6
[Desktop Entry]
Name=Awesome
Comment=This session logs you into Awesome
Type=Application
Exec=$HOME/.start-session.sh awesome
TryExec=/usr/bin/awesome

事实上,在启动完 GDM 还没进入 WM 之前,Ctrl+Alt+F1 切换到命令行下面,查看进程会发现

1
2
3
root       637     1  0 08:44 ?        00:00:00 /usr/lib/polkit-1/polkitd --no-debug
root      1072     1  0 08:44 ?        00:00:00 /usr/sbin/console-kit-daemon --no-daemon
rtkit     1260     1  0 08:45 ?        00:00:00 /usr/lib/rtkit-daemon

果不其然,PolicyKit 和 ConsoleKit 已经在运行了。

实测 Awesome / Xmonad 已经可以正常授权 NetworkManager 来编辑无线了。

May 17, 2012 01:07 AM

May 16, 2012

王宇希

Linux Kernel in a Nutshell 笔记(一)

2.Requirements for Building and Using the Kernel

注意:
1.在编译内核的过程中,从 downloading 到 uncompress 到 configure 以及 build 务必不要使用 root,只有在 install 器件的两三个命令需要用到 root 权限。
2.kernel 的源代码不要放在 /usr/src/ 目录下,该目录下是放置一些头文件以及系统库文件的地方,另外,开发啥的也不要在此目录下进行。

编译一个 kernel,无外乎这三个工具。

compiler,一般情况下就是 gcc 了:
$ gcc --version
gcc (Ubuntu 4.4.3-4ubuntu5.1) 4.4.3
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

linker,binutils 工具包包含链接需要的工具:
$ ld -v
GNU ld (GNU Binutils for Ubuntu) 2.20.1-system.20100303

make,一般是在 make 包里面:
$ make --version
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for x86_64-pc-linux-gnu

对于大部分的程序来说,内核的升级对其没有影响,但是有些系统级别的程序由于内核的升级会产生一些问题,如果升级了内核,这些工具可能也需要升级到对应的版本。

util-linux
跟磁盘相关的,挂载,格式化,硬件时钟等:
$ fdformat --version
fdformat (util-linux-ng 2.17.2)
$ sudo apt-cache show util-linux | head
Package: util-linux
Essential: yes
Priority: required
Section: utils
Installed-Size: 2344
Maintainer: Ubuntu Core Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: LaMont Jones <lamont@debian.org>
Architecture: amd64
Version: 2.17.2-0ubuntu1.10.04.2
Replaces: e2fsprogs (<= 1.41.8-1ubuntu1), fdisk, linux32, miscutils, schedutils, setterm, sparc-utils

module-init-tools
跟内核模块相关的,对于 2.6.18 的内核来说,0.9.10 版本是其最老的能够工作的版本,建议升级到新的版本,这样可能带来更多的功能,比如 blacklistint modules 来阻止 udev 来自动加载模块的功能就是新版本才有的:
$ depmod -V
module-init-tools 3.11.1
$ sudo apt-cache show module-init-tools | head
Package: module-init-tools
Priority: required
Section: admin
Installed-Size: 376
Maintainer: Scott James Remnant <scott@ubuntu.com>
Architecture: amd64
Version: 3.11.1-2ubuntu1
Depends: libc6 (>= 2.8), upstart-job
Breaks: initramfs-tools (<< 0.92bubuntu23)
Filename: pool/main/m/module-init-tools/module-init-tools_3.11.1-2ubuntu1_amd64.deb

filesystem-spceific tools
文件系统相关的

ext 系统的使用 e2fsprogs 这个工具,ext2/ext3/ext4:
$ tune2fs 
tune2fs 1.41.11 (14-Mar-2010)
$ sudo apt-cache show e2fsprogs | head
Package: e2fsprogs
Essential: yes
Priority: required
Section: admin
Installed-Size: 2148
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Theodore Y. Ts'o <tytso@mit.edu>
Architecture: amd64
Version: 1.41.11-1ubuntu2.1
Replaces: hurd (<= 20040301-1), libblkid1 (<< 1.38+1.39-WIP-2005.12.10-2), libuuid1 (<< 1.38+1.39-WIP-2005.12.10-2)

JFS
$ fsck.jfs -V
$ sudo apt-cache show  jfsutils | head

Package: jfsutils
Priority: optional
Section: admin
Installed-Size: 1128
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Stefan Hornburg (Racke) <racke@linuxia.de>
Architecture: amd64
Version: 1.1.12-2.1
Depends: libc6 (>= 2.7), libuuid1 (>= 2.16-1)
Filename: pool/main/j/jfsutils/jfsutils_1.1.12-2.1_amd64.deb

ReiserFS
$ reiserfsck -V
$ sudo apt-cache show  reiser4progs | head

Package: reiser4progs
Priority: optional
Section: admin
Installed-Size: 1284
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Felix Zielcke <fzielcke@z-51.de>
Architecture: amd64
Version: 1.0.7-5ubuntu1
Depends: libc6 (>= 2.7), libncurses5 (>= 5.6+20071006-3), libreadline6 (>= 6.0), libuuid1 (>= 2.16)
Filename: pool/main/r/reiser4progs/reiser4progs_1.0.7-5ubuntu1_amd64.deb

XFS
$ xfs_db -V
$ sudo apt-cache show  xfsprogs| head

Package: xfsprogs
Priority: optional
Section: admin
Installed-Size: 3412
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Nathan Scott <nathans@debian.org>
Architecture: amd64
Version: 3.1.0ubuntu1
Provides: fsck-backend
Depends: libc6 (>= 2.10), libreadline6 (>= 6.0), libuuid1 (>= 2.16)

Quota
配额相关的:
$ quota -V
$ sudo apt-cache show  quota | head

Package: quota
Priority: optional
Section: admin
Installed-Size: 1468
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Michael Meskes <meskes@debian.org>
Architecture: amd64
Version: 3.17-6
Depends: e2fslibs (>= 1.37), libc6 (>= 2.7), libcomerr2 (>= 1.01), libdbus-1-3 (>= 1.0.2), libldap-2.4-2 (>= 2.4.7), libnl1 (>= 1.1), libwrap0 (>= 7.6-4~), debconf (>= 1.2.9) | debconf-2.0, lsb-base (>= 3.2-13)
Suggests: libnet-ldap-perl, rpcbind | portmap

NFS
网络文件系统,主要是 nfs-common 这个包:
$ showmount --version
$ sudo apt-cache show  nfs-common | head

Package: nfs-common
Priority: optional
Section: net
Installed-Size: 632
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Anibal Monsalve Salazar <anibal@debian.org>
Architecture: amd64
Source: nfs-utils
Version: 1:1.2.0-4ubuntu4.2
Replaces: mount (<< 2.13~), nfs-client, nfs-kernel-server (<< 1:1.0.7-5)

udev
设备命名相关的,由于 /dev/ 以来 /sys/,而 /sys/ 会随着内核的升级而经常改变,所以建议使用随 kernel 发行的 udev,2.6.18 的内核的的最老的版本为 081:
$ udevadm  --version
151
$ sudo apt-cache show udev | head
Package: udev
Priority: required
Section: admin
Installed-Size: 1592
Maintainer: Scott James Remnant <scott@ubuntu.com>
Architecture: amd64
Version: 151-12.3
Replaces: hotplug, ifrename, initramfs-tools (<< 0.040ubuntu1), udev-extras (<= 20090618)
Depends: libacl1 (>= 2.2.11-1), libc6 (>= 2.9), libglib2.0-0 (>= 2.16.0), libselinux1 (>= 1.32), libusb-0.1-4 (>= 2:0.1.12), upstart-job, module-init-tools (>= 3.2.1-0ubuntu3), initramfs-tools (>= 0.92bubuntu63), procps, adduser, util-linux (>> 2.15~rc2)
Suggests: watershed

process tools
查看进程的包:
$ ps --version
procps version 3.2.8
$ sudo apt-cache show procps | head
Package: procps
Priority: required
Section: admin
Installed-Size: 808
Maintainer: Ubuntu Core Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Craig Small <csmall@debian.org>
Architecture: amd64
Version: 1:3.2.8-1ubuntu4.2
Replaces: bsdutils (<< 2.9x-1), watch
Provides: watch

by jaseywang at May 16, 2012 01:19 PM

May 15, 2012

孙峻文

sunjw.us is live now

sunjw.us is live now.

Android Design has a new mirror.

This blog has been moved to sunjw.us.

No longer update here.

by sunjwvista at May 15, 2012 12:14 PM

May 13, 2012

王宇希

热插拔的一些问题

一台 R510,12 块硬盘,在启动进行 SAS 检查的时候只能检查到 11 块硬盘,slot 7的硬盘缺失(编号从 0 开始,到 slot 11),最初没有理会这个问题,系统照装,安装完毕后磁盘的编号如下:
$ ls /dev/sd*
sda   sdc   sdc2  sdd   sde   sdf   sdg   sdh   sdi   sdj   sdk   sdl   sdm
sdb   sdc1  sdc5  sdd1  sde1  sdf1  sdg1  sdh1  sdi1  sdj1  sdk1  sdl1  sdm1

系统启动加载硬盘的信息:
$ dmesg  | grep disk
[    9.008580] sd 1:0:0:0: [sda] Attached SCSI removable disk
[    9.133147] sd 2:0:0:1: [sdb] Attached SCSI removable disk
[   13.128908] sd 0:0:1:0: [sdd] Attached SCSI disk
[   13.131742] sd 0:0:2:0: [sde] Attached SCSI disk
[   13.133006] sd 0:0:0:0: [sdc] Attached SCSI disk
[   13.133979] sd 0:0:3:0: [sdf] Attached SCSI disk
[   13.137656] sd 0:0:4:0: [sdg] Attached SCSI disk
[   13.141043] sd 0:0:5:0: [sdh] Attached SCSI disk
[   13.142132] sd 0:0:6:0: [sdi] Attached SCSI disk
[   13.145329] sd 0:0:7:0: [sdj] Attached SCSI disk
[   13.150285] sd 0:0:8:0: [sdk] Attached SCSI disk
[   13.150904] sd 0:0:9:0: [sdl] Attached SCSI disk
[   13.153535] sd 0:0:10:0: [sdm] Attached SCSI disk

从内核动态的 scsi 文件中可以看到硬盘的排列是从 0-10 的:
$ cat /proc/scsi/scsi
Attached devices:
Host: scsi1 Channel: 00 Id: 00 Lun: 00
  Vendor: iDRAC    Model: LCDRIVE          Rev: 0323
  Type:   Direct-Access                    ANSI  SCSI revision: 00
Host: scsi2 Channel: 00 Id: 00 Lun: 00
  Vendor: iDRAC    Model: Virtual CD       Rev: 0323
  Type:   CD-ROM                           ANSI  SCSI revision: 00
Host: scsi2 Channel: 00 Id: 00 Lun: 01
  Vendor: iDRAC    Model: Virtual Floppy   Rev: 0323
  Type:   Direct-Access                    ANSI  SCSI revision: 00
Host: scsi0 Channel: 00 Id: 00 Lun: 00
  Vendor: SEAGATE  Model: ST3600057SS      Rev: ES65
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi0 Channel: 00 Id: 01 Lun: 00
  Vendor: SEAGATE  Model: ST3600057SS      Rev: ES65
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi0 Channel: 00 Id: 02 Lun: 00
  Vendor: SEAGATE  Model: ST3600057SS      Rev: ES65
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi0 Channel: 00 Id: 03 Lun: 00
  Vendor: SEAGATE  Model: ST3600057SS      Rev: ES65
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi0 Channel: 00 Id: 04 Lun: 00
  Vendor: SEAGATE  Model: ST3600057SS      Rev: ES65
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi0 Channel: 00 Id: 05 Lun: 00
  Vendor: SEAGATE  Model: ST3600057SS      Rev: ES65
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi0 Channel: 00 Id: 06 Lun: 00
  Vendor: SEAGATE  Model: ST3600057SS      Rev: ES65
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi0 Channel: 00 Id: 07 Lun: 00
  Vendor: SEAGATE  Model: ST3600057SS      Rev: ES65
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi0 Channel: 00 Id: 08 Lun: 00
  Vendor: SEAGATE  Model: ST3600057SS      Rev: ES65
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi0 Channel: 00 Id: 09 Lun: 00
  Vendor: SEAGATE  Model: ST3600057SS      Rev: ES65
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi0 Channel: 00 Id: 10 Lun: 00
  Vendor: SEAGATE  Model: ST3600057SS      Rev: ES65
  Type:   Direct-Access                    ANSI  SCSI revision: 05

后来将 slot 7 的硬盘取出,换上新的硬盘,此时从 scsi 上读到的是新硬盘的 ID 为 11,磁盘编号变为了 sdn。显然,我们想要的是 slot 11 的磁盘编号对应 sdn,slot 11 对应 sdm … slot 7 对应的则是 sdj。然后做了下面这个实验,系统盘是在 slot 0 上,其余从 slot 1 到 slot 11 都是做数据,没有 RAID。将数据的 11 块硬盘全部格式化,依照对应的 slot 进行重新划分,也就是说:
slot 0     – sdc
slot 1     – sdd
slot 2     – sde
slot 3     – sdf
slot 4     – sdg
slot 5     – sdh
slot 6     – sdi
slot 7     – sdj *
slot 8     – sdk
slot 9     – sdl
slot 10 – sdm
slot 11 – sdn

然后 mount -a,此时很完美,/proc/partitions, /proc/scsi/scsi 显示的都是理想的对应情况。接下来,我将 slot 7 上的硬盘给直接拔出,scsi 显示如下信息:
$ cat /proc/scsi/scsi
Attached devices:
Host: scsi1 Channel: 00 Id: 00 Lun: 00
  Vendor: iDRAC    Model: LCDRIVE          Rev: 0323
  Type:   Direct-Access                    ANSI  SCSI revision: 00
Host: scsi2 Channel: 00 Id: 00 Lun: 00
  Vendor: iDRAC    Model: Virtual CD       Rev: 0323
  Type:   CD-ROM                           ANSI  SCSI revision: 00
Host: scsi2 Channel: 00 Id: 00 Lun: 01
  Vendor: iDRAC    Model: Virtual Floppy   Rev: 0323
  Type:   Direct-Access                    ANSI  SCSI revision: 00
Host: scsi0 Channel: 00 Id: 00 Lun: 00
  Vendor: SEAGATE  Model: ST3600057SS      Rev: ES65
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi0 Channel: 00 Id: 01 Lun: 00
  Vendor: SEAGATE  Model: ST3600057SS      Rev: ES65
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi0 Channel: 00 Id: 02 Lun: 00
  Vendor: SEAGATE  Model: ST3600057SS      Rev: ES65
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi0 Channel: 00 Id: 03 Lun: 00
  Vendor: SEAGATE  Model: ST3600057SS      Rev: ES65
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi0 Channel: 00 Id: 04 Lun: 00
  Vendor: SEAGATE  Model: ST3600057SS      Rev: ES65
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi0 Channel: 00 Id: 05 Lun: 00
  Vendor: SEAGATE  Model: ST3600057SS      Rev: ES65
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi0 Channel: 00 Id: 06 Lun: 00
  Vendor: SEAGATE  Model: ST3600057SS      Rev: ES65
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi0 Channel: 00 Id: 08 Lun: 00
  Vendor: SEAGATE  Model: ST3600057SS      Rev: ES65
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi0 Channel: 00 Id: 09 Lun: 00
  Vendor: SEAGATE  Model: ST3600057SS      Rev: ES65
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi0 Channel: 00 Id: 10 Lun: 00
  Vendor: SEAGATE  Model: ST3600057SS      Rev: ES65
  Type:   Direct-Access                    ANSI  SCSI revision: 05

$ df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sdc5            576671280 149679332 397698740  28% /
none                  24769492       304  24769188   1% /dev
none                  24773936         0  24773936   0% /dev/shm
none                  24773936        72  24773864   1% /var/run
none                  24773936         0  24773936   0% /var/lock
none                  24773936         0  24773936   0% /lib/init/rw
/dev/sdc1               188403     36940    141735  21% /boot
/dev/sdd1            576862176    202304 547356912   1% /data/data1
/dev/sde1            576862176    202304 547356912   1% /data/data2
/dev/sdf1            576862176    202304 547356912   1% /data/data3
/dev/sdg1            576862176    202304 547356912   1% /data/data4
/dev/sdh1            576862176    202304 547356912   1% /data/data5
/dev/sdi1            576862176    202304 547356912   1% /data/data6
/dev/sdj1            576862176    202304 547356912   1% /data/data7
/dev/sdk1            576862176    202304 547356912   1% /data/data8
/dev/sdl1            576862176    202304 547356912   1% /data/data9
/dev/sdm1            576862176    202304 547356912   1% /data/data10
/dev/sdn1            576862176    202304 547356912   1% /data/data11

可以看到 slot 7 上的硬盘确实被拔出了:
$ cd /data/data11
$ ll
ls: reading directory .: Input/output error
total 0
$ sudo umont /data/data11

接下来,我再准备将其再插上去,我肯定希望系统能再次识别出如下的信息:
Host: scsi0 Channel: 00 Id: 07 Lun: 00
  Vendor: SEAGATE  Model: ST3600057SS      Rev: ES65
  Type:   Direct-Access                    ANSI  SCSI revision: 05

于是 g 了一下,说可以像下面这样操作:
1.将新硬盘插到机器上
2.echo "scsi add-single-device 0 0 7 0" > /proc/scsi/scsi

上面的几个数字分别代表 Host, Channel, Id, Lun,其中第一个 Host 也就是 SAS 控制器。参照 scsi 里面其余的硬盘就知道规律了。按照上面说的做了,但是奇怪的是,slot 7 的那块硬盘并没有像想象的那样安排在 Id 为 07 的位置上,而是显示为了 12。
考虑到我刚刚是直接硬拔出来的,先进行如下操作,再将 slot 7 的硬盘再次拔出:
# echo "scsi remove-single-device 0 0 12 0" > /proc/scsi/scsi

然后在插上,但是此时 Id 又变成了 13。最后 reboot 了一下,又恢复到了我们的理想状态,slot 7 的 Id 恢复为了 7。尽管这个对系统运行没有什么影响,但是每拔一次 Id 有要变一次的情况,看着实在是不舒服。

ref:
https://raid.wiki.kernel.org/articles/h/a/r/Hardware_issues.html
http://www-uxsup.csx.cam.ac.uk/pub/doc/suse/suse9.3/suselinux-adminguide_en/cha.hotplug.html
http://rackerhacker.com/2009/04/23/re-scan-the-scsi-bus-in-linux-after-hot-swapping-a-drive/

http://serverfault.com/questions/5336/how-do-i-make-linux-recognize-a-new-sata-dev-sda-drive-i-hot-swapped-in-without

by jaseywang at May 13, 2012 06:48 AM

May 11, 2012

王宇希

寂寞的时候,我就坐在桌子上,45 度角仰望天空

困的眼睛都睁不开了,要睡觉觉了耶


寂寞的时候,我就坐在桌子上,45 度角仰望天空

我在乐此不疲的舔爪子

45 度角,仰望天空,之后,继续舔爪子

困的眼睛都睁不开了,要睡觉觉了耶 寂寞的时候,我就坐在桌子上,45 度角仰望天空 我在乐此不疲的舔爪子 45 度角,仰望天空,之后,继续舔爪子

by jaseywang at May 11, 2012 04:43 AM

May 09, 2012

alswl

使用独立图床子域名

最近在将 Wordpres 切换到 OctoPress,顺便将图片统一放到Upload4D管理。

我挑选图床管理程序有下面几个需求,需求由强到弱排列:

  • 开源
  • 简单
  • 不需数据库支持
  • 支持分目录
  • 允许上传图片
  • 支持后台直接操作文件
  • 支持用户管理,不允许其他人上传
  • 页面美观
  • 不要生成缩略图等文件
  • 软件持续更新

于是我踏上了「考古之旅」,先后试用了 MiniGal Nano / MG2 / CF Image Host Script / minishowcase 等等图床软件,评测记录如下。

参赛选手

MiniGal Nano

MG Nano

  • 没有上传功能
  • 没有后台管理功能
  • 2010年最后更新

MG2

MG2 前台 MG2 管理界面

  • 假目录,其实所有照片在同一目录下面
  • 界面丑
  • 09年更新

美优网 Meiu Studio|php相册系统

  • 国产
  • 需要 MySQL

CF Image Hosting Script v1.4.2

CF Image Hosting

  • 据说煎蛋在使用
  • 无法用户控制
  • 无目录

Minishowcase

  • 没看见上传功能
  • 没看见目录功能
  • 2009年更新

Qdig

Qdig

  • 无法上传
  • 2006年更新

iFoto, CSS-based GD2 photo gallery

iFoto

  • 无法上传
  • 2006年更新

Encode Explorer

Encode Explorer

  • 这其实是一个文件管理器
  • 支持预览
  • 不支持多文件上传
  • 其他要求全部达到

最终选择

最后,我选择了 Encode Explorer,坑爹吧,获胜者居然是一个文件管理软件, 而不是一个图床软件。

Encode Explorer 是单文件程序,代码一共3k多行,我看了一下,还能支持多语言, 我就加上了中文支持,并且修正了新建目录/新建文件的权限 bug,改为目录755, 文件644,并且这两个模式可以在配置文件修改。

修改之后的 Encode Explorer 可以在 alswl / encode-explorer 找到。

既然已经不单纯是图床了,那我也把以前的一些附件放到这个子域名下,域名也要由 img.log4d.com 改为 upload.log4d.com 。

我用 sed 命令将原来的图片和附件命令批量修改,命令如下 sed -i 's/log4d.com\/wp-content\/uploads/upload.log4d.com/g' ./_posts/*

ps:今天是我博客独立3周年纪念日,本来想在今天之前把 Wordpress 迁移到 OctoPress,可惜最近太忙,就耽误了。

May 09, 2012 08:21 AM

May 08, 2012

王宇希

关于 Out of Socket memory 的解释

一台 Nginx server,到晚上高峰 messages 出现大量的如下信息:
Apr 23 22:43:21 rs1 kernel: [...] Out of socket memory

两种情况会出发 "Out of socket memory" 的信息:
1.有很多的孤儿套接字(orphan sockets)
2.tcp socket 用尽了给他分配的内存

首先看看情况 2。对于 TCP socket 来说,使用 pages 来计数的,而非 bytes,一般情况下 1 page = 4096 bytes。page 大小可以通过下面命令获得:
$ getconf PAGESIZE
4096

查看内核分配了多少的内存给 TCP:
$ cat /proc/sys/net/ipv4/tcp_mem
69618   92825   139236
第一个数字表示,当 tcp 使用的 page 少于 69618 时,kernel 不对其进行任何的干预
第二个数字表示,当 tcp 使用了超过 92825 的 pages 时,kernel 会进入 “memory pressure”
第三个数字表示,当 tcp 使用的 pages 超过 139236 时,我们就会看到题目中显示的信息

查看 tcp 实际用的内存:
$ cat /proc/net/sockstat
sockets: used 116
TCP: inuse 3 orphan 0 tw 4 alloc 4 mem 110
UDP: inuse 1 mem 1
UDPLITE: inuse 0
RAW: inuse 0
FRAG: inuse 0 memory 0
可以看到,实际使用的 mem(110) 远远小于 69618,所以,“Out of socket memory”的错误是由于第一种情况引起的。

关于 orphan socket 的解释,请看这里。orphan socket 对于应用程序来说,意义不大,这也是内核要限制被 orphan socket 消耗内存的原因。而对于 web server 来说,有大量的 orphan socket 也属正常,那么多的连接放在那儿了。
查看 orphan socket 限制:
$ cat /proc/sys/net/ipv4/tcp_max_orphans

对比当前系统中的:
$ cat /proc/net/sockstat
sockets: used 14565
TCP: inuse 35938 orphan 21564 tw 70529 alloc 35942 mem 1894

由于内核代码中有个位运算,所以实际的跟最大的是 2x 或者是 4x 的关系。现在根据实际情况,将 tcp_max_orphans 调到一个合理的值就可以了。原则上该值建议只增大,另外,每个 orphan 会消耗大概 64KB 的内存。

还有个叫 tcp_orphan_retries 参数,对于 web server,可以减小。

涉及到内核的东西,网上大部分都是病急乱投医。这个不分是中文的还是英文的,要找到一篇好的解释真不容易。

ref:
http://blog.tsunanet.net/2011/03/out-of-socket-memory.html

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/ip-sysctl.txt;hb=v2.6.38-rc8#l271

by jaseywang at May 08, 2012 04:18 PM

May 06, 2012

王宇希

2.6.32-33 内核跑到 208 天宕机

Ubuntu 10.04 2.6.32-33-server SMP x86_64 机器,跑到大概 208 天左右出现宕机。截屏:


/var/log/kern.log:
Mar 21 12:45:17 unode11 kernel: [18446743993.492018] BUG: soft lockup – CPU#1 stuck for 17163091968s! [ruby:18753]
Mar 21 12:45:17 unode11 kernel: [18446743993.492438] Modules linked in: ip6table_filter ip6_tables ipt_LOG xt_limit xt_tcpudp xt_state ipt_REJECT iptable_filter iptable_nat nf_nat nf_conntrack_ipv4 nf_conntrack nf_defrag_ipv4 ip_tables x_tables fbcon tileblit font bitblit softcursor psmouse lp parport dell_wmi power_meter serio_raw vga16fb bnx2 joydev vgastate dcdbas usbhid hid megaraid_sas
Mar 21 12:45:17 unode11 kernel: [18446743993.492476] CPU 1:
Mar 21 12:45:17 unode11 kernel: [18446743993.492479] Modules linked in: ip6table_filter ip6_tables ipt_LOG xt_limit xt_tcpudp xt_state ipt_REJECT iptable_filter iptable_nat nf_nat nf_conntrack_ipv4 nf_conntrack nf_defrag_ipv4 ip_tables x_tables fbcon tileblit font bitblit softcursor psmouse lp parport dell_wmi power_meter serio_raw vga16fb bnx2 joydev vgastate dcdbas usbhid hid megaraid_sas
Mar 21 12:45:17 unode11 kernel: [18446743993.492515] Pid: 18753, comm: ruby Not tainted 2.6.32-33-server #72-Ubuntu PowerEdge R410
Mar 21 12:45:17 unode11 kernel: [18446743993.492518] RIP: 0033:[] [] 0x47a88a
Mar 21 12:45:17 unode11 kernel: [18446743993.492527] RSP: 002b:00007fff2c0a50d0 EFLAGS: 00000202
Mar 21 12:45:17 unode11 kernel: [18446743993.492531] RAX: 000000000000000b RBX: 0000000002067600 RCX: 000000000000001e
Mar 21 12:45:17 unode11 kernel: [18446743993.492535] RDX: 0000000000000000 RSI: 0000000000433a10 RDI: 0000000002067600
Mar 21 12:45:17 unode11 kernel: [18446743993.492538] RBP: ffffffff81013cae R08: 0000000001fe5000 R09: 0000000000000000
Mar 21 12:45:17 unode11 kernel: [18446743993.492542] R10: 00007f895350b5c0 R11: 00007f895345d942 R12: 00007fff2c0a5110
Mar 21 12:45:17 unode11 kernel: [18446743993.492545] R13: 0000000000000180 R14: 000000000779c080 R15: 0000000000000000
Mar 21 12:45:17 unode11 kernel: [18446743993.492550] FS: 00007f8954478720(0000) GS:ffff880009000000(0000) knlGS:0000000000000000
Mar 21 12:45:17 unode11 kernel: [18446743993.492554] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
Mar 21 12:45:17 unode11 kernel: [18446743993.492557] CR2: 0000000008aa3000 CR3: 0000000426311000 CR4: 00000000000006e0
Mar 21 12:45:17 unode11 kernel: [18446743993.492561] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
Mar 21 12:45:17 unode11 kernel: [18446743993.492564] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
Mar 21 12:45:17 unode11 kernel: [18446743993.492567] Call Trace:
Mar 21 12:45:17 unode11 kernel: [18446743993.492577] BUG: soft lockup – CPU#2 stuck for 17163091968s! [ruby:18759]
Mar 21 12:45:17 unode11 kernel: [18446743993.492997] Modules linked in: ip6table_filter ip6_tables ipt_LOG xt_limit xt_tcpudp xt_state ipt_REJECT iptable_filter iptable_nat nf_nat nf_conntrack_ipv4 nf_conntrack nf_defrag_ipv4 ip_tables x_tables fbcon tileblit font bitblit softcursor psmouse lp parport dell_wmi power_meter serio_raw vga16fb bnx2 joydev vgastate dcdbas usbhid hid megaraid_sas

经确认,是 2.6.32-33 的 bug,由 sched_clock 函数引起。这里描述了发生的条件:
* Interl 的 CPU
* /proc/cpuinfo 内包含 constant_tsc, nonstop_tsc flag
* dmesg 或者 /var/log/boot.msg 不包含 "Marking TSC unstable" 字符
* 非 xen

同样的问题发生在 CentOS Linux release 6.0 (Final) 2.6.32-71.el6.x86_64 #1 SMP 服务器上。目前比较好的解决办法是在 208 天前重启一下服务器,或者升级内核。

根据官方的建议,还可以在 kernel 后面追加 noapic 参数
注意:不是 acpi=off

说几句,该 bug 发现之后,Ubuntu 没有先修复身为 LTS 的 10.04 Lucid 版本,而是先修复的 Maverick、Natty 等版本,直到现在(5 月 1 日),Lucid 才有修复的意图,launch 上终于是 "Nominated for Lucid by" 了,截止发稿时间(5 月 7 日)依然维持该状态。社区的东西免费是好事,但是出了问题,尤其像这种大 bug,没人催没人修的局面就尴尬了,相比之下,Suse 很早就释出了修复后的内核版本,redhat 应该也不会太掉后。

ref:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/805341
https://www.kernel.org/pub/linux/kernel/v2.6/longterm/ChangeLog-2.6.32.50
http://www.novell.com/support/viewContent.do?externalId=7009834&sliceId=1

http://thread.gmane.org/gmane.linux.kernel/1132515

by jaseywang at May 06, 2012 04:15 PM

孙峻文

JSMinNpp 1.11 Released

What’s New 1.11
Move to Google Code.
Add a Json Viewer.
Change classes inheritance hierarchy to build a smaller binary file.

Download from here and try.

Although the source code repository has been moved to Google Code, downloading is still from SouceForge.net.

Sooner or later, it will be on GitHub

by sunjwvista at May 06, 2012 10:52 AM

May 05, 2012

王宇希

bonding

Ubuntu
安装 ifenslave,用来将 slave 接口 attach/detach 到 bonding 设备:
$ sudo apt-get install ifenslave

$ cat /etc/modprobe.d/bond.conf
alias bond0 bonding
options bonding mode=1 miimon=100

$ cat /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet manual

auto eth1
iface eth1 inet manual

auto bond0
iface bond0 inet static
 address 192.168.10.53
 netmask 255.255.255.0
 gateway 192.168.10.254
 bond-slaves eth0 eth1

$ sudo /etc/init.d/networking restart

CentOS
$ cat /etc/modprobe.d/bonding.conf
alias bond0 bonding
options bond0 mode=5 miimon=100

$ pwd
/etc/sysconfig/network-scripts

$ cat ifcfg-bond0
DEVICE=bond0
ONBOOT=yes
IPADDR=192.168.11.17
NETMASK=255.255.255.0
NETWORK=192.168.11.0
USERCTL=no
BOOTPROTO=no

$ cat ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
USERCTL=no
MASTER=bond0
SLAVE=yes
BOOTPROTO=no

$ cat ifcfg-eth1
DEVICE=eth1
ONBOOT=yes
USERCTL=no
MASTER=bond0
SLAVE=yes
BOOTPROTO=no

$ ifconfig
bond0     Link encap:Ethernet  HWaddr 11:11:11:11:11:0F 
          inet addr:192.168.11.17  Bcast:192.168.11.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
          RX packets:12844796 errors:0 dropped:0 overruns:0 frame:0
          TX packets:23873909 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:3461648575 (3.2 GiB)  TX bytes:1675766839 (1.5 GiB)

eth0      Link encap:Ethernet  HWaddr 11:11:11:11:11:0F 
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:12844796 errors:0 dropped:0 overruns:0 frame:0
          TX packets:23873909 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3461648575 (3.2 GiB)  TX bytes:1675766839 (1.5 GiB)
          Interrupt:36 Memory:d6000000-d6012800

eth1      Link encap:Ethernet  HWaddr 11:11:11:11:11:11 
          UP BROADCAST SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
          Interrupt:48 Memory:d8000000-d8012800

使用过程中出现如下错误:
modprobe: FATAL: Error inserting bonding (/lib/modules/2.6.18-194.17.1.el5/kernel/drivers/net/bonding/bonding.ko): Unknown symbol in module, or unknown parameter

需要开启 ipv6 模块的支持:
$ cat /etc/modprobe.d/disable-ipv6.conf
#install ipv6 /bin/true
#
options ipv6 disable=1

ref:
https://help.ubuntu.com/community/UbuntuBonding

http://sys64738.dk/doku.php?id=interface_bonding

by jaseywang at May 05, 2012 03:23 AM

May 04, 2012

alswl

《HTML5 实战 WebApp 阅读应用 – Shiu》幻灯片

今天去南京 HTML5 沙龙分享了一个幻灯片,讲 Shiu 的开发,同时也分享在这里。

Shiu 的源码托管在 Github,地址是 https://github.com/alswl/shiu 感兴趣可以去看看。

噢,Shiu (/ʃʐy/),中文音标 (shi rü)),是一款基于 WebApp 的阅读应用。

May 04, 2012 04:00 PM

May 02, 2012

王宇希

厦门小游

上个月去了趟厦门(当然不是五一去的了),呆了一周,跟大家分享下美景与美食。空气清新,气候宜人,总的来说,好山好水好风光。

7 点的沙滩,还没被糟蹋前

被水侵蚀的岩石

环岛路,烟雾朦胧(不是灰尘,是水汽)

菽庄花园

在南普陀看到的 IPad?

满山的花儿

岛上最好吃的食品

小眼睛大排档名不虚传呐,好吃到暴

除了上面这些,还有很和谐的涂鸦,比如这张,是在厦大芙蓉隧道拍的 :D

要给的建议就是,带上你的 IOS,带上你的 Android,开着 GPS,就不会丢了。

P.S: 如果看不到图片 99.999 % 是你的问题,只要 Dropbox 不挂,图片也不会挂。

by jaseywang at May 02, 2012 07:00 PM

April 29, 2012

王宇希

logrotate 中几个重要指令的理解

1.create:create mode owner group Immediately after rotation (before the postrotate script is run) the log file  is  created  (with  the  same name as the log file just rotated).  mode specifies the mode for the log file in octal (the same as chmod(2)), owner specifies the user  name  who  will own the log file, and group specifies the group the log file will belong to. Any of the log file attributes may be omitted, in which case those attributes  for  the  new  file will  use  the  same  values  as the original log file for the omitted attributes. This option can be disabled using the nocreate option.

以下面这个为例:
$ cat /etc/logrotate.conf
/var/log/test.log {
        size 1M
    create 666 jaseywang jaseywang
}
$ sudo logrotate /etc/logrotate.conf

可以通过下面这个实验来验证,开三个窗口,分别执行:
# while true;do cat /dev/zero  > /var/log/test.log ;done
# logrotate   /etc/logrotate.conf
# ll /var/log/test.log*

也就是说 logrotate 之后生成的 file.log 新文件的权限,用户,用户组,执行了 logrotate 之后,该日志文件对应的服务会向 test.log.1 文件继续写入而不是向 test.log 写入。

2.copytruncate:Truncate:the original log file in place after creating a copy, instead of moving the old log file and optionally creating a new one.  It can be used when some program  can not  be  told  to  close its logfile and thus might continue writing (appending) to the previous log file forever.  Note that there is a very small time slice between  copying the  file  and  truncating it, so some logging data might be lost.  When this option is used, the create option will have no effect, as the old log file stays in place.

truncate 理解起来就是清空文件内容,但是保留该文件,等同于下面这个命令:
$ > filename

Linux 下面有个 truncate 命令,可以用来 shrink/extend 文件大小,如果 -s 后面的数值大于指定文件的大小,多出来的部分将会以零字节填充;如果小于,多出的来的数据将丢失。
注意:如果 truncate 一个大于文件实际大小的文件,系统并没有给该文件分配 inode,只是一个声称的大小罢了,这点可以通过 ls -s 看出,或者 du 也能看出。当然,du -b 的作用跟 ls -l 等同。

3.copy:Make a copy of the log file, but don't change the original at all.  This option can  be used,  for  instance,  to  make  a snapshot of the current log file, or when some other utility needs to truncate or parse the file.  When this  option  is  used,  the  create option will have no effect, as the old log file stays in place.

4.compress
compresscmd /bin/bzip2
compressext .bz2
默认会以 .gz 结尾,如果使用 bzip2,那么需要指定以 bz2 结尾

5.size
默认为 bytes,可以以 M/G 结尾

这样解释 last 指令显示的内容就简单了,常常发现 last 只会显示从某段时间开始的登录/reboot 等信息,就是系统默认做了 logrotate 的,如果要看之前的登录信息,执行:
$ last -f wtmp.1

by jaseywang at April 29, 2012 04:58 AM

April 27, 2012

王宇希

Ubuntu 10.04 server 安装 sun-java

有一批机器默认安装的是 openjdk,现在需要安装 sun-java-jdk。即先卸载后安装。
网上很多的说法是添加下面的源:
deb http://archive.canonical.com/ lucid partner

然后 update:
$ sudo aptitude update

但是并没有找到 sun 的包:
$ sudo apt-cache search sun-java6-jdk

G 了下,sun 的包已经被移到 ppa 里面去了:
$ sudo apt-get install python-software-properties
$ sudo add-apt-repository ppa:sun-java-community-team/sun-java6
$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk


安装完了查看版本,发现依然是 openjdk 的:
$ java -version
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.13) (6b20-1.9.13-0ubuntu1~10.04.1)
OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode)
$ which java
/usr/bin/java
$ ll /usr/bin/java
lrwxrwxrwx 1 root root 22 2012-03-11 00:10 /usr/bin/java -> /etc/alternatives/java
$ ll /etc/alternatives/java
lrwxrwxrwx 1 root root 40 2012-03-11 00:10 /etc/alternatives/java -> /usr/lib/jvm/java-6-openjdk/jre/bin/ja

可以直接卸载掉 openjdk:
$ sudo apt-get remove openjdk-6-jdk --purge -y
$ sudo apt-get autoremove

卸载软件包是有一定风险的,保守做法可以将 sun-java 设置为 "default":
$ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                      Priority   Status
————————————————————
* 0            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-6-sun/jre/bin/java       63        manual mode

Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/java-6-sun/jre/bin/java to provide /usr/bin/java (java) in manual mode.

$ ll /etc/alternatives/java
lrwxrwxrwx 1 root root 36 2012-03-11 00:11 /etc/alternatives/java -> /usr/lib/jvm/java-6-sun/jre/bin/java
$ java -version
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b06)
Java HotSpot(TM) 64-Bit Server VM (build 17.0-b16, mixed mode)

或者直接运行:
$ sudo update-java-alternatives -s java-6-sun
 

by jaseywang at April 27, 2012 01:16 PM

李凡希

泰国游记

2008年菲律宾2009年台湾省2010年美国硅谷2011年美国硅谷,最近几年每年都有一次出境的机会,运气还不错。前几天公司组织了一次以自费为主的泰国游,行程总得来说不是很有意思,就在这里分享一下这次行程的一些Tips和体会,供大家参考。

本次行程主要包含泰国曼谷和芭提雅两个城市,总共在泰国呆5个白天,由于是跟团游,总的感觉是所有的时间都被旅行社占用掉了,完全没有自主的时间。这点对于喜欢乱逛的我来说是很郁闷的,尤其是没有机会去体验曼谷市区的轨道交通,颇为遗憾。

在出发前,建议在国内提前到银行预约泰铢的兑换,在国内兑换的汇率比在泰国要合算的多,最不济的情况下,在泰国的ATM机上用银联卡直接提款也比在机场或导游那里兑换要合算。泰国银联的普及率还是比较高的,大部分情况下用银联卡比走VISA/MasterCard是要合算的。

泰国天气较热,阳光也比较强烈,最好准备SPF指数较高的防晒产品。跟其它国家一样,酒店大多不提供一次性用品,自己带上比较靠谱。泰国电压跟中国一样AC220V 50Hz,插座大多是美标的三脚插座,两脚插头的设备都没有压力,三脚的可能需要转换器。

泰国洒店大多不提供免费Wi-Fi和Internet服务,可以付费使用但价格较高,或者可以在泰国购买手机卡打电话或上网。中国移动和中国电信的泰国漫游资费都比较高,GSM和CDMA网络泰国都有,不用换手机。

泰国有遍地的7-Eleven便利店,在那里可以买到日常用品和手机卡。便利店的店员不保证能听懂中文或英文,但酒店和旅游场所的人大多会一点中文或英文。

TrueMove运营商为游客设计的手机卡49泰铢一张,另外可以用充值卡充值50或90铢。打中国的电话是1.07铢/分钟,上网可以用50铢包50M的流量。以我个人的经历,TrueMove的网络很不怎么样,常常上不了网,而且扣费也扣得莫明其妙。客服电话是收费的,而且只有泰文提示音,我是乱按了好久才转接到人工服务的,人工服务可以用英语。所以如果要用TrueMove,应该在国内时先上网查好它的各项服务的使用方法。

泰国服务业普遍有收小费的习惯,一般情况下可以给20泰铢左右。

我的这次行程景点主要包括曼谷的玉佛寺、大皇宫、湄南河、大城王朝遗迹(维修中)、芭堤雅水上集市、金沙岛和五世皇行宫,总体来说没有感觉看到有特别让人Wow的东西。进入皇家的建筑要求穿长裤和有袖上衣,不然就只能花钱买一条布把自己围起来了。

导游带的泰国购物点主要包括珠宝中心、皮件中心、燕窝中心、干果市场、毒蛇研究中心和免税店。某种程度上说宝石、鳄鱼皮、燕窝、水果干和蛇药确实可以算是泰国的特产,是值得买的,但对于导游带去的购物点,尤其是珠宝中心,还是尽量要谨慎一些,如果确实要买,建议提前做功课。我对于干果市场的水果干品质表示极度怀疑,所以后来特地偷闲跑到曼谷当地一家很大的Tesco Lotus超市去,结果发现这么大的综合超市中完全不见水果干这种商品,7-Eleven/Big C便利店也没有,看来水果干这个东西是“特供”外国游客了。在泰国购买欧莱雅的化妆品相比国内比较有优势,其它的都明显比美国或香港要贵得多。Lee的牛仔裤大约2000铢左右,跟美国或菲律宾比也很没有优势。

最具泰国特色的人妖表演或相关的“自费”项目,实话说没有什么特别值得一看,大多所谓表演很拙劣,不具有艺术性,可以映证那句“不看后悔,看了也后悔”的话。相对来说在芭提雅艺城看的泰国历史文化演出还比较有意思一点,不过这个如果不提前做点功课了解一点泰国历史的话, 看不懂。

泰国很多景点都有一个不错的营销模式,在游客进入景区时,会有人以迅雷不及掩耳之势为各位游客拍摄照片。等游客游完景点后,这些照片已经冲印完毕并嵌入相框,或做成盆子、杯子之类的工艺品,放在景点门口以100-200铢的价格出售。尽管大家都自己带着相机拍照,但看到这些成品的照片还是会有很多人愿意花钱买下来。这种“所见即所得”的营销模式,感觉比在国内常见的搭个大阳伞被动等人花钱来拍照的的效果要好得多。

泰国新鲜的热带水果还是很便宜的,椰子即使在景区宰客的情况下,也只有20-25铢一个。山竹、榴莲、红毛丹和芒果都很值得推荐 。对了,还有DQ的冰淇凌也很便宜,小杯的只要29铢。

大部分照片都按惯例放在Picasa相册(包括Google+)中了,有兴趣的自行设法去看吧:

by Li Fanxi at April 27, 2012 12:46 PM

April 23, 2012

王宇希

SSH 的一些细节

一般的 HTTPS 认证如下:
1.浏览器连接 HTTPS 默认的 443 端口
2.服务器提供起 public key,(X509 证书)
3.浏览器 check 该证书颁发自一个受信任的 CA
4.浏览器 check 服务器证书上的 CN(X509 Common Name)跟你浏览的域名相匹配

上面这个步骤跟 ssh 的连接过程很类似,除了一点:ssh 没有 CA 的概念。下面描述一下 ssh 连接过程:
1.用户发起连接的请求
2.服务器收到请求,将自己的公钥发给用户
3.用户使用该公钥加密密码,发送给服务器
4.服务器私钥解密,验证密码正确性

但是使用上面密码的验证方式有一个缺点,如果在客户跟服务器通信的过程中被一个中间人截获(Man-in-middle),也就是说中间人截获了客户的登录请求,假冒服务器,将中间人的公钥发给了客户端。上面说了,ssh 是没有 CA 概念的,因此用户无法辨认此公钥的真伪,如果被中间人截获,那么用户跟真正服务器之间就没有信息可言了。

$ ssh -p 11111 jaseywang@10.18.10.31
The authenticity of host '[10.18.10.31]:11111 ([10.18.10.31]:11111)' can't be established.
RSA key fingerprint is a3:e4:dd:7a:13:fe:91:76:38:51:ee:9d:b8:6b:8a:03.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[10.18.10.31]:11111' (RSA) to the list of known hosts.
jaseywang@10.18.10.31's password:

上面这个是首次连接服务器时候出现的信息,就是无法确认该公钥是否是服务器的公钥,真假自辩。
key fingerprint 就是服务器 RSA 的公钥经过 MD5 后的一个散列。如果你输入 yes,ssh 客户端会将其公钥保存至 ~/.ssh/known_hosts 文件,这个文件从某种意义上来说就是一个"CA",经过你确认的,没问题的服务器的公钥才会保存在这个文件里面。当你下一次再次连接时,就不会显示上面那段话了,实际上在这之前,客户端会检查下面几个地方:
1.全局配置文件 /etc/ssh/ssh_known_hosts,这个可以通过 GlobalKnownHostFile 来修改
2.用户本地文件 $HOME/.ssh/known_hosts,这个可以通过 UserKnownHostsFile 参数来修改

如何验证该公钥就是你需要连接的服务器的公钥了?这个又是一个超出技术范畴的事件,可以把服务器的公钥发布在网络上,然后当你首次连接时进行匹配或者当你登录进去之后通过 ssh-keygen 检查其公钥,通常是在 /etc/ssh

$ ssh -p 11111 jaseywang@10.18.10.30
The authenticity of host '[10.18.10.30]:11111 ([10.18.10.30]:11111)' can't be established.
RSA key fingerprint is 17:2c:67:30:24:ab:79:4b:ae:fd:b2:b6:56:b8:28:71.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[10.18.10.30]:11111' (RSA) to the list of known hosts.
jaseywang@10.18.10.30's password:

$ ls
moduli  ssh_config  sshd_config  ssh_host_dsa_key  ssh_host_dsa_key.pub  ssh_host_rsa_key  ssh_host_rsa_key.pub
$ ssh-keygen  -l -f -v ssh_host_rsa_key.pub
2048 17:2c:67:30:24:ab:79:4b:ae:fd:b2:b6:56:b8:28:71 ssh_host_rsa_key.pub (RSA)
+–[ RSA 2048]—-+
|      ..+        |
|       o +       |
|      . . =      |
|     o   + .     |
|    o o.S .      |
|  . E+.o..       |
|   o ..o         |
|  . .o=          |
|   .o+=.         |
+—————–+

ssh 通常有三种方式来应对一个未被确认或者公钥被修改过的情况,通过 StrictHostKeyChecking 指令:
$ ssh -o  StrictHostKeyChecking=no -p 11111 jaseywang@10.18.10.30
Warning: Permanently added '[10.18.10.30]:11111' (RSA) to the list of known hosts.
jaseywang@10.18.10.30's password:

$ ssh -o  StrictHostKeyChecking=ask -p 11111 jaseywang@10.18.10.30
The authenticity of host '[10.18.10.30]:11111 ([10.18.10.30]:11111)' can't be established.
RSA key fingerprint is 17:2c:67:30:24:ab:79:4b:ae:fd:b2:b6:56:b8:28:71.
Are you sure you want to continue connecting (yes/no)?

$ ssh -o  StrictHostKeyChecking=yes -p 11111 jaseywang@10.18.10.30
No RSA host key is known for [10.18.10.30]:11111 and you have requested strict checking.
Host key verification failed.

这里就完全体现的安全跟方便的相对关系了,最安全的是 StrictHostKeyChecking=yes 选项,但是如果 known_hosts 事先没有此服务器的公钥的话,将拒绝登录。而我们会经常看到下面这个情景:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
69:38:ba:80:93:b8:2a:29:ec:b3:65:e2:40:da:78:54.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending key in /etc/ssh/ssh_known_hosts:153
Password authentication is disabled to avoid man-in-the-middle attacks.
Keyboard-interactive authentication is disabled to avoid man-in-the-middle attacks.
Permission denied (publickey,keyboard-interactive).

出现这个情况最可能是服务器重新生成了密钥对,或者重新安装了系统导致密钥对更换,或者该服务器的 IP 变更了。解决他就可以使用上面的方式了:
$ ssh -o StrictHostKeyChecking=no -p 11111 jaseywang@10.18.10.30
或者将其重定向到 /dev/null 中,也就是不将公钥记录到 known_hosts 里面:
$ ssh -o GlobalKnownHostsFile=/dev/null -p 11111 jaseywang@10.18.10.30

对于 ssh 的种类,主流的包括 V2 版本的 RSA/DSA,以及现在几乎不用的 V1 版本的 RSA。如果 public key 丢失,可以通过 ssh-keygen 还原:
$ pwd
/home/jaseywang/.ssh
$ ll
total 44
-rw-r–r– 1 jaseywang jaseywang  6541 Mar 14 18:24 config
-rw——- 1 jaseywang jaseywang  1675 Feb 26 20:09 id_rsa
-rw-r–r– 1 jaseywang jaseywang   401 Feb 26 20:09 id_rsa.pub
-rw-r–r– 1 jaseywang jaseywang 25380 Mar 23 03:39 known_hosts
$ ssh-keygen -y -f id_rsa
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDeNQGkMk4GTl3+5W2tYsAVQ/7stDx/2zAH3ETCo6jIOP0f07OV3CVOERW7AyhZmM0pQtrQsUzjCs7Jw9nJRHZDDUtdeTbFEA/eMHbtzeV0kNtyyutXKT9ymXf7z8CtSuJcd52SttubU6hsOBWz2rUkdz6HMvJhjBt38QW/
$ cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDeNQGkMk4GTl3+5W2tYsAVQ/7stDx5/2zAH3ETCo6jIOP0f07OV3CVOERW7AyhZmM0pQtrQsUzjCs7Jw9nJRHZDDUtdeTbFEAh/eMHbtzeV0kNtyyutXKT9ymXf7z8CtSuJcd52SttubU6hsOBWz2rUkdz6HMvJhjBt38QW/w

ref:

http://www.symantec.com/connect/articles/ssh-host-key-protection

by jaseywang at April 23, 2012 12:23 PM

孙峻文

开始向 Google Code 迁移

上次做 PPT 的时候被 @Li Fanxi大神 问到一个问题,为什么不把 Tetris5 托管在 Google Code。当时倒是没多想,毕竟 SourceForge.net 的用这也比较熟了,所以也没有太多考虑过是不是应该试试别的托管服务。后来逐渐的开始使用 GitHub 以及 SourceForge.net 时不时的无法访问(和墙没什么关系,是 SourceForge.net 自己的问题),让我开始有了换个托管服务的想法。

一开始想直接迁移到 GitHub 上,但是目前 Git 还不太会用,而且之前的项目一直用 svn 管理的,所以考虑了一下还是 Google Code + svn 作为迁移目标。

第一个迁移的是 fHash,说明、截图和下载已经转移完毕,代码库随后也会移过去。

JSMinNpp 也会被转移过去,并且将会趁此机会改名为 JsToolNpp,因为现在已经远远不是一个 JSMin 功能这么简单了。这个估计要花一些时间才能完成,希望赶得上下一个版本的发布。

by sunjwvista at April 23, 2012 12:02 PM

April 20, 2012

王宇希

OpenSSL asn1_d2i_read_bio 缓冲区溢出攻击

受影响的版本包括 0.9.8v 之前的(0.9.8u,0.9.8t…0.9.8k..0.9.2b…0.9.1c),1.0.0 之前的以及 1.0.1 之前的。

Ubuntu 10.04 LTS(0.9.8k 25 Mar 2009),CentOS 5.5/5.6(0.9.8e-fips-rhel5 01 Jul 2008) 均受此影响。

Ubuntu 打补丁的方式如下:
$ wget https://launchpad.net/ubuntu/+archive/primary/+files/openssl_0.9.8k.orig.tar.gz
$ wget https://launchpad.net/ubuntu/+archive/primary/+files/openssl_0.9.8k-7ubuntu8.10.diff.gz
$ wget https://launchpad.net/ubuntu/+archive/primary/+files/openssl_0.9.8k-7ubuntu8.10.dsc
$ tar zxvf openssl_0.9.8k.orig.tar.gz
$ gzip -d openssl_0.9.8k-7ubuntu8.10.diff.gz
$ cd openssl-0.9.8k
$ patch -1 < ../openssl_0.9.8k-7ubuntu8.10.diff

或者直接通过 dsc 文件来完成补丁:
$ sudo apt-get install dpkg-dev
$ dpkg-source -x openssl_0.9.8k-7ubuntu8.10.dsc

编译安装:
$ ./config
$ make
$ sudo make install

这样会将新的 openssl 的文件安装至 /usr/local/ssl/ 下面:
$ tree -L 1 /usr/local/ssl/
/usr/local/ssl/
├── bin
├── certs
├── include
├── lib
├── man
├── misc
├── openssl.cnf
└── private

7 directories, 1 file

编译的时候可以指定安装的目录,下面这个会覆盖系统上的:
$ ./config --prefix=/usr

当然,最简单的方式还是通过包管理器来升级:
$ sudo apt-get update
$ sudo apt-get -y install openssl libssl0.9.8

by jaseywang at April 20, 2012 06:28 PM

xterm

自己配的一个 .Xdefaults 文件,可以显示中文,需要有 wenquanyi micro 字体支持:
xterm*locale: true
xterm.utf8: true
xterm*utf8Title: true
xterm*borderWidth: 0
xterm*faceName: WenQuanYi Mirco Hei:antialias=True:pixelsize=14
xterm*faceNameDoublesize: WenQuanYi Micro Hei:pixelsize=14
xterm*scrollBar: false
XTerm*background: black
XTerm*foreground: #00FF00
XTerm.termName:    xterm-256color
XTerm*boldMode:    true
XTerm*colorBDMode: false
XTerm*colorBD:     #ffffff
XTerm*cursorColor: #c0c090

也可以在启动 xterm 时加上其他的参数:
$ xterm -sl 300 -fg green -bg black -cr red

ref:

http://www.xfree86.org/4.0.1/xterm.1.html

by jaseywang at April 20, 2012 12:35 PM

April 19, 2012

alswl

Vim 下模拟 Emacs 键绑定

Vimer 需要 Emacs 键绑定?看上去很蛋疼的需求吧。其实不然,大部分的 Shell / Readline 默认绑定的是 Emacs 键位绑定(处于输入状态下,Emacs 的键位很好用)。Vim 的模式切换很牛逼,但是 Insert 模式下面,只有寥寥几个快捷键,我修改了配置文件,绑定需要的 Emcas 按键到 Vim 中来。

Github 中搜索关键字 Vim Emcas key bind,出来一些结果,不是很完美,我又慢慢调教了几个星期,放出我的 .vimrc。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
" 模拟 Emacs 键绑定
" Move
inoremap <C-a> <Home>
inoremap <C-e> <End>
"inoremap <C-p> <Up>
"inoremap <C-n> <Down>
inoremap <C-b> <Left>
inoremap <C-f> <Right>
inoremap <M-b> <C-o>b
inoremap <M-f> <C-o>w
" Rubout word / line and enter insert mode
" use <Esc><Right> instead of <C-o>
inoremap <C-w> <Esc>dbcl
" delete
inoremap <C-u> <Esc>d0cl
inoremap <C-k> <Esc><Right>C
inoremap <C-d> <Esc><Right>s
inoremap <M-d> <C-o>de

需要的朋友请取用,我的 Vim 配置文件和插件在 https://github.com/alswl/dotfiles

April 19, 2012 04:00 PM

April 18, 2012

王宇希

使用 Cobbler 安装 Ubuntu 出现的问题

pxe 安装 Ubuntu 10.04,使用 apt-mirror 同步源在内网使用,然后在 preseed 文件上修改的这两段:
d-i mirror/http/hostname string http://your-private-ip
d-i mirror/http/directory string /ubuntu

在使用 iDRAC 打开安装界面,Ctrl+Alt+F4 观察安装的 log 时,发现启动到一定阶段系统没有相应了,出现如下的提示:
cat can't open '/tmp/net-retriever-xxxx-deduplicate/*': No such file or directory.

之前直接使用 mirrors.sohu.com 的源并没有出现问题,初步判定是由于使用了内部源引起的。
G 后发现是使用 apt-mirror 同步源时没有同步 netboot 下面的某些目录, rsync 下面的目录:
deb-amd64 http://mirrors.sohu.com/ubuntu lucid main/installer-amd64
deb-amd64 http://mirrors.sohu.com/ubuntu lucid main/debian-installer restricted/debian-installer universe/debian-installer multiverse/debian-installer
#deb-amd64 http://mirrors.sohu.com/ubuntu lucid-updates main/debian-installer restricted/debian-installer universe/debian-installer
#deb-amd64 http://mirrors.sohu.com/ubuntu lucid-security main/debian-installer restricted/debian-installer universe/debian-installer

其实只要同步前两个链接就可以,加 # 可选择性同步。

如果出现 "WARNING **: bad d-i Packages file" 类似的提示,修改 preseed 文件的认证:
d-i debian-installer/allow_unauthenticated string true

另外,apt-mirror 同步时,可注视掉 /etc/apt/mirror.list 里面的 deb-src 开头的几段,即不同步源文件,这样差不多 90G 可以同步一个 lucid x86_64 的 lucid/lucid-secuirty/lucid-updates/lucid-proposed/lucid-backports。

ref:
http://ubuntuforums.org/showthread.php?p=9369393
http://askubuntu.com/questions/35758/where-is-the-netboot-image

http://irclogs.ubuntu.com/2009/12/04/%23ubuntu-installer.html

by jaseywang at April 18, 2012 04:16 PM

April 16, 2012

王宇希

ssh 使用不同的私钥登录

在 .ssh 下生成了两套密钥:
# ssh-keygen -f ~/.ssh/id_rsa.work -C "work key"
# ssh-keygen -f ~/.ssh/id_rsa.home -C "home key"

如何使用不同的私钥登录不同的机器?在 ssh_config 或者 ~/.ssh/config 里面定义:
Host work
    hostname YOUR_IP
    User jaseywang
    port YOUR_SSH_PORT
    IdentityFile ~/.ssh/id_rsa.work
 
Host home
    hostname YOUR_IP
    User jaseywang
    port YOUR_SSH_PORT
    IdentityFile ~/.ssh/id_rsa.home

如果将 IdentityFile 定义在 Host 外面则对全局生效, Host 内如果再定义该指定,覆盖全局的。

by jaseywang at April 16, 2012 02:50 PM

April 15, 2012

王宇希

Ubuntu 自动加载 ssh 私钥

使用 gnome 里面有个叫 gnome keyring 的东西,专门用来管理用户的登录等认证过程,默认集成了一个 ssh agent。
gnome 启动后,ssh agent 会自动的加载 ~/.ssh/ 下面跟 *.pub 匹配的私钥文件,如果仅仅有一个私钥而没有公钥,则不会加载。当然,由于某些原因,我们可能需要禁用掉该机制。有如下几种方式。

1.在 gnome-session-properties 中禁用 SSH Key Agent 开始选项

2.编译 gnome-keyring 时候禁用 ssh-agent:
$ ./configure --disable-ssh-agent

3.手动开启 gnome-keyring,通过 –components 选项禁用跟 ssh 相关的支持:
$ gnome-keyring-daemon --components keyring,pkcs11

ref:
https://live.gnome.org/GnomeKeyring/Ssh
 

by jaseywang at April 15, 2012 04:51 AM

April 13, 2012

alswl

使用 Vundle 管理 Vim 插件

早在这个月初,我就在 Vim 的邮件列表看到了一封关于 Vim 插件管理的 邮件。 才惊呼原来有这么强大的插件可以用来管理我那一坨插件, 今天细细阅读并查了一些资料,便开始配置自己的 Vim。

几种管理插件

Vim 的插件管理工具有蛮多,比如:

Vim-addon-manager 和 vimana 的对比,参见 Vim的插件管理工具

我最会选择了 Vundle,通过子目录管理插件,支持 Git 更新。 我其实不太喜欢子目录,觉得目录太多了看着烦,但是考虑到在没有良好的 PKG 包描述文件的前提下,分子目录是一种简单有效(粗暴)的方法。

Vundle 通过 git 来对插件进行更新,有三种源可以添加:

  • github 中 vim-scripts 的项目(这个账号是为 Pathogen 建的,用来建立对 Vim.org 上脚本的镜像)
  • github 某个 Vim 插件项目
  • 某个 git 源

以上也是我推荐的选择插件顺序,我认为没有必要去取最新的开发版插件。

Vundle 安装

无二话,官方文档的 Quick Start 写的很详细 ,一句话:

$ git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle

然后开始配置 .vimrc,我的 .vimrc

重点是配置各种 Bundle 我的配置如下

" My Bundles here:

" vim-scripts repos

" Syntax
Bundle 'asciidoc.vim'
Bundle 'confluencewiki.vim'
Bundle 'html5.vim'
Bundle 'JavaScript-syntax'
"Bundle 'mako.vim'
Bundle 'moin.vim'
Bundle 'python.vim–Vasiliev'
Bundle 'xml.vim'

" Color

Bundle 'desert256.vim'
Bundle 'Impact'
Bundle 'matrix.vim'
Bundle 'vibrantink'
Bundle 'vividchalk.vim'

" Ftplugin
Bundle 'python_fold'

" Indent
"Bundle 'indent/html.vim'
Bundle 'IndentAnything'
Bundle 'Javascript-Indentation'
Bundle 'mako.vim–Torborg'
Bundle 'gg/python.vim'

" Plugin
Bundle 'The-NERD-tree'
Bundle 'AutoClose–Alves'
Bundle 'auto_mkdir'
Bundle 'cecutil'
Bundle 'fcitx.vim'
Bundle 'FencView.vim'
"Bundle 'FuzzyFinder'
Bundle 'jsbeautify'
Bundle 'L9'
Bundle 'Mark'
Bundle 'matrix.vim'
Bundle 'mru.vim'
Bundle 'The-NERD-Commenter'
"Bundle 'project.vim'
Bundle 'restart.vim'
Bundle 'taglist.vim'
"Bundle 'templates.vim'
"Bundle 'vimim.vim'
Bundle 'ZenCoding.vim'
Bundle 'css_color.vim'
Bundle 'hallettj/jslint.vim'

需要注意的是,Vim 插件名称可能存在重名的情况,这时候就需要在插件后面加上作者的姓氏, 比如 Bundle 'Javascript-Indentation' ,而遇到插件名有空格和斜杠的话, 需要将空格和斜杠替换为 -

执行 BundleInstall 即可完成安装,如果出现错误提示,多半是名称有问题, 去 github 和 vim.org 搜索一下吧。

更多参考:

ps:这篇文章第一次尝试使用 Markdown 写博,以前全部是在用 Asciidoc 写(我的 Github 里的 README,都喜欢用 .asciidoc)。貌似是由于 github 带动, Mardown 自 2010 年之后使用人数猛涨,证据在此,上图是 Markdown,下图是 Asciidoc

Markdown vs Asciidoc

April 13, 2012 04:00 PM

April 11, 2012

王宇希

New Arch Linux

之前 TP 上的硬盘挂了,收了 @zypatroon 同学的二手盘。下面简单记录下本次安装 arch x86_64 的的部分操作。

# adduser jaseywang
# userdel -r http ftp
# groupdel games

# visudo
jaseywang ALL=(ALL) NOPASSWD:ALL

# cat /etc/pacman.conf
[archlinuxfr]
Server = http://repo.archlinux.fr/x86_64
# pacman -Syu

# pacman -S alsa-utils
# gpasswd -a jaseywang audio
# alsaconf

# echo "set bell-style none">>/etc/inputrc
$ echo "set vb">>~/.vimrc


# pacman -S gvim
# cp /etc/vimrc /etc/vimrc.bak
# cp /usr/share/vim/vim73/vimrc_example.vim /etc/vimrc

# pacman -S xorg-server xorg-utils xorg-xinit mesa
# pacman -S xf86-video-intel



Failed to load module “intel” (module does not exist,0)
Failed to load module “vesa” (module does not exist,0)
Failed to load module “fbdev” (module does not exist,0)
# pacman -S xf86-video-intel xf86-video-vesa xf86-video-fbdev

# pacman -S dbus awesome



# Fonts & Input method
# yaourt -S wqy-microhei ibus ibus-pinyin

# Virtualization
# pacman -S virtualbox virtualbox-additions virtualbox-modules

# System
# pacman htop findutils mlocate rsync curl w3m lftp aria2 unrar gvim unzip zip gimp firefox chromium android-sdk-patform-tools screen xterm bash-completion bc

# Movie & Music
# pacman -S moc vlc

# Pacman config
# pacman -S yaourt pacman-color

# Pdf viewer
# pacman -S zathura zathura-djvu zathura-pdf-poppler

# Image related
# pacman -S viewnior xzgx imagemagick feh xcompmgr

# Torrent
# pacman -S rtorrent

# Office
# pacman -S libreoffice

# Network protocol analyzer
# pacman -S wireshark-gtk tcpdump

# Network related
# pacman -S dnsutils net-tools iputils  netcfg dialog

# File manager
# pacman -S vifm ranger dropbox

# Filesystem related
# pacman -S ntfs-3g

# Live USB
# pacman unetbootin

$ grep -v ^# /etc/rc.conf | grep -v ^$
LOCALE="en_US.UTF-8"
DAEMON_LOCALE="no"
HARDWARECLOCK="localtime"
TIMEZONE="Asia/Shanghai"
KEYMAP="us"
CONSOLEFONT=
CONSOLEMAP=
USECOLOR="yes"
MODULES=(vboxdrv vboxnetflt)
UDEV_TIMEOUT=30
USEDMRAID="no"
USEBTRFS="no"
USELVM="no"
HOSTNAME="op"
NETWORK_PERSIST="no"
NETWORKS=(ethernet-static)
DAEMONS=(hwclock syslog-ng !network dbus net-profiles !netfs crond slim sshd dropboxd synergys)

$ cat ~/.xprofile
export GTK_IM_MODULE=ibus
export XMODIFIERS=@im=ibus
export QT_IM_MODULE=ibus
ibus-daemon -x -d

$ cat ~/.xinitrc
exec awesome

遇到的一些问题。

# pacman -S sudo
error: pacman: signature from "Allan McRae <me@allanmcrae.com>" is unknown trust
error: failed to commit transaction (invalid or corrupted package (PGP signature))
Errors occurred, no packages were upgraded.

# sudo mv /etc/pacman.conf /etc/pacman.conf.old
# sudo mv /etc/pacman.conf.pacnew /etc/pacman.conf
# sudo pacman-key --init

# pacman -Syu


Replace module-init-tools with core/kmod? [Y/n]
module-init-tools
This package contains a set of programs for loading, inserting, and removing kernel modules for Linux (versions 2.5.48 and above). It serves the same function that the "modutils" package serves for Linux 2.4.
With module-init-tools being declared a dead project by its current maintainer, a new project has stepped up to take its place: kmod. This is intended to be a drop-in replacement, though deprecated functionality in module-init-tools has not been reimplemented.
# cd /etc/modprobe.d
# mv modprobe.conf.pacsave modprobe.conf

# pacman -Syu


initscripts: /etc/profile.d/locale.sh exists in filesystem
# rm -f /etc/profile.d/locale.sh
# pacman -Syu

Pacman "filesystem: /etc/mtab exists in filesystem"
# pacman -S filesystem --force
 

by jaseywang at April 11, 2012 02:51 PM

陈沁欣

无题

莫仗虎狼飞将弓,

时行势运法自弘。

君德当荐春夜雨,

一世孤身万载隆。

                                              2012年4月10日

by antcxgjs@gmail.com(星光居士) at April 11, 2012 02:41 AM

April 08, 2012

王宇希

开启 Cisco SNMP

可选项,提示之用:
(config)# snmp-server contact jaseywang#gmail.com
(config)# snmp-server location Nanjing, Jiangsu
(config)# snmp-server chassis-id Cisco-switch

设置一个 cummunity 的字符串,类似密码,获取该机器的信息就是通过该 community:
(config)# snmp-server community hello_world rw
 
community 为必选,其余的为可选,全部的命令为:
(config)# snmp-server community string [view view-name] [ro | rw] [access-list-number]

设置"trap"以通知收集信息的机器即 10.18.10.1(NMS)
(config)# snmp-server host 10.18.10.1 version 2c hello_world
(config)# snmp-server enable traps snmp all

对访问权限做出一定的控制:
(config)# ip access-list standard SNMP
(config-std-nacl)# permit host 10.18.10.1
(config-std-nacl)# deny any log
(config-std-nacl)# exit

关闭:
Switch (config)# no snmp-server community string
Switch (config)# no snmp-server

ref:

http://www.cisco.com/en/US/docs/switches/lan/catalyst2960/software/release/12.2_25_fx/configuration/guide/swsnmp.html

by jaseywang at April 08, 2012 03:53 PM

April 05, 2012

王宇希

“去除” ls 显示的文件后面的波浪符号(~)

ls 会发现列出的文件除了我们想看的 file,通常还会有一个 file~ 文件,每次看到确实蛮烦人的,通过加 -B 参数可以解决此类问题:
alias ls='ls -lB –color=auto –group-directories-first'

"-B, –ignore-backups do not list implied entries ending with ~"

当然,要真正的删除可以使用下面的方式:
# find / -name "*~" -type f -exec rm {} \;
 

by jaseywang at April 05, 2012 06:26 AM