2013年4月30日 星期二

How do I check and configure serial ports under Linux?



How do I check and configure serial ports under Linux for various purposes such as modem, connecting null modems or connect a dumb terminal?

Linux offers various tools. Linux uses ttySx for a serial port device name. For example, COM1 (DOS/Windows name) is ttyS0, COM2 is ttyS1 and so on.

Task: Display Detected System's Serial Support

Simple run dmesg command
$ dmesg | grep tty
Output:
[   37.531286] serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[   37.531841] 00:0b: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[   37.532138] 0000:04:00.3: ttyS1 at I/O 0x1020 (irq = 18) is a 16550A

setserial command

setserial is a program designed to set and/or report the configuration information associated with a serial port. This information includes what I/O port and IRQ a particular serial port is using, and whether or not the break key should be interpreted as the Secure Attention Key, and so on. Just type the following command:
$ setserial -g /dev/ttyS[0123]
Output:
/dev/ttyS0, UART: 16550A, Port: 0x03f8, IRQ: 4
/dev/ttyS1, UART: 16550A, Port: 0x1020, IRQ: 18
/dev/ttyS2, UART: unknown, Port: 0x03e8, IRQ: 4
/dev/ttyS3, UART: unknown, Port: 0x02e8, IRQ: 3
setserial with -g option help to find out what physical serial ports your Linux box has.

Linux serial console programs

Once serial ports identified you can configure Linux box using various utilities:
  1. minicom- The best friendly serial communication program for controlling modems and connecting to dump devices
  2. wvidial or other GUI dial up networking program - a PPP dialer with built-in intelligence.
  3. getty / agetty - agetty opens a tty port, prompts for a login name and invokes the /bin/login command.
  4. grub / lilo configuration - To configure serial port as the system console

iSCSI initiator configuration in RedHat Enterprise Linux 5


iSCSI initiator configuration in RedHat Enterprise Linux 5

The following post will discuss about iSCSI initiator configuration in RedHat Enterprise Linux 5, this method is also applicable to all RHEL5 derivatives. The iSCSI LUNs will be provided by an HP P4000 array.
First of all we need to get and install the iscsi-initiator-utils RPM package, you can use yum to get and install the package from any supported repository for CentOS or RHEL. You can also download the package from RedHat Network if you have a valid RHN account and your system doesn’t have internet connection.
[root@rhel5 ~]# rpm -ivh /tmp/iscsi-initiator-utils-6.2.0.871-0.16.el5.x86_64.rpm
Preparing...                ########################################### [100%]
   1:iscsi-initiator-utils  ########################################### [100%]
[root@rhel5 ~]#
[root@rhel5 ~]#rpm -qa | grep iscsi
iscsi-initiator-utils-6.2.0.871-0.16.el5
[root@rhel5 ~]# rpm -qi iscsi-initiator-utils-6.2.0.871-0.16.el5
Name        : iscsi-initiator-utils        Relocations: (not relocatable)
Version     : 6.2.0.871                         Vendor: Red Hat, Inc.
Release     : 0.16.el5                      Build Date: Tue 09 Mar 2010 09:16:29 PM CET
Install Date: Wed 16 Feb 2011 11:34:03 AM CET      Build Host: x86-005.build.bos.redhat.com
Group       : System Environment/Daemons    Source RPM: iscsi-initiator-utils-6.2.0.871-0.16.el5.src.rpm
Size        : 1960412                          License: GPL
Signature   : DSA/SHA1, Wed 10 Mar 2010 04:26:37 PM CET, Key ID 5326810137017186
Packager    : Red Hat, Inc. 
URL         : http://www.open-iscsi.org
Summary     : iSCSI daemon and utility programs
Description :
The iscsi package provides the server daemon for the iSCSI protocol,
as well as the utility programs used to manage it. iSCSI is a protocol
for distributed disk access using SCSI commands sent over Internet
Protocol networks.
[root@rhel5 ~]#
Next we are going to configure the initiator. The iSCSI initiator is composed by two services,iscsi and iscsid, enable them to start at system startup using chkconfig.
[root@rhel5 ~]# chkconfig iscsi on
[root@rhel5 ~]# chkconfig iscsid on
[root@rhel5 ~]#
[root@rhel5 ~]# chkconfig --list | grep iscsi
iscsi           0:off   1:off   2:on    3:on    4:on    5:on    6:off
iscsid          0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@rhel5 ~]#
[root@rhel5 ~]#
Once iSCSI is configured start the service.
[root@rhel5 ~]# service iscsi start
iscsid is stopped
Starting iSCSI daemon:                                     [  OK  ]
                                                           [  OK  ]
