2012年3月11日星期日

我的VI设定


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Environment
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nocompatible
"behave mswin
set fileencodings=utf-8,gb2312,ucs-bom,euc-cn,euc-tw,gb18030,gbk,cp936

" With a map leader it's possible to do extra key combinations
" like <leader>w saves the current file
let g:mapleader = ","


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Sets how many lines of history VIM has to remember
set history=700
"set colorcolumn=80
set number
set cursorline
"set cursorcolumn

" Enable filetype plugin
filetype on
filetype plugin on
filetype indent on

" Set to auto read when a file is changed from the outside
set autoread

" Fast saving
nmap <leader>w :w!<cr>

" Fast quiting
nmap <leader>q :q<cr>

" system clipboard
set clipboard+=unnamed

" Maximize window
autocmd GUIEnter * simalt ~x

" 带有如下符号的单词不要被换行分割
set iskeyword+=_,$,@,%,#,-

" Mouse enable
set mouse=a

" folder enable with space
set foldenable
set foldmethod=manual
nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>

" 启动时不显示援助索马里儿童的提示
set shortmess=atI


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => VIM user interface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set 7 lines to the curors - when moving vertical..
set so=7

set wildmenu "Turn on WiLd menu

set ruler "Always show current position

set cmdheight=2 "The commandbar height

set hid "Change buffer - without saving

" Set backspace config
set backspace=eol,start,indent
set whichwrap+=<,>,h,l

set ignorecase "Ignore case when searching
set smartcase

set hlsearch "Highlight search things

set incsearch "Make search act like search in modern browsers
set nolazyredraw "Don't redraw while executing macros

set magic "Set magic on, for regular expressions

set showmatch "Show matching bracets when text indicator is over them
set mat=2 "How many tenths of a second to blink

" No sound on errors
set noerrorbells
set novisualbell
set t_vb=
set tm=500

set listchars=tab:>.,trail:.,extends:#,nbsp:. " Highlight problematic whitespace

if has('statusline')
    " Always show the statusline
    set laststatus=2

    " Broken down into easily includeable segments
    set statusline=%<%f\    " Filename
    set statusline+=%w%h%m%r " Options
    "set statusline+=%{fugitive#statusline()} "  Git Hotness
    set statusline+=\ [%{&ff}/%Y]            " filetype
    set statusline+=\ [%{getcwd()}%h\]          " current dir
    set statusline+=\ [A=\%03.3b/H=\%02.2B] " ASCII / Hexadecimal value of char
    set statusline+=%=%-16.(%l/%L,%c%V%)\ %p%%  " Right aligned file nav info
endif


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Colors and Fonts
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
syntax enable "Enable syntax hl

if has("gui_running")
    set guioptions-=m
    set guioptions-=T
    map <silent> <F11> :if &guioptions =~# 'T' <Bar>
            \set guioptions-=T <Bar>
            \set guioptions-=m <bar>
        \else <Bar>
            \set guioptions+=T <Bar>
            \set guioptions+=m <Bar>
        \endif<CR>
    set t_Co=256
    colorscheme desert
else
    colorscheme zellner
endif


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Files, backups and undo
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Turn backup off, since most stuff is in SVN, git anyway...
set nobackup
set nowb
set noswapfile

"Persistent undo
try
    if MySys() == "windows"
      set undodir=C:\Windows\Temp
    else
      set undodir=~/.vim_runtime/undodir
    endif

    set undofile
catch
endtry


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Text, tab and indent related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set expandtab
set shiftwidth=4
set tabstop=4
set smarttab

set lbr
set tw=500

set ai "Auto indent
set si "Smart indet
set wrap "Wrap lines

" Remove trailing whitespaces and ^M chars
autocmd FileType c,cpp,java,php,js,python,twig,xml,yml autocmd BufWritePre <buffer> :call setline(1,map(getline(1,"$"),'substitute(v:val,"\\s\\+$","","")'))


""""""""""""""""""""""""""""""
" => Visual mode related
""""""""""""""""""""""""""""""
" Really useful!
"  In visual mode when you press * or # to search for the current selection
vnoremap <silent> * :call VisualSearch('f')<CR>
vnoremap <silent> # :call VisualSearch('b')<CR>

" When you press gv you vimgrep after the selected text
vnoremap <silent> gv :call VisualSearch('gv')<CR>
map <leader>g :vimgrep // **/*<left><left><left><left><left><left>


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Other's Key Mappings
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Yank from the cursor to the end of the line, to be consistent with C and D.
nnoremap Y y$
nnoremap noah :call SetCompany("NOAH")<cr>
nnoremap fj :call SetCompany("FJ")<cr>
noremap <S-tab> :call TabToSpace()<cr><esc>
"noremap <C-P> :hardcopy<cr>

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Moving around, tabs and buffers
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Smart way to move btw. windows
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l

