2014年6月18日 星期三

Sned Mail 如何用外部信件發信

一般來說當你用command 的方式去寄信,通常是用本機的sendmail去寄,若不想用本機,該如何設定
vim /etc/mail/submit.cf
找到MTAHost
將 D{MTAHost}[127.0.0.1] 改為 D{MTAHost}[10.10.2.10]  在重新啟動 sendmail 
service sendmail restart 
就可以囉,但前提是該主機的sendmail 已經設定好,並允許本機的RELAY 才可以喔


遠端桌面如何登到CONSOLE 的畫面,同站在電腦面前

一般來說,用遠端桌面雖說是同一個登入帳號,比如administrator但若同時間有兩個administratir 登入遠端,其實你會看到兩個畫面是不同的。

有沒有辦法用遠端桌面可以筆看到如VNC的畫面,就是Console 的畫面,而不是另一個畫面

XP:   mstsc /admin 之後的操作就沒改變,進去後就是Console 的畫面

2013年12月6日 星期五

CentOS-6.3安装配置SVN


zhoulf 2013-02-02 原创

安装说明

系统环境:CentOS-6.3
安装方式:yum install (源码安装容易产生版本兼容的问题)
安装软件:系统自动下载SVN软件

检查已安装版本

#检查是否安装了低版本的SVN
[root@localhost /]# rpm -qa subversion
#卸载旧版本SVN
[root@localhost modules]# yum remove subversion

安装SVN

[root@localhost modules]# yum install httpd httpd-devel subversion mod_dav_svn mod_auth_mysql

确认已安装了svn模块

[root@localhost /]# cd /etc/httpd/modules
[root@localhost modules]# ls | grep svn
mod_authz_svn.so
mod_dav_svn.so

验证安装