Setting up iSCSI targets: iscsiadm: No records found!
                                                           [  OK  ]
[root@rhel5 ~]#
[root@rhel5 ~]# service iscsi status
iscsid (pid  14170) is running...
[root@rhel5 ~]#
From the P4000 CMC we need to add the server to the management group configuration like we would do with any other server.
The server iqn can be found in the file /etc/iscsi/initiatorname.iscsi.
[root@cl-node1 ~]# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.1994-05.com.redhat:2551bf29b48
[root@cl-node1 ~]#
Create any iSCSI volumes you need in the P4000 arrays and assign them to the RedHat system. Then to discover the presented LUNs, from the Linux server run the iscsiadm command.
[root@rhel5 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.126.60
192.168.126.60:3260,1 iqn.2003-10.com.lefthandnetworks:mlab:62:lv-rhel01
[root@rhel5 ~]#
Restart the iSCSI initiator to make the new block device available to the operative system.
[root@rhel5 ~]# service iscsi restart
Stopping iSCSI daemon:
iscsid dead but pid file exists                            [  OK  ]
Starting iSCSI daemon:                                     [  OK  ]
                                                           [  OK  ]
Setting up iSCSI targets: Logging in to [iface: default, target: iqn.2003-10.com.lefthandnetworks:mlab:62:lv-rhel01, portal: 192.168.126.60,3260]
Login to [iface: default, target: iqn.2003-10.com.lefthandnetworks:mlab:62:lv-rhel01, portal: 192.168.126.60,3260]: successful
                                                           [  OK  ]
[root@rhel5 ~]#
Then check that the new disk is available, I used lsscsi but fdisk -l will do.
[root@rhel5 ~]# lsscsi
[0:0:0:0]    disk    VMware,  VMware Virtual S 1.0   /dev/sda
[2:0:0:0]    disk    LEFTHAND iSCSIDisk        9000  /dev/sdb
[root@rhel5 ~]#
[root@rhel5 ~]# fdisk -l /dev/sdb 

Disk /dev/sdb: 156.7 GB, 156766306304 bytes
255 heads, 63 sectors/track, 19059 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table
[root@rhel5 ~]#
At this point the iSCSI configuration is done, the new LUNs will be available through a system reboot as long as the iscsi service is enabled.

iSCSI-target and client 設定


iSCSI-target 設定
建置時之環境:
 伺服器主機:192.168.10.101
 作業系統:CentOS 5.4 x86
 iscsi-target版本:iSCSI enterprise Target  1.4.20.2


一、iSCSI Server


1.安裝系統相關套件
 [root@localhost ~]#yum -y install kernel.x86_64 (或 kernel.i386 版本)
 [root@localhost ~]#yum -y install kernel-devel.x86_64 (版本需與kernel版本同)

 [root@localhost ~]#yum -y install openssl-devel



 [root@localhost ~]#yum -y install gcc



 [root@localhost ~]#yum -y install rpm-build


 [root@localhost ~]#reboot(安裝 kernel 必須重新啟動)


2.安裝 iscsitarget


 下載及安裝iscsi-target套件。

  [root@localhost ~]#tar -xvf iscsitarget-1.4.20.2.tar.gz



  [root@localhost ~]#cd iscsitarget-1.4.20.2



  [root@localhost ~]#make



  [root@localhost ~]#make install



3.建立 iSCSI 使用硬碟空間區塊(若使用單獨之分割區,例 /dev/md0 或 /dev/sdd,則此步驟略過)
 [root@localhost ~]# mkdir -p /iSCSI(可使用單一分割區或建立一目錄)
 [root@localhost ~]# dd if=/dev/zero of=/iSCSI/LUN0 bs=1024 count=40000(指定iscsi磁碟裝置為LUN0,大小為40M)
 [root@localhost ~]# dd if=/dev/zero of=/iSCSI/LUN1 bs=1024 count=8000000指定iscsi磁碟裝置為LUN1,大小為8G)

4.編輯 IET daemon 之設定檔(相關說明在/root/iscsitarget-1.4.19/README)


 (1)相關設定檔 :



  /etc/iet/ietd.conf



  /etc/iet/initiators.allow



  /etc/iet/targets.allow


 (2)編輯主要設定檔

  [root@localhost ~]# vi /etc/iet/ietd.conf


  主要修改以下幾項
# iqn.yyyy-mm.[:identifier]
# iqn通常為日期及網域反置(例tw.com.aa),加上storage標籤組合而成。
Target iqn.2010-03.tw.edu.tn.tnmr:storage.iscsi.iHD01
# 設定使用空間的路徑,LUN必須由編號0開始
#使用某一目錄 ( 例 /iSCSI ) 之空間時
Lun 0 Path=/iSCSI/LUN0,Type=fileio
Lun 1 Path=/iSCSI/LUN1,Type=fileio
#使用某一分割區 ( 例 /dev/md0 或 /dev/sdd ) 之空間時
Lun 0 Path=/dev/md0,Type=fileio
Lun 1 Path=/dev/sdd,Type=fileio
# Alias 可有可無
Alias iSCSI
MaxConnections 1
InitialR2T Yes
ImmediateData Yes

4.開啟防火牆 3260 port,重啟iptables (service iptables restart)


5.設定與啟動 iSCSI-Target 服務

 [root@centos1 ~]# chkconfig iscsi-target on



 [root@centos1 ~]# service iscsi-target start







二、iSCSI client端

(一)Linux OS

1.安裝

 [root@centos2 ~]# yum -y install iscsi-initiator-utils
2.編輯設定檔

 /etc/iscsi/iscsid.conf(一般可以用預設值)

 /etc/iscsi/initiatorname.iscsi (名稱須和Server端相同)

 [root@centos2 ~]# vi /etc/iscsi/initiatorname.iscs

          InitiatorName=iqn.2010-03.tw.idv.lu:storage.iscsi.vg01
(InitiatorName須和target 名稱相同)

3.啟動
(1)設定開機後自動啟動
[root@centos2 ~]# chkconfig iscsi on
(2)立刻啟動
[root@centos2 ~]# service iscsi start

4.列出與掛上 Server 上的 iSCSI Target

 [root@centos2 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.10.101

5.掛載

 [root@centos2 ~]# iscsiadm -m node -p 192.168.128.101 -T iqn.2010-03.tw.edu.tn.tnmr:storage.iscsi.iHD01 -l -d 10



 訊息:


 iscsiadm: updated 'node.session.err_timeo.lu_reset_timeout', '30' => '20'


Login to [iface: default, target: iqn.2010-4.tw.edu.tn.tnmr:storage.iscsi.iHD01,  portal: 192.168.10.101,3260]: successful
如果有以上的訊息 login to [xxx] : successful表示已正常連上。

6.列出本機上掛載的 iSCSI 項目
[root@centos2 ~]# iscsiadm --mode node 192.168.10.101:3260,1

iqn.2010-4.tw.edu.tn.tnmr:storage.iscsi.iHD01

7.查詢掛載位置


[root@centos2 ~]# tail -f /var/log/messages | grep "SCSI device" Feb 7 08:33:52 localhost kernel: SCSI device sdk: drive cache: write through
-->掛載為 /dev/sdk

8.列出目前硬碟狀態
[root@centos2 ~]# fdisk -l

9.進行硬碟作分割 (fdisk /dev/sdk)

10.格式化 (mkfs.ext3 /dev/sdk1)

11.掛載/dev/sdk1到預定的目錄上(例/mnt/iscsi )
[root@centos2 ~]# mkdir /mnt/iscsi
[root@centos2 ~]# mount /dev/sdc1 /mnt/iscsi

12.列出主機分割區使用情形
[root@centos2 ~]# df -h
Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol00


/dev/sdk1 38M 4.5M 32M 13% /mnt/iscsi

2013年4月24日 星期三

設定 /etc/resolv.conf 檔案


此檔案可用來設定 DNS 用戶端要求名稱解析時,所定義的各項內容。我們分別來看一個完整的resolv.conf的檔案:

domain twnic.com.tw
nameserver 192.168.10.1
nameserver 192.168.2.5
search twnic.com.tw twnic.net.tw

“domain”指定本地的網域名稱,如果查詢時的名稱沒有包含小數點,則會自動補上此處的網域名稱為字尾再送給DNS伺服器。
“nameserver”指定用戶端要求進行名稱解析的 nameserver IP位址,在此可指定多部DNS伺服器,則用戶端將會依序提出查詢要求。

“search”這個選項為非必要選項,而功能在於若使用者指定主機名稱查詢時,所需要搜尋的網域名稱。例如,當我們設 “search twnic.com.tw”時,當DNS伺服器在做名稱解析過程中,無法對輸入的名稱,例如pc1,找出相對應的IP時,則DNS會利用search的設定值加上需查詢的名稱,即pc1.twnic.com.tw來進行解析,解析失敗時則會嘗試pc1.twnic.net.tw。

需要注意的是當我們想嘗試多種在沒有包含小數點,於字尾補上所需要搜尋的網域名稱時,我們會在"search"中指定幾種組合給DNS伺服器,而不能在"domain"中指定。因為“domain”是指定本地的網域名稱,而搜尋時也以“domain”為優先嘗試,如果失敗之後才會嘗試"search"中的組合。

Linux - 設定TimeZone


轉載於: http://linux-guys.blogspot.tw/2011/02/linux-timezone.html


第一種
查看目前時區
[root@darwin-test ~]# date
Wed Feb  9 05:20:22 EST 2011

[root@darwin-test ~]# cat /etc/sysconfig/clock
# The ZONE parameter is only evaluated by system-config-date.
# The timezone of the system is defined by the contents of /etc/localtime.
ZONE="America/New_York"   //目前是New York時區
UTC=true
ARC=false

暫時設定台灣時區
[root@darwin-test ~]# export TZ='Asia/Taipei'
[root@darwin-test ~]# date
Wed Feb  9 18:22:24 CST 2011

永久設定時區
[root@darwin-test ~]# system-config-date
[root@darwin-test ~]# cat /etc/sysconfig/clock
# The ZONE parameter is only evaluated by system-config-date.
# The timezone of the system is defined by the contents of /etc/localtime.
ZONE="Asia/Taipei"
UTC=true
ARC=false

[root@darwin-test ~]# date
Wed Feb  9 18:26:16 CST 2011

另一作法-永久設定時區
編輯家目錄.profile or $HOME/.bash_profile
#vi $HOME/.profile
內容如下
export TZ='Asia/Taipei'

另一命令可供參考
[root@darwin-test ~]# tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.
 1) Africa
 2) Americas
 3) Antarctica
 4) Arctic Ocean
 5) Asia
 6) Atlantic Ocean
 7) Australia
 8) Europe
 9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