" Close the current buffer
map <leader>bd :Bclose<cr>

" Close all the buffers
map <leader>ba :1,300 bd!<cr>

" Tab configuration
"nmap <C-S-tab> :tabprevious<cr>
"nmap <C-tab> :tabnext<cr>
imap <C-S-tab> <ESC>:tabprevious<cr>a
imap <C-tab> <ESC>:tabnext<cr>a
"nmap <C-t> :tabnew<cr>
imap <C-t> <ESC>:tabnew<cr>a
"map <C-w> :tabclose<cr>
imap <C-w> <esc>:tabclose<cr>a

" When pressing <leader>cd switch to the directory of the open buffer
map <leader>cd :cd %:p:h<cr>

" Specify the behavior when switching between buffers
try
    set switchbuf=usetab
    set stal=2
catch
endtry


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin Setteing              
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Minibuffer {
    let g:miniBufExplModSelTarget = 1
    let g:miniBufExplorerMoreThanOne = 2
    let g:miniBufExplModSelTarget = 0
    let g:miniBufExplUseSingleClick = 1
    let g:miniBufExplMapWindowNavVim = 1
    let g:miniBufExplVSplit = 25
    let g:miniBufExplSplitBelow=1
    let g:bufExplorerSortBy = "name"

    autocmd BufRead,BufNew :call UMiniBufExplorer

    map <leader>u :TMiniBufExplorer<cr>
" }


" NerdTree {
    map <C-e> :NERDTreeToggle<CR>
    "nmap <leader>nt :NERDTreeFind<CR>

    let NERDTreeShowBookmarks=1
    let NERDTreeIgnore=['\.pyc', '\~$', '\.swo$', '\.swp$', '\.git', '\.hg', '\.svn', '\.bzr']
    let NERDTreeChDirMode=0
    let NERDTreeQuitOnOpen=1
    let NERDTreeShowHidden=1
    let NERDTreeKeepTreeInNewTab=1
" }


" FencView {
    let g:fencview_autodetect=0
    nmap <silent> <leader>fe :FencAutoDetect<CR>
    nmap <silent> <leader>fv :FencView<CR>
" }


" winmanager {
    let g:winManagerWindowLayout='FileExplorer|TagList'
    nmap wm :WMToggle<cr>
" }


" A {
    nnoremap <silent> <F12> :A<CR>
" }


" Grep {
    nnoremap <silent> <F3> :Grep<CR>
" }


" Ctags {
    set tags=tags;
    " Sort by name
    let Tlist_Sort_Type = "name"

    " list in right side
    let Tlist_Use_Right_Window = 1
    let Tlist_Compart_Format = 1
    let Tlist_Exist_OnlyWindow = 1

    " 不要关闭其他文件的tags
    let Tlist_File_Fold_Auto_Close = 0

    " 不要显示折叠树
    let Tlist_Enable_Fold_Column = 0
" }


" MRU {
    let MRU_Max_Entries = 400
    map <leader>f :MRU<CR>
" }


" Yankring {
    map <leader>y :YRShow<cr>
" }


" bufExplorer {
    let g:bufExplorerDefaultHelp=0
    let g:bufExplorerShowRelativePath=1
    nmap <leader>b :BufExplorer<CR>
" }

" Calendar {
    "let calendar_diary = "D:\diary"
" }

" FuzzyFinder {
    "nnoremap <unique> <leader>fb :FufBuffer!<CR>
    nnoremap <leader>ff :FufFile!<CR>
    "nnoremap <unique> <leader>fc :FufRenewCache<CR>
    "autocmd FileType fuf nmap <C-c> <ESC>
    "let g:fuf_patternSeparator = ' '
    "let g:fuf_modesDisable = ['mrucmd']
    "let g:fuf_mrufile_exclude = '\v\.DS_Store|\.git|\.swp|\.svn'
    "let g:fuf_mrufile_maxItem = 100
    "let g:fuf_enumeratingLimit = 20
    "let g:fuf_file_exclude = '\v\.DS_Store|\.git|\.swp|\.svn'
" }
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Functions                  
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
fun! MySys()
    return "linux"
endfun


function! CurDir()
    let curdir = getcwd()
    return curdir
endfunction


function! SetCompany(name)
    let s:lineno=line(".")
    let s:linestr = getline(".")
    if strlen(s:linestr) < 70
        for i in range(strlen(s:linestr)+1, 70, 1)
            let s:linestr.=" "
        endfor
        let s:linestr.=a:name
        :+1
        return setline (s:lineno, s:linestr)
    endif
    :+1
endfunction


function! TabToSpace()
    :set ts=4
    :set expandtab
    :%retab! "加!是用于处理非空白字符之后的TAB,即所有的TAB,若不加!,则只处理行首的TAB。
endfunction


function! VisualSearch(direction) range
    let l:saved_reg = @"
    execute "normal! vgvy"

    let l:pattern = escape(@", '\\/.*$^~[]')
    let l:pattern = substitute(l:pattern, "\n$", "", "")

    if a:direction == 'b'
        execute "normal ?" . l:pattern . "^M"
    elseif a:direction == 'gv'
        call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.')
    elseif a:direction == 'f'
        execute "normal /" . l:pattern . "^M"
    endif

    let @/ = l:pattern
    let @" = l:saved_reg
endfunction

2012年3月10日星期六

VI命令


vi编辑器是所有Unix及Linux系统下标准的编辑器,它的强大不逊 色于任何最新的文本编辑器,这里只是简单地介绍一下它的用法和一小部分指令。由于对Unix及Linux系统的任何版本,vi编辑器是完全相同的,因此您 可以在其他任何介绍vi的地方进一步了解它。Vi也是Linux中最基本的文本编辑器,学会它后,您将在Linux的世界里畅行无阻。
1、vi的基本概念
基本上vi可以分为三种状态,分别是命令模式(command mode)、插入模式(Insert mode)和底行模式(last line mode),各模式的功能区分如下:

1) 命令行模式command mode)
控制屏幕光标的移动,字符、字或行的删除,移动复制某区段及进入Insert mode下,或者到 last line mode。

