2010-10-22

Boot Ubunto into Text Mode

Modify '/etc/default/grub' to replace "quiet splash" with "text" as below:

GRUB_DEFAULT=0
GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="text"
GRUB_CMDLINE_LINUX=""
...

Then run command to make it effective:

sudo update-grub

Reboot to check.

2010-10-21

Redirect syslog from busybox system to Ubuntu

Busybox syslogd uses '/etc/syslog.conf' as the configuration file. From this configuration file, can configure syslogd redirect the log messages to remote host.

- Settings of embedded system

  Check '/etc/syslog.conf' file for the configuration:

  * Make sure the 'remote' is included in variable 'DESTINATION'.

  * Make sure the variable 'REMOTE' is defined and put the right IP address of the remote syslog server

  example:

     DESTINATION="remote"
     REMOTE=<ip-of-remote-host>:514

  Restart the syslogd daemon after configuration.

- Settings of Ubuntu

  Note: assuming 'rsyslog' is used as the syslog server.

  Check '/etc/rsyslog.conf' file for the configuration:

  * Make sure rsyslog accepts remote syslog message via UDP and TCP by uncommenting out below lines:

   $ModLoad imudp
   $UDPServerRun 514

   $ModLoad imtcp
   $TCPServerRun 514

  Restart 'rsyslog' on Ubuntu after configuration. Now Ubuntu should be able to accept syslog message from target system.

- Customize the syslog on Ubuntu

1. Use simple log format

  By default, the syslog message on Ubuntu includes timing, host, and application name as prefix. Sometimes it's annoying. Customize to use simple format without these message:

  Change '/etc/rsyslog.conf' file to add a new line like this to define a new format:

   $template SimpleFormat,"%msg:::drop-last-lf%\n"

  Now you can change '/etc/rsyslog/50-default.conf' to use this format.

2. Use separate log file for particular application or host

   You may want to use separate log file for your own application, or for message from particular host. This can be done by adding configure to '/etc/rsyslog/50-default.conf' like this:

      if $programname == 'controller' then /var/log/controller.log;SimpleFormat

      if $HOSTNAME != 'localhost' then /var/log/board.log;SimpleFormat

   The first line makes the rsyslog daemon to use separate file '/var/log/controller.log' for all messages from application named 'controller' using the simple format defined above.

   The second line makes the rsyslog daemon to use separate file '/var/log/board.log' for all message coming from remote machines using the simple format defined above.





2010-10-20

PuTTY + Xming 远程使用 Linux GUI


  在家里的PC上用VMWare做了一个Oracle Enterprise Linux虚拟机做数据库,虚拟机OEL没启用图形界面,因此需要在PC上装一个X Window Server才能使用GUI。
    看Wiki系统地了解了一下X Window System。X Window System(常被简称为X11或X),是一套基于X display protocol的windowing system,X GUI环境的功能包括窗口的绘制、移动,以及与鼠标、键盘等输入设备的交互。X 协议当前版本为MIT在1987年9月制定的11版----这就是X11的来历,最新版则是2008年9月发布的X11R7.4。
    X采用C/S模型:一个X server 和多个应用程序(client)通信。server接收client的请求绘制窗口,并将来自鼠标、键盘等设备的输入传递给client。
    初学X的用户经常被描述如何远程使用Linux GUI环境的文档搞糊涂:Linux主机上的应用程序被称为client,而用户终端计算机被称为server,看上去好像说反了。实际上,X是从程序结构而非用户或硬件环境的角度来描述的,在用户终端上工作的X server为应用程序提供服务,所以被看作server,而Linux主机上的应用程序接受服务,所以被看作client。
    X server和client可以位于同一计算机上,例如在Linux主机上使用KDE等桌面环境就是这种模式。X server也可以通过同构网络、异构网络或Internet与client通信。
    X server与client之间的通信是不加密的,这个问题可以通过SSH解决。SSH是Secure Shell的简称,SSH可以看作是通信被加密压缩版的telnet。我需要用到SSH的forwarding功能,当X server与client所在计算机都支持SSH协议时,X server与client之间不安全的TCP/IP连接可以转送到(forwarding)二者之间建立的SSH连接上。
    说了一堆概念,现在可以挽起袖子干活了。Linux主机(A, IP: 192.168.1.201)和Windows客户机(B, IP: 192.168.1.101)都已经装好了,我要做的就是在 B 上安装一个X server,一个SSH客户端,在A上启用SSH的X11 forwarding。
1 安装配置B上的X server
X server我选择的是Xming,这是一个免费的windows平台上的X server。需要安装两个组件,主程序和字体
  • Xming X server, Xming-6-9-0-31-setup.exe
  • Xming Fonts, Xming-fonts-7-3-0-22-setup.exe
Xming.install.03.png
Xming.install.05.png   
    运行XLaunch配置Xming X server,将配置保存为.xlaunch 文件。使用默认设置即可。
Xming.config.01.png    Display 代表一套 I/O 设备,包括显示、鼠标、键盘;Display Number 就是这套 I/O 设备的代号;同时 Display Number 还决定了 Xming X server 的 TCP 端口,端口号为 6000 + Display Number。Linux 主机上的应用程序通过此端口建立与 Xming X server 的连接。
Xming.config.02.png
Xming.config.03.png
Xming.config.04.png
       将配置保存为Xming.display.0.xlaunch。双击此文件就能启动X server,系统栏里多了一个Xming的图标。
2 安装配置B上的SSH
    SSH客户端使用PuTTY,PuTTY是freeware+greenware,就一个exe文件。
PuTTY.config.01.png
配置 Session:配置主机IP,连接方式为SSH
PuTTY.config.02.png
Connection\Data:保存连接使用的用户名
PuTTY.config.03.png
Connection\SSH\X11:Enable X11 Forwarding,X display Location 为 localhost:0,这里的 0 就是配置 Xming X server 时指定的 Display Number。
PuTTY.config.05.png 
保存设置为 VSERVER01。
3 配置A上的SSH
    要允许Linux主机上的SSH X转发,查看 /etc/ssh/sshd_config 文件,加入以下一行,
X11Forwrding yes
    至此配置完成。在B上使用PuTTY连接到A,输入xclock &,可以看到X server工作的效果了。

参考
【2】SSH
【3】Xming
【4】PuTTY
【5】Putty + Xming 方便的远程Linux GUI
【6】Xming + PuTTY 在Windows下远程Linux主机使用图形界面的程序
http://hi.baidu.com/mooncold/blog/item/8e0dfddc4f29a3a4cd11663a.html

连接ssh缓慢的问题

sshd收到客户端连接请求时默认会做域名反查,反查过程如果慢,用户就会感觉连接慢。
1.最直接的办法是修改sshd的配置,UseDNS项改为0,重启sshd 。
2.修改hosts或resolv.conf , 使得sshd能够快速进行域名反查。