#? 5
Please select a country.
 1) Afghanistan           18) Israel                35) Palestine
 2) Armenia               19) Japan                 36) Philippines
 3) Azerbaijan            20) Jordan                37) Qatar
 4) Bahrain               21) Kazakhstan            38) Russia
 5) Bangladesh            22) Korea (North)         39) Saudi Arabia
 6) Bhutan                23) Korea (South)         40) Singapore
 7) Brunei                24) Kuwait                41) Sri Lanka
 8) Cambodia              25) Kyrgyzstan            42) Syria
 9) China                 26) Laos                  43) Taiwan
10) Cyprus                27) Lebanon               44) Tajikistan
11) East Timor            28) Macau                 45) Thailand
12) Georgia               29) Malaysia              46) Turkmenistan
13) Hong Kong             30) Mongolia              47) United Arab Emirates
14) India                 31) Myanmar (Burma)       48) Uzbekistan
15) Indonesia             32) Nepal                 49) Vietnam
16) Iran                  33) Oman                  50) Yemen
17) Iraq                  34) Pakistan
#? 43
The following information has been given:
        Taiwan
Therefore TZ='Asia/Taipei' will be used.
Local time is now:      Wed Feb  9 18:21:13 CST 2011.
Universal Time is now:  Wed Feb  9 10:21:13 UTC 2011.
Is the above information OK?
1) Yes
2) No
#? 1
You can make this change permanent for yourself by appending the line
        TZ='Asia/Taipei'; export TZto the file '.profile' in your home directory;