2) 插入模式(Insert mode)
只有在Insert mode下,才可以做文字输入,按「ESC」键可回到命令行模式。

3) 底行模式(last line mode)
将文件保存或退出vi,也可以设置编辑环境,如寻找字符串、列出行号……等。
不过一般我们在使用时把vi简化成两个模式,就是将底行模式(last line mode)也算入命令行模式command mode)。

2、vi的基本操作
a) 进入vi
在系统提示符号输入vi及文件名称后,就进入vi全屏幕编辑画面:
$ vi myfile
不过有一点要特别注意,就是您进入vi之后,是处于「命令行模式(command mode)」,您要切换到「插入模式(Insert mode)」才能够输入文字。初次使用vi的人都会想先用上下左右键移动光标,结果电脑一直哔哔叫,把自己气个半死,所以进入vi后,先不要乱动,转换到 「插入模式(Insert mode)」再说吧!

b) 切换至插入模式(Insert mode)编辑文件
在「命令行模式(command mode)」下按一下字母「i」就可以进入「插入模式(Insert mode)」,这时候你就可以开始输入文字了。

c) Insert 的切换
您目前处于「插入模式(Insert mode)」,您就只能一直输入文字,如果您发现输错了字!想用光标键往回移动,将该字删除,就要先按一下「ESC」键转到「命令行模式(command mode)」再删除文字。

d) 退出vi及保存文件
在「命令行模式(command mode)」下,按一下「:」冒号键进入「Last line mode」,例如:
: w filename (输入 「w filename」将文章以指定的文件名filename保存)
: wq (输入「wq」,存盘并退出vi)
: q! (输入q!, 不存盘强制退出vi)

3、命令行模式(command mode)功能键
1). 插入模式
按「i」切换进入插入模式「insert mode」,按“i”进入插入模式后是从光标当前位置开始输入文件;
按「a」进入插入模式后,是从目前光标所在位置的下一个位置开始输入文字;
按「o」进入插入模式后,是插入新的一行,从行首开始输入文字。

2). 从插入模式切换为命令行模式
按「ESC」键。

3). 移动光标
vi可以直接用键盘上的光标来上下左右移动,但正规的vi是用小写英文字母「h」、「j」、「k」、「l」,分别控制光标左、下、上、右移一格。
按「ctrl」+「b」:屏幕往“后”移动一页。
按「ctrl」+「f」:屏幕往“前”移动一页。
按「ctrl」+「u」:屏幕往“后”移动半页。
按「ctrl」+「d」:屏幕往“前”移动半页。

按数字「0」:移到文章的开头。
按「G」:移动到文章的最后。
按「$」:移动到光标所在行的“行尾”。
按「^」:移动到光标所在行的“行首”
按「w」:光标跳到下个字的开头
按「e」:光标跳到下个字的字尾
按「b」:光标回到上个字的开头
按「#l」:光标移到该行的第#个位置,如:5l,56l。

4). 删除文字
「x」:每按一次,删除光标所在位置的“后面”一个字符。
「#x」:例如,「6x」表示删除光标所在位置的“后面”6个字符。
「X」:大写的X,每按一次,删除光标所在位置的“前面”一个字符。
「#X」:例如,「20X」表示删除光标所在位置的“前面”20个字符。
「dd」:删除光标所在行。
「#dd」:从光标所在行开始删除#行

