首页 > *nix技术, Shell命令, 多机集群 > TIPC 2.0.0 使用初试

TIPC 2.0.0 使用初试

2012年3月4日 发表评论 阅读评论 13,292 次浏览

照例先看相关版本:

[root@localhost lenky]# uname -a
Linux localhost.localdomain 2.6.38.8 #1 SMP Sat Dec 31 17:17:47 EST 2011 i686 i686 i386 GNU/Linux
[root@localhost lenky]# ls -l
total 72
drwxrwxr-x. 5 root root  4096 May  7  2010 tipcutils-2.0.0
-rw-r--r--. 1 root root 66495 Mar  3  2012 tipcutils-2.0.0.tar.gz
[root@localhost lenky]#

从内核2.6.35开始,TIPC 2.0就已经合入主线,所以这里的2.6.38.8内核正好合适,可直接利用内核中的TIPC 2.0模块,当然,要使用它必须首先确保已经打开了对应的内核编译选项,具体位置在Networking support —> Networking options —> The TIPC Protocol (EXPERIMENTAL),以模块形式编译即可:

[root@localhost lenky]# cat /usr/src/linux-2.6.38.8/.config | grep TIPC
CONFIG_TIPC=m
CONFIG_TIPC_ADVANCED=y
CONFIG_TIPC_NODES=255
CONFIG_TIPC_PORTS=8191
CONFIG_TIPC_LOG=0
CONFIG_TIPC_DEBUG=y
[root@localhost lenky]# 

操作TIPC 2.0的用户工具需要对应的2.0.0版本后的tipc-config,从http://tipc.sourceforge.net/tipc_linux.shtml下载最新的tipc-config源码进行编译。由于tipc-config源码中使用到内核头文件,所以需要指定内核头文件的位置,这在Makefile里以INCLUDE_PATH变量的形式存在:

ifdef INCLUDE_PATH
# Specifies path to directory that resolves #include <linux/tipc.h>
IFLAGS = -I${INCLUDE_PATH}
endif

直接make编译会出错:

[root@localhost tipcutils-2.0.0]# make
make -C tipc-config
make[1]: Entering directory `/root/home/lenky/tipcutils-2.0.0/tipc-config'
cc  -D VERSION=\"2.0.0\" -Wall -O2    -c -o tipc-config.o tipc-config.c
tipc-config.c: In function ‘show_stats’:
tipc-config.c:1084: error: ‘TIPC_CMD_SHOW_STATS’ undeclared (first use in this function)
tipc-config.c:1084: error: (Each undeclared identifier is reported only once
tipc-config.c:1084: error: for each function it appears in.)
make[1]: *** [tipc-config.o] Error 1
make[1]: Leaving directory `/root/home/lenky/tipcutils-2.0.0/tipc-config'
make: *** [tipc-config] Error 2
[root@localhost tipcutils-2.0.0]#

可以这样:

[root@localhost tipcutils-2.0.0]# export INCLUDE_PATH=/usr/src/linux-`uname -r`/include
[root@localhost tipcutils-2.0.0]# make
make -C tipc-config
make[1]: Entering directory `/root/home/lenky/tipcutils-2.0.0/tipc-config'
cc -I/usr/src/linux-2.6.38.8/include -D VERSION=\"2.0.0\" -Wall -O2    -c -o tipc-config.o tipc-config.c
In file included from /usr/src/linux-2.6.38.8/include/linux/tipc.h:40,
                 from tipc-config.c:46:
/usr/src/linux-2.6.38.8/include/linux/types.h:13:2: warning: #warning "Attempt to use kernel headers from user space, see http://kernelnewbies.org/KernelHeaders"
...
/usr/src/linux-2.6.38.8/include/linux/types.h:13:2: warning: #warning "Attempt to use kernel headers from user space, see http://kernelnewbies.org/KernelHeaders"
gcc -I/usr/src/linux-2.6.38.8/include  -Wall -O2  server_tipc.o  -o server_tipc
make[2]: Leaving directory `/root/home/lenky/tipcutils-2.0.0/demos/benchmark'
make[1]: Leaving directory `/root/home/lenky/tipcutils-2.0.0/demos'
[root@localhost tipcutils-2.0.0]# 

或者这样:

[root@localhost tipcutils-2.0.0]# make INCLUDE_PATH=/usr/src/linux-`uname -r`/include
make -C tipc-config
make[1]: Entering directory `/root/home/lenky/tipcutils-2.0.0/tipc-config'
cc -I/usr/src/linux-2.6.38.8/include -D VERSION=\"2.0.0\" -Wall -O2    -c -o tipc-config.o tipc-config.c
In file included from /usr/src/linux-2.6.38.8/include/linux/tipc.h:40,
                 from tipc-config.c:46:
/usr/src/linux-2.6.38.8/include/linux/types.h:13:2: warning: #warning "Attempt to use kernel headers from user space, see http://kernelnewbies.org/KernelHeaders"
...
/usr/src/linux-2.6.38.8/include/linux/types.h:13:2: warning: #warning "Attempt to use kernel headers from user space, see http://kernelnewbies.org/KernelHeaders"
gcc -I/usr/src/linux-2.6.38.8/include  -Wall -O2  server_tipc.o  -o server_tipc
make[2]: Leaving directory `/root/home/lenky/tipcutils-2.0.0/demos/benchmark'
make[1]: Leaving directory `/root/home/lenky/tipcutils-2.0.0/demos'
[root@localhost tipcutils-2.0.0]# 

不管怎样,应用层工具tipc-config编译好了:

[root@localhost tipc-config]# ls -F
Makefile  README  tipc-config*  tipc-config.c  tipc-config.o
[root@localhost tipc-config]# 