检验已经安装的SVN版本信息
[root@localhost modules]# svnserve --version
svnserve,版本 1.6.11 (r934486)
编译于 Jun 23 2012,00:44:03
版权所有 (C) 2000-2009 CollabNet。
Subversion 是开放源代码软件,请参阅 http://subversion.tigris.org/ 站点。
此产品包含由 CollabNet(http://www.Collab.Net/) 开发的软件。
下列版本库后端(FS) 模块可用:
* fs_base : 模块只能操作BDB版本库。
* fs_fs : 模块与文本文件(FSFS)版本库一起工作。
Cyrus SASL 认证可用。

代码库创建

SVN软件安装完成后还需要建立SVN库
[root@localhost modules]# mkdir -p /opt/svn/repositories
[root@localhost modules]# svnadmin create /opt/svn/repositories
执行上面的命令后,自动建立repzhoulf 2013-02-02 原创ositories库,查看/opt/svn/repositories 文件夹发现包含了conf, db,format,hooks, locks, README.txt等文件,说明一个SVN库已经建立。

配置代码库

进入上面生成的文件夹conf下,进行配置
[root@localhost modules]# cd /opt/svn/repositories/conf

用户密码passwd配置

[root@localhost password]# cd /opt/svn/repositories/conf
[root@admin conf]# vi + passwd
修改passwd为以下内容:
[users]
# harry = harryssecret
# sally = sallyssecret
zhoulf=123456

权限控制authz配置

[root@admin conf]# vi + authz
目的是设置哪些用户可以访问哪些目录,向authz文件追加以下内容:
#设置[/]代表根目录下所有的资源
[/]
zhoulf=rw

服务svnserve.conf配置

[root@admin conf]# vi + svnserve.conf
追加以下内容:
[general]
#匿名访问的权限,可以是read,write,none,默认为read
anon-access=none
#使授权用户有写权限
auth-access=write
#密码数据库的路径
password-db=passwd
#访问控制文件
authz-db=authz
#认证命名空间,subversion会在认证提示里显示,并且作为凭证缓存的关键字
realm=/opt/svn/repositories

配置防火墙端口zhoulf 2013-02-02 原创

[root@localhost conf]# vi /etc/sysconfig/iptables
添加以下内容:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3690 -j ACCEPT
保存后重启防火墙
[root@localhost conf]# service iptables restart

启动SVN

svnserve -d -r /opt/svn/repositories

查看SVN进程

[root@localhost conf]# ps -ef|grep svn|grep -v grep
root     12538     1  0 14:40 ?        00:00:00 svnserve -d -r /opt/svn/repositories

检测SVN 端口

[root@localhost conf]# netstat -ln |grep 3690
tcp        0      0 0.0.0.0:3690                0.0.0.0:*                   LISTEN

停止重启SVN

[root@localhost password]# killall svnserve    //停止
[root@localhost password]# svnserve -d -r /opt/svn/repositories  // 启动

测试

SVN服务已经启动,使用客户端测试连接。
客户端连接地址:svn://192.168.15.231
用户名/密码: zhoulf/123456
测试创建文件夹等操作。


2007/06/14 16:51
以下是有關SVN備份及同步的工作記事 有關SVN的架設及使用請看這一篇


SVN Server端檔案庫備份


svnadmin hotcopy 原始檔案庫路徑 要備份目標路徑

例如

svnadmin hotcopy D:\SVNRoot\Proj1 E:\SVNBack\Proj1

另外 備份目標必須為空目錄
所以備份前需要先刪除舊有資料 或是建立新資料夾
可以使用windows所提供的批此檔及排程來自動備份
批次檔內容例如下方

@echo off

set SVN_BackUp=E:\SVNBackup
set SVN_ROOT=D:\SVNRoot
set SVN_BackUp_Dir=%SVN_BackUp%\%date:~0,4%%date:~5,2%%date:~8,2%

if not exist %SVN_BackUp% mkdir %SVN_BackUp%
if exist %SVN_BackUp_Dir% goto ALREADY_EXIST_DATE
mkdir %SVN_BackUp_Dir%
for /r %SVN_ROOT% %%D in (.) do @if exist "%%D\conf\svnserve.conf" svnadmin hotcopy %%~fD %SVN_BackUp_Dir%\%%~nD
goto END

:ALREADY_EXIST_DATE
echo 目錄%SVN_BackUp_Dir%已存在

:END

將上方內容存檔到D:\SVNRoot\BackUp.bat
並利用Windows排程 每天晚上10點備份

at 22:00 /every:s,m,t,w,th,f,sa "D:\SVNRoot\BackUp.bat"


不過這一個功能僅能本機端使用
可以注意到svnadmin後面的參數給的都是本機端的路徑
所以處理檔案也都不需要經過SVNService


SNV 檔案庫同步

在新版的SVN提供了SVNSYNC的程式 可以達成兩個檔案庫之間的同步
和上方備份不同的是 他可以經由遠端來運作 因此可以備份到不同電腦上
另外在備份之前不需要刪除舊有資料 因為他是同步
Subversion的官網上雖然有文章介紹如何使用
不過是針對Linux的環境下的說明...
那在Windows雖然很類似 不過要作一些修改

首先 要建立同步目標的檔案庫

svnadmin create DestRepository

然後設定DestRepository的Conf檔跟建立一個新的帳號 (例如"SvnSync")
並在來源檔案庫新增一筆一樣的帳號密碼
並且在hooks的目錄下建立一個新的檔案叫
"pre-revprop-change.bat"
檔案內容使用空白即可運作
不過這一個目標檔案庫有一個限制 他不應該被一般使用者Commit資料上去
也就是說應該只有svnsync可以對他作寫入的動作
應此建議將檔案內容修改為下列所述

@echo off

set repos=%1
set rev=%2
set user=%3
set propname=%4
set action=%5

if not '%user%'=='SvnSync' goto ERROR_USERNAME
exit 0
:ERROR_USERNAME
echo Only allow user SvnSync. >&2
exit 1 

此動作是檢查使用者帳號是否為SvnSync (大小寫有分)
如果要不分大小寫 請將此行改為

if /I not '%user%'=='SvnSync' goto ERROR_USERNAME


接下來要對此檔案庫做初始化的動作 讓他知道要跟哪個來源作同步

svnsync init --username SvnSync --password XXX 目標檔案庫位址 來源檔案庫位址

這一個命令的目標跟來來源都是使用位址 因此可以使用本地端或是遠端路徑
例如

svnsync init --username SvnSync --password XXX file:///E:/SVNBackup/DestRepository svn://SVNServer/SourceRepository

注意 本地端位置中斜線的方向跟數量

最後就是同步的動作

svnsync sync --username SvnSync --password XXX 目標檔案庫位址

同樣的 我們可以寫一些批次檔來達成自動化的目的
方式是在來源檔案庫的hooks的目錄下 建立一個新檔案叫做
"post-commit.bat"
他會在來源檔案庫接受每一次的Commit之後啟動 內容為下

@echo off
svnsync sync --non-interactive --username SvnSync --password XXX svn://SVNServer2/DestRepository

這邊是備份到跟來源檔案庫不同的Server上
可以依據每個人不同的需求作更動...

結論是 新的1.4版中的svnsync實在很好用
上半段文章看看就好 使用hotcopy的方式實在是太浪費磁碟空間了
不過前提示 要先把伺服器換成1.4版或以後的版本
並且 目標檔案庫必須是使用1.4版以後的svnadmin所建立的

另外可以發現 寫一些批次檔放進hooks目錄中
可以達成蠻多功能的 有興趣可以網路上搜尋一下文章看看

希望此文章對有使用SVN並架設在Windows上的人有一些幫助

update
如有遇到同步失敗, 或是不同Thread同時要進行同步造成鎖定而錯誤
可使用下列指令解決鎖定

svn propdel svn:sync-lock --revprop -r 0 目標檔案庫位址

SVN (Subversion) Backup and Restore


1. Backup (dump) SVN (Subversion) repository
1.1 Create Dump from SVN (Subversion) repository
svnadmin dump /path/to/reponame > /path/to/reponame.dump
Real example
svnadmin dump /var/www/svn/testrepo > /backups/testrepo.dump
1.2 Gzip Created Dump
gzip -9 /path/to/reponame.dump
Real example
gzip -9 /backups/testrepo.dump
1.3 SVN Dump and Gzip Dump with One-liner
svnadmin dump /path/to/reponame | gzip -9 > /path/to/reponame.dump.gz
Real example
svnadmin dump /var/www/svn/testrepo | gzip -9 > /backups/testrepo.dump.gz
2. Restore (load) SVN (Subversion) repository
2.1 Unzip Dump File
gunzip /path/to/reponame.dump.gz
Real example
gunzip /backups/testrepo.dump.gz
2.2 Create Empty SVN (Subversion) Repository
svnadmin create /path/to/reponame
Real example
svnadmin create /var/www/svn/testrepo
2.3 Setup SVN (Subversion) Repository Permissions
chown -R svnuser:svngroup /path/to/reponame

## If you use SELinux then remember also set security context ##
chcon -R -t httpd_sys_content_t /path/to/reponame

## Following enables commits over http ##
chcon -R -t httpd_sys_rw_content_t /path/to/reponame
Real example
chown -R apache:apache /var/www/svn/testrepo

## Set security context ## 
chcon -R -t httpd_sys_content_t /var/www/svn/testrepo

## Following enables commits over http ##
chcon -R -t httpd_sys_rw_content_t /var/www/svn/testrepo
2.4 Load Data to Repository from SVN (Subversion) Backup
svnadmin load /path/to/reponame < /path/to/reponame.dump
Real example
svnadmin load /var/www/svn/testrepo < /backups/testrepo.dump
3. Automatic SVN (Subversion) Repository Backups
3.1 Edit Crontab
crontab -e
3.2 Add SVN Dump Command to Crontab
@daily svnadmin dump /path/to/reponame > /path/to/reponame.dump
## OR ##
@weekly svnadmin dump /path/to/reponame > /path/to/reponame.dump
Real example
@weekly svnadmin dump /var/www/svn/testrepo > /backups/testrepo.dump
3.3 More Advanced SVN Dump Example with Time and Date and Gzip
@daily svnadmin dump /path/to/reponame | gzip -9 > /path/to/reponame-$(date +"\%Y-\%m-\%d-\%T").dump.gz
Real example
@daily svnadmin dump /var/www/svn/testrepo | gzip -9 > /backups/testrepo-$(date +"\%Y-\%m-\%d-\%T").dump.gz

以上文章摘自
http://www.if-not-true-then-false.com/2012/svn-subversion-backup-and-restore/

2013年10月23日 星期三

RedHat 5.5 64 Bit 安裝 iftop


以下這一個檔案不分32Bit or 64Bit
wget http://www.ex-parrot.com/pdw/iftop/download/iftop-0.17.tar.gz

tar zxvf iftop-0.17.tar.gz

cd iftop-0.17

./configure

checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets ${MAKE}... yes
checking for gcc... gcc
checking for C compiler default output... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking how to run the C preprocessor... gcc -E
checking for egrep... grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking sys/ioctl.h usability... yes
checking sys/ioctl.h presence... yes
checking for sys/ioctl.h... yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking sys/sockio.h usability... no
checking sys/sockio.h presence... no
checking for sys/sockio.h... no
checking for unistd.h... (cached) yes
checking for an ANSI C-conforming const... yes
checking for size_t... yes
checking whether time.h and sys/time.h may both be included... yes
checking sys/dlpi.h usability... no
checking sys/dlpi.h presence... no
checking for sys/dlpi.h... no
checking for regcomp... yes
checking for select... yes
checking for strdup... yes
checking for strerror... yes
checking for strspn... yes
checking for library containing socket... none required
checking for library containing log... -lm
checking for gethostbyname... yes
checking for library containing inet_aton... none required
checking for library containing inet_pton... none required
checking for inet_aton... yes
checking for inet_pton... yes
checking size of u_int8_t... 1
checking size of u_int16_t... 2
checking size of u_int32_t... 4
checking for library containing getnameinfo... none required
checking for library containing gethostbyaddr_r... none required
checking how to call gethostbyaddr_r... 8 args, int return
checking gethostbyaddr_r usability... yes
checking where to find pcap.h... no idea
configure: error: can't find pcap.h
You're not going to get very far without libpcap.

你需要安裝 libpcap-devel


checking for a curses library containing mvchgat... none found
configure: error: Curses! Foiled again!
  (Can't find a curses library supporting mvchgat.)

  Consider installing ncurses.

你需要將 ncurses和ncurses-devel都装上


make && make install

make  all-recursive
make[1]: Entering directory `/root/iftop-0.17'
Making all in config
make[2]: Entering directory `/root/iftop-0.17/config'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/iftop-0.17/config'
make[2]: Entering directory `/root/iftop-0.17'
source='addr_hash.c' object='addr_hash.o' libtool=no \
       depfile='.deps/addr_hash.Po' tmpdepfile='.deps/addr_hash.TPo' \
       depmode=gcc3 /bin/sh ./config/depcomp \
       gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2  -c `test -f 'addr_hash.c' || echo './'`addr_hash.c
source='edline.c' object='edline.o' libtool=no \
       depfile='.deps/edline.Po' tmpdepfile='.deps/edline.TPo' \
       depmode=gcc3 /bin/sh ./config/depcomp \
       gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2  -c `test -f 'edline.c' || echo './'`edline.c
source='hash.c' object='hash.o' libtool=no \
       depfile='.deps/hash.Po' tmpdepfile='.deps/hash.TPo' \
       depmode=gcc3 /bin/sh ./config/depcomp \
       gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2  -c `test -f 'hash.c' || echo './'`hash.c
source='iftop.c' object='iftop.o' libtool=no \
       depfile='.deps/iftop.Po' tmpdepfile='.deps/iftop.TPo' \
       depmode=gcc3 /bin/sh ./config/depcomp \
       gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2  -c `test -f 'iftop.c' || echo './'`iftop.c
source='ns_hash.c' object='ns_hash.o' libtool=no \
       depfile='.deps/ns_hash.Po' tmpdepfile='.deps/ns_hash.TPo' \
       depmode=gcc3 /bin/sh ./config/depcomp \
       gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2  -c `test -f 'ns_hash.c' || echo './'`ns_hash.c
source='options.c' object='options.o' libtool=no \
       depfile='.deps/options.Po' tmpdepfile='.deps/options.TPo' \
       depmode=gcc3 /bin/sh ./config/depcomp \
       gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2  -c `test -f 'options.c' || echo './'`options.c
source='resolver.c' object='resolver.o' libtool=no \
       depfile='.deps/resolver.Po' tmpdepfile='.deps/resolver.TPo' \
       depmode=gcc3 /bin/sh ./config/depcomp \
       gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2  -c `test -f 'resolver.c' || echo './'`resolver.c
source='screenfilter.c' object='screenfilter.o' libtool=no \
       depfile='.deps/screenfilter.Po' tmpdepfile='.deps/screenfilter.TPo' \
       depmode=gcc3 /bin/sh ./config/depcomp \
       gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2  -c `test -f 'screenfilter.c' || echo './'`screenfilter.c
source='serv_hash.c' object='serv_hash.o' libtool=no \
       depfile='.deps/serv_hash.Po' tmpdepfile='.deps/serv_hash.TPo' \
       depmode=gcc3 /bin/sh ./config/depcomp \
       gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2  -c `test -f 'serv_hash.c' || echo './'`serv_hash.c
source='sorted_list.c' object='sorted_list.o' libtool=no \
       depfile='.deps/sorted_list.Po' tmpdepfile='.deps/sorted_list.TPo' \
       depmode=gcc3 /bin/sh ./config/depcomp \
       gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2  -c `test -f 'sorted_list.c' || echo './'`sorted_list.c
source='threadprof.c' object='threadprof.o' libtool=no \
       depfile='.deps/threadprof.Po' tmpdepfile='.deps/threadprof.TPo' \
       depmode=gcc3 /bin/sh ./config/depcomp \
       gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2  -c `test -f 'threadprof.c' || echo './'`threadprof.c
source='ui.c' object='ui.o' libtool=no \
       depfile='.deps/ui.Po' tmpdepfile='.deps/ui.TPo' \
       depmode=gcc3 /bin/sh ./config/depcomp \
       gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2  -c `test -f 'ui.c' || echo './'`ui.c
source='util.c' object='util.o' libtool=no \
       depfile='.deps/util.Po' tmpdepfile='.deps/util.TPo' \
       depmode=gcc3 /bin/sh ./config/depcomp \
       gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2  -c `test -f 'util.c' || echo './'`util.c
source='addrs_ioctl.c' object='addrs_ioctl.o' libtool=no \
       depfile='.deps/addrs_ioctl.Po' tmpdepfile='.deps/addrs_ioctl.TPo' \
       depmode=gcc3 /bin/sh ./config/depcomp \
       gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2  -c `test -f 'addrs_ioctl.c' || echo './'`addrs_ioctl.c
source='addrs_dlpi.c' object='addrs_dlpi.o' libtool=no \
       depfile='.deps/addrs_dlpi.Po' tmpdepfile='.deps/addrs_dlpi.TPo' \
       depmode=gcc3 /bin/sh ./config/depcomp \
       gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2  -c `test -f 'addrs_dlpi.c' || echo './'`addrs_dlpi.c
source='dlcommon.c' object='dlcommon.o' libtool=no \
       depfile='.deps/dlcommon.Po' tmpdepfile='.deps/dlcommon.TPo' \
       depmode=gcc3 /bin/sh ./config/depcomp \
       gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2  -c `test -f 'dlcommon.c' || echo './'`dlcommon.c
source='stringmap.c' object='stringmap.o' libtool=no \
       depfile='.deps/stringmap.Po' tmpdepfile='.deps/stringmap.TPo' \
       depmode=gcc3 /bin/sh ./config/depcomp \
       gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2  -c `test -f 'stringmap.c' || echo './'`stringmap.c
source='cfgfile.c' object='cfgfile.o' libtool=no \
       depfile='.deps/cfgfile.Po' tmpdepfile='.deps/cfgfile.TPo' \
       depmode=gcc3 /bin/sh ./config/depcomp \
       gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2  -c `test -f 'cfgfile.c' || echo './'`cfgfile.c
source='vector.c' object='vector.o' libtool=no \
       depfile='.deps/vector.Po' tmpdepfile='.deps/vector.TPo' \
       depmode=gcc3 /bin/sh ./config/depcomp \
       gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2  -c `test -f 'vector.c' || echo './'`vector.c
gcc  -g -O2    -o iftop  addr_hash.o edline.o hash.o iftop.o ns_hash.o options.o resolver.o screenfilter.o serv_hash.o sorted_list.o threadprof.o ui.o util.o addrs_ioctl.o addrs_dlpi.o dlcommon.o stringmap.o cfgfile.o vector.o  -lpcap -lm  -lcurses -lpthread
make[2]: Leaving directory `/root/iftop-0.17'
make[1]: Leaving directory `/root/iftop-0.17'
Making install in config
make[1]: Entering directory `/root/iftop-0.17/config'
make[2]: Entering directory `/root/iftop-0.17/config'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/root/iftop-0.17/config'
make[1]: Leaving directory `/root/iftop-0.17/config'
make[1]: Entering directory `/root/iftop-0.17'
make[2]: Entering directory `/root/iftop-0.17'
/bin/sh ./config/mkinstalldirs /usr/local/sbin
 /usr/bin/install -c iftop /usr/local/sbin/iftop
/bin/sh ./config/mkinstalldirs /usr/local/man/man8
mkdir -p -- /usr/local/man/man8
/usr/bin/install -c -m 644 ./iftop.8 /usr/local/man/man8/iftop.8
make[2]: Leaving directory `/root/iftop-0.17'
make[1]: Leaving directory `/root/iftop-0.17'
[root@aps24 iftop-0.17]# iftop
interface: eth0
Unable to get IP address for interface: eth0
ioctl(SIOCGIFADDR): Cannot assign requested address
MAC address is: 5c:f3:fc:4b:fa:76

以上這樣就可以使用,在任何位置輸入iftop 即可

2013年9月25日 星期三

Redhat 4,5 Bonding 雙網卡網路

RedHat 4 的作法
vim /etc/modprobe.conf
alias bond0 bonding

若有多張網卡,可定議如下
alias bondx bonding
x為數字
依此類推

新增/etc/sysconfig/network-script/ifcfg-bond0
若有多張網卡,可以定議如下
/etc/sysconfig/network-script/ifcfg-bondx
x為數字
/etc/sysconfig/network-script/ifcfg-bond0 設定如下
DEVICE=bond0
IPADDR=192.168.1.2
NETMASK=255.255.255.0
USERCTL=no
BOOTPROTO=none
ONBOOT=yes
BONDING_OPTS="mode=1 miimon=100"

/etc/sysconfig/network-script/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no

/etc/sysconfig/network-script/ifcfg-eth1
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no

重啟網路
service network restart


RedHat 5 的作法
新增/etc/modprobe.d/aliases.conf ,這檔名可以自定,只要最後是帶.conf就可以被系統認出
alias bond0 bonding 若有多張網卡,設定與RH4相同

新增/etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
TYPE=bonding
BOOTPROTO=static
IPADDR=192.168.1.3
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
ONBOOT=yes
USERCTL=no
NM_CONTROLLED=no
BONDING_OPTS="mode=6 miimon=100 updelay=200 downdelay=200"

vim /etc/sysconfig/network-scripts/ifcfg-eth0
# Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet
DEVICE=eth0
HWADDR=5C:F3:FC:4B:FA:xx 這是你要綁定那一張網卡,可別照抄了
BOOTPROTO=none
NM_CONTROLLED=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no


/etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
HWADDR=5C:F3:FC:4B:FA:xx  這是你要綁定那一張網卡,可別照抄了
BOOTPROTO=none
NM_CONTROLLED=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no

重啟網路
service network restart


模式有以下幾種,我各人比較偏好模式6
以下摘自http://marcustsai.blogspot.tw/2012/11/rhel5-6-nic-bonding.html
3.Bond Mode:

0balance-rr‧負載平衡模式, 需有 switch 設定 (trunk) 支援才能發揮實質效果
‧具容錯功能, 其中一張 Slave 網卡失效仍可持續運作
1active-backup‧同一時間只有單一 Slave 網卡運作
‧Active Slave 網卡失效時自動啟用次一順位 Slave 網卡
‧不需 switch 支援
2balance-xorTransmit based on [(source MAC address XOR'd with destination MAC address) modulo slave count]. This selects the same slave for each destination MAC address. This mode provides load balancing and fault tolerance.
3broadcast‧所有 Slave 網卡一齊收送網路封包
‧具容錯功能, 其中一張 Slave 網卡失效仍可持續運作
4802.3adIEEE 802.3ad Dynamic link aggregation. Creates aggregation groups that share the same speed and duplex settings. Utilizes all slaves in the active aggregator according to the 802.3ad specification.

*Pre-requisites:

1. Ethtool support in the base drivers for retrieving the speed and duplex of each slave.

2. A switch that supports IEEE 802.3ad Dynamic link aggregation. Most switches will require some type of configuration to enable 802.3ad mode
此模式可以參考 http://phorum.study-area.org/index.php?topic=43051.0
5balance-tlb‧傳出自動負載平衡
‧傳入由 Current Active Slave 負責
‧具容錯功能, 其中一張 Slave 網卡失效仍可持續運作
‧不需 switch 支援及設定
6balance-alb‧傳出及傳入皆自動負載平衡
‧具容錯功能, 其中一張 Slave 網卡失效仍可持續運作
‧Slave 網卡 driver 需支援 setting hardware address 功能
‧不需 switch 支援及設定