5). 复制
「yw」:将光标所在之处到字尾的字符复制到缓冲区中。
「#yw」:复制#个字到缓冲区
「yy」:复制光标所在行到缓冲区。
「#yy」:例如,「6yy」表示拷贝从光标所在的该行“往下数”6行文字。
「p」:将缓冲区内的字符贴到光标所在位置。注意:所有与“y”有关的复制命令都必须与“p”配合才能完成复制与粘贴功能。
   v :字符选择,会将光标经过癿地方反白选择!
   V: 行选择,会将光标经过癿行反白选择!
   [Ctrl]+v:区块选择,可以用长方形癿方式选择资料

6). 替换
「r」:替换光标所在处的字符。
「R」:替换光标所到之处的字符,直到按下「ESC」键为止。

7). 回复上一次操作
「u」:如果您误执行一个命令,可以马上按下「u」,回到上一个操作。按多次“u”可以执行多次回复。
          [Ctrl]+r :重做上一个劢作。(常用)

8). 更改
「cw」:更改光标所在处的字到字尾处
「c#w」:例如,「c3w」表示更改3个字

9). 跳至指定的行
「ctrl」+「g」列出光标所在行的行号。
「#G」:例如,「15G」,表示移动光标至文章的第15行行首。

4、Last line mode下命令简介
在使用「last line mode」之前,请记住先按「ESC」键确定您已经处于「command mode」下后,再按「:」冒号即可进入「last line mode」。

A) 列出行号
「set nu」:输入「set nu」后,会在文件中的每一行前面列出行号。

B) 跳到文件中的某一行
「#」:「#」号表示一个数字,在冒号后输入一个数字,再按回车键就会跳到该行了,如输入数字15,再回车,就会跳到文章的第15行。

C) 查找字符
「/关键字」:向后查找,先按「/」键,再输入您想寻找的字符,如果第一次找的关键字不是您想要的,可以一直按「n」会往后寻找到您要的关键字为止。  查找上一个N
「?关键字」:向前查找,先按「?」键,再输入您想寻找的字符,如果第一次找的关键字不是您想要的,可以一直按「n」会往前寻找到您要的关键字为止。 查找上一个N

D) 保存文件
「w」:在冒号输入字母「w」就可以将文件保存起来。

E) 离开vi
「q」:按「q」就是退出,如果无法离开vi,可以在「q」后跟一个「!」强制离开vi。
「qw」:一般建议离开时,搭配「w」一起使用,这样在退出的时候还可以保存文件。


Storage Management and Disaster Recovery

1.Storage Basics
   1.1 Devices
     You can see which disk devices are available on your host by listing them using the ls command.
     $ ls -l /dev/sd*
     The actual device file name consists of the prefix sd and a letter indicating which disk it belongs to. The first detected disk is sda, the second is sdb, the third is sdc, and so on. Finally, each partition on the disk gets its own device node as well, and the partition number is the final part of the name. This means that sda1 is the first partition on disk sda, sdb2 is the second partition on disk sdb, and so on. We’ll discuss partitions shortly.

   1.2 Partitions


   1.3 using your File System
     1.3.1 Automating Mounts
     Each partition you want to mount automatically at startup needs to be listed in the /etc/fstab file.

#
# /etc/fstab
# Created by anaconda on Sun Aug 14 02:56:30 2011
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=7d014851-6087-4d10-ac52-22bdc850d49a /                       ext4    defaults        1 1
UUID=62cfa358-911e-4719-a6b6-698eacaa47a4 /boot                   ext4    defaults        1 2
UUID=3f8a5e7e-cd61-428c-a5e5-2154be503249 /home                   ext4    defaults        1 2
UUID=7551321b-8375-414f-8812-66d000efc33a swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/scd0       /media/cdrom0   udf,iso9660 user,noauto,exec,utf8 0       0
/dev/sda1               /var/samba              ext3    defaults        0 0   --追加的partition

     You can specify a   comma‑  separated list of types to try, as is the case with the   DVD‑  ROM drive, /dev/scd0. This tries the udf DVD file system first and then iso9660, which is used by   CD‑  ROMs.
     To add your new partition, you will need to know its UUID. You can find this in the tune2fs listing, or you can use the blkid utility. If you run the latter without any parameters, it prints the UUID for all detected block devices
[root@hadoop-master ~]# blkid
/dev/sda1: UUID="62cfa358-911e-4719-a6b6-698eacaa47a4" TYPE="ext4"
/dev/sda2: UUID="7d014851-6087-4d10-ac52-22bdc850d49a" TYPE="ext4"
/dev/sda3: UUID="7551321b-8375-414f-8812-66d000efc33a" TYPE="swap"
/dev/sda5: UUID="3f8a5e7e-cd61-428c-a5e5-2154be503249" TYPE="ext4"

     To mount your ext4 partition with the default mount options, add the following line to the /etc/fstab file:
     UUID= 62cfa358-911e-4719-a6b6-698eacaa47a4   /mnt/data  ext4  defaults  0  0
     If you want to use the device node instead, you can add this:
     /dev/sda1  /mnt/data  ext4  defaults  0  0
     Now you can test this entry without the need to reboot. If you use the mount command and only pass the mount point as a parameter, it will check the /etc/fstab file for a matching entry and mount that, with the options specified in the file:
     $ sudo mount /mnt/data
     You can   double‑  check that the file system is mounted by running the mount command without any parameters, which will list all mounted file systems on the host
     $ mount

     1.3.2 Checking File System Usage
  • $ df -h
  • $ du -sh /etc




2012年3月9日星期五

Networking and Firewalls

1.Introduction to Networks and Networking
   1.1 Getting Started with Interfaces
     To display the status of all the interfaces on a host, use this command:
     $­ifconfig­–a      

     To make it easier to explore the configuration of an interface, you can also display a single interface, like so:
     $­ifconfig­ eth0
     
     激活网卡
     $­sudo ­ifconfig­ eth0­ up
     失效网卡
     $­sudo ­ifconfig­ eth0­ down
     ­$sudo ­ifdown ­eth0
     修改网卡IP
     ­$sudo ­ifconfig eth0 192.168.0.3 netmask 255.255.255.0  --netmask 可以省略

     The ifconfig command can also be used to add and delete IP addresses to and from an interface; here is how we could have added our 192.168.0.1 IP address to the eth0 interface:
     $­sudo ­ifconfig ­eth0­ add­ 192.168.0.1
     The ifconfig command can also be used to delete an IP address from an interface like so:
     $­sudo ­ifconfig ­eth0 ­del­ 192.168.0.1


修改ip地址
即时生效:
# ifconfig eth0 192.168.0.20 netmask 255.255.255.0
启动生效:
#  vi /etc/sysconfig/network-scripts/ifcfg-eth0
(CENTOS6以后,ifcfg-Auto_eth0)

修改default gateway
即时生效:
# route add default gw 192.168.0.254
启动生效:
修改/etc/sysconfig/network-scripts/ifcfg-eth0

修改dns
修改/etc/resolv.conf
修改后可即时生效,启动同样有效

修改host name
即时生效:
# hostname fc2
启动生效:
修改/etc/sysconfig/network

etc/sysconfig/network-scripts/ifcfg-ethN 文件
在RedHat中,系统网络设备的配置文件保存在“/etc/sysconfig/network-scripts”目录下,ifcfg-eth0包含第一块网卡的配置信息,ifcfg-eth1包含第二块网卡的配置信息。
下面是“/etc/sysconfig/network-scripts/ifcfg-eth0”文件的示例:
DEVICE=eth0
IPADDR=x.x.x.x
NETMASK=255.255.255.0
NETWORK=x.x.x.x
BROADCAST=x.x.x.x
ONBOOT=yes
BOOTPROTO=none
USERCTL=no

若希望手工修改网络地址或在新的接口上增加新的网络界面,可以通过修改对应的文件(ifcfg-ethN)或创建新的文件来实现。
DEVICE=name     name表示物理设备的名字
IPADDR=addr     addr表示赋给该卡的IP地址
NETMASK=mask    mask表示网络掩码
NETWORK=addr    addr表示网络地址
BROADCAST=addr   addr表示广播地址
ONBOOT=yes/no   启动时是否激活该卡
none:无须启动协议
bootp:使用bootp协议
dhcp:使用dhcp协议
USERCTL=yes/no       是否允许非root用户控制该设备

   1.2 general Network Troubleshooting

  • ping
  • mtr

      mtr www.google.com 的输出结果如下

                             My traceroute  [v0.71]

localhost.localdomain (0.0.0.0)                        Fri Mar  9 22:55:45 2012
Keys:  Help   Display mode   Restart statistics   Order of fields   quit
                                              Packets               Pings
 Host                                       Loss%  Last   Avg  Best  Wrst StDev
 1. 192.168.1.1                              0.0%   1.1   1.2   0.9   5.2   0.6
 2. 118.23.8.90                              0.0%  50.1  34.4   9.7  64.3  12.0
 3. 118.23.7.213                             0.0%  55.6  33.4  11.0  63.6  11.5
 4. 118.23.96.29                             0.0%  52.9  36.3  12.1  63.2  11.9
 5. 122.28.168.29                            0.0%  55.6  35.1  13.4  71.1  12.8
 6. 118.23.168.86                            0.0%  44.1  39.6  12.8 151.8  20.0
 7. 118.23.146.226                           0.0%  54.2  38.1  13.1 133.1  16.5
 8. 211.129.61.38                            2.0%  75.3  62.6  37.6 126.3  17.4
 9. 209.85.241.90                            0.0%  56.7  43.5  17.6 155.4  22.1
10. 209.85.241.133                           0.0%  54.8  37.4  15.0  65.9  12.3
11. nrt19s12-in-f20.1e100.net                0.0%  54.6  35.7  13.2  67.2  12.4

Loss% : 是显示的每个对应IP的丢包率
Last     : 显示的最近一次的返回时延
Avg      :是平均值 这个应该是发送ping包的平均时延
Best     :是最好或者说时延最短的
Wrst     :是最差或者说时延最常的
StDev : 是标准偏差

  • tcpdump
  • netstat

     We will then start the nc command using the -l, or listen, option on the host with the IP address of 192.168.0.1.

     $­sudo ­nc ­-l ­80

     This binds our nc command to all interfaces on the port. We can test that by running another command called netstat:

     $­sudo ­netstat­ –lpt
     tcp        0      0 *:http                      *:*                         LISTEN      5154/nc
     -l : listen for network connections
     -p: display what applications are using each connection
     -t : look for TCP connections only

   1.3 Netfilter and iptables
     The iptables command is the   user‑  space management tool for Netfilter. It allows the operating system to perform packet filtering and shaping at a kernel level, and this allows it to be under fewer restrictions than   user‑  space programs. This is especially useful for dedicated firewall and router hosts

     1.3.1 Tables
     Netfilter has four built‑in tables that can hold rules for process‑ing traffic. The first is the filter table, which is the default table used for all rules related to the filtering of your traffic. The second is nat, which handles NAT rules. Next is the mangle table, which covers a variety of packet alteration functions. Last of all is the raw table, which is used to exempt packets from connection tracking and is called before any other Netfilter table.
     1.3.2 Chains
     Each of the Netfilter tables, filter, nat, mangle, and raw, contain sets of predefined hooks that Netfilter will process in order.

   Built-in Chains
Chain                 description
INPUT              Used to sequence rules for packets coming to the host interface(s). Found in the filter and
                          mangle tables only.
FORWARD      Used to sequence rules for packets destined for another host. Found in the filter and
                         mangle  table only.
OUTPUT          Used to sequence rules for outgoing packets originating from the host interface(s). Found in
                          the filter, nat, mangle, and raw tables.
PREROUTING    Used to alter packets before they are routed to the other chains. Found in the nat,
                            mangle, and raw tables.
POSTROUTING Used to alter packets after they have left the other chains and are about to go out of the
                            interface(s). Found in the nat and mangle tables only.

具体可以参考下面链接
 http://javafreeman.blogspot.com/2012/03/netfilteriptables.html






     

netfilter/iptables全攻略(转)

无法查看这则摘要。请 点击此处查看博文。

2012年3月8日星期四

Startup and Services

1.Understanding the GRUB Boot Loader
   1.1 Configuring GRUB
      The GRUB boot loader is highly configurable, and its configuration is contained in the grub.conf
configuration file. On Red Hat, it can be found at /boot/grub/grub.conf (and the file is usually linked symbolically to /etc/grub.conf).


#boot=/dev/sda
default=1
timeout=5
splashimage=(hd0,2)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-238.19.1.el5)
        root (hd0,2)
        kernel /vmlinuz-2.6.18-238.19.1.el5 ro root=LABEL=/ rhgb quiet
        initrd /initrd-2.6.18-238.19.1.el5.img
title CentOS (2.6.18-238.12.1.el5)
        root (hd0,2)
        kernel /vmlinuz-2.6.18-238.12.1.el5 ro root=LABEL=/ rhgb quiet
        initrd /initrd-2.6.18-238.12.1.el5.img


   1.2 Securing Your Boot Loader

     GRUB provides the ability to set a password to the boot loader so that any changes to the preconfigured boot process requires the user to enter a password. First you have to generate an MD5 hash password, and then add that to the grub.conf file. To do this, you need to initiate GRUB’s   command-  line manager using the grub command.

$ sudo grub
grub> md5crypt
Password: ************
Encrypted: $1$3yQFp$MEDEglsxOvuTWzWaztRly.
grub> quit

Next, add this to your grub.conf file like so:
default=1
timeout=10
splashimage=(hd0,2)/grub/splash.xpm.gz
password   --  md5 $1$3yQFp$MEDEglsxOvuTWzWaztRly     --全局密码,不能直接使用e命令编辑
hiddenmenu
title CentOS (2.6.18-238.19.1.el5)
password   --  md5 $1$3yQFp$MEDEglsxOvuTWzWaztRly     --菜单密码,输入菜单密码才能启动
        root (hd0,2)
        kernel /vmlinuz-2.6.18-238.19.1.el5 ro root=LABEL=/ rhgb quiet
        initrd /initrd-2.6.18-238.19.1.el5.img
title CentOS (2.6.18-238.12.1.el5)
        root (hd0,2)
        kernel /vmlinuz-2.6.18-238.12.1.el5 ro root=LABEL=/ rhgb quiet
        initrd /initrd-2.6.18-238.12.1.el5.img

   1.3 Configuring init

     Red Hat generally starts in runlevel 5 if you have a GUI console installed or runlevel 3 for command line only. Red Hat has the following runlevels:
Runlevel 0: Shuts down the host and brings the system to a halt
Runlevel 1: Runs in   single-  user (maintenance) mode, command console, no network
Runlevel 2: Is unassigned
Runlevel 3: Runs in multiuser mode, with network, and starts level 3 programs
Runlevel 4: Is unassigned
Runlevel 5: Runs in multiuser mode, with network, X Windows (KDE, GNOME), and starts level 5 programs.
Runlevel 6: Reboots the host


     On most distributions, including Red Hat, the /sbin/init tool is configured using the /etc/inittab file. The init tool uses a series of scripts and directories under the /etc/rc.d directory named rc.x where x is the runlevel; for example, the /etc/rc.d/rc3.d directory stores the applications in runlevel 3.
    $ man inittab



     To change the default runlevel, which is the most common reason for editing the inittab file, you change the initdefault line. Here, the default runlevel is 5:
     id:5:initdefault:
To change the default runlevel from 5 to 3, you replace the number 5 with 3 like so:
     id:3:initdefault:

     You can use the telinit or init command to switch between runlevels. First, work out what runlevel you

are at now by using the runlevel command, which will return a message showing the previous and current runlevel, as shown in this example:
     $ sudo runlevel
     N 5

     $ sudo telinit 3
     $ sudo init 3


   1.4 Managing Services
     You can examine what services will start in each runlevel by listing the contents of the /etc/rc.d/rcn.d directories (where n is a runlevel between 0 and 6). Let’s look at part of the contents of the /etc/rc.d/rc3.d directory.
$ ls -l /etc/rc.d/rc3.d/
lrwxrwxrwx 1 root root 16   2008-04-  29 06:58 K02httpd -> ../init.d/httpd
lrwxrwxrwx 1 root root 17   2008-04-  29 07:31 K30postfix -> ../init.d/postfix
lrwxrwxrwx 1 root root 20   2007-11-  09 04:48 K50netconsole -> ../init.d/netconsole
lrwxrwxrwx 1 root root 19   2008-08-  19 06:58 S08ip6tables -> ../init.d/ip6tables
lrwxrwxrwx 1 root root 18   2008-08-  19 06:58 S08iptables -> ../init.d/iptables
lrwxrwxrwx 1 root root 17   2007-11-  09 04:48 S80postfix -> ../init.d/postfix

     You can see that all the files in the /etc/rc.d/rc3.d directory are symbolic links to indi-vidual init.d scripts, which are found in /etc/rc.d/init.d/ directory contain the instructions about how to start, stop, and return the status of each application or service.

   1.5 Managing Services on Red Hat
     let’s start by looking at a Red Hat init script: take a look at the postfix script located in /etc/init.d. Let’s look at the top of the script using the head command:
     $ sudo head –n 5 /etc/init.d/postfix
     This will show the first five lines of the /etc/init.d/postfix file, as you can see in   Listing 5-4.

#!/bin/bash
# postfix      Postfix Mail Transfer Agent
# chkconfig: 2345 80 30
# description: Postfix is a Mail Transport Agent, which is the program \
#              that moves mail from one machine to another.


     On line 3 you see chkconfig: 2345 80 30. This information is used by a program called chkconfig to set up the symbolic links to the /etc/rc.d/rc2.d, /etc/rc.d/rc3.d, /etc/rc.d/rc4.d, and /etc/rc.d/rc5.d directories you saw earlier in this chapter. In this case, the Postfix script starts on runlevels 2, 3, 4, and 5 (as indicated by 2345), runs with a priority of 80, and stops with a priority of 30. The chkconfig command creates the symbolic links (often called symlinks) to the /etc/init.d/postfix script in the /etc/rc.d/rcn.d/ directories with the S80 and K30 prefixes. The #description line used by chkconfig is also important. Both the ckconfig
and description definitions must be present, or an error will result.

     1.5.1 Starting and Stopping Services at Boot and Shutdown
     to change service runlevels in Red Hat is to use the chkconfig command.
     Option   Description
     --list      Gives information pertaining to a service if that service is specified. Otherwise, all services                        
                  are listed, with information given as to whether the service is started or stopped in each runlevel.
     --add    Adds a service to chkconfig management. An entry in each runlevel is created according to the
                  information found in the init script.
     --del     Removes the service from chkconfig management. The symlinks in the /etc/rcn.d directories are
                  removed.
     --level   Manages services for particular levels combined with the name of the service and the setting you
                  wish (e.g., chkconfig   --  level 25 httpd off).



     $ sudo /sbin/chkconfig   --  list


     If you intend to have the Postfix mail server added to the default runlevels according to the /etc/rc.d/init.d/postfix script, let chkconfig manage it for you by entering the following command:
     $ sudo chkconfig postfix on

     This turns the service on for the runlevels specified in the init.d script through chkconfig: 2345 80 30 by default. You can also manually specify with chkconfig the exact runlevels you wish Postfix to start in. For example:
     $ sudo chkconfig   --  level 35 postfix on
     This command will turn Postfix on at runlevels 3 and 5. When your host is rebooted, it will now start the Postfix service in either runlevel 3 or 5, but not in 2 or 4, unless specifically instructed to do so.


     If you wish to turn a service off so it doesn’t start when your host is restarted, you would issue the following command:
     $ sudo chkconfig postfix off


     1.5.2 Starting and Stopping running Services

     All of the scripts located in the /etc/init.d directory are generally executable. Each script can also usually take one of the following arguments: start, stop, restart, reload, or status. To see how to restart the Postfix service, take a look at the following example:
     $ sudo /etc/init.d/postfix restart



    The following command line will reload Postfix (this will reread the configuration files, and the processes will restart as soon as they can):
     $ sudo service postfix reload
     Reloading postfix:                                         [  OK  ]

   1.6 Shutting Down and Rebooting Your Linux Host
     1.6.1 Shutting Down
     $ sudo shutdown –h now
     $ sudo  init 0



     1.6.2 Rebooting
     $ sudo shutdown –r now
     $ sudo  init 6







Notepad++で文字化け

インストールした直後のデフォルト状態だと日本語の文字が文字化けするようです。
(なんか、どこかのバージョンで日本語対応になったと思ってんだけど気のせいかな?)
 
対応は簡単で以下のような設定を行えばOKです。
1. [設定]-[スタイル設定]をメニューから選択
2. 表示されるダイアログから以下の3項目を設定します。
フォント名: 日本語が表示可能なフォントを選択
フォント名を他のスタイルにも適用:チェックする
フォントサイズを他のスタイルにも適用:チェックする

2012年3月6日星期二

linux下查看进程内存使用情况(转)


动态查看一个进程的内存使用
  1. 1、top命令  
  2. top -d 1 -p pid [,pid ...]  //设置为delay 1s,默认是delay 3s  
  3. 如果想根据内存使用量进行排序,可以shift + m(Sort by memory usage)  


静态查看一个进程的内存使用

  1. 1、pmap命令  
  2. pmap pid  
  3.   
  4. 2、ps命令  
  5. ps aux|grep process_name  
  6.   
  7. 3、查看/proc/process_id/文件夹下的status文件  
  8. Name:   php  
  9. State:  R (running)  
  10. SleepAVG:       0%  
  11. Tgid:   21574  
  12. Pid:    21574  
  13. PPid:   10005  
  14. TracerPid:      0  
  15. Uid:    1000    1000    1000    1000  
  16. Gid:    100     100     100     100  
  17. FDSize: 256  
  18. Groups: 16 100   
  19. VmPeak:   161740 kB  
  20. VmSize:   161740 kB  
  21. VmLck:         0 kB  
  22. VmHWM:    107144 kB  
  23. VmRSS:    107144 kB  
  24. VmData:   106192 kB  
  25. VmStk:        84 kB  
  26. VmExe:      5588 kB  
  27. VmLib:      7884 kB  
  28. VmPTE:       268 kB  
  29. Threads:        1  
  30. SigQ:   0/69632  
  31. SigPnd: 0000000000000000  
  32. ShdPnd: 0000000000000000  
  33. SigBlk: 0000000000000000  
  34. SigIgn: 0000000000001000  
  35. SigCgt: 00000001818040a7  
  36. CapInh: 0000000000000000  
  37. CapPrm: 0000000000000000  
  38. CapEff: 0000000000000000  
  39. Cpus_allowed:   00000000,00000000,00000000,0000000f  
  40. Mems_allowed:   1  
  41.   
  42. 任务虚拟地址空间的大小 VmSize  
  43. 应用程序正在使用的物理内存的大小 VmRSS