弄两台机器(A和B),一样的环境(我这里是两台虚拟机,在虚拟机A上准备好TIPC的相关环境后克隆得到B),机器A:

[root@localhost tipc-config]# ls
Makefile  README  tipc-config  tipc-config.c  tipc-config.o
[root@localhost tipc-config]# ifconfig eth0 | grep addr
eth0      Link encap:Ethernet  HWaddr 00:0C:29:A3:25:7D  
          inet addr:192.168.205.130  Bcast:192.168.205.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fea3:257d/64 Scope:Link
[root@localhost tipc-config]# uname -a
Linux localhost.localdomain 2.6.38.8 #1 SMP Sat Dec 31 17:17:47 EST 2011 i686 i686 i386 GNU/Linux
[root@localhost tipc-config]# ./tipc-config -netid=8888 -a=1.1.1 -be=eth:eth0
TIPC module not installed
[root@localhost tipc-config]# modprobe tipc
[root@localhost tipc-config]# ./tipc-config -netid=8888 -a=1.1.1 -be=eth:eth0
[root@localhost tipc-config]# 

使用dmesg命令可以看到如下信息:

[root@localhost tipc-config]# dmesg -c
...
TIPC: Activated (version 2.0.0 compiled Dec 31 2011 17:13:52)
NET: Registered protocol family 30
TIPC: Started in single node mode
TIPC: Started in network mode
TIPC: Own node address <1.1.1>, network identity 8888
TIPC: Enabled bearer <eth:eth0>, discovery domain <1.1.0>, priority 10
[root@localhost tipc-config]# 

再操作机器B:

[root@localhost tipc-config]# ls
Makefile  README  tipc-config  tipc-config.c  tipc-config.o
[root@localhost tipc-config]# ifconfig eth1 | grep addr
eth1      Link encap:Ethernet  HWaddr 00:0C:29:11:83:B6  
          inet addr:192.168.205.131  Bcast:192.168.205.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe11:83b6/64 Scope:Link
[root@localhost tipc-config]# uname -a
Linux localhost.localdomain 2.6.38.8 #1 SMP Sat Dec 31 17:17:47 EST 2011 i686 i686 i386 GNU/Linux
[root@localhost tipc-config]# modprobe tipc
[root@localhost tipc-config]# ./tipc-config -netid=8888 -a=1.1.2 -be=eth:eth1
[root@localhost tipc-config]# dmesg -c
...
TIPC: Activated (version 2.0.0 compiled Dec 31 2011 17:13:52)
NET: Registered protocol family 30
TIPC: Started in single node mode
TIPC: Started in network mode
TIPC: Own node address <1.1.2>, network identity 8888
TIPC: Enabled bearer <eth:eth1>, discovery domain <1.1.0>, priority 10
TIPC: Established link <1.1.2:eth1-1.1.1:eth0> on network plane A
[root@localhost tipc-config]# 

相比之前机器A的dmesg信息,多了最后的“Established link”信息,不过再看机器A的dmesg信息:

[root@localhost tipc-config]# dmesg -c
TIPC: Established link <1.1.1:eth0-1.1.2:eth1> on network plane A
[root@localhost tipc-config]# 

也有了“Established link”信息,说明机器A和机器B已经自动相互发现并进行了链接。好了,先来执行官方的demo程序试验一下,首选当然是hello world程序,机器A:

[root@localhost tipc-config]# cd ../demos/
[root@localhost demos]# cd hello_world/
[root@localhost hello_world]# ls -F
client_tipc*  client_tipc.c  client_tipc.o  Makefile  server_tipc*  server_tipc.c  server_tipc.o
[root@localhost hello_world]# ./server_tipc 
****** TIPC server hello world program started ******

此时程序server_tipc处于等待链接连接状态,再执行机器B上的client_tipc:

[root@localhost tipc-config]# cd ../demos/hello_world/
[root@localhost hello_world]# ls -F
client_tipc*  client_tipc.c  client_tipc.o  Makefile  server_tipc*  server_tipc.c  server_tipc.o
[root@localhost hello_world]# ./client_tipc 
****** TIPC client hello world program started ******

Client: received response: Uh ? 

****** TIPC client hello program finished ******
[root@localhost hello_world]# 

回过来看机器A上的server_tipc:

[root@localhost hello_world]# ./server_tipc 
****** TIPC server hello world program started ******

Server: Message received: Hello World !

****** TIPC server hello program finished ******
[root@localhost hello_world]# 

OK,OVER!

参考资料:http://tipc.sourceforge.net/doc/tipc_2.0_users_guide.html

转载请保留地址:http://www.lenky.info/archives/2012/03/1248http://lenky.info/?p=1248


备注:如无特殊说明,文章内容均出自Lenky个人的真实理解而并非存心妄自揣测来故意愚人耳目。由于个人水平有限,虽力求内容正确无误,但仍然难免出错,请勿见怪,如果可以则请留言告之,并欢迎来讨论。另外值得说明的是,Lenky的部分文章以及部分内容参考借鉴了网络上各位网友的热心分享,特别是一些带有完全参考的文章,其后附带的链接内容也许更直接、更丰富,而我只是做了一下归纳&转述,在此也一并表示感谢。关于本站的所有技术文章,欢迎转载,但请遵从CC创作共享协议,而一些私人性质较强的心情随笔,建议不要转载。

法律:根据最新颁布的《信息网络传播权保护条例》,如果您认为本文章的任何内容侵犯了您的权利,请以Email或书面等方式告知,本站将及时删除相关内容或链接。

  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.
您必须在 登录 后才能发布评论.