then log out and log in again.
Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Asia/Taipei

現在要做的事情就是按照提示,把TZ='Asia/Taipei'; export TZ   添加到.profile中(bash對應加到.bash_profile)。


tzselect命令用於選擇時區。要注意的是tzselect只是幫我們把選擇的時區顯示出來,並不會實際生效,也就是說它僅僅告訴我們怎麼樣去設置環境變量TZ。

如果你要永久更改時區,按照tzselect命令提示的信息,在.profile或者/etc/profile中設置正確的TZ環境變量並導出。還有另外一種更改時區的方法就是直接更改系統配置文件/etc/sysconfig/clock,然後修改符號鏈接/etc/locatime對應的文件,詳見示例三。

第二種

示例三 通過更改配置文件來修改時區
[root@new55 ~]# cat /etc/sysconfig/clock
# The ZONE parameter is only evaluated by system-config-date.
# The timezone of the system is defined by the contents of /etc/localtime.
ZONE="Asia/Shanghai"
UTC=true
ARC=false
[root@new55 ~]#
修改linux系統時區
    1) 可修改/etc/sysconfig/clock
        ZONE=Asia/Shanghai ( 查/usr/share/zoneinfo 下面的文件。 )
        UTC=false ( 硬件時鐘是否為UTC 或者說GMT 時鐘。 )
        ARC=false (如果是在Alpha 機器上,則設置為true 。 )
    (把硬件時鐘設置為UTC 的好處就是他能自動設置夏時制,缺點是,在安裝有多重操作系統啟動的機器上,在另外的操作系統上時鐘會錯誤。 )
    2) rm /etc/localtime
        Zhy: 這個文件是個符號鏈接?如果是在系統安裝時就設置好的話,就是個普通文件。
    3) 以上海為例:
        ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime



第三種

變更 Linux 系統預設時區(timezone)
1. 使用 root 帳號登入終端機
2. 執行 date 指令,此時會出現類似 Wed Jan 27 14:11:29 CST 2010 的訊息,其中 CST 就是目前系統預設時區
3. 切換到 /usr/share/zoneinfo 目錄,其中有所有時區(timezone)的列表, Taipei 時區在 Asia 下
4.  執行 mv /etc/localtime  /etc/localtime-old 備份目前設定
5.  執行 ln -sf /usr/share/zoneinfo/Asia/Taipei /etc/localtime 將欲使用的時區 softlink 到 /etc/localtime
6.  修改 /etc/sysconfig/clock 檔案內容,改為 ZONE="Asia/Taipei"
7.  執行 /sbin/hwclock --systohc 同步硬體時鐘





如何在Windows的事件檢視器event viewer,查詢開機關機的紀錄

Windows 如何 事件檢視器 查詢開機關機紀錄 Step1: 打開windows的 「 事件檢視器 」,開啟「 建立自訂檢視… 」視窗,在「事件記錄檔」選項,將「Windows 紀錄」內勾選「系統」選項。 Step2: 內含/排除事件識別碼: 」排除事件識別碼打「6